2 #include "mainwindow.h"
12 MainWindow::MainWindow(QString url, int quality):
15 swipe_start = QPoint(0,0);
16 setAttribute(Qt::WA_Maemo5StackedWindow);
19 QMenuBar *menu = new QMenuBar(this);
20 QAction *connect_action = new QAction("Connect", this);
21 disconnect_action = new QAction("Disconnect", this);
22 scaling = new QAction("Rescale Remote Screen", this);
23 scaling->setCheckable(true);
24 scaling->setChecked(true);
25 menu->addAction(scaling);
26 QAction *about_action = new QAction("About", this);
27 menu->addAction(about_action);
29 //menu->setAttribute(Qt::WA_Maemo5StackedWindow);
32 connect(about_action, SIGNAL(triggered()),
34 connect(connect_action, SIGNAL(triggered()),
35 this, SLOT(connectDialog()));
36 connect(disconnect_action, SIGNAL(triggered()),
37 this, SLOT(disconnectFromHost()));
40 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
41 //setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
44 disconnect_action->setEnabled(false);
47 vnc_view = new VncView(0, url, RemoteView::Quality(quality));
48 connect(scaling, SIGNAL(toggled(bool)),
49 vnc_view, SLOT(enableScaling(bool)));
55 void MainWindow::grabZoomKeys(bool grab)
57 unsigned long val = (grab)?1:0;
58 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
60 qWarning("Couldn't get zoom key atom");
63 XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER,
64 32, PropModeReplace, reinterpret_cast<unsigned char *>(&val), 1);
67 void MainWindow::closeEvent(QCloseEvent*) {
70 vnc_view->startQuitting();
73 void MainWindow::about() {
74 QMessageBox::about(this, tr("About Presence VNC"),
75 tr("<center><h1>Presence VNC 0.1 alpha</h1>\
76 A touch screen friendly VNC client\
77 <small><p>©2010 Christian Pulvermacher <pulvermacher@gmx.de></p>\
78 <p>Based on KRDC, © 2007-2008 Urs Wolfer</small></center>\
79 <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>"));
82 /* swipe not used, and doesn't work without scaling anyway :/
83 virtual bool event(QEvent *event) {
84 if(event->type() == QEvent::MouseMove) {
85 QMouseEvent *ev = dynamic_cast<QMouseEvent* >(event);
86 if(!swipe_start.isNull()) {
87 QPoint diff = swipe_start - ev->pos();
88 const int swipe_dist = 60;
89 if(diff.x() > swipe_dist and diff.y() < swipe_dist and diff.y() > -swipe_dist) { //
91 swipe_start = QPoint(0,0);
93 } else if((width() - ev->x()) < 10) {
94 swipe_start = ev->pos();
96 std::cout << "mousex: " << width() - ev->x() << "\n";
97 //TODO: make scrolling over border result in wheel events? i get weird (out of range) mouse events when that happens
99 } else if(event->type() == QEvent::MouseButtonRelease) {
100 swipe_start = QPoint(0,0);
103 // std::cout << "event " << event->type() << "\n";
104 return QScrollArea::event(event);
109 void MainWindow::connectDialog()
111 QString url = QInputDialog::getText(this, "Connect to Host", "VNC Server:");
112 if(url.isEmpty()) { //dialog dismissed or nothing entered
115 url = "vnc://" + url;
117 disconnectFromHost();
119 vnc_view = new VncView(0, url, RemoteView::Quality(2)); //TODO: get quality in dialog
122 connect(scaling, SIGNAL(toggled(bool)),
123 vnc_view, SLOT(enableScaling(bool)));
125 disconnect_action->setEnabled(true);
128 void MainWindow::disconnectFromHost()
130 vnc_view->startQuitting();
133 disconnect(scaling, SIGNAL(toggled(bool)),
134 vnc_view, SLOT(enableScaling(bool)));
137 disconnect_action->setEnabled(false);