#include "configdialog.h"
#include "aboutdialog.h"
#include "vlcbrowseelement.h"
-
+#include "accountdialog.h"
BrowseMainWindow::BrowseMainWindow(QWidget *parent) :
QMainWindow(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);
mContents = new QList<VlcBrowseElement>();
+ //mResponse = new QByteArray();
+
ui->playButton->setIcon(QIcon::fromTheme("camera_playback"));
ui->addButton->setIcon(QIcon::fromTheme("general_add"));
ui->browseButton->setIcon(QIcon::fromTheme("filemanager_media_folder"));
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()
}
VlcBrowseElement BrowseMainWindow::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 VlcBrowseElement());
}
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();
ui->listWidget->clear();
+ mResponse.clear();
QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/browse.xml?dir=" + dir)));
- connect(reply,SIGNAL(readyRead()),this,SLOT(parseXmlDirectory()));
+ //reply->setReadBufferSize(1024 * 500);
+ connect(reply,SIGNAL(readyRead()),this,SLOT(readReady()));
+ connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(finished(QNetworkReply *)));
}
-void BrowseMainWindow::parseXmlDirectory() {
- qDebug() << "got called!";
+void BrowseMainWindow::readReady() {
QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender());
+ // append to buffer
+ mResponse += reply->readAll();
+}
+void BrowseMainWindow::finished(QNetworkReply * reply) {
+ // now we can call parseXmlDirectory to process the full buffers
+ this->parseXmlDirectory();
+ // only interested in finished signals
+ disconnect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(finished(QNetworkReply *)));
+}
+void BrowseMainWindow::parseXmlDirectory() {
QDomDocument doc;
- doc.setContent(reply->readAll());
+ doc.setContent(this->mResponse);
QDomElement docElem = doc.documentElement();
QDomNodeList elements = docElem.elementsByTagName("element");
- mContents->clear();
- //mContents = new QList<VlcBrowseElement>();
- // we can sort by filders then files alphabetically by running to lists and appending them at the end
+ // we can sort by folders then files alphabetically by running to lists and appending them at the end
// vlc alpha sorts everything in the incoming stream, we just need to seperate files from folders.
QList<VlcBrowseElement>* files = new QList<VlcBrowseElement>();
if (0 < elements.count()) {
}
}
delete files;
- //reply->deleteLater();
- delete reply;
+ mResponse.clear();
// Update UI
this->updateList();
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() {
ui->listWidget->addItem(item);
}
// other types ignored
- //if (item) delete item;
}
}
}