11 |
#include "pictureview.h" |
#include "pictureview.h" |
12 |
#include "videoview.h" |
#include "videoview.h" |
13 |
|
|
14 |
|
#include "httpwrapper.h" |
15 |
|
|
16 |
|
|
17 |
MainView::MainView(QWidget* parent) |
MainView::MainView(QWidget* parent) |
18 |
: QWidget(parent) |
: QWidget(parent) |
19 |
{ |
{ |
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 |
{ |
{ |
|
static int count = 0; |
|
57 |
screenManager.timerTick(); |
screenManager.timerTick(); |
58 |
|
|
59 |
//if (count == 0) |
readXml(); |
60 |
// video->loadUrl(""); |
|
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 |
|
qDebug() << "reread"; |
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 ( (count%10) == 0) { |
if (lastScreenSwitch.isNull() || lastScreenSwitch.elapsed() > (currentItem.runtime*1000)) { |
90 |
|
|
91 |
int t = count / 10; |
if (lastScreenSwitch.isNull()) |
92 |
|
currentItemIdx = 0; |
93 |
|
else |
94 |
|
currentItemIdx = (currentItemIdx+1) % screenItems.size(); |
95 |
|
currentItem = screenItems.at(currentItemIdx); |
96 |
|
picture->loadFromUrl( currentItem.url ); |
97 |
|
|
98 |
if ( (t%2) == 0) { |
lastScreenSwitch = QTime::currentTime(); |
|
picture->loadFromUrl("http://87.104.25.138/infoscreens/data/images/image1.jpg"); |
|
|
} else { |
|
|
picture->loadFromUrl("http://87.104.25.138/infoscreens/data/images/image2.jpg"); |
|
|
} |
|
99 |
} |
} |
|
count++; |
|
100 |
} |
} |