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"
26 PlayerMainWindow::PlayerMainWindow(QWidget *parent) :
28 ui(new Ui::PlayerMainWindow)
31 setWindowTitle("Vlc remote");
34 mIp = settings.value("ip").toString();
40 mTimer = new QTimer(this);
41 mNetManager = new QNetworkAccessManager(this);
42 mPlayListMainWindow = new PlayListMainWindow;
45 ui->playlistButton->setIcon(QIcon::fromTheme("notes_bullets"));
46 ui->previousButton->setIcon(QIcon::fromTheme("pdf_viewer_first_page"));
47 ui->nextButton->setIcon(QIcon::fromTheme("pdf_viewer_last_page"));
48 ui->playButton->setIcon(QIcon::fromTheme("camera_playback"));
49 ui->stopButton->setIcon(QIcon::fromTheme("camera_video_stop"));
50 ui->pauseButton->setIcon(QIcon::fromTheme("camera_video_pause"));
51 ui->fullscreenButton->setIcon(QIcon::fromTheme("general_fullsize"));
52 ui->volDown->setIcon(QIcon::fromTheme("statusarea_volumelevel1"));
53 ui->volUp->setIcon(QIcon::fromTheme("statusarea_volumelevel4"));
55 #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
56 mPlayListMainWindow->setParent(this);
57 mPlayListMainWindow->setAttribute(Qt::WA_Maemo5StackedWindow);
58 mPlayListMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true);
59 mPlayListMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true);
60 setAttribute(Qt::WA_Maemo5StackedWindow);
61 mPlayListMainWindow->setWindowFlags(mPlayListMainWindow->windowFlags() | Qt::Window);
64 connect(mTimer,SIGNAL(timeout()),this,SLOT(askStatus()));
65 connect(ui->actionConfiguration,SIGNAL(triggered()),this,SLOT(showConfig()));
66 connect(ui->actionAbout,SIGNAL(triggered()),this,SLOT(showAbout()));
67 connect(ui->playlistButton,SIGNAL(clicked()),mPlayListMainWindow,SLOT(show()));
68 connect(ui->playButton,SIGNAL(clicked()),this,SLOT(play()));
69 connect(ui->stopButton,SIGNAL(clicked()),this,SLOT(stop()));
70 connect(ui->pauseButton,SIGNAL(clicked()),this,SLOT(pause()));
71 connect(ui->previousButton,SIGNAL(clicked()),this,SLOT(previous()));
72 connect(ui->nextButton,SIGNAL(clicked()),this,SLOT(next()));
73 connect(ui->fullscreenButton,SIGNAL(clicked()),this,SLOT(fullscreen()));
74 connect(ui->volUp,SIGNAL(clicked()),this,SLOT(volUp()));
75 connect(ui->volDown,SIGNAL(clicked()),this,SLOT(volDown()));
76 connect(ui->slider,SIGNAL(sliderMoved(int)),this,SLOT(slide(int)));
82 PlayerMainWindow::~PlayerMainWindow()
87 void PlayerMainWindow::changeEvent(QEvent *e)
89 QMainWindow::changeEvent(e);
91 case QEvent::LanguageChange:
92 ui->retranslateUi(this);
99 void PlayerMainWindow::play()
102 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_play")));
105 void PlayerMainWindow::stop()
107 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_stop")));
110 void PlayerMainWindow::pause()
112 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_pause")));
115 void PlayerMainWindow::previous()
117 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_previous")));
120 void PlayerMainWindow::next()
122 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_next")));
125 void PlayerMainWindow::fullscreen()
127 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=fullscreen")));
130 void PlayerMainWindow::volUp()
132 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val=500")));
135 void PlayerMainWindow::volDown()
138 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val=-20")));
141 void PlayerMainWindow::slide(int value)
143 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=seek&val="+QString::number(value)+"%25")));
147 void PlayerMainWindow::showConfig()
149 // ConfigDialog * dialog = new AccountDialog;
152 void PlayerMainWindow::showAbout()
155 AboutDialog * dialog = new AboutDialog;
161 void PlayerMainWindow::askStatus()
164 QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml")));
165 connect(reply,SIGNAL(readyRead()),this,SLOT(parseXmlStatus()));
167 void PlayerMainWindow::parseXmlStatus()
169 QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender());
171 doc.setContent(reply->readAll());
172 QDomElement docElem = doc.documentElement();
174 int volume = docElem.namedItem("volume").toElement().text().toInt();
175 int length = docElem.namedItem("length").toElement().text().toInt();
176 int time = docElem.namedItem("time").toElement().text().toInt();
177 int position = docElem.namedItem("position").toElement().text().toInt();
178 QString state =docElem.namedItem("state").toElement().text();
180 QTime timeLength(0,0,0) ;
181 timeLength = timeLength.addSecs(time);
183 ui->timeLabel->setText(timeLength.toString("mm:ss"));
186 QDomNode infoNode = docElem.namedItem("information");
187 QDomNode metaInfoNode = infoNode.namedItem("meta-information");
188 QString title = metaInfoNode.namedItem("title").toElement().text();
190 if ( position >= 0 && position <=100)
191 ui->slider->setValue(position);
193 ui->label->setText(title);