Initial commit
[keepassx] / src / dialogs / AddBookmarkDlg.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Tarek Saidi                                     *
3  *   tarek.saidi@arcor.de                                                  *
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  *   This program 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 this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18  ***************************************************************************/
19
20
21 #include "AddBookmarkDlg.h"
22
23
24 AddBookmarkDlg::AddBookmarkDlg(QWidget* parent, QString DefaultFilename, int _ItemID):QDialog(parent)
25 {
26         setupUi(this);
27         ItemID=_ItemID;
28         connect(Button_Browse,SIGNAL(clicked()),this,SLOT(OnButtonBrowse()));
29         connect(buttonBox->button(QDialogButtonBox::Ok),SIGNAL(clicked()),this,SLOT(OnButtonOk()));
30         connect(buttonBox->button(QDialogButtonBox::Cancel),SIGNAL(clicked()),this,SLOT(reject()));
31         if(ItemID==-1){
32                 createBanner(&BannerPixmap,getPixmap("bookmark_add"),tr("Add Bookmark"),width());
33
34                 if(DefaultFilename.isEmpty())
35                         QMetaObject::invokeMethod(this, "OnButtonBrowse", Qt::QueuedConnection);
36                 else
37                         Edit_Filename->setText(DefaultFilename);
38         }
39         else {
40                 createBanner(&BannerPixmap,getPixmap("bookmark_edit"),tr("Edit Bookmark"),width());
41
42                 Edit_Title->setText(KpxBookmarks::title(ItemID));
43                 Edit_Filename->setText(KpxBookmarks::path(ItemID));
44                 setWindowTitle(tr("Edit Bookmark"));
45         }
46 }
47
48 void AddBookmarkDlg::paintEvent(QPaintEvent *event){
49         QDialog::paintEvent(event);
50         QPainter painter(this);
51         painter.setClipRegion(event->region());
52         painter.drawPixmap(QPoint(0,0),BannerPixmap);
53 }
54
55 void AddBookmarkDlg::OnButtonBrowse(){
56         QString path=KpxFileDialogs::openExistingFile(this,"AddBookmarkDlg", tr("Add Bookmark"),
57                                                                                       QStringList() << tr("KeePass Databases (*.kdb)") << tr("All Files (*)"));
58         if(path!=QString())
59                 Edit_Filename->setText(path);
60 }
61
62 void AddBookmarkDlg::OnButtonOk(){
63         if(ItemID==-1)
64                 ItemID=KpxBookmarks::add(Edit_Title->text(),Edit_Filename->text());
65         else
66                 KpxBookmarks::edit(Edit_Title->text(),Edit_Filename->text(),ItemID);
67         accept();
68 }