cleanup
[presencevnc] / src / vncclientthread.cpp
index ac71844..de97b5d 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "vncclientthread.h"
 
-#include <QCoreApplication>
 #include <QMutexLocker>
 #include <QTimer>
 
@@ -116,12 +115,20 @@ char *VncClientThread::passwdHandler(rfbClient *cl)
     VncClientThread *t = (VncClientThread*)rfbClientGetClientData(cl, 0);
     Q_ASSERT(t);
 
-    t->passwordRequest();
     t->m_passwordError = true;
+    t->passwordRequest();
 
     return strdup(t->password().toLocal8Bit());
 }
 
+void VncClientThread::setPassword(const QString &password)
+{
+       if(password.isNull()) //cancelled, don't retry
+               m_passwordError = false;
+
+       m_password = password;
+}
+
 void VncClientThread::outputHandler(const char *format, ...)
 {
     va_list args;
@@ -159,7 +166,6 @@ VncClientThread::VncClientThread(QObject *parent)
         : QThread(parent)
         , frameBuffer(0)
 {
-       outputErrorMessageString.clear(); //don't deliver error messages of old instances...
     QMutexLocker locker(&mutex);
     m_stopped = false;
 
@@ -262,10 +268,11 @@ void VncClientThread::run()
     int passwd_failures = 0;
     while (!m_stopped) { // try to connect as long as the server allows
         m_passwordError = false;
+               outputErrorMessageString.clear(); //don't deliver error messages of old instances...
 
         rfbClientLog = outputHandler;
         rfbClientErr = outputHandler;
-        cl = rfbGetClient(8, 3, 4);
+        cl = rfbGetClient(8, 3, 4); // bitsPerSample, samplesPerPixel, bytesPerPixel
         cl->MallocFrameBuffer = newclient;
         cl->canHandleNewFBSize = true;
         cl->GetPassword = passwdHandler;
@@ -282,31 +289,24 @@ void VncClientThread::run()
             m_port += 5900;
         cl->serverPort = m_port;
 
+               cl->listenSpecified = rfbBool(listen_port > 0);
+               cl->listenPort = listen_port;
+
         kDebug(5011) << "--------------------- trying init ---------------------";
 
-               if(listen_port) { //listen for incoming connections
-                       int argc = 2;
-                       char* argv[2] = { "x", "-listen" }; //this isn't exactly elegant..
-                       cl->listenPort = listen_port;
-                       if (rfbInitClient(cl, &argc, argv))
-                               break;
-               } else { //connect to host
-                       if (rfbInitClient(cl, 0, 0))
-                               break;
-               }
+               if (rfbInitClient(cl, 0, 0))
+                       break;
 
+               //init failed...
         if (m_passwordError) {
                        passwd_failures++;
-                       if(passwd_failures > 2) {
-                               m_stopped = true;
-                               return;
-                       }
-                       continue;
+                       if(passwd_failures < 3)
+                               continue; //that's ok, try again
                }
 
-               //clean, just exit
+               //stop connecting
                m_stopped = true;
-        return;
+        return; //no cleanup necessary, cl was free()d by rfbInitClient()
     }
 
     locker.unlock();
@@ -383,5 +383,3 @@ void VncClientThread::clientCut(const QString &text)
 
     m_eventQueue.enqueue(new ClientCutEvent(text));
 }
-
-#include "moc_vncclientthread.cpp"