#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(QChar(0x2026), this, SLOT(showKeyMenu())); //"..." button
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*) {
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());
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::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
}
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <QtGui>
+
+#ifdef Q_WS_HILDON
#include <QMaemo5ValueButton>
#include <QMaemo5ListPickSelector>
+#endif
#include "preferences.h"
{
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";
config_ver = 2;
}
+ Q_ASSERT(config_ver == current_ver);
settings.setValue("config_version", config_ver);
settings.sync();
}
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);
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);
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();