use less cpu when minimized
authorchristian <christian@christian-laptop.(none)>
Fri, 20 Aug 2010 18:04:34 +0000 (20:04 +0200)
committerchristian <christian@christian-laptop.(none)>
Fri, 20 Aug 2010 18:04:34 +0000 (20:04 +0200)
debian/changelog
src/connectdialog.cpp
src/mainwindow.cpp
src/vncview.cpp

index 4779bc2..9855e1c 100644 (file)
@@ -1,9 +1,10 @@
 presencevnc (0.4) unstable; urgency=low
 
-  * Add button to launch virtual keyboard
-  * Add history to connect dialog
+  * Add virtual keyboard
+  * Remember VNC servers and passwords
   * Fix tearing after scrolling
-  * Real fullscreen
+  * Hide toolbar in fullscreen mode
+  * Use less CPU when minimized
 
  -- Christian Pulvermacher <pulvermacher@gmx.de>  Sat, 07 Aug 2010 11:52:56 +0200
 
index ce3586f..a6ebcae 100644 (file)
@@ -34,11 +34,17 @@ ConnectDialog::ConnectDialog(QWidget *parent):
        QStringList hostnames = settings.childGroups();
        QStringList hostnames_sorted = hostnames;
        foreach(QString hostname, hostnames) {
+               if(!settings.contains(hostname + "/position")) {
+                       //can happen when host was given as a command line argument, don't show those
+                       hostnames_sorted.removeAll(hostname);
+                       continue;
+               }
+
                int position = settings.value(hostname + "/position").toInt();
                if(position < 0)
                        position = 0;
-               else if(position >= hostnames.size())
-                       position = hostnames.size()-1;
+               else if(position >= hostnames_sorted.size())
+                       position = hostnames_sorted.size()-1;
 
                hostnames_sorted.replace(position, hostname);
        }
@@ -95,6 +101,9 @@ void ConnectDialog::accept()
 
                QStringList hostnames = settings.childGroups();
                foreach(QString hostname, hostnames) {
+                       if(!settings.contains(hostname + "/position"))
+                               continue; //ignore entries without position
+
                        int position = settings.value(hostname + "/position").toInt();
                        if(position < rearrange_up_to_pos)
                                settings.setValue(hostname + "/position", position+1);
index 233e8ed..255b96a 100644 (file)
@@ -251,8 +251,8 @@ void MainWindow::forceResizeDelayed()
 
 void MainWindow::toggleFullscreen()
 {
+       toolbar->setVisible(show_toolbar->isChecked() and (windowState() & Qt::WindowFullScreen)); //hide toolbar in fullscreen
        setWindowState(windowState() ^ Qt::WindowFullScreen); 
-       toolbar->setVisible(show_toolbar->isChecked() and !(windowState() & Qt::WindowFullScreen)); //hide toolbar in fullscreen
        forceResizeDelayed();
 }
 
index c0a5c11..7b01060 100644 (file)
 critical(parent, caption, message)
 
 #include <QApplication>
+#include <QCheckBox>
+#include <QDialog>
 #include <QImage>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
 #include <QPainter>
 #include <QMouseEvent>
+#include <QPushButton>
 #include <QEvent>
 #include <QSettings>
 #include <QTime>
@@ -216,17 +221,54 @@ void VncView::requestPassword()
         return;
     }
 
-    bool ok;
-    QString password = QInputDialog::getText(this, //krazy:exclude=qclasses
-                                             tr("Password required"),
-                                             tr("Please enter the password for the remote desktop:"),
-                                             QLineEdit::Password, QString(), &ok);
-    m_firstPasswordTry = false;
-    if (ok) {
-        vncThread.setPassword(password);
-    } else {
-        startQuitting();
-    }
+       QSettings settings;
+       settings.beginGroup("hosts");
+       QString password = settings.value(QString("%1/password").arg(m_host), "").toString();
+       //check for saved password
+       if(m_firstPasswordTry and !password.isEmpty()) {
+               kDebug(5011) << "Trying saved password";
+               m_firstPasswordTry = false;
+               vncThread.setPassword(password);
+               return;
+       }
+       m_firstPasswordTry = false;
+
+       //build dialog
+       QDialog dialog(this);
+       dialog.setWindowTitle(tr("Password required"));
+
+       QLineEdit passwordbox;
+       passwordbox.setEchoMode(QLineEdit::Password);
+       passwordbox.setText(password);
+       QCheckBox save_password(tr("Save Password"));
+       save_password.setChecked(!password.isEmpty()); //offer to overwrite saved password
+       QPushButton ok_button(tr("Done"));
+       ok_button.setMaximumWidth(100);
+       connect(&ok_button, SIGNAL(clicked()),
+               &dialog, SLOT(accept()));
+
+       QHBoxLayout layout1;
+       QVBoxLayout layout2;
+       layout2.addWidget(&passwordbox);
+       layout2.addWidget(&save_password);
+       layout1.addLayout(&layout2);
+       layout1.addWidget(&ok_button);
+       dialog.setLayout(&layout1);
+
+       if(dialog.exec()) { //dialog accepted
+               password = passwordbox.text();
+
+               if(save_password.isChecked()) {
+                       kDebug(5011) << "Saving password for host '" << m_host << "'";
+
+                       settings.setValue(QString("%1/password").arg(m_host), password);
+                       settings.sync();
+               }
+
+               vncThread.setPassword(password);
+       } else {
+               startQuitting();
+       }
 }
 
 void VncView::outputErrorMessage(const QString &message)
@@ -246,7 +288,10 @@ void VncView::outputErrorMessage(const QString &message)
 
 void VncView::updateImage(int x, int y, int w, int h)
 {
-//     kDebug(5011) << "got update" << width() << height();
+       if(!QApplication::focusWidget()) { //no focus, we're probably minimized
+               return;
+       }
+     //kDebug(5011) << "got update" << width() << height();
 
     m_x = x;
     m_y = y;
@@ -378,10 +423,10 @@ void VncView::paintEvent(QPaintEvent *event)
                                                                   qRound(m_h*m_verticalFactor),
                                                                   Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
     } else {
-         kDebug(5011) << "resize repaint";
+         //kDebug(5011) << "resize repaint";
         QRect rect = event->rect();
         if (!force_full_repaint and (rect.width() != width() || rect.height() != height())) {
-             kDebug(5011) << "Partial repaint";
+          //   kDebug(5011) << "Partial repaint";
             const int sx = rect.x()/m_horizontalFactor;
             const int sy = rect.y()/m_verticalFactor;
             const int sw = rect.width()/m_horizontalFactor;