#include <QInputDialog>
#include <QFile>
#include <QDesktopWidget>
+#include <QTranslator>
#include "player/player.h"
ui(new Ui::MainWindow)
{
Config config;
- _icons_theme = config.getValue("ui/iconstheme").toString();
_library = new Library(config.applicationDir(), config.applicationDir());
ui->setupUi(this);
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);
+ setAttribute(Qt::WA_Maemo5StackedWindow);
+ _player_form = new PlayerForm(_library, this);
+ ui->centralWidget->layout()->addWidget(_player_form);
+ _library_form = new LibraryForm(_library, this);
+ _directory_form = new DirectoryView(this);
+ _directory_form->hide();
_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);
- 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");
- 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");
+ _manage_library_form = new ManageLibraryForm(_library, this);
connect(_player_form, SIGNAL(library()), this, SLOT(library()));
- 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_form, SIGNAL(refreshPlayer()), this, SLOT(player()));
+ connect(ui->actionManageLibrary, SIGNAL(triggered()), this, SLOT(_manage_library()));
+ connect(ui->actionSavePlaylist, SIGNAL(triggered()), this, SLOT(_save_playlist()));
+ connect(_player_form, SIGNAL(clearPlaylist()), this, SLOT(_clear_current_playlist()));
+ connect(ui->actionSetTimer, SIGNAL(triggered()), this, SLOT(_set_timer()));
+ connect(ui->actionEqualizer, SIGNAL(triggered()), this, SLOT(_equalizer()));
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()));
+ connect(_player_form, SIGNAL(refreshLibrary()), _library_form, SLOT(refresh()));
+ connect(_manage_library_form, SIGNAL(refreshLibrary()), _library_form, SLOT(refresh()));
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()));
- updateIcons();
+ connect(_player_form, SIGNAL(fullscreen(bool)), this, SLOT(_fullscreen(bool)));
+ connect(_library_form, SIGNAL(addAndPlay(Track)), _player_form, SLOT(play(Track)));
+ connect(_directory_form, SIGNAL(addAndPlay(Track)), _player_form, SLOT(play(Track)));
+ connect(_player_form, SIGNAL(dirView()), _directory_form, SLOT(show()));
+ connect(_directory_form, SIGNAL(addTracks(QList<Track>)), this, SLOT(_add_tracks(QList<Track>)));
+ _player_form->reload(true);
+ QString mode = config.getValue("ui/orientation").toString();
+ if (mode == "landscape") {
+ setAttribute(Qt::WA_Maemo5LandscapeOrientation);
+ _player_form->landscapeMode();
+ _library_form->landscapeMode();
+ _equalizer_dialog->landscapeMode();
+ _directory_form->lanscapeMode();
+ } else if (mode == "portrait") {
+ setAttribute(Qt::WA_Maemo5PortraitOrientation);
+ _player_form->portraitMode();
+ _library_form->portraitMode();
+ _equalizer_dialog->portraitMode();
+ _directory_form->portraitMode();
+ } else if (mode == "auto") { // initialization in landscape
+ _player_form->landscapeMode();
+ _library_form->landscapeMode();
+ _equalizer_dialog->landscapeMode();
+ _directory_form->lanscapeMode();
+ setAttribute(Qt::WA_Maemo5AutoOrientation);
+ }
_library_form->updateIcons();
_player_form->updateIcons();
- hideSearchPanel();
- _player_form->reload(true);
- library();
+ _manage_library_form->updateIcons();
+ _directory_form->updateIcons();
+ _player_form->checkGradient();
+ _library_form->checkGradient();
+ _directory_form->updateGradient();
+ setWindowTitle("SomePlayer");
}
MainWindow::~MainWindow()
"Author: Nikolay Tischenko aka \"somebody\" <niktischenko@gmail.com>");
}
-void MainWindow::player(bool reread) {
- Config config;
- setAttribute(Qt::WA_Maemo5AutoOrientation, config.getValue("ui/portraitmode").toString() != "disabled");
- ui->stackedWidget->setCurrentIndex(0);
- _player_form->reload(reread);
- setWindowTitle("SomePlayer");
+void MainWindow::player() {
+ _player_form->reload(true);
+ _orientation_changed(); // workaround
}
void MainWindow::library() {
- setAttribute(Qt::WA_Maemo5AutoOrientation, false);
ui->menuBar->setEnabled(true);
- ui->stackedWidget->setCurrentIndex(1);
- showSearchPanel();
- setWindowTitle("SomePlayer Library");
+ _library_form->show();
+ _orientation_changed(); // workaround
+ _manage_library_form->hide();
}
-void MainWindow::_add_directory() {
- QString directory = QFileDialog::getExistingDirectory (this, "Select directory", "/home/user/MyDocs", QFileDialog::ShowDirsOnly );
- if (!directory.isEmpty()) {
- showBusyWidget("<H1>Scanning... Please wait</H1>");
- _library->addDirectory(directory);
- }
+void MainWindow::_manage_library() {
+ _manage_library_form->refresh();
+ _manage_library_form->show();
}
void MainWindow::_save_playlist() {
QList<QString> playlists = _library->getPlaylistsNames();
playlists.removeOne(_CURRENT_PLAYLIST_SUBST_);
- SavePlaylistDialog dialog(this);
+ Playlist cur = _library->getCurrentPlaylist();
+ // construct playlist name if possible
+ QString suggest_name;
+ QList<Track> tracks = cur.tracks();
+ QString artist = tracks.at(0).metadata().artist(), album = tracks.at(0).metadata().album();
+ foreach (Track t, tracks) {
+ if (t.metadata().album() != album)
+ album = "";
+ if (t.metadata().artist() != artist)
+ artist = "";
+ }
+ if (album.isEmpty() && artist.isEmpty()) {
+ suggest_name = "New playlist";
+ } else if (album.isEmpty()) {
+ suggest_name = artist;
+ } else {
+ suggest_name = QString("%1 - %2").arg(artist).arg(album);
+ }
+
+ // constructed
+ SavePlaylistDialog dialog(suggest_name, this);
dialog.setPlaylistNames(playlists);
if (dialog.exec() == QDialog::Accepted) {
QString name = dialog.selectedName();
}
}
if (append) {
- Playlist cur = _library->getCurrentPlaylist();
Playlist target = _library->getPlaylist(name);
QList<Track> tracks = cur.tracks();
foreach (Track track, tracks) {
}
_library->savePlaylist(target);
} else {
- Playlist playlist = _library->getCurrentPlaylist();
- playlist.setName(name);
- _library->savePlaylist(playlist);
+ cur.setName(name);
+ _library->savePlaylist(cur);
}
}
}
_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();
- ui->searchLine->setFocus(Qt::MouseFocusReason);
- }
-}
-
-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);
- } else if (ui->stackedWidget->currentIndex() == 1) { // library
- _library_form->search(pattern);
- }
-}
-
-void MainWindow::_nextItem() {
- if (ui->stackedWidget->currentIndex() == 0) { // player
- _player_form->nextItem();
- } else if (ui->stackedWidget->currentIndex() == 1) { // library
- _library_form->nextItem();
- }
-}
-
-void MainWindow::_prevItem() {
- if (ui->stackedWidget->currentIndex() == 0) { // player
- _player_form->prevItem();
- } else if (ui->stackedWidget->currentIndex() == 1) { // library
- _library_form->prevItem();
- }
-}
-
-void MainWindow::_cancelSearch() {
- if (ui->stackedWidget->currentIndex() == 0) { // player
- _player_form->cancelSearch();
- } else if (ui->stackedWidget->currentIndex() == 1) { // library
- _library_form->cancelSearch();
- }
-}
-
-void MainWindow::_toggle_full_screen() {
- if (isFullScreen()) {
- ui->fscreenButton->setIcon(QIcon(":/icons/"+_icons_theme+"/fullscreen.png"));
- showNormal();
- } else {
- ui->fscreenButton->setIcon(QIcon(":/icons/"+_icons_theme+"/window.png"));
- showFullScreen();
- }
-}
-
-void MainWindow::_add_files() {
- QStringList files = QFileDialog::getOpenFileNames(this, "Add file");
- if (!files.isEmpty()) _player_form->addFiles(files);
-}
-
void MainWindow::_set_timer() {
TimerDialog dialog(this);
dialog.init();
if (_timer->isActive()) {
dialog.showDisable();
- int msec = _timer->interval();
+ int msec = _timeout_interval;
int h = msec/3600000;
int m = msec/60000 - h * 60;
int s = msec/1000 - h * 3600 - m * 60;
if (!dialog.timerDisabled()) {
int h, m, s;
dialog.getTime(&h, &m, &s);
- _timer->setInterval(h*3600000+m*60000+s*1000);
+ _timeout_interval = h*3600000+m*60000+s*1000;
+ _timer->setInterval(1000);
+ _timer->setSingleShot(false);
_timer->start();
} else if (_timer->isActive()) {
_timer->stop();
+ _player_form->hideCountdown();
}
}
}
void MainWindow::_timeout() {
- _player_form->stop();
- _timer->stop();
+ _timeout_interval -= 1000;
+ if (_timeout_interval <= 0) {
+ _player_form->stop();
+ _player_form->hideCountdown();
+ _timer->stop();
+ } else {
+ int h = _timeout_interval / 3600000;
+ int m = (_timeout_interval / 60000) - 60*h;
+ int s = (_timeout_interval / 1000) - 3600*h - 60*m;
+ QString hp = h < 10 ? QString("0%1").arg(h) : QString("%1").arg(h);
+ QString mp = m < 10 ? QString("0%1").arg(m) : QString("%1").arg(m);
+ QString sp = s < 10 ? QString("0%1").arg(s) : QString("%1").arg(s);
+ _player_form->showCountdown(hp+":"+mp+":"+sp);
+ }
}
void MainWindow::_equalizer() {
void MainWindow::settings() {
SettingsDialog dialog;
dialog.exec();
- updateIcons();
Config config;
- _player_form->updateIcons();
- _library_form->updateIcons();
_library_form->refresh();
- if (ui->stackedWidget->currentIndex() == 0) { // player view
- setAttribute(Qt::WA_Maemo5AutoOrientation, config.getValue("ui/portraitmode").toString() != "disabled");
+ 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::updateIcons() {
- Config config;
- _icons_theme = config.getValue("ui/iconstheme").toString();
- ui->fscreenButton->setIcon(QIcon(":/icons/"+_icons_theme+"/fullscreen.png"));
- ui->prevButton->setIcon(QIcon(":/icons/"+_icons_theme+"/back.png"));
- ui->nextButton->setIcon(QIcon(":/icons/"+_icons_theme+"/forward.png"));
- ui->searchButton->setIcon(QIcon(":/icons/"+_icons_theme+"/search.png"));
-
+ _player_form->updateIcons();
+ _library_form->updateIcons();
+ _manage_library_form->updateIcons();
+ _player_form->checkGradient();
+ _library_form->checkGradient();
+ _directory_form->updateIcons();
+ _directory_form->updateGradient();
+ QTranslator *translator = new QTranslator(this);
+ translator->load(QString("/opt/someplayer/someplayer_%1").arg(config.getValue("ui/language").toString()));
+ QApplication::installTranslator(translator);
}
void MainWindow::_orientation_changed() {
QRect screenGeometry = QApplication::desktop()->screenGeometry();
if (screenGeometry.width() > screenGeometry.height()) {
_player_form->landscapeMode();
- ui->toolsWidget->setVisible(true);
+ _library_form->landscapeMode();
+ _equalizer_dialog->landscapeMode();
+ _directory_form->lanscapeMode();
} else {
_player_form->portraitMode();
- ui->toolsWidget->setVisible(false);
+ _library_form->portraitMode();
+ _equalizer_dialog->portraitMode();
+ _directory_form->portraitMode();
}
}
+
+void MainWindow::_fullscreen(bool f) {
+ if (f) showFullScreen();
+ else showNormal();
+}
+
+void MainWindow::_add_tracks(QList<Track> tracks) {
+ Playlist cur = _library->getCurrentPlaylist();
+ foreach (Track track, tracks) {
+ cur.addTrack(track);
+ }
+ _library->saveCurrentPlaylist(cur);
+ _player_form->reload(true);
+}