3 #include "playermainwindow.h"
4 #include "ui_playermainwindow.h"
5 #include "configdialog.h"
6 #include "aboutdialog.h"
8 PlayerMainWindow::PlayerMainWindow(QWidget *parent) :
10 ui(new Ui::PlayerMainWindow)
15 mIp = settings.value("ip").toString();
21 mTimer = new QTimer(this);
22 mNetManager = new QNetworkAccessManager(this);
23 mPlayListMainWindow = new PlayListMainWindow;
26 ui->playlistButton->setIcon(QIcon::fromTheme("notes_bullets"));
27 ui->previousButton->setIcon(QIcon::fromTheme("pdf_viewer_first_page"));
28 ui->nextButton->setIcon(QIcon::fromTheme("pdf_viewer_last_page"));
29 ui->playButton->setIcon(QIcon::fromTheme("camera_playback"));
30 ui->stopButton->setIcon(QIcon::fromTheme("camera_video_stop"));
31 ui->pauseButton->setIcon(QIcon::fromTheme("camera_video_pause"));
32 ui->fullscreenButton->setIcon(QIcon::fromTheme("general_fullsize"));
33 ui->volDown->setIcon(QIcon::fromTheme("statusarea_volumelevel1"));
34 ui->volUp->setIcon(QIcon::fromTheme("statusarea_volumelevel4"));
36 #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
37 mPlayListMainWindow->setParent(this);
38 mPlayListMainWindow->setAttribute(Qt::WA_Maemo5StackedWindow);
39 mPlayListMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true);
40 mPlayListMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true);
41 setAttribute(Qt::WA_Maemo5StackedWindow);
42 mPlayListMainWindow->setWindowFlags(mPlayListMainWindow->windowFlags() | Qt::Window);
45 connect(mTimer,SIGNAL(timeout()),this,SLOT(askStatus()));
46 connect(ui->actionConfiguration,SIGNAL(triggered()),this,SLOT(showConfig()));
47 connect(ui->actionAbout,SIGNAL(triggered()),this,SLOT(showAbout()));
48 connect(ui->playlistButton,SIGNAL(clicked()),mPlayListMainWindow,SLOT(show()));
49 connect(ui->playButton,SIGNAL(clicked()),this,SLOT(play()));
50 connect(ui->stopButton,SIGNAL(clicked()),this,SLOT(stop()));
51 connect(ui->pauseButton,SIGNAL(clicked()),this,SLOT(pause()));
52 connect(ui->previousButton,SIGNAL(clicked()),this,SLOT(previous()));
53 connect(ui->nextButton,SIGNAL(clicked()),this,SLOT(next()));
54 connect(ui->fullscreenButton,SIGNAL(clicked()),this,SLOT(fullscreen()));
55 connect(ui->volUp,SIGNAL(clicked()),this,SLOT(volUp()));
56 connect(ui->volDown,SIGNAL(clicked()),this,SLOT(volDown()));
57 connect(ui->slider,SIGNAL(sliderMoved(int)),this,SLOT(slide(int)));
63 PlayerMainWindow::~PlayerMainWindow()
68 void PlayerMainWindow::changeEvent(QEvent *e)
70 QMainWindow::changeEvent(e);
72 case QEvent::LanguageChange:
73 ui->retranslateUi(this);
80 void PlayerMainWindow::play()
83 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_play")));
86 void PlayerMainWindow::stop()
88 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_stop")));
91 void PlayerMainWindow::pause()
93 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_pause")));
96 void PlayerMainWindow::previous()
98 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_previous")));
101 void PlayerMainWindow::next()
103 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_next")));
106 void PlayerMainWindow::fullscreen()
108 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=fullscreen")));
111 void PlayerMainWindow::volUp()
113 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val=500")));
116 void PlayerMainWindow::volDown()
119 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val=-20")));
122 void PlayerMainWindow::slide(int value)
124 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=seek&val="+QString::number(value)+"%25")));
128 void PlayerMainWindow::showConfig()
130 ConfigDialog * dialog = new ConfigDialog;
133 void PlayerMainWindow::showAbout()
136 AboutDialog * dialog = new AboutDialog;
142 void PlayerMainWindow::askStatus()
145 QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml")));
146 connect(reply,SIGNAL(readyRead()),this,SLOT(parseXmlStatus()));
148 void PlayerMainWindow::parseXmlStatus()
150 QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender());
152 doc.setContent(reply->readAll());
153 QDomElement docElem = doc.documentElement();
155 int volume = docElem.namedItem("volume").toElement().text().toInt();
156 int length = docElem.namedItem("length").toElement().text().toInt();
157 int time = docElem.namedItem("time").toElement().text().toInt();
158 int position = docElem.namedItem("position").toElement().text().toInt();
159 QString state =docElem.namedItem("state").toElement().text();
161 QTime timeLength(0,0,0) ;
162 timeLength = timeLength.addSecs(time);
164 ui->timeLabel->setText(timeLength.toString("mm:ss"));
167 QDomNode infoNode = docElem.namedItem("information");
168 QDomNode metaInfoNode = infoNode.namedItem("meta-information");
169 QString title = metaInfoNode.namedItem("title").toElement().text();
171 if ( position >= 0 && position <=100)
172 ui->slider->setValue(position);
174 ui->label->setText(title);