From 64c24021e25a85192a4b74d2f2f4a4947c4a8aa9 Mon Sep 17 00:00:00 2001 From: Christian Pulvermacher Date: Sat, 11 Sep 2010 13:48:10 +0200 Subject: [PATCH] Increase portability --- src/connectdialog.cpp | 7 +++--- src/mainwindow.cpp | 64 +++++++++++++++++++++++++++++++++++++++++-------- src/mainwindow.h | 1 + src/preferences.cpp | 19 ++++++++++++++- vnc.pro | 5 +++- 5 files changed, 81 insertions(+), 15 deletions(-) diff --git a/src/connectdialog.cpp b/src/connectdialog.cpp index a6ebcae..7694835 100644 --- a/src/connectdialog.cpp +++ b/src/connectdialog.cpp @@ -53,7 +53,7 @@ ConnectDialog::ConnectDialog(QWidget *parent): //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); @@ -85,8 +85,8 @@ void ConnectDialog::accept() //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) { @@ -114,6 +114,7 @@ void ConnectDialog::accept() settings.setValue(QString("%1/position").arg(hosts.currentText()), 0); } settings.endGroup(); + settings.sync(); emit connectToHost(QString("vnc://") + hosts.currentText()); deleteLater(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d152aad..3a3b9b6 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -23,13 +23,14 @@ #include "preferences.h" #include "vncview.h" +#ifdef Q_WS_HILDON #include #include #include #include +#endif -#include 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"); - setAttribute(Qt::WA_Maemo5StackedWindow); migrateConfiguration(); - 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 @@ -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())); +#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())); +#endif //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 - QMenuBar *menu = new QMenuBar(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()); - menu->addAction(scaling); 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); - menu->addAction(pref_action); 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())); @@ -100,6 +122,7 @@ MainWindow::MainWindow(QString url, int quality): grabZoomKeys(true); reloadSettings(); + //TODO: can i replace this with resizeEvent? connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(forceResize())); @@ -121,6 +144,7 @@ MainWindow::MainWindow(QString url, int quality): 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) { @@ -129,6 +153,7 @@ void MainWindow::grabZoomKeys(bool grab) } XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER, 32, PropModeReplace, reinterpret_cast(&val), 1); +#endif } void MainWindow::closeEvent(QCloseEvent*) { @@ -200,10 +225,14 @@ void MainWindow::statusChanged(RemoteView::RemoteStatus status) switch(status) { case RemoteView::Connecting: +#ifdef Q_WS_HILDON setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true); +#endif break; case RemoteView::Connected: +#ifdef Q_WS_HILDON 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()); @@ -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 +#ifdef Q_WS_HILDON QMaemo5InformationBox::information(this, tr("Connection lost")); +#endif //clean up scroll_area->setWidget(0); @@ -226,7 +257,9 @@ void MainWindow::statusChanged(RemoteView::RemoteStatus status) } break; case RemoteView::Disconnected: +#ifdef Q_WS_HILDON setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false); +#endif if(old_status == RemoteView::Disconnecting) { scroll_area->setWidget(0); //remove widget } @@ -277,18 +310,29 @@ void MainWindow::showPreferences() 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); +#endif if(vnc_view) vnc_view->reloadSettings(); } +void MainWindow::resizeEvent(QResizeEvent *event) +{ + QMainWindow::resizeEvent(event); + + forceResize(); +} + void MainWindow::showInputPanel() { +#ifdef Q_WS_HILDON vnc_view->setAttribute(Qt::WA_InputMethodEnabled, true); QEvent event(QEvent::RequestSoftwareInputPanel); QApplication::sendEvent(vnc_view, &event); +#endif } diff --git a/src/mainwindow.h b/src/mainwindow.h index 46fca44..4c50e78 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -61,6 +61,7 @@ public slots: void toggleFullscreen(); protected: void closeEvent(QCloseEvent*); + void resizeEvent(QResizeEvent *event); private: void grabZoomKeys(bool grab); void reloadSettings(); diff --git a/src/preferences.cpp b/src/preferences.cpp index ea0874b..62de562 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -17,8 +17,11 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include + +#ifdef Q_WS_HILDON #include #include +#endif #include "preferences.h" @@ -28,8 +31,15 @@ void migrateConfiguration() { 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; + } std::cout << "Migrating from configuration ver. " << config_ver << "\n"; @@ -56,6 +66,7 @@ void migrateConfiguration() config_ver = 2; } + Q_ASSERT(config_ver == current_ver); settings.setValue("config_version", config_ver); settings.sync(); } @@ -69,6 +80,7 @@ Preferences::Preferences(QWidget *parent): 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); @@ -105,9 +117,11 @@ Preferences::Preferences(QWidget *parent): 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); +#endif QPushButton *ok = new QPushButton(tr("Done")); ok->setMaximumWidth(100); @@ -125,9 +139,12 @@ Preferences::Preferences(QWidget *parent): 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()); +#endif + settings.setValue("disable_tapping", disable_tapping->isChecked()); settings.sync(); diff --git a/vnc.pro b/vnc.pro index 159ef89..e417365 100644 --- a/vnc.pro +++ b/vnc.pro @@ -2,9 +2,12 @@ TEMPLATE = app TARGET = presencevnc-bin LIBS += -Llibvnc/libvncclient/.libs -lvncclient DEFINES += QTONLY -QT += maemo5 CONFIG += silent release +maemo5 { + QT += maemo5 +} + OBJECTS_DIR = $${PWD}/tmp MOC_DIR = $${PWD}/tmp VPATH = $${PWD}/src -- 1.7.9.5