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

Diff of /infoscreen/webview.cpp

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

revision 507 by torben, Fri Dec 11 22:15:18 2009 UTC revision 540 by torben, Sat Jan 9 15:22:14 2010 UTC
# Line 1  Line 1 
1  #include <QApplication>  #include <QApplication>
 #include <QtWebKit>  
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);
         QTimer* timer = new QTimer(this);  
         connect(timer, SIGNAL(timeout()), this, SLOT(onTimer()));  
         timer->start(1000);  
14  }  }
15    
16  void MyWebView::show() {  void MyWebView::start(QString url, QString screenid) {
17          QWebView::show();      try {
18          try {            this->load( QUrl( generateUrl(url, screenid) ) );
19                  this->load( QUrl( generateUrl() ) );      } catch (std::exception& e) {
20          } catch (std::exception& e) {          showError(e.what() );
21                  showError(e.what() );      }
         }  
22    
23  }  }
24    
25  void MyWebView::showError(const char* msg) {  void MyWebView::showError(const char* msg) {
26          QString str("<html><body><center><h1>");      QString str("<html><body><center><h1>");
27          str.append(msg).append("</h1></center></body></html>");      str.append(msg).append("</h1></center></body></html>");
28          this->setHtml( str );      this->setHtml( str );
29  }  }
30    
31  QString MyWebView::generateUrl() {  QString MyWebView::generateUrl(QString url, QString screenid) {
32          QDesktopWidget* desktop = QApplication::desktop();      QDesktopWidget* desktop = QApplication::desktop();
33          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);  
34    
35    
36          std::cout << url.toAscii().data() << std::endl;      QString width, height;
37        width.setNum( rect.width() );
38        height.setNum( rect.height() );
39    
         return url;  
 }  
40    
41  //public slots:      if (url.length() == 0) {
42  void MyWebView::test() {          throw std::runtime_error("No url in config file");
43          std::cout << "test" << std::endl;      }
44  }  
45        url.append("?screen_id=").append(screenid);
46        url.append("&width=").append(width);
47        url.append("&height=").append(height);
48    
49    
50  void MyWebView::onTimer() {      qDebug() << "URL:" << url;
51          static int count = 0;  
52          count++;  
53        return url;
         if (count == 10) {  
                 system("xset dpms force off");  
         }  
           
         std::cout << "timer" << std::endl;  
54  }  }
55    

Legend:
Removed from v.507  
changed lines
  Added in v.540

  ViewVC Help
Powered by ViewVC 1.1.20