cleanup
[fapman] / settings.cpp
1 /*
2         This file is part of Faster Application Manager.
3
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.
8
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.
13
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/>.
16
17         (C) Heikki Holstila 2010
18 */
19
20 #include "settings.h"
21 #include "ui_settings.h"
22 #include "mainwindow.h"
23 #include "aaptinterface.h"
24 #include "packageview.h"
25 #include "confirmdialog.h"
26 #include "searchoptions.h"
27
28 Settings::Settings(QWidget *parent) :
29     QDialog(parent),
30     ui(new Ui::Settings)
31 {
32     ui->setupUi(this);
33
34         iAptInterface = 0;
35         iQSettings = new QSettings("/root/.fapman/settings.ini",QSettings::IniFormat);
36 }
37
38 Settings::~Settings()
39 {
40         iQSettings->sync();
41         delete iQSettings;
42     delete ui;
43 }
44
45 void Settings::changeEvent(QEvent *e)
46 {
47     QDialog::changeEvent(e);
48     switch (e->type()) {
49     case QEvent::LanguageChange:
50         ui->retranslateUi(this);
51         break;
52     default:
53         break;
54     }
55 }
56
57 void Settings::openWin()
58 {
59         ui->checkBox_fetchdates->setChecked( iQSettings->value("fetch_dates", false).toBool() );
60         ui->checkBox_autorotation->setChecked( iQSettings->value("disable_autorotation", false).toBool() );
61         ui->checkBox_autoremove->setChecked( iQSettings->value("enable_autoremove", true).toBool() );
62         ui->checkBox_autoclean->setChecked( iQSettings->value("enable_autoclean", true).toBool() );
63         ui->checkBox_remove_readfull->setChecked( iQSettings->value("remove_readfull", false).toBool() );
64
65         ui->checkBox_proxies->setChecked( iQSettings->value("use_proxies", false).toBool() );
66         ui->lineEdit_http_proxy->setText( iQSettings->value("http_proxy","").toString() );
67         ui->lineEdit_https_proxy->setText( iQSettings->value("https_proxy","").toString() );
68
69         ui->comboBox_sortorder->setCurrentIndex( iQSettings->value("default_sort_order",0).toInt() );
70
71         ui->checkBox_playsound->setChecked( iQSettings->value("sound_notify", false).toBool() );
72         ui->lineEdit_soundfile->setText( iQSettings->value("sound_file","/usr/share/sounds/ui-operation_ready.wav").toString() );
73
74         open();
75 }
76
77 void Settings::on_btn_OK_clicked()
78 {
79         if( ui->checkBox_fetchdates->isChecked() != iQSettings->value("fetch_dates",false).toBool() && iAptInterface ) {
80                 iAptInterface->setNeedRefresh(-1,-1,-1,1);
81         }
82         if( ui->comboBox_sortorder->currentIndex() != iQSettings->value("default_sort_order",0).toInt() ) {
83                 iPackageView->setSortOrder( (PackageView::sortOrder)ui->comboBox_sortorder->currentIndex() );
84         }
85
86         iQSettings->setValue("fetch_dates", ui->checkBox_fetchdates->isChecked() );
87         iQSettings->setValue("disable_autorotation", ui->checkBox_autorotation->isChecked() );
88         iQSettings->setValue("enable_autoremove", ui->checkBox_autoremove->isChecked() );
89         iQSettings->setValue("enable_autoclean", ui->checkBox_autoclean->isChecked() );
90         iQSettings->setValue("remove_readfull", ui->checkBox_remove_readfull->isChecked() );
91
92         iQSettings->setValue("use_proxies", ui->checkBox_proxies->isChecked() );
93         iQSettings->setValue("http_proxy", ui->lineEdit_http_proxy->text() );
94         iQSettings->setValue("https_proxy", ui->lineEdit_https_proxy->text() );
95
96         iQSettings->setValue("default_sort_order", ui->comboBox_sortorder->currentIndex() );
97
98         iQSettings->setValue("sound_notify", ui->checkBox_playsound->isChecked() );
99         iQSettings->setValue("sound_file", ui->lineEdit_soundfile->text() );
100
101         if( ui->comboBox_sortorder->currentIndex() == (int)PackageView::SortDateDesc && !ui->checkBox_fetchdates->isChecked() ) {
102                 iQSettings->setValue("fetch_dates", true );
103                 iAptInterface->setNeedRefresh(-1,-1,-1,1);
104
105                 ConfirmDialog d(false, this);
106                 d.setText("Notice","You have selected date as the default sorting criterion. Fetching dates has been automatically enabled.");
107                 d.exec();
108         }
109
110 #ifdef Q_WS_MAEMO_5
111         if( !iQSettings->value("disable_autorotation",false).toBool() ) {
112                 dynamic_cast<MainWindow*>(this->parent())->setAttribute(Qt::WA_Maemo5AutoOrientation);
113         } else {
114                 dynamic_cast<MainWindow*>(this->parent())->setAttribute(Qt::WA_Maemo5LandscapeOrientation);
115         }
116 #endif
117
118         accept();
119 }
120
121 void Settings::on_pushButton_picksound_clicked()
122 {
123         //QFileInfo i( ui->lineEdit_soundfile->text() );
124         QString f = QFileDialog::getOpenFileName(this, "Select sound file", "/", "Audio (*.wav *.mp3 *.ogg)");
125         if( !f.isNull() ) {
126                 ui->lineEdit_soundfile->setText(f);
127         }
128 }
129
130 void Settings::on_pushButton_searchOptions_clicked()
131 {
132         SearchOptions s(this);
133         s.setSelections( iQSettings->value("search_pkgnames",true).toBool(),
134                                          iQSettings->value("search_displaynames",true).toBool(),
135                                          iQSettings->value("search_descshort",true).toBool(),
136                                          iQSettings->value("search_desclong",false).toBool() );
137         if( s.exec() )
138         {
139                 iQSettings->setValue("search_pkgnames", s.searchPkgName() );
140                 iQSettings->setValue("search_displaynames", s.searchDisplayName() );
141                 iQSettings->setValue("search_descshort", s.searchDescShort() );
142                 iQSettings->setValue("search_desclong", s.searchDescLong() );
143
144                 iPackageView->setSearchOptions(s.searchPkgName(), s.searchDisplayName(),
145                                                                            s.searchDescShort(), s.searchDescLong() );
146         }
147 }