3 Copyright (C) 2010 Christian Pulvermacher
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.
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.
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.
22 #include <QMaemo5ValueButton>
23 #include <QMaemo5ListPickSelector>
26 #include "preferences.h"
30 void migrateConfiguration()
33 int config_ver = settings.value("config_version", 0).toInt();
34 const int current_ver = 3;
35 if(config_ver == current_ver) //config file up-to-date
37 if(config_ver > current_ver) {
38 std::cout << "Warning: Config file was created by a newer version of Presence VNC. This may break things.\n";
42 if(settings.allKeys().isEmpty()) { //no config file
43 settings.setValue("config_version", current_ver);
48 std::cout << "Migrating from configuration ver. " << config_ver << "\n";
51 int left_zoom = settings.value("left_zoom", 0).toInt();
52 int right_zoom = settings.value("left_zoom", 0).toInt();
54 settings.setValue("left_zoom", left_zoom+1);
56 settings.setValue("left_zoom", right_zoom+1);
60 QString last_hostname = settings.value("last_hostname", "").toString();
61 settings.remove("last_hostname");
62 if(!last_hostname.isEmpty()) {
63 //make sure hostname is sane
64 last_hostname.remove(QChar('/'));
65 last_hostname.remove(QChar('\\'));
66 last_hostname = last_hostname.toLower();
68 settings.setValue(QString("hosts/%1/position").arg(last_hostname), 0);
74 bool rescale = settings.value("rescale", false).toBool();
75 settings.remove("rescale");
83 settings.setValue("zoomlevel", zoomlevel);
87 Q_ASSERT(config_ver == current_ver);
88 settings.setValue("config_version", config_ver);
93 Preferences::Preferences(QWidget *parent):
96 setWindowTitle(tr("Preferences"));
98 QHBoxLayout *layout1 = new QHBoxLayout();
99 QVBoxLayout *layout2 = new QVBoxLayout();
102 QMaemo5ValueButton *rotation = new QMaemo5ValueButton(tr("Screen rotation"), this);
103 rotation_selector = new QMaemo5ListPickSelector(this);
104 QStandardItemModel *model = new QStandardItemModel(0, 1, this);
105 model->appendRow(new QStandardItem(tr("Automatic")));
106 model->appendRow(new QStandardItem(tr("Landscape")));
107 model->appendRow(new QStandardItem(tr("Portrait")));
108 rotation_selector->setModel(model);
109 rotation_selector->setCurrentIndex(settings.value("screen_rotation", 0).toInt());
110 rotation->setPickSelector(rotation_selector);
111 rotation->setValueLayout(QMaemo5ValueButton::ValueBesideText);
112 layout2->addWidget(rotation);
114 QMaemo5ValueButton *leftzoom = new QMaemo5ValueButton(tr("Left zoom button"), this);
115 leftzoom_selector = new QMaemo5ListPickSelector(this);
116 QStandardItemModel *key_model = new QStandardItemModel(0, 1, this);
117 key_model->insertRow(0, new QStandardItem(tr("Left click")));
118 key_model->insertRow(1, new QStandardItem(tr("Right click")));
119 key_model->insertRow(2, new QStandardItem(tr("Middle click")));
120 key_model->insertRow(3, new QStandardItem(tr("Wheel up")));
121 key_model->insertRow(4, new QStandardItem(tr("Wheel down")));
122 key_model->insertRow(5, new QStandardItem(tr("Page up")));
123 key_model->insertRow(6, new QStandardItem(tr("Page down")));
124 leftzoom_selector->setModel(key_model);
125 leftzoom_selector->setCurrentIndex(settings.value("left_zoom", 0).toInt());
126 leftzoom->setPickSelector(leftzoom_selector);
127 leftzoom->setValueLayout(QMaemo5ValueButton::ValueBesideText);
128 layout2->addWidget(leftzoom);
130 QMaemo5ValueButton *rightzoom = new QMaemo5ValueButton(tr("Right zoom button"), this);
131 rightzoom_selector = new QMaemo5ListPickSelector(this);
132 rightzoom_selector->setModel(key_model);
133 rightzoom_selector->setCurrentIndex(settings.value("right_zoom", 1).toInt());
134 rightzoom->setPickSelector(rightzoom_selector);
135 rightzoom->setValueLayout(QMaemo5ValueButton::ValueBesideText);
136 layout2->addWidget(rightzoom);
138 //useful if one only wants to click using the zoom buttons exclusively
139 disable_tapping = new QCheckBox(tr("Disable tapping"), this);
140 disable_tapping->setChecked(settings.value("disable_tapping", false).toBool());
141 layout2->addWidget(disable_tapping);
144 always_show_local_cursor = new QCheckBox(tr("Always show local cursor"), this);
145 always_show_local_cursor->setChecked(settings.value("always_show_local_cursor", false).toBool());
146 layout2->addWidget(always_show_local_cursor);
148 zoom_to_cursor = new QCheckBox(tr("Zoom to cursor"), this);
149 zoom_to_cursor->setChecked(settings.value("zoom_to_cursor", true).toBool());
150 layout2->addWidget(zoom_to_cursor);
152 QPushButton *ok = new QPushButton(tr("Done"));
153 ok->setMaximumWidth(100);
155 layout1->addLayout(layout2);
156 layout1->addWidget(ok);
160 connect(ok, SIGNAL(clicked()),
161 this, SLOT(accept()));
162 connect(this, SIGNAL(accepted()),
166 void Preferences::save()
169 settings.setValue("screen_rotation", rotation_selector->currentIndex());
170 settings.setValue("left_zoom", leftzoom_selector->currentIndex());
171 settings.setValue("right_zoom", rightzoom_selector->currentIndex());
172 settings.setValue("disable_tapping", disable_tapping->isChecked());
174 settings.setValue("always_show_local_cursor", always_show_local_cursor->isChecked());
175 settings.setValue("zoom_to_cursor", zoom_to_cursor->isChecked());