set doubleclick timeout to 1/2s; further cleanup
[presencevnc] / src / vncview.cpp
index 1d4932e..6d01968 100644 (file)
@@ -65,14 +65,12 @@ VncView::VncView(QWidget *parent, const KUrl &url, RemoteView::Quality quality,
         m_buttonMask(0),
        cursor_x(0),
        cursor_y(0),
-        m_repaint(false),
         m_quitFlag(false),
         m_firstPasswordTry(true),
         m_dontSendClipboard(false),
         m_horizontalFactor(1.0),
         m_verticalFactor(1.0),
         m_forceLocalCursor(false),
-       force_full_repaint(false),
        quality(quality),
        listen_port(listen_port)
 {
@@ -86,6 +84,9 @@ VncView::VncView(QWidget *parent, const KUrl &url, RemoteView::Quality quality,
     connect(&vncThread, SIGNAL(passwordRequest()), this, SLOT(requestPassword()), Qt::BlockingQueuedConnection);
     connect(&vncThread, SIGNAL(outputErrorMessage(QString)), this, SLOT(outputErrorMessage(QString)));
 
+       //don't miss early connection failures
+       connect(&vncThread, SIGNAL(finished()), this, SLOT(startQuitting()));
+
     m_clipboard = QApplication::clipboard();
     connect(m_clipboard, SIGNAL(selectionChanged()), this, SLOT(clipboardSelectionChanged()));
     connect(m_clipboard, SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
@@ -103,12 +104,6 @@ VncView::~VncView()
     startQuitting();
 }
 
-void VncView::forceFullRepaint()
-{
-       force_full_repaint = true;
-       repaint();
-}
-
 bool VncView::eventFilter(QObject *obj, QEvent *event)
 {
     if (m_viewOnly) {
@@ -141,6 +136,9 @@ QSize VncView::minimumSizeHint() const
 
 void VncView::startQuitting()
 {
+       if(isQuitting())
+               return;
+
     kDebug(5011) << "about to quit";
 
     //const bool connected = status() == RemoteView::Connected;
@@ -237,7 +235,8 @@ void VncView::requestPassword()
        QHBoxLayout layout1;
        QVBoxLayout layout2;
        layout2.addWidget(&passwordbox);
-       layout2.addWidget(&save_password);
+       if(!m_host.isEmpty()) //don't save incomming connections
+               layout2.addWidget(&save_password);
        layout1.addLayout(&layout2);
        layout1.addWidget(&ok_button);
        dialog.setLayout(&layout1);
@@ -245,7 +244,7 @@ void VncView::requestPassword()
        if(dialog.exec()) { //dialog accepted
                password = passwordbox.text();
 
-               if(save_password.isChecked()) {
+               if(!m_host.isEmpty() and save_password.isChecked()) {
                        kDebug(5011) << "Saving password for host '" << m_host << "'";
 
                        settings.setValue(QString("%1/password").arg(m_host), password);
@@ -254,14 +253,12 @@ void VncView::requestPassword()
 
                vncThread.setPassword(password);
        } else {
-               startQuitting();
+               vncThread.setPassword(QString()); //null string to exit
        }
 }
 
 void VncView::outputErrorMessage(const QString &message)
 {
-    kDebug(5011) << message;
-
     if (message == "INTERNAL:APPLE_VNC_COMPATIBILTY") {
         setCursor(localDotCursor());
         m_forceLocalCursor = true;
@@ -299,7 +296,7 @@ void VncView::updateImage(int x, int y, int w, int h)
 
     m_frame = vncThread.image();
 
-    if (!m_initDone) {
+    if (!m_initDone) { //TODO this seems an odd place for initialization
         setAttribute(Qt::WA_StaticContents);
         setAttribute(Qt::WA_OpaquePaintEvent);
         installEventFilter(this);
@@ -309,7 +306,6 @@ void VncView::updateImage(int x, int y, int w, int h)
         setMouseTracking(true); // get mouse events even when there is no mousebutton pressed
         setFocusPolicy(Qt::WheelFocus);
         setStatus(Connected);
-//         emit framebufferSizeChanged(m_frame.width(), m_frame.height());
         emit connected();
         
                resize(width(), height());
@@ -326,9 +322,7 @@ void VncView::updateImage(int x, int y, int w, int h)
         emit framebufferSizeChanged(m_frame.width(), m_frame.height());
     }
 
-    m_repaint = true;
     repaint(qRound(m_x * m_horizontalFactor), qRound(m_y * m_verticalFactor), qRound(m_w * m_horizontalFactor), qRound(m_h * m_verticalFactor));
-    m_repaint = false;
 }
 
 void VncView::setViewOnly(bool viewOnly)
@@ -401,38 +395,26 @@ void VncView::paintEvent(QPaintEvent *event)
 
     event->accept();
 
-    QPainter painter(this);
-
        Qt::TransformationMode transformation_mode = Qt::SmoothTransformation;
        if( m_horizontalFactor >= 1.0 )
                transformation_mode = Qt::FastTransformation;
 
-    if (m_repaint and !force_full_repaint) {
-//         kDebug(5011) << "normal repaint";
-        painter.drawImage(QRect(qRound(m_x*m_horizontalFactor), qRound(m_y*m_verticalFactor),
-                                qRound(m_w*m_horizontalFactor), qRound(m_h*m_verticalFactor)), 
-                          m_frame.copy(m_x, m_y, m_w, m_h).scaled(qRound(m_w*m_horizontalFactor), 
-                                                                  qRound(m_h*m_verticalFactor),
-                                                                  Qt::IgnoreAspectRatio, transformation_mode));
-    } else {
-         //kDebug(5011) << "resize repaint";
-        QRect rect = event->rect();
-        if (!force_full_repaint and (rect.width() != width() || rect.height() != height())) {
-          //   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;
-            const int sh = rect.height()/m_verticalFactor;
-            painter.drawImage(rect, 
-                              m_frame.copy(sx, sy, sw, sh).scaled(rect.width(), rect.height(),
-                                                                  Qt::IgnoreAspectRatio, transformation_mode));
-        } else {
-             kDebug(5011) << "Full repaint" << width() << height() << m_frame.width() << m_frame.height();
-            painter.drawImage(QRect(0, 0, width(), height()), 
-                              m_frame.scaled(m_frame.width() * m_horizontalFactor, m_frame.height() * m_verticalFactor,
-                                             Qt::IgnoreAspectRatio, transformation_mode));
-                       force_full_repaint = false;
-        }
+       const QRect update_rect = event->rect();
+    QPainter painter(this);
+       if (update_rect != rect()) {
+               // kDebug(5011) << "Partial repaint";
+               const int sx = qRound(update_rect.x()/m_horizontalFactor);
+               const int sy = qRound(update_rect.y()/m_verticalFactor);
+               const int sw = qRound(update_rect.width()/m_horizontalFactor);
+               const int sh = qRound(update_rect.height()/m_verticalFactor);
+
+               painter.drawImage(update_rect, 
+                                                 m_frame.copy(sx, sy, sw, sh).scaled(update_rect.size(), Qt::IgnoreAspectRatio, transformation_mode));
+       } else {
+               kDebug(5011) << "Full repaint" << width() << height() << m_frame.width() << m_frame.height();
+
+               painter.drawImage(rect(),
+                                                 m_frame.scaled(size(), Qt::IgnoreAspectRatio, transformation_mode));
     }
 
        //draw local cursor ourselves, normal mouse pointer doesn't deal with scrolling
@@ -450,7 +432,7 @@ void VncView::paintEvent(QPaintEvent *event)
 void VncView::resizeEvent(QResizeEvent *event)
 {
     RemoteView::resizeEvent(event);
-    forceFullRepaint();
+    update();
 }
 
 bool VncView::event(QEvent *event)
@@ -817,10 +799,12 @@ void VncView::sendKeySequence(QKeySequence keys)
 
        //to get at individual key presses, we split 'keys' into its components
        QList<int> key_list;
-       for(int i = 0; ; i++) {
-               QString k = keys.toString().section('+', i, i);
+       int pos = 0;
+       while(true) {
+               QString k = keys.toString().section('+', pos, pos);
                if(k.isEmpty())
                        break;
+
                //kDebug(5011) << "found key: " << k;
                if(k == "Alt") {
                        key_list.append(Qt::Key_Alt);
@@ -831,6 +815,8 @@ void VncView::sendKeySequence(QKeySequence keys)
                } else {
                        key_list.append(QKeySequence(k)[0]);
                }
+               
+               pos++;
        }
        
        for(int i = 0; i < key_list.count(); i++)