2 * SomePlayer - An alternate music player for Maemo 5
3 * Copyright (C) 2010 Nikolay (somebody) Tischenko <niktischenko@gmail.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "mainwindow.h"
21 #include "ui_mainwindow.h"
22 #include <QFileDialog>
23 #include <QMessageBox>
24 #include <QInputDialog>
27 #include "player/player.h"
31 using namespace SomePlayer::DataObjects;
33 MainWindow::MainWindow(QWidget *parent) :
35 ui(new Ui::MainWindow)
37 _library = new Library(_DATABASE_PATH_, _PLAYLISTS_PATH_);
39 connect(ui->actionAbout_Qt, SIGNAL(triggered()), this, SLOT(aboutQt()));
40 connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
42 _player_form = new PlayerForm(_library, ui->stackedWidget);
43 _library_form = new LibraryForm(_library, ui->stackedWidget);
44 _busy_widget = new BusyWidget(ui->stackedWidget);
45 ui->stackedWidget->insertWidget(0, _player_form);
46 ui->stackedWidget->insertWidget(1, _library_form);
47 ui->stackedWidget->insertWidget(2, _busy_widget);
48 QAction *add_directory = ui->menuLibrary->addAction("Add directory");
49 QAction *save_playlist = ui->menuLibrary->addAction("Save playlist");
50 QAction *clear_playlist = ui->menuLibrary->addAction("Clear current playlist");
51 connect(_player_form, SIGNAL(library()), this, SLOT(library()));
52 connect(_library_form, SIGNAL(player()), this, SLOT(player()));
53 connect(add_directory, SIGNAL(triggered()), this, SLOT(_add_directory()));
54 connect(save_playlist, SIGNAL(triggered()), this, SLOT(_save_playlist()));
55 connect(clear_playlist, SIGNAL(triggered()), this, SLOT(_clear_current_playlist()));
56 connect(_library, SIGNAL(done()), this, SLOT(library()));
57 connect(_library_form, SIGNAL(done()), this, SLOT(library()));
58 connect(_library_form, SIGNAL(busy(QString)), this, SLOT(showBusyWidget(QString)));
59 connect(ui->searchButton, SIGNAL(clicked()), this, SLOT(_toggle_search_line()));
60 connect(_player_form, SIGNAL(showSearchPanel()), this, SLOT(showSearchPanel()));
61 connect(_player_form, SIGNAL(hideSearchPanel()), this, SLOT(hideSearchPanel()));
62 connect(ui->searchLine, SIGNAL(textChanged(QString)), this, SLOT(_search(QString)));
63 connect(ui->nextButton, SIGNAL(clicked()), this, SLOT(_nextItem()));
64 connect(ui->prevButton, SIGNAL(clicked()), this, SLOT(_prevItem()));
65 connect(ui->fscreenButton, SIGNAL(clicked()), this, SLOT(_toggle_full_screen()));
70 MainWindow::~MainWindow()
77 void MainWindow::aboutQt() {
78 QMessageBox::aboutQt(this, "About Qt");
81 void MainWindow::about() {
82 QMessageBox::about(this, "About SomePlayer", "Alternate music player for Maemo 5 "
83 "written in C++ with Qt4\n\n"
84 "Author: Nikolay Tischenko aka \"somebody\" <niktischenko@gmail.com>");
87 void MainWindow::player() {
88 ui->stackedWidget->setCurrentIndex(0);
89 _player_form->reload();
90 setWindowTitle("SomePlayer");
93 void MainWindow::library() {
94 ui->menuBar->setEnabled(true);
95 ui->stackedWidget->setCurrentIndex(1);
97 setWindowTitle("SomePlayer Library");
100 void MainWindow::_add_directory() {
101 QString directory = QFileDialog::getExistingDirectory (this, "Select directory", "/home/user/MyDocs", QFileDialog::ShowDirsOnly );
102 if (!directory.isEmpty()) {
103 showBusyWidget("<H1>Scanning... Please wait</H1>");
104 _library->addDirectory(directory);
108 void MainWindow::_save_playlist() {
109 QString name = QInputDialog::getText(this, "Playlist name", "Name:");
110 Playlist playlist = _library->getCurrentPlaylist();
111 playlist.setName(name);
112 _library->savePlaylist(playlist);
115 void MainWindow::_clear_current_playlist() {
116 Playlist playlist = _library->getCurrentPlaylist();
118 _library->saveCurrentPlaylist(playlist);
119 _player_form->reload();
122 void MainWindow::showBusyWidget(QString caption) {
123 _busy_widget->setText(caption);
124 ui->menuBar->setEnabled(false);
126 ui->stackedWidget->setCurrentIndex(2);
129 void MainWindow::_toggle_search_line() {
130 if (ui->searchLine->isVisible()) {
131 ui->searchLine->setText("");
132 ui->searchLine->hide();
133 ui->nextButton->hide();
134 ui->prevButton->hide();
137 ui->searchLine->show();
138 ui->nextButton->show();
139 ui->prevButton->show();
143 void MainWindow::showSearchPanel() {
144 ui->searchButton->show();
145 ui->searchLine->setFocus();
148 void MainWindow::hideSearchPanel() {
149 ui->searchLine->setText("");
150 ui->searchLine->hide();
151 ui->nextButton->hide();
152 ui->prevButton->hide();
153 ui->searchButton->hide();
157 void MainWindow::_search(QString pattern) {
158 if (ui->stackedWidget->currentIndex() == 0) { // player
159 _player_form->search(pattern);
160 } else if (ui->stackedWidget->currentIndex() == 1) { // library
161 _library_form->search(pattern);
165 void MainWindow::_nextItem() {
166 if (ui->stackedWidget->currentIndex() == 0) { // player
167 _player_form->nextItem();
168 } else if (ui->stackedWidget->currentIndex() == 1) { // library
169 _library_form->nextItem();
173 void MainWindow::_prevItem() {
174 if (ui->stackedWidget->currentIndex() == 0) { // player
175 _player_form->prevItem();
176 } else if (ui->stackedWidget->currentIndex() == 1) { // library
177 _library_form->prevItem();
181 void MainWindow::_cancelSearch() {
182 if (ui->stackedWidget->currentIndex() == 0) { // player
183 _player_form->cancelSearch();
184 } else if (ui->stackedWidget->currentIndex() == 1) { // library
185 _library_form->cancelSearch();
189 void MainWindow::_toggle_full_screen() {
190 if (isFullScreen()) {
191 ui->fscreenButton->setIcon(QIcon(":/icons/fullscreen.png"));
194 ui->fscreenButton->setIcon(QIcon(":/icons/window.png"));