Add static currentIP() in AccountDialog and change all
authorlepelley <lepelley@lepelley.(none)>
Tue, 17 Aug 2010 00:31:14 +0000 (02:31 +0200)
committerlepelley <lepelley@lepelley.(none)>
Tue, 17 Aug 2010 00:31:14 +0000 (02:31 +0200)
Add Init() for each class

accountdialog.cpp
accountdialog.h
browsemainwindow.cpp
browsemainwindow.h
main.cpp
playermainwindow.cpp
playlistmainwindow.cpp
playlistmainwindow.h

index 009e220..b64f7e8 100644 (file)
@@ -35,6 +35,19 @@ void AccountDialog::add()
     dialog->exec();
     load();
 }
+QString AccountDialog::currentIp()
+{
+
+    QSettings settings;
+    QString useKey = settings.value("config/currentKey").toString();
+    QString useIp ;
+    if ( !useKey.isEmpty())
+        useIp = settings.value("account/"+useKey).toString();
+
+    else return QString();
+
+    return useIp;
+}
 
 void AccountDialog::load()
 {
@@ -44,9 +57,9 @@ void AccountDialog::load()
     ui->listWidget->clear(); // tjr effacer , sinon on rajoute
 
     QSettings settings;
-    settings.beginGroup("config");
-    QString useKey = settings.value("currentKey").toString();
-    settings.endGroup();
+
+    QString useKey = settings.value("config/currentKey").toString();
+
 
     settings.beginGroup("account");
     foreach ( QString key, settings.allKeys())
@@ -124,12 +137,8 @@ void AccountDialog::rem()
 void AccountDialog::use()
 {
     QString currentKey = ui->listWidget->currentItem()->text();
-
     QSettings settings;
-    settings.beginGroup("config");
-    settings.setValue("currentKey", currentKey);
-    settings.endGroup();
-
+    settings.setValue("config/currentKey", currentKey);
     load();
 }
 
index 75d64a3..4e9ce4d 100644 (file)
@@ -16,7 +16,7 @@ public:
     ~AccountDialog();
     void asyncTestConnection();
 
-
+static QString  currentIp();
 
 public slots:
     void add();
index 599b632..f4bcef5 100644 (file)
@@ -21,7 +21,7 @@
 #include "configdialog.h"
 #include "aboutdialog.h"
 #include "vlcbrowseelement.h"
-
+#include "accountdialog.h"
 
 BrowseMainWindow::BrowseMainWindow(QWidget *parent) :
         QMainWindow(parent),
@@ -32,8 +32,6 @@ BrowseMainWindow::BrowseMainWindow(QWidget *parent) :
     mCurrentDir = "~/"; // This works on win as well as linux, would guess mac too.
     setWindowTitle("Vlc remote");
 
-    QSettings settings;
-    mIp = settings.value("ip").toString();
 
     mNetManager = new QNetworkAccessManager(this);
 
@@ -53,7 +51,14 @@ BrowseMainWindow::BrowseMainWindow(QWidget *parent) :
     connect(ui->playButton,SIGNAL(clicked()),this,SLOT(onPlay()));
     connect(ui->listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
 
-    this->browseDirectory(mCurrentDir);
+    init();
+
+
+}
+void BrowseMainWindow::init()  // THIS METHOD IS CALLED WHEN CONFIG CHANGED...
+{
+    mIp = AccountDialog::currentIp();
+    browseDirectory(mCurrentDir);
 }
 
 BrowseMainWindow::~BrowseMainWindow()
@@ -122,11 +127,11 @@ void BrowseMainWindow::onBrowse() {
 
 void BrowseMainWindow::onAddToPlaylist() {
     /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=in_enqueue&input=" + mCurrentElement.path)));
-}
+                             }
 
 void BrowseMainWindow::onPlay() {
     /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=in_play&input=" + mCurrentElement.path)));
-}
+                             }
 
 void BrowseMainWindow::browseDirectory(QString dir) {
     mContents->clear();
@@ -189,11 +194,11 @@ void BrowseMainWindow::parseXmlDirectory() {
 
 void BrowseMainWindow::writeFile(QString path, QByteArray text) {
     QFile file(path);
-         if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
-             return;
+    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
+        return;
 
-         QTextStream out(&file);
-         out << text;
+    QTextStream out(&file);
+    out << text;
 }
 
 void BrowseMainWindow::updateList() {
index d287019..163adb7 100644 (file)
@@ -35,6 +35,7 @@ public:
     ~BrowseMainWindow();
 
 public slots:
+    void init();
     void browseDirectory(QString);
     void onBrowse();
     void onPlay();
index b0145af..510c848 100644 (file)
--- a/main.cpp
+++ b/main.cpp
  */
 #include <QtGui/QApplication>
 #include <QSettings>
-#include "playlistmainwindow.h"
+#include <QLocale>
+#include <QTextCodec>
+#include <QTranslator>
+#include <QDebug>
 #include "playermainwindow.h"
-
+#include "accountdialog.h"
 int main(int argc, char *argv[])
 {
     QApplication a(argc, argv);
@@ -35,9 +38,13 @@ int main(int argc, char *argv[])
 
     QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));
 
-    PlayerMainWindow * mainwindow = new PlayerMainWindow;
 
-    mainwindow->showMaximized();
+    qDebug() << AccountDialog::currentIp();
+
+
+  PlayerMainWindow * mainwindow = new PlayerMainWindow;
+//
+   mainwindow->showMaximized();
 
     return a.exec();
 }
index 9558fe1..5df823d 100644 (file)
@@ -94,14 +94,19 @@ PlayerMainWindow::PlayerMainWindow(QWidget *parent) :
 }
 void PlayerMainWindow::init()
 {
-    QSettings settings;
-    QString currentKey = settings.value("config/currentKey").toString();
-    mIp = settings.value("account/"+currentKey).toString();
+
+    mIp= AccountDialog::currentIp();
 
     if ( mIp.isEmpty())
         showConfig();
+
     else
+    {
         mTimer->start(5000);
+        mPlayListMainWindow->init();
+        mBrowserMainWindow->init();
+    }
+
 }
 
 PlayerMainWindow::~PlayerMainWindow()
@@ -186,6 +191,7 @@ void PlayerMainWindow::showConfig()
     mTimer->stop();
     AccountDialog * dialog = new AccountDialog;
     dialog->exec();
+
     init();
 
 
index ce22140..9dabb54 100644 (file)
@@ -21,7 +21,7 @@
 #include <QSettings>
 #include "configdialog.h"
 #include "aboutdialog.h"
-
+#include "accountdialog.h"
 
 PlayListMainWindow::PlayListMainWindow(QWidget *parent) :
         QMainWindow(parent),
@@ -35,11 +35,6 @@ PlayListMainWindow::PlayListMainWindow(QWidget *parent) :
     mCurrentDepth = 0;
     mCurrentVlcIndex = 0;
 
-    QSettings settings;
-    QString currentKey = settings.value("config/currentKey").toString();
-    mIp = settings.value("account/"+currentKey).toString();
-
-    //mIp = settings.value("ip").toString();
 
     mNetManager = new QNetworkAccessManager(this);
 
@@ -67,7 +62,15 @@ PlayListMainWindow::PlayListMainWindow(QWidget *parent) :
     connect(ui->clearButton,SIGNAL(clicked()),this,SLOT(onClear()));
     connect(ui->listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
 
-    this->requestPlayList();
+    init();
+
+}
+void PlayListMainWindow::init()  // CALL WHEN CONFIG CHANGES
+{
+    mIp = AccountDialog::currentIp();
+    requestPlayList();
+
+
 }
 
 PlayListMainWindow::~PlayListMainWindow()
@@ -105,27 +108,27 @@ void PlayListMainWindow::onListSelectionChanged() {
 void PlayListMainWindow::onRemove() {
     if (0 < this->mCurrentVlcIndex) {
         /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_delete&id=" + QString::number(this->mCurrentVlcIndex))));
-        this->requestPlayList();
-    }
+                                     this->requestPlayList();
+                                 }
 }
 void PlayListMainWindow::onPlay() {
     if (0 < this->mCurrentVlcIndex) {
         /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_play&id=" + QString::number(this->mCurrentVlcIndex))));
-    }
+                                 }
 }
 void PlayListMainWindow::onRepeat() {
     /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_repeat")));
-}
+                             }
 void PlayListMainWindow::onLoop() {
     /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_loop")));
-}
+                             }
 void PlayListMainWindow::onShuffle() {
     /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_random")));
-}
+                             }
 void PlayListMainWindow::onClear() {
     /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_empty")));
-    this->requestPlayList();
-}
+                                 this->requestPlayList();
+                             }
 void PlayListMainWindow::requestPlayList() {
     ui->listWidget->clear();
     ui->removeButton->setDisabled(true);
@@ -182,11 +185,11 @@ void PlayListMainWindow::parseXmlPlayList() {
 
 VlcPlayListElementSimple PlayListMainWindow::getElementFromText(QString text) {
     //if (0 != QString::compare("", text)) {
-        for (int idx = 0; idx < mContents->count(); ++idx) {
-            if (0 == QString::compare(text, mContents->at(idx).name)) {
-                return mContents->at(idx);
-            }
+    for (int idx = 0; idx < mContents->count(); ++idx) {
+        if (0 == QString::compare(text, mContents->at(idx).name)) {
+            return mContents->at(idx);
         }
+    }
     //}
     return *(new VlcPlayListElementSimple());
 }
index 47c38f4..7eba61f 100644 (file)
@@ -37,7 +37,7 @@ class PlayListMainWindow : public QMainWindow {
 public:
     explicit PlayListMainWindow(QWidget *parent = 0);
     ~PlayListMainWindow();
-
+    void init();
 public slots:
     void onClear();
     void onShuffle();