0.7.1
[fapman] / repoview.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 <QtGui>
21 #include "repoview.h"
22 #include "ui_repoview.h"
23 #include "mainwindow.h"
24 #include "aaptinterface.h"
25 #include "confirmdialog.h"
26 #include "repository.h"
27 #include "repoedit.h"
28
29 RepoView::RepoView(QWidget *parent) :
30     QMainWindow(parent),
31     ui(new Ui::RepoView)
32 {
33         iMainWindow = dynamic_cast<MainWindow*>(parent);
34         ui->setupUi(this);
35 #ifdef Q_WS_MAEMO_5
36         this->setAttribute(Qt::WA_Maemo5StackedWindow);
37         this->setWindowFlags(Qt::Window);
38         this->setAttribute(Qt::WA_Maemo5AutoOrientation);
39 #endif
40
41         iModified = false;
42 }
43
44 RepoView::~RepoView()
45 {
46     delete ui;
47 }
48
49 void RepoView::changeEvent(QEvent *e)
50 {
51     QMainWindow::changeEvent(e);
52     switch (e->type()) {
53     case QEvent::LanguageChange:
54         ui->retranslateUi(this);
55         break;
56     default:
57         break;
58     }
59 }
60
61 void RepoView::openWin()
62 {
63         if( !isVisible() ) {
64                 iModified = false;
65         }
66
67         ui->listWidget->clear();
68
69         for( int i=0; i<iAptInterface->repositories()->count(); i++ )
70         {
71                 QListWidgetItem* l = new QListWidgetItem( ui->listWidget );
72                 if( iAptInterface->repositories()->at(i)->enabled() )
73                         l->setIcon(QPixmap(":/icons/icons/pkg_install.png"));
74                 else
75                         l->setIcon(QPixmap(":/icons/icons/pkg_remove.png"));
76                 l->setText( iAptInterface->repositories()->at(i)->name() );
77                 l->setData(Qt::UserRole, i);
78                 ui->listWidget->addItem( l );
79         }
80
81         show();
82 }
83
84 void RepoView::closeEvent(QCloseEvent *event)
85 {
86         event->accept();
87
88         if( iModified )
89         {
90                 iAptInterface->writeRepositories();
91                 iMainWindow->on_btnUpdate_clicked();
92         }
93 }
94
95 void RepoView::on_btnNew_clicked()
96 {
97         Repository* n = new Repository();
98         iAptInterface->repositories()->append(n);
99
100         // add an option to set these directly
101         //"deb http://repository.maemo.org/extras-testing/ fremantle free non-free"
102         //"deb http://repository.maemo.org/extras-devel/ fremantle free non-free";
103
104         RepoEdit e(iAptInterface, n, iAptInterface->repositories()->count()-1, this);
105         if( !e.exec() ) {
106                 if( n ) {
107                         delete n;
108                         iAptInterface->repositories()->removeAt( iAptInterface->repositories()->count()-1 );
109                         n=0;
110                 }
111         } else {
112                 iModified = true;
113         }
114
115         openWin();
116 }
117
118 void RepoView::on_listWidget_itemClicked(QListWidgetItem* item)
119 {
120         Repository* r = iAptInterface->repositories()->at( item->data(Qt::UserRole).toInt() );
121         if( r!=0 ) {
122                 RepoEdit e(iAptInterface, r, item->data(Qt::UserRole).toInt(), this);
123                 if( e.exec() )
124                         iModified = true;
125                 openWin();
126         }
127 }
128
129 void RepoView::on_actionRe_import_HAM_repo_settings_triggered()
130 {
131         ConfirmDialog d(true, this);
132         d.setText("Confirm repository import","You're about to re-read the repository settings from Hildon Application Manager. This will import the "
133                           "repositories that are currently enabled in HAM and it will clear your current repository settings here. Continue?");
134         if( d.exec() )
135         {
136                 QFile r(KOwnRepoFile);
137                 QFile n(KOwnRepoNamesFile);
138                 r.remove();
139                 n.remove();
140                 iAptInterface->readRepositoryInfo();
141                 iModified = true;
142                 openWin();      // refresh view
143         }
144 }