release 0.5
[presencevnc] / src / mainwindow.cpp
index 3a3b9b6..dbe099f 100644 (file)
@@ -23,7 +23,7 @@
 #include "preferences.h"
 #include "vncview.h"
 
-#ifdef Q_WS_HILDON
+#ifdef Q_WS_MAEMO_5
 #include <QtMaemo5>
 #include <QX11Info>
 
 MainWindow::MainWindow(QString url, int quality):
        QMainWindow(0),
        vnc_view(0),
-       scroll_area(new ScrollArea(0))
+       scroll_area(new ScrollArea(0)),
+       key_menu(0)
 {
        setWindowTitle("Presence VNC");
 
        migrateConfiguration();
        QSettings settings;
 
-#ifdef Q_WS_HILDON
+#ifdef Q_WS_MAEMO_5
        setAttribute(Qt::WA_Maemo5StackedWindow);
 #endif
 
@@ -53,7 +54,7 @@ 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
+#ifdef Q_WS_MAEMO_5
        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
@@ -79,7 +80,7 @@ MainWindow::MainWindow(QString url, int quality):
        QAction *pref_action = new QAction(tr("Preferences"), this);
        QAction *about_action = new QAction(tr("About"), this);
 
-#ifdef Q_WS_HILDON
+#ifdef Q_WS_MAEMO_5
        menuBar()->addAction(connect_action);
        menuBar()->addAction(disconnect_action);
        menuBar()->addAction(scaling);
@@ -91,8 +92,8 @@ MainWindow::MainWindow(QString url, int quality):
        session_menu->addAction(connect_action);
        session_menu->addAction(disconnect_action);
        session_menu->addSeparator();
-       //session_menu->addAction(pref_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"));
@@ -122,10 +123,6 @@ 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()));
-
        if(url.isNull()) {
                disconnect_action->setEnabled(false);
                toolbar->setEnabled(false);
@@ -139,12 +136,13 @@ MainWindow::MainWindow(QString url, int quality):
                scroll_area->setWidget(vnc_view);
                vnc_view->start();
                vnc_view->enableScaling(scaling->isChecked());
+               key_menu = new KeyMenu(this);
        }
 }
 
 void MainWindow::grabZoomKeys(bool grab)
 {
-#ifdef Q_WS_HILDON
+#ifdef Q_WS_MAEMO_5
        unsigned long val = (grab)?1:0;
        Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
        if(!atom) {
@@ -183,16 +181,16 @@ void MainWindow::about() {
 void MainWindow::showConnectDialog()
 {
        ConnectDialog *connect_dialog = new ConnectDialog(this);
-       connect(connect_dialog, SIGNAL(connectToHost(QString)),
-               this, SLOT(connectToHost(QString)));
+       connect(connect_dialog, SIGNAL(connectToHost(QString, int)),
+               this, SLOT(connectToHost(QString, int)));
        connect_dialog->exec();
 }
 
-void MainWindow::connectToHost(QString url)
+void MainWindow::connectToHost(QString url, int quality)
 {
        disconnectFromHost();
 
-       vnc_view = new VncView(this, url, RemoteView::Quality(2));
+       vnc_view = new VncView(this, url, RemoteView::Quality(quality));
 
        connect(scaling, SIGNAL(toggled(bool)),
                vnc_view, SLOT(enableScaling(bool)));
@@ -203,6 +201,10 @@ void MainWindow::connectToHost(QString url)
        vnc_view->enableScaling(scaling->isChecked());
        disconnect_action->setEnabled(true);
        toolbar->setEnabled(true);
+
+       if(key_menu) //reset
+               delete key_menu;
+       key_menu = new KeyMenu(this);
 }
 
 void MainWindow::disconnectFromHost()
@@ -225,12 +227,12 @@ void MainWindow::statusChanged(RemoteView::RemoteStatus status)
 
        switch(status) {
        case RemoteView::Connecting:
-#ifdef Q_WS_HILDON
+#ifdef Q_WS_MAEMO_5
                setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
 #endif
                break;
        case RemoteView::Connected:
-#ifdef Q_WS_HILDON
+#ifdef Q_WS_MAEMO_5
                setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
 #endif
                if(!scaling->isChecked()) {
@@ -241,7 +243,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
-#ifdef Q_WS_HILDON
+#ifdef Q_WS_MAEMO_5
                        QMaemo5InformationBox::information(this, tr("Connection lost"));
 #endif
                        
@@ -257,7 +259,7 @@ void MainWindow::statusChanged(RemoteView::RemoteStatus status)
                }
                break;
        case RemoteView::Disconnected:
-#ifdef Q_WS_HILDON
+#ifdef Q_WS_MAEMO_5
                setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
 #endif
                if(old_status == RemoteView::Disconnecting) {
@@ -285,16 +287,23 @@ void MainWindow::forceResizeDelayed()
 
 void MainWindow::toggleFullscreen()
 {
-       toolbar->setVisible(show_toolbar->isChecked() and (windowState() & Qt::WindowFullScreen)); //hide toolbar in fullscreen
+       bool in_fullscreen = windowState() & Qt::WindowFullScreen;
+
+       //hide menu/toolbar in fullscreen (new state is !in_fullscreen)
+       toolbar->setVisible(show_toolbar->isChecked() and in_fullscreen);
+
+#ifndef Q_WS_MAEMO_5
+       //menu bar is invisible by default on maemo
+       menuBar()->setVisible(in_fullscreen);
+#endif
+
        setWindowState(windowState() ^ Qt::WindowFullScreen); 
        forceResizeDelayed();
 }
 
 void MainWindow::showKeyMenu()
 {
-       static KeyMenu *key_menu = new KeyMenu(this);
        key_menu->exec();
-
        vnc_view->sendKeySequence(key_menu->getKeySequence());
 }
 
@@ -310,7 +319,7 @@ void MainWindow::showPreferences()
 void MainWindow::reloadSettings()
 {
        QSettings settings;
-#ifdef Q_WS_HILDON
+#ifdef Q_WS_MAEMO_5
        int rotation = settings.value("screen_rotation", 0).toInt();
        setAttribute(Qt::WA_Maemo5AutoOrientation, rotation == 0);
        setAttribute(Qt::WA_Maemo5LandscapeOrientation, rotation == 1);
@@ -330,8 +339,11 @@ void MainWindow::resizeEvent(QResizeEvent *event)
 
 void MainWindow::showInputPanel()
 {
-#ifdef Q_WS_HILDON
+#ifdef Q_WS_MAEMO_5
+       //TODO: when hardware keyboard is open, this will only cause the IM to mess up 'real' key events
        vnc_view->setAttribute(Qt::WA_InputMethodEnabled, true);
+       vnc_view->setInputMethodHints(Qt::ImhNoAutoUppercase); //without this, IM starts with caps lock
+
        QEvent event(QEvent::RequestSoftwareInputPanel);
        QApplication::sendEvent(vnc_view, &event);
 #endif