1 /* VLC-REMOTE for MAEMO 5
2 * Copyright (C) 2010 Schutz Sacha <istdasklar@gmail.com>
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2,
5 * or (at your option) any later version, as published by the Free
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "playermainwindow.h"
21 #include "ui_playermainwindow.h"
22 #include "configdialog.h"
23 #include "aboutdialog.h"
24 #include "accountdialog.h"
27 PlayerMainWindow::PlayerMainWindow(QWidget *parent) :
29 ui(new Ui::PlayerMainWindow)
32 setWindowTitle("Vlc remote");
36 mTimer = new QTimer(this);
37 mNetManager = new QNetworkAccessManager(this);
38 mPlayListMainWindow = new PlayListMainWindow;
39 mBrowserMainWindow = new BrowseMainWindow;
44 ui->playlistButton->setIcon(QIcon::fromTheme("notes_bullets"));
45 ui->browseButton->setIcon(QIcon::fromTheme("filemanager_media_folder"));
47 ui->previousButton->setIcon(QIcon::fromTheme("pdf_viewer_first_page"));
48 ui->nextButton->setIcon(QIcon::fromTheme("pdf_viewer_last_page"));
49 ui->playButton->setIcon(QIcon::fromTheme("camera_playback"));
50 ui->stopButton->setIcon(QIcon::fromTheme("camera_video_stop"));
51 ui->pauseButton->setIcon(QIcon::fromTheme("camera_video_pause"));
52 ui->fullscreenButton->setIcon(QIcon::fromTheme("general_fullsize"));
53 ui->volDown->setIcon(QIcon::fromTheme("statusarea_volumelevel1"));
54 ui->volUp->setIcon(QIcon::fromTheme("statusarea_volumelevel4"));
55 ui->volMute->setIcon(QIcon::fromTheme("statusarea_volume_mute"));
58 #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
59 mPlayListMainWindow->setParent(this);
60 mPlayListMainWindow->setAttribute(Qt::WA_Maemo5StackedWindow);
61 mPlayListMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true);
62 mPlayListMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true);
63 setAttribute(Qt::WA_Maemo5StackedWindow);
64 mPlayListMainWindow->setWindowFlags(mPlayListMainWindow->windowFlags() | Qt::Window);
66 mBrowserMainWindow->setParent(this);
67 mBrowserMainWindow->setAttribute(Qt::WA_Maemo5StackedWindow);
68 mBrowserMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true);
69 mBrowserMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true);
70 setAttribute(Qt::WA_Maemo5StackedWindow);
71 mBrowserMainWindow->setWindowFlags(mBrowserMainWindow->windowFlags() | Qt::Window);
75 connect(mTimer,SIGNAL(timeout()),this,SLOT(askStatus()));
76 connect(ui->actionConfiguration,SIGNAL(triggered()),this,SLOT(showConfig()));
77 connect(ui->actionAbout,SIGNAL(triggered()),this,SLOT(showAbout()));
78 connect(ui->playlistButton,SIGNAL(clicked()),mPlayListMainWindow,SLOT(show()));
79 connect(ui->playlistButton,SIGNAL(clicked()),mPlayListMainWindow,SLOT(showPlayList()));
80 connect(ui->browseButton,SIGNAL(clicked()),mBrowserMainWindow,SLOT(show()));
81 connect(ui->browseButton,SIGNAL(clicked()),mBrowserMainWindow,SLOT(showCurrentDirectory()));
83 connect(ui->playButton,SIGNAL(clicked()),this,SLOT(play()));
84 connect(ui->stopButton,SIGNAL(clicked()),this,SLOT(stop()));
85 connect(ui->pauseButton,SIGNAL(clicked()),this,SLOT(pause()));
86 connect(ui->previousButton,SIGNAL(clicked()),this,SLOT(previous()));
87 connect(ui->nextButton,SIGNAL(clicked()),this,SLOT(next()));
88 connect(ui->fullscreenButton,SIGNAL(clicked()),this,SLOT(fullscreen()));
89 connect(ui->volUp,SIGNAL(clicked()),this,SLOT(volUp()));
90 connect(ui->volDown,SIGNAL(clicked()),this,SLOT(volDown()));
91 connect(ui->volMute,SIGNAL(clicked()),this,SLOT(volMute()));
92 connect(ui->slider,SIGNAL(sliderMoved(int)),this,SLOT(slide(int)));
97 void PlayerMainWindow::init()
100 mIp= AccountDialog::currentIp();
108 mPlayListMainWindow->init();
109 mBrowserMainWindow->init();
114 PlayerMainWindow::~PlayerMainWindow()
119 void PlayerMainWindow::changeEvent(QEvent *e)
121 QMainWindow::changeEvent(e);
123 case QEvent::LanguageChange:
124 ui->retranslateUi(this);
131 void PlayerMainWindow::play()
134 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_play")));
137 void PlayerMainWindow::stop()
139 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_stop")));
142 void PlayerMainWindow::pause()
144 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_pause")));
147 void PlayerMainWindow::previous()
149 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_previous")));
152 void PlayerMainWindow::next()
154 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_next")));
157 void PlayerMainWindow::fullscreen()
159 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=fullscreen")));
162 void PlayerMainWindow::volUp()
164 QUrl url = QUrl("http://"+mIp+"/requests/status.xml?command=volume");
165 url.addEncodedQueryItem(QByteArray("val"), QByteArray("%2B20"));
166 mNetManager->get(QNetworkRequest(url));
168 void PlayerMainWindow::volDown()
171 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val=-20")));
174 void PlayerMainWindow::volMute()
176 this->mMuted = !this->mMuted;
178 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val=0")));
181 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val="+QString::number(this->mVolume))));
185 void PlayerMainWindow::slide(int value)
187 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=seek&val="+QString::number(value)+"%25")));
191 void PlayerMainWindow::showConfig()
194 AccountDialog * dialog = new AccountDialog;
201 void PlayerMainWindow::showAbout()
204 AboutDialog * dialog = new AboutDialog;
209 void PlayerMainWindow::askStatus()
212 QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml")));
213 connect(reply,SIGNAL(readyRead()),this,SLOT(parseXmlStatus()));
216 void PlayerMainWindow::parseXmlStatus()
218 QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender());
220 doc.setContent(reply->readAll());
221 QDomElement docElem = doc.documentElement();
223 int volume = docElem.namedItem("volume").toElement().text().toInt();
224 int length = docElem.namedItem("length").toElement().text().toInt();
225 int time = docElem.namedItem("time").toElement().text().toInt();
226 int position = docElem.namedItem("position").toElement().text().toInt();
227 QString state =docElem.namedItem("state").toElement().text();
231 this->mVolume = volume;
232 this->mMuted = false;
239 QTime timeLength(0,0,0) ;
240 timeLength = timeLength.addSecs(time);
242 ui->timeLabel->setText(timeLength.toString("mm:ss"));
245 QDomNode infoNode = docElem.namedItem("information");
246 QDomNode metaInfoNode = infoNode.namedItem("meta-information");
247 QString title = metaInfoNode.namedItem("title").toElement().text();
249 if ( position >= 0 && position <=100)
250 ui->slider->setValue(position);
252 ui->label->setText(title);