From: lepelley Date: Tue, 17 Aug 2010 00:31:14 +0000 (+0200) Subject: Add static currentIP() in AccountDialog and change all X-Git-Tag: v0.5~50 X-Git-Url: https://vcs.maemo.org/git/?p=vlc-remote;a=commitdiff_plain;h=ac5b64748ab0910c969efd2c54f6b4de0eb65d4d Add static currentIP() in AccountDialog and change all Add Init() for each class --- diff --git a/accountdialog.cpp b/accountdialog.cpp index 009e220..b64f7e8 100644 --- a/accountdialog.cpp +++ b/accountdialog.cpp @@ -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(); } diff --git a/accountdialog.h b/accountdialog.h index 75d64a3..4e9ce4d 100644 --- a/accountdialog.h +++ b/accountdialog.h @@ -16,7 +16,7 @@ public: ~AccountDialog(); void asyncTestConnection(); - +static QString currentIp(); public slots: void add(); diff --git a/browsemainwindow.cpp b/browsemainwindow.cpp index 599b632..f4bcef5 100644 --- a/browsemainwindow.cpp +++ b/browsemainwindow.cpp @@ -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() { diff --git a/browsemainwindow.h b/browsemainwindow.h index d287019..163adb7 100644 --- a/browsemainwindow.h +++ b/browsemainwindow.h @@ -35,6 +35,7 @@ public: ~BrowseMainWindow(); public slots: + void init(); void browseDirectory(QString); void onBrowse(); void onPlay(); diff --git a/main.cpp b/main.cpp index b0145af..510c848 100644 --- a/main.cpp +++ b/main.cpp @@ -17,9 +17,12 @@ */ #include #include -#include "playlistmainwindow.h" +#include +#include +#include +#include #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(); } diff --git a/playermainwindow.cpp b/playermainwindow.cpp index 9558fe1..5df823d 100644 --- a/playermainwindow.cpp +++ b/playermainwindow.cpp @@ -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(); diff --git a/playlistmainwindow.cpp b/playlistmainwindow.cpp index ce22140..9dabb54 100644 --- a/playlistmainwindow.cpp +++ b/playlistmainwindow.cpp @@ -21,7 +21,7 @@ #include #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()); } diff --git a/playlistmainwindow.h b/playlistmainwindow.h index 47c38f4..7eba61f 100644 --- a/playlistmainwindow.h +++ b/playlistmainwindow.h @@ -37,7 +37,7 @@ class PlayListMainWindow : public QMainWindow { public: explicit PlayListMainWindow(QWidget *parent = 0); ~PlayListMainWindow(); - + void init(); public slots: void onClear(); void onShuffle();