2 |
#include <QDesktopWidget> |
#include <QDesktopWidget> |
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) { |
|
connect(this, SIGNAL( loadFinished(bool) ), this, SLOT( onChange(bool) ) ); |
|
9 |
|
|
10 |
QWebSettings* settings = QWebSettings::globalSettings(); |
QWebSettings* settings = QWebSettings::globalSettings(); |
11 |
settings->setAttribute( QWebSettings::JavascriptEnabled, true); |
settings->setAttribute( QWebSettings::JavascriptEnabled, true); |
12 |
settings->setAttribute( QWebSettings::PluginsEnabled, true); |
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::start() { |
void WebView::start(QString& url, QString& screenid) { |
16 |
try { |
try { |
17 |
this->load( QUrl( generateUrl() ) ); |
this->load( QUrl( generateUrl(url, screenid) ) ); |
18 |
} catch (std::exception& e) { |
} catch (std::exception& e) { |
19 |
showError(e.what() ); |
showError(e.what() ); |
20 |
} |
} |
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(); |
33 |
|
|
37 |
height.setNum( rect.height() ); |
height.setNum( rect.height() ); |
38 |
|
|
39 |
|
|
|
QSettings settings("Caddi", "infoscreen"); |
|
|
qDebug() << "Settings: " << settings.fileName(); |
|
|
|
|
|
QString url = settings.value("url").toString(); |
|
|
QString screenid = settings.value("screenid").toString(); |
|
|
|
|
40 |
if (url.length() == 0) { |
if (url.length() == 0) { |
41 |
throw std::runtime_error("No url in config file"); |
throw std::runtime_error("No url in config file"); |
42 |
} |
} |
52 |
return url; |
return url; |
53 |
} |
} |
54 |
|
|
|
//public slots: |
|
|
void MyWebView::onChange(bool success) { |
|
|
//qDebug() << "html" << this->page()->mainFrame()->toHtml(); |
|
|
} |
|
|
|
|
|
|
|
|
void MyWebView::onTimer() { |
|
|
} |
|