change history format; fix screen tearing
authorchristian <christian@christian-laptop.(none)>
Thu, 19 Aug 2010 21:55:38 +0000 (23:55 +0200)
committerchristian <christian@christian-laptop.(none)>
Thu, 19 Aug 2010 21:55:38 +0000 (23:55 +0200)
debian/changelog
src/connectdialog.cpp
src/connectdialog.h
src/mainwindow.cpp
src/mainwindow.h
src/preferences.cpp

index c5c6d40..4779bc2 100644 (file)
@@ -1,6 +1,8 @@
 presencevnc (0.4) unstable; urgency=low
 
   * Add button to launch virtual keyboard
+  * Add history to connect dialog
+  * Fix tearing after scrolling
   * Real fullscreen
 
  -- Christian Pulvermacher <pulvermacher@gmx.de>  Sat, 07 Aug 2010 11:52:56 +0200
index 91790d7..ce3586f 100644 (file)
@@ -29,19 +29,27 @@ ConnectDialog::ConnectDialog(QWidget *parent):
        setWindowTitle(tr("Connect to VNC Server"));
        QSettings settings;
 
-       int i = 0;
-       for(;;) { //read history
-               QString hostname = settings.value(QString("host%1").arg(i), "").toString();
-               if(hostname.isEmpty())
-                       break;
-
-               hosts.addItem(hostname);
-               i++;
+       //read history
+       settings.beginGroup("hosts");
+       QStringList hostnames = settings.childGroups();
+       QStringList hostnames_sorted = hostnames;
+       foreach(QString hostname, hostnames) {
+               int position = settings.value(hostname + "/position").toInt();
+               if(position < 0)
+                       position = 0;
+               else if(position >= hostnames.size())
+                       position = hostnames.size()-1;
+
+               hostnames_sorted.replace(position, hostname);
        }
+       settings.endGroup();
+
+       //set up combobox
+       hosts.addItems(hostnames_sorted);
        hosts.setEditable(true);
        hosts.lineEdit()->setInputMethodHints(Qt::ImhLowercaseOnly); //doesn't work, but I tried.
        connect(&hosts, SIGNAL(editTextChanged(QString)),
-               this, SLOT(convertToLowercase(QString)));
+               this, SLOT(cleanHostname(QString)));
        layout.addWidget(&hosts);
 
        QPushButton *done = new QPushButton(tr("Done"));
@@ -53,8 +61,10 @@ ConnectDialog::ConnectDialog(QWidget *parent):
        setLayout(&layout);
 }
 
-void ConnectDialog::convertToLowercase(QString newtext)
+void ConnectDialog::cleanHostname(QString newtext)
 {
+       newtext.remove(QChar('/'));
+       newtext.remove(QChar('\\'));
        hosts.lineEdit()->setText(newtext.toLower());
 }
 
@@ -69,32 +79,32 @@ void ConnectDialog::accept()
 
        //save url?
        QSettings settings;
+               settings.beginGroup("hosts");
        bool new_item = hosts.itemText(hosts.currentIndex()) != hosts.currentText();
        bool used_old_host = !new_item and hosts.currentIndex() > 0;
-       int rearrange_from_idx;
+       int rearrange_up_to_pos;
        if(new_item) {
                std::cout << "adding new item to history\n";
-               int i = 0;
-               for(;;) { //find first unused key
-                       QString hostname = settings.value(QString("host%1").arg(i), "").toString();
-                       if(hostname.isEmpty())
-                               break;
-                       i++;
-               }
-               rearrange_from_idx = i;
+               rearrange_up_to_pos = hosts.count(); //use free index
        } else if(used_old_host) {
-               rearrange_from_idx = hosts.currentIndex();
+               rearrange_up_to_pos = hosts.currentIndex();
        }
 
        if(new_item or used_old_host) {
-               std::cout << "rearranging history,  last index " << rearrange_from_idx << "\n";
+               std::cout << "rearranging history,  last index " << rearrange_up_to_pos << "\n";
 
-               for(int i = rearrange_from_idx-1; i >= 0; i--) { //increment index for each entry newer than the selected one
-                       QString hostname = settings.value(QString("host%1").arg(i), "").toString();
-                       settings.setValue(QString("host%1").arg(i+1), hostname);
+               QStringList hostnames = settings.childGroups();
+               foreach(QString hostname, hostnames) {
+                       int position = settings.value(hostname + "/position").toInt();
+                       if(position < rearrange_up_to_pos)
+                               settings.setValue(hostname + "/position", position+1);
                }
-               settings.setValue(QString("host0"), hosts.currentText());
+               //position 0 is now free
+
+               //move selected host to front
+               settings.setValue(QString("%1/position").arg(hosts.currentText()), 0);
        }
+       settings.endGroup();
 
        emit connectToHost(QString("vnc://") + hosts.currentText());
        deleteLater();
index ee1e7cb..513cb11 100644 (file)
@@ -31,7 +31,7 @@ public slots:
 signals:
        void connectToHost(QString url);
 private slots:
-       void convertToLowercase(QString newtext);
+       void cleanHostname(QString newtext);
 private:
        QHBoxLayout layout;
        QComboBox hosts;
index d0f5299..233e8ed 100644 (file)
@@ -33,7 +33,7 @@
 MainWindow::MainWindow(QString url, int quality):
        QMainWindow(0),
        vnc_view(0),
-       scroll_area(new QScrollArea(0))
+       scroll_area(new ScrollArea(0))
 {
        setWindowTitle("Presence VNC");
        setAttribute(Qt::WA_Maemo5StackedWindow);
@@ -63,21 +63,21 @@ MainWindow::MainWindow(QString url, int quality):
 
        //set up menu
        QMenuBar *menu = new QMenuBar(this);
-       QAction *connect_action = new QAction("Connect", this);
-       disconnect_action = new QAction("Disconnect", this);
+       QAction *connect_action = new QAction(tr("Connect"), this);
+       disconnect_action = new QAction(tr("Disconnect"), this);
        menu->addAction(connect_action);
        menu->addAction(disconnect_action);
-       scaling = new QAction("Fit to Screen", this);
+       scaling = new QAction(tr("Fit to Screen"), this);
        scaling->setCheckable(true);
        scaling->setChecked(settings.value("rescale", true).toBool());
        menu->addAction(scaling);
-       show_toolbar = new QAction("Show Toolbar", this);
+       show_toolbar = new QAction(tr("Show Toolbar"), this);
        show_toolbar->setCheckable(true);
        show_toolbar->setChecked(settings.value("show_toolbar", true).toBool());
        menu->addAction(show_toolbar);
-       QAction *pref_action = new QAction("Preferences", this);
+       QAction *pref_action = new QAction(tr("Preferences"), this);
        menu->addAction(pref_action);
-       QAction *about_action = new QAction("About", this);
+       QAction *about_action = new QAction(tr("About"), this);
        menu->addAction(about_action);
 
        connect(about_action, SIGNAL(triggered()),
@@ -211,7 +211,7 @@ void MainWindow::statusChanged(RemoteView::RemoteStatus status)
                break;
        case RemoteView::Disconnecting:
                if(old_status != RemoteView::Disconnected) { //Disconnecting also occurs while connecting, so check last state
-                       QMaemo5InformationBox::information(this, "Connection lost");
+                       QMaemo5InformationBox::information(this, tr("Connection lost"));
                        
                        //clean up
                        scroll_area->setWidget(0);
index a160167..e3104fd 100644 (file)
 #include "remoteview.h"
 #include "vncview.h"
 
+//fix tearing during scrolling
+class ScrollArea : public QScrollArea {
+public:
+       ScrollArea(QWidget *parent) : QScrollArea(parent) { }
+protected:
+       virtual void scrollContentsBy(int dx, int dy)
+       {
+               QScrollArea::scrollContentsBy(dx, dy);
+               if(widget())
+                       widget()->update(); //update whole widget
+       }
+};
+
 class MainWindow : public QMainWindow {
        Q_OBJECT
 public:
@@ -51,7 +64,7 @@ private:
        void grabZoomKeys(bool grab);
        void reloadSettings();
        VncView *vnc_view;
-       QScrollArea *scroll_area;
+       ScrollArea *scroll_area;
        QToolBar *toolbar;      
        QAction *scaling, *show_toolbar, *disconnect_action;
 };
index 4e15e00..a1e66e3 100644 (file)
@@ -45,8 +45,14 @@ void migrateConfiguration()
        if(config_ver == 1) {
                QString last_hostname = settings.value("last_hostname", "").toString();
                settings.remove("last_hostname");
-               if(!last_hostname.isEmpty())
-                       settings.setValue("host0", last_hostname);
+               if(!last_hostname.isEmpty()) {
+                       //make sure hostname is sane
+                       last_hostname.remove(QChar('/'));
+                       last_hostname.remove(QChar('\\'));
+                       last_hostname = last_hostname.toLower();
+
+                       settings.setValue(QString("hosts/%1/position").arg(last_hostname), 0);
+               }
                
                config_ver = 2;
        }
@@ -58,7 +64,7 @@ void migrateConfiguration()
 Preferences::Preferences(QWidget *parent):
        QDialog(parent)
 {
-       setWindowTitle("Preferences");
+       setWindowTitle(tr("Preferences"));
 
        QHBoxLayout *layout1 = new QHBoxLayout();
        QVBoxLayout *layout2 = new QVBoxLayout();