6 |
|
|
7 |
#include <QTimer> |
#include <QTimer> |
8 |
|
|
|
//#include <VideoPlayer> //Phonon |
|
|
//#include <MediaSource> //Phonon |
|
|
|
|
9 |
#include "MyWebView.h" |
#include "MyWebView.h" |
10 |
#include "clientsiderender.h" |
#include "clientsiderender.h" |
11 |
|
#include "pictureview.h" |
12 |
|
#include "videoview.h" |
13 |
|
|
14 |
|
#include "httpwrapper.h" |
15 |
|
|
16 |
|
|
17 |
MainView::MainView(QWidget* parent) |
MainView::MainView(QWidget* parent) |
20 |
this->resize(400,400); |
this->resize(400,400); |
21 |
this->setWindowState( Qt::WindowFullScreen ); |
this->setWindowState( Qt::WindowFullScreen ); |
22 |
|
|
23 |
// qApp->setOverrideCursor( QCursor( Qt::BlankCursor) ); |
qApp->setOverrideCursor( QCursor( Qt::BlankCursor) ); |
|
|
|
|
|
|
|
//Phonon::VideoPlayer* video; |
|
|
//video = new Phonon::VideoPlayer(Phonon::VideoCategory, this); |
|
|
//video->load( Phonon::MediaSource("http://todic.dk/ps3cache/Inglourious_Basterds_2009.avi") ); |
|
|
//layout->addWidget(video,1); |
|
|
//video->play(); |
|
24 |
|
|
25 |
render = new ClientSideRender(this); |
render = new ClientSideRender(this); |
26 |
render->setVisible( false ); |
render->setVisible( false ); |
27 |
|
|
28 |
web = new MyWebView(this); |
web = new MyWebView(this); |
29 |
web->setVisible( true); |
web->setVisible( false); |
30 |
|
|
31 |
|
picture = new PictureView(this); |
32 |
|
picture->setVisible( false ); |
33 |
|
|
34 |
|
video = new VideoView(this); |
35 |
|
video->setVisible(false); |
36 |
|
|
37 |
QVBoxLayout* layout = new QVBoxLayout(); |
QVBoxLayout* layout = new QVBoxLayout(); |
38 |
layout->addWidget(web,1); |
layout->addWidget(web,1); |
39 |
layout->addWidget(render,1); |
layout->addWidget(render,1); |
40 |
|
layout->addWidget(picture,1); |
41 |
|
layout->addWidget(video,1); |
42 |
layout->addStretch(); |
layout->addStretch(); |
43 |
layout->setContentsMargins(0,0,0,0); |
layout->setContentsMargins(0,0,0,0); |
44 |
setLayout(layout); |
setLayout(layout); |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
QTimer* timer = new QTimer(this); |
QTimer* timer = new QTimer(this); |
49 |
connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); |
connect(timer, SIGNAL(timeout() ), this, SLOT(onTimer() )); |
50 |
timer->start(1000); |
timer->start(100); |
51 |
|
|
|
web->start(); |
|
52 |
} |
} |
53 |
|
|
54 |
|
|
55 |
void MainView::onTimer() |
void MainView::onTimer() |
56 |
{ |
{ |
57 |
screenManager.timerTick(); |
screenManager.timerTick(); |
58 |
|
|
59 |
|
readXml(); |
60 |
|
|
61 |
|
switchScreens(); |
62 |
|
} |
63 |
|
|
64 |
|
|
65 |
|
bool MainView::readXml() |
66 |
|
{ |
67 |
|
const int TIMEOUT = 30*60*1000; // 30 minutter |
68 |
|
if ( lastXml.isNull() || lastXml.elapsed() > TIMEOUT) { |
69 |
|
|
70 |
|
xmlHandler.readXml( "http://infoscreen.sundhedhorsens.dk/infoscreen/screen_xml.php?screen_id=1" ); |
71 |
|
|
72 |
|
lastXml = QTime::currentTime(); |
73 |
|
|
74 |
|
screenItems = xmlHandler.getScreenSet(); |
75 |
|
|
76 |
|
if ( currentItemIdx >= screenItems.size() ) |
77 |
|
currentItemIdx = screenItems.size()-1; //avoid overflow |
78 |
|
|
79 |
|
|
80 |
|
return true; |
81 |
|
} else { |
82 |
|
return false; |
83 |
|
} |
84 |
|
} |
85 |
|
|
86 |
|
void MainView::switchScreens() |
87 |
|
{ |
88 |
|
|
89 |
|
if (lastScreenSwitch.isNull() || lastScreenSwitch.elapsed() > (currentItem.runtime*1000)) { |
90 |
|
|
91 |
|
QTime now = QTime::currentTime(); |
92 |
|
if (lastScreenSwitch.isNull()) |
93 |
|
currentItemIdx = -1; |
94 |
|
|
95 |
|
bool found = false; |
96 |
|
int tries = 0; |
97 |
|
|
98 |
|
|
99 |
|
while (found == false && tries <= screenItems.size()) { //find next with valid display time |
100 |
|
tries++; |
101 |
|
currentItemIdx = (currentItemIdx+1) % screenItems.size(); |
102 |
|
currentItem = screenItems.at(currentItemIdx); |
103 |
|
|
104 |
|
if (currentItem.start <= now && now <= currentItem.stop ) |
105 |
|
found = true; |
106 |
|
} |
107 |
|
|
108 |
|
if (found) { |
109 |
|
|
110 |
|
if (currentItem.module == "info_image") { |
111 |
|
ensureVisible(picture); |
112 |
|
|
113 |
|
picture->loadFromUrl( currentItem.url ); |
114 |
|
|
115 |
|
} |
116 |
|
|
117 |
|
|
118 |
|
} else { |
119 |
|
qDebug() << "no screen"; |
120 |
|
hideAll(); |
121 |
|
} |
122 |
|
lastScreenSwitch = QTime::currentTime(); |
123 |
|
|
124 |
|
} |
125 |
|
} |
126 |
|
|
127 |
|
void MainView::ensureVisible(QWidget* widget) |
128 |
|
{ |
129 |
|
if (! widget->isVisible()) { |
130 |
|
hideAll(); |
131 |
|
widget->setVisible(true); |
132 |
|
} |
133 |
|
} |
134 |
|
|
135 |
|
void MainView::hideAll() |
136 |
|
{ |
137 |
|
render->setVisible( false ); |
138 |
|
web->setVisible( false); |
139 |
|
picture->setVisible( false ); |
140 |
|
video->setVisible(false); |
141 |
} |
} |