Initial commit
[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         setupUi(this);
29         db=database;
30         handle=Handle;
31         group=new CGroup();
32         group->Title=handle->title();
33         group->Image=handle->image();
34         connect( ButtonBox, SIGNAL( accepted() ), this, SLOT( OnOK() ) );
35         connect( ButtonBox, SIGNAL( rejected() ), this, SLOT( OnCancel() ) );
36         connect( Button_Icon, SIGNAL( clicked() ), this, SLOT( OnIconDlg() ));
37         adjustSize();
38         setMaximumSize(size());
39         setMinimumSize(size());
40 }
41
42
43 CEditGroupDialog::CEditGroupDialog(IDatabase* database,CGroup* Group,QWidget* parent, Qt::WFlags fl)
44         : QDialog(parent,fl)
45 {
46         setupUi(this);
47         db=database;
48         group=Group;
49         handle=NULL;
50         connect( ButtonBox, SIGNAL( accepted() ), this, SLOT( OnOK() ) );
51         connect( ButtonBox, SIGNAL( rejected() ), this, SLOT( OnCancel() ) );
52         connect( Button_Icon, SIGNAL( clicked() ), this, SLOT( OnIconDlg() ));
53 }
54
55 CEditGroupDialog::~CEditGroupDialog(){
56 }
57
58 void CEditGroupDialog::showEvent(QShowEvent *event){
59         if(event->spontaneous()==false){
60                 EditTitle->setText(group->Title);
61                 for(int i=0;i<db->numIcons();i++){
62                         ComboIconPicker->insertItem(i,db->icon(i),"");
63                 }
64                 ComboIconPicker->setCurrentIndex(group->Image);
65         }
66 }
67
68 void CEditGroupDialog::OnOK()
69 {
70         int r=1;
71         if(EditTitle->text()!=group->Title){
72                 group->Title=EditTitle->text();
73                 r=2;
74         }
75         if(ComboIconPicker->currentIndex()!=group->Image){
76                 group->Image=ComboIconPicker->currentIndex();
77                 r=2;
78         }
79         if(handle){
80                 handle->setTitle(group->Title);
81                 handle->setImage(group->Image);
82         }
83         done(r);
84 }
85
86 void CEditGroupDialog::OnCancel()
87 {
88         done(0);
89 }
90
91
92 void CEditGroupDialog::OnIconDlg(){
93         CSelectIconDlg dlg(db,group->Image,this);
94         int r=dlg.exec();
95         if(r!=-1){
96                 ComboIconPicker->clear();
97                 for(int i=0;i<db->numIcons();i++)
98                         ComboIconPicker->insertItem(i,db->icon(i),"");
99                 group->Image=r;
100                 ComboIconPicker->setCurrentIndex(r);
101         }
102 }