X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fmainwindow.cpp;h=f962a56c4dafcbfd7f32e80d8138c2acb2c0f33c;hb=refs%2Ftags%2F1.3.5;hp=a7d59d07e06dbd2be3d104d9e85a11fc1f5ce329;hpb=40103460aba82191a72f1e6d852b70f96e6fbdae;p=someplayer diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a7d59d0..f962a56 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -23,10 +23,15 @@ #include #include #include +#include #include "player/player.h" #include "library.h" +#include "timerdialog.h" +#include "equalizerdialog.h" +#include "saveplaylistdialog.h" +#include "settingsdialog.h" using namespace SomePlayer::DataObjects; using namespace SomePlayer::Storage; @@ -38,12 +43,14 @@ MainWindow::MainWindow(QWidget *parent) : Config config; _library = new Library(config.applicationDir(), config.applicationDir()); ui->setupUi(this); - connect(ui->actionAbout_Qt, SIGNAL(triggered()), this, SLOT(aboutQt())); connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about())); + connect(ui->actionSettings, SIGNAL(triggered()), this, SLOT(settings())); setAnimated(true); _player_form = new PlayerForm(_library, ui->stackedWidget); _library_form = new LibraryForm(_library, ui->stackedWidget); _busy_widget = new BusyWidget(ui->stackedWidget); + _timer = new QTimer(this); + _equalizer_dialog = new EqualizerDialog(this); ui->stackedWidget->insertWidget(0, _player_form); ui->stackedWidget->insertWidget(1, _library_form); ui->stackedWidget->insertWidget(2, _busy_widget); @@ -51,24 +58,48 @@ MainWindow::MainWindow(QWidget *parent) : QAction *save_playlist = ui->menuLibrary->addAction("Save playlist"); QAction *clear_playlist = ui->menuLibrary->addAction("Clear current playlist"); QAction *add_files = ui->menuLibrary->addAction("Add file to current playlist"); + QAction *set_timer = ui->menuBar->addAction("Set timer"); + QAction *equalizer = ui->menuBar->addAction("Equalizer"); connect(_player_form, SIGNAL(library()), this, SLOT(library())); - connect(_library_form, SIGNAL(player()), this, SLOT(player())); + connect(_library_form, SIGNAL(player(bool)), this, SLOT(player(bool))); 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(add_files, SIGNAL(triggered()), this, SLOT(_add_files())); + connect(set_timer, SIGNAL(triggered()), this, SLOT(_set_timer())); + connect(equalizer, SIGNAL(triggered()), this, SLOT(_equalizer())); connect(_library, SIGNAL(done()), this, SLOT(library())); + connect(_library, SIGNAL(done()), _library_form, SLOT(refresh())); + connect(_library, SIGNAL(addingTracks(int)), _busy_widget, SLOT(setMax(int))); + connect(_library, SIGNAL(trackAdded()), _busy_widget, SLOT(tick())); 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())); - connect(ui->fscreenButton, SIGNAL(clicked()), this, SLOT(_toggle_full_screen())); - hideSearchPanel(); + connect(_timer, SIGNAL(timeout()), this, SLOT(_timeout())); + connect(_equalizer_dialog, SIGNAL(valueChanged(int,int)), this, SLOT(_equalizer_value_changed(int, int))); + connect(_equalizer_dialog, SIGNAL(equalizerEnabled()), _player_form, SLOT(enableEqualizer())); + connect(_equalizer_dialog, SIGNAL(equalizerDisabled()), _player_form, SLOT(disableEqualizer())); + connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(_orientation_changed())); + connect(_player_form, SIGNAL(fullscreen(bool)), this, SLOT(_fullscreen(bool))); + connect(_library_form, SIGNAL(fullscreen(bool)), this, SLOT(_fullscreen(bool))); + _player_form->reload(true); library(); + QString mode = config.getValue("ui/orientation").toString(); + if (mode == "landscape") { + setAttribute(Qt::WA_Maemo5LandscapeOrientation); + _player_form->landscapeMode(); + _library_form->landscapeMode(); + _equalizer_dialog->landscapeMode(); + } else if (mode == "portrait") { + setAttribute(Qt::WA_Maemo5PortraitOrientation); + _player_form->portraitMode(); + _library_form->portraitMode(); + _equalizer_dialog->portraitMode(); + } else if (mode == "auto") { // initialization in landscape + _player_form->landscapeMode(); + _library_form->landscapeMode(); + _equalizer_dialog->landscapeMode(); + setAttribute(Qt::WA_Maemo5AutoOrientation); + } } MainWindow::~MainWindow() @@ -78,27 +109,24 @@ MainWindow::~MainWindow() delete ui; } -void MainWindow::aboutQt() { - QMessageBox::aboutQt(this, "About Qt"); -} - void MainWindow::about() { - QMessageBox::about(this, "About SomePlayer", "Alternate music player for Maemo 5 " + QMessageBox::about(this, QString("About SomePlayer v")+_SOMEPLAYER_VERSION_, "Alternate music player for Maemo 5 " "written in C++ with Qt4\n\n" "Author: Nikolay Tischenko aka \"somebody\" "); } -void MainWindow::player() { +void MainWindow::player(bool reread) { ui->stackedWidget->setCurrentIndex(0); - _player_form->reload(); + _player_form->reload(reread); setWindowTitle("SomePlayer"); + _orientation_changed(); // workaround } void MainWindow::library() { ui->menuBar->setEnabled(true); ui->stackedWidget->setCurrentIndex(1); - showSearchPanel(); setWindowTitle("SomePlayer Library"); + _orientation_changed(); // workaround } void MainWindow::_add_directory() { @@ -110,97 +138,132 @@ void MainWindow::_add_directory() { } void MainWindow::_save_playlist() { - QString name = QInputDialog::getText(this, "Playlist name", "Name:"); - Playlist playlist = _library->getCurrentPlaylist(); - playlist.setName(name); - _library->savePlaylist(playlist); + QList playlists = _library->getPlaylistsNames(); + playlists.removeOne(_CURRENT_PLAYLIST_SUBST_); + SavePlaylistDialog dialog(this); + dialog.setPlaylistNames(playlists); + if (dialog.exec() == QDialog::Accepted) { + QString name = dialog.selectedName(); + bool append = false; + if (playlists.contains(name)) { + if (QMessageBox::question(this, "Append to playlist?", "Playlist with name \""+name+"\" already exists.\n" + "Dow you want to append current playlist to it?", + QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) { + append = true; + } else { + append = false; + } + } + if (append) { + Playlist cur = _library->getCurrentPlaylist(); + Playlist target = _library->getPlaylist(name); + QList tracks = cur.tracks(); + foreach (Track track, tracks) { + target.addTrack(track); + } + _library->savePlaylist(target); + } else { + 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(); + _player_form->reload(true); } void MainWindow::showBusyWidget(QString caption) { _busy_widget->setText(caption); ui->menuBar->setEnabled(false); - hideSearchPanel(); 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(); - ui->searchLine->setFocus(); +void MainWindow::_add_files() { + QStringList files = QFileDialog::getOpenFileNames(this, "Add file"); + if (!files.isEmpty()) _player_form->addFiles(files); } -void MainWindow::hideSearchPanel() { - ui->searchLine->setText(""); - ui->searchLine->hide(); - ui->nextButton->hide(); - ui->prevButton->hide(); - ui->searchButton->hide(); - _cancelSearch(); +void MainWindow::_set_timer() { + TimerDialog dialog(this); + dialog.init(); + if (_timer->isActive()) { + dialog.showDisable(); + int msec = _timer->interval(); + int h = msec/3600000; + int m = msec/60000 - h * 60; + int s = msec/1000 - h * 3600 - m * 60; + dialog.setTime(h, m, s); + } + if (QDialog::Accepted == dialog.exec()) { + if (!dialog.timerDisabled()) { + int h, m, s; + dialog.getTime(&h, &m, &s); + _timer->setInterval(h*3600000+m*60000+s*1000); + _timer->start(); + } else if (_timer->isActive()) { + _timer->stop(); + } + } } -void MainWindow::_search(QString pattern) { - if (ui->stackedWidget->currentIndex() == 0) { // player - _player_form->search(pattern); - } else if (ui->stackedWidget->currentIndex() == 1) { // library - _library_form->search(pattern); - } +void MainWindow::_timeout() { + _player_form->stop(); + _timer->stop(); } -void MainWindow::_nextItem() { - if (ui->stackedWidget->currentIndex() == 0) { // player - _player_form->nextItem(); - } else if (ui->stackedWidget->currentIndex() == 1) { // library - _library_form->nextItem(); +void MainWindow::_equalizer() { + if (_player_form->isEqualizerAvailable()) { + double val = 0; + for (int i = 0; i < 10; i++) { + _player_form->equalizerValue(i, &val); + _equalizer_dialog->setValue(i, (int)(val * 10 + 0.5)); + } + _equalizer_dialog->setEqualizerEnabled(_player_form->isEqualizerEnabled()); + _equalizer_dialog->reloadPresets(); + _equalizer_dialog->exec(); + } else { + QMessageBox::information(this, "Error", "No equalizer support. Please install gstreamer0.10-plugins-good-extra"); } } -void MainWindow::_prevItem() { - if (ui->stackedWidget->currentIndex() == 0) { // player - _player_form->prevItem(); - } else if (ui->stackedWidget->currentIndex() == 1) { // library - _library_form->prevItem(); - } +void MainWindow::_equalizer_value_changed(int band, int val) { + _player_form->setEqualizerValue(band, (val / 10.0)); } -void MainWindow::_cancelSearch() { - if (ui->stackedWidget->currentIndex() == 0) { // player - _player_form->cancelSearch(); - } else if (ui->stackedWidget->currentIndex() == 1) { // library - _library_form->cancelSearch(); +void MainWindow::settings() { + SettingsDialog dialog; + dialog.exec(); + Config config; + _library_form->refresh(); + QString mode = config.getValue("ui/orientation").toString(); + if (mode == "landscape") { + setAttribute(Qt::WA_Maemo5LandscapeOrientation); + } else if (mode == "portrait") { + setAttribute(Qt::WA_Maemo5PortraitOrientation); + } else if (mode == "auto") { + setAttribute(Qt::WA_Maemo5AutoOrientation); } } -void MainWindow::_toggle_full_screen() { - if (isFullScreen()) { - ui->fscreenButton->setIcon(QIcon(":/icons/fullscreen.png")); - showNormal(); +void MainWindow::_orientation_changed() { + QRect screenGeometry = QApplication::desktop()->screenGeometry(); + if (screenGeometry.width() > screenGeometry.height()) { + _player_form->landscapeMode(); + _library_form->landscapeMode(); + _equalizer_dialog->landscapeMode(); } else { - ui->fscreenButton->setIcon(QIcon(":/icons/window.png")); - showFullScreen(); + _player_form->portraitMode(); + _library_form->portraitMode(); + _equalizer_dialog->portraitMode(); } } -void MainWindow::_add_files() { - QStringList files = QFileDialog::getOpenFileNames(this, "Add file"); - if (!files.isEmpty()) _player_form->addFiles(files); +void MainWindow::_fullscreen(bool f) { + if (f) showFullScreen(); + else showNormal(); }