1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
5 #include <QInputDialog>
8 #include "player/player.h"
12 using namespace SomePlayer::DataObjects;
14 MainWindow::MainWindow(QWidget *parent) :
16 ui(new Ui::MainWindow)
18 _library = new Library(_DATABASE_PATH_, _PLAYLISTS_PATH_);
20 connect(ui->actionAbout_Qt, SIGNAL(triggered()), this, SLOT(aboutQt()));
21 connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
23 _player_form = new PlayerForm(_library, ui->stackedWidget);
24 _library_form = new LibraryForm(_library, ui->stackedWidget);
25 _busy_widget = new BusyWidget(ui->stackedWidget);
26 ui->stackedWidget->insertWidget(0, _player_form);
27 ui->stackedWidget->insertWidget(1, _library_form);
28 ui->stackedWidget->insertWidget(2, _busy_widget);
29 QAction *add_directory = ui->menuLibrary->addAction("Add directory");
30 QAction *save_playlist = ui->menuLibrary->addAction("Save playlist");
31 QAction *clear_playlist = ui->menuLibrary->addAction("Clear current playlist");
32 connect(_player_form, SIGNAL(library()), this, SLOT(library()));
33 connect(_library_form, SIGNAL(player()), this, SLOT(player()));
34 connect(add_directory, SIGNAL(triggered()), this, SLOT(_add_directory()));
35 connect(save_playlist, SIGNAL(triggered()), this, SLOT(_save_playlist()));
36 connect(clear_playlist, SIGNAL(triggered()), this, SLOT(_clear_current_playlist()));
37 connect(_library, SIGNAL(done()), this, SLOT(library()));
38 connect(_library_form, SIGNAL(done()), this, SLOT(library()));
39 connect(_library_form, SIGNAL(busy(QString)), this, SLOT(showBusyWidget(QString)));
40 connect(ui->searchButton, SIGNAL(clicked()), this, SLOT(_toggle_search_line()));
41 connect(_player_form, SIGNAL(showSearchPanel()), this, SLOT(showSearchPanel()));
42 connect(_player_form, SIGNAL(hideSearchPanel()), this, SLOT(hideSearchPanel()));
43 connect(ui->searchLine, SIGNAL(textChanged(QString)), this, SLOT(_search(QString)));
44 connect(ui->nextButton, SIGNAL(clicked()), this, SLOT(_nextItem()));
45 connect(ui->prevButton, SIGNAL(clicked()), this, SLOT(_prevItem()));
50 MainWindow::~MainWindow()
57 void MainWindow::aboutQt() {
58 QMessageBox::aboutQt(this, "About Qt");
61 void MainWindow::about() {
62 QMessageBox::about(this, "About SomePlayer", "Alternate music player for Maemo 5 "
63 "written in C++ with Qt4\n\n"
64 "Author: Nikolay Tischenko aka \"somebody\" <niktischenko@gmail.com>");
67 void MainWindow::player() {
68 ui->stackedWidget->setCurrentIndex(0);
69 _player_form->reload();
70 setWindowTitle("SomePlayer");
73 void MainWindow::library() {
74 ui->menuBar->setEnabled(true);
75 ui->stackedWidget->setCurrentIndex(1);
77 setWindowTitle("SomePlayer Library");
80 void MainWindow::_add_directory() {
81 QString directory = QFileDialog::getExistingDirectory (this, "Select directory", "/home/user/MyDocs", QFileDialog::ShowDirsOnly );
82 if (!directory.isEmpty()) {
83 showBusyWidget("<H1>Scanning... Please wait</H1>");
84 _library->addDirectory(directory);
88 void MainWindow::_save_playlist() {
89 QString name = QInputDialog::getText(this, "Playlist name", "Name:");
90 Playlist playlist = _library->getCurrentPlaylist();
91 playlist.setName(name);
92 _library->savePlaylist(playlist);
95 void MainWindow::_clear_current_playlist() {
96 Playlist playlist = _library->getCurrentPlaylist();
98 _library->saveCurrentPlaylist(playlist);
99 _player_form->reload();
102 void MainWindow::showBusyWidget(QString caption) {
103 _busy_widget->setText(caption);
104 ui->menuBar->setEnabled(false);
106 ui->stackedWidget->setCurrentIndex(2);
109 void MainWindow::_toggle_search_line() {
110 if (ui->searchLine->isVisible()) {
111 ui->searchLine->setText("");
112 ui->searchLine->hide();
113 ui->nextButton->hide();
114 ui->prevButton->hide();
117 ui->searchLine->show();
118 ui->nextButton->show();
119 ui->prevButton->show();
123 void MainWindow::showSearchPanel() {
124 ui->searchButton->show();
127 void MainWindow::hideSearchPanel() {
128 ui->searchLine->setText("");
129 ui->searchLine->hide();
130 ui->nextButton->hide();
131 ui->prevButton->hide();
132 ui->searchButton->hide();
136 void MainWindow::_search(QString pattern) {
137 if (ui->stackedWidget->currentIndex() == 0) { // player
138 _player_form->search(pattern);
142 void MainWindow::_nextItem() {
143 if (ui->stackedWidget->currentIndex() == 0) { // player
144 _player_form->nextItem();
148 void MainWindow::_prevItem() {
149 if (ui->stackedWidget->currentIndex() == 0) { // player
150 _player_form->prevItem();
154 void MainWindow::_cancelSearch() {
155 if (ui->stackedWidget->currentIndex() == 0) { // player
156 _player_form->cancelSearch();