X-Git-Url: http://git.maemo.org/git/?p=someplayer;a=blobdiff_plain;f=src%2Fmainwindow.cpp;h=61d7a59c94042c0e56b719304437dfd2028c0040;hp=2c576f9bdb800046b0150677fb2d06cff1c3955a;hb=b0e8612b3fe8ff513f9c63637c4a546a4a0cea58;hpb=7b2a40e92ca217556f2ea5dbb95248b2800909a1 diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2c576f9..61d7a59 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2,21 +2,156 @@ #include "ui_mainwindow.h" #include #include +#include #include +#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())); + setAnimated(true); + _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 _player_form; + delete _library_form; delete ui; } -void MainWindow::openMedia() -{ +void MainWindow::aboutQt() { + QMessageBox::aboutQt(this, "About Qt"); +} + +void MainWindow::about() { + QMessageBox::about(this, "About SomePlayer", "Alternate music player for Maemo 5 " + "written in C++ with Qt4\n\n" + "Author: Nikolay Tischenko aka \"somebody\" "); +} + +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(); + } }