From: christian Date: Fri, 20 Aug 2010 18:04:34 +0000 (+0200) Subject: use less cpu when minimized X-Git-Tag: 0.6~66 X-Git-Url: http://git.maemo.org/git/?a=commitdiff_plain;h=9d471f6dedb9223a18239be2ddee363205a532f4;p=presencevnc use less cpu when minimized --- diff --git a/debian/changelog b/debian/changelog index 4779bc2..9855e1c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Sat, 07 Aug 2010 11:52:56 +0200 diff --git a/src/connectdialog.cpp b/src/connectdialog.cpp index ce3586f..a6ebcae 100644 --- a/src/connectdialog.cpp +++ b/src/connectdialog.cpp @@ -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); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 233e8ed..255b96a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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(); } diff --git a/src/vncview.cpp b/src/vncview.cpp index c0a5c11..7b01060 100644 --- a/src/vncview.cpp +++ b/src/vncview.cpp @@ -30,9 +30,14 @@ critical(parent, caption, message) #include +#include +#include #include +#include +#include #include #include +#include #include #include #include @@ -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;