X-Git-Url: http://git.maemo.org/git/?p=someplayer;a=blobdiff_plain;f=src%2Fmainwindow.cpp;h=61d7a59c94042c0e56b719304437dfd2028c0040;hp=20dc3a9347a752cb86db1c7b42661eb71a79a82c;hb=b0e8612b3fe8ff513f9c63637c4a546a4a0cea58;hpb=de6604ba0154d3233889a330b8f229c952614021 diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 20dc3a9..61d7a59 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2,46 +2,58 @@ #include "ui_mainwindow.h" #include #include +#include #include -#include "player.h" +#include "player/player.h" #include "library.h" +using namespace SomePlayer::DataObjects; + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { + _library = new Library(_DATABASE_PATH_, _PLAYLISTS_PATH_); ui->setupUi(this); - connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(openMedia())); connect(ui->actionAbout_Qt, SIGNAL(triggered()), this, SLOT(aboutQt())); connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about())); - connect(ui->actionPlayer, SIGNAL(triggered()), this, SLOT(player())); - connect(ui->actionLibrary, SIGNAL(triggered()), this, SLOT(library())); setAnimated(true); - _playerForm = new PlayerForm(); - _libraryForm = new LibraryForm(); - ui->stackedWidget->insertWidget(0, _playerForm); - ui->stackedWidget->insertWidget(1, _libraryForm); - _playerForm->setAttribute(Qt::WA_Maemo5StackedWindow); - _libraryForm->setAttribute(Qt::WA_Maemo5StackedWindow); - connect(_playerForm, SIGNAL(library()), this, SLOT(library())); + _player_form = new PlayerForm(_library, ui->stackedWidget); + _library_form = new LibraryForm(_library, ui->stackedWidget); + _busy_widget = new BusyWidget(ui->stackedWidget); + ui->stackedWidget->insertWidget(0, _player_form); + ui->stackedWidget->insertWidget(1, _library_form); + ui->stackedWidget->insertWidget(2, _busy_widget); + QAction *add_directory = ui->menuLibrary->addAction("Add directory"); + QAction *save_playlist = ui->menuLibrary->addAction("Save playlist"); + QAction *clear_playlist = ui->menuLibrary->addAction("Clear current playlist"); + connect(_player_form, SIGNAL(library()), this, SLOT(library())); + connect(_library_form, SIGNAL(player()), this, SLOT(player())); + connect(add_directory, SIGNAL(triggered()), this, SLOT(_add_directory())); + connect(save_playlist, SIGNAL(triggered()), this, SLOT(_save_playlist())); + connect(clear_playlist, SIGNAL(triggered()), this, SLOT(_clear_current_playlist())); + connect(_library, SIGNAL(done()), this, SLOT(library())); + connect(_library_form, SIGNAL(done()), this, SLOT(library())); + connect(_library_form, SIGNAL(busy(QString)), this, SLOT(showBusyWidget(QString))); + connect(ui->searchButton, SIGNAL(clicked()), this, SLOT(_toggle_search_line())); + connect(_player_form, SIGNAL(showSearchPanel()), this, SLOT(showSearchPanel())); + connect(_player_form, SIGNAL(hideSearchPanel()), this, SLOT(hideSearchPanel())); + connect(ui->searchLine, SIGNAL(textChanged(QString)), this, SLOT(_search(QString))); + connect(ui->nextButton, SIGNAL(clicked()), this, SLOT(_nextItem())); + connect(ui->prevButton, SIGNAL(clicked()), this, SLOT(_prevItem())); + hideSearchPanel(); library(); } MainWindow::~MainWindow() { - delete _playerForm; - delete _libraryForm; + delete _player_form; + delete _library_form; delete ui; } -void MainWindow::openMedia() -{ -// SomePlayer::DataObjects::Library *l = new SomePlayer::DataObjects::Library("/tmp", "/tmp"); -// l->addDirectory("/mnt/music/Three Days Grace"); -} - void MainWindow::aboutQt() { QMessageBox::aboutQt(this, "About Qt"); } @@ -54,10 +66,92 @@ void MainWindow::about() { void MainWindow::player() { ui->stackedWidget->setCurrentIndex(0); + _player_form->reload(); setWindowTitle("SomePlayer"); } void MainWindow::library() { + ui->menuBar->setEnabled(true); ui->stackedWidget->setCurrentIndex(1); + showSearchPanel(); setWindowTitle("SomePlayer Library"); } + +void MainWindow::_add_directory() { + QString directory = QFileDialog::getExistingDirectory (this, "Select directory", "/home/user/MyDocs", QFileDialog::ShowDirsOnly ); + if (!directory.isEmpty()) { + showBusyWidget("

Scanning... Please wait

"); + _library->addDirectory(directory); + } +} + +void MainWindow::_save_playlist() { + QString name = QInputDialog::getText(this, "Playlist name", "Name:"); + Playlist playlist = _library->getCurrentPlaylist(); + playlist.setName(name); + _library->savePlaylist(playlist); +} + +void MainWindow::_clear_current_playlist() { + Playlist playlist = _library->getCurrentPlaylist(); + playlist.clear(); + _library->saveCurrentPlaylist(playlist); + _player_form->reload(); +} + +void MainWindow::showBusyWidget(QString caption) { + _busy_widget->setText(caption); + ui->menuBar->setEnabled(false); + ui->stackedWidget->setCurrentIndex(2); +} + +void MainWindow::_toggle_search_line() { + if (ui->searchLine->isVisible()) { + ui->searchLine->setText(""); + ui->searchLine->hide(); + ui->nextButton->hide(); + ui->prevButton->hide(); + _cancelSearch(); + } else { + ui->searchLine->show(); + ui->nextButton->show(); + ui->prevButton->show(); + } +} + +void MainWindow::showSearchPanel() { + ui->searchButton->show(); +} + +void MainWindow::hideSearchPanel() { + ui->searchLine->setText(""); + ui->searchLine->hide(); + ui->nextButton->hide(); + ui->prevButton->hide(); + ui->searchButton->hide(); + _cancelSearch(); +} + +void MainWindow::_search(QString pattern) { + if (ui->stackedWidget->currentIndex() == 0) { // player + _player_form->search(pattern); + } +} + +void MainWindow::_nextItem() { + if (ui->stackedWidget->currentIndex() == 0) { // player + _player_form->nextItem(); + } +} + +void MainWindow::_prevItem() { + if (ui->stackedWidget->currentIndex() == 0) { // player + _player_form->prevItem(); + } +} + +void MainWindow::_cancelSearch() { + if (ui->stackedWidget->currentIndex() == 0) { // player + _player_form->cancelSearch(); + } +}