Release 0.4.3-3maemo with patches to disable menus/actions, add ScrollArea and fix...
[keepassx] / src / lib / EntryView.h
1 /***************************************************************************
2  *   Copyright (C) 2005 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  *                                                                         *
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 #ifndef _ENTRY_VIEW_H_
22 #define _ENTRY_VIEW_H_
23
24 #include "Kdb3Database.h"
25
26 class GroupViewItem;
27 enum SelectionState{NONE,SINGLE,MULTIPLE,SEARCHGROUP};
28
29 class EntryViewItem:public QTreeWidgetItem{
30         public:
31                 EntryViewItem(QTreeWidget *parent);
32                 EntryViewItem(QTreeWidget *parent, QTreeWidgetItem * preceding);
33                 EntryViewItem(QTreeWidgetItem *parent);
34                 EntryViewItem(QTreeWidgetItem *parent, QTreeWidgetItem * preceding);
35                 IEntryHandle* EntryHandle;
36                 bool operator<(const QTreeWidgetItem& other) const;
37         private:
38                 int compare(const QTreeWidgetItem& other, int col, int index) const;
39 };
40
41 class KeepassEntryView:public QTreeWidget{
42         Q_OBJECT
43         public:
44                 KeepassEntryView(QWidget* parent=0);
45                 ~KeepassEntryView();
46                 void showSearchResults();
47                 void showGroup(IGroupHandle* group);
48                 void refreshItems();
49                 void retranslateColumns();
50                 IDatabase* db;
51                 QList<EntryViewItem*>Items;
52                 QList<IEntryHandle*> SearchResults;
53                 QMenu *ContextMenu;
54                 void setCurrentEntry(IEntryHandle* entry);
55                 inline IGroupHandle* getCurrentGroup() { return CurrentGroup; };
56                 bool columnVisible(int col);
57                 void setColumnVisible(int col, bool visible);
58                 
59         private:
60                 QClipboard* Clipboard;
61                 QTimer ClipboardTimer;
62                 QPoint DragStartPos;
63                 QList<QTreeWidgetItem*> DragItems;
64                 IGroupHandle* CurrentGroup;
65                 enum EntryViewMode {Normal, ShowSearchResults};
66                 EntryViewMode ViewMode;
67                 bool AutoResizeColumns;
68                 QList<int> columnSizes;
69                 
70                 QString columnString(IEntryHandle* entry, int col, bool forceClearText=false);
71                 inline QString columnStringView(EntryViewItem* item, int col, bool forceClearText=false) {
72                         return columnString(item->EntryHandle, col, forceClearText);
73                 };
74                 void updateEntry(EntryViewItem*);
75                 void editEntry(EntryViewItem*);
76                 void createItems(QList<IEntryHandle*>& entries);
77                 void saveHeaderView();
78                 void restoreHeaderView();
79                 
80                 void contextMenuEvent(QContextMenuEvent *event);
81                 void paintEvent(QPaintEvent* event);
82                 void resizeEvent(QResizeEvent* event);
83                 void mousePressEvent(QMouseEvent *event);
84                 void mouseMoveEvent(QMouseEvent *event);
85         
86         private slots:
87                 void OnGroupChanged(IGroupHandle* group);
88                 void OnShowSearchResults();
89                 void OnEntryActivated(QTreeWidgetItem*,int);
90                 void OnEntryDblClicked(QTreeWidgetItem*,int);
91                 void OnNewEntry();
92                 void OnItemsChanged();
93                 void updateIcons();
94                 void OnUsernameToClipboard();
95                 void OnPasswordToClipboard();
96                 void OnEditEntry();
97                 void OnClipboardTimeOut();
98                 void OnCloneEntry();
99                 void OnDeleteEntry();
100                 void OnSaveAttachment();
101 #ifdef AUTOTYPE
102                 void OnAutoType();
103 #endif
104                 void removeDragItems();
105                 void OnEditOpenUrl();
106                 void OnEditCopyUrl();
107                 void resizeColumns();
108         
109         signals:
110                 void fileModified();
111                 void selectionChanged(SelectionState);
112                 void requestCreateGroup(QString title, quint32 image, GroupViewItem* parent);
113                 void viewModeChanged(bool searchResultMode);
114 };
115
116 #endif