*/
#include "connectdialog.h"
#include "fullscreenexitbutton.h"
+#include "keymenu.h"
#include "mainwindow.h"
#include "preferences.h"
#include "vncview.h"
+#ifdef Q_WS_HILDON
#include <QtMaemo5>
#include <QX11Info>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
+#endif
-#include <iostream>
MainWindow::MainWindow(QString url, int quality):
QMainWindow(0),
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("Mod", this, SLOT(showModifierMenu()));
- toolbar->addAction("Tab", this, SLOT(sendTab()));
- toolbar->addAction("Esc", this, SLOT(sendEsc()));
- toolbar->addAction("PgUp", this, SLOT(sendPgUp()));
- toolbar->addAction("PgDn", this, SLOT(sendPgDn()));
+ toolbar->addAction(QChar(0x2026), this, SLOT(showKeyMenu())); //"..." button
+ toolbar->addAction(tr("Tab"), this, SLOT(sendTab()));
+ 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();
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()));
grabZoomKeys(true);
reloadSettings();
+ //TODO: can i replace this with resizeEvent?
connect(QApplication::desktop(), SIGNAL(resized(int)),
this, SLOT(forceResize()));
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) {
}
XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER,
32, PropModeReplace, reinterpret_cast<unsigned char *>(&val), 1);
+#endif
}
void MainWindow::closeEvent(QCloseEvent*) {
void MainWindow::about() {
QMessageBox::about(this, tr("About Presence VNC"),
- tr("<center><h1>Presence VNC 0.4</h1>\
-A touchscreen friendly VNC client\
+ tr("<center><h1>Presence VNC 0.5</h1>\
+<p>A touchscreen friendly VNC client</p>\
+<p><a href=\"https://garage.maemo.org/projects/presencevnc/\">https://garage.maemo.org/projects/presencevnc</a></p></center>\
<small><p>©2010 Christian Pulvermacher <pulvermacher@gmx.de></p>\
<p>Based on KRDC, © 2007-2008 Urs Wolfer</p>\
-<p>and LibVNCServer, © 2001-2003 Johannes E. Schindelin</p></small></center>\
-<p>This program is free software; License: <a href=\"http://www.gnu.org/licenses/gpl-2.0.html\">GNU GPL 2</a> or later.</p>"));
+<p>and LibVNCServer, © 2001-2003 Johannes E. Schindelin</p>\
+<p>This program is free software; License: <a href=\"http://www.gnu.org/licenses/gpl-2.0.html\">GNU GPL 2</a> or later.</p></small>"));
}
void MainWindow::showConnectDialog()
{
disconnectFromHost();
- vnc_view = new VncView(this, url, RemoteView::Quality(2)); //TODO: get quality in dialog
+ vnc_view = new VncView(this, url, RemoteView::Quality(2));
connect(scaling, SIGNAL(toggled(bool)),
vnc_view, SLOT(enableScaling(bool)));
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()) {
- //if remote desktop is shown in full size, 2nd connection will have black screen
//ugly hack to force a refresh (forceFullRepaint() doesn't repaint?? -> vnc_view hidden???)
vnc_view->resize(scroll_area->size());
vnc_view->enableScaling(false);
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);
}
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
}
void MainWindow::toggleFullscreen()
{
+ toolbar->setVisible(show_toolbar->isChecked() and (windowState() & Qt::WindowFullScreen)); //hide toolbar in fullscreen
setWindowState(windowState() ^ Qt::WindowFullScreen);
- toolbar->setVisible(show_toolbar->isChecked() and !(windowState() & Qt::WindowFullScreen)); //hide toolbar in fullscreen
forceResizeDelayed();
}
-void MainWindow::showModifierMenu()
+void MainWindow::showKeyMenu()
{
- static QMenu *mod_menu = new QMenu(tr("Modifiers"), this);
- static QAction *win = mod_menu->addAction(tr("Win"));
- static QAction *alt = mod_menu->addAction(tr("Alt"));
- win->setCheckable(true);
- alt->setCheckable(true);
-
- //show menu at top-left corner of toolbar
- QAction *chosen = mod_menu->exec(toolbar->mapToGlobal(QPoint(0,0)));
- if(!chosen) {
- return;
- } else if(chosen == alt) {
- vnc_view->sendKey(Qt::Key_Alt);
- } else if(chosen == win) {
- vnc_view->sendKey(Qt::Key_Meta);
- } else {
- std::cout << "unhandled action?\n";
- }
+ static KeyMenu *key_menu = new KeyMenu(this);
+ key_menu->exec();
+
+ vnc_view->sendKeySequence(key_menu->getKeySequence());
}
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
}