2 This file is part of Faster Application Manager.
4 Faster Application Manager is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 Faster Application Manager is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with Faster Application Manager. If not, see <http://www.gnu.org/licenses/>.
17 (C) Heikki Holstila 2010
22 #include "ui_settings.h"
23 #include "mainwindow.h"
24 #include "aaptinterface.h"
25 #include "packageview.h"
26 #include "confirmdialog.h"
27 #include "searchoptions.h"
29 Settings::Settings(QWidget *parent) :
36 iQSettings = new QSettings("/root/.fapman/settings.ini",QSettings::IniFormat);
42 delete iQSettings; iQSettings=0;
46 void Settings::changeEvent(QEvent *e)
48 QDialog::changeEvent(e);
50 case QEvent::LanguageChange:
51 ui->retranslateUi(this);
58 void Settings::openWin()
60 ui->checkBox_fetchdates->setChecked( iQSettings->value("fetch_dates", false).toBool() );
61 ui->checkBox_autorotation->setChecked( iQSettings->value("disable_autorotation", false).toBool() );
62 ui->checkBox_autoremove->setChecked( iQSettings->value("enable_autoremove", true).toBool() );
63 ui->checkBox_autoclean->setChecked( iQSettings->value("enable_autoclean", true).toBool() );
64 ui->checkBox_remove_readfull->setChecked( iQSettings->value("remove_readfull", false).toBool() );
65 ui->checkBox_no_catalogs_autoupdate->setChecked( iQSettings->value("no_catalogs_autoupdate",false).toBool() );
66 ui->checkBox_always_fetch_changes->setChecked( iQSettings->value("always_fetch_changes",false).toBool() );
68 ui->checkBox_proxies->setChecked( iQSettings->value("use_proxies", false).toBool() );
69 ui->lineEdit_http_proxy->setText( iQSettings->value("http_proxy","").toString() );
70 ui->lineEdit_https_proxy->setText( iQSettings->value("https_proxy","").toString() );
72 ui->comboBox_sortorder->setCurrentIndex( iQSettings->value("default_sort_order",0).toInt() );
74 ui->checkBox_playsound->setChecked( iQSettings->value("sound_notify", false).toBool() );
75 ui->lineEdit_soundfile->setText( iQSettings->value("sound_file","/usr/share/sounds/ui-operation_ready.wav").toString() );
80 void Settings::on_btn_OK_clicked()
82 if( ui->checkBox_fetchdates->isChecked() != iQSettings->value("fetch_dates",false).toBool() && iAptInterface ) {
83 iAptInterface->setNeedRefresh(-1,-1,-1,1);
85 if( ui->comboBox_sortorder->currentIndex() != iQSettings->value("default_sort_order",0).toInt() ) {
86 iPackageView->setSortOrder( (PackageView::sortOrder)ui->comboBox_sortorder->currentIndex() );
89 iQSettings->setValue("fetch_dates", ui->checkBox_fetchdates->isChecked() );
90 iQSettings->setValue("disable_autorotation", ui->checkBox_autorotation->isChecked() );
91 iQSettings->setValue("enable_autoremove", ui->checkBox_autoremove->isChecked() );
92 iQSettings->setValue("enable_autoclean", ui->checkBox_autoclean->isChecked() );
93 iQSettings->setValue("remove_readfull", ui->checkBox_remove_readfull->isChecked() );
94 iQSettings->setValue("no_catalogs_autoupdate", ui->checkBox_no_catalogs_autoupdate->isChecked() );
95 iQSettings->setValue("always_fetch_changes", ui->checkBox_always_fetch_changes->isChecked() );
97 iQSettings->setValue("use_proxies", ui->checkBox_proxies->isChecked() );
98 iQSettings->setValue("http_proxy", ui->lineEdit_http_proxy->text().trimmed() );
99 iQSettings->setValue("https_proxy", ui->lineEdit_https_proxy->text().trimmed() );
101 iQSettings->setValue("default_sort_order", ui->comboBox_sortorder->currentIndex() );
103 iQSettings->setValue("sound_notify", ui->checkBox_playsound->isChecked() );
104 iQSettings->setValue("sound_file", ui->lineEdit_soundfile->text() );
106 if( ui->comboBox_sortorder->currentIndex() == (int)PackageView::SortDateDesc && !ui->checkBox_fetchdates->isChecked() ) {
107 iQSettings->setValue("fetch_dates", true );
108 iAptInterface->setNeedRefresh(-1,-1,-1,1);
110 ConfirmDialog d(false, this);
111 d.setText("Notice","You have selected date as the default sorting criterion. Fetching dates has been automatically enabled.");
116 if( !iQSettings->value("disable_autorotation",false).toBool() ) {
117 dynamic_cast<MainWindow*>(this->parent())->setAttribute(Qt::WA_Maemo5AutoOrientation);
119 dynamic_cast<MainWindow*>(this->parent())->setAttribute(Qt::WA_Maemo5LandscapeOrientation);
126 void Settings::on_pushButton_picksound_clicked()
128 //QFileInfo i( ui->lineEdit_soundfile->text() );
129 QString f = QFileDialog::getOpenFileName(this, "Select sound file", "/", "Audio (*.wav *.mp3 *.ogg)");
131 ui->lineEdit_soundfile->setText(f);
135 void Settings::on_pushButton_searchOptions_clicked()
137 SearchOptions s(this);
138 s.setSelections( iQSettings->value("search_pkgnames",true).toBool(),
139 iQSettings->value("search_displaynames",true).toBool(),
140 iQSettings->value("search_descshort",true).toBool(),
141 iQSettings->value("search_desclong",false).toBool() );
144 iQSettings->setValue("search_pkgnames", s.searchPkgName() );
145 iQSettings->setValue("search_displaynames", s.searchDisplayName() );
146 iQSettings->setValue("search_descshort", s.searchDescShort() );
147 iQSettings->setValue("search_desclong", s.searchDescLong() );
149 iPackageView->setSearchOptions(s.searchPkgName(), s.searchDisplayName(),
150 s.searchDescShort(), s.searchDescLong() );
154 QNetworkProxy Settings::createProxyFromString(QString proxystr)
156 proxystr = proxystr.trimmed();
157 QString hostname = "";
163 int pos_proto = proxystr.indexOf("://");
164 if( pos_proto != -1 )
166 proto = proxystr.left(pos_proto+3);
167 proxystr = proxystr.mid(pos_proto+3);
172 int pos_half = proxystr.indexOf('@');
176 temp = proxystr.mid(pos_half+1);
177 temp2 = proxystr.left(pos_half);
180 if( !temp2.isNull() ) {
181 int pos_pass = temp2.indexOf(':');
185 user = temp2.left(pos_pass);
186 pass = temp2.mid(pos_pass+1);
190 int pos_port = temp.indexOf(':');
194 hostname = temp.left(pos_port);
195 port = temp.mid(pos_port+1).remove('/').toInt();
198 hostname = proto + hostname;
199 qDebug() << "creating proxy" << hostname << port << user << pass;
201 QNetworkProxy p(QNetworkProxy::HttpProxy, hostname, port, user, pass);