2 #include "ui_settings.h"
3 #include "../common/dbusclient.h"
8 Settings::Settings(QWidget *parent) :
12 intervals << tr("1 second") << tr("2 seconds") << tr("5 seconds") <<
13 tr("10 seconds") << tr("20 seconds") << tr("30 seconds") <<
14 tr("60 seconds") << tr("120 seconds");
17 addUIElements(); //Add Maemo 5 Specific widgets
19 settings = new QSettings();
22 //Make the window a modal panel
23 setWindowFlags(Qt::Dialog);
24 setWindowModality(Qt::ApplicationModal);
26 connect(ui->login_user, SIGNAL(returnPressed()), ui->login_pass, SLOT(setFocus()));
27 connect(ui->login_pass, SIGNAL(returnPressed()), SLOT(close()));
28 connect(ui->ok_button, SIGNAL(clicked()), SLOT(close()));
35 delete interval_button;
36 delete interval_selector;
37 delete interval_model;
43 void Settings::addUIElements()
45 QVBoxLayout* ui_layout = (QVBoxLayout*)ui->scrollArea->widget()->layout();
47 interval_button = new QMaemo5ValueButton("Update Interval",ui->scrollArea->widget());
48 interval_button->setValueLayout(QMaemo5ValueButton::ValueBesideText);
49 interval_selector = new QMaemo5ListPickSelector;
50 interval_model = new QStandardItemModel(0, 1);
51 populateListModel(interval_model);
52 interval_selector->setModel(interval_model);
53 interval_button->setPickSelector(interval_selector);
54 ui_layout->insertWidget(4, interval_button);
58 void Settings::closeEvent(QCloseEvent *event)
68 void Settings::loadSettings()
70 unsigned short location;
71 unsigned short interval;
73 ui->connectIfNecessary->setChecked( settings->value("autoconnect",true).toBool() );
74 ui->launchOnPowerOn->setChecked( settings->value("autolaunch",false).toBool() );
76 location = settings->value("location", LOCATION_METHOD_GNSS).toInt();
78 ui->login_user->setText(settings->value("user","my_username").toString());
79 ui->login_pass->setText(settings->value("pass","my_password").toString());
81 switch(settings->value("interval", LOCATION_INTERVAL_20S).toInt()) {
82 case LOCATION_INTERVAL_1S:
85 case LOCATION_INTERVAL_2S:
88 case LOCATION_INTERVAL_5S:
91 case LOCATION_INTERVAL_10S:
94 case LOCATION_INTERVAL_20S:
97 case LOCATION_INTERVAL_30S:
100 case LOCATION_INTERVAL_60S:
103 case LOCATION_INTERVAL_120S:
107 interval_selector->setCurrentIndex(interval);
110 if (DBusClient::daemonRunning())
111 ui->status_on->setChecked(true);
113 ui->status_off->setChecked(true);
117 case LOCATION_METHOD_GNSS:
118 ui->location_gps->setChecked(true);
120 case LOCATION_METHOD_AGNSS | LOCATION_METHOD_ACWP:
121 ui->location_gps_network->setChecked(true);
123 case LOCATION_METHOD_ACWP:
124 ui->location_network->setChecked(true);
130 void Settings::populateListModel(QStandardItemModel *model)
132 for(int i = 0; i < intervals.size(); ++i) {
133 QStandardItem *item = new QStandardItem(intervals.at(i));
134 item->setTextAlignment(Qt::AlignCenter); // the Maemo 5 design spec recommends this.
135 item->setEditable(false); // prevent editing of the item
136 model->appendRow(item);
140 void Settings::storeSettings()
142 unsigned short status;
143 unsigned short location;
144 unsigned short interval;
146 settings->setValue("autoconnect", ui->connectIfNecessary->checkState());
147 settings->setValue("autolaunch", ui->launchOnPowerOn->checkState());
148 settings->setValue("user", ui->login_user->text());
149 settings->setValue("pass", ui->login_pass->text());
151 switch(interval_selector->currentIndex()) {
153 interval = LOCATION_INTERVAL_1S;
156 interval = LOCATION_INTERVAL_2S;
159 interval = LOCATION_INTERVAL_5S;
162 interval = LOCATION_INTERVAL_10S;
165 interval = LOCATION_INTERVAL_20S;
168 interval = LOCATION_INTERVAL_30S;
171 interval = LOCATION_INTERVAL_60S;
174 interval = LOCATION_INTERVAL_120S;
177 settings->setValue("interval", interval);
179 if (ui->location_gps->isChecked())
180 location = LOCATION_METHOD_GNSS;
181 else if (ui->location_gps_network->isChecked())
182 location = LOCATION_METHOD_AGNSS | LOCATION_METHOD_ACWP;
183 else if (ui->location_network->isChecked())
184 location = LOCATION_METHOD_ACWP;
185 settings->setValue("location", location);
188 settings->setValue("status", status);
192 void Settings::updateDaemon()
194 if (ui->status_on->isChecked()) {
195 if (DBusClient::daemonRunning())
196 DBusClient::reloadDaemonConfig();
198 (new QProcess())->start(QString("/opt/linfati.com/googlelatitude-daemon"));
200 else if (ui->status_off->isChecked())
201 DBusClient::quitDaemon();
202 //else if (ui->status_hide->isChecked())
203 // status = STATUS_HIDE;
207 void Settings::changeEvent(QEvent *e)
209 QWidget::changeEvent(e);
211 case QEvent::LanguageChange:
212 ui->retranslateUi(this);