1 |
torben |
506 |
#include <QApplication> |
2 |
|
|
#include <QDesktopWidget> |
3 |
|
|
#include <iostream> |
4 |
|
|
#include <stdexcept> |
5 |
|
|
|
6 |
|
|
#include "MyWebView.h" |
7 |
|
|
|
8 |
|
|
|
9 |
|
|
MyWebView::MyWebView(QWidget* parent) : QWebView(parent) { |
10 |
|
|
// this->setWindowState( Qt::WindowFullScreen ); |
11 |
|
|
qApp->setOverrideCursor( QCursor( Qt::BlankCursor) ); |
12 |
|
|
|
13 |
|
|
connect(this, SIGNAL( loadStarted() ), this, SLOT( test() ) ); |
14 |
torben |
507 |
|
15 |
|
|
QTimer* timer = new QTimer(this); |
16 |
|
|
connect(timer, SIGNAL(timeout()), this, SLOT(onTimer())); |
17 |
|
|
timer->start(1000); |
18 |
torben |
506 |
} |
19 |
|
|
|
20 |
|
|
void MyWebView::show() { |
21 |
|
|
QWebView::show(); |
22 |
|
|
try { |
23 |
|
|
this->load( QUrl( generateUrl() ) ); |
24 |
|
|
} catch (std::exception& e) { |
25 |
|
|
showError(e.what() ); |
26 |
|
|
} |
27 |
|
|
|
28 |
|
|
} |
29 |
|
|
|
30 |
|
|
void MyWebView::showError(const char* msg) { |
31 |
|
|
QString str("<html><body><center><h1>"); |
32 |
|
|
str.append(msg).append("</h1></center></body></html>"); |
33 |
|
|
this->setHtml( str ); |
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
QString MyWebView::generateUrl() { |
37 |
|
|
QDesktopWidget* desktop = QApplication::desktop(); |
38 |
|
|
QRect rect = desktop->screenGeometry(); |
39 |
|
|
|
40 |
|
|
QString width; |
41 |
|
|
width.setNum( rect.width() ); |
42 |
|
|
|
43 |
|
|
QString height; |
44 |
|
|
height.setNum( rect.height() ); |
45 |
|
|
|
46 |
|
|
|
47 |
|
|
QSettings settings("Caddi", "infoscreen"); |
48 |
|
|
std::cout << settings.fileName().toAscii().data() << std::endl; |
49 |
|
|
QString url = settings.value("url").toString(); |
50 |
|
|
QString screenid = settings.value("screenid").toString(); |
51 |
|
|
|
52 |
|
|
if (url.length() == 0) { |
53 |
|
|
throw std::runtime_error("No url in config file"); |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
url.append("?screen_id=").append(screenid); |
57 |
|
|
url.append("&width=").append(width); |
58 |
|
|
url.append("&height=").append(height); |
59 |
|
|
|
60 |
|
|
|
61 |
|
|
std::cout << url.toAscii().data() << std::endl; |
62 |
|
|
|
63 |
|
|
return url; |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
//public slots: |
67 |
|
|
void MyWebView::test() { |
68 |
|
|
std::cout << "test" << std::endl; |
69 |
|
|
} |
70 |
|
|
|
71 |
torben |
507 |
|
72 |
|
|
void MyWebView::onTimer() { |
73 |
|
|
static int count = 0; |
74 |
|
|
count++; |
75 |
|
|
|
76 |
|
|
if (count == 10) { |
77 |
|
|
system("xset dpms force off"); |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
std::cout << "timer" << std::endl; |
81 |
|
|
} |