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