1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
5 #include <QInputDialog>
8 #include "player/player.h"
12 using namespace SomePlayer::DataObjects;
14 MainWindow::MainWindow(QWidget *parent) :
16 ui(new Ui::MainWindow)
18 _library = new Library(_DATABASE_PATH_, _PLAYLISTS_PATH_);
20 connect(ui->actionAbout_Qt, SIGNAL(triggered()), this, SLOT(aboutQt()));
21 connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
23 _player_form = new PlayerForm(_library, ui->stackedWidget);
24 _library_form = new LibraryForm(_library, ui->stackedWidget);
25 _busy_widget = new BusyWidget(ui->stackedWidget);
26 ui->stackedWidget->insertWidget(0, _player_form);
27 ui->stackedWidget->insertWidget(1, _library_form);
28 ui->stackedWidget->insertWidget(2, _busy_widget);
29 QAction *add_directory = ui->menuLibrary->addAction("Add directory");
30 QAction *save_playlist = ui->menuLibrary->addAction("Save playlist");
31 QAction *clear_playlist = ui->menuLibrary->addAction("Clear current playlist");
32 connect(_player_form, SIGNAL(library()), this, SLOT(library()));
33 connect(_library_form, SIGNAL(player()), this, SLOT(player()));
34 connect(add_directory, SIGNAL(triggered()), this, SLOT(_add_directory()));
35 connect(save_playlist, SIGNAL(triggered()), this, SLOT(_save_playlist()));
36 connect(clear_playlist, SIGNAL(triggered()), this, SLOT(_clear_current_playlist()));
37 connect(_library, SIGNAL(done()), this, SLOT(library()));
38 connect(_library_form, SIGNAL(done()), this, SLOT(library()));
39 connect(_library_form, SIGNAL(busy(QString)), this, SLOT(showBusyWidget(QString)));
40 connect(ui->searchButton, SIGNAL(clicked()), this, SLOT(_toggle_search_line()));
41 connect(_player_form, SIGNAL(showSearchPanel()), this, SLOT(showSearchPanel()));
42 connect(_player_form, SIGNAL(hideSearchPanel()), this, SLOT(hideSearchPanel()));
43 connect(ui->searchLine, SIGNAL(textChanged(QString)), this, SLOT(_search(QString)));
44 connect(ui->nextButton, SIGNAL(clicked()), this, SLOT(_nextItem()));
45 connect(ui->prevButton, SIGNAL(clicked()), this, SLOT(_prevItem()));
46 connect(ui->fscreenButton, SIGNAL(clicked()), this, SLOT(_toggle_full_screen()));
51 MainWindow::~MainWindow()
58 void MainWindow::aboutQt() {
59 QMessageBox::aboutQt(this, "About Qt");
62 void MainWindow::about() {
63 QMessageBox::about(this, "About SomePlayer", "Alternate music player for Maemo 5 "
64 "written in C++ with Qt4\n\n"
65 "Author: Nikolay Tischenko aka \"somebody\" <niktischenko@gmail.com>");
68 void MainWindow::player() {
69 ui->stackedWidget->setCurrentIndex(0);
70 _player_form->reload();
71 setWindowTitle("SomePlayer");
74 void MainWindow::library() {
75 ui->menuBar->setEnabled(true);
76 ui->stackedWidget->setCurrentIndex(1);
78 setWindowTitle("SomePlayer Library");
81 void MainWindow::_add_directory() {
82 QString directory = QFileDialog::getExistingDirectory (this, "Select directory", "/home/user/MyDocs", QFileDialog::ShowDirsOnly );
83 if (!directory.isEmpty()) {
84 showBusyWidget("<H1>Scanning... Please wait</H1>");
85 _library->addDirectory(directory);
89 void MainWindow::_save_playlist() {
90 QString name = QInputDialog::getText(this, "Playlist name", "Name:");
91 Playlist playlist = _library->getCurrentPlaylist();
92 playlist.setName(name);
93 _library->savePlaylist(playlist);
96 void MainWindow::_clear_current_playlist() {
97 Playlist playlist = _library->getCurrentPlaylist();
99 _library->saveCurrentPlaylist(playlist);
100 _player_form->reload();
103 void MainWindow::showBusyWidget(QString caption) {
104 _busy_widget->setText(caption);
105 ui->menuBar->setEnabled(false);
107 ui->stackedWidget->setCurrentIndex(2);
110 void MainWindow::_toggle_search_line() {
111 if (ui->searchLine->isVisible()) {
112 ui->searchLine->setText("");
113 ui->searchLine->hide();
114 ui->nextButton->hide();
115 ui->prevButton->hide();
118 ui->searchLine->show();
119 ui->nextButton->show();
120 ui->prevButton->show();
124 void MainWindow::showSearchPanel() {
125 ui->searchButton->show();
126 ui->searchLine->setFocus();
129 void MainWindow::hideSearchPanel() {
130 ui->searchLine->setText("");
131 ui->searchLine->hide();
132 ui->nextButton->hide();
133 ui->prevButton->hide();
134 ui->searchButton->hide();
138 void MainWindow::_search(QString pattern) {
139 if (ui->stackedWidget->currentIndex() == 0) { // player
140 _player_form->search(pattern);
141 } else if (ui->stackedWidget->currentIndex() == 1) { // library
142 _library_form->search(pattern);
146 void MainWindow::_nextItem() {
147 if (ui->stackedWidget->currentIndex() == 0) { // player
148 _player_form->nextItem();
149 } else if (ui->stackedWidget->currentIndex() == 1) { // library
150 _library_form->nextItem();
154 void MainWindow::_prevItem() {
155 if (ui->stackedWidget->currentIndex() == 0) { // player
156 _player_form->prevItem();
157 } else if (ui->stackedWidget->currentIndex() == 1) { // library
158 _library_form->prevItem();
162 void MainWindow::_cancelSearch() {
163 if (ui->stackedWidget->currentIndex() == 0) { // player
164 _player_form->cancelSearch();
165 } else if (ui->stackedWidget->currentIndex() == 1) { // library
166 _library_form->cancelSearch();
170 void MainWindow::_toggle_full_screen() {
171 if (isFullScreen()) {
172 ui->fscreenButton->setIcon(QIcon(":/icons/fullscreen.png"));
175 ui->fscreenButton->setIcon(QIcon(":/icons/window.png"));