#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->listWidget->setTextElideMode(Qt::ElideMiddle);
+ ui->listWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->playButton->setIcon(QIcon::fromTheme("camera_playback"));
ui->addButton->setIcon(QIcon::fromTheme("general_add"));
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();
+}
+void BrowseMainWindow::showCurrentDirectory() // THIS METHOD IS CALLED WHEN WINDOW IS OPENED...
+{
+ browseDirectory(mCurrentDir);
}
BrowseMainWindow::~BrowseMainWindow()
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)));
- //reply->setReadBufferSize(1024 * 500);
connect(reply,SIGNAL(readyRead()),this,SLOT(readReady()));
connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(finished(QNetworkReply *)));
}
dir->date = QDate::fromString(node.attributes().namedItem("date").nodeValue());
dir->path = node.attributes().namedItem("path").nodeValue();
dir->name = node.attributes().namedItem("name").nodeValue();
- dir->extension = node.attributes().namedItem("extension").nodeValue();
+ dir->extension = getExtension(dir->path, node.attributes().namedItem("extension").nodeValue());
++idx;
if (0 != QString::compare("directory", dir->type)) {
files->append(*dir);
}
+ else if (0 == QString::compare("..", dir->name)) {
+ this->mContents->prepend(*dir);
+ }
else {
this->mContents->append(*dir);
}
this->updateList();
}
+QString BrowseMainWindow::getExtension(QString path, QString extension) {
+ // return extension if exists
+ if (!extension.isNull() && !extension.isEmpty()) return extension;
+ // return blank if no path
+ if (path.isNull() || path.isEmpty()) return "";
+ // otherwise extract the extension
+ int dot_pos = path.lastIndexOf('.');
+ if (0 < dot_pos) {
+ return path.right(path.length() - (dot_pos + 1));
+ }
+ else { // no dot
+ return "";
+ }
+}
+
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() {