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("Mod"); //TODO
24 toolbar->addAction("Tab", this, SLOT(sendTab()));
25 toolbar->addAction("Esc", this, SLOT(sendEsc()));
26 toolbar->addAction("PgUp", this, SLOT(sendPgUp()));
27 toolbar->addAction("PgDn", this, SLOT(sendPgDn()));
28 toolbar->addAction("Fullscreen", this, SLOT(toggleFullscreen()));
32 QMenuBar *menu = new QMenuBar(this);
33 QAction *connect_action = new QAction("Connect", this);
34 disconnect_action = new QAction("Disconnect", this);
35 menu->addAction(connect_action);
36 menu->addAction(disconnect_action);
37 scaling = new QAction("Rescale Remote Screen", this);
38 scaling->setCheckable(true);
39 scaling->setChecked(true);
40 menu->addAction(scaling);
41 QAction *show_toolbar = new QAction("Show Toolbar", this);
42 show_toolbar->setCheckable(true);
43 show_toolbar->setChecked(true);
44 menu->addAction(show_toolbar);
45 QAction *about_action = new QAction("About", this);
46 menu->addAction(about_action);
48 //menu->setAttribute(Qt::WA_Maemo5StackedWindow);
51 connect(about_action, SIGNAL(triggered()),
53 connect(connect_action, SIGNAL(triggered()),
54 this, SLOT(connectDialog()));
55 connect(disconnect_action, SIGNAL(triggered()),
56 this, SLOT(disconnectFromHost()));
57 connect(show_toolbar, SIGNAL(toggled(bool)),
58 toolbar, SLOT(setVisible(bool)));
60 setCentralWidget(scroll_area);
63 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
64 //setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
67 disconnect_action->setEnabled(false);
68 toolbar->setEnabled(false);
71 vnc_view = new VncView(0, url, RemoteView::Quality(quality));
72 connect(scaling, SIGNAL(toggled(bool)),
73 vnc_view, SLOT(enableScaling(bool)));
74 connect(vnc_view, SIGNAL(statusChanged(RemoteView::RemoteStatus)),
75 this, SLOT(statusChanged(RemoteView::RemoteStatus)));
76 scroll_area->setWidget(vnc_view);
81 void MainWindow::grabZoomKeys(bool grab)
83 unsigned long val = (grab)?1:0;
84 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
86 qWarning("Couldn't get zoom key atom");
89 XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER,
90 32, PropModeReplace, reinterpret_cast<unsigned char *>(&val), 1);
93 void MainWindow::closeEvent(QCloseEvent*) {
99 void MainWindow::about() {
100 QMessageBox::about(this, tr("About Presence VNC"),
101 tr("<center><h1>Presence VNC 0.1 alpha</h1>\
102 A touch screen friendly VNC client\
103 <small><p>©2010 Christian Pulvermacher <pulvermacher@gmx.de></p>\
104 <p>Based on KRDC, © 2007-2008 Urs Wolfer</small></center>\
105 <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>"));
108 /* swipe not used, and doesn't work without scaling anyway :/
109 virtual bool event(QEvent *event) {
110 if(event->type() == QEvent::MouseMove) {
111 QMouseEvent *ev = dynamic_cast<QMouseEvent* >(event);
112 if(!swipe_start.isNull()) {
113 QPoint diff = swipe_start - ev->pos();
114 const int swipe_dist = 60;
115 if(diff.x() > swipe_dist and diff.y() < swipe_dist and diff.y() > -swipe_dist) { //
117 swipe_start = QPoint(0,0);
119 } else if((width() - ev->x()) < 10) {
120 swipe_start = ev->pos();
122 std::cout << "mousex: " << width() - ev->x() << "\n";
123 //TODO: make scrolling over border result in wheel events? i get weird (out of range) mouse events when that happens
125 } else if(event->type() == QEvent::MouseButtonRelease) {
126 swipe_start = QPoint(0,0);
129 // std::cout << "event " << event->type() << "\n";
130 return QScrollArea::event(event);
135 void MainWindow::connectDialog()
138 QString url = QInputDialog::getText(this, "Connect to Host", "VNC Server:", QLineEdit::Normal, settings.value("last_hostname", "").toString());
139 if(url.isEmpty()) { //dialog dismissed or nothing entered
142 settings.setValue("last_hostname", url);
143 url = "vnc://" + url;
145 disconnectFromHost();
147 vnc_view = new VncView(0, url, RemoteView::Quality(2)); //TODO: get quality in dialog
148 scroll_area->setWidget(vnc_view);
150 connect(scaling, SIGNAL(toggled(bool)),
151 vnc_view, SLOT(enableScaling(bool)));
152 connect(vnc_view, SIGNAL(statusChanged(RemoteView::RemoteStatus)),
153 this, SLOT(statusChanged(RemoteView::RemoteStatus)));
155 disconnect_action->setEnabled(true);
156 toolbar->setEnabled(true);
159 void MainWindow::disconnectFromHost()
164 vnc_view->startQuitting();
165 scroll_area->setWidget(0);
167 vnc_view->disconnect(); //remove all connections
170 disconnect_action->setEnabled(false);
171 toolbar->setEnabled(false);
174 void MainWindow::statusChanged(RemoteView::RemoteStatus status)
176 static RemoteView::RemoteStatus old_status = RemoteView::Disconnected;
179 case RemoteView::Connecting:
180 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
182 case RemoteView::Connected:
183 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
185 case RemoteView::Disconnecting:
186 if(old_status != RemoteView::Disconnected) { //Disconnecting also occurs while connecting, so check last state
187 QMaemo5InformationBox::information(this, "Connection lost");
190 case RemoteView::Disconnected:
191 if(old_status == RemoteView::Disconnecting) {
192 scroll_area->setWidget(0); //remove widget