Began refactoring settings handling.
[vlc-remote] / browsemainwindow.cpp
index c21bd91..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()) {
@@ -91,7 +115,8 @@ void BrowseMainWindow::onListSelectionChanged() {
             ui->browseButton->setDisabled(true);
             ui->playButton->setDisabled(true);
             ui->addButton->setDisabled(true);
-            browseDirectory(mCurrentElement.path);
+            mCurrentDir = mCurrentElement.path;
+            browseDirectory(mCurrentDir);
         }
         else {
             // can we browse?
@@ -122,7 +147,8 @@ void BrowseMainWindow::onBrowse() {
     // check for directory
     if (0 == QString::compare("directory", mCurrentElement.type)) {
         // call browseDirectory
-        this->browseDirectory(mCurrentElement.path);
+        mCurrentDir = mCurrentElement.path;
+        browseDirectory(mCurrentDir);
     }
     else {
         ui->browseButton->setDisabled(true);