Update connection parameters when the user has changed things in the options
dialog.


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4422 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/vncviewer/CConn.cxx b/vncviewer/CConn.cxx
index 45189d7..9525c71 100644
--- a/vncviewer/CConn.cxx
+++ b/vncviewer/CConn.cxx
@@ -33,6 +33,7 @@
 #include <FL/fl_ask.H>
 
 #include "CConn.h"
+#include "OptionsDialog.h"
 #include "i18n.h"
 #include "parameters.h"
 
@@ -44,6 +45,10 @@
 
 static rfb::LogWriter vlog("CConn");
 
+static const PixelFormat mediumColourPF(8,3,0,1,1,1,1,2,1,0);
+static const PixelFormat lowColourPF(8,6,0,1,3,3,3,4,2,0);
+static const PixelFormat verylowColourPF(8,8,0,0);
+
 CConn::CConn(const char* vncServerName)
   : serverHost(0), serverPort(0), sock(NULL), desktop(NULL),
     currentEncoding(encodingTight), lastServerEncoding((unsigned int)-1),
@@ -89,10 +94,14 @@
   setStreams(&sock->inStream(), &sock->outStream());
 
   initialiseProtocol();
+
+  OptionsDialog::addCallback(handleOptions, this);
 }
 
 CConn::~CConn()
 {
+  OptionsDialog::removeCallback(handleOptions);
+
   free(serverHost);
   if (sock)
     Fl::remove_fd(sock->getFd());
@@ -472,11 +481,11 @@
       pf = fullColourPF;
     } else {
       if (lowColourLevel == 0)
-        pf = PixelFormat(8,3,0,1,1,1,1,2,1,0);
+        pf = mediumColourPF;
       else if (lowColourLevel == 1)
-        pf = PixelFormat(8,6,0,1,3,3,3,4,2,0);
+        pf = lowColourPF;
       else
-        pf = PixelFormat(8,8,0,0);
+        pf = verylowColourPF;
     }
     char str[256];
     pf.print(str, 256);
@@ -497,3 +506,49 @@
  
   forceNonincremental = false;
 }
+
+void CConn::handleOptions(void *data)
+{
+  CConn *self = (CConn*)data;
+
+  // Checking all the details of the current set of encodings is just
+  // a pain. Assume something has changed, as resending the encoding
+  // list is cheap. Avoid overriding what the auto logic has selected
+  // though.
+  if (!autoSelect) {
+    int encNum = encodingNum(preferredEncoding);
+
+    if (encNum != -1)
+      self->currentEncoding = encNum;
+
+    self->cp.qualityLevel = qualityLevel;
+  }
+
+  self->cp.supportsLocalCursor = useLocalCursor;
+
+  self->cp.customCompressLevel = customCompressLevel;
+  self->cp.compressLevel = compressLevel;
+
+  self->cp.noJpeg = noJpeg;
+
+  self->encodingChange = true;
+
+  // Format changes refreshes the entire screen though and are therefore
+  // very costly. It's probably worth the effort to see if it is necessary
+  // here.
+  PixelFormat pf;
+
+  if (fullColour) {
+    pf = self->fullColourPF;
+  } else {
+    if (lowColourLevel == 0)
+      pf = mediumColourPF;
+    else if (lowColourLevel == 1)
+      pf = lowColourPF;
+    else
+      pf = verylowColourPF;
+  }
+
+  if (!pf.equal(self->cp.pf()))
+    self->formatChange = true;
+}