0.7.1
[fapman] / repoedit.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 "repoedit.h"
21 #include "ui_repoedit.h"
22 #include "repository.h"
23 #include "confirmdialog.h"
24 #include "aaptinterface.h"
25
26 RepoEdit::RepoEdit(AAptInterface* apt, Repository* repo, int pos, QWidget *parent) :
27     QDialog(parent),
28     ui(new Ui::RepoEdit)
29 {
30     ui->setupUi(this);
31         iRepo = repo;
32         iPos = pos;
33         iAptInterface = apt;
34
35         ui->lineEdit_name->setText( iRepo->name() );
36         ui->lineEdit_url->setText( iRepo->url()+iRepo->dir() );
37         ui->lineEdit_components->setText( iRepo->components() );
38         ui->lineEdit_dist->setText( iRepo->dist() );
39         ui->checkBox_Enabled->setChecked( iRepo->enabled() );
40         iRevertEnabledTo = iRepo->enabled();
41
42         on_lineEdit_name_textEdited("");
43 }
44
45 RepoEdit::~RepoEdit()
46 {
47     delete ui;
48 }
49
50 void RepoEdit::changeEvent(QEvent *e)
51 {
52     QDialog::changeEvent(e);
53     switch (e->type()) {
54     case QEvent::LanguageChange:
55         ui->retranslateUi(this);
56         break;
57     default:
58         break;
59     }
60 }
61
62 void RepoEdit::on_btn_OK_clicked()
63 {
64                 iRepo->set( ui->lineEdit_name->text().trimmed(), ui->lineEdit_url->text().trimmed(),
65                                         ui->lineEdit_dist->text().trimmed(), ui->lineEdit_components->text().trimmed(),
66                                         ui->checkBox_Enabled->isChecked() );
67
68                 accept();
69 }
70
71 void RepoEdit::on_btn_Delete_clicked()
72 {
73         ConfirmDialog d(true, this);
74         d.setText("Confirmation","Really delete this repository?");
75         if( d.exec() ) {
76
77                 if( iRepo ) {
78                         delete iRepo;
79                         iAptInterface->repositories()->removeAt(iPos);
80                         iRepo = 0;
81                 }
82
83                 accept();
84         }
85 }
86
87 void RepoEdit::on_lineEdit_name_textEdited(QString )
88 {
89         QString n = ui->lineEdit_name->text();
90         QString u = ui->lineEdit_url->text();
91
92         if( n == "" || u == "" ) {
93                 ui->btn_OK->setEnabled(false);
94                 ui->checkBox_Enabled->setEnabled(false);
95                 ui->checkBox_Enabled->setChecked(false);
96                 return;
97         }
98
99         if( !u.contains("://") ) {
100                 ui->btn_OK->setEnabled(false);
101                 ui->checkBox_Enabled->setEnabled(false);
102                 ui->checkBox_Enabled->setChecked(false);
103                 return;
104         }
105
106         ui->btn_OK->setEnabled(true);
107         ui->checkBox_Enabled->setEnabled(true);
108         ui->checkBox_Enabled->setChecked(iRevertEnabledTo);
109 }
110
111 void RepoEdit::on_lineEdit_url_textEdited(QString )
112 {
113         on_lineEdit_name_textEdited("");
114 }
115
116 void RepoEdit::on_checkBox_Enabled_clicked()
117 {
118         iRevertEnabledTo = ui->checkBox_Enabled->isChecked();
119 }