1 #include "mainwindow.h"
12 MainWindow::MainWindow(QString url, int quality):
15 scroll_area(new QScrollArea(0))
17 setWindowTitle("Presence VNC");
18 swipe_start = QPoint(0,0);
19 setAttribute(Qt::WA_Maemo5StackedWindow);
22 toolbar = new QToolBar(0);
23 toolbar->addAction("Esc", this, SLOT(sendEsc()));
24 toolbar->addAction("Tab", this, SLOT(sendTab()));
28 QMenuBar *menu = new QMenuBar(this);
29 QAction *connect_action = new QAction("Connect", this);
30 disconnect_action = new QAction("Disconnect", this);
31 menu->addAction(connect_action);
32 menu->addAction(disconnect_action);
33 scaling = new QAction("Rescale Remote Screen", this);
34 scaling->setCheckable(true);
35 scaling->setChecked(true);
36 menu->addAction(scaling);
37 QAction *show_toolbar = new QAction("Show Toolbar", this);
38 show_toolbar->setCheckable(true);
39 show_toolbar->setChecked(true);
40 menu->addAction(show_toolbar);
41 QAction *about_action = new QAction("About", this);
42 menu->addAction(about_action);
44 //menu->setAttribute(Qt::WA_Maemo5StackedWindow);
47 connect(about_action, SIGNAL(triggered()),
49 connect(connect_action, SIGNAL(triggered()),
50 this, SLOT(connectDialog()));
51 connect(disconnect_action, SIGNAL(triggered()),
52 this, SLOT(disconnectFromHost()));
53 connect(show_toolbar, SIGNAL(toggled(bool)),
54 toolbar, SLOT(setVisible(bool)));
56 setCentralWidget(scroll_area);
59 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
60 //setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
63 disconnect_action->setEnabled(false);
64 toolbar->setEnabled(false);
67 vnc_view = new VncView(0, url, RemoteView::Quality(quality));
68 connect(scaling, SIGNAL(toggled(bool)),
69 vnc_view, SLOT(enableScaling(bool)));
70 connect(vnc_view, SIGNAL(statusChanged(RemoteView::RemoteStatus)),
71 this, SLOT(statusChanged(RemoteView::RemoteStatus)));
72 scroll_area->setWidget(vnc_view);
77 void MainWindow::grabZoomKeys(bool grab)
79 unsigned long val = (grab)?1:0;
80 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
82 qWarning("Couldn't get zoom key atom");
85 XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER,
86 32, PropModeReplace, reinterpret_cast<unsigned char *>(&val), 1);
89 void MainWindow::closeEvent(QCloseEvent*) {
95 void MainWindow::about() {
96 QMessageBox::about(this, tr("About Presence VNC"),
97 tr("<center><h1>Presence VNC 0.1 alpha</h1>\
98 A touch screen friendly VNC client\
99 <small><p>©2010 Christian Pulvermacher <pulvermacher@gmx.de></p>\
100 <p>Based on KRDC, © 2007-2008 Urs Wolfer</small></center>\
101 <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>"));
104 /* swipe not used, and doesn't work without scaling anyway :/
105 virtual bool event(QEvent *event) {
106 if(event->type() == QEvent::MouseMove) {
107 QMouseEvent *ev = dynamic_cast<QMouseEvent* >(event);
108 if(!swipe_start.isNull()) {
109 QPoint diff = swipe_start - ev->pos();
110 const int swipe_dist = 60;
111 if(diff.x() > swipe_dist and diff.y() < swipe_dist and diff.y() > -swipe_dist) { //
113 swipe_start = QPoint(0,0);
115 } else if((width() - ev->x()) < 10) {
116 swipe_start = ev->pos();
118 std::cout << "mousex: " << width() - ev->x() << "\n";
119 //TODO: make scrolling over border result in wheel events? i get weird (out of range) mouse events when that happens
121 } else if(event->type() == QEvent::MouseButtonRelease) {
122 swipe_start = QPoint(0,0);
125 // std::cout << "event " << event->type() << "\n";
126 return QScrollArea::event(event);
131 void MainWindow::connectDialog()
134 QString url = QInputDialog::getText(this, "Connect to Host", "VNC Server:", QLineEdit::Normal, settings.value("last_hostname", "").toString());
135 if(url.isEmpty()) { //dialog dismissed or nothing entered
138 settings.setValue("last_hostname", url);
139 url = "vnc://" + url;
141 disconnectFromHost();
143 vnc_view = new VncView(0, url, RemoteView::Quality(2)); //TODO: get quality in dialog
144 scroll_area->setWidget(vnc_view);
146 connect(scaling, SIGNAL(toggled(bool)),
147 vnc_view, SLOT(enableScaling(bool)));
148 connect(vnc_view, SIGNAL(statusChanged(RemoteView::RemoteStatus)),
149 this, SLOT(statusChanged(RemoteView::RemoteStatus)));
151 disconnect_action->setEnabled(true);
152 toolbar->setEnabled(true);
155 void MainWindow::disconnectFromHost()
160 vnc_view->startQuitting();
161 scroll_area->setWidget(0);
163 vnc_view->disconnect(); //remove all connections
166 disconnect_action->setEnabled(false);
167 toolbar->setEnabled(false);
170 void MainWindow::statusChanged(RemoteView::RemoteStatus status)
172 static RemoteView::RemoteStatus old_status = RemoteView::Disconnected;
175 case RemoteView::Connecting:
176 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
178 case RemoteView::Connected:
179 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
181 case RemoteView::Disconnecting:
182 if(old_status != RemoteView::Disconnected) { //Disconnecting also occurs while connecting, so check last state
183 QMaemo5InformationBox::information(this, "Connection lost");
186 case RemoteView::Disconnected:
187 if(old_status == RemoteView::Disconnecting) {
188 scroll_area->setWidget(0); //remove widget