summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/pwmview.h
blob: e42b17a6206db09f49756a3cf9364f7bb5a78e14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/***************************************************************************
 *                                                                         *
 *   copyright (C) 2003, 2004 by Michael Buesch                            *
 *   email: mbuesch@freenet.de                                             *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License version 2        *
 *   as published by the Free Software Foundation.                         *
 *                                                                         *
 ***************************************************************************/

/***************************************************************************
 * copyright (C) 2004 by Ulf Schenk
 * This file is originaly based on version 1.0.1 of pwmanager
 * and was modified to run on embedded devices that run microkde
 *
 * $Id$
 **************************************************************************/  

#ifndef PWMVIEW_H
#define PWMVIEW_H

//US ENH: wouldn't it be a good idea if we could use this consts everywhere else.
//US ENH: for examle in listviewpwm.cpp
//US ENH: Because of that I transfer them into the headerfile.
#define COLUMN_DESC		0
#define COLUMN_NAME		1
#define COLUMN_PW		2
#define COLUMN_URL		3
#define COLUMN_LAUNCHER		4


#include "listviewpwm.h"
#include "pwmdoc.h"
#include "pwmviewstyle.h"

#include <kconfig.h>
#include <klocale.h>
#include <kdialogbase.h>

#include <qevent.h>
#include <qfont.h>
#include <qobject.h>
#include <qtextbrowser.h>

#include <vector>
#include <string>

using std::string;
using std::vector;

class PwM;
class ConfFile;
class PwMStatusBar;


/** View class for PwM */
class PwMView : public PwMViewStyle
{
	Q_OBJECT
	friend class PwMViewStyle;
public:
	/** construtor */
	PwMView(PwM *_mainClass, QWidget* parent, PwMDoc *_doc,
		const char *name = 0);
	/** destructor */
	~PwMView();

	/** returns pointer to the document */
	PwMDoc* document()
			{ return doc; }
	/** returns the index of the currently selected entry.
	  * (index as represented in PwMDoc !)
	  */
	bool getCurEntryIndex(unsigned int *index);
	/** returns the position of the given item in the document
	  * Note: This func only serches in the current category.
	  */
	bool getDocEntryIndex(unsigned int *index,
			      const QListViewItem *item);

public slots:
	/** update the view (call if dirty) */
	void updateView()
		{
			updateCategories();
			shiftToView();
		}
	/** (re)sort all items and (re)shift them to listView. */
	void shiftToView();
	/** handle clicking on an item */
	void handleToggle(QListViewItem *item);
	/** handle right-clicking on an item */
	void handleRightClick(QListViewItem *item, const QPoint &point, int);
	/** selects the item at "index" */
	void selAt(int index);
	/** rename category button pressed */
	void renCatButton_slot();
	/** delete category button pressed */
	void delCatButton_slot();

protected:
	/** right-click context-menu */
	QPopupMenu *ctxMenu;

protected:
	/** update the categories from document */
	void updateCategories();
	/** widget resize event */
	void resizeEvent(QResizeEvent *);
	/** initialize context-menu */
	void initCtxMenu();
	/** tempoarly disable auto-sorting and user-sorting */
	void tmpDisableSort()
			{ lv->setSorting(-1); }
	/** re-enable tempoarly disabled sorting */
	void tmpReEnableSort()
		{
			lv->setSorting(lv->columns() + 1,
				       true/*lv->sortOrder() == Qt::Ascending*/);
		}
	/** The user pressed and released a key. */
	void keyReleaseEvent(QKeyEvent *e);

protected slots:
	/** changes the comment text-edit, because a new item has been selected */
	void refreshCommentTextEdit(QListViewItem *curItem);
	/** copy pw to clipboard */
	void copyPwToClip();
	/** copy name to clipboard */
	void copyNameToClip();
	/** copy desc to clipboard */
	void copyDescToClip();
	/** copy url to clipboard */
	void copyUrlToClip();
	/** copy launcher to clipboard */
	void copyLauncherToClip();
	/** copy comment to clipboard */
	void copyCommentToClip();
	/** reorganize the "listViewPos" positions in the document
	  * (for the current category only!)
	  */
	void reorgLp();

private:
	/** document */
	PwMDoc *doc;
	/** pointer to the main class "PwM" */
	PwM *mainClass;
};


//US ENH basic widget to view an password entry. We need it for the sync stuff.
//But might be oif interest for other functionalities as well.
class PwMDataItemView : public QTextBrowser
{
  public:
    PwMDataItemView( QWidget *parent = 0, const char *name = 0 );

    /**
      Sets the PwMDataItem object. It is displayed immediately.

      @param a The PwMDataItem object.
     */
    void setPwMDataItem( const PwMDataItem& a );

    /**
      Returns the current PwMDataItem object.
     */
    PwMDataItem pwmdataitem() const;

  private:
    PwMDataItem mItem;
};


//US ENH we need this chooser when syncing results in a conflict
class PwMDataItemChooser : public KDialogBase
{
    Q_OBJECT

  public:
    PwMDataItemChooser( PwMDataItem loc, PwMDataItem rem, bool takeloc, QWidget *parent = 0, const char *name = 0 );

    int executeD( bool local );

  private:
    int mSyncResult;

  private slots:
    void slot_remote();
    void slot_local();

};


#endif