Import 0.4.3 version in mainstream branch
[keepassx] / src / dialogs / EditGroupDlg.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005 by Tarek Saidi                                     *
3  *   tarek@linux                                                           *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; version 2 of the License.               *
8
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21
22 #include "EditGroupDlg.h"
23 #include "SelectIconDlg.h"
24
25 CEditGroupDialog::CEditGroupDialog(IDatabase* database,IGroupHandle* Handle,QWidget* parent, Qt::WFlags fl)
26 : QDialog(parent,fl)
27 {
28         db = database;
29         handle = Handle;
30         group = new CGroup();
31         group->Title = handle->title();
32         group->Image = handle->image();
33         
34         init();
35 }
36
37
38 CEditGroupDialog::CEditGroupDialog(IDatabase* database,CGroup* Group,QWidget* parent, Qt::WFlags fl)
39         : QDialog(parent,fl)
40 {
41         db = database;
42         handle = NULL;
43         group = Group;
44         
45         init();
46 }
47
48 CEditGroupDialog::~CEditGroupDialog(){
49 }
50
51 void CEditGroupDialog::init() {
52         setupUi(this);
53         
54         connect( ButtonBox, SIGNAL( accepted() ), this, SLOT( OnOK() ) );
55         connect( ButtonBox, SIGNAL( rejected() ), this, SLOT( OnCancel() ) );
56         connect( Button_Icon, SIGNAL( clicked() ), this, SLOT( OnIconDlg() ));
57         
58         EditTitle->setText(group->Title);
59         
60         for(int i=0;i<db->numIcons();i++){
61                 ComboIconPicker->insertItem(i,db->icon(i),"");
62         }
63         ComboIconPicker->setCurrentIndex(group->Image);
64         
65         adjustSize();
66         setMaximumSize(size());
67         setMinimumSize(size());
68 }
69
70
71 void CEditGroupDialog::OnOK()
72 {
73         int r=1;
74         if(EditTitle->text()!=group->Title){
75                 group->Title=EditTitle->text();
76                 r=2;
77         }
78         if(ComboIconPicker->currentIndex()!=group->Image){
79                 group->Image=ComboIconPicker->currentIndex();
80                 r=2;
81         }
82         if(handle){
83                 handle->setTitle(group->Title);
84                 handle->setImage(group->Image);
85         }
86         done(r);
87 }
88
89 void CEditGroupDialog::OnCancel()
90 {
91         done(0);
92 }
93
94
95 void CEditGroupDialog::OnIconDlg(){
96         CSelectIconDlg dlg(db,group->Image,this);
97         int r=dlg.exec();
98         if(r!=-1){
99                 ComboIconPicker->clear();
100                 for(int i=0;i<db->numIcons();i++)
101                         ComboIconPicker->insertItem(i,db->icon(i),"");
102                 group->Image=r;
103                 ComboIconPicker->setCurrentIndex(r);
104         }
105 }