5 |
#include <QVBoxLayout> |
#include <QVBoxLayout> |
6 |
|
|
7 |
#include <QTimer> |
#include <QTimer> |
8 |
|
#include <QKeyEvent> |
9 |
#include <VideoPlayer> //Phonon |
#include <QSettings> |
10 |
#include <MediaSource> //Phonon |
#include <QMessageBox> |
11 |
|
|
12 |
#include "MyWebView.h" |
#include "MyWebView.h" |
13 |
|
#include "clientsiderender.h" |
14 |
|
#include "pictureview.h" |
15 |
|
#include "videoview.h" |
16 |
|
|
17 |
|
#include "httpwrapper.h" |
18 |
|
|
19 |
|
|
20 |
MainView::MainView(QWidget* parent) |
MainView::MainView(QWidget* parent) |
21 |
: QWidget(parent) |
: QWidget(parent) |
22 |
{ |
{ |
|
this->setWindowState( Qt::WindowFullScreen ); |
|
|
qApp->setOverrideCursor( QCursor( Qt::BlankCursor) ); |
|
23 |
|
|
24 |
|
settings = new QSettings("Caddi", "infoscreen"); |
25 |
//Phonon::VideoPlayer* video; |
url = settings->value("url").toString(); |
26 |
//video = new Phonon::VideoPlayer(Phonon::VideoCategory, this); |
bool xmlMode = settings->value("xml").toBool(); |
27 |
//video->load( Phonon::MediaSource("http://todic.dk/ps3cache/Inglourious_Basterds_2009.avi") ); |
screenid = settings->value("screenid").toString(); |
28 |
//layout->addWidget(video,1); |
|
29 |
//video->play(); |
if (url == "" || screenid == "") { |
30 |
|
QMessageBox::warning(this,"infoscreen","Could not find url or screenid in config file " + settings->fileName()); |
31 |
web = new MyWebView(this); |
|
32 |
|
exit(1); //Normal qApp->exit() doesn't terminate the init sequence so use std C exit function |
33 |
QVBoxLayout* layout = new QVBoxLayout(); |
} |
34 |
layout->addWidget(web,1); |
|
35 |
|
|
36 |
layout->addStretch(); |
|
37 |
layout->setContentsMargins(0,0,0,0); |
this->resize(400,400); |
38 |
setLayout(layout); |
this->setWindowState( Qt::WindowFullScreen ); |
39 |
|
this->grabKeyboard(); |
40 |
QTimer* timer = new QTimer(this); |
|
41 |
connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); |
qApp->setOverrideCursor( QCursor( Qt::BlankCursor) ); |
42 |
timer->start(1000); |
|
43 |
|
render = new ClientSideRender(this); |
44 |
|
render->setVisible( false ); |
45 |
web->start(); |
|
46 |
|
web = new MyWebView(this); |
47 |
|
web->setVisible( false); |
48 |
|
|
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 |
|
QTimer* 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 |
} |
} |
83 |
|
|
84 |
|
void MainView::keyPressEvent ( QKeyEvent* event ) |
85 |
|
{ |
86 |
|
int key = event->key(); |
87 |
|
if (key == ' ' || key == Qt::Key_Return || key == Qt::Key_Enter) { |
88 |
|
qApp->quit(); |
89 |
|
} |
90 |
|
} |
91 |
|
|
92 |
void MainView::onTimer() |
void MainView::onTimer() |
93 |
{ |
{ |
94 |
screenManager.timerTick(); |
screenManager.timerTick(); |
95 |
|
|
96 |
|
readXml(); |
97 |
|
|
98 |
|
switchScreens(); |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
bool MainView::readXml() |
103 |
|
{ |
104 |
|
const int TIMEOUT = 30*60*1000; // 30 minutter |
105 |
|
if ( lastXml.isNull() || lastXml.elapsed() > TIMEOUT) { |
106 |
|
|
107 |
|
|
108 |
|
xmlHandler.readXml( xmlUrl ); |
109 |
|
|
110 |
|
lastXml = QTime::currentTime(); |
111 |
|
|
112 |
|
screenItems = xmlHandler.getScreenSet(); |
113 |
|
|
114 |
|
if ( currentItemIdx >= screenItems.size() ) |
115 |
|
currentItemIdx = screenItems.size()-1; //avoid overflow |
116 |
|
|
117 |
|
|
118 |
|
return true; |
119 |
|
} else { |
120 |
|
return false; |
121 |
|
} |
122 |
|
} |
123 |
|
|
124 |
|
void MainView::switchScreens() |
125 |
|
{ |
126 |
|
|
127 |
|
if (lastScreenSwitch.isNull() || lastScreenSwitch.elapsed() > (currentItem.runtime*1000)) { |
128 |
|
|
129 |
|
QTime now = QTime::currentTime(); |
130 |
|
if (lastScreenSwitch.isNull()) |
131 |
|
currentItemIdx = -1; |
132 |
|
|
133 |
|
bool found = false; |
134 |
|
int tries = 0; |
135 |
|
|
136 |
|
if (screenItems.size() > 0) { //only try if we have a any screens |
137 |
|
while (found == false && tries <= screenItems.size()) { //find next with valid display time |
138 |
|
tries++; |
139 |
|
currentItemIdx = (currentItemIdx+1) % screenItems.size(); |
140 |
|
currentItem = screenItems.at(currentItemIdx); |
141 |
|
|
142 |
|
if (currentItem.start <= now && now <= currentItem.stop ) |
143 |
|
found = true; |
144 |
|
} |
145 |
|
} |
146 |
|
|
147 |
|
if (found) { |
148 |
|
|
149 |
|
if (currentItem.module == "info_image") { |
150 |
|
ensureVisible(picture); |
151 |
|
|
152 |
|
picture->loadFromUrl( currentItem.url ); |
153 |
|
|
154 |
|
} |
155 |
|
|
156 |
|
|
157 |
|
} else { |
158 |
|
qDebug() << "no screen"; |
159 |
|
hideAll(); |
160 |
|
} |
161 |
|
lastScreenSwitch = QTime::currentTime(); |
162 |
|
|
163 |
|
} |
164 |
|
} |
165 |
|
|
166 |
|
void MainView::ensureVisible(QWidget* widget) |
167 |
|
{ |
168 |
|
if (! widget->isVisible()) { |
169 |
|
hideAll(); |
170 |
|
widget->setVisible(true); |
171 |
|
} |
172 |
|
} |
173 |
|
|
174 |
|
void MainView::hideAll() |
175 |
|
{ |
176 |
|
render->setVisible( false ); |
177 |
|
web->setVisible( false); |
178 |
|
picture->setVisible( false ); |
179 |
|
video->setVisible(false); |
180 |
} |
} |