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

Diff of /infoscreen/webview.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.508  
changed lines
  Added in v.534

  ViewVC Help
Powered by ViewVC 1.1.20