From: druid23 Date: Sat, 21 Aug 2010 13:50:31 +0000 (+0100) Subject: Began refactoring settings handling. X-Git-Tag: v0.5~19 X-Git-Url: https://vcs.maemo.org/git/?p=vlc-remote;a=commitdiff_plain;h=f9fe22e0066fcde0f4e53a9e715962f2e1b2f241 Began refactoring settings handling. Added per account home folder settings and corresponding menu on Browser new file: appsettings.cpp new file: appsettings.h modified: browsemainwindow.cpp modified: browsemainwindow.h modified: browsemainwindow.ui modified: main.cpp modified: playlistmainwindow.cpp modified: vlcRemote.pro --- diff --git a/appsettings.cpp b/appsettings.cpp new file mode 100644 index 0000000..570158b --- /dev/null +++ b/appsettings.cpp @@ -0,0 +1,52 @@ +/* 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 "appsettings.h" +// initialize static storage for settings reference +//QSettings AppSettings::settings; + +AppSettings::AppSettings() { +} + +AppSettings::~AppSettings() { + ; +} + +QString AppSettings::getCurrentKey() { + QSettings sets; + return sets.value("config/currentKey", "").toString(); +} +QString AppSettings::getCurrentIp() { + QSettings sets; + return sets.value("account/" + getCurrentKey(), "").toString(); +} +VlcDirectory AppSettings::getHomeDirectory() { + QSettings sets; + VlcDirectory home; + home.name = sets.value("config/accounts/" + getCurrentKey() + "/homeDirName", "Default").toString(); + home.path = sets.value("config/accounts/" + getCurrentKey() + "/homeDirPath", "~/").toString(); + return home; +} +bool AppSettings::setHomeDirectory(VlcDirectory dir) { + QSettings sets; + sets.setValue("config/accounts/" + getCurrentKey() + "/homeDirName", dir.name); + sets.setValue("config/accounts/" + getCurrentKey() + "/homeDirPath", dir.path); + return true; +} +QList* AppSettings::getFavourites() { return new QList(); } +bool AppSettings::addFavourite(VlcDirectory dir) { return true; } +bool AppSettings::deleteFavourite(VlcDirectory dir) { return true; } diff --git a/appsettings.h b/appsettings.h new file mode 100644 index 0000000..2a752be --- /dev/null +++ b/appsettings.h @@ -0,0 +1,42 @@ +/* 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 APPSETTINGS_H +#define APPSETTINGS_H +#include + +struct VlcDirectory { + QString name; + QString path; +}; + +class AppSettings { +public: + explicit AppSettings(); + ~AppSettings(); + static QString getCurrentKey(); + static QString getCurrentIp(); + static VlcDirectory getHomeDirectory(); + static QList* getFavourites(); + static bool addFavourite(VlcDirectory dir); + static bool deleteFavourite(VlcDirectory dir); + static bool setHomeDirectory(VlcDirectory dir); +//private: + //static QSettings settings; +}; + +#endif // APPSETTINGS_H diff --git a/browsemainwindow.cpp b/browsemainwindow.cpp index b410e31..d429502 100644 --- a/browsemainwindow.cpp +++ b/browsemainwindow.cpp @@ -21,7 +21,7 @@ #include "configdialog.h" #include "aboutdialog.h" #include "vlcbrowseelement.h" -#include "accountdialog.h" +#include "appsettings.h" BrowseMainWindow::BrowseMainWindow(QWidget *parent) : QMainWindow(parent), @@ -29,7 +29,7 @@ BrowseMainWindow::BrowseMainWindow(QWidget *parent) : { ui->setupUi(this); - mCurrentDir = "~/"; // This works on win as well as linux, would guess mac too. + mCurrentDir = "~/"; //AppSettings::getHomeDirectory().path; // This works on win as well as linux, would guess mac too. setWindowTitle("Vlc remote"); @@ -52,13 +52,23 @@ BrowseMainWindow::BrowseMainWindow(QWidget *parent) : connect(ui->playButton,SIGNAL(clicked()),this,SLOT(onPlay())); connect(ui->listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged())); + connect(ui->actionGoHome, SIGNAL(triggered()), this, SLOT(showHomeFolder())); + connect(ui->actionSetHome, SIGNAL(triggered()), this, SLOT(setHomeFolder())); + connect(ui->actionViewFavourites, SIGNAL(triggered()), this, SLOT(showFavourites())); + connect(ui->actionSetFavourite, SIGNAL(triggered()), this, SLOT(setFavourite())); + init(); } void BrowseMainWindow::init() // THIS METHOD IS CALLED WHEN CONFIG CHANGED... { - mIp = AccountDialog::currentIp(); + mIp = AppSettings::getCurrentIp(); // AccountDialog::currentIp(); + setHomeDirectory(); +} +void BrowseMainWindow::setHomeDirectory() +{ + mCurrentDir = AppSettings::getHomeDirectory().path; } void BrowseMainWindow::showCurrentDirectory() // THIS METHOD IS CALLED WHEN WINDOW IS OPENED... { @@ -82,6 +92,20 @@ void BrowseMainWindow::changeEvent(QEvent *e) } } +void BrowseMainWindow::showHomeFolder() { + browseDirectory(AppSettings::getHomeDirectory().path); +} +void BrowseMainWindow::setHomeFolder() { + if (0 < mCurrentDir.length()) { + VlcDirectory dir; + dir.name = "Home"; + dir.path = mCurrentDir; + AppSettings::setHomeDirectory(dir); + } +} +void BrowseMainWindow::showFavourites() {} +void BrowseMainWindow::setFavourite() {} + void BrowseMainWindow::onListSelectionChanged() { QList items = ui->listWidget->selectedItems(); if (0 < items.count()) { diff --git a/browsemainwindow.h b/browsemainwindow.h index b83a32c..dc802da 100644 --- a/browsemainwindow.h +++ b/browsemainwindow.h @@ -44,6 +44,11 @@ public slots: void finished(QNetworkReply * reply); void readReady(); void showCurrentDirectory(); + void setHomeFolder(); + void showHomeFolder(); + void setFavourite(); + void showFavourites(); + void setHomeDirectory(); protected slots: void parseXmlDirectory(); diff --git a/browsemainwindow.ui b/browsemainwindow.ui index ca133f6..395c0dd 100644 --- a/browsemainwindow.ui +++ b/browsemainwindow.ui @@ -60,16 +60,29 @@ menu - + + + + - + - Portrait Mode + Home - + - Landscape Mode + Set as Home + + + + + Favourites + + + + + Add to Favourite diff --git a/main.cpp b/main.cpp index caf2cb0..6c74fa1 100644 --- a/main.cpp +++ b/main.cpp @@ -22,7 +22,7 @@ #include #include #include "playermainwindow.h" -#include "accountdialog.h" +#include "appsettings.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); @@ -39,7 +39,7 @@ int main(int argc, char *argv[]) QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8")); - qDebug() << AccountDialog::currentIp(); + qDebug() << AppSettings::getCurrentIp(); PlayerMainWindow * mainwindow = new PlayerMainWindow; diff --git a/playlistmainwindow.cpp b/playlistmainwindow.cpp index 4ce67a7..62b8616 100644 --- a/playlistmainwindow.cpp +++ b/playlistmainwindow.cpp @@ -21,7 +21,7 @@ #include #include "configdialog.h" #include "aboutdialog.h" -#include "accountdialog.h" +#include "appsettings.h" #include "vlcstatus.h" PlayListMainWindow::PlayListMainWindow(QWidget *parent) : @@ -71,7 +71,7 @@ PlayListMainWindow::PlayListMainWindow(QWidget *parent) : } void PlayListMainWindow::init() // CALL WHEN CONFIG CHANGES { - mIp = AccountDialog::currentIp(); + mIp = AppSettings::getCurrentIp(); // AccountDialog::currentIp(); } void PlayListMainWindow::showPlayList() // CALL WHEN SHOWN { diff --git a/vlcRemote.pro b/vlcRemote.pro index 76dfee5..8b4c0c9 100644 --- a/vlcRemote.pro +++ b/vlcRemote.pro @@ -18,7 +18,8 @@ SOURCES += main.cpp \ browsemainwindow.cpp \ vlcbrowseelement.cpp \ vlcplaylistelementsimple.cpp \ - vlcstatus.cpp + vlcstatus.cpp \ + appsettings.cpp HEADERS += playlistmainwindow.h \ playermainwindow.h \ configdialog.h \ @@ -28,7 +29,8 @@ HEADERS += playlistmainwindow.h \ browsemainwindow.h \ vlcbrowseelement.h \ vlcplaylistelementsimple.h \ - vlcstatus.h + vlcstatus.h \ + appsettings.h FORMS += playlistmainwindow.ui \ playermainwindow.ui \ configdialog.ui \ @@ -37,5 +39,4 @@ FORMS += playlistmainwindow.ui \ browsemainwindow.ui OTHER_FILES += vlc-remote.desktop RESOURCES += ressources.qrc - TRANSLATIONS = vlcremote_fr_FR.ts