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 connect(_player_form, SIGNAL(library()), this, SLOT(library()));
54 connect(_library_form, SIGNAL(player()), this, SLOT(player()));
55 connect(add_directory, SIGNAL(triggered()), this, SLOT(_add_directory()));
56 connect(save_playlist, SIGNAL(triggered()), this, SLOT(_save_playlist()));
57 connect(clear_playlist, SIGNAL(triggered()), this, SLOT(_clear_current_playlist()));
58 connect(_library, SIGNAL(done()), this, SLOT(library()));
59 connect(_library_form, SIGNAL(done()), this, SLOT(library()));
60 connect(_library_form, SIGNAL(busy(QString)), this, SLOT(showBusyWidget(QString)));
61 connect(ui->searchButton, SIGNAL(clicked()), this, SLOT(_toggle_search_line()));
62 connect(_player_form, SIGNAL(showSearchPanel()), this, SLOT(showSearchPanel()));
63 connect(_player_form, SIGNAL(hideSearchPanel()), this, SLOT(hideSearchPanel()));
64 connect(ui->searchLine, SIGNAL(textChanged(QString)), this, SLOT(_search(QString)));
65 connect(ui->nextButton, SIGNAL(clicked()), this, SLOT(_nextItem()));
66 connect(ui->prevButton, SIGNAL(clicked()), this, SLOT(_prevItem()));
67 connect(ui->fscreenButton, SIGNAL(clicked()), this, SLOT(_toggle_full_screen()));
72 MainWindow::~MainWindow()
79 void MainWindow::aboutQt() {
80 QMessageBox::aboutQt(this, "About Qt");
83 void MainWindow::about() {
84 QMessageBox::about(this, "About SomePlayer", "Alternate music player for Maemo 5 "
85 "written in C++ with Qt4\n\n"
86 "Author: Nikolay Tischenko aka \"somebody\" <niktischenko@gmail.com>");
89 void MainWindow::player() {
90 ui->stackedWidget->setCurrentIndex(0);
91 _player_form->reload();
92 setWindowTitle("SomePlayer");
95 void MainWindow::library() {
96 ui->menuBar->setEnabled(true);
97 ui->stackedWidget->setCurrentIndex(1);
99 setWindowTitle("SomePlayer Library");
102 void MainWindow::_add_directory() {
103 QString directory = QFileDialog::getExistingDirectory (this, "Select directory", "/home/user/MyDocs", QFileDialog::ShowDirsOnly );
104 if (!directory.isEmpty()) {
105 showBusyWidget("<H1>Scanning... Please wait</H1>");
106 _library->addDirectory(directory);
110 void MainWindow::_save_playlist() {
111 QString name = QInputDialog::getText(this, "Playlist name", "Name:");
112 Playlist playlist = _library->getCurrentPlaylist();
113 playlist.setName(name);
114 _library->savePlaylist(playlist);
117 void MainWindow::_clear_current_playlist() {
118 Playlist playlist = _library->getCurrentPlaylist();
120 _library->saveCurrentPlaylist(playlist);
121 _player_form->reload();
124 void MainWindow::showBusyWidget(QString caption) {
125 _busy_widget->setText(caption);
126 ui->menuBar->setEnabled(false);
128 ui->stackedWidget->setCurrentIndex(2);
131 void MainWindow::_toggle_search_line() {
132 if (ui->searchLine->isVisible()) {
133 ui->searchLine->setText("");
134 ui->searchLine->hide();
135 ui->nextButton->hide();
136 ui->prevButton->hide();
139 ui->searchLine->show();
140 ui->nextButton->show();
141 ui->prevButton->show();
145 void MainWindow::showSearchPanel() {
146 ui->searchButton->show();
147 ui->searchLine->setFocus();
150 void MainWindow::hideSearchPanel() {
151 ui->searchLine->setText("");
152 ui->searchLine->hide();
153 ui->nextButton->hide();
154 ui->prevButton->hide();
155 ui->searchButton->hide();
159 void MainWindow::_search(QString pattern) {
160 if (ui->stackedWidget->currentIndex() == 0) { // player
161 _player_form->search(pattern);
162 } else if (ui->stackedWidget->currentIndex() == 1) { // library
163 _library_form->search(pattern);
167 void MainWindow::_nextItem() {
168 if (ui->stackedWidget->currentIndex() == 0) { // player
169 _player_form->nextItem();
170 } else if (ui->stackedWidget->currentIndex() == 1) { // library
171 _library_form->nextItem();
175 void MainWindow::_prevItem() {
176 if (ui->stackedWidget->currentIndex() == 0) { // player
177 _player_form->prevItem();
178 } else if (ui->stackedWidget->currentIndex() == 1) { // library
179 _library_form->prevItem();
183 void MainWindow::_cancelSearch() {
184 if (ui->stackedWidget->currentIndex() == 0) { // player
185 _player_form->cancelSearch();
186 } else if (ui->stackedWidget->currentIndex() == 1) { // library
187 _library_form->cancelSearch();
191 void MainWindow::_toggle_full_screen() {
192 if (isFullScreen()) {
193 ui->fscreenButton->setIcon(QIcon(":/icons/fullscreen.png"));
196 ui->fscreenButton->setIcon(QIcon(":/icons/window.png"));