/[projects]/infoscreen/webview.cpp
ViewVC logotype

Annotation of /infoscreen/webview.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 534 - (hide annotations) (download)
Thu Jan 7 19:42:12 2010 UTC (14 years, 4 months ago) by torben
Original Path: infoscreen/MyWebView.cpp
File size: 1786 byte(s)
indentation
1 torben 506 #include <QApplication>
2     #include <QDesktopWidget>
3     #include <stdexcept>
4    
5     #include "MyWebView.h"
6    
7    
8 torben 512 MyWebView::MyWebView(QWidget* parent) : QWebView(parent) {
9 torben 534 connect(this, SIGNAL( loadFinished(bool) ), this, SLOT( onChange(bool) ) );
10 torben 507
11 torben 534 QWebSettings* settings = QWebSettings::globalSettings();
12     settings->setAttribute( QWebSettings::JavascriptEnabled, true);
13     settings->setAttribute( QWebSettings::PluginsEnabled, true);
14 torben 512
15    
16    
17 torben 534 QTimer* timer = new QTimer(this);
18     connect(timer, SIGNAL(timeout()), this, SLOT(onTimer()));
19     timer->start(1000);
20    
21 torben 506 }
22    
23 torben 512 void MyWebView::start() {
24 torben 534 try {
25     this->load( QUrl( generateUrl() ) );
26     } catch (std::exception& e) {
27     showError(e.what() );
28     }
29 torben 506
30     }
31    
32     void MyWebView::showError(const char* msg) {
33 torben 534 QString str("<html><body><center><h1>");
34     str.append(msg).append("</h1></center></body></html>");
35     this->setHtml( str );
36 torben 506 }
37    
38     QString MyWebView::generateUrl() {
39 torben 534 QDesktopWidget* desktop = QApplication::desktop();
40     QRect rect = desktop->screenGeometry();
41 torben 506
42    
43 torben 534 QString width, height;
44     width.setNum( rect.width() );
45     height.setNum( rect.height() );
46 torben 512
47    
48 torben 534 QSettings settings("Caddi", "infoscreen");
49     qDebug() << "Settings: " << settings.fileName();
50 torben 506
51 torben 534 QString url = settings.value("url").toString();
52     QString screenid = settings.value("screenid").toString();
53 torben 506
54 torben 534 if (url.length() == 0) {
55     throw std::runtime_error("No url in config file");
56     }
57 torben 506
58 torben 534 url.append("?screen_id=").append(screenid);
59     url.append("&width=").append(width);
60     url.append("&height=").append(height);
61 torben 506
62    
63 torben 534 qDebug() << "URL:" << url;
64 torben 512
65 torben 534
66     return url;
67 torben 506 }
68    
69     //public slots:
70 torben 512 void MyWebView::onChange(bool success) {
71     //qDebug() << "html" << this->page()->mainFrame()->toHtml();
72 torben 506 }
73    
74 torben 507
75     void MyWebView::onTimer() {
76     }

  ViewVC Help
Powered by ViewVC 1.1.20