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 = 2;
35 if(config_ver == current_ver) //config file up-to-date
38 if(settings.allKeys().isEmpty()) { //no config file
39 settings.setValue("config_version", current_ver);
44 std::cout << "Migrating from configuration ver. " << config_ver << "\n";
47 int left_zoom = settings.value("left_zoom", 0).toInt();
48 int right_zoom = settings.value("left_zoom", 0).toInt();
50 settings.setValue("left_zoom", left_zoom+1);
52 settings.setValue("left_zoom", right_zoom+1);
56 QString last_hostname = settings.value("last_hostname", "").toString();
57 settings.remove("last_hostname");
58 if(!last_hostname.isEmpty()) {
59 //make sure hostname is sane
60 last_hostname.remove(QChar('/'));
61 last_hostname.remove(QChar('\\'));
62 last_hostname = last_hostname.toLower();
64 settings.setValue(QString("hosts/%1/position").arg(last_hostname), 0);
69 Q_ASSERT(config_ver == current_ver);
70 settings.setValue("config_version", config_ver);
75 Preferences::Preferences(QWidget *parent):
78 setWindowTitle(tr("Preferences"));
80 QHBoxLayout *layout1 = new QHBoxLayout();
81 QVBoxLayout *layout2 = new QVBoxLayout();
84 QMaemo5ValueButton *rotation = new QMaemo5ValueButton(tr("Screen Rotation"), this);
85 rotation_selector = new QMaemo5ListPickSelector(this);
86 QStandardItemModel *model = new QStandardItemModel(0, 1, this);
87 model->appendRow(new QStandardItem(tr("Automatic")));
88 model->appendRow(new QStandardItem(tr("Landscape")));
89 model->appendRow(new QStandardItem(tr("Portrait")));
90 rotation_selector->setModel(model);
91 rotation_selector->setCurrentIndex(settings.value("screen_rotation", 0).toInt());
92 rotation->setPickSelector(rotation_selector);
93 rotation->setValueLayout(QMaemo5ValueButton::ValueBesideText);
94 layout2->addWidget(rotation);
96 QMaemo5ValueButton *leftzoom = new QMaemo5ValueButton(tr("Left Zoom Button"), this);
97 leftzoom_selector = new QMaemo5ListPickSelector(this);
98 QStandardItemModel *key_model = new QStandardItemModel(0, 1, this);
99 key_model->insertRow(0, new QStandardItem(tr("Left Click")));
100 key_model->insertRow(1, new QStandardItem(tr("Right Click")));
101 key_model->insertRow(2, new QStandardItem(tr("Middle Click")));
102 key_model->insertRow(3, new QStandardItem(tr("Wheel Up")));
103 key_model->insertRow(4, new QStandardItem(tr("Wheel Down")));
104 key_model->insertRow(5, new QStandardItem(tr("Page Up")));
105 key_model->insertRow(6, new QStandardItem(tr("Page Down")));
106 leftzoom_selector->setModel(key_model);
107 leftzoom_selector->setCurrentIndex(settings.value("left_zoom", 0).toInt());
108 leftzoom->setPickSelector(leftzoom_selector);
109 leftzoom->setValueLayout(QMaemo5ValueButton::ValueBesideText);
110 layout2->addWidget(leftzoom);
112 QMaemo5ValueButton *rightzoom = new QMaemo5ValueButton(tr("Right Zoom Button"), this);
113 rightzoom_selector = new QMaemo5ListPickSelector(this);
114 rightzoom_selector->setModel(key_model);
115 rightzoom_selector->setCurrentIndex(settings.value("right_zoom", 1).toInt());
116 rightzoom->setPickSelector(rightzoom_selector);
117 rightzoom->setValueLayout(QMaemo5ValueButton::ValueBesideText);
118 layout2->addWidget(rightzoom);
120 //useful if one only wants to click using the zoom buttons exclusively
121 disable_tapping = new QCheckBox(tr("Disable Tapping"), this);
122 disable_tapping->setChecked(settings.value("disable_tapping", false).toBool());
123 layout2->addWidget(disable_tapping);
126 QPushButton *ok = new QPushButton(tr("Done"));
127 ok->setMaximumWidth(100);
129 layout1->addLayout(layout2);
130 layout1->addWidget(ok);
134 connect(ok, SIGNAL(clicked()),
135 this, SLOT(accept()));
136 connect(this, SIGNAL(accepted()),
140 void Preferences::save()
143 settings.setValue("screen_rotation", rotation_selector->currentIndex());
144 settings.setValue("left_zoom", leftzoom_selector->currentIndex());
145 settings.setValue("right_zoom", rightzoom_selector->currentIndex());
148 settings.setValue("disable_tapping", disable_tapping->isChecked());