From a2ae6a8e153e0fab468bbd7d13052d81eba6e665 Mon Sep 17 00:00:00 2001 From: druid23 Date: Wed, 8 Sep 2010 03:06:57 +0100 Subject: [PATCH] Implemented settings dialog and refactored accordingly. modified: src/appsettings.cpp modified: src/appsettings.h modified: src/playermainwindow.cpp modified: src/playermainwindow.h modified: src/playermainwindow.ui new file: src/settingsdialog.cpp new file: src/settingsdialog.h new file: src/settingsdialog.ui modified: src/src.pro --- src/appsettings.cpp | 6 +- src/appsettings.h | 2 +- src/playermainwindow.cpp | 62 +++++- src/playermainwindow.h | 4 + src/playermainwindow.ui | 19 +- src/settingsdialog.cpp | 127 ++++++++++++ src/settingsdialog.h | 64 ++++++ src/settingsdialog.ui | 488 ++++++++++++++++++++++++++++++++++++++++++++++ src/src.pro | 9 +- 9 files changed, 763 insertions(+), 18 deletions(-) create mode 100644 src/settingsdialog.cpp create mode 100644 src/settingsdialog.h create mode 100644 src/settingsdialog.ui diff --git a/src/appsettings.cpp b/src/appsettings.cpp index 1a48354..0707023 100644 --- a/src/appsettings.cpp +++ b/src/appsettings.cpp @@ -159,10 +159,10 @@ int AppSettings::getPingTimeout() { } return _pingTimeout; } -int AppSettings::setPingTimeout(int havePingTimeout) { +int AppSettings::setPingTimeout(int pingTimeout) { QSettings sets; - sets.setValue("config/pingTimeout", havePingTimeout); - _havePingTimeout = havePingTimeout; + sets.setValue("config/pingTimeout", pingTimeout); + _pingTimeout = pingTimeout; _havePingTimeout = true; return _pingTimeout; } diff --git a/src/appsettings.h b/src/appsettings.h index 8280a18..1121b49 100644 --- a/src/appsettings.h +++ b/src/appsettings.h @@ -32,7 +32,7 @@ #define RETRIEVE_ART_TIMEOUT 500 #endif #ifndef RETRY_NETWORK_TIMEOUT -#define RETRY_NETWORK_TIMEOUT 20000 +#define RETRY_NETWORK_TIMEOUT 25000 #endif #ifndef SHOW_UNKNOWN_FILETYPES diff --git a/src/playermainwindow.cpp b/src/playermainwindow.cpp index a400cd7..f5b5d55 100644 --- a/src/playermainwindow.cpp +++ b/src/playermainwindow.cpp @@ -23,10 +23,12 @@ #include "configdialog.h" #include "aboutdialog.h" #include "accountdialog.h" + #include "settingsdialog.h" #include "appsettings.h" #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) #include #endif +#include PlayerMainWindow::PlayerMainWindow(QWidget *parent) : QMainWindow(parent), @@ -90,11 +92,13 @@ #endif connect(mTimer,SIGNAL(timeout()),this,SLOT(askStatus())); + connect(ui->actionSettings,SIGNAL(triggered()),this,SLOT(showSettings())); connect(ui->actionConfiguration,SIGNAL(triggered()),this,SLOT(showConfig())); connect(ui->actionAbout,SIGNAL(triggered()),this,SLOT(showAbout())); - connect(ui->actionPortrait,SIGNAL(triggered()),this,SLOT(setPortrait())); - connect(ui->actionLandscape,SIGNAL(triggered()),this,SLOT(setLandscape())); - connect(ui->actionAutoRotate,SIGNAL(triggered()),this,SLOT(setAutoRotate())); + connect(ui->actionFavourites,SIGNAL(triggered()),this,SLOT(showFavourites())); + //connect(ui->actionPortrait,SIGNAL(triggered()),this,SLOT(setPortrait())); + //connect(ui->actionLandscape,SIGNAL(triggered()),this,SLOT(setLandscape())); + //connect(ui->actionAutoRotate,SIGNAL(triggered()),this,SLOT(setAutoRotate())); connect(ui->playlistButton,SIGNAL(clicked()),mPlayListMainWindow,SLOT(show())); connect(ui->playlistButton,SIGNAL(clicked()),mPlayListMainWindow,SLOT(showPlayList())); connect(ui->browseButton,SIGNAL(clicked()),mBrowserMainWindow,SLOT(show())); @@ -184,6 +188,27 @@ mFavouritesMainWindow->init(); } + void PlayerMainWindow::updateFromSettings() + { + #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) + switch (AppSettings::getOrientation()) { + case LANDSCAPE: + this->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true); + break; + case PORTRAIT: + this->setAttribute(Qt::WA_Maemo5PortraitOrientation, true); + break; + case AUTO_ROTATE: + this->setAttribute(Qt::WA_Maemo5AutoOrientation, true); + break; + } + #endif + if (AppSettings::getShowAlbumArt()) { + this->mIsFirstStatusCall = true; + } + mTimer->start(AppSettings::getStatusPollTimeout()); + } + void PlayerMainWindow::setPortrait() { #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) @@ -298,6 +323,12 @@ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=seek&val="+QString::number(value)+"%25"))); } + void PlayerMainWindow::showSettings() + { + SettingsDialog * dialog = new SettingsDialog(this); + connect(dialog, SIGNAL(closeSignal()), this, SLOT(updateFromSettings())); + dialog->exec(); + } void PlayerMainWindow::showConfig() { mTimer->stop(); @@ -473,7 +504,7 @@ ui->playpauseButton->setIcon(QIcon::fromTheme("camera_playback")); } - if (STOP == mCurrentStatus.state) { + if (STOP == mCurrentStatus.state || !AppSettings::getShowAlbumArt()) { ui->labelArtPortrait->setVisible(false); ui->labelArtLandscape->setVisible(false); } @@ -482,8 +513,10 @@ // potential actions: // rebuild display layout // retrieve album art - mHasImage = false; - QTimer::singleShot(AppSettings::getRetrieveArtTimeout(), mPlayListMainWindow, SLOT(requestPlayList())); + if (AppSettings::getShowAlbumArt()) { + mHasImage = false; + QTimer::singleShot(AppSettings::getRetrieveArtTimeout(), mPlayListMainWindow, SLOT(requestPlayList())); + } } // Update the buttons on the playlist window if (NULL != this->mPlayListMainWindow) { @@ -563,4 +596,21 @@ ui->labelArtPortrait->setVisible(true); } } + void PlayerMainWindow::closeEvent(QCloseEvent * event) { + if (!AppSettings::getAlertOnClose() || PLAYING != mCurrentStatus.state) { + event->accept(); + } + else { // handle alert + if (QMessageBox::Yes == QMessageBox::question(this + , tr("Really quit?") + , tr("You currently have media playing on your remote machine. Are you sure you wish to quit vlc-remote?") + , QMessageBox::Yes | QMessageBox::No + , QMessageBox::No)) { + event->accept(); + } + else { + event->ignore(); + } + } + } diff --git a/src/playermainwindow.h b/src/playermainwindow.h index 85eada0..063508d 100644 --- a/src/playermainwindow.h +++ b/src/playermainwindow.h @@ -39,6 +39,7 @@ public: public slots: void askStatus(); + void showSettings(); void showConfig(); void showAbout(); void showFavourites(); @@ -60,6 +61,7 @@ public slots: void finished(QNetworkReply * reply); void error(QNetworkReply::NetworkError code); void readReady(); + void updateFromSettings(); void orientationChanged(); void setPortrait(); void setLandscape(); @@ -69,8 +71,10 @@ public slots: protected slots: void parseXmlStatus(); + protected: void changeEvent(QEvent *e); + void closeEvent(QCloseEvent *); private: diff --git a/src/playermainwindow.ui b/src/playermainwindow.ui index 44d8e65..09a3436 100644 --- a/src/playermainwindow.ui +++ b/src/playermainwindow.ui @@ -6,7 +6,7 @@ 0 0 - 794 + 790 641 @@ -273,7 +273,7 @@ 0 0 - 794 + 790 20 @@ -281,11 +281,10 @@ menu + - - - + @@ -314,6 +313,16 @@ Auto Rotate + + + Settings + + + + + Favourites + + diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp new file mode 100644 index 0000000..5686f0d --- /dev/null +++ b/src/settingsdialog.cpp @@ -0,0 +1,127 @@ +/* VLC-REMOTE for MAEMO 5 +* Copyright (C) 2010 Schutz Sacha , Dru Moore , Yann Nave +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2, +* or (at your option) any later version, as published by the Free +* Software Foundation +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#include "settingsdialog.h" +#include "ui_settingsdialog.h" +#include "appsettings.h" + + + +SettingsDialog::SettingsDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::SettingsDialog) +{ + ui->setupUi(this); + ui->scrollArea->setWidget(ui->scrollAreaWidgetContents); + connect(ui->radioButtonAutoRotate, SIGNAL(released()), this, SLOT(setOrientationAutoRotate())); + connect(ui->radioButtonLandscape, SIGNAL(released()), this, SLOT(setOrientationLandscape())); + connect(ui->radioButtonPortrait, SIGNAL(released()), this, SLOT(setOrientationPortrait())); + connect(ui->checkBoxAlertOnClose, SIGNAL(toggled(bool)), this, SLOT(setAlertOnClose(bool))); + connect(ui->checkBoxShowArt, SIGNAL(toggled(bool)), this, SLOT(setShowAlbumArt(bool))); + connect(ui->checkBoxUnknownFiles, SIGNAL(toggled(bool)), this, SLOT(setShowUnknownFileTypes(bool))); + connect(ui->comboBoxPollFrequency, SIGNAL(currentIndexChanged(int)), this, SLOT(setStatusPollTimeout(int))); + connect(ui->comboBoxPingTimeout, SIGNAL(currentIndexChanged(int)), this, SLOT(setPingTimeout(int))); + connect(ui->comboBoxConnectionTimeout, SIGNAL(currentIndexChanged(int)), this, SLOT(setConnectionTimeout(int))); + connect(ui->comboBoxRetryNetworkDelay, SIGNAL(currentIndexChanged(int)), this, SLOT(setRetryNetworkTimeout(int))); + connect(ui->comboBoxRetrieveArtDelay, SIGNAL(currentIndexChanged(int)), this, SLOT(setRetrieveArtTimeout(int))); + init(); + +} + +SettingsDialog::~SettingsDialog() +{ + delete ui; +} + +void SettingsDialog::init() +{ + switch (AppSettings::getOrientation()) { + case LANDSCAPE: + ui->radioButtonLandscape->setChecked(true); + break; + case PORTRAIT: + ui->radioButtonPortrait->setChecked(true); + break; + case AUTO_ROTATE: + default: + ui->radioButtonAutoRotate->setChecked(true); + break; + } + + ui->checkBoxAlertOnClose->setChecked(AppSettings::getAlertOnClose()); + ui->checkBoxShowArt->setChecked(AppSettings::getShowAlbumArt()); + ui->checkBoxUnknownFiles->setChecked(AppSettings::getShowUnknownFileTypes()); + int idx = -1; + idx = ui->comboBoxPollFrequency->findText(QString::number(AppSettings::getStatusPollTimeout())); + ui->comboBoxPollFrequency->setCurrentIndex(-1 < idx ? idx : 0); + idx = ui->comboBoxConnectionTimeout->findText(QString::number(AppSettings::getConnectionTimeout())); + ui->comboBoxConnectionTimeout->setCurrentIndex(-1 < idx ? idx : 0); + idx = ui->comboBoxPingTimeout->findText(QString::number(AppSettings::getPingTimeout())); + ui->comboBoxPingTimeout->setCurrentIndex(-1 < idx ? idx : 0); + idx = ui->comboBoxRetryNetworkDelay->findText(QString::number(AppSettings::getRetryNetworkTimeout())); + ui->comboBoxRetryNetworkDelay->setCurrentIndex(-1 < idx ? idx : 0); + idx = ui->comboBoxRetrieveArtDelay->findText(QString::number(AppSettings::getRetrieveArtTimeout())); + ui->comboBoxRetrieveArtDelay->setCurrentIndex(-1 < idx ? idx : 0); +} + +void SettingsDialog::setOrientationLandscape() { + setOrientation(LANDSCAPE); +} +void SettingsDialog::setOrientationPortrait() { + setOrientation(PORTRAIT); +} +void SettingsDialog::setOrientationAutoRotate() { + setOrientation(AUTO_ROTATE); +} +void SettingsDialog::setOrientation(Orientation orientation) { + AppSettings::setOrientation(orientation); +} +void SettingsDialog::setStatusPollTimeout(int idx) { + Q_UNUSED(idx); + AppSettings::setStatusPollTimeout(ui->comboBoxPollFrequency->currentText().toInt()); +} +void SettingsDialog::setPingTimeout(int idx) { + Q_UNUSED(idx); + AppSettings::setPingTimeout(ui->comboBoxPingTimeout->currentText().toInt()); +} +void SettingsDialog::setConnectionTimeout(int idx) { + Q_UNUSED(idx); + AppSettings::setConnectionTimeout(ui->comboBoxConnectionTimeout->currentText().toInt()); +} +void SettingsDialog::setRetrieveArtTimeout(int idx) { + Q_UNUSED(idx); + AppSettings::setRetrieveArtTimeout(ui->comboBoxRetrieveArtDelay->currentText().toInt()); +} +void SettingsDialog::setRetryNetworkTimeout(int idx) { + Q_UNUSED(idx); + AppSettings::setRetryNetworkTimeout(ui->comboBoxRetryNetworkDelay->currentText().toInt()); +} +void SettingsDialog::setShowUnknownFileTypes(bool state) { + AppSettings::setShowUnknownFileTypes(state); +} +void SettingsDialog::setShowAlbumArt(bool state) { + AppSettings::setShowAlbumArt(state); +} +void SettingsDialog::setAlertOnClose(bool state) { + AppSettings::setAlertOnClose(state); +} + +void SettingsDialog::closeEvent(QCloseEvent * event) { + Q_UNUSED(event); + emit closeSignal(); + this->close(); +} diff --git a/src/settingsdialog.h b/src/settingsdialog.h new file mode 100644 index 0000000..ae6c10a --- /dev/null +++ b/src/settingsdialog.h @@ -0,0 +1,64 @@ +/* VLC-REMOTE for MAEMO 5 +* Copyright (C) 2010 Schutz Sacha , Dru Moore , Yann Nave +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2, +* or (at your option) any later version, as published by the Free +* Software Foundation +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#ifndef SETTINGSDIALOG_H +#define SETTINGSDIALOG_H + +#include +#include "appsettings.h" + +namespace Ui { + class SettingsDialog; +} + +class SettingsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SettingsDialog(QWidget *parent = 0); + ~SettingsDialog(); + + +//static QString currentIp(); + +public slots: + void init(); + void setOrientationLandscape(); + void setOrientationPortrait(); + void setOrientationAutoRotate(); + void setStatusPollTimeout(int); + void setPingTimeout(int); + void setConnectionTimeout(int); + void setRetrieveArtTimeout(int); + void setRetryNetworkTimeout(int); + void setShowUnknownFileTypes(bool); + void setShowAlbumArt(bool); + void setAlertOnClose(bool); + +protected: + void closeEvent(QCloseEvent *); + void setOrientation(Orientation); + +private: + Ui::SettingsDialog *ui; + +signals: + void closeSignal(); +}; + +#endif // SETTINGSDIALOG_H diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui new file mode 100644 index 0000000..85cf589 --- /dev/null +++ b/src/settingsdialog.ui @@ -0,0 +1,488 @@ + + + SettingsDialog + + + + 0 + 0 + 803 + 450 + + + + Application Settings + + + + + 0 + 0 + 781 + 391 + + + + + QLayout::SetDefaultConstraint + + + + + + 0 + 0 + + + + Qt::ScrollBarAlwaysOff + + + false + + + + + 0 + 0 + 700 + 1000 + + + + + 0 + 0 + + + + + + 0 + 0 + 681 + 471 + + + + + QLayout::SetMinAndMaxSize + + + + + Orientation + + + + + + + + + Landscape + + + + + + + Portrait + + + + + + + Auto Rotate + + + + + + + + + Behaviour + + + + + + + + + Qt::LeftToRight + + + Show album art? + + + + + + + + + + + Show unknown filetypes? + + + + + + + + + + + Alert on close when media playing? + + + + + + + + + Advanced settings + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing + + + + + Retry network delay (ms) + + + + + + + + 1000 + + + + + 2500 + + + + + 5000 + + + + + 10000 + + + + + 25000 + + + + + 50000 + + + + + 100000 + + + + + 250000 + + + + + 500000 + + + + + + + + + 1000 + + + + + 2500 + + + + + 5000 + + + + + 10000 + + + + + 25000 + + + + + 50000 + + + + + 100000 + + + + + 250000 + + + + + 500000 + + + + + + + + Update frequency (ms) + + + + + + + Ping timeout (ms) + + + + + + + + 100 + + + + + 250 + + + + + 500 + + + + + 1000 + + + + + 2500 + + + + + 5000 + + + + + 10000 + + + + + 25000 + + + + + 50000 + + + + + 100000 + + + + + 250000 + + + + + 500000 + + + + + + + + Connection timeout (ms) + + + + + + + + 1000 + + + + + 2500 + + + + + 5000 + + + + + 7500 + + + + + 10000 + + + + + 25000 + + + + + 50000 + + + + + 100000 + + + + + 250000 + + + + + 500000 + + + + + + + + Retrieve Art Delay + + + + + + + + 100 + + + + + 250 + + + + + 500 + + + + + 1000 + + + + + 2500 + + + + + 5000 + + + + + 10000 + + + + + 25000 + + + + + 50000 + + + + + 100000 + + + + + 250000 + + + + + 500000 + + + + + + + + + + + + + + + + + diff --git a/src/src.pro b/src/src.pro index 35196ae..a13c497 100644 --- a/src/src.pro +++ b/src/src.pro @@ -20,7 +20,8 @@ SOURCES += main.cpp \ vlcplaylistelementsimple.cpp \ vlcstatus.cpp \ appsettings.cpp \ - favouritesmainwindow.cpp + favouritesmainwindow.cpp \ + settingsdialog.cpp HEADERS += playlistmainwindow.h \ playermainwindow.h \ configdialog.h \ @@ -32,14 +33,16 @@ HEADERS += playlistmainwindow.h \ vlcplaylistelementsimple.h \ vlcstatus.h \ appsettings.h \ - favouritesmainwindow.h + favouritesmainwindow.h \ + settingsdialog.h FORMS += playlistmainwindow.ui \ playermainwindow.ui \ configdialog.ui \ aboutdialog.ui \ accountdialog.ui \ browsemainwindow.ui \ - favouritesmainwindow.ui + favouritesmainwindow.ui \ + settingsdialog.ui OTHER_FILES += vlc-remote.desktop RESOURCES += ressources.qrc TRANSLATIONS = vlcremote_fr_FR.ts -- 1.7.9.5