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;
32 using namespace SomePlayer::Storage;
34 MainWindow::MainWindow(QWidget *parent) :
36 ui(new Ui::MainWindow)
39 _library = new Library(config.applicationDir(), config.applicationDir());
41 connect(ui->actionAbout_Qt, SIGNAL(triggered()), this, SLOT(aboutQt()));
42 connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
44 _player_form = new PlayerForm(_library, ui->stackedWidget);
45 _library_form = new LibraryForm(_library, ui->stackedWidget);
46 _busy_widget = new BusyWidget(ui->stackedWidget);
47 ui->stackedWidget->insertWidget(0, _player_form);
48 ui->stackedWidget->insertWidget(1, _library_form);
49 ui->stackedWidget->insertWidget(2, _busy_widget);
50 QAction *add_directory = ui->menuLibrary->addAction("Add directory");
51 QAction *save_playlist = ui->menuLibrary->addAction("Save playlist");
52 QAction *clear_playlist = ui->menuLibrary->addAction("Clear current playlist");
53 QAction *add_files = ui->menuLibrary->addAction("Add file to current playlist");
54 connect(_player_form, SIGNAL(library()), this, SLOT(library()));
55 connect(_library_form, SIGNAL(player()), this, SLOT(player()));
56 connect(add_directory, SIGNAL(triggered()), this, SLOT(_add_directory()));
57 connect(save_playlist, SIGNAL(triggered()), this, SLOT(_save_playlist()));
58 connect(clear_playlist, SIGNAL(triggered()), this, SLOT(_clear_current_playlist()));
59 connect(add_files, SIGNAL(triggered()), this, SLOT(_add_files()));
60 connect(_library, SIGNAL(done()), this, SLOT(library()));
61 connect(_library_form, SIGNAL(done()), this, SLOT(library()));
62 connect(_library_form, SIGNAL(busy(QString)), this, SLOT(showBusyWidget(QString)));
63 connect(ui->searchButton, SIGNAL(clicked()), this, SLOT(_toggle_search_line()));
64 connect(_player_form, SIGNAL(showSearchPanel()), this, SLOT(showSearchPanel()));
65 connect(_player_form, SIGNAL(hideSearchPanel()), this, SLOT(hideSearchPanel()));
66 connect(ui->searchLine, SIGNAL(textChanged(QString)), this, SLOT(_search(QString)));
67 connect(ui->nextButton, SIGNAL(clicked()), this, SLOT(_nextItem()));
68 connect(ui->prevButton, SIGNAL(clicked()), this, SLOT(_prevItem()));
69 connect(ui->fscreenButton, SIGNAL(clicked()), this, SLOT(_toggle_full_screen()));
74 MainWindow::~MainWindow()
81 void MainWindow::aboutQt() {
82 QMessageBox::aboutQt(this, "About Qt");
85 void MainWindow::about() {
86 QMessageBox::about(this, "About SomePlayer", "Alternate music player for Maemo 5 "
87 "written in C++ with Qt4\n\n"
88 "Author: Nikolay Tischenko aka \"somebody\" <niktischenko@gmail.com>");
91 void MainWindow::player() {
92 ui->stackedWidget->setCurrentIndex(0);
93 _player_form->reload();
94 setWindowTitle("SomePlayer");
97 void MainWindow::library() {
98 ui->menuBar->setEnabled(true);
99 ui->stackedWidget->setCurrentIndex(1);
101 setWindowTitle("SomePlayer Library");
104 void MainWindow::_add_directory() {
105 QString directory = QFileDialog::getExistingDirectory (this, "Select directory", "/home/user/MyDocs", QFileDialog::ShowDirsOnly );
106 if (!directory.isEmpty()) {
107 showBusyWidget("<H1>Scanning... Please wait</H1>");
108 _library->addDirectory(directory);
112 void MainWindow::_save_playlist() {
113 QString name = QInputDialog::getText(this, "Playlist name", "Name:");
114 Playlist playlist = _library->getCurrentPlaylist();
115 playlist.setName(name);
116 _library->savePlaylist(playlist);
119 void MainWindow::_clear_current_playlist() {
120 Playlist playlist = _library->getCurrentPlaylist();
122 _library->saveCurrentPlaylist(playlist);
123 _player_form->reload();
126 void MainWindow::showBusyWidget(QString caption) {
127 _busy_widget->setText(caption);
128 ui->menuBar->setEnabled(false);
130 ui->stackedWidget->setCurrentIndex(2);
133 void MainWindow::_toggle_search_line() {
134 if (ui->searchLine->isVisible()) {
135 ui->searchLine->setText("");
136 ui->searchLine->hide();
137 ui->nextButton->hide();
138 ui->prevButton->hide();
141 ui->searchLine->show();
142 ui->nextButton->show();
143 ui->prevButton->show();
147 void MainWindow::showSearchPanel() {
148 ui->searchButton->show();
149 ui->searchLine->setFocus();
152 void MainWindow::hideSearchPanel() {
153 ui->searchLine->setText("");
154 ui->searchLine->hide();
155 ui->nextButton->hide();
156 ui->prevButton->hide();
157 ui->searchButton->hide();
161 void MainWindow::_search(QString pattern) {
162 if (ui->stackedWidget->currentIndex() == 0) { // player
163 _player_form->search(pattern);
164 } else if (ui->stackedWidget->currentIndex() == 1) { // library
165 _library_form->search(pattern);
169 void MainWindow::_nextItem() {
170 if (ui->stackedWidget->currentIndex() == 0) { // player
171 _player_form->nextItem();
172 } else if (ui->stackedWidget->currentIndex() == 1) { // library
173 _library_form->nextItem();
177 void MainWindow::_prevItem() {
178 if (ui->stackedWidget->currentIndex() == 0) { // player
179 _player_form->prevItem();
180 } else if (ui->stackedWidget->currentIndex() == 1) { // library
181 _library_form->prevItem();
185 void MainWindow::_cancelSearch() {
186 if (ui->stackedWidget->currentIndex() == 0) { // player
187 _player_form->cancelSearch();
188 } else if (ui->stackedWidget->currentIndex() == 1) { // library
189 _library_form->cancelSearch();
193 void MainWindow::_toggle_full_screen() {
194 if (isFullScreen()) {
195 ui->fscreenButton->setIcon(QIcon(":/icons/fullscreen.png"));
198 ui->fscreenButton->setIcon(QIcon(":/icons/window.png"));
203 void MainWindow::_add_files() {
204 QStringList files = QFileDialog::getOpenFileNames(this, "Add file");
205 if (!files.isEmpty()) _player_form->addFiles(files);