From b50155674d2a9bf2c3cf80668a844ce42a71251b Mon Sep 17 00:00:00 2001 From: christian Date: Sun, 18 Jul 2010 15:29:45 +0200 Subject: [PATCH] add preferences dialog --- src/mainwindow.cpp | 26 ++++++++++++++++-- src/mainwindow.h | 2 ++ src/preferences.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++++ src/preferences.h | 38 +++++++++++++++++++++++++ src/vncclientthread.cpp | 1 + vnc.pro | 6 ++-- 6 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 src/preferences.cpp create mode 100644 src/preferences.h diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 364d20b..1fb945c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,4 +1,5 @@ #include "mainwindow.h" +#include "preferences.h" #include "vncview.h" #include @@ -44,6 +45,8 @@ MainWindow::MainWindow(QString url, int quality): show_toolbar->setCheckable(true); show_toolbar->setChecked(settings.value("show_toolbar", true).toBool()); menu->addAction(show_toolbar); + QAction *pref_action = new QAction("Preferences", this); + menu->addAction(pref_action); QAction *about_action = new QAction("About", this); menu->addAction(about_action); @@ -52,6 +55,8 @@ MainWindow::MainWindow(QString url, int quality): connect(about_action, SIGNAL(triggered()), this, SLOT(about())); + connect(pref_action, SIGNAL(triggered()), + this, SLOT(showPreferences())); connect(connect_action, SIGNAL(triggered()), this, SLOT(connectDialog())); connect(disconnect_action, SIGNAL(triggered()), @@ -64,8 +69,7 @@ MainWindow::MainWindow(QString url, int quality): setCentralWidget(scroll_area); grabZoomKeys(true); - setAttribute(Qt::WA_Maemo5AutoOrientation, true); - //setAttribute(Qt::WA_Maemo5PortraitOrientation, true); + loadPreferences(); connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(forceResize())); @@ -253,3 +257,21 @@ void MainWindow::showModifierMenu() std::cout << "unhandled action?\n"; } } + +void MainWindow::showPreferences() +{ + Preferences *p = new Preferences(this); + p->exec(); + delete p; + + loadPreferences(); +} + +void MainWindow::loadPreferences() +{ + QSettings settings; + int rotation = settings.value("screen_rotation", 0).toInt(); + setAttribute(Qt::WA_Maemo5AutoOrientation, rotation == 0); + setAttribute(Qt::WA_Maemo5LandscapeOrientation, rotation == 1); + setAttribute(Qt::WA_Maemo5PortraitOrientation, rotation == 2); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index edfe2b8..70b8cab 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -21,6 +21,7 @@ public slots: void sendPgUp() { vnc_view->sendKey(Qt::Key_PageUp); } void sendPgDn() { vnc_view->sendKey(Qt::Key_PageDown); } void showModifierMenu(); + void showPreferences(); void statusChanged(RemoteView::RemoteStatus status); void toggleFullscreen(); protected: @@ -28,6 +29,7 @@ protected: void closeEvent(QCloseEvent*); private: void grabZoomKeys(bool grab); + void loadPreferences(); VncView *vnc_view; QScrollArea *scroll_area; //QWidget *menu; diff --git a/src/preferences.cpp b/src/preferences.cpp new file mode 100644 index 0000000..0311bda --- /dev/null +++ b/src/preferences.cpp @@ -0,0 +1,70 @@ +/* + Presence VNC + Copyright (C) 2010 Christian Pulvermacher + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#include +#include +#include + +#include "preferences.h" + +Preferences::Preferences(QWidget *parent): + QDialog(parent) +{ + setWindowTitle("Preferences"); + + QHBoxLayout *layout1 = new QHBoxLayout(); + QVBoxLayout *layout2 = new QVBoxLayout(); + + QMaemo5ValueButton *rotation = new QMaemo5ValueButton(tr("Screen Rotation"), this); + //rotation->setValueText(settings.value("sound_filename", SOUND_FILE).toString()); + rotation_selector = new QMaemo5ListPickSelector(this); + QStandardItemModel *model = new QStandardItemModel(0, 1, this); + model->appendRow(new QStandardItem(tr("Automatic"))); + model->appendRow(new QStandardItem(tr("Landscape"))); + model->appendRow(new QStandardItem(tr("Portrait"))); + rotation_selector->setModel(model); + rotation_selector->setCurrentIndex(settings.value("screen_rotation", 0).toInt()); + rotation->setPickSelector(rotation_selector); + rotation->setValueLayout(QMaemo5ValueButton::ValueBesideText); + layout2->addWidget(rotation); + + QPushButton *ok = new QPushButton("OK"); + + layout1->addLayout(layout2); + layout1->addWidget(ok); + + setLayout(layout1); + + connect(ok, SIGNAL(clicked()), + this, SLOT(accept())); + connect(this, SIGNAL(accepted()), + this, SLOT(save())); +} + +Preferences::~Preferences() +{ + +} + + +void Preferences::save() +{ + settings.setValue("screen_rotation", rotation_selector->currentIndex()); + + settings.sync(); +} diff --git a/src/preferences.h b/src/preferences.h new file mode 100644 index 0000000..9563160 --- /dev/null +++ b/src/preferences.h @@ -0,0 +1,38 @@ +/* + Presence VNC + Copyright (C) 2010 Christian Pulvermacher + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef PREFERENCES_H +#define PREFERENCES_H + +#include + +class QMaemo5ListPickSelector; + +class Preferences : public QDialog { + Q_OBJECT +public: + Preferences(QWidget *parent); + ~Preferences(); +private slots: + void save(); +private: + QSettings settings; + QMaemo5ListPickSelector *rotation_selector; +}; +#endif diff --git a/src/vncclientthread.cpp b/src/vncclientthread.cpp index a9dab21..49616fd 100644 --- a/src/vncclientthread.cpp +++ b/src/vncclientthread.cpp @@ -176,6 +176,7 @@ VncClientThread::~VncClientThread() kDebug(5011) << "Quit VNC thread success:" << quitSuccess; delete [] frameBuffer; + delete cl; } void VncClientThread::checkOutputErrorMessage() diff --git a/vnc.pro b/vnc.pro index 4cdd307..3edce47 100644 --- a/vnc.pro +++ b/vnc.pro @@ -3,12 +3,12 @@ TARGET = presencevnc-bin LIBS += -Llibvnc/libvncclient/.libs -lvncclient DEFINES += QTONLY QT += maemo5 -CONFIG += silent +CONFIG += silent debug OBJECTS_DIR = $${PWD}/tmp MOC_DIR = $${PWD}/tmp VPATH = $${PWD}/src INCLUDEPATH = $${PWD}/src -HEADERS += remoteview.h vncclientthread.h vncview.h mainwindow.h -SOURCES += main.cpp remoteview.cpp vncclientthread.cpp vncview.cpp mainwindow.cpp +HEADERS += remoteview.h vncclientthread.h vncview.h mainwindow.h preferences.h +SOURCES += main.cpp remoteview.cpp vncclientthread.cpp vncview.cpp mainwindow.cpp preferences.cpp -- 1.7.9.5