1 |
#include "MainView.h" |
#include "MainView.h" |
2 |
|
#include <QApplication> |
3 |
#include <QPushButton> |
#include <QPushButton> |
4 |
|
#include <QLabel> |
5 |
#include <QVBoxLayout> |
#include <QVBoxLayout> |
6 |
|
|
7 |
#include <QTimer> |
#include <QTimer> |
8 |
|
#include <QKeyEvent> |
9 |
|
#include <QSettings> |
10 |
|
#include <QMessageBox> |
11 |
|
|
12 |
|
#include "MyWebView.h" |
13 |
|
#include "clientsiderender.h" |
14 |
|
#include "pictureview.h" |
15 |
|
#include "videoview.h" |
16 |
|
|
17 |
#include <VideoPlayer> //Phonon |
#include "httpwrapper.h" |
|
#include <MediaObject> //Phonon |
|
|
#include <MediaSource> //Phonon |
|
18 |
|
|
|
#include <iostream> |
|
|
using namespace std; |
|
19 |
|
|
|
Phonon::VideoPlayer* video = 0; |
|
20 |
MainView::MainView(QWidget* parent) |
MainView::MainView(QWidget* parent) |
21 |
: QWidget(parent) |
: QWidget(parent), timer(0) |
22 |
{ |
{ |
|
this->resize(400,400); |
|
|
//this->setWindowState( Qt::WindowFullScreen ); |
|
23 |
|
|
24 |
|
settings = new QSettings("Caddi", "infoscreen"); |
25 |
|
url = settings->value("url").toString(); |
26 |
|
bool xmlMode = settings->value("xml").toBool(); |
27 |
|
screenid = settings->value("screenid").toString(); |
28 |
|
|
29 |
/* red = new QWidget(this); |
if (url == "" || screenid == "") { |
30 |
red->setStyleSheet("QWidget { background-color: red; }"); |
QMessageBox::warning(this,"infoscreen","Could not find url or screenid in config file " + settings->fileName()); |
31 |
|
|
32 |
green = new QWidget(this); |
exit(1); //Normal qApp->exit() doesn't terminate the init sequence so use std C exit function |
33 |
green->setStyleSheet("QWidget { background-color: green; }"); |
} |
|
green->setVisible(false); |
|
34 |
|
|
|
current = red;*/ |
|
|
|
|
|
video = new Phonon::VideoPlayer(Phonon::VideoCategory, this); |
|
|
Phonon::MediaSource* source = new Phonon::MediaSource("http://todic.dk/ps3cache/Inglourious_Basterds_2009.avi"); |
|
|
|
|
|
video->load( *source ); |
|
|
|
|
35 |
|
|
36 |
|
|
37 |
QVBoxLayout* layout = new QVBoxLayout(); |
this->resize(400,400); |
38 |
//layout->addWidget(red,1 ); |
this->setWindowState( Qt::WindowFullScreen ); |
39 |
//layout->addWidget(green,1); |
this->grabKeyboard(); |
|
layout->addWidget(video,1); |
|
|
layout->addStretch(); |
|
|
layout->setContentsMargins(0,0,0,0); |
|
|
setLayout(layout); |
|
40 |
|
|
41 |
|
qApp->setOverrideCursor( QCursor( Qt::BlankCursor) ); |
42 |
|
|
43 |
|
render = new ClientSideRender(this); |
44 |
|
render->setVisible( false ); |
45 |
|
|
46 |
QTimer* timer = new QTimer(this); |
web = new MyWebView(this); |
47 |
connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); |
web->setVisible( false); |
48 |
timer->start(1000); |
|
49 |
|
picture = new PictureView(this); |
50 |
|
picture->setVisible( false ); |
51 |
|
|
52 |
|
video = new VideoView(this); |
53 |
|
video->setVisible(false); |
54 |
|
|
55 |
|
QVBoxLayout* layout = new QVBoxLayout(); |
56 |
|
layout->addWidget(web,1); |
57 |
|
layout->addWidget(render,1); |
58 |
|
layout->addWidget(picture,1); |
59 |
|
layout->addWidget(video,1); |
60 |
|
layout->addStretch(); |
61 |
|
layout->setContentsMargins(0,0,0,0); |
62 |
|
setLayout(layout); |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
if (xmlMode == true) { |
68 |
|
xmlUrl = url + "?screen_id=" + screenid; |
69 |
|
qDebug() << "Starting XML mode"; |
70 |
|
qDebug() << "xmlUrl" << xmlUrl; |
71 |
|
|
72 |
|
timer = new QTimer(this); |
73 |
|
connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); |
74 |
|
timer->start(100); |
75 |
|
} else { |
76 |
|
qDebug() << "Starting plain browser mode"; |
77 |
|
web->setVisible(true); |
78 |
|
web->start(url,screenid); |
79 |
|
} |
80 |
} |
} |
81 |
|
|
82 |
|
void MainView::closeEvent ( QCloseEvent * event ) |
83 |
|
{ |
84 |
|
Q_UNUSED(event); |
85 |
|
exit(0); //force application shutdown |
86 |
|
} |
87 |
|
|
88 |
|
void MainView::keyPressEvent ( QKeyEvent* event ) |
89 |
|
{ |
90 |
|
int key = event->key(); |
91 |
|
if (key == ' ' || key == Qt::Key_Return || key == Qt::Key_Enter) { |
92 |
|
close(); |
93 |
|
} |
94 |
|
} |
95 |
|
|
96 |
void MainView::onTimer() |
void MainView::onTimer() |
97 |
{ |
{ |
98 |
cout << "timer" << endl; |
screenManager.timerTick(); |
99 |
if (!video->isPlaying() ) { |
|
100 |
video->play(); |
readXml(); |
101 |
cout << "starting" << endl; |
|
102 |
} |
switchScreens(); |
103 |
|
} |
104 |
/* |
|
105 |
if( current == red) { |
|
106 |
red->setVisible(false); |
bool MainView::readXml() |
107 |
green->setVisible(true); |
{ |
108 |
current = green; |
const int TIMEOUT = 30*60*1000; // 30 minutter |
109 |
} else { |
if ( lastXml.isNull() || lastXml.elapsed() > TIMEOUT) { |
110 |
red->setVisible(true); |
|
111 |
green->setVisible(false); |
|
112 |
current = red; |
bool res = xmlHandler.readXml( xmlUrl ); |
113 |
}*/ |
|
114 |
|
lastXml = QTime::currentTime(); |
115 |
|
|
116 |
|
screenItems = xmlHandler.getScreenSet(); |
117 |
|
|
118 |
|
if ( currentItemIdx >= screenItems.size() ) |
119 |
|
currentItemIdx = screenItems.size()-1; //avoid overflow |
120 |
|
|
121 |
|
|
122 |
|
return true; |
123 |
|
} else { |
124 |
|
return false; |
125 |
|
} |
126 |
|
} |
127 |
|
|
128 |
|
void MainView::switchScreens() |
129 |
|
{ |
130 |
|
if (video->isVisible() && video->isPlaying() ) { |
131 |
|
return; //wait until current clip has finished |
132 |
|
} |
133 |
|
|
134 |
|
if (lastScreenSwitch.isNull() || lastScreenSwitch.elapsed() > (currentItem.runtime*1000)) { |
135 |
|
|
136 |
|
QTime now = QTime::currentTime(); |
137 |
|
if (lastScreenSwitch.isNull()) |
138 |
|
currentItemIdx = -1; |
139 |
|
|
140 |
|
bool found = false; |
141 |
|
int tries = 0; |
142 |
|
|
143 |
|
if (screenItems.size() > 0) { //only try if we have a any screens |
144 |
|
while (found == false && tries <= screenItems.size()) { //find next with valid display time |
145 |
|
tries++; |
146 |
|
currentItemIdx = (currentItemIdx+1) % screenItems.size(); |
147 |
|
currentItem = screenItems.at(currentItemIdx); |
148 |
|
|
149 |
|
if (currentItem.start <= now && now <= currentItem.stop ) |
150 |
|
found = true; |
151 |
|
} |
152 |
|
} |
153 |
|
|
154 |
|
if (found) { |
155 |
|
|
156 |
|
if (currentItem.module == "info_image") { |
157 |
|
ensureVisible(picture); |
158 |
|
|
159 |
|
picture->loadFromUrl( currentItem.url ); |
160 |
|
|
161 |
|
} |
162 |
|
if (currentItem.module == "info_web") { |
163 |
|
ensureVisible(web); |
164 |
|
web->load(currentItem.url); |
165 |
|
} |
166 |
|
if (currentItem.module == "info_video") { |
167 |
|
ensureVisible(video); |
168 |
|
video->loadUrl(currentItem.url); |
169 |
|
} |
170 |
|
|
171 |
|
errorInfoScreen("Unknown module: " + currentItem.module ); |
172 |
|
|
173 |
|
} else { |
174 |
|
qDebug() << "no screen"; |
175 |
|
errorInfoScreen("Der er ingen information at vise"); |
176 |
|
} |
177 |
|
lastScreenSwitch = QTime::currentTime(); |
178 |
|
|
179 |
|
} |
180 |
|
} |
181 |
|
|
182 |
|
void MainView::errorInfoScreen(QString msg) |
183 |
|
{ |
184 |
|
ensureVisible(web); |
185 |
|
web->setHtml("<html>\ |
186 |
|
<body text='#505050' bgcolor='#000000'>\ |
187 |
|
<table width='100%' height='100%'><tr><td align='center' valign='middel'><h1>" + msg+ "</h1></td></tr></table>\ |
188 |
|
</body></html>"); |
189 |
|
} |
190 |
|
|
191 |
|
void MainView::ensureVisible(QWidget* widget) |
192 |
|
{ |
193 |
|
if (! widget->isVisible()) { |
194 |
|
hideAll(); |
195 |
|
widget->setVisible(true); |
196 |
|
} |
197 |
|
} |
198 |
|
|
199 |
|
void MainView::hideAll() |
200 |
|
{ |
201 |
|
render->setVisible( false ); |
202 |
|
web->setVisible( false); |
203 |
|
picture->setVisible( false ); |
204 |
|
video->setVisible(false); |
205 |
} |
} |