1 #include "mainwindow.h"
12 MainWindow::MainWindow(QString url, int quality):
15 scroll_area(new QScrollArea(0))
17 swipe_start = QPoint(0,0);
18 setAttribute(Qt::WA_Maemo5StackedWindow);
21 toolbar = new QToolBar(0);
22 toolbar->addAction("Esc", this, SLOT(sendEsc()));
23 toolbar->addAction("Tab", this, SLOT(sendTab()));
27 QMenuBar *menu = new QMenuBar(this);
28 QAction *connect_action = new QAction("Connect", this);
29 disconnect_action = new QAction("Disconnect", this);
30 menu->addAction(connect_action);
31 menu->addAction(disconnect_action);
32 scaling = new QAction("Rescale Remote Screen", this);
33 scaling->setCheckable(true);
34 scaling->setChecked(true);
35 menu->addAction(scaling);
36 QAction *show_toolbar = new QAction("Show Toolbar", this);
37 show_toolbar->setCheckable(true);
38 show_toolbar->setChecked(true);
39 menu->addAction(show_toolbar);
40 QAction *about_action = new QAction("About", this);
41 menu->addAction(about_action);
43 //menu->setAttribute(Qt::WA_Maemo5StackedWindow);
46 connect(about_action, SIGNAL(triggered()),
48 connect(connect_action, SIGNAL(triggered()),
49 this, SLOT(connectDialog()));
50 connect(disconnect_action, SIGNAL(triggered()),
51 this, SLOT(disconnectFromHost()));
52 connect(show_toolbar, SIGNAL(toggled(bool)),
53 toolbar, SLOT(setVisible(bool)));
55 setCentralWidget(scroll_area);
58 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
59 //setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
62 disconnect_action->setEnabled(false);
65 vnc_view = new VncView(0, url, RemoteView::Quality(quality));
66 connect(scaling, SIGNAL(toggled(bool)),
67 vnc_view, SLOT(enableScaling(bool)));
68 connect(vnc_view, SIGNAL(statusChanged(RemoteView::RemoteStatus)),
69 this, SLOT(statusChanged(RemoteView::RemoteStatus)));
70 scroll_area->setWidget(vnc_view);
75 void MainWindow::grabZoomKeys(bool grab)
77 unsigned long val = (grab)?1:0;
78 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
80 qWarning("Couldn't get zoom key atom");
83 XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER,
84 32, PropModeReplace, reinterpret_cast<unsigned char *>(&val), 1);
87 void MainWindow::closeEvent(QCloseEvent*) {
93 void MainWindow::about() {
94 QMessageBox::about(this, tr("About Presence VNC"),
95 tr("<center><h1>Presence VNC 0.1 alpha</h1>\
96 A touch screen friendly VNC client\
97 <small><p>©2010 Christian Pulvermacher <pulvermacher@gmx.de></p>\
98 <p>Based on KRDC, © 2007-2008 Urs Wolfer</small></center>\
99 <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>"));
102 /* swipe not used, and doesn't work without scaling anyway :/
103 virtual bool event(QEvent *event) {
104 if(event->type() == QEvent::MouseMove) {
105 QMouseEvent *ev = dynamic_cast<QMouseEvent* >(event);
106 if(!swipe_start.isNull()) {
107 QPoint diff = swipe_start - ev->pos();
108 const int swipe_dist = 60;
109 if(diff.x() > swipe_dist and diff.y() < swipe_dist and diff.y() > -swipe_dist) { //
111 swipe_start = QPoint(0,0);
113 } else if((width() - ev->x()) < 10) {
114 swipe_start = ev->pos();
116 std::cout << "mousex: " << width() - ev->x() << "\n";
117 //TODO: make scrolling over border result in wheel events? i get weird (out of range) mouse events when that happens
119 } else if(event->type() == QEvent::MouseButtonRelease) {
120 swipe_start = QPoint(0,0);
123 // std::cout << "event " << event->type() << "\n";
124 return QScrollArea::event(event);
129 void MainWindow::connectDialog()
132 QString url = QInputDialog::getText(this, "Connect to Host", "VNC Server:", QLineEdit::Normal, settings.value("last_hostname", "").toString());
133 if(url.isEmpty()) { //dialog dismissed or nothing entered
136 settings.setValue("last_hostname", url);
137 url = "vnc://" + url;
139 disconnectFromHost();
141 vnc_view = new VncView(0, url, RemoteView::Quality(2)); //TODO: get quality in dialog
142 scroll_area->setWidget(vnc_view);
144 connect(scaling, SIGNAL(toggled(bool)),
145 vnc_view, SLOT(enableScaling(bool)));
146 connect(vnc_view, SIGNAL(statusChanged(RemoteView::RemoteStatus)),
147 this, SLOT(statusChanged(RemoteView::RemoteStatus)));
149 disconnect_action->setEnabled(true);
152 void MainWindow::disconnectFromHost()
157 vnc_view->startQuitting();
158 scroll_area->setWidget(0);
160 vnc_view->disconnect(); //remove all connections
163 disconnect_action->setEnabled(false);
166 void MainWindow::statusChanged(RemoteView::RemoteStatus status)
168 static RemoteView::RemoteStatus old_status = RemoteView::Disconnected;
171 case RemoteView::Connecting:
172 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
174 case RemoteView::Connected:
175 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
177 case RemoteView::Disconnecting:
178 if(old_status != RemoteView::Disconnected) { //Disconnecting also occurs while connecting, so check last state
179 QMaemo5InformationBox::information(this, "Connection lost");
182 case RemoteView::Disconnected:
183 if(old_status == RemoteView::Disconnecting) {
184 scroll_area->setWidget(0); //remove widget