int main(int argc, char *argv[])
{
+ QCoreApplication::setOrganizationName("Presence VNC");
+ QCoreApplication::setApplicationName("Presence VNC");
+
QApplication app(argc, argv);
QString url;
url = arguments.at(1);
if(arguments.count() > 2)
quality = arguments.at(2).toInt();
- } else {
- url = QInputDialog::getText(0, "Connect to Host", "VNC Server:");
- if(url.isEmpty()) { //dialog dismissed or nothing entered
- return 1;
- }
- url = "vnc://" + url;
}
MainWindow main(url, quality);
main.show();
-
#include "mainwindow.h"
#include "vncview.h"
+#include <QtMaemo5>
#include <QX11Info>
#include <X11/Xlib.h>
#include <iostream>
MainWindow::MainWindow(QString url, int quality):
- QScrollArea(0)
+ QMainWindow(0),
+ vnc_view(0),
+ scroll_area(new QScrollArea(0))
{
swipe_start = QPoint(0,0);
setAttribute(Qt::WA_Maemo5StackedWindow);
+ //set up toolbar
+ toolbar = new QToolBar(0);
+ toolbar->addAction("Esc", this, SLOT(sendEsc()));
+ toolbar->addAction("Tab", this, SLOT(sendTab()));
+ addToolBar(toolbar);
+
//set up menu
QMenuBar *menu = new QMenuBar(this);
QAction *connect_action = new QAction("Connect", this);
disconnect_action = new QAction("Disconnect", this);
+ menu->addAction(connect_action);
+ menu->addAction(disconnect_action);
scaling = new QAction("Rescale Remote Screen", this);
scaling->setCheckable(true);
scaling->setChecked(true);
menu->addAction(scaling);
+ QAction *show_toolbar = new QAction("Show Toolbar", this);
+ show_toolbar->setCheckable(true);
+ show_toolbar->setChecked(true);
+ menu->addAction(show_toolbar);
QAction *about_action = new QAction("About", this);
menu->addAction(about_action);
this, SLOT(connectDialog()));
connect(disconnect_action, SIGNAL(triggered()),
this, SLOT(disconnectFromHost()));
+ connect(show_toolbar, SIGNAL(toggled(bool)),
+ toolbar, SLOT(setVisible(bool)));
+
+ setCentralWidget(scroll_area);
grabZoomKeys(true);
setAttribute(Qt::WA_Maemo5AutoOrientation, true);
vnc_view = new VncView(0, url, RemoteView::Quality(quality));
connect(scaling, SIGNAL(toggled(bool)),
vnc_view, SLOT(enableScaling(bool)));
- setWidget(vnc_view);
+ connect(vnc_view, SIGNAL(statusChanged(RemoteView::RemoteStatus)),
+ this, SLOT(statusChanged(RemoteView::RemoteStatus)));
+ scroll_area->setWidget(vnc_view);
vnc_view->start();
}
}
void MainWindow::closeEvent(QCloseEvent*) {
hide();
grabZoomKeys(false);
- vnc_view->startQuitting();
+ disconnectFromHost();
}
void MainWindow::about() {
void MainWindow::connectDialog()
{
- QString url = QInputDialog::getText(this, "Connect to Host", "VNC Server:");
+ QSettings settings;
+ QString url = QInputDialog::getText(this, "Connect to Host", "VNC Server:", QLineEdit::Normal, settings.value("last_hostname", "").toString());
if(url.isEmpty()) { //dialog dismissed or nothing entered
return;
}
+ settings.setValue("last_hostname", url);
url = "vnc://" + url;
disconnectFromHost();
vnc_view = new VncView(0, url, RemoteView::Quality(2)); //TODO: get quality in dialog
- setWidget(vnc_view);
+ scroll_area->setWidget(vnc_view);
connect(scaling, SIGNAL(toggled(bool)),
vnc_view, SLOT(enableScaling(bool)));
+ connect(vnc_view, SIGNAL(statusChanged(RemoteView::RemoteStatus)),
+ this, SLOT(statusChanged(RemoteView::RemoteStatus)));
vnc_view->start();
disconnect_action->setEnabled(true);
}
void MainWindow::disconnectFromHost()
{
+ if(!vnc_view)
+ return;
+
vnc_view->startQuitting();
- setWidget(0);
+ scroll_area->setWidget(0);
- disconnect(scaling, SIGNAL(toggled(bool)),
- vnc_view, SLOT(enableScaling(bool)));
+ vnc_view->disconnect(); //remove all connections
delete vnc_view;
vnc_view = 0;
disconnect_action->setEnabled(false);
}
+
+void MainWindow::statusChanged(RemoteView::RemoteStatus status)
+{
+ static RemoteView::RemoteStatus old_status = RemoteView::Disconnected;
+
+ switch(status) {
+ case RemoteView::Connecting:
+ setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
+ break;
+ case RemoteView::Connected:
+ setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
+ break;
+ case RemoteView::Disconnecting:
+ if(old_status != RemoteView::Disconnected) { //Disconnecting also occurs while connecting, so check last state
+ QMaemo5InformationBox::information(this, "Connection lost");
+ }
+ break;
+ case RemoteView::Disconnected:
+ if(old_status == RemoteView::Disconnecting) {
+ scroll_area->setWidget(0); //remove widget
+ }
+ break;
+ }
+
+ old_status = status;
+}
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
#include <QtGui>
-#include <QX11Info>
-
+#include "remoteview.h"
#include "vncview.h"
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
-
-#include <iostream>
-
-class MainWindow : public QScrollArea {
+class MainWindow : public QMainWindow {
Q_OBJECT
+public:
+ MainWindow(QString url, int quality);
+public slots:
+ void connectDialog();
+ void disconnectFromHost();
+ void about();
+ void statusChanged(RemoteView::RemoteStatus status);
+protected:
+ //virtual bool event(QEvent *event);
+ void closeEvent(QCloseEvent*);
private:
+ void grabZoomKeys(bool grab);
VncView *vnc_view;
- QWidget *menu;
+ QScrollArea *scroll_area;
+ //QWidget *menu;
+ QToolBar *toolbar;
QPoint swipe_start;
+ QAction *scaling;
+ QAction *disconnect_action;
-public:
- MainWindow(QString url, int quality) : QScrollArea(0) {
- swipe_start = QPoint(0,0);
- setAttribute(Qt::WA_Maemo5StackedWindow);
-
- vnc_view = new VncView(0, url, RemoteView::Quality(quality));
- setWidget(vnc_view);
-
- //set up menu
- QMenuBar *menu = new QMenuBar(this);
- QAction *scaling = new QAction("Rescale Remote Screen", this);
- scaling->setCheckable(true);
- scaling->setChecked(true);
- menu->addAction(scaling);
- QAction *about_action = new QAction("About", this);
- menu->addAction(about_action);
-
- //menu->setAttribute(Qt::WA_Maemo5StackedWindow);
- //menu->hide();
-
- connect(scaling, SIGNAL(toggled(bool)),
- vnc_view, SLOT(enableScaling(bool)));
- connect(about_action, SIGNAL(triggered()),
- this, SLOT(about()));
-
- grabZoomKeys(true);
- setAttribute(Qt::WA_Maemo5AutoOrientation, true);
- //setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
-
- vnc_view->start();
- }
-
- void grabZoomKeys(bool grab)
- {
- unsigned long val = (grab)?1:0;
- Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
- if(!atom) {
- qWarning("Couldn't get zoom key atom");
- return;
- }
- XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER,
- 32, PropModeReplace, reinterpret_cast<unsigned char *>(&val), 1);
- }
- void closeEvent(QCloseEvent*) {
- hide();
- grabZoomKeys(false);
- vnc_view->startQuitting();
- }
-public slots:
- void about() {
- QMessageBox::about(this, tr("About Presence VNC"),
- tr("<center><h1>Presence VNC 0.1 alpha</h1>\
-A touch screen friendly VNC client\
-<small><p>©2010 Christian Pulvermacher <pulvermacher@gmx.de></p>\
-<p>Based on KRDC, © 2007-2008 Urs Wolfer</small></center>\
-<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>"));
- }
-
-protected:
-/* swipe not used, and doesn't work without scaling anyway :/
- virtual bool event(QEvent *event) {
- if(event->type() == QEvent::MouseMove) {
- QMouseEvent *ev = dynamic_cast<QMouseEvent* >(event);
- if(!swipe_start.isNull()) {
- QPoint diff = swipe_start - ev->pos();
- const int swipe_dist = 60;
- if(diff.x() > swipe_dist and diff.y() < swipe_dist and diff.y() > -swipe_dist) { //
- menu->show();
- swipe_start = QPoint(0,0);
- }
- } else if((width() - ev->x()) < 10) {
- swipe_start = ev->pos();
- }
- std::cout << "mousex: " << width() - ev->x() << "\n";
- //TODO: make scrolling over border result in wheel events? i get weird (out of range) mouse events when that happens
- return true;
- } else if(event->type() == QEvent::MouseButtonRelease) {
- swipe_start = QPoint(0,0);
- return true;
- } else {
-// std::cout << "event " << event->type() << "\n";
- return QScrollArea::event(event);
- }
- }
- */
+private slots:
+ void sendEsc() { vnc_view->sendKey(Qt::Key_Escape); }
+ void sendTab() { vnc_view->sendKey(Qt::Key_Tab); }
};
+#endif
else
m_buttonMask &= 0xfe;
vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
- kDebug(5011) << "left zoom";
} else if(e->key() == Qt::Key_F7) {
if(pressed)
m_buttonMask |= 0x04;
else
m_buttonMask &= 0xfb;
vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
- kDebug(5011) << "right zoom";
} else if (k) {
vncThread.keyEvent(k, pressed);
}
vncThread.clientCut(text);
}
+//fake key events
+void VncView::sendKey(Qt::Key key)
+{
+ rfbKeySym k = 0;
+ if(key == Qt::Key_Escape)
+ switch(key) {
+ case Qt::Key_Escape:
+ k = 0xff1b;
+ break;
+ case Qt::Key_Tab:
+ k = 0xff09;
+ break;
+ default:
+ kDebug(5011) << "unhandled Qt::Key value " << key;
+ return;
+ }
+
+ vncThread.keyEvent(k, true);
+ vncThread.keyEvent(k, false);
+}
+
#include "moc_vncview.cpp"
void setQuality(int q);
void setViewOnly(bool viewOnly);
void showDotCursor(DotCursorState state);
+ void sendKey(Qt::Key key);
virtual void updateConfiguration();