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