summaryrefslogtreecommitdiff
path: root/noncore/apps/zsafe/zsafe.h
blob: 0be579ca218327a0af7a4d07cc9eae8f26754dad (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
/****************************************************************************
** Form interface generated from reading ui file 'zsafe.ui'
**
** Created: Sat Apr 6 17:57:42 2002
**
** Author: Carsten Schneider <CarstenSchneider@t-online.de>
**
** $Id$
**
** Homepage: http://home.t-online.de/home/CarstenSchneider/zsafe/index.html
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/
#ifndef ZSAFE_H
#define ZSAFE_H

#include <stdio.h>

#include "infoform.h"
#include "categorylist.h"
#include "shadedlistitem.h"

#include <qmainwindow.h>

#include <qvariant.h>
#include <qdialog.h>
#include <qwidgetstack.h>
#include <qtimer.h>

class QVBoxLayout; 
class QHBoxLayout; 
class QGridLayout; 
class ZListView;
class QListViewItem;
class QToolButton;
class QTextBrowser;
class QPopupMenu;
#ifdef DESKTOP
// #ifndef WIN32
class QSettings;
// #endif
#else
class Config;
#endif
class CategoryDialog;
class QPixmap;

// number of fields for one entry
#define FIELD_SIZE 7

class ZSafe : public QMainWindow
{ 
    Q_OBJECT

protected:
    void paintEvent( QPaintEvent * e );

    bool raiseFlag;
    QTimer raiseTimer;

public:
    ZSafe( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
    ~ZSafe();
    static QString appName() { return QString::fromLatin1( QUICKAPP_NAME ); }

     static const QColor *evenRowColor; 
     static const QColor *oddRowColor;  

    ZListView* ListView;

    QString cfgFile;
    QString iconPath;

    InfoForm *infoForm;
    CategoryDialog *categoryDialog;

    QListViewItem *selectedItem; // current selected item
    QListViewItem *copiedItem; // copied item
    bool IsCopy;
    bool IsCut;
    bool modified; // true if database is modified
    bool showpwd;  // show PWD Dialog

    QListViewItem *lastSearchedCategory; 
    QListViewItem *lastSearchedItem; 
    QString        lastSearchedName;
    QString        lastSearchedUsername;
    QString        lastSearchedComment;
   

    CategoryList categories; // list of categories

    bool isCategory(QListViewItem *_item);
    void getDocPassword(QString title);
    QString filename;
   
    enum {
                PWERR_GOOD,     // success
                PWERR_OPEN,     // can't open filedescriptor / can't create file
                PWERR_PERM,     // permissions are bad
                PWERR_SYML,     // is a symlink
                PWERR_STAT,     // can't get file status
                PWERR_DATA      // can't read correct data
    };

    long load_buffer_length;
    long save_buffer_length;

    /** password for the file */
    QString m_password;
    /** globals needed for file loading */
    int lastcount, size;
    /** these three are needed in all save functions and initialized in save _init() */
    FILE *fd;
    unsigned short iv[4];
    char *buffer;
    /** these two are global because save_entry() and save_finalize() both n eed them */
    int bufferIndex;
    unsigned short plaintext[4];

#ifdef DESKTOP
// #ifndef WIN32
    QSettings *conf;
// #endif
#else
    Config *conf;
#endif
    bool expandTree;
    QPopupMenu *file;

    QTimer docuTimer;


    bool openDocument(const char* filename, const char* format=0);
    int loadInit(const char* filename, const char *password);
    int loadEntry(char *entry[4]);
    int loadFinalize(void);
    bool saveDocument(const char* filename, bool withPwd, const char* format=0);
    int saveInit(const char *filename, const char *password);
    int saveEntry(char *entry[4]);
    int saveFinalize(void);
    void saveConf();
    QPixmap * getPredefinedIcon(QString category);
    QString getFieldLabel (QListViewItem *_item, QString field, QString def);
    QString getFieldLabel (QString category, QString field, QString def);
    void setCategoryDialogFields(CategoryDialog *dialog);
    void setCategoryDialogFields(CategoryDialog *dialog, QString category);
    void saveCategoryDialogFields(CategoryDialog *dialog);


    void resume(int signum);
    void exitZs (int ec);

		QString zsaveDialog();

public slots:
    virtual void deletePwd();
    virtual void editPwd();
    virtual void newPwd();
    virtual void findPwd();
    virtual void quitMe();
    virtual void listViewSelected( QListViewItem *_item);
    virtual void showInfo( QListViewItem *_item);
    virtual void writeAllEntries();
    virtual void readAllEntries();
    virtual void removeAsciiFile();
    virtual void setPasswordDialogDone();

    virtual void addCategory();
    virtual void delCategory();
    virtual void editCategory();
    virtual void cutItem();
    virtual void copyItem();
    virtual void pasteItem();

    virtual void newDocument();
    virtual void loadDocument();
    virtual void saveDocumentAs();
    virtual void saveDocumentWithoutPwd();
    virtual void saveDocumentWithPwd();
    virtual void setExpandFlag();

    virtual void categoryFieldActivated( const QString& str);

		virtual void ListPressed(int, QListViewItem *, const QPoint&, int);
	  virtual void copyClip( const QString &text);

private slots:
    void setDocument(const QString& fileref);
    void slotLoadDocu();
    void slotRaiseTimer();

};

#endif // ZSAFE_H