Increase portability
authorChristian Pulvermacher <christian@hazel.(none)>
Sat, 11 Sep 2010 11:48:10 +0000 (13:48 +0200)
committerChristian Pulvermacher <christian@hazel.(none)>
Sat, 11 Sep 2010 11:48:10 +0000 (13:48 +0200)
src/connectdialog.cpp
src/mainwindow.cpp
src/mainwindow.h
src/preferences.cpp
vnc.pro

index a6ebcae..7694835 100644 (file)
@@ -53,7 +53,7 @@ ConnectDialog::ConnectDialog(QWidget *parent):
        //set up combobox
        hosts.addItems(hostnames_sorted);
        hosts.setEditable(true);
        //set up combobox
        hosts.addItems(hostnames_sorted);
        hosts.setEditable(true);
-       hosts.lineEdit()->setInputMethodHints(Qt::ImhLowercaseOnly); //doesn't work, but I tried.
+       //hosts.lineEdit()->setInputMethodHints(Qt::ImhLowercaseOnly); //doesn't work, but I tried.
        connect(&hosts, SIGNAL(editTextChanged(QString)),
                this, SLOT(cleanHostname(QString)));
        layout.addWidget(&hosts);
        connect(&hosts, SIGNAL(editTextChanged(QString)),
                this, SLOT(cleanHostname(QString)));
        layout.addWidget(&hosts);
@@ -85,8 +85,8 @@ void ConnectDialog::accept()
 
        //save url?
        QSettings settings;
 
        //save url?
        QSettings settings;
-               settings.beginGroup("hosts");
-       bool new_item = hosts.itemText(hosts.currentIndex()) != hosts.currentText();
+       settings.beginGroup("hosts");
+       bool new_item = !settings.contains(hosts.currentText());
        bool used_old_host = !new_item and hosts.currentIndex() > 0;
        int rearrange_up_to_pos;
        if(new_item) {
        bool used_old_host = !new_item and hosts.currentIndex() > 0;
        int rearrange_up_to_pos;
        if(new_item) {
@@ -114,6 +114,7 @@ void ConnectDialog::accept()
                settings.setValue(QString("%1/position").arg(hosts.currentText()), 0);
        }
        settings.endGroup();
                settings.setValue(QString("%1/position").arg(hosts.currentText()), 0);
        }
        settings.endGroup();
+       settings.sync();
 
        emit connectToHost(QString("vnc://") + hosts.currentText());
        deleteLater();
 
        emit connectToHost(QString("vnc://") + hosts.currentText());
        deleteLater();
index d152aad..3a3b9b6 100644 (file)
 #include "preferences.h"
 #include "vncview.h"
 
 #include "preferences.h"
 #include "vncview.h"
 
+#ifdef Q_WS_HILDON
 #include <QtMaemo5>
 #include <QX11Info>
 
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
 #include <QtMaemo5>
 #include <QX11Info>
 
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
+#endif
 
 
-#include <iostream>
 
 MainWindow::MainWindow(QString url, int quality):
        QMainWindow(0),
 
 MainWindow::MainWindow(QString url, int quality):
        QMainWindow(0),
@@ -37,12 +38,14 @@ MainWindow::MainWindow(QString url, int quality):
        scroll_area(new ScrollArea(0))
 {
        setWindowTitle("Presence VNC");
        scroll_area(new ScrollArea(0))
 {
        setWindowTitle("Presence VNC");
-       setAttribute(Qt::WA_Maemo5StackedWindow);
 
        migrateConfiguration();
 
        migrateConfiguration();
-
        QSettings settings;
 
        QSettings settings;
 
+#ifdef Q_WS_HILDON
+       setAttribute(Qt::WA_Maemo5StackedWindow);
+#endif
+
        //set up toolbar
        toolbar = new QToolBar(0);
        toolbar->addAction(QChar(0x2026), this, SLOT(showKeyMenu())); //"..." button
        //set up toolbar
        toolbar = new QToolBar(0);
        toolbar->addAction(QChar(0x2026), this, SLOT(showKeyMenu())); //"..." button
@@ -50,8 +53,10 @@ MainWindow::MainWindow(QString url, int quality):
        toolbar->addAction(tr("Esc"), this, SLOT(sendEsc()));
        toolbar->addAction(tr("PgUp"), this, SLOT(sendPgUp()));
        toolbar->addAction(tr("PgDn"), this, SLOT(sendPgDn()));
        toolbar->addAction(tr("Esc"), this, SLOT(sendEsc()));
        toolbar->addAction(tr("PgUp"), this, SLOT(sendPgUp()));
        toolbar->addAction(tr("PgDn"), this, SLOT(sendPgDn()));
+#ifdef Q_WS_HILDON
        toolbar->addAction(QIcon("/usr/share/icons/hicolor/48x48/hildon/chat_enter.png"), "", this, SLOT(sendReturn()));
        toolbar->addAction(QIcon("/usr/share/icons/hicolor/48x48/hildon/control_keyboard.png"), "", this, SLOT(showInputPanel()));
        toolbar->addAction(QIcon("/usr/share/icons/hicolor/48x48/hildon/chat_enter.png"), "", this, SLOT(sendReturn()));
        toolbar->addAction(QIcon("/usr/share/icons/hicolor/48x48/hildon/control_keyboard.png"), "", this, SLOT(showInputPanel()));
+#endif
 
        //move fullscreen button to the right
        QWidget *spacer = new QWidget();
 
        //move fullscreen button to the right
        QWidget *spacer = new QWidget();
@@ -63,23 +68,40 @@ MainWindow::MainWindow(QString url, int quality):
        toolbar->setVisible(settings.value("show_toolbar", true).toBool());
 
        //set up menu
        toolbar->setVisible(settings.value("show_toolbar", true).toBool());
 
        //set up menu
-       QMenuBar *menu = new QMenuBar(this);
        QAction *connect_action = new QAction(tr("Connect"), this);
        disconnect_action = new QAction(tr("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(tr("Fit to Screen"), this);
        scaling->setCheckable(true);
        scaling->setChecked(settings.value("rescale", true).toBool());
        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(tr("Show Toolbar"), this);
        show_toolbar->setCheckable(true);
        show_toolbar->setChecked(settings.value("show_toolbar", true).toBool());
        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(tr("Preferences"), this);
        QAction *pref_action = new QAction(tr("Preferences"), this);
-       menu->addAction(pref_action);
        QAction *about_action = new QAction(tr("About"), this);
        QAction *about_action = new QAction(tr("About"), this);
-       menu->addAction(about_action);
+
+#ifdef Q_WS_HILDON
+       menuBar()->addAction(connect_action);
+       menuBar()->addAction(disconnect_action);
+       menuBar()->addAction(scaling);
+       menuBar()->addAction(show_toolbar);
+       menuBar()->addAction(pref_action);
+       menuBar()->addAction(about_action);
+#else
+       QMenu* session_menu = menuBar()->addMenu(tr("&Session"));
+       session_menu->addAction(connect_action);
+       session_menu->addAction(disconnect_action);
+       session_menu->addSeparator();
+       //session_menu->addAction(pref_action);
+       //session_menu->addSeparator();
+       session_menu->addAction(tr("&Quit"), this, SLOT(close()));
+
+       QMenu* view_menu = menuBar()->addMenu(tr("&View"));
+       view_menu->addAction(scaling);
+       view_menu->addAction(show_toolbar);
+
+       QMenu* help_menu = menuBar()->addMenu(tr("&Help"));
+       help_menu->addAction(about_action);
+#endif
 
        connect(about_action, SIGNAL(triggered()),
                this, SLOT(about()));
 
        connect(about_action, SIGNAL(triggered()),
                this, SLOT(about()));
@@ -100,6 +122,7 @@ MainWindow::MainWindow(QString url, int quality):
        grabZoomKeys(true);
        reloadSettings();
 
        grabZoomKeys(true);
        reloadSettings();
 
+       //TODO: can i replace this with resizeEvent?
        connect(QApplication::desktop(), SIGNAL(resized(int)),
                this, SLOT(forceResize()));
 
        connect(QApplication::desktop(), SIGNAL(resized(int)),
                this, SLOT(forceResize()));
 
@@ -121,6 +144,7 @@ MainWindow::MainWindow(QString url, int quality):
 
 void MainWindow::grabZoomKeys(bool grab)
 {
 
 void MainWindow::grabZoomKeys(bool grab)
 {
+#ifdef Q_WS_HILDON
        unsigned long val = (grab)?1:0;
        Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
        if(!atom) {
        unsigned long val = (grab)?1:0;
        Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
        if(!atom) {
@@ -129,6 +153,7 @@ void MainWindow::grabZoomKeys(bool grab)
        }
        XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER,
                32, PropModeReplace, reinterpret_cast<unsigned char *>(&val), 1);
        }
        XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER,
                32, PropModeReplace, reinterpret_cast<unsigned char *>(&val), 1);
+#endif
 }
 
 void MainWindow::closeEvent(QCloseEvent*) {
 }
 
 void MainWindow::closeEvent(QCloseEvent*) {
@@ -200,10 +225,14 @@ void MainWindow::statusChanged(RemoteView::RemoteStatus status)
 
        switch(status) {
        case RemoteView::Connecting:
 
        switch(status) {
        case RemoteView::Connecting:
+#ifdef Q_WS_HILDON
                setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
                setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
+#endif
                break;
        case RemoteView::Connected:
                break;
        case RemoteView::Connected:
+#ifdef Q_WS_HILDON
                setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
                setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
+#endif
                if(!scaling->isChecked()) {
                        //ugly hack to force a refresh (forceFullRepaint() doesn't repaint?? -> vnc_view hidden???)
                        vnc_view->resize(scroll_area->size());
                if(!scaling->isChecked()) {
                        //ugly hack to force a refresh (forceFullRepaint() doesn't repaint?? -> vnc_view hidden???)
                        vnc_view->resize(scroll_area->size());
@@ -212,7 +241,9 @@ void MainWindow::statusChanged(RemoteView::RemoteStatus status)
                break;
        case RemoteView::Disconnecting:
                if(old_status != RemoteView::Disconnected) { //Disconnecting also occurs while connecting, so check last state
                break;
        case RemoteView::Disconnecting:
                if(old_status != RemoteView::Disconnected) { //Disconnecting also occurs while connecting, so check last state
+#ifdef Q_WS_HILDON
                        QMaemo5InformationBox::information(this, tr("Connection lost"));
                        QMaemo5InformationBox::information(this, tr("Connection lost"));
+#endif
                        
                        //clean up
                        scroll_area->setWidget(0);
                        
                        //clean up
                        scroll_area->setWidget(0);
@@ -226,7 +257,9 @@ void MainWindow::statusChanged(RemoteView::RemoteStatus status)
                }
                break;
        case RemoteView::Disconnected:
                }
                break;
        case RemoteView::Disconnected:
+#ifdef Q_WS_HILDON
                setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
                setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
+#endif
                if(old_status == RemoteView::Disconnecting) {
                        scroll_area->setWidget(0); //remove widget
                }
                if(old_status == RemoteView::Disconnecting) {
                        scroll_area->setWidget(0); //remove widget
                }
@@ -277,18 +310,29 @@ void MainWindow::showPreferences()
 void MainWindow::reloadSettings()
 {
        QSettings settings;
 void MainWindow::reloadSettings()
 {
        QSettings settings;
+#ifdef Q_WS_HILDON
        int rotation = settings.value("screen_rotation", 0).toInt();
        setAttribute(Qt::WA_Maemo5AutoOrientation, rotation == 0);
        setAttribute(Qt::WA_Maemo5LandscapeOrientation, rotation == 1);
        setAttribute(Qt::WA_Maemo5PortraitOrientation, rotation == 2);
        int rotation = settings.value("screen_rotation", 0).toInt();
        setAttribute(Qt::WA_Maemo5AutoOrientation, rotation == 0);
        setAttribute(Qt::WA_Maemo5LandscapeOrientation, rotation == 1);
        setAttribute(Qt::WA_Maemo5PortraitOrientation, rotation == 2);
+#endif
 
        if(vnc_view)
                vnc_view->reloadSettings();
 }
 
 
        if(vnc_view)
                vnc_view->reloadSettings();
 }
 
+void MainWindow::resizeEvent(QResizeEvent *event)
+{
+       QMainWindow::resizeEvent(event);
+
+       forceResize();
+}
+
 void MainWindow::showInputPanel()
 {
 void MainWindow::showInputPanel()
 {
+#ifdef Q_WS_HILDON
        vnc_view->setAttribute(Qt::WA_InputMethodEnabled, true);
        QEvent event(QEvent::RequestSoftwareInputPanel);
        QApplication::sendEvent(vnc_view, &event);
        vnc_view->setAttribute(Qt::WA_InputMethodEnabled, true);
        QEvent event(QEvent::RequestSoftwareInputPanel);
        QApplication::sendEvent(vnc_view, &event);
+#endif
 }
 }
index 46fca44..4c50e78 100644 (file)
@@ -61,6 +61,7 @@ public slots:
        void toggleFullscreen();
 protected:
        void closeEvent(QCloseEvent*);
        void toggleFullscreen();
 protected:
        void closeEvent(QCloseEvent*);
+       void resizeEvent(QResizeEvent *event);
 private:
        void grabZoomKeys(bool grab);
        void reloadSettings();
 private:
        void grabZoomKeys(bool grab);
        void reloadSettings();
index ea0874b..62de562 100644 (file)
     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 #include <QtGui>
     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 #include <QtGui>
+
+#ifdef Q_WS_HILDON
 #include <QMaemo5ValueButton>
 #include <QMaemo5ListPickSelector>
 #include <QMaemo5ValueButton>
 #include <QMaemo5ListPickSelector>
+#endif
 
 #include "preferences.h"
 
 
 #include "preferences.h"
 
@@ -28,8 +31,15 @@ void migrateConfiguration()
 {
        QSettings settings;
        int config_ver = settings.value("config_version", 0).toInt();
 {
        QSettings settings;
        int config_ver = settings.value("config_version", 0).toInt();
-       if(config_ver == 2) //config file up-to-date
+       const int current_ver = 2;
+       if(config_ver == current_ver) //config file up-to-date
+               return;
+       
+       if(settings.allKeys().isEmpty()) { //no config file
+               settings.setValue("config_version", current_ver);
+               settings.sync();
                return;
                return;
+       }
 
        std::cout << "Migrating from configuration ver. " << config_ver << "\n";
 
 
        std::cout << "Migrating from configuration ver. " << config_ver << "\n";
 
@@ -56,6 +66,7 @@ void migrateConfiguration()
                
                config_ver = 2;
        }
                
                config_ver = 2;
        }
+       Q_ASSERT(config_ver == current_ver);
        settings.setValue("config_version", config_ver);
        settings.sync();
 }
        settings.setValue("config_version", config_ver);
        settings.sync();
 }
@@ -69,6 +80,7 @@ Preferences::Preferences(QWidget *parent):
        QHBoxLayout *layout1 = new QHBoxLayout();
        QVBoxLayout *layout2 = new QVBoxLayout();
 
        QHBoxLayout *layout1 = new QHBoxLayout();
        QVBoxLayout *layout2 = new QVBoxLayout();
 
+#ifdef Q_WS_HILDON
        QMaemo5ValueButton *rotation = new QMaemo5ValueButton(tr("Screen Rotation"), this);
        rotation_selector = new QMaemo5ListPickSelector(this);
        QStandardItemModel *model = new QStandardItemModel(0, 1, this);
        QMaemo5ValueButton *rotation = new QMaemo5ValueButton(tr("Screen Rotation"), this);
        rotation_selector = new QMaemo5ListPickSelector(this);
        QStandardItemModel *model = new QStandardItemModel(0, 1, this);
@@ -105,9 +117,11 @@ Preferences::Preferences(QWidget *parent):
        rightzoom->setValueLayout(QMaemo5ValueButton::ValueBesideText);
        layout2->addWidget(rightzoom);
 
        rightzoom->setValueLayout(QMaemo5ValueButton::ValueBesideText);
        layout2->addWidget(rightzoom);
 
+       //useful if one only wants to click using the zoom buttons exclusively
        disable_tapping = new QCheckBox(tr("Disable Tapping"), this);
        disable_tapping->setChecked(settings.value("disable_tapping", false).toBool());
        layout2->addWidget(disable_tapping);
        disable_tapping = new QCheckBox(tr("Disable Tapping"), this);
        disable_tapping->setChecked(settings.value("disable_tapping", false).toBool());
        layout2->addWidget(disable_tapping);
+#endif
 
        QPushButton *ok = new QPushButton(tr("Done"));
        ok->setMaximumWidth(100);
 
        QPushButton *ok = new QPushButton(tr("Done"));
        ok->setMaximumWidth(100);
@@ -125,9 +139,12 @@ Preferences::Preferences(QWidget *parent):
 
 void Preferences::save()
 {
 
 void Preferences::save()
 {
+#ifdef Q_WS_HILDON
        settings.setValue("screen_rotation", rotation_selector->currentIndex());
        settings.setValue("left_zoom", leftzoom_selector->currentIndex());
        settings.setValue("right_zoom", rightzoom_selector->currentIndex());
        settings.setValue("screen_rotation", rotation_selector->currentIndex());
        settings.setValue("left_zoom", leftzoom_selector->currentIndex());
        settings.setValue("right_zoom", rightzoom_selector->currentIndex());
+#endif
+
        settings.setValue("disable_tapping", disable_tapping->isChecked());
 
        settings.sync();
        settings.setValue("disable_tapping", disable_tapping->isChecked());
 
        settings.sync();
diff --git a/vnc.pro b/vnc.pro
index 159ef89..e417365 100644 (file)
--- a/vnc.pro
+++ b/vnc.pro
@@ -2,9 +2,12 @@ TEMPLATE = app
 TARGET = presencevnc-bin
 LIBS += -Llibvnc/libvncclient/.libs -lvncclient
 DEFINES += QTONLY
 TARGET = presencevnc-bin
 LIBS += -Llibvnc/libvncclient/.libs -lvncclient
 DEFINES += QTONLY
-QT += maemo5
 CONFIG += silent release
 
 CONFIG += silent release
 
+maemo5 {
+       QT += maemo5
+}
+
 OBJECTS_DIR = $${PWD}/tmp
 MOC_DIR = $${PWD}/tmp
 VPATH = $${PWD}/src
 OBJECTS_DIR = $${PWD}/tmp
 MOC_DIR = $${PWD}/tmp
 VPATH = $${PWD}/src