Began refactoring settings handling.
authordruid23 <usr@dru-id.co.uk>
Sat, 21 Aug 2010 13:50:31 +0000 (14:50 +0100)
committerdruid23 <usr@dru-id.co.uk>
Sat, 21 Aug 2010 13:50:31 +0000 (14:50 +0100)
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

appsettings.cpp [new file with mode: 0644]
appsettings.h [new file with mode: 0644]
browsemainwindow.cpp
browsemainwindow.h
browsemainwindow.ui
main.cpp
playlistmainwindow.cpp
vlcRemote.pro

diff --git a/appsettings.cpp b/appsettings.cpp
new file mode 100644 (file)
index 0000000..570158b
--- /dev/null
@@ -0,0 +1,52 @@
+/*   VLC-REMOTE for MAEMO 5
+*   Copyright (C) 2010 Schutz Sacha <istdasklar@gmail.com>, Dru Moore <usr@dru-id.co.uk>, Yann Nave <yannux@onbebop.net>
+*   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<VlcDirectory>* AppSettings::getFavourites() { return new QList<VlcDirectory>(); }
+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 (file)
index 0000000..2a752be
--- /dev/null
@@ -0,0 +1,42 @@
+/*   VLC-REMOTE for MAEMO 5
+*   Copyright (C) 2010 Schutz Sacha <istdasklar@gmail.com>, Dru Moore <usr@dru-id.co.uk>, Yann Nave <yannux@onbebop.net>
+*   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 <QSettings>
+
+struct VlcDirectory {
+    QString name;
+    QString path;
+};
+
+class AppSettings {
+public:
+    explicit AppSettings();
+    ~AppSettings();
+    static QString getCurrentKey();
+    static QString getCurrentIp();
+    static VlcDirectory getHomeDirectory();
+    static QList<VlcDirectory>* getFavourites();
+    static bool addFavourite(VlcDirectory dir);
+    static bool deleteFavourite(VlcDirectory dir);
+    static bool setHomeDirectory(VlcDirectory dir);
+//private:
+    //static QSettings settings;
+};
+
+#endif // APPSETTINGS_H
index b410e31..d429502 100644 (file)
@@ -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<QListWidgetItem *> items = ui->listWidget->selectedItems();
     if (0 < items.count()) {
index b83a32c..dc802da 100644 (file)
@@ -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();
index ca133f6..395c0dd 100644 (file)
      <string>menu</string>
     </property>
    </widget>
-   <addaction name="menuMenu"/>
+   <addaction name="actionGoHome"/>
+   <addaction name="actionSetHome"/>
+   <addaction name="actionViewFavourites"/>
+   <addaction name="actionSetFavourite"/>
   </widget>
-  <action name="actionPortrait">
+  <action name="actionGoHome">
    <property name="text">
-    <string>Portrait Mode</string>
+    <string>Home</string>
    </property>
   </action>
-  <action name="actionLandscape">
+  <action name="actionSetHome">
    <property name="text">
-    <string>Landscape Mode</string>
+    <string>Set as Home</string>
+   </property>
+  </action>
+  <action name="actionViewFavourites">
+   <property name="text">
+    <string>Favourites</string>
+   </property>
+  </action>
+  <action name="actionSetFavourite">
+   <property name="text">
+    <string>Add to Favourite</string>
    </property>
   </action>
  </widget>
index caf2cb0..6c74fa1 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -22,7 +22,7 @@
 #include <QTranslator>
 #include <QDebug>
 #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;
index 4ce67a7..62b8616 100644 (file)
@@ -21,7 +21,7 @@
 #include <QSettings>
 #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
 {
index 76dfee5..8b4c0c9 100644 (file)
@@ -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