8f6cc9be3b442fe3ec683514db6fd8f64259ae93
[presencevnc] / src / preferences.cpp
1 /*
2     Presence VNC
3     Copyright (C) 2010 Christian Pulvermacher
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 #include <QtGui>
20 #include <QMaemo5ValueButton>
21 #include <QMaemo5ListPickSelector>
22
23 #include "preferences.h"
24
25 #include <iostream>
26
27 void migrateConfiguration()
28 {
29         QSettings settings;
30         int config_ver = settings.value("config_version", 0).toInt();
31         if(config_ver == 1) //config file up-to-date
32                 return;
33
34         std::cout << "Migrating from configuration ver. " << config_ver << "\n";
35
36         if(config_ver == 0) {
37                 int left_zoom = settings.value("left_zoom", 0).toInt();
38                 int right_zoom = settings.value("left_zoom", 0).toInt();
39                 if(left_zoom >= 2)
40                         settings.setValue("left_zoom", left_zoom+1);
41                 if(right_zoom >= 2)
42                         settings.setValue("left_zoom", right_zoom+1);
43                 config_ver = 1;
44         }
45         settings.setValue("config_version", config_ver);
46         settings.sync();
47 }
48
49
50 Preferences::Preferences(QWidget *parent):
51         QDialog(parent)
52 {
53         setWindowTitle("Preferences");
54
55         QHBoxLayout *layout1 = new QHBoxLayout();
56         QVBoxLayout *layout2 = new QVBoxLayout();
57
58         QMaemo5ValueButton *rotation = new QMaemo5ValueButton(tr("Screen Rotation"), this);
59         rotation_selector = new QMaemo5ListPickSelector(this);
60         QStandardItemModel *model = new QStandardItemModel(0, 1, this);
61         model->appendRow(new QStandardItem(tr("Automatic")));
62         model->appendRow(new QStandardItem(tr("Landscape")));
63         model->appendRow(new QStandardItem(tr("Portrait")));
64         rotation_selector->setModel(model);
65         rotation_selector->setCurrentIndex(settings.value("screen_rotation", 0).toInt());
66         rotation->setPickSelector(rotation_selector);
67         rotation->setValueLayout(QMaemo5ValueButton::ValueBesideText);
68         layout2->addWidget(rotation);
69
70         QMaemo5ValueButton *leftzoom = new QMaemo5ValueButton(tr("Left Zoom Button"), this);
71         leftzoom_selector = new QMaemo5ListPickSelector(this);
72         QStandardItemModel *key_model = new QStandardItemModel(0, 1, this);
73         key_model->insertRow(0, new QStandardItem(tr("Left Click")));
74         key_model->insertRow(1, new QStandardItem(tr("Right Click")));
75         key_model->insertRow(2, new QStandardItem(tr("Middle Click")));
76         key_model->insertRow(3, new QStandardItem(tr("Wheel Up")));
77         key_model->insertRow(4, new QStandardItem(tr("Wheel Down")));
78         key_model->insertRow(5, new QStandardItem(tr("Page Up")));
79         key_model->insertRow(6, new QStandardItem(tr("Page Down")));
80         leftzoom_selector->setModel(key_model);
81         leftzoom_selector->setCurrentIndex(settings.value("left_zoom", 0).toInt());
82         leftzoom->setPickSelector(leftzoom_selector);
83         leftzoom->setValueLayout(QMaemo5ValueButton::ValueBesideText);
84         layout2->addWidget(leftzoom);
85
86         QMaemo5ValueButton *rightzoom = new QMaemo5ValueButton(tr("Right Zoom Button"), this);
87         rightzoom_selector = new QMaemo5ListPickSelector(this);
88         rightzoom_selector->setModel(key_model);
89         rightzoom_selector->setCurrentIndex(settings.value("right_zoom", 1).toInt());
90         rightzoom->setPickSelector(rightzoom_selector);
91         rightzoom->setValueLayout(QMaemo5ValueButton::ValueBesideText);
92         layout2->addWidget(rightzoom);
93
94         disable_tapping = new QCheckBox(tr("Disable Tapping"), this);
95         disable_tapping->setChecked(settings.value("disable_tapping", false).toBool());
96         layout2->addWidget(disable_tapping);
97
98         QPushButton *ok = new QPushButton("Done");
99         ok->setMaximumWidth(100);
100
101         layout1->addLayout(layout2);
102         layout1->addWidget(ok);
103
104         setLayout(layout1);
105
106         connect(ok, SIGNAL(clicked()),
107                 this, SLOT(accept()));
108         connect(this, SIGNAL(accepted()),
109                 this, SLOT(save()));
110 }
111
112 Preferences::~Preferences() { }
113
114 void Preferences::save()
115 {
116         settings.setValue("screen_rotation", rotation_selector->currentIndex());
117         settings.setValue("left_zoom", leftzoom_selector->currentIndex());
118         settings.setValue("right_zoom", rightzoom_selector->currentIndex());
119         settings.setValue("disable_tapping", disable_tapping->isChecked());
120
121         settings.sync();
122 }