summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-09-15 17:53:22 (UTC)
committer ulf69 <ulf69>2004-09-15 17:53:22 (UTC)
commitd3925ba5bd25224bc4a60d3d6a107c464994a1ea (patch) (unidiff)
tree60f69da1d2b79ee3081e7ef5c09a46470ca6eda0
parentce83a3479d23b9e8a59c745ccd0a0b14f64ef4e8 (diff)
downloadkdepimpi-d3925ba5bd25224bc4a60d3d6a107c464994a1ea.zip
kdepimpi-d3925ba5bd25224bc4a60d3d6a107c464994a1ea.tar.gz
kdepimpi-d3925ba5bd25224bc4a60d3d6a107c464994a1ea.tar.bz2
initial revision
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--pwmanager/BUGS3
-rw-r--r--pwmanager/COPYING.LGPL517
-rw-r--r--pwmanager/CodingStyle36
-rw-r--r--pwmanager/Makefile.am26
-rw-r--r--pwmanager/NEWS1
-rw-r--r--pwmanager/VERSION1
-rw-r--r--pwmanager/configure.in.bot34
-rw-r--r--pwmanager/file-format137
-rw-r--r--pwmanager/keycard-format55
-rw-r--r--pwmanager/pwmanager/addentrywnd.cpp203
-rw-r--r--pwmanager/pwmanager/addentrywnd.h74
-rw-r--r--pwmanager/pwmanager/addentrywnd.ui483
-rw-r--r--pwmanager/pwmanager/addentrywndimpl.cpp174
-rw-r--r--pwmanager/pwmanager/addentrywndimpl.h114
-rw-r--r--pwmanager/pwmanager/advcommedit.cpp10
-rw-r--r--pwmanager/pwmanager/advcommedit.h63
-rw-r--r--pwmanager/pwmanager/advcommedit.ui274
-rw-r--r--pwmanager/pwmanager/advcommeditimpl.cpp149
-rw-r--r--pwmanager/pwmanager/advcommeditimpl.h79
-rw-r--r--pwmanager/pwmanager/base64.cpp207
-rw-r--r--pwmanager/pwmanager/base64.h97
-rw-r--r--pwmanager/pwmanager/binentrygen.cpp71
-rw-r--r--pwmanager/pwmanager/binentrygen.h65
-rw-r--r--pwmanager/pwmanager/blowfish.cpp579
-rw-r--r--pwmanager/pwmanager/blowfish.h120
-rw-r--r--pwmanager/pwmanager/commentbox.cpp238
-rw-r--r--pwmanager/pwmanager/commentbox.h100
-rw-r--r--pwmanager/pwmanager/compiler.h61
-rw-r--r--pwmanager/pwmanager/compressbzip2.cpp138
-rw-r--r--pwmanager/pwmanager/compressbzip2.h50
-rw-r--r--pwmanager/pwmanager/compressgzip.cpp115
-rw-r--r--pwmanager/pwmanager/compressgzip.h50
-rw-r--r--pwmanager/pwmanager/configuration.cpp459
-rw-r--r--pwmanager/pwmanager/configuration.h336
-rw-r--r--pwmanager/pwmanager/configuration_31compat.cpp365
-rw-r--r--pwmanager/pwmanager/configuration_31compat.h146
-rw-r--r--pwmanager/pwmanager/configwnd.cpp264
-rw-r--r--pwmanager/pwmanager/configwnd.h91
-rw-r--r--pwmanager/pwmanager/configwnd.ui687
-rw-r--r--pwmanager/pwmanager/configwndimpl.cpp126
-rw-r--r--pwmanager/pwmanager/configwndimpl.h55
-rw-r--r--pwmanager/pwmanager/findwnd.cpp153
-rw-r--r--pwmanager/pwmanager/findwnd.h61
-rw-r--r--pwmanager/pwmanager/findwnd.ui327
-rw-r--r--pwmanager/pwmanager/findwndimpl.cpp125
-rw-r--r--pwmanager/pwmanager/findwndimpl.h61
-rw-r--r--pwmanager/pwmanager/genpasswd.cpp192
-rw-r--r--pwmanager/pwmanager/genpasswd.h76
-rw-r--r--pwmanager/pwmanager/getkeycardwnd.cpp67
-rw-r--r--pwmanager/pwmanager/getkeycardwnd.h53
-rw-r--r--pwmanager/pwmanager/getmasterpwwnd.cpp88
-rw-r--r--pwmanager/pwmanager/getmasterpwwnd.h48
-rw-r--r--pwmanager/pwmanager/getmasterpwwnd.ui110
-rw-r--r--pwmanager/pwmanager/getmasterpwwndimpl.cpp46
-rw-r--r--pwmanager/pwmanager/getmasterpwwndimpl.h40
-rw-r--r--pwmanager/pwmanager/globalstuff.cpp35
-rw-r--r--pwmanager/pwmanager/globalstuff.h113
-rw-r--r--pwmanager/pwmanager/gpasmanfile.cpp437
-rw-r--r--pwmanager/pwmanager/gpasmanfile.h67
-rw-r--r--pwmanager/pwmanager/htmlgen.cpp248
-rw-r--r--pwmanager/pwmanager/htmlgen.h136
-rw-r--r--pwmanager/pwmanager/htmlparse.cpp184
-rw-r--r--pwmanager/pwmanager/htmlparse.h45
-rw-r--r--pwmanager/pwmanager/ipc.cpp152
-rw-r--r--pwmanager/pwmanager/ipc.h73
-rw-r--r--pwmanager/pwmanager/listobjselectwnd.cpp131
-rw-r--r--pwmanager/pwmanager/listobjselectwnd.h85
-rw-r--r--pwmanager/pwmanager/listviewpwm.cpp86
-rw-r--r--pwmanager/pwmanager/listviewpwm.h57
-rw-r--r--pwmanager/pwmanager/main.cpp210
-rw-r--r--pwmanager/pwmanager/printtext.cpp107
-rw-r--r--pwmanager/pwmanager/printtext.h68
-rw-r--r--pwmanager/pwmanager/pwgenwnd.cpp187
-rw-r--r--pwmanager/pwmanager/pwgenwnd.h78
-rw-r--r--pwmanager/pwmanager/pwgenwnd.ui363
-rw-r--r--pwmanager/pwmanager/pwgenwndimpl.cpp112
-rw-r--r--pwmanager/pwmanager/pwgenwndimpl.h54
-rw-r--r--pwmanager/pwmanager/pwm.cpp1192
-rw-r--r--pwmanager/pwmanager/pwm.h255
-rw-r--r--pwmanager/pwmanager/pwmanagerE.pro143
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp2775
-rw-r--r--pwmanager/pwmanager/pwmdoc.h701
-rw-r--r--pwmanager/pwmanager/pwmdocui.cpp436
-rw-r--r--pwmanager/pwmanager/pwmdocui.h129
-rw-r--r--pwmanager/pwmanager/pwmexception.cpp58
-rw-r--r--pwmanager/pwmanager/pwmexception.h216
-rw-r--r--pwmanager/pwmanager/pwminit.cpp617
-rw-r--r--pwmanager/pwmanager/pwminit.h222
-rw-r--r--pwmanager/pwmanager/pwmprint.cpp188
-rw-r--r--pwmanager/pwmanager/pwmprint.h55
-rw-r--r--pwmanager/pwmanager/pwmtray.cpp482
-rw-r--r--pwmanager/pwmanager/pwmtray.h292
-rw-r--r--pwmanager/pwmanager/pwmview.cpp452
-rw-r--r--pwmanager/pwmanager/pwmview.h140
-rw-r--r--pwmanager/pwmanager/pwmviewstyle.cpp205
-rw-r--r--pwmanager/pwmanager/pwmviewstyle.h108
-rw-r--r--pwmanager/pwmanager/pwmviewstyle_0.cpp93
-rw-r--r--pwmanager/pwmanager/pwmviewstyle_0.h99
-rw-r--r--pwmanager/pwmanager/pwmviewstyle_1.cpp130
-rw-r--r--pwmanager/pwmanager/pwmviewstyle_1.h107
-rw-r--r--pwmanager/pwmanager/randomizer.cpp124
-rw-r--r--pwmanager/pwmanager/randomizer.h67
-rw-r--r--pwmanager/pwmanager/rc2.cpp222
-rw-r--r--pwmanager/pwmanager/rc2.h50
-rw-r--r--pwmanager/pwmanager/rencatwnd.cpp70
-rw-r--r--pwmanager/pwmanager/rencatwnd.h60
-rw-r--r--pwmanager/pwmanager/selftest.cpp105
-rw-r--r--pwmanager/pwmanager/selftest.h67
-rw-r--r--pwmanager/pwmanager/serializer.cpp664
-rw-r--r--pwmanager/pwmanager/serializer.h102
-rw-r--r--pwmanager/pwmanager/setmasterpwwnd.cpp150
-rw-r--r--pwmanager/pwmanager/setmasterpwwnd.h63
-rw-r--r--pwmanager/pwmanager/setmasterpwwnd.ui294
-rw-r--r--pwmanager/pwmanager/setmasterpwwndimpl.cpp152
-rw-r--r--pwmanager/pwmanager/setmasterpwwndimpl.h72
-rw-r--r--pwmanager/pwmanager/sha1.cpp355
-rw-r--r--pwmanager/pwmanager/sha1.h75
-rw-r--r--pwmanager/pwmanager/spinforsignal.cpp91
-rw-r--r--pwmanager/pwmanager/spinforsignal.h55
-rw-r--r--pwmanager/pwmanager/subtbledit.cpp140
-rw-r--r--pwmanager/pwmanager/subtbledit.h62
-rw-r--r--pwmanager/pwmanager/subtbledit.ui264
-rw-r--r--pwmanager/pwmanager/subtbleditimpl.cpp138
-rw-r--r--pwmanager/pwmanager/subtbleditimpl.h84
-rw-r--r--pwmanager/pwmanager/waitwnd.cpp94
-rw-r--r--pwmanager/pwmanager/waitwnd.h61
126 files changed, 24104 insertions, 0 deletions
diff --git a/pwmanager/BUGS b/pwmanager/BUGS
new file mode 100644
index 0000000..2856a41
--- a/dev/null
+++ b/pwmanager/BUGS
@@ -0,0 +1,3 @@
1PwManager BUGS
2==============
3
diff --git a/pwmanager/COPYING.LGPL b/pwmanager/COPYING.LGPL
new file mode 100644
index 0000000..cd46641
--- a/dev/null
+++ b/pwmanager/COPYING.LGPL
@@ -0,0 +1,517 @@
1All source-files explicitly marked as LGPL licensed in their header,
2are distributed under the conditions of the following license:
3
4
5
6
7
8
9 GNU LESSER GENERAL PUBLIC LICENSE
10 Version 2.1, February 1999
11
12 Copyright (C) 1991, 1999 Free Software Foundation, Inc.
13 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 Everyone is permitted to copy and distribute verbatim copies
15 of this license document, but changing it is not allowed.
16
17[This is the first released version of the Lesser GPL. It also counts
18 as the successor of the GNU Library Public License, version 2, hence
19 the version number 2.1.]
20
21 Preamble
22
23 The licenses for most software are designed to take away your
24freedom to share and change it. By contrast, the GNU General Public
25Licenses are intended to guarantee your freedom to share and change
26free software--to make sure the software is free for all its users.
27
28 This license, the Lesser General Public License, applies to some
29specially designated software packages--typically libraries--of the
30Free Software Foundation and other authors who decide to use it. You
31can use it too, but we suggest you first think carefully about whether
32this license or the ordinary General Public License is the better
33strategy to use in any particular case, based on the explanations
34below.
35
36 When we speak of free software, we are referring to freedom of use,
37not price. Our General Public Licenses are designed to make sure that
38you have the freedom to distribute copies of free software (and charge
39for this service if you wish); that you receive source code or can get
40it if you want it; that you can change the software and use pieces of
41it in new free programs; and that you are informed that you can do
42these things.
43
44 To protect your rights, we need to make restrictions that forbid
45distributors to deny you these rights or to ask you to surrender these
46rights. These restrictions translate to certain responsibilities for
47you if you distribute copies of the library or if you modify it.
48
49 For example, if you distribute copies of the library, whether gratis
50or for a fee, you must give the recipients all the rights that we gave
51you. You must make sure that they, too, receive or can get the source
52code. If you link other code with the library, you must provide
53complete object files to the recipients, so that they can relink them
54with the library after making changes to the library and recompiling
55it. And you must show them these terms so they know their rights.
56
57 We protect your rights with a two-step method: (1) we copyright the
58library, and (2) we offer you this license, which gives you legal
59permission to copy, distribute and/or modify the library.
60
61 To protect each distributor, we want to make it very clear that
62there is no warranty for the free library. Also, if the library is
63modified by someone else and passed on, the recipients should know
64that what they have is not the original version, so that the original
65author's reputation will not be affected by problems that might be
66introduced by others.
67^L
68 Finally, software patents pose a constant threat to the existence of
69any free program. We wish to make sure that a company cannot
70effectively restrict the users of a free program by obtaining a
71restrictive license from a patent holder. Therefore, we insist that
72any patent license obtained for a version of the library must be
73consistent with the full freedom of use specified in this license.
74
75 Most GNU software, including some libraries, is covered by the
76ordinary GNU General Public License. This license, the GNU Lesser
77General Public License, applies to certain designated libraries, and
78is quite different from the ordinary General Public License. We use
79this license for certain libraries in order to permit linking those
80libraries into non-free programs.
81
82 When a program is linked with a library, whether statically or using
83a shared library, the combination of the two is legally speaking a
84combined work, a derivative of the original library. The ordinary
85General Public License therefore permits such linking only if the
86entire combination fits its criteria of freedom. The Lesser General
87Public License permits more lax criteria for linking other code with
88the library.
89
90 We call this license the "Lesser" General Public License because it
91does Less to protect the user's freedom than the ordinary General
92Public License. It also provides other free software developers Less
93of an advantage over competing non-free programs. These disadvantages
94are the reason we use the ordinary General Public License for many
95libraries. However, the Lesser license provides advantages in certain
96special circumstances.
97
98 For example, on rare occasions, there may be a special need to
99encourage the widest possible use of a certain library, so that it
100becomes a de-facto standard. To achieve this, non-free programs must
101be allowed to use the library. A more frequent case is that a free
102library does the same job as widely used non-free libraries. In this
103case, there is little to gain by limiting the free library to free
104software only, so we use the Lesser General Public License.
105
106 In other cases, permission to use a particular library in non-free
107programs enables a greater number of people to use a large body of
108free software. For example, permission to use the GNU C Library in
109non-free programs enables many more people to use the whole GNU
110operating system, as well as its variant, the GNU/Linux operating
111system.
112
113 Although the Lesser General Public License is Less protective of the
114users' freedom, it does ensure that the user of a program that is
115linked with the Library has the freedom and the wherewithal to run
116that program using a modified version of the Library.
117
118 The precise terms and conditions for copying, distribution and
119modification follow. Pay close attention to the difference between a
120"work based on the library" and a "work that uses the library". The
121former contains code derived from the library, whereas the latter must
122be combined with the library in order to run.
123^L
124 GNU LESSER GENERAL PUBLIC LICENSE
125 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
126
127 0. This License Agreement applies to any software library or other
128program which contains a notice placed by the copyright holder or
129other authorized party saying it may be distributed under the terms of
130this Lesser General Public License (also called "this License").
131Each licensee is addressed as "you".
132
133 A "library" means a collection of software functions and/or data
134prepared so as to be conveniently linked with application programs
135(which use some of those functions and data) to form executables.
136
137 The "Library", below, refers to any such software library or work
138which has been distributed under these terms. A "work based on the
139Library" means either the Library or any derivative work under
140copyright law: that is to say, a work containing the Library or a
141portion of it, either verbatim or with modifications and/or translated
142straightforwardly into another language. (Hereinafter, translation is
143included without limitation in the term "modification".)
144
145 "Source code" for a work means the preferred form of the work for
146making modifications to it. For a library, complete source code means
147all the source code for all modules it contains, plus any associated
148interface definition files, plus the scripts used to control
149compilation and installation of the library.
150
151 Activities other than copying, distribution and modification are not
152covered by this License; they are outside its scope. The act of
153running a program using the Library is not restricted, and output from
154such a program is covered only if its contents constitute a work based
155on the Library (independent of the use of the Library in a tool for
156writing it). Whether that is true depends on what the Library does
157and what the program that uses the Library does.
158
159 1. You may copy and distribute verbatim copies of the Library's
160complete source code as you receive it, in any medium, provided that
161you conspicuously and appropriately publish on each copy an
162appropriate copyright notice and disclaimer of warranty; keep intact
163all the notices that refer to this License and to the absence of any
164warranty; and distribute a copy of this License along with the
165Library.
166
167 You may charge a fee for the physical act of transferring a copy,
168and you may at your option offer warranty protection in exchange for a
169fee.
170
171 2. You may modify your copy or copies of the Library or any portion
172of it, thus forming a work based on the Library, and copy and
173distribute such modifications or work under the terms of Section 1
174above, provided that you also meet all of these conditions:
175
176 a) The modified work must itself be a software library.
177
178 b) You must cause the files modified to carry prominent notices
179 stating that you changed the files and the date of any change.
180
181 c) You must cause the whole of the work to be licensed at no
182 charge to all third parties under the terms of this License.
183
184 d) If a facility in the modified Library refers to a function or a
185 table of data to be supplied by an application program that uses
186 the facility, other than as an argument passed when the facility
187 is invoked, then you must make a good faith effort to ensure that,
188 in the event an application does not supply such function or
189 table, the facility still operates, and performs whatever part of
190 its purpose remains meaningful.
191
192 (For example, a function in a library to compute square roots has
193 a purpose that is entirely well-defined independent of the
194 application. Therefore, Subsection 2d requires that any
195 application-supplied function or table used by this function must
196 be optional: if the application does not supply it, the square
197 root function must still compute square roots.)
198
199These requirements apply to the modified work as a whole. If
200identifiable sections of that work are not derived from the Library,
201and can be reasonably considered independent and separate works in
202themselves, then this License, and its terms, do not apply to those
203sections when you distribute them as separate works. But when you
204distribute the same sections as part of a whole which is a work based
205on the Library, the distribution of the whole must be on the terms of
206this License, whose permissions for other licensees extend to the
207entire whole, and thus to each and every part regardless of who wrote
208it.
209
210Thus, it is not the intent of this section to claim rights or contest
211your rights to work written entirely by you; rather, the intent is to
212exercise the right to control the distribution of derivative or
213collective works based on the Library.
214
215In addition, mere aggregation of another work not based on the Library
216with the Library (or with a work based on the Library) on a volume of
217a storage or distribution medium does not bring the other work under
218the scope of this License.
219
220 3. You may opt to apply the terms of the ordinary GNU General Public
221License instead of this License to a given copy of the Library. To do
222this, you must alter all the notices that refer to this License, so
223that they refer to the ordinary GNU General Public License, version 2,
224instead of to this License. (If a newer version than version 2 of the
225ordinary GNU General Public License has appeared, then you can specify
226that version instead if you wish.) Do not make any other change in
227these notices.
228^L
229 Once this change is made in a given copy, it is irreversible for
230that copy, so the ordinary GNU General Public License applies to all
231subsequent copies and derivative works made from that copy.
232
233 This option is useful when you wish to copy part of the code of
234the Library into a program that is not a library.
235
236 4. You may copy and distribute the Library (or a portion or
237derivative of it, under Section 2) in object code or executable form
238under the terms of Sections 1 and 2 above provided that you accompany
239it with the complete corresponding machine-readable source code, which
240must be distributed under the terms of Sections 1 and 2 above on a
241medium customarily used for software interchange.
242
243 If distribution of object code is made by offering access to copy
244from a designated place, then offering equivalent access to copy the
245source code from the same place satisfies the requirement to
246distribute the source code, even though third parties are not
247compelled to copy the source along with the object code.
248
249 5. A program that contains no derivative of any portion of the
250Library, but is designed to work with the Library by being compiled or
251linked with it, is called a "work that uses the Library". Such a
252work, in isolation, is not a derivative work of the Library, and
253therefore falls outside the scope of this License.
254
255 However, linking a "work that uses the Library" with the Library
256creates an executable that is a derivative of the Library (because it
257contains portions of the Library), rather than a "work that uses the
258library". The executable is therefore covered by this License.
259Section 6 states terms for distribution of such executables.
260
261 When a "work that uses the Library" uses material from a header file
262that is part of the Library, the object code for the work may be a
263derivative work of the Library even though the source code is not.
264Whether this is true is especially significant if the work can be
265linked without the Library, or if the work is itself a library. The
266threshold for this to be true is not precisely defined by law.
267
268 If such an object file uses only numerical parameters, data
269structure layouts and accessors, and small macros and small inline
270functions (ten lines or less in length), then the use of the object
271file is unrestricted, regardless of whether it is legally a derivative
272work. (Executables containing this object code plus portions of the
273Library will still fall under Section 6.)
274
275 Otherwise, if the work is a derivative of the Library, you may
276distribute the object code for the work under the terms of Section 6.
277Any executables containing that work also fall under Section 6,
278whether or not they are linked directly with the Library itself.
279^L
280 6. As an exception to the Sections above, you may also combine or
281link a "work that uses the Library" with the Library to produce a
282work containing portions of the Library, and distribute that work
283under terms of your choice, provided that the terms permit
284modification of the work for the customer's own use and reverse
285engineering for debugging such modifications.
286
287 You must give prominent notice with each copy of the work that the
288Library is used in it and that the Library and its use are covered by
289this License. You must supply a copy of this License. If the work
290during execution displays copyright notices, you must include the
291copyright notice for the Library among them, as well as a reference
292directing the user to the copy of this License. Also, you must do one
293of these things:
294
295 a) Accompany the work with the complete corresponding
296 machine-readable source code for the Library including whatever
297 changes were used in the work (which must be distributed under
298 Sections 1 and 2 above); and, if the work is an executable linked
299 with the Library, with the complete machine-readable "work that
300 uses the Library", as object code and/or source code, so that the
301 user can modify the Library and then relink to produce a modified
302 executable containing the modified Library. (It is understood
303 that the user who changes the contents of definitions files in the
304 Library will not necessarily be able to recompile the application
305 to use the modified definitions.)
306
307 b) Use a suitable shared library mechanism for linking with the
308 Library. A suitable mechanism is one that (1) uses at run time a
309 copy of the library already present on the user's computer system,
310 rather than copying library functions into the executable, and (2)
311 will operate properly with a modified version of the library, if
312 the user installs one, as long as the modified version is
313 interface-compatible with the version that the work was made with.
314
315 c) Accompany the work with a written offer, valid for at least
316 three years, to give the same user the materials specified in
317 Subsection 6a, above, for a charge no more than the cost of
318 performing this distribution.
319
320 d) If distribution of the work is made by offering access to copy
321 from a designated place, offer equivalent access to copy the above
322 specified materials from the same place.
323
324 e) Verify that the user has already received a copy of these
325 materials or that you have already sent this user a copy.
326
327 For an executable, the required form of the "work that uses the
328Library" must include any data and utility programs needed for
329reproducing the executable from it. However, as a special exception,
330the materials to be distributed need not include anything that is
331normally distributed (in either source or binary form) with the major
332components (compiler, kernel, and so on) of the operating system on
333which the executable runs, unless that component itself accompanies
334the executable.
335
336 It may happen that this requirement contradicts the license
337restrictions of other proprietary libraries that do not normally
338accompany the operating system. Such a contradiction means you cannot
339use both them and the Library together in an executable that you
340distribute.
341^L
342 7. You may place library facilities that are a work based on the
343Library side-by-side in a single library together with other library
344facilities not covered by this License, and distribute such a combined
345library, provided that the separate distribution of the work based on
346the Library and of the other library facilities is otherwise
347permitted, and provided that you do these two things:
348
349 a) Accompany the combined library with a copy of the same work
350 based on the Library, uncombined with any other library
351 facilities. This must be distributed under the terms of the
352 Sections above.
353
354 b) Give prominent notice with the combined library of the fact
355 that part of it is a work based on the Library, and explaining
356 where to find the accompanying uncombined form of the same work.
357
358 8. You may not copy, modify, sublicense, link with, or distribute
359the Library except as expressly provided under this License. Any
360attempt otherwise to copy, modify, sublicense, link with, or
361distribute the Library is void, and will automatically terminate your
362rights under this License. However, parties who have received copies,
363or rights, from you under this License will not have their licenses
364terminated so long as such parties remain in full compliance.
365
366 9. You are not required to accept this License, since you have not
367signed it. However, nothing else grants you permission to modify or
368distribute the Library or its derivative works. These actions are
369prohibited by law if you do not accept this License. Therefore, by
370modifying or distributing the Library (or any work based on the
371Library), you indicate your acceptance of this License to do so, and
372all its terms and conditions for copying, distributing or modifying
373the Library or works based on it.
374
375 10. Each time you redistribute the Library (or any work based on the
376Library), the recipient automatically receives a license from the
377original licensor to copy, distribute, link with or modify the Library
378subject to these terms and conditions. You may not impose any further
379restrictions on the recipients' exercise of the rights granted herein.
380You are not responsible for enforcing compliance by third parties with
381this License.
382^L
383 11. If, as a consequence of a court judgment or allegation of patent
384infringement or for any other reason (not limited to patent issues),
385conditions are imposed on you (whether by court order, agreement or
386otherwise) that contradict the conditions of this License, they do not
387excuse you from the conditions of this License. If you cannot
388distribute so as to satisfy simultaneously your obligations under this
389License and any other pertinent obligations, then as a consequence you
390may not distribute the Library at all. For example, if a patent
391license would not permit royalty-free redistribution of the Library by
392all those who receive copies directly or indirectly through you, then
393the only way you could satisfy both it and this License would be to
394refrain entirely from distribution of the Library.
395
396If any portion of this section is held invalid or unenforceable under
397any particular circumstance, the balance of the section is intended to
398apply, and the section as a whole is intended to apply in other
399circumstances.
400
401It is not the purpose of this section to induce you to infringe any
402patents or other property right claims or to contest validity of any
403such claims; this section has the sole purpose of protecting the
404integrity of the free software distribution system which is
405implemented by public license practices. Many people have made
406generous contributions to the wide range of software distributed
407through that system in reliance on consistent application of that
408system; it is up to the author/donor to decide if he or she is willing
409to distribute software through any other system and a licensee cannot
410impose that choice.
411
412This section is intended to make thoroughly clear what is believed to
413be a consequence of the rest of this License.
414
415 12. If the distribution and/or use of the Library is restricted in
416certain countries either by patents or by copyrighted interfaces, the
417original copyright holder who places the Library under this License
418may add an explicit geographical distribution limitation excluding those
419countries, so that distribution is permitted only in or among
420countries not thus excluded. In such case, this License incorporates
421the limitation as if written in the body of this License.
422
423 13. The Free Software Foundation may publish revised and/or new
424versions of the Lesser General Public License from time to time.
425Such new versions will be similar in spirit to the present version,
426but may differ in detail to address new problems or concerns.
427
428Each version is given a distinguishing version number. If the Library
429specifies a version number of this License which applies to it and
430"any later version", you have the option of following the terms and
431conditions either of that version or of any later version published by
432the Free Software Foundation. If the Library does not specify a
433license version number, you may choose any version ever published by
434the Free Software Foundation.
435^L
436 14. If you wish to incorporate parts of the Library into other free
437programs whose distribution conditions are incompatible with these,
438write to the author to ask for permission. For software which is
439copyrighted by the Free Software Foundation, write to the Free
440Software Foundation; we sometimes make exceptions for this. Our
441decision will be guided by the two goals of preserving the free status
442of all derivatives of our free software and of promoting the sharing
443and reuse of software generally.
444
445 NO WARRANTY
446
447 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
448WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
449EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
450OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
451KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
452IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
453PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
454LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
455THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
456
457 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
458WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
459AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
460FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
461CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
462LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
463RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
464FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
465SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
466DAMAGES.
467
468 END OF TERMS AND CONDITIONS
469^L
470 How to Apply These Terms to Your New Libraries
471
472 If you develop a new library, and you want it to be of the greatest
473possible use to the public, we recommend making it free software that
474everyone can redistribute and change. You can do so by permitting
475redistribution under these terms (or, alternatively, under the terms
476of the ordinary General Public License).
477
478 To apply these terms, attach the following notices to the library.
479It is safest to attach them to the start of each source file to most
480effectively convey the exclusion of warranty; and each file should
481have at least the "copyright" line and a pointer to where the full
482notice is found.
483
484
485 <one line to give the library's name and a brief idea of what it does.>
486 Copyright (C) <year> <name of author>
487
488 This library is free software; you can redistribute it and/or
489 modify it under the terms of the GNU Lesser General Public
490 License as published by the Free Software Foundation; either
491 version 2.1 of the License, or (at your option) any later version.
492
493 This library is distributed in the hope that it will be useful,
494 but WITHOUT ANY WARRANTY; without even the implied warranty of
495 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
496 Lesser General Public License for more details.
497
498 You should have received a copy of the GNU Lesser General Public
499 License along with this library; if not, write to the Free Software
500 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
501
502Also add information on how to contact you by electronic and paper mail.
503
504You should also get your employer (if you work as a programmer) or
505your school, if any, to sign a "copyright disclaimer" for the library,
506if necessary. Here is a sample; alter the names:
507
508 Yoyodyne, Inc., hereby disclaims all copyright interest in the
509 library `Frob' (a library for tweaking knobs) written by James
510 Random Hacker.
511
512 <signature of Ty Coon>, 1 April 1990
513 Ty Coon, President of Vice
514
515That's all there is to it!
516
517
diff --git a/pwmanager/CodingStyle b/pwmanager/CodingStyle
new file mode 100644
index 0000000..67beae8
--- a/dev/null
+++ b/pwmanager/CodingStyle
@@ -0,0 +1,36 @@
1
2 PwManager coding style
3
4This program is being developed with the linux-kernel coding-style
5in mind. Please read these guidelines first, to get a basic
6knowledge of the style. You can find it in
7/usr/src/linux/Documentation/CodingStyle for example.
8
9A few other guidelines apply to this program, too:
10
11- Please use new-style C++ casts, if you need to make a cast.
12
13- The class PwMDoc is _only_ for internal document-data-
14 management. Don't put any view- or user-interface-stuff in
15 it. Not even a MessageBox. You may use the class PwMDocUi
16 to add UI-functionality to the document.
17
18- Don't add any document related stuff to another class
19 than PwMDoc. Exception: Put it into its own class and
20 invoke this class from within PwMDoc.
21
22- This program makes extensive use of inline functions, for
23 example to access data-members from outside of the class.
24 Please try to do so, too.
25
26- Don't try to optimize code for speed, where speed doesn't
27 matter. Instead optimize it for readability.
28
29- In the code we use the string "PwM" instead of "PwManager",
30 where needed. This has two reasons. The original name of
31 this program was "PwM". The second reason is that it's shorter.
32
33- It's an absolute requirement to have fun while developing
34 code for this application.
35
36 Michael Buesch
diff --git a/pwmanager/Makefile.am b/pwmanager/Makefile.am
new file mode 100644
index 0000000..91202d2
--- a/dev/null
+++ b/pwmanager/Makefile.am
@@ -0,0 +1,26 @@
1SUBDIRS = pwmanager
2
3AUTOMAKE_OPTIONS = dist-bzip2
4
5MAINTAINERCLEANFILES = subdirs configure.in acinclude.m4 configure.files
6
7EXTRA_DIST = rpm debian file-format keycard-format COPYING.LGPL CodingStyle
8
9# target to generate a .pot file manually (without scripty)
10messages_manually:
11 extractrc `find . -name "*.rc" -o -name "*.ui"` > rc.cpp
12 LIST=`find . -name \*.h -o -name \*.hh -o -name \*.H -o -name \*.hxx -o -name \*.hpp -o -name \*.cpp -o -name \*.cc -o -name \*.cxx -o -name \*.ecpp -o -name \*.C`; \
13 if test -n "$$LIST"; then \
14 xgettext -ki18n -kI18N_NOOP -o ./pwmanager.pot $$LIST ; \
15 fi
16 rm -f rc.cpp
17
18# target for automatic .pot file merging by scripty.
19# disable this target to disable automatic merging.
20#messages: rc.cpp
21 #$(EXTRACTRC) `find . -name "*.rc" -o -name "*.ui"` > rc.cpp
22 #LIST=`find . -name \*.h -o -name \*.hh -o -name \*.H -o -name \*.hxx -o -name \*.hpp -o -name \*.cpp -o -name \*.cc -o -name \*.cxx -o -name \*.ecpp -o -name \*.C`; \
23 #if test -n "$$LIST"; then \
24 # $(XGETTEXT) $$LIST -o $(podir)/pwmanager.pot; \
25 #fi
26 #rm -f rc.cpp
diff --git a/pwmanager/NEWS b/pwmanager/NEWS
new file mode 100644
index 0000000..8d1c8b6
--- a/dev/null
+++ b/pwmanager/NEWS
@@ -0,0 +1 @@
diff --git a/pwmanager/VERSION b/pwmanager/VERSION
new file mode 100644
index 0000000..df6f065
--- a/dev/null
+++ b/pwmanager/VERSION
@@ -0,0 +1 @@
PwManager 1.0
diff --git a/pwmanager/configure.in.bot b/pwmanager/configure.in.bot
new file mode 100644
index 0000000..f281f69
--- a/dev/null
+++ b/pwmanager/configure.in.bot
@@ -0,0 +1,34 @@
1dnl Put here things to be done at the very end - telling users
2dnl about additional packages to install.
3
4if test "${keycard_available}" != "yes" ; then
5 echo ""
6 echo "PwManager is built without chipcard (Smartcard) support."
7 echo "Either libchipcard is unavailable, or you have manually"
8 echo "disabled compiling of chipcard support."
9 echo ""
10fi
11
12if test "${kwallet_available}" != "yes" ; then
13 echo ""
14 echo "PwManager is built without KWallet support."
15 echo "Either KWallet is unavailable (KDE-3.2 not installed), or"
16 echo "you have manually disabled compiling of KWallet support."
17 echo ""
18fi
19
20if test "${bzlib_available}" != "yes" ; then
21 echo ""
22 echo "PwManager: FATAL! libbzip2 not found!"
23fi
24
25if test "${zlib_available}" != "yes" ; then
26 echo ""
27 echo "PwManager: FATAL! zlib not found!"
28fi
29
30if test "`echo ${DO_NOT_COMPILE} | grep "pwmanager" | awk '{print $0}'`" != "" ; then
31 echo ""
32 echo "PwManager compilation is disabled because of missing required libraries!"
33 echo ""
34fi
diff --git a/pwmanager/file-format b/pwmanager/file-format
new file mode 100644
index 0000000..610ab51
--- a/dev/null
+++ b/pwmanager/file-format
@@ -0,0 +1,137 @@
1<========================>
2< Format of *.pwm file >
3<========================>
4fileversion: 0x05 revision: 0x01
5
6(note: another revision doesn't change fore- or
7 backward compatibility)
8
9
10The file has a header and a data-body.
11
12****************************************************
13* The header is build from the following elements: *
14****************************************************
15PWM_PASSWORD_FILE
16[FILEVER]
17[KEY-HASH-ALGO]
18[DATA-HASH-ALGO]
19[CRYPT-ALGO]
20[COMPRESSED-FLAG]
21[MPW-FLAG]
22[BYTES-RESERVED]
23[KEY-HASH]
24[DATA-HASH]
25
26
27(note: fields marked with ~ were added _after_
28 revision 0x01)
29
30
31PWM_PASSWORD_FILE is a magic string to indentify the file.
32This string is put directly at offset 0x00 of the file.
33
34[FILEVER] is one byte for holding the file-version.
35This byte is directly appended to the "magic-string".
36(no newline or other separators between these fields)
37
38[HASH-ALGO] is one byte for holding the type of the hash-algorithm
39used to hash the key.
400x01 => SHA1
41
42[DATA-HASH-ALGO] is one byte for holding the type of the
43hash-algorithm used to hash the raw data-stream.
440x01 => SHA1
45
46[CRYPT-ALGO] is one byte containing the type of the crypt-algorithm
47used to encrypt the data.
480x01 => Blowfish
49
50[COMPRESSED-FLAG] is one byte which can be
510x00 => not compressed
520x01 => compressed with gzip
530x02 => compressed with bzip2
54
55[MPW-FLAG] is one byte, either 0x00 if
56we used a master password to encrypt the data,
57or 0x01, if we used a chipcard to encrypt the data.
58
59[BYTES-RESERVED]
6064-bytes reserved for future-use.
61Set all these to 0x00.
62
63[KEY-HASH] is the hash of the key. This field has no constant
64length, because it's length depends on the algorithm
65used in HASH-ALGO.
66
67[DATA-HASH] is a hash of the raw, unencrypted, serialized
68data stream.
69
70
71**************
72* Data-body: *
73**************
74
75The data-body follows the header directly.
76It contains the encrypted serialized data in XML-format.
77It may be compressed.
78For an example
79how to serialize the data, have a look at:
80PwMDoc::serializeDta();
81PwMDoc::deSerializeDta();
82The class "Serializer"
83PwMDoc::encrypt();
84PwMDoc::decrypt();
85
86These functions are called by:
87PwMDoc::saveDoc();
88PwMDoc::openDoc();
89so, please have a look at these two functions, too.
90
91
92
93Example of an XML-data-block:
94
95<PwM-xml-dat ver="0x02">
96 <categories>
97 <cat_0 name="catName">
98 <entry_0>
99 <desc>sampleDesc</desc>
100 <name>sampleName</name>
101 <pw>samplePw</pw>
102 <comment>sampleComment</comment>
103 <url>sampleUrl</url>
104 <launcher>sampleLauncher</launcher>
105 <listViewPos>sampleListViewPos</listViewPos>
106 <b>0</b>
107 </entry_0>
108 <entry_1>
109 <desc>sampleDesc</desc>
110 <name>sampleName</name>
111 <pw>samplePw</pw>
112 <comment>sampleComment</comment>
113 <url>sampleUrl</url>
114 <launcher>sampleLauncher</launcher>
115 <listViewPos>sampleListViewPos</listViewPos>
116 <b>1</b>
117 </entry_1>
118 </cat_0>
119 </categories>
120</PwM-xml-dat>
121
1222004-06-05:
123So I introduced shorter names for the entries. We also have to support
124the old names to be backward compatibel.
125New names are:
126 PwM-xml-dat = P
127 <categories> = <c>
128 <cat_X> = <cX>
129 <entry_X> = <eX>
130 <desc> = <d>
131 <name> = <n>
132 <pw> = <p>
133 <comment> = <c>
134 <url> = <u>
135 <launcher> = <l>
136 <listViewPos> = <v>
137 <b> = <b>
diff --git a/pwmanager/keycard-format b/pwmanager/keycard-format
new file mode 100644
index 0000000..1ae1b5e
--- a/dev/null
+++ b/pwmanager/keycard-format
@@ -0,0 +1,55 @@
1<=========================>
2< Format of PwM-KeyCard >
3<=========================>
4cardformat version: 0x01
5
6The keycard has a small header area and a key-data body.
7
8The header is built with the following scheme:
9
10PWMKEYCARD
11[CARDVER]
12[CARD-ID]
13[KEYDATA-LENGTH]
14
15
16After this header, the key-data-body with the length
17[KEYDATA-LENGTH] follows.
18
19Explanation of the header-fields:
20
21PWMKEYCARD is a magic string at the beginning of the card
22to indentify the chipcard as a "pwm-keycard".
23
24[CARDVER] is one byte for holding the card-format version.
25
26[CARD-ID] are 4 bytes (an unsigned BIG-ENDIAN value)
27to hold an ID number for the card.
28
29[KEYDATA-LENGTH] are 2 bytes (an unsigned short) for holding
30the length of the key-data in BIG-ENDIAN format.
31
32
33*******************************
34* KeyCard backup-image format *
35*******************************
36backup image version: 0x01
37
38PWMKEYCARD_BACKUPIMAGE
39[IMAGEVER]
40[CARD-ID]
41[KEYDATA]
42
43
44PWMKEYCARD_BACKUPIMAGE
45magic header.
46
47[IMAGEVER]
48version indentifier of the backup-image.
49
50[CARD-ID]
51card-ID. see keycard-format.
52
53[KEYDATA]
54All data after CARD-ID until the end of the file
55is treated as the key itself.
diff --git a/pwmanager/pwmanager/addentrywnd.cpp b/pwmanager/pwmanager/addentrywnd.cpp
new file mode 100644
index 0000000..fa98075
--- a/dev/null
+++ b/pwmanager/pwmanager/addentrywnd.cpp
@@ -0,0 +1,203 @@
1/****************************************************************************
2** Form implementation generated from reading ui file 'addentrywnd.ui'
3**
4** Created: Tue Sep 14 13:42:03 2004
5** by: The User Interface Compiler ($Id$)
6**
7** WARNING! All changes made in this file will be lost!
8****************************************************************************/
9
10#include "addentrywnd.h"
11
12#include <qvariant.h>
13#include <qlineedit.h>
14#include <qpushbutton.h>
15#include <qcombobox.h>
16#include <qlabel.h>
17#include <qgroupbox.h>
18#include <qlayout.h>
19#include <qtooltip.h>
20#include <qwhatsthis.h>
21
22/*
23 * Constructs a addEntryWnd as a child of 'parent', with the
24 * name 'name' and widget flags set to 'f'.
25 *
26 * The dialog will by default be modeless, unless you set 'modal' to
27 * TRUE to construct a modal dialog.
28 */
29addEntryWnd::addEntryWnd( QWidget* parent, const char* name, bool modal, WFlags fl )
30 : QDialog( parent, name, modal, fl )
31{
32 if ( !name )
33 setName( "addEntryWnd" );
34
35 launcherLineEdit = new QLineEdit( this, "launcherLineEdit" );
36 launcherLineEdit->setGeometry( QRect( 310, 90, 250, 21 ) );
37
38 cancelButton = new QPushButton( this, "cancelButton" );
39 cancelButton->setGeometry( QRect( 290, 320, 260, 27 ) );
40
41 generateButton = new QPushButton( this, "generateButton" );
42 generateButton->setGeometry( QRect( 137, 210, 120, 27 ) );
43
44 descLineEdit = new QLineEdit( this, "descLineEdit" );
45 descLineEdit->setGeometry( QRect( 10, 30, 250, 20 ) );
46
47 categoryComboBox = new QComboBox( FALSE, this, "categoryComboBox" );
48 categoryComboBox->setGeometry( QRect( 10, 80, 250, 27 ) );
49 categoryComboBox->setEditable( TRUE );
50 categoryComboBox->setSizeLimit( 100 );
51 categoryComboBox->setAutoCompletion( TRUE );
52 categoryComboBox->setDuplicatesEnabled( FALSE );
53
54 usernameLineEdit = new QLineEdit( this, "usernameLineEdit" );
55 usernameLineEdit->setGeometry( QRect( 10, 140, 250, 20 ) );
56
57 pwLineEdit = new QLineEdit( this, "pwLineEdit" );
58 pwLineEdit->setGeometry( QRect( 10, 190, 250, 20 ) );
59 pwLineEdit->setEchoMode( QLineEdit::Password );
60
61 urlLineEdit = new QLineEdit( this, "urlLineEdit" );
62 urlLineEdit->setGeometry( QRect( 10, 269, 250, 20 ) );
63
64 textLabel1_3 = new QLabel( this, "textLabel1_3" );
65 textLabel1_3->setGeometry( QRect( 276, 10, 20, 280 ) );
66 textLabel1_3->setFrameShape( QLabel::VLine );
67
68 textLabel1 = new QLabel( this, "textLabel1" );
69 textLabel1->setGeometry( QRect( 10, 10, 250, 20 ) );
70
71 textLabel1_2 = new QLabel( this, "textLabel1_2" );
72 textLabel1_2->setGeometry( QRect( 10, 60, 250, 20 ) );
73
74 textLabel2 = new QLabel( this, "textLabel2" );
75 textLabel2->setGeometry( QRect( 10, 120, 250, 20 ) );
76 textLabel2->setFrameShape( QLabel::NoFrame );
77 textLabel2->setFrameShadow( QLabel::Plain );
78
79 textLabel3 = new QLabel( this, "textLabel3" );
80 textLabel3->setGeometry( QRect( 10, 170, 250, 20 ) );
81
82 textLabel2_2 = new QLabel( this, "textLabel2_2" );
83 textLabel2_2->setGeometry( QRect( 10, 248, 250, 20 ) );
84
85 textLabel3_2 = new QLabel( this, "textLabel3_2" );
86 textLabel3_2->setGeometry( QRect( 309, 8, 250, 20 ) );
87
88 textLabel1_4 = new QLabel( this, "textLabel1_4" );
89 textLabel1_4->setGeometry( QRect( 310, 30, 250, 16 ) );
90
91 textLabel3_3 = new QLabel( this, "textLabel3_3" );
92 textLabel3_3->setGeometry( QRect( 310, 50, 130, 16 ) );
93
94 textLabel2_3 = new QLabel( this, "textLabel2_3" );
95 textLabel2_3->setGeometry( QRect( 310, 70, 130, 16 ) );
96
97 textLabel5 = new QLabel( this, "textLabel5" );
98 textLabel5->setGeometry( QRect( 440, 70, 120, 16 ) );
99
100 textLabel4_2 = new QLabel( this, "textLabel4_2" );
101 textLabel4_2->setGeometry( QRect( 440, 50, 120, 16 ) );
102
103 revealButton = new QPushButton( this, "revealButton" );
104 revealButton->setGeometry( QRect( 10, 210, 120, 27 ) );
105 revealButton->setToggleButton( TRUE );
106
107 okButton = new QPushButton( this, "okButton" );
108 okButton->setGeometry( QRect( 20, 320, 260, 27 ) );
109
110 groupBox1 = new QGroupBox( this, "groupBox1" );
111 groupBox1->setGeometry( QRect( 300, 140, 260, 150 ) );
112
113 commentDummy = new QLabel( groupBox1, "commentDummy" );
114 commentDummy->setGeometry( QRect( 10, 20, 240, 80 ) );
115
116 advancedCommentButton = new QPushButton( groupBox1, "advancedCommentButton" );
117 advancedCommentButton->setGeometry( QRect( 10, 110, 240, 30 ) );
118 advancedCommentButton->setToggleButton( TRUE );
119 languageChange();
120 resize( QSize(570, 357).expandedTo(minimumSizeHint()) );
121 clearWState( WState_Polished );
122
123 // signals and slots connections
124 connect( generateButton, SIGNAL( clicked() ), this, SLOT( generateButton_slot() ) );
125 connect( revealButton, SIGNAL( toggled(bool) ), this, SLOT( revealButton_slot() ) );
126 connect( cancelButton, SIGNAL( clicked() ), this, SLOT( cancelButton_slot() ) );
127 connect( okButton, SIGNAL( clicked() ), this, SLOT( okButton_slot() ) );
128 connect( advancedCommentButton, SIGNAL( toggled(bool) ), this, SLOT( advancedCommentButton_slot(bool) ) );
129
130 // tab order
131 setTabOrder( descLineEdit, categoryComboBox );
132 setTabOrder( categoryComboBox, usernameLineEdit );
133 setTabOrder( usernameLineEdit, pwLineEdit );
134 setTabOrder( pwLineEdit, revealButton );
135 setTabOrder( revealButton, generateButton );
136 setTabOrder( generateButton, urlLineEdit );
137 setTabOrder( urlLineEdit, launcherLineEdit );
138 setTabOrder( launcherLineEdit, okButton );
139 setTabOrder( okButton, cancelButton );
140
141}
142
143/*
144 * Destroys the object and frees any allocated resources
145 */
146addEntryWnd::~addEntryWnd()
147{
148 // no need to delete child widgets, Qt does it all for us
149}
150
151/*
152 * Sets the strings of the subwidgets using the current
153 * language.
154 */
155void addEntryWnd::languageChange()
156{
157 setCaption( tr( "edit/add a password-entry" ) );
158 cancelButton->setText( tr( "&Cancel" ) );
159 generateButton->setText( tr( "&Generate" ) );
160 textLabel1_3->setText( QString::null );
161 textLabel1->setText( tr( "Description:" ) );
162 textLabel1_2->setText( tr( "Category:" ) );
163 textLabel2->setText( tr( "Username:" ) );
164 textLabel3->setText( tr( "Password:" ) );
165 textLabel2_2->setText( tr( "URL:" ) );
166 textLabel3_2->setText( tr( "Launcher:" ) );
167 textLabel1_4->setText( tr( "$d = Description" ) );
168 textLabel3_3->setText( tr( "$n = Username" ) );
169 textLabel2_3->setText( tr( "$c = Comment" ) );
170 textLabel5->setText( tr( "$u = URL" ) );
171 textLabel4_2->setText( tr( "$p = Password" ) );
172 revealButton->setText( tr( "&Reveal" ) );
173 okButton->setText( tr( "&OK" ) );
174 groupBox1->setTitle( tr( "Comment:" ) );
175 commentDummy->setText( QString::null );
176 advancedCommentButton->setText( tr( "advanced comment" ) );
177}
178
179void addEntryWnd::okButton_slot()
180{
181 qWarning( "addEntryWnd::okButton_slot(): Not implemented yet" );
182}
183
184void addEntryWnd::cancelButton_slot()
185{
186 qWarning( "addEntryWnd::cancelButton_slot(): Not implemented yet" );
187}
188
189void addEntryWnd::revealButton_slot()
190{
191 qWarning( "addEntryWnd::revealButton_slot(): Not implemented yet" );
192}
193
194void addEntryWnd::generateButton_slot()
195{
196 qWarning( "addEntryWnd::generateButton_slot(): Not implemented yet" );
197}
198
199void addEntryWnd::advancedCommentButton_slot(bool)
200{
201 qWarning( "addEntryWnd::advancedCommentButton_slot(bool): Not implemented yet" );
202}
203
diff --git a/pwmanager/pwmanager/addentrywnd.h b/pwmanager/pwmanager/addentrywnd.h
new file mode 100644
index 0000000..905e265
--- a/dev/null
+++ b/pwmanager/pwmanager/addentrywnd.h
@@ -0,0 +1,74 @@
1/****************************************************************************
2** Form interface generated from reading ui file 'addentrywnd.ui'
3**
4** Created: Tue Sep 14 13:42:03 2004
5** by: The User Interface Compiler ($Id$)
6**
7** WARNING! All changes made in this file will be lost!
8****************************************************************************/
9
10#ifndef ADDENTRYWND_H
11#define ADDENTRYWND_H
12
13#include <qvariant.h>
14#include <qdialog.h>
15
16class QVBoxLayout;
17class QHBoxLayout;
18class QGridLayout;
19class QSpacerItem;
20class QLineEdit;
21class QPushButton;
22class QComboBox;
23class QLabel;
24class QGroupBox;
25
26class addEntryWnd : public QDialog
27{
28 Q_OBJECT
29
30public:
31 addEntryWnd( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
32 ~addEntryWnd();
33
34 QLineEdit* launcherLineEdit;
35 QPushButton* cancelButton;
36 QPushButton* generateButton;
37 QLineEdit* descLineEdit;
38 QComboBox* categoryComboBox;
39 QLineEdit* usernameLineEdit;
40 QLineEdit* pwLineEdit;
41 QLineEdit* urlLineEdit;
42 QLabel* textLabel1_3;
43 QLabel* textLabel1;
44 QLabel* textLabel1_2;
45 QLabel* textLabel2;
46 QLabel* textLabel3;
47 QLabel* textLabel2_2;
48 QLabel* textLabel3_2;
49 QLabel* textLabel1_4;
50 QLabel* textLabel3_3;
51 QLabel* textLabel2_3;
52 QLabel* textLabel5;
53 QLabel* textLabel4_2;
54 QPushButton* revealButton;
55 QPushButton* okButton;
56 QGroupBox* groupBox1;
57 QLabel* commentDummy;
58 QPushButton* advancedCommentButton;
59
60public slots:
61 virtual void okButton_slot();
62 virtual void cancelButton_slot();
63 virtual void revealButton_slot();
64 virtual void generateButton_slot();
65 virtual void advancedCommentButton_slot(bool on);
66
67protected:
68
69protected slots:
70 virtual void languageChange();
71
72};
73
74#endif // ADDENTRYWND_H
diff --git a/pwmanager/pwmanager/addentrywnd.ui b/pwmanager/pwmanager/addentrywnd.ui
new file mode 100644
index 0000000..7ea7342
--- a/dev/null
+++ b/pwmanager/pwmanager/addentrywnd.ui
@@ -0,0 +1,483 @@
1<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
2<class>addEntryWnd</class>
3<widget class="QDialog">
4 <property name="name">
5 <cstring>addEntryWnd</cstring>
6 </property>
7 <property name="geometry">
8 <rect>
9 <x>0</x>
10 <y>0</y>
11 <width>570</width>
12 <height>357</height>
13 </rect>
14 </property>
15 <property name="caption">
16 <string>edit/add a password-entry</string>
17 </property>
18 <widget class="QLineEdit">
19 <property name="name">
20 <cstring>launcherLineEdit</cstring>
21 </property>
22 <property name="geometry">
23 <rect>
24 <x>310</x>
25 <y>90</y>
26 <width>250</width>
27 <height>21</height>
28 </rect>
29 </property>
30 </widget>
31 <widget class="QPushButton">
32 <property name="name">
33 <cstring>cancelButton</cstring>
34 </property>
35 <property name="geometry">
36 <rect>
37 <x>290</x>
38 <y>320</y>
39 <width>260</width>
40 <height>27</height>
41 </rect>
42 </property>
43 <property name="text">
44 <string>&amp;Cancel</string>
45 </property>
46 </widget>
47 <widget class="QPushButton">
48 <property name="name">
49 <cstring>generateButton</cstring>
50 </property>
51 <property name="geometry">
52 <rect>
53 <x>137</x>
54 <y>210</y>
55 <width>120</width>
56 <height>27</height>
57 </rect>
58 </property>
59 <property name="text">
60 <string>&amp;Generate</string>
61 </property>
62 </widget>
63 <widget class="QLineEdit">
64 <property name="name">
65 <cstring>descLineEdit</cstring>
66 </property>
67 <property name="geometry">
68 <rect>
69 <x>10</x>
70 <y>30</y>
71 <width>250</width>
72 <height>20</height>
73 </rect>
74 </property>
75 </widget>
76 <widget class="QComboBox">
77 <property name="name">
78 <cstring>categoryComboBox</cstring>
79 </property>
80 <property name="geometry">
81 <rect>
82 <x>10</x>
83 <y>80</y>
84 <width>250</width>
85 <height>27</height>
86 </rect>
87 </property>
88 <property name="editable">
89 <bool>true</bool>
90 </property>
91 <property name="sizeLimit">
92 <number>100</number>
93 </property>
94 <property name="autoCompletion">
95 <bool>true</bool>
96 </property>
97 <property name="duplicatesEnabled">
98 <bool>false</bool>
99 </property>
100 </widget>
101 <widget class="QLineEdit">
102 <property name="name">
103 <cstring>usernameLineEdit</cstring>
104 </property>
105 <property name="geometry">
106 <rect>
107 <x>10</x>
108 <y>140</y>
109 <width>250</width>
110 <height>20</height>
111 </rect>
112 </property>
113 </widget>
114 <widget class="QLineEdit">
115 <property name="name">
116 <cstring>pwLineEdit</cstring>
117 </property>
118 <property name="geometry">
119 <rect>
120 <x>10</x>
121 <y>190</y>
122 <width>250</width>
123 <height>20</height>
124 </rect>
125 </property>
126 <property name="echoMode">
127 <enum>Password</enum>
128 </property>
129 </widget>
130 <widget class="QLineEdit">
131 <property name="name">
132 <cstring>urlLineEdit</cstring>
133 </property>
134 <property name="geometry">
135 <rect>
136 <x>10</x>
137 <y>269</y>
138 <width>250</width>
139 <height>20</height>
140 </rect>
141 </property>
142 </widget>
143 <widget class="QLabel">
144 <property name="name">
145 <cstring>textLabel1_3</cstring>
146 </property>
147 <property name="geometry">
148 <rect>
149 <x>276</x>
150 <y>10</y>
151 <width>20</width>
152 <height>280</height>
153 </rect>
154 </property>
155 <property name="frameShape">
156 <enum>VLine</enum>
157 </property>
158 <property name="text">
159 <string></string>
160 </property>
161 </widget>
162 <widget class="QLabel">
163 <property name="name">
164 <cstring>textLabel1</cstring>
165 </property>
166 <property name="geometry">
167 <rect>
168 <x>10</x>
169 <y>10</y>
170 <width>250</width>
171 <height>20</height>
172 </rect>
173 </property>
174 <property name="text">
175 <string>Description:</string>
176 </property>
177 </widget>
178 <widget class="QLabel">
179 <property name="name">
180 <cstring>textLabel1_2</cstring>
181 </property>
182 <property name="geometry">
183 <rect>
184 <x>10</x>
185 <y>60</y>
186 <width>250</width>
187 <height>20</height>
188 </rect>
189 </property>
190 <property name="text">
191 <string>Category:</string>
192 </property>
193 </widget>
194 <widget class="QLabel">
195 <property name="name">
196 <cstring>textLabel2</cstring>
197 </property>
198 <property name="geometry">
199 <rect>
200 <x>10</x>
201 <y>120</y>
202 <width>250</width>
203 <height>20</height>
204 </rect>
205 </property>
206 <property name="frameShape">
207 <enum>NoFrame</enum>
208 </property>
209 <property name="frameShadow">
210 <enum>Plain</enum>
211 </property>
212 <property name="text">
213 <string>Username:</string>
214 </property>
215 </widget>
216 <widget class="QLabel">
217 <property name="name">
218 <cstring>textLabel3</cstring>
219 </property>
220 <property name="geometry">
221 <rect>
222 <x>10</x>
223 <y>170</y>
224 <width>250</width>
225 <height>20</height>
226 </rect>
227 </property>
228 <property name="text">
229 <string>Password:</string>
230 </property>
231 </widget>
232 <widget class="QLabel">
233 <property name="name">
234 <cstring>textLabel2_2</cstring>
235 </property>
236 <property name="geometry">
237 <rect>
238 <x>10</x>
239 <y>248</y>
240 <width>250</width>
241 <height>20</height>
242 </rect>
243 </property>
244 <property name="text">
245 <string>URL:</string>
246 </property>
247 </widget>
248 <widget class="QLabel">
249 <property name="name">
250 <cstring>textLabel3_2</cstring>
251 </property>
252 <property name="geometry">
253 <rect>
254 <x>309</x>
255 <y>8</y>
256 <width>250</width>
257 <height>20</height>
258 </rect>
259 </property>
260 <property name="text">
261 <string>Launcher:</string>
262 </property>
263 </widget>
264 <widget class="QLabel">
265 <property name="name">
266 <cstring>textLabel1_4</cstring>
267 </property>
268 <property name="geometry">
269 <rect>
270 <x>310</x>
271 <y>30</y>
272 <width>250</width>
273 <height>16</height>
274 </rect>
275 </property>
276 <property name="text">
277 <string>$d = Description</string>
278 </property>
279 </widget>
280 <widget class="QLabel">
281 <property name="name">
282 <cstring>textLabel3_3</cstring>
283 </property>
284 <property name="geometry">
285 <rect>
286 <x>310</x>
287 <y>50</y>
288 <width>130</width>
289 <height>16</height>
290 </rect>
291 </property>
292 <property name="text">
293 <string>$n = Username</string>
294 </property>
295 </widget>
296 <widget class="QLabel">
297 <property name="name">
298 <cstring>textLabel2_3</cstring>
299 </property>
300 <property name="geometry">
301 <rect>
302 <x>310</x>
303 <y>70</y>
304 <width>130</width>
305 <height>16</height>
306 </rect>
307 </property>
308 <property name="text">
309 <string>$c = Comment</string>
310 </property>
311 </widget>
312 <widget class="QLabel">
313 <property name="name">
314 <cstring>textLabel5</cstring>
315 </property>
316 <property name="geometry">
317 <rect>
318 <x>440</x>
319 <y>70</y>
320 <width>120</width>
321 <height>16</height>
322 </rect>
323 </property>
324 <property name="text">
325 <string>$u = URL</string>
326 </property>
327 </widget>
328 <widget class="QLabel">
329 <property name="name">
330 <cstring>textLabel4_2</cstring>
331 </property>
332 <property name="geometry">
333 <rect>
334 <x>440</x>
335 <y>50</y>
336 <width>120</width>
337 <height>16</height>
338 </rect>
339 </property>
340 <property name="text">
341 <string>$p = Password</string>
342 </property>
343 </widget>
344 <widget class="QPushButton">
345 <property name="name">
346 <cstring>revealButton</cstring>
347 </property>
348 <property name="geometry">
349 <rect>
350 <x>10</x>
351 <y>210</y>
352 <width>120</width>
353 <height>27</height>
354 </rect>
355 </property>
356 <property name="text">
357 <string>&amp;Reveal</string>
358 </property>
359 <property name="toggleButton">
360 <bool>true</bool>
361 </property>
362 </widget>
363 <widget class="QPushButton">
364 <property name="name">
365 <cstring>okButton</cstring>
366 </property>
367 <property name="geometry">
368 <rect>
369 <x>20</x>
370 <y>320</y>
371 <width>260</width>
372 <height>27</height>
373 </rect>
374 </property>
375 <property name="text">
376 <string>&amp;OK</string>
377 </property>
378 </widget>
379 <widget class="QGroupBox">
380 <property name="name">
381 <cstring>groupBox1</cstring>
382 </property>
383 <property name="geometry">
384 <rect>
385 <x>300</x>
386 <y>140</y>
387 <width>260</width>
388 <height>150</height>
389 </rect>
390 </property>
391 <property name="title">
392 <string>Comment:</string>
393 </property>
394 <widget class="QLabel">
395 <property name="name">
396 <cstring>commentDummy</cstring>
397 </property>
398 <property name="geometry">
399 <rect>
400 <x>10</x>
401 <y>20</y>
402 <width>240</width>
403 <height>80</height>
404 </rect>
405 </property>
406 <property name="text">
407 <string></string>
408 </property>
409 </widget>
410 <widget class="QPushButton">
411 <property name="name">
412 <cstring>advancedCommentButton</cstring>
413 </property>
414 <property name="geometry">
415 <rect>
416 <x>10</x>
417 <y>110</y>
418 <width>240</width>
419 <height>30</height>
420 </rect>
421 </property>
422 <property name="text">
423 <string>advanced comment</string>
424 </property>
425 <property name="toggleButton">
426 <bool>true</bool>
427 </property>
428 </widget>
429 </widget>
430</widget>
431<connections>
432 <connection>
433 <sender>generateButton</sender>
434 <signal>clicked()</signal>
435 <receiver>addEntryWnd</receiver>
436 <slot>generateButton_slot()</slot>
437 </connection>
438 <connection>
439 <sender>revealButton</sender>
440 <signal>toggled(bool)</signal>
441 <receiver>addEntryWnd</receiver>
442 <slot>revealButton_slot()</slot>
443 </connection>
444 <connection>
445 <sender>cancelButton</sender>
446 <signal>clicked()</signal>
447 <receiver>addEntryWnd</receiver>
448 <slot>cancelButton_slot()</slot>
449 </connection>
450 <connection>
451 <sender>okButton</sender>
452 <signal>clicked()</signal>
453 <receiver>addEntryWnd</receiver>
454 <slot>okButton_slot()</slot>
455 </connection>
456 <connection>
457 <sender>advancedCommentButton</sender>
458 <signal>toggled(bool)</signal>
459 <receiver>addEntryWnd</receiver>
460 <slot>advancedCommentButton_slot(bool)</slot>
461 </connection>
462</connections>
463<tabstops>
464 <tabstop>descLineEdit</tabstop>
465 <tabstop>categoryComboBox</tabstop>
466 <tabstop>usernameLineEdit</tabstop>
467 <tabstop>pwLineEdit</tabstop>
468 <tabstop>revealButton</tabstop>
469 <tabstop>generateButton</tabstop>
470 <tabstop>urlLineEdit</tabstop>
471 <tabstop>launcherLineEdit</tabstop>
472 <tabstop>okButton</tabstop>
473 <tabstop>cancelButton</tabstop>
474</tabstops>
475<slots>
476 <slot>okButton_slot()</slot>
477 <slot>cancelButton_slot()</slot>
478 <slot>revealButton_slot()</slot>
479 <slot>generateButton_slot()</slot>
480 <slot>advancedCommentButton_slot(bool on)</slot>
481</slots>
482<layoutdefaults spacing="6" margin="11"/>
483</UI>
diff --git a/pwmanager/pwmanager/addentrywndimpl.cpp b/pwmanager/pwmanager/addentrywndimpl.cpp
new file mode 100644
index 0000000..9e0fde9
--- a/dev/null
+++ b/pwmanager/pwmanager/addentrywndimpl.cpp
@@ -0,0 +1,174 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * Many very good improvements and the original implementations of *
7 * them came from Matt Scifo <mscifo@o1.com> *
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License version 2 *
11 * as published by the Free Software Foundation. *
12 * *
13 ***************************************************************************/
14
15/***************************************************************************
16 * copyright (C) 2004 by Ulf Schenk
17 * This file is originaly based on version 1.0.1 of pwmanager
18 * and was modified to run on embedded devices that run microkde
19 *
20 * $Id$
21 **************************************************************************/
22
23#include "addentrywndimpl.h"
24#include "pwmexception.h"
25#include "pwgenwndimpl.h"
26#ifndef PWM_EMBEDDED
27#include "advcommeditimpl.h"
28#endif
29#include "htmlgen.h"
30
31#include <kmessagebox.h>
32#include <klocale.h>
33
34#include <qpushbutton.h>
35#include <qlabel.h>
36
37
38AddEntryWndImpl::AddEntryWndImpl()
39{
40 editAdvCommentButton = 0;
41 commentTextEdit = 0;
42 switchComment(false);
43 pwGen = new PwGenWndImpl(this);
44}
45
46AddEntryWndImpl::~AddEntryWndImpl()
47{
48 delete_ifnot_null(editAdvCommentButton);
49 delete_ifnot_null(commentTextEdit);
50 delete pwGen;
51}
52
53void AddEntryWndImpl::okButton_slot()
54{
55 if (pwLineEdit->text().isEmpty()) {
56 KMessageBox::error(this,
57 i18n("Sorry, you haven't set a password."),
58 i18n("no password"));
59 return;
60 }
61 if (descLineEdit->text().isEmpty()) {
62 KMessageBox::error(this,
63 i18n
64 ("You haven't set a \"Description\"."),
65 i18n("Description not set"));
66 return;
67 }
68 done(1);
69}
70
71void AddEntryWndImpl::cancelButton_slot()
72{
73 done(2);
74}
75
76void AddEntryWndImpl::setCurrCategory(const QString &cat)
77{
78 int i, count = categoryComboBox->count();
79
80 for (i = 0; i < count; ++i) {
81 if (categoryComboBox->text(i) == cat) {
82 categoryComboBox->setCurrentItem(i);
83 return;
84 }
85 }
86 BUG();
87}
88
89void AddEntryWndImpl::revealButton_slot()
90{
91 if (revealButton->isOn()) {
92 pwLineEdit->setEchoMode(QLineEdit::Normal);
93 } else {
94 pwLineEdit->setEchoMode(QLineEdit::Password);
95 }
96}
97
98void AddEntryWndImpl::generateButton_slot()
99{
100 if (!pwGen->exec())
101 return;
102 setPassword(pwGen->getPassword());
103}
104
105QString AddEntryWndImpl::getComment()
106{
107 if (isAdvancedComment()) {
108 return advCommentDta;
109 }
110 return commentTextEdit->text();
111}
112
113void AddEntryWndImpl::setComment(const QString &comm)
114{
115 if (HtmlGen::isHtml(comm)) {
116 advancedCommentButton->setOn(true);
117 advCommentDta = comm;
118 } else {
119 advancedCommentButton->setOn(false);
120 commentTextEdit->setText(comm);
121 }
122}
123
124void AddEntryWndImpl::advancedCommentButton_slot(bool on)
125{
126 switchComment(on);
127}
128
129void AddEntryWndImpl::switchComment(bool toAdvanced)
130{
131 useAdvComment = toAdvanced;
132 if (toAdvanced) {
133 if (commentTextEdit) {
134 savedCommentText = commentTextEdit->text();
135 delete_and_null(commentTextEdit);
136 }
137 if (editAdvCommentButton)
138 return;
139 editAdvCommentButton = new QPushButton(i18n("Edit advanced comment..."),
140 commentDummy);
141 editAdvCommentButton->resize(commentDummy->size().width(), 50);
142 connect(editAdvCommentButton, SIGNAL(clicked()),
143 this, SLOT(editAdvCommentButton_slot()));
144 editAdvCommentButton->show();
145 } else {
146 delete_ifnot_null(editAdvCommentButton);
147 if (commentTextEdit)
148 return;
149#ifndef PWM_EMBEDDED
150 commentTextEdit = new QTextEdit(commentDummy);
151 commentTextEdit->setTextFormat(Qt::PlainText);
152#else
153 commentTextEdit = new QMultiLineEdit(commentDummy);
154#endif
155 commentTextEdit->resize(commentDummy->size());
156 commentTextEdit->setText(savedCommentText);
157 commentTextEdit->show();
158 }
159}
160
161void AddEntryWndImpl::editAdvCommentButton_slot()
162{
163#ifndef PWM_EMBEDDED
164 AdvCommEditImpl editor(this);
165 editor.setHtmlDta(advCommentDta);
166 if (editor.exec())
167 return;
168 advCommentDta = editor.getHtmlDta();
169#endif
170}
171
172#ifndef PWM_EMBEDDED
173#include "addentrywndimpl.moc"
174#endif
diff --git a/pwmanager/pwmanager/addentrywndimpl.h b/pwmanager/pwmanager/addentrywndimpl.h
new file mode 100644
index 0000000..c0bfcee
--- a/dev/null
+++ b/pwmanager/pwmanager/addentrywndimpl.h
@@ -0,0 +1,114 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef __ADDENTRYWNDIMPL_H
21#define __ADDENTRYWNDIMPL_H
22
23#include "addentrywnd.h"
24
25#include <qlineedit.h>
26#ifndef PWM_EMBEDDED
27#include <qtextedit.h>
28#else
29#include <qmultilineedit.h>
30#endif
31
32#include <qcombobox.h>
33#include <qpushbutton.h>
34
35class PwGenWndImpl;
36
37/** "add/edit" Window */
38class AddEntryWndImpl : public addEntryWnd
39{
40 Q_OBJECT
41public:
42 AddEntryWndImpl();
43 ~AddEntryWndImpl();
44
45 /* get... functions */
46 QString getDescription()
47 { return descLineEdit->text(); }
48 QString getCategory()
49 { return categoryComboBox->currentText(); }
50 QString getUsername()
51 { return usernameLineEdit->text(); }
52 QString getPassword()
53 { return pwLineEdit->text(); }
54 QString getUrl()
55 { return urlLineEdit->text(); }
56 QString getLauncher()
57 { return launcherLineEdit->text(); }
58 QString getComment();
59
60 /* set... functions */
61 void setDescription(const QString &desc)
62 { descLineEdit->setText(desc); }
63 void setCurrCategory(const QString &cat);
64 void addCategory(const QString &cat)
65 { categoryComboBox->insertItem(cat); }
66 void setUsername(const QString &name)
67 { usernameLineEdit->setText(name); }
68 void setPassword(const QString &pw)
69 { pwLineEdit->setText(pw); }
70 void setUrl(const QString &url)
71 { urlLineEdit->setText(url); }
72 void setLauncher(const QString launcher)
73 { launcherLineEdit->setText(launcher); }
74 void setComment(const QString &comm);
75
76 /** are we using an advanced comment */
77 bool isAdvancedComment()
78 { return useAdvComment; }
79
80public slots:
81 /** OK button pressed */
82 void okButton_slot();
83 /** cancel button pressed */
84 void cancelButton_slot();
85 /** Reveal button pressed */
86 void revealButton_slot();
87 /** Generate button pressed */
88 void generateButton_slot();
89 /** advanced comment button pressed */
90 void advancedCommentButton_slot(bool on);
91 /** edit advanced comment button pressed */
92 void editAdvCommentButton_slot();
93
94protected:
95 void switchComment(bool toAdvanced);
96
97protected:
98 QPushButton *editAdvCommentButton;
99#ifndef PWM_EMBEDDED
100 QTextEdit *commentTextEdit;
101#else
102 QMultiLineEdit * commentTextEdit;
103#endif
104 /** saved data from normal comment text edit box */
105 QString savedCommentText;
106 /** use an advanced comment? */
107 bool useAdvComment;
108 /** data of advanced comment (if available) */
109 QString advCommentDta;
110 /** password generation object */
111 PwGenWndImpl *pwGen;
112};
113
114#endif
diff --git a/pwmanager/pwmanager/advcommedit.cpp b/pwmanager/pwmanager/advcommedit.cpp
new file mode 100644
index 0000000..93e4468
--- a/dev/null
+++ b/pwmanager/pwmanager/advcommedit.cpp
@@ -0,0 +1,10 @@
1/****************************************************************************
2** Form implementation generated from reading ui file 'advcommedit.ui'
3**
4** Created: Fri Sep 10 13:16:20 2004
5** by: The User Interface Compiler (uic)
6**
7** WARNING! All changes made in this file will be lost!
8****************************************************************************/
9#include "advcommedit.h"
10
diff --git a/pwmanager/pwmanager/advcommedit.h b/pwmanager/pwmanager/advcommedit.h
new file mode 100644
index 0000000..eb3bf6e
--- a/dev/null
+++ b/pwmanager/pwmanager/advcommedit.h
@@ -0,0 +1,63 @@
1/****************************************************************************
2** Form interface generated from reading ui file 'advcommedit.ui'
3**
4** Created: Mon Sep 13 14:27:05 2004
5** by: The User Interface Compiler ($Id$)
6**
7** WARNING! All changes made in this file will be lost!
8****************************************************************************/
9
10#ifndef ADVCOMMEDIT_H
11#define ADVCOMMEDIT_H
12
13#include <qvariant.h>
14#include <qdialog.h>
15
16class QVBoxLayout;
17class QHBoxLayout;
18class QGridLayout;
19class QSpacerItem;
20class QLabel;
21class QGroupBox;
22class QPushButton;
23class QLineEdit;
24class QListBox;
25class QListBoxItem;
26
27class advCommEdit : public QDialog
28{
29 Q_OBJECT
30
31public:
32 advCommEdit( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
33 ~advCommEdit();
34
35 QLabel* textLabel2;
36 QGroupBox* groupBox1;
37 QLabel* previewDummy;
38 QPushButton* okButton;
39 QPushButton* cancelButton;
40 QPushButton* refreshPreviewButton;
41 QLineEdit* titleLineEdit;
42 QLabel* textLabel3;
43 QListBox* entryListBox;
44 QPushButton* editButton;
45 QPushButton* delButton;
46 QPushButton* addTblButton;
47
48public slots:
49 virtual void okButton_slot();
50 virtual void cancelButton_slot();
51 virtual void updatePreview();
52 virtual void addSubtblButton_slot();
53 virtual void editButton_slot();
54 virtual void delButton_slot();
55
56protected:
57
58protected slots:
59 virtual void languageChange();
60
61};
62
63#endif // ADVCOMMEDIT_H
diff --git a/pwmanager/pwmanager/advcommedit.ui b/pwmanager/pwmanager/advcommedit.ui
new file mode 100644
index 0000000..4e8d7e9
--- a/dev/null
+++ b/pwmanager/pwmanager/advcommedit.ui
@@ -0,0 +1,274 @@
1<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
2<class>advCommEdit</class>
3<widget class="QDialog">
4 <property name="name">
5 <cstring>advCommEdit</cstring>
6 </property>
7 <property name="geometry">
8 <rect>
9 <x>0</x>
10 <y>0</y>
11 <width>685</width>
12 <height>326</height>
13 </rect>
14 </property>
15 <property name="caption">
16 <string>Advanced HTML-comment editor</string>
17 </property>
18 <widget class="QLabel">
19 <property name="name">
20 <cstring>textLabel2</cstring>
21 </property>
22 <property name="geometry">
23 <rect>
24 <x>20</x>
25 <y>10</y>
26 <width>310</width>
27 <height>20</height>
28 </rect>
29 </property>
30 <property name="text">
31 <string>Global title:</string>
32 </property>
33 <property name="alignment">
34 <set>AlignCenter</set>
35 </property>
36 </widget>
37 <widget class="QGroupBox">
38 <property name="name">
39 <cstring>groupBox1</cstring>
40 </property>
41 <property name="geometry">
42 <rect>
43 <x>360</x>
44 <y>10</y>
45 <width>310</width>
46 <height>250</height>
47 </rect>
48 </property>
49 <property name="title">
50 <string>preview</string>
51 </property>
52 <widget class="QLabel">
53 <property name="name">
54 <cstring>previewDummy</cstring>
55 </property>
56 <property name="geometry">
57 <rect>
58 <x>10</x>
59 <y>20</y>
60 <width>290</width>
61 <height>220</height>
62 </rect>
63 </property>
64 <property name="text">
65 <string></string>
66 </property>
67 </widget>
68 </widget>
69 <widget class="QPushButton">
70 <property name="name">
71 <cstring>okButton</cstring>
72 </property>
73 <property name="geometry">
74 <rect>
75 <x>20</x>
76 <y>280</y>
77 <width>180</width>
78 <height>31</height>
79 </rect>
80 </property>
81 <property name="text">
82 <string>&amp;OK</string>
83 </property>
84 </widget>
85 <widget class="QPushButton">
86 <property name="name">
87 <cstring>cancelButton</cstring>
88 </property>
89 <property name="geometry">
90 <rect>
91 <x>490</x>
92 <y>280</y>
93 <width>180</width>
94 <height>31</height>
95 </rect>
96 </property>
97 <property name="text">
98 <string>&amp;Cancel</string>
99 </property>
100 </widget>
101 <widget class="QPushButton">
102 <property name="name">
103 <cstring>refreshPreviewButton</cstring>
104 </property>
105 <property name="geometry">
106 <rect>
107 <x>240</x>
108 <y>280</y>
109 <width>210</width>
110 <height>31</height>
111 </rect>
112 </property>
113 <property name="text">
114 <string>Refresh preview</string>
115 </property>
116 </widget>
117 <widget class="QLineEdit">
118 <property name="name">
119 <cstring>titleLineEdit</cstring>
120 </property>
121 <property name="geometry">
122 <rect>
123 <x>20</x>
124 <y>30</y>
125 <width>310</width>
126 <height>26</height>
127 </rect>
128 </property>
129 </widget>
130 <widget class="QLabel">
131 <property name="name">
132 <cstring>textLabel3</cstring>
133 </property>
134 <property name="geometry">
135 <rect>
136 <x>20</x>
137 <y>70</y>
138 <width>310</width>
139 <height>20</height>
140 </rect>
141 </property>
142 <property name="frameShape">
143 <enum>NoFrame</enum>
144 </property>
145 <property name="frameShadow">
146 <enum>Plain</enum>
147 </property>
148 <property name="text">
149 <string>Current entries:</string>
150 </property>
151 <property name="alignment">
152 <set>AlignCenter</set>
153 </property>
154 </widget>
155 <widget class="QListBox">
156 <property name="name">
157 <cstring>entryListBox</cstring>
158 </property>
159 <property name="geometry">
160 <rect>
161 <x>20</x>
162 <y>90</y>
163 <width>180</width>
164 <height>130</height>
165 </rect>
166 </property>
167 </widget>
168 <widget class="QPushButton">
169 <property name="name">
170 <cstring>editButton</cstring>
171 </property>
172 <property name="geometry">
173 <rect>
174 <x>210</x>
175 <y>140</y>
176 <width>121</width>
177 <height>31</height>
178 </rect>
179 </property>
180 <property name="text">
181 <string>edit</string>
182 </property>
183 </widget>
184 <widget class="QPushButton">
185 <property name="name">
186 <cstring>delButton</cstring>
187 </property>
188 <property name="geometry">
189 <rect>
190 <x>210</x>
191 <y>180</y>
192 <width>121</width>
193 <height>31</height>
194 </rect>
195 </property>
196 <property name="text">
197 <string>delete</string>
198 </property>
199 </widget>
200 <widget class="QPushButton">
201 <property name="name">
202 <cstring>addTblButton</cstring>
203 </property>
204 <property name="geometry">
205 <rect>
206 <x>210</x>
207 <y>100</y>
208 <width>120</width>
209 <height>31</height>
210 </rect>
211 </property>
212 <property name="text">
213 <string>Add</string>
214 </property>
215 </widget>
216</widget>
217<connections>
218 <connection>
219 <sender>okButton</sender>
220 <signal>clicked()</signal>
221 <receiver>advCommEdit</receiver>
222 <slot>okButton_slot()</slot>
223 </connection>
224 <connection>
225 <sender>cancelButton</sender>
226 <signal>clicked()</signal>
227 <receiver>advCommEdit</receiver>
228 <slot>cancelButton_slot()</slot>
229 </connection>
230 <connection>
231 <sender>refreshPreviewButton</sender>
232 <signal>clicked()</signal>
233 <receiver>advCommEdit</receiver>
234 <slot>updatePreview()</slot>
235 </connection>
236 <connection>
237 <sender>addTblButton</sender>
238 <signal>clicked()</signal>
239 <receiver>advCommEdit</receiver>
240 <slot>addSubtblButton_slot()</slot>
241 </connection>
242 <connection>
243 <sender>editButton</sender>
244 <signal>clicked()</signal>
245 <receiver>advCommEdit</receiver>
246 <slot>editButton_slot()</slot>
247 </connection>
248 <connection>
249 <sender>delButton</sender>
250 <signal>clicked()</signal>
251 <receiver>advCommEdit</receiver>
252 <slot>delButton_slot()</slot>
253 </connection>
254</connections>
255<tabstops>
256 <tabstop>titleLineEdit</tabstop>
257 <tabstop>entryListBox</tabstop>
258 <tabstop>addTblButton</tabstop>
259 <tabstop>editButton</tabstop>
260 <tabstop>delButton</tabstop>
261 <tabstop>okButton</tabstop>
262 <tabstop>refreshPreviewButton</tabstop>
263 <tabstop>cancelButton</tabstop>
264</tabstops>
265<slots>
266 <slot>okButton_slot()</slot>
267 <slot>cancelButton_slot()</slot>
268 <slot>updatePreview()</slot>
269 <slot>addSubtblButton_slot()</slot>
270 <slot>editButton_slot()</slot>
271 <slot>delButton_slot()</slot>
272</slots>
273<layoutdefaults spacing="6" margin="11"/>
274</UI>
diff --git a/pwmanager/pwmanager/advcommeditimpl.cpp b/pwmanager/pwmanager/advcommeditimpl.cpp
new file mode 100644
index 0000000..59e5e5b
--- a/dev/null
+++ b/pwmanager/pwmanager/advcommeditimpl.cpp
@@ -0,0 +1,149 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12
13/***************************************************************************
14 * copyright (C) 2004 by Ulf Schenk
15 * This file is originaly based on version 1.0.1 of pwmanager
16 * and was modified to run on embedded devices that run microkde
17 *
18 * $Id$
19 **************************************************************************/
20
21#include "advcommeditimpl.h"
22#include "htmlgen.h"
23#include "htmlparse.h"
24#include "pwmexception.h"
25#include "subtbleditimpl.h"
26
27#include <qlineedit.h>
28#include <qlabel.h>
29
30#include <khtml_part.h>
31#include <khtmlview.h>
32
33
34AdvCommEditImpl::AdvCommEditImpl(QWidget* parent,
35 const char* name,
36 WFlags fl)
37 : advCommEdit(parent, name, fl)
38{
39 dta = new HtmlComment;
40 preview = new KHTMLPart(previewDummy);
41 preview->view()->resize(previewDummy->size());
42 preview->show();
43}
44
45AdvCommEditImpl::~AdvCommEditImpl()
46{
47 delete dta;
48 delete preview;
49}
50
51void AdvCommEditImpl::okButton_slot()
52{
53 updateTitle();
54 done(0);
55}
56
57void AdvCommEditImpl::cancelButton_slot()
58{
59 done(1);
60}
61
62void AdvCommEditImpl::addSubtblButton_slot()
63{
64 SubTblEditImpl editor(this);
65 if (editor.exec())
66 return;
67 QString subTitle(editor.getTitle());
68 HtmlComment::SubTable subTbl;
69 subTbl.setTitle(subTitle);
70 subTbl.setEntries(editor.getEntries());
71 dta->addSubtable(subTbl);
72 entryListBox->insertItem(subTitle);
73 updatePreview();
74}
75
76void AdvCommEditImpl::editButton_slot()
77{
78 int index = curIndex();
79 if (index == -1)
80 return;
81 SubTblEditImpl editor(this);
82 HtmlComment::SubTable subTbl = dta->subtableAt(index);
83 editor.setContent(subTbl.getTitle(), subTbl.getEntryList());
84 if (editor.exec())
85 return;
86 QString subTitle(editor.getTitle());
87 subTbl.setTitle(subTitle);
88 subTbl.setEntries(editor.getEntries());
89 dta->setSubtblAt(index, subTbl);
90 entryListBox->changeItem(subTitle, index);
91 updatePreview();
92}
93
94void AdvCommEditImpl::delButton_slot()
95{
96 int index = curIndex();
97 if (index == -1)
98 return;
99 dta->eraseSubtable(index);
100 entryListBox->removeItem(index);
101 updatePreview();
102}
103
104void AdvCommEditImpl::updatePreview()
105{
106 updateTitle();
107 HtmlGen htmlGen;
108 htmlGen.styleSheetDummy(false);
109 QString code(htmlGen.genHtmlComment(dta));
110 if (code.isEmpty())
111 return;
112 preview->begin();
113 preview->write(code);
114 preview->end();
115}
116
117void AdvCommEditImpl::updateTitle()
118{
119 dta->setTitle(titleLineEdit->text());
120}
121
122QString AdvCommEditImpl::getHtmlDta()
123{
124 HtmlGen htmlGen;
125 return htmlGen.genHtmlComment(dta);
126}
127
128void AdvCommEditImpl::setHtmlDta(const QString &str)
129{
130 if (str.isEmpty())
131 return;
132 PWM_ASSERT(HtmlGen::isHtml(str));
133 HtmlParse htmlParse;
134 if (!htmlParse.parseHtmlComment(str, dta)) {
135 printWarn("AdvCommEditImpl::setHtmlDta(): parseHtmlComment() failed!");
136 return;
137 }
138 titleLineEdit->setText(dta->getTitle());
139 const vector<HtmlComment::SubTable> *subTbls = dta->getSubTableList();
140 vector<HtmlComment::SubTable>::const_iterator i = subTbls->begin(),
141 end = subTbls->end();
142 while (i != end) {
143 entryListBox->insertItem(i->getTitle());
144 ++i;
145 }
146 updatePreview();
147}
148
149#include "advcommeditimpl.moc"
diff --git a/pwmanager/pwmanager/advcommeditimpl.h b/pwmanager/pwmanager/advcommeditimpl.h
new file mode 100644
index 0000000..67f3ac6
--- a/dev/null
+++ b/pwmanager/pwmanager/advcommeditimpl.h
@@ -0,0 +1,79 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef ADVCOMMEDITIMPL_H
21#define ADVCOMMEDITIMPL_H
22
23#include <qlistbox.h>
24
25#include "advcommedit.h"
26
27class HtmlComment;
28class KHTMLPart;
29
30class AdvCommEditImpl : public advCommEdit
31{
32 Q_OBJECT
33public:
34 AdvCommEditImpl(QWidget* parent = 0,
35 const char* name = 0,
36 WFlags fl = 0);
37 ~AdvCommEditImpl();
38
39 /** returns the HTML data for the comment */
40 QString getHtmlDta();
41 /** sets the HTML data, parses and displays it */
42 void setHtmlDta(const QString &str);
43
44public slots:
45 /** sync preview with dta */
46 void updatePreview();
47 /** ok button pressed */
48 void okButton_slot();
49 /** cancel button pressed */
50 void cancelButton_slot();
51 /** add subtbl button pressed */
52 void addSubtblButton_slot();
53 /** edit button pressed */
54 void editButton_slot();
55 /** delete button pressed */
56 void delButton_slot();
57
58protected slots:
59
60protected:
61 /** read the title from the line-edit and update dta */
62 void updateTitle();
63 /** returns the index of the currently selected entry */
64 int curIndex()
65#ifndef PWM_EMBEDDED
66 { return entryListBox->index(entryListBox->selectedItem()); }
67#else
68 { return entryListBox->currentItem(); }
69#endif
70protected:
71 /** current internal representation structure
72 * of the comment
73 */
74 HtmlComment *dta;
75 /** preview browser */
76 KHTMLPart *preview;
77};
78
79#endif
diff --git a/pwmanager/pwmanager/base64.cpp b/pwmanager/pwmanager/base64.cpp
new file mode 100644
index 0000000..0360678
--- a/dev/null
+++ b/pwmanager/pwmanager/base64.cpp
@@ -0,0 +1,207 @@
1/*******************************************************************
2 * base64.h
3 * © Copyright 1995 John Halleck
4 * All Rights Reserved
5 *
6 * ported to c++ by Michael Buesch <mbuesch@freenet.de>
7 *
8 * --ABSTRACT-- base64.h
9 * Do the base 64 encoding as used by PEM and MIME.
10 *
11 * --KEYWORDS-- base64.h
12 *
13 * --CONTENTS-- base64.h
14 * Date, Department, Author
15 * 23nov1994, John Halleck
16 * Revision history
17 * For each revision: Date, change summary, authorizing document,
18 * change department, section, author
19 * 23nov1994, Initial Creation, John Halleck
20 * 8apr1995, split library into hex and base64 libraries, John Halleck
21 * Unit purpose
22 * (What does this do?)
23 * [Nothing]
24 * External Units accessed
25 * Name, purpose, access summary
26 * [None]
27 * Exceptions propagated by this unit
28 * [None]
29 * Machine-dependencies
30 * Access type, purpose, and justification
31 * [None]
32 * Compiler-dependencies
33 * [None]
34 *********************************************************************/
35
36/***************************************************************************
37 * *
38 * This program is free software; you can redistribute it and/or modify *
39 * it under the terms of the GNU General Public License version 2 *
40 * as published by the Free Software Foundation. *
41 * *
42 ***************************************************************************/
43
44#include "base64.h"
45#include "globalstuff.h"
46
47
48static const char prtcode[] =
49 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
50
51
52string Base64::encode(const string &data)
53{
54 initCtx();
55 string::const_iterator i = data.begin(),
56 end = data.end();
57 while (i != end) {
58 encodeChar(*i);
59 ++i;
60 }
61 encFinalizeCtx();
62 return ctx.buf;
63}
64
65string Base64::decode(const string &data)
66{
67 initCtx();
68 string::const_iterator i = data.begin(),
69 end = data.end();
70 while (i != end) {
71 decodeChar(*i);
72 ++i;
73 }
74 decFinalizeCtx();
75 return ctx.buf;
76}
77
78void Base64::initCtx()
79{
80 ctx.temp = 0;
81 ctx.bytes = 0;
82 ctx.buf = "";
83}
84
85void Base64::encFinalizeCtx()
86{
87 /* flush the output side of things, by putting out the last characters */
88 switch (ctx.bytes) {
89 case 0:
90 /* nothing in progress */
91 break;
92 case 2:
93 ctx.buf.append(1, static_cast<char>(prtcode[ctx.temp << 2 & 0x3F]));
94 ctx.buf.append(1, '=');
95 break;
96 case 1:
97 ctx.buf.append(1, static_cast<char>(prtcode[ctx.temp << 4 & 0x3F]));
98 ctx.buf.append(1, '=');
99 ctx.buf.append(1, '=');
100 }
101}
102
103void Base64::decFinalizeCtx()
104{
105 if (ctx.bytes == 1)
106 decodeChar('A');
107}
108
109void Base64::encodeChar(unsigned char c)
110{
111 int result;
112
113 /* Add this 8 bit byte to what we have...*/
114 result = ctx.temp;
115 result = (result << 8) | (c & 0xFF);
116
117 /* And output all 6 bit base 64 characters now formed */
118 switch (ctx.bytes++) {
119 case 0:
120 ctx.buf.append(1, static_cast<char>(prtcode[result >> 2 & 0x3F]));
121 result &= 0x3;
122 break;
123 case 1:
124 ctx.buf.append(1, static_cast<char>(prtcode[result >> 4 & 0x3F]));
125 result &= 0xF;
126 break;
127 case 2:
128 ctx.buf.append(1, static_cast<char>(prtcode[result >> 6 & 0x3F]));
129 ctx.buf.append(1, static_cast<char>(prtcode[result & 0x3F]));
130 result = 0;
131 ctx.bytes = 0;
132 }
133 ctx.temp = result;
134}
135
136void Base64::decodeChar(char c)
137{
138 int result;
139
140 result = ctx.temp;
141
142 /* Convert Base64 character to its 6 bit nibble */
143 if (c == '/') {
144 result = (result << 6) | 63;
145 } else if (c == '+') {
146 result = (result << 6) | 62;
147 } else if (c >= 'A' && c <= 'Z') {
148 result = (result << 6) | (c - 'A');
149 } else if (c >= 'a' && c <= 'z') {
150 result = (result << 6) | (c - 'a' + 26);
151 } else if (c >= '0' && c <= '9') {
152 result = (result << 6) | (c - '0' + 52);
153 } else if (c == '=') {
154 ctx.bytes = 0;
155 ctx.temp = 0;
156 }
157
158 /* Add that nibble to the output, outputting any complete 8 bit bytes formed */
159 switch (ctx.bytes++) {
160 case 0:
161 break;
162 case 1:
163 ctx.buf.append(1, static_cast<char>(result >> 4 & 0xFF));
164 result &= 0xF;
165 break;
166 case 2:
167 ctx.buf.append(1, static_cast<char>(result >> 2 & 0xFF));
168 result &= 0x3;
169 break;
170 case 3:
171 ctx.buf.append(1, static_cast<char>(result & 0xFF));
172 ctx.bytes = 0;
173 result = 0;
174 }
175 if (c == '=') {
176 ctx.bytes = 0;
177 result = 0;
178 }
179
180 ctx.temp = result;
181}
182
183bool Base64::selfTest()
184{
185 string plain1("Base64");
186 string plain2("abcdefghijklmnopqrstuvwxyz");
187 string enc1("QmFzZTY0");
188 string enc2("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXo=");
189 string buf;
190
191 Base64 base64;
192
193 buf = base64.encode(plain1);
194 if (unlikely(buf != enc1))
195 return false;
196 buf = base64.decode(buf);
197 if (unlikely(buf != plain1))
198 return false;
199
200 buf = base64.encode(plain2);
201 if (unlikely(buf != enc2))
202 return false;
203 buf = base64.decode(buf);
204 if (unlikely(buf != plain2))
205 return false;
206 return true;
207}
diff --git a/pwmanager/pwmanager/base64.h b/pwmanager/pwmanager/base64.h
new file mode 100644
index 0000000..f497b9e
--- a/dev/null
+++ b/pwmanager/pwmanager/base64.h
@@ -0,0 +1,97 @@
1/*******************************************************************
2 * base64.h
3 * © Copyright 1995 John Halleck
4 * All Rights Reserved
5 *
6 * ported to c++ by Michael Buesch <mbuesch@freenet.de>
7 *
8 * --ABSTRACT-- base64.h
9 * Do the base 64 encoding as used by PEM and MIME.
10 *
11 * --KEYWORDS-- base64.h
12 *
13 * --CONTENTS-- base64.h
14 * Date, Department, Author
15 * 23nov1994, John Halleck
16 * Revision history
17 * For each revision: Date, change summary, authorizing document,
18 * change department, section, author
19 * 23nov1994, Initial Creation, John Halleck
20 * 8apr1995, split library into hex and base64 libraries, John Halleck
21 * Unit purpose
22 * (What does this do?)
23 * [Nothing]
24 * External Units accessed
25 * Name, purpose, access summary
26 * [None]
27 * Exceptions propagated by this unit
28 * [None]
29 * Machine-dependencies
30 * Access type, purpose, and justification
31 * [None]
32 * Compiler-dependencies
33 * [None]
34 *********************************************************************/
35
36/***************************************************************************
37 * *
38 * This program is free software; you can redistribute it and/or modify *
39 * it under the terms of the GNU General Public License version 2 *
40 * as published by the Free Software Foundation. *
41 * *
42 ***************************************************************************/
43
44/***************************************************************************
45 * copyright (C) 2004 by Ulf Schenk
46 * This file is originaly based on version 1.0.1 of pwmanager
47 * and was modified to run on embedded devices that run microkde
48 *
49 * $Id$
50 **************************************************************************/
51
52
53#ifndef __BASE64_H
54#define __BASE64_H
55
56#include <string>
57
58using std::string;
59
60class Base64
61{
62protected:
63 struct Base64Ctx
64 {
65 int temp;// Working value for input
66 int bytes;// which input byte we are working on
67 string buf;// Data buffer
68 };
69
70public:
71 Base64() {}
72 /** run algorithm self test */
73 static bool selfTest();
74
75 /** encode "data" */
76 string encode(const string &data);
77 /** decode "data" */
78 string decode(const string &data);
79
80protected:
81 /** initialize the context */
82 void initCtx();
83 /** finalize the context */
84 void encFinalizeCtx();
85 /** finalize the context */
86 void decFinalizeCtx();
87 /** encode a character */
88 void encodeChar(unsigned char c);
89 /** decode a character */
90 void decodeChar(char c);
91
92protected:
93 /** Base64 context */
94 Base64Ctx ctx;
95};
96
97#endif // __BASE64_H
diff --git a/pwmanager/pwmanager/binentrygen.cpp b/pwmanager/pwmanager/binentrygen.cpp
new file mode 100644
index 0000000..7d5ae45
--- a/dev/null
+++ b/pwmanager/pwmanager/binentrygen.cpp
@@ -0,0 +1,71 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20
21#include "binentrygen.h"
22#include "base64.h"
23#include "pwmexception.h"
24
25
26void BinEntryGen::encode(const QByteArray &data,
27 PwMDataItem *ret,
28 DataType type)
29{
30 ret->clear();
31 ret->name = tostr(static_cast<int>(type));
32 ret->binary = true;
33 if (data.size() == 0)
34 return;
35 Base64 b64;
36 string d(data.data(), data.size());
37 ret->pw = b64.encode(d);
38}
39
40void BinEntryGen::decode(const PwMDataItem &data,
41 QByteArray *ret,
42 DataType *type)
43{
44 BUG_ON(!data.binary);
45 int t = strtol(data.name.c_str(), 0, 10);
46 *type = static_cast<DataType>(t);
47 switch (*type) {
48 case None:
49 case KWalletMap:
50 case KWalletStream:
51 break;
52 default:
53 *type = None;
54 }
55 if (data.pw == "") {
56 ret->fill(0);
57 ret->resize(0);
58 return;
59 }
60 Base64 b64;
61 string d(b64.decode(data.pw));
62 ret->duplicate(d.c_str(), d.length());
63}
64
65BinEntryGen::DataType BinEntryGen::binType(const PwMDataItem &data)
66{
67 if (!data.binary)
68 return None;
69 int type = strtol(data.name.c_str(), 0, 10);
70 return (static_cast<DataType>(type));
71}
diff --git a/pwmanager/pwmanager/binentrygen.h b/pwmanager/pwmanager/binentrygen.h
new file mode 100644
index 0000000..a58cd42
--- a/dev/null
+++ b/pwmanager/pwmanager/binentrygen.h
@@ -0,0 +1,65 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef __BINENTRYGEN_H
21#define __BINENTRYGEN_H
22
23#include "pwmdoc.h"
24
25#include <qcstring.h>
26
27
28/** Binary entry generator.
29 * This generator generates a normal struct PwMDataItem
30 * from binary data (using base64 encoding).
31 * This mechanism is used to support the binary interface functions
32 * of the KWallet emulation, for example.
33 *
34 * The format of the encoded binary data as a PwMDataItem is as follows:
35 *
36 * PwMDataItem::desc contains the normal description string for
37 * this entry. Nothing surprising.
38 * PwMDataItem::name contains the "DataType" number in ascii format.
39 * PwMDataItem::pw contains the base64 encoded data stream.
40 * PwMDataItem::binary is always true for binary entries.
41 * All other PwMDataItems are currently unused by BinEntryGen.
42 */
43class BinEntryGen
44{
45public:
46 enum DataType
47 {
48 None = 0,
49 KWalletMap,
50 KWalletStream
51 };
52
53public:
54 BinEntryGen() { }
55
56 /** Encode the binary "data" and return it in "ret" */
57 void encode(const QByteArray &data, PwMDataItem *ret, DataType type);
58 /** Decode the "data" and return it as binary "ret" */
59 void decode(const PwMDataItem &data, QByteArray *ret, DataType *type);
60
61 /** Return the data type for this binary data item */
62 DataType binType(const PwMDataItem &data);
63};
64
65#endif // __BINENTRYGEN_H
diff --git a/pwmanager/pwmanager/blowfish.cpp b/pwmanager/pwmanager/blowfish.cpp
new file mode 100644
index 0000000..2ca58ce
--- a/dev/null
+++ b/pwmanager/pwmanager/blowfish.cpp
@@ -0,0 +1,579 @@
1/* 2003.05.02: Derived from libgcrypt-1.1.12 by Michael Buesch */
2
3/* blowfish.c - Blowfish encryption
4 *Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc.
5 *
6 * This file is part of Libgcrypt.
7 *
8 * Libgcrypt is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser general Public License as
10 * published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
12 *
13 * Libgcrypt is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 *
22 * For a description of the algorithm, see:
23 * Bruce Schneier: Applied Cryptography. John Wiley & Sons, 1996.
24 * ISBN 0-471-11709-9. Pages 336 ff.
25 */
26
27/* Test values:
28 * key "abcdefghijklmnopqrstuvwxyz";
29 * plain "BLOWFISH"
30 * cipher 32 4E D0 FE F4 13 A2 03
31 *
32 */
33
34/***************************************************************************
35 * copyright (C) 2004 by Ulf Schenk
36 * This file is originaly based on version 1.0.1 of pwmanager
37 * and was modified to run on embedded devices that run microkde
38 *
39 * $Id$
40 **************************************************************************/
41
42
43#include <string.h>
44#include <stdlib.h>
45
46#include "blowfish.h"
47#include "globalstuff.h"
48
49
50/* precomputed S boxes */
51static const uint32_t ks0[256] = {
52 0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7, 0xB8E1AFED, 0x6A267E96,
53 0xBA7C9045, 0xF12C7F99, 0x24A19947, 0xB3916CF7, 0x0801F2E2, 0x858EFC16,
54 0x636920D8, 0x71574E69, 0xA458FEA3, 0xF4933D7E, 0x0D95748F, 0x728EB658,
55 0x718BCD58, 0x82154AEE, 0x7B54A41D, 0xC25A59B5, 0x9C30D539, 0x2AF26013,
56 0xC5D1B023, 0x286085F0, 0xCA417918, 0xB8DB38EF, 0x8E79DCB0, 0x603A180E,
57 0x6C9E0E8B, 0xB01E8A3E, 0xD71577C1, 0xBD314B27, 0x78AF2FDA, 0x55605C60,
58 0xE65525F3, 0xAA55AB94, 0x57489862, 0x63E81440, 0x55CA396A, 0x2AAB10B6,
59 0xB4CC5C34, 0x1141E8CE, 0xA15486AF, 0x7C72E993, 0xB3EE1411, 0x636FBC2A,
60 0x2BA9C55D, 0x741831F6, 0xCE5C3E16, 0x9B87931E, 0xAFD6BA33, 0x6C24CF5C,
61 0x7A325381, 0x28958677, 0x3B8F4898, 0x6B4BB9AF, 0xC4BFE81B, 0x66282193,
62 0x61D809CC, 0xFB21A991, 0x487CAC60, 0x5DEC8032, 0xEF845D5D, 0xE98575B1,
63 0xDC262302, 0xEB651B88, 0x23893E81, 0xD396ACC5, 0x0F6D6FF3, 0x83F44239,
64 0x2E0B4482, 0xA4842004, 0x69C8F04A, 0x9E1F9B5E, 0x21C66842, 0xF6E96C9A,
65 0x670C9C61, 0xABD388F0, 0x6A51A0D2, 0xD8542F68, 0x960FA728, 0xAB5133A3,
66 0x6EEF0B6C, 0x137A3BE4, 0xBA3BF050, 0x7EFB2A98, 0xA1F1651D, 0x39AF0176,
67 0x66CA593E, 0x82430E88, 0x8CEE8619, 0x456F9FB4, 0x7D84A5C3, 0x3B8B5EBE,
68 0xE06F75D8, 0x85C12073, 0x401A449F, 0x56C16AA6, 0x4ED3AA62, 0x363F7706,
69 0x1BFEDF72, 0x429B023D, 0x37D0D724, 0xD00A1248, 0xDB0FEAD3, 0x49F1C09B,
70 0x075372C9, 0x80991B7B, 0x25D479D8, 0xF6E8DEF7, 0xE3FE501A, 0xB6794C3B,
71 0x976CE0BD, 0x04C006BA, 0xC1A94FB6, 0x409F60C4, 0x5E5C9EC2, 0x196A2463,
72 0x68FB6FAF, 0x3E6C53B5, 0x1339B2EB, 0x3B52EC6F, 0x6DFC511F, 0x9B30952C,
73 0xCC814544, 0xAF5EBD09, 0xBEE3D004, 0xDE334AFD, 0x660F2807, 0x192E4BB3,
74 0xC0CBA857, 0x45C8740F, 0xD20B5F39, 0xB9D3FBDB, 0x5579C0BD, 0x1A60320A,
75 0xD6A100C6, 0x402C7279, 0x679F25FE, 0xFB1FA3CC, 0x8EA5E9F8, 0xDB3222F8,
76 0x3C7516DF, 0xFD616B15, 0x2F501EC8, 0xAD0552AB, 0x323DB5FA, 0xFD238760,
77 0x53317B48, 0x3E00DF82, 0x9E5C57BB, 0xCA6F8CA0, 0x1A87562E, 0xDF1769DB,
78 0xD542A8F6, 0x287EFFC3, 0xAC6732C6, 0x8C4F5573, 0x695B27B0, 0xBBCA58C8,
79 0xE1FFA35D, 0xB8F011A0, 0x10FA3D98, 0xFD2183B8, 0x4AFCB56C, 0x2DD1D35B,
80 0x9A53E479, 0xB6F84565, 0xD28E49BC, 0x4BFB9790, 0xE1DDF2DA, 0xA4CB7E33,
81 0x62FB1341, 0xCEE4C6E8, 0xEF20CADA, 0x36774C01, 0xD07E9EFE, 0x2BF11FB4,
82 0x95DBDA4D, 0xAE909198, 0xEAAD8E71, 0x6B93D5A0, 0xD08ED1D0, 0xAFC725E0,
83 0x8E3C5B2F, 0x8E7594B7, 0x8FF6E2FB, 0xF2122B64, 0x8888B812, 0x900DF01C,
84 0x4FAD5EA0, 0x688FC31C, 0xD1CFF191, 0xB3A8C1AD, 0x2F2F2218, 0xBE0E1777,
85 0xEA752DFE, 0x8B021FA1, 0xE5A0CC0F, 0xB56F74E8, 0x18ACF3D6, 0xCE89E299,
86 0xB4A84FE0, 0xFD13E0B7, 0x7CC43B81, 0xD2ADA8D9, 0x165FA266, 0x80957705,
87 0x93CC7314, 0x211A1477, 0xE6AD2065, 0x77B5FA86, 0xC75442F5, 0xFB9D35CF,
88 0xEBCDAF0C, 0x7B3E89A0, 0xD6411BD3, 0xAE1E7E49, 0x00250E2D, 0x2071B35E,
89 0x226800BB, 0x57B8E0AF, 0x2464369B, 0xF009B91E, 0x5563911D, 0x59DFA6AA,
90 0x78C14389, 0xD95A537F, 0x207D5BA2, 0x02E5B9C5, 0x83260376, 0x6295CFA9,
91 0x11C81968, 0x4E734A41, 0xB3472DCA, 0x7B14A94A, 0x1B510052, 0x9A532915,
92 0xD60F573F, 0xBC9BC6E4, 0x2B60A476, 0x81E67400, 0x08BA6FB5, 0x571BE91F,
93 0xF296EC6B, 0x2A0DD915, 0xB6636521, 0xE7B9F9B6, 0xFF34052E, 0xC5855664,
94 0x53B02D5D, 0xA99F8FA1, 0x08BA4799, 0x6E85076A
95};
96
97static const uint32_t ks1[256] = {
98 0x4B7A70E9, 0xB5B32944, 0xDB75092E, 0xC4192623, 0xAD6EA6B0, 0x49A7DF7D,
99 0x9CEE60B8, 0x8FEDB266, 0xECAA8C71, 0x699A17FF, 0x5664526C, 0xC2B19EE1,
100 0x193602A5, 0x75094C29, 0xA0591340, 0xE4183A3E, 0x3F54989A, 0x5B429D65,
101 0x6B8FE4D6, 0x99F73FD6, 0xA1D29C07, 0xEFE830F5, 0x4D2D38E6, 0xF0255DC1,
102 0x4CDD2086, 0x8470EB26, 0x6382E9C6, 0x021ECC5E, 0x09686B3F, 0x3EBAEFC9,
103 0x3C971814, 0x6B6A70A1, 0x687F3584, 0x52A0E286, 0xB79C5305, 0xAA500737,
104 0x3E07841C, 0x7FDEAE5C, 0x8E7D44EC, 0x5716F2B8, 0xB03ADA37, 0xF0500C0D,
105 0xF01C1F04, 0x0200B3FF, 0xAE0CF51A, 0x3CB574B2, 0x25837A58, 0xDC0921BD,
106 0xD19113F9, 0x7CA92FF6, 0x94324773, 0x22F54701, 0x3AE5E581, 0x37C2DADC,
107 0xC8B57634, 0x9AF3DDA7, 0xA9446146, 0x0FD0030E, 0xECC8C73E, 0xA4751E41,
108 0xE238CD99, 0x3BEA0E2F, 0x3280BBA1, 0x183EB331, 0x4E548B38, 0x4F6DB908,
109 0x6F420D03, 0xF60A04BF, 0x2CB81290, 0x24977C79, 0x5679B072, 0xBCAF89AF,
110 0xDE9A771F, 0xD9930810, 0xB38BAE12, 0xDCCF3F2E, 0x5512721F, 0x2E6B7124,
111 0x501ADDE6, 0x9F84CD87, 0x7A584718, 0x7408DA17, 0xBC9F9ABC, 0xE94B7D8C,
112 0xEC7AEC3A, 0xDB851DFA, 0x63094366, 0xC464C3D2, 0xEF1C1847, 0x3215D908,
113 0xDD433B37, 0x24C2BA16, 0x12A14D43, 0x2A65C451, 0x50940002, 0x133AE4DD,
114 0x71DFF89E, 0x10314E55, 0x81AC77D6, 0x5F11199B, 0x043556F1, 0xD7A3C76B,
115 0x3C11183B, 0x5924A509, 0xF28FE6ED, 0x97F1FBFA, 0x9EBABF2C, 0x1E153C6E,
116 0x86E34570, 0xEAE96FB1, 0x860E5E0A, 0x5A3E2AB3, 0x771FE71C, 0x4E3D06FA,
117 0x2965DCB9, 0x99E71D0F, 0x803E89D6, 0x5266C825, 0x2E4CC978, 0x9C10B36A,
118 0xC6150EBA, 0x94E2EA78, 0xA5FC3C53, 0x1E0A2DF4, 0xF2F74EA7, 0x361D2B3D,
119 0x1939260F, 0x19C27960, 0x5223A708, 0xF71312B6, 0xEBADFE6E, 0xEAC31F66,
120 0xE3BC4595, 0xA67BC883, 0xB17F37D1, 0x018CFF28, 0xC332DDEF, 0xBE6C5AA5,
121 0x65582185, 0x68AB9802, 0xEECEA50F, 0xDB2F953B, 0x2AEF7DAD, 0x5B6E2F84,
122 0x1521B628, 0x29076170, 0xECDD4775, 0x619F1510, 0x13CCA830, 0xEB61BD96,
123 0x0334FE1E, 0xAA0363CF, 0xB5735C90, 0x4C70A239, 0xD59E9E0B, 0xCBAADE14,
124 0xEECC86BC, 0x60622CA7, 0x9CAB5CAB, 0xB2F3846E, 0x648B1EAF, 0x19BDF0CA,
125 0xA02369B9, 0x655ABB50, 0x40685A32, 0x3C2AB4B3, 0x319EE9D5, 0xC021B8F7,
126 0x9B540B19, 0x875FA099, 0x95F7997E, 0x623D7DA8, 0xF837889A, 0x97E32D77,
127 0x11ED935F, 0x16681281, 0x0E358829, 0xC7E61FD6, 0x96DEDFA1, 0x7858BA99,
128 0x57F584A5, 0x1B227263, 0x9B83C3FF, 0x1AC24696, 0xCDB30AEB, 0x532E3054,
129 0x8FD948E4, 0x6DBC3128, 0x58EBF2EF, 0x34C6FFEA, 0xFE28ED61, 0xEE7C3C73,
130 0x5D4A14D9, 0xE864B7E3, 0x42105D14, 0x203E13E0, 0x45EEE2B6, 0xA3AAABEA,
131 0xDB6C4F15, 0xFACB4FD0, 0xC742F442, 0xEF6ABBB5, 0x654F3B1D, 0x41CD2105,
132 0xD81E799E, 0x86854DC7, 0xE44B476A, 0x3D816250, 0xCF62A1F2, 0x5B8D2646,
133 0xFC8883A0, 0xC1C7B6A3, 0x7F1524C3, 0x69CB7492, 0x47848A0B, 0x5692B285,
134 0x095BBF00, 0xAD19489D, 0x1462B174, 0x23820E00, 0x58428D2A, 0x0C55F5EA,
135 0x1DADF43E, 0x233F7061, 0x3372F092, 0x8D937E41, 0xD65FECF1, 0x6C223BDB,
136 0x7CDE3759, 0xCBEE7460, 0x4085F2A7, 0xCE77326E, 0xA6078084, 0x19F8509E,
137 0xE8EFD855, 0x61D99735, 0xA969A7AA, 0xC50C06C2, 0x5A04ABFC, 0x800BCADC,
138 0x9E447A2E, 0xC3453484, 0xFDD56705, 0x0E1E9EC9, 0xDB73DBD3, 0x105588CD,
139 0x675FDA79, 0xE3674340, 0xC5C43465, 0x713E38D8, 0x3D28F89E, 0xF16DFF20,
140 0x153E21E7, 0x8FB03D4A, 0xE6E39F2B, 0xDB83ADF7
141};
142
143static const uint32_t ks2[256] = {
144 0xE93D5A68, 0x948140F7, 0xF64C261C, 0x94692934, 0x411520F7, 0x7602D4F7,
145 0xBCF46B2E, 0xD4A20068, 0xD4082471, 0x3320F46A, 0x43B7D4B7, 0x500061AF,
146 0x1E39F62E, 0x97244546, 0x14214F74, 0xBF8B8840, 0x4D95FC1D, 0x96B591AF,
147 0x70F4DDD3, 0x66A02F45, 0xBFBC09EC, 0x03BD9785, 0x7FAC6DD0, 0x31CB8504,
148 0x96EB27B3, 0x55FD3941, 0xDA2547E6, 0xABCA0A9A, 0x28507825, 0x530429F4,
149 0x0A2C86DA, 0xE9B66DFB, 0x68DC1462, 0xD7486900, 0x680EC0A4, 0x27A18DEE,
150 0x4F3FFEA2, 0xE887AD8C, 0xB58CE006, 0x7AF4D6B6, 0xAACE1E7C, 0xD3375FEC,
151 0xCE78A399, 0x406B2A42, 0x20FE9E35, 0xD9F385B9, 0xEE39D7AB, 0x3B124E8B,
152 0x1DC9FAF7, 0x4B6D1856, 0x26A36631, 0xEAE397B2, 0x3A6EFA74, 0xDD5B4332,
153 0x6841E7F7, 0xCA7820FB, 0xFB0AF54E, 0xD8FEB397, 0x454056AC, 0xBA489527,
154 0x55533A3A, 0x20838D87, 0xFE6BA9B7, 0xD096954B, 0x55A867BC, 0xA1159A58,
155 0xCCA92963, 0x99E1DB33, 0xA62A4A56, 0x3F3125F9, 0x5EF47E1C, 0x9029317C,
156 0xFDF8E802, 0x04272F70, 0x80BB155C, 0x05282CE3, 0x95C11548, 0xE4C66D22,
157 0x48C1133F, 0xC70F86DC, 0x07F9C9EE, 0x41041F0F, 0x404779A4, 0x5D886E17,
158 0x325F51EB, 0xD59BC0D1, 0xF2BCC18F, 0x41113564, 0x257B7834, 0x602A9C60,
159 0xDFF8E8A3, 0x1F636C1B, 0x0E12B4C2, 0x02E1329E, 0xAF664FD1, 0xCAD18115,
160 0x6B2395E0, 0x333E92E1, 0x3B240B62, 0xEEBEB922, 0x85B2A20E, 0xE6BA0D99,
161 0xDE720C8C, 0x2DA2F728, 0xD0127845, 0x95B794FD, 0x647D0862, 0xE7CCF5F0,
162 0x5449A36F, 0x877D48FA, 0xC39DFD27, 0xF33E8D1E, 0x0A476341, 0x992EFF74,
163 0x3A6F6EAB, 0xF4F8FD37, 0xA812DC60, 0xA1EBDDF8, 0x991BE14C, 0xDB6E6B0D,
164 0xC67B5510, 0x6D672C37, 0x2765D43B, 0xDCD0E804, 0xF1290DC7, 0xCC00FFA3,
165 0xB5390F92, 0x690FED0B, 0x667B9FFB, 0xCEDB7D9C, 0xA091CF0B, 0xD9155EA3,
166 0xBB132F88, 0x515BAD24, 0x7B9479BF, 0x763BD6EB, 0x37392EB3, 0xCC115979,
167 0x8026E297, 0xF42E312D, 0x6842ADA7, 0xC66A2B3B, 0x12754CCC, 0x782EF11C,
168 0x6A124237, 0xB79251E7, 0x06A1BBE6, 0x4BFB6350, 0x1A6B1018, 0x11CAEDFA,
169 0x3D25BDD8, 0xE2E1C3C9, 0x44421659, 0x0A121386, 0xD90CEC6E, 0xD5ABEA2A,
170 0x64AF674E, 0xDA86A85F, 0xBEBFE988, 0x64E4C3FE, 0x9DBC8057, 0xF0F7C086,
171 0x60787BF8, 0x6003604D, 0xD1FD8346, 0xF6381FB0, 0x7745AE04, 0xD736FCCC,
172 0x83426B33, 0xF01EAB71, 0xB0804187, 0x3C005E5F, 0x77A057BE, 0xBDE8AE24,
173 0x55464299, 0xBF582E61, 0x4E58F48F, 0xF2DDFDA2, 0xF474EF38, 0x8789BDC2,
174 0x5366F9C3, 0xC8B38E74, 0xB475F255, 0x46FCD9B9, 0x7AEB2661, 0x8B1DDF84,
175 0x846A0E79, 0x915F95E2, 0x466E598E, 0x20B45770, 0x8CD55591, 0xC902DE4C,
176 0xB90BACE1, 0xBB8205D0, 0x11A86248, 0x7574A99E, 0xB77F19B6, 0xE0A9DC09,
177 0x662D09A1, 0xC4324633, 0xE85A1F02, 0x09F0BE8C, 0x4A99A025, 0x1D6EFE10,
178 0x1AB93D1D, 0x0BA5A4DF, 0xA186F20F, 0x2868F169, 0xDCB7DA83, 0x573906FE,
179 0xA1E2CE9B, 0x4FCD7F52, 0x50115E01, 0xA70683FA, 0xA002B5C4, 0x0DE6D027,
180 0x9AF88C27, 0x773F8641, 0xC3604C06, 0x61A806B5, 0xF0177A28, 0xC0F586E0,
181 0x006058AA, 0x30DC7D62, 0x11E69ED7, 0x2338EA63, 0x53C2DD94, 0xC2C21634,
182 0xBBCBEE56, 0x90BCB6DE, 0xEBFC7DA1, 0xCE591D76, 0x6F05E409, 0x4B7C0188,
183 0x39720A3D, 0x7C927C24, 0x86E3725F, 0x724D9DB9, 0x1AC15BB4, 0xD39EB8FC,
184 0xED545578, 0x08FCA5B5, 0xD83D7CD3, 0x4DAD0FC4, 0x1E50EF5E, 0xB161E6F8,
185 0xA28514D9, 0x6C51133C, 0x6FD5C7E7, 0x56E14EC4, 0x362ABFCE, 0xDDC6C837,
186 0xD79A3234, 0x92638212, 0x670EFA8E, 0x406000E0
187};
188
189static const uint32_t ks3[256] = {
190 0x3A39CE37, 0xD3FAF5CF, 0xABC27737, 0x5AC52D1B, 0x5CB0679E, 0x4FA33742,
191 0xD3822740, 0x99BC9BBE, 0xD5118E9D, 0xBF0F7315, 0xD62D1C7E, 0xC700C47B,
192 0xB78C1B6B, 0x21A19045, 0xB26EB1BE, 0x6A366EB4, 0x5748AB2F, 0xBC946E79,
193 0xC6A376D2, 0x6549C2C8, 0x530FF8EE, 0x468DDE7D, 0xD5730A1D, 0x4CD04DC6,
194 0x2939BBDB, 0xA9BA4650, 0xAC9526E8, 0xBE5EE304, 0xA1FAD5F0, 0x6A2D519A,
195 0x63EF8CE2, 0x9A86EE22, 0xC089C2B8, 0x43242EF6, 0xA51E03AA, 0x9CF2D0A4,
196 0x83C061BA, 0x9BE96A4D, 0x8FE51550, 0xBA645BD6, 0x2826A2F9, 0xA73A3AE1,
197 0x4BA99586, 0xEF5562E9, 0xC72FEFD3, 0xF752F7DA, 0x3F046F69, 0x77FA0A59,
198 0x80E4A915, 0x87B08601, 0x9B09E6AD, 0x3B3EE593, 0xE990FD5A, 0x9E34D797,
199 0x2CF0B7D9, 0x022B8B51, 0x96D5AC3A, 0x017DA67D, 0xD1CF3ED6, 0x7C7D2D28,
200 0x1F9F25CF, 0xADF2B89B, 0x5AD6B472, 0x5A88F54C, 0xE029AC71, 0xE019A5E6,
201 0x47B0ACFD, 0xED93FA9B, 0xE8D3C48D, 0x283B57CC, 0xF8D56629, 0x79132E28,
202 0x785F0191, 0xED756055, 0xF7960E44, 0xE3D35E8C, 0x15056DD4, 0x88F46DBA,
203 0x03A16125, 0x0564F0BD, 0xC3EB9E15, 0x3C9057A2, 0x97271AEC, 0xA93A072A,
204 0x1B3F6D9B, 0x1E6321F5, 0xF59C66FB, 0x26DCF319, 0x7533D928, 0xB155FDF5,
205 0x03563482, 0x8ABA3CBB, 0x28517711, 0xC20AD9F8, 0xABCC5167, 0xCCAD925F,
206 0x4DE81751, 0x3830DC8E, 0x379D5862, 0x9320F991, 0xEA7A90C2, 0xFB3E7BCE,
207 0x5121CE64, 0x774FBE32, 0xA8B6E37E, 0xC3293D46, 0x48DE5369, 0x6413E680,
208 0xA2AE0810, 0xDD6DB224, 0x69852DFD, 0x09072166, 0xB39A460A, 0x6445C0DD,
209 0x586CDECF, 0x1C20C8AE, 0x5BBEF7DD, 0x1B588D40, 0xCCD2017F, 0x6BB4E3BB,
210 0xDDA26A7E, 0x3A59FF45, 0x3E350A44, 0xBCB4CDD5, 0x72EACEA8, 0xFA6484BB,
211 0x8D6612AE, 0xBF3C6F47, 0xD29BE463, 0x542F5D9E, 0xAEC2771B, 0xF64E6370,
212 0x740E0D8D, 0xE75B1357, 0xF8721671, 0xAF537D5D, 0x4040CB08, 0x4EB4E2CC,
213 0x34D2466A, 0x0115AF84, 0xE1B00428, 0x95983A1D, 0x06B89FB4, 0xCE6EA048,
214 0x6F3F3B82, 0x3520AB82, 0x011A1D4B, 0x277227F8, 0x611560B1, 0xE7933FDC,
215 0xBB3A792B, 0x344525BD, 0xA08839E1, 0x51CE794B, 0x2F32C9B7, 0xA01FBAC9,
216 0xE01CC87E, 0xBCC7D1F6, 0xCF0111C3, 0xA1E8AAC7, 0x1A908749, 0xD44FBD9A,
217 0xD0DADECB, 0xD50ADA38, 0x0339C32A, 0xC6913667, 0x8DF9317C, 0xE0B12B4F,
218 0xF79E59B7, 0x43F5BB3A, 0xF2D519FF, 0x27D9459C, 0xBF97222C, 0x15E6FC2A,
219 0x0F91FC71, 0x9B941525, 0xFAE59361, 0xCEB69CEB, 0xC2A86459, 0x12BAA8D1,
220 0xB6C1075E, 0xE3056A0C, 0x10D25065, 0xCB03A442, 0xE0EC6E0E, 0x1698DB3B,
221 0x4C98A0BE, 0x3278E964, 0x9F1F9532, 0xE0D392DF, 0xD3A0342B, 0x8971F21E,
222 0x1B0A7441, 0x4BA3348C, 0xC5BE7120, 0xC37632D8, 0xDF359F8D, 0x9B992F2E,
223 0xE60B6F47, 0x0FE3F11D, 0xE54CDA54, 0x1EDAD891, 0xCE6279CF, 0xCD3E7E6F,
224 0x1618B166, 0xFD2C1D05, 0x848FD2C5, 0xF6FB2299, 0xF523F357, 0xA6327623,
225 0x93A83531, 0x56CCCD02, 0xACF08162, 0x5A75EBB5, 0x6E163697, 0x88D273CC,
226 0xDE966292, 0x81B949D0, 0x4C50901B, 0x71C65614, 0xE6C6C7BD, 0x327A140A,
227 0x45E1D006, 0xC3F27B9A, 0xC9AA53FD, 0x62A80F00, 0xBB25BFE2, 0x35BDD2F6,
228 0x71126905, 0xB2040222, 0xB6CBCF7C, 0xCD769C2B, 0x53113EC0, 0x1640E3D3,
229 0x38ABBD60, 0x2547ADF0, 0xBA38209C, 0xF746CE76, 0x77AFA1C5, 0x20756060,
230 0x85CBFE4E, 0x8AE88DD8, 0x7AAAF9B0, 0x4CF9AA7E, 0x1948C25C, 0x02FB8A8C,
231 0x01C36AE4, 0xD6EBE1F9, 0x90D4F869, 0xA65CDEA0, 0x3F09252D, 0xC208E69F,
232 0xB74E6132, 0xCE77E25B, 0x578FDFE3, 0x3AC372E6
233};
234
235static const uint32_t ps[BLOWFISH_ROUNDS + 2] = {
236 0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344, 0xA4093822, 0x299F31D0,
237 0x082EFA98, 0xEC4E6C89, 0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
238 0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917, 0x9216D5D9, 0x8979FB1B
239};
240
241void Blowfish::burn_stack(int bytes)
242{
243 char buf[64];
244
245 memset(buf, 0, sizeof buf);
246 bytes -= sizeof buf;
247 if (bytes > 0)
248 burn_stack(bytes);
249}
250
251void Blowfish::do_encrypt(uint32_t * ret_xl, uint32_t * ret_xr)
252{
253#if BLOWFISH_ROUNDS == 16
254 uint32_t xl, xr, *s0, *s1, *s2, *s3, *p;
255
256 xl = *ret_xl;
257 xr = *ret_xr;
258 p = bc.p;
259 s0 = bc.s0;
260 s1 = bc.s1;
261 s2 = bc.s2;
262 s3 = bc.s3;
263
264 R(xl, xr, 0, p, s0, s1, s2, s3);
265 R(xr, xl, 1, p, s0, s1, s2, s3);
266 R(xl, xr, 2, p, s0, s1, s2, s3);
267 R(xr, xl, 3, p, s0, s1, s2, s3);
268 R(xl, xr, 4, p, s0, s1, s2, s3);
269 R(xr, xl, 5, p, s0, s1, s2, s3);
270 R(xl, xr, 6, p, s0, s1, s2, s3);
271 R(xr, xl, 7, p, s0, s1, s2, s3);
272 R(xl, xr, 8, p, s0, s1, s2, s3);
273 R(xr, xl, 9, p, s0, s1, s2, s3);
274 R(xl, xr, 10, p, s0, s1, s2, s3);
275 R(xr, xl, 11, p, s0, s1, s2, s3);
276 R(xl, xr, 12, p, s0, s1, s2, s3);
277 R(xr, xl, 13, p, s0, s1, s2, s3);
278 R(xl, xr, 14, p, s0, s1, s2, s3);
279 R(xr, xl, 15, p, s0, s1, s2, s3);
280
281 xl ^= p[BLOWFISH_ROUNDS];
282 xr ^= p[BLOWFISH_ROUNDS + 1];
283
284 *ret_xl = xr;
285 *ret_xr = xl;
286
287#else
288 uint32_t xl, xr, temp, *p;
289 int i;
290
291 xl = *ret_xl;
292 xr = *ret_xr;
293 p = bc.p;
294
295 for (i = 0; i < BLOWFISH_ROUNDS; i++) {
296 xl ^= p[i];
297 xr ^= function_F(xl);
298 temp = xl;
299 xl = xr;
300 xr = temp;
301 }
302 temp = xl;
303 xl = xr;
304 xr = temp;
305
306 xr ^= p[BLOWFISH_ROUNDS];
307 xl ^= p[BLOWFISH_ROUNDS + 1];
308
309 *ret_xl = xl;
310 *ret_xr = xr;
311#endif
312}
313
314void Blowfish::do_decrypt(uint32_t * ret_xl, uint32_t * ret_xr)
315{
316#if BLOWFISH_ROUNDS == 16
317 uint32_t xl, xr, *s0, *s1, *s2, *s3, *p;
318
319 xl = *ret_xl;
320 xr = *ret_xr;
321 p = bc.p;
322 s0 = bc.s0;
323 s1 = bc.s1;
324 s2 = bc.s2;
325 s3 = bc.s3;
326
327 R(xl, xr, 17, p, s0, s1, s2, s3);
328 R(xr, xl, 16, p, s0, s1, s2, s3);
329 R(xl, xr, 15, p, s0, s1, s2, s3);
330 R(xr, xl, 14, p, s0, s1, s2, s3);
331 R(xl, xr, 13, p, s0, s1, s2, s3);
332 R(xr, xl, 12, p, s0, s1, s2, s3);
333 R(xl, xr, 11, p, s0, s1, s2, s3);
334 R(xr, xl, 10, p, s0, s1, s2, s3);
335 R(xl, xr, 9, p, s0, s1, s2, s3);
336 R(xr, xl, 8, p, s0, s1, s2, s3);
337 R(xl, xr, 7, p, s0, s1, s2, s3);
338 R(xr, xl, 6, p, s0, s1, s2, s3);
339 R(xl, xr, 5, p, s0, s1, s2, s3);
340 R(xr, xl, 4, p, s0, s1, s2, s3);
341 R(xl, xr, 3, p, s0, s1, s2, s3);
342 R(xr, xl, 2, p, s0, s1, s2, s3);
343
344 xl ^= p[1];
345 xr ^= p[0];
346
347 *ret_xl = xr;
348 *ret_xr = xl;
349
350#else
351 uint32_t xl, xr, temp, *p;
352 int i;
353
354 xl = *ret_xl;
355 xr = *ret_xr;
356 p = bc.p;
357
358 for (i = BLOWFISH_ROUNDS + 1; i > 1; i--) {
359 xl ^= p[i];
360 xr ^= function_F(xl);
361 temp = xl;
362 xl = xr;
363 xr = temp;
364 }
365
366 temp = xl;
367 xl = xr;
368 xr = temp;
369
370 xr ^= p[1];
371 xl ^= p[0];
372
373 *ret_xl = xl;
374 *ret_xr = xr;
375#endif
376}
377
378void Blowfish::do_encrypt_block(byte * outbuf, byte * inbuf)
379{
380 uint32_t d1, d2;
381
382 d1 = inbuf[0] << 24 | inbuf[1] << 16 | inbuf[2] << 8 | inbuf[3];
383 d2 = inbuf[4] << 24 | inbuf[5] << 16 | inbuf[6] << 8 | inbuf[7];
384 do_encrypt(&d1, &d2);
385 outbuf[0] = (d1 >> 24) & 0xff;
386 outbuf[1] = (d1 >> 16) & 0xff;
387 outbuf[2] = (d1 >> 8) & 0xff;
388 outbuf[3] = d1 & 0xff;
389 outbuf[4] = (d2 >> 24) & 0xff;
390 outbuf[5] = (d2 >> 16) & 0xff;
391 outbuf[6] = (d2 >> 8) & 0xff;
392 outbuf[7] = d2 & 0xff;
393}
394
395void Blowfish::encrypt_block(byte * outbuf, byte * inbuf)
396{
397 do_encrypt_block(outbuf, inbuf);
398 burn_stack(64);
399}
400
401void Blowfish::do_decrypt_block(byte * outbuf, byte * inbuf)
402{
403 uint32_t d1, d2;
404
405 d1 = inbuf[0] << 24 | inbuf[1] << 16 | inbuf[2] << 8 | inbuf[3];
406 d2 = inbuf[4] << 24 | inbuf[5] << 16 | inbuf[6] << 8 | inbuf[7];
407 do_decrypt(&d1, &d2);
408 outbuf[0] = (d1 >> 24) & 0xff;
409 outbuf[1] = (d1 >> 16) & 0xff;
410 outbuf[2] = (d1 >> 8) & 0xff;
411 outbuf[3] = d1 & 0xff;
412 outbuf[4] = (d2 >> 24) & 0xff;
413 outbuf[5] = (d2 >> 16) & 0xff;
414 outbuf[6] = (d2 >> 8) & 0xff;
415 outbuf[7] = d2 & 0xff;
416}
417
418void Blowfish::decrypt_block(byte * outbuf, byte * inbuf)
419{
420 do_decrypt_block(outbuf, inbuf);
421 burn_stack(64);
422}
423
424bool Blowfish::selfTest()
425{
426 byte plain1[] = "BLOWFISH";
427 byte key1[] = "abcdefghijklmnopqrstuvwxyz";
428 byte cipher1[] = "\x32\x4E\xD0\xFE\xF4\x13\xA2\x03";
429 byte plain2[] = "\xFE\xDC\xBA\x98\x76\x54\x32\x10";
430 byte key2[] = "\x41\x79\x6E\xA0\x52\x61\x6E\xE4";
431 byte cipher2[] = "\xE1\x13\xF4\x10\x2C\xFC\xCE\x43";
432 byte buffer[8];
433
434 Blowfish blowfish;
435
436 blowfish.bf_setkey(key1, array_size(key1) - 1);
437 blowfish.bf_encrypt(buffer, plain1, array_size(plain1) - 1);
438 if (unlikely(memcmp(buffer, cipher1, array_size(cipher1) - 1)))
439 return false;
440
441 blowfish.bf_decrypt(buffer, buffer, array_size(buffer));
442 if (unlikely(memcmp(buffer, plain1, array_size(plain1) - 1)))
443 return false;
444
445 blowfish.bf_setkey(key2, array_size(key2) - 1);
446 blowfish.bf_encrypt(buffer, plain2, array_size(plain2) - 1);
447 if (unlikely(memcmp(buffer, cipher2, array_size(cipher2) - 1)))
448 return false;
449
450 blowfish.bf_decrypt(buffer, buffer, array_size(buffer));
451 if (unlikely(memcmp(buffer, plain2, array_size(plain2) - 1)))
452 return false;
453
454 return true;
455}
456
457int Blowfish::do_bf_setkey(byte * key, unsigned int keylen)
458{
459 int i, j;
460 uint32_t data, datal, datar;
461
462 for (i = 0; i < BLOWFISH_ROUNDS + 2; ++i)
463 bc.p[i] = ps[i];
464 for (i = 0; i < 256; ++i) {
465 bc.s0[i] = ks0[i];
466 bc.s1[i] = ks1[i];
467 bc.s2[i] = ks2[i];
468 bc.s3[i] = ks3[i];
469 }
470
471 for (i = j = 0; i < BLOWFISH_ROUNDS + 2; ++i) {
472#ifdef BIG_ENDIAN_HOST
473 ((byte *) & data)[0] = key[j];
474 ((byte *) & data)[1] = key[(j + 1) % keylen];
475 ((byte *) & data)[2] = key[(j + 2) % keylen];
476 ((byte *) & data)[3] = key[(j + 3) % keylen];
477#else
478 ((byte *) & data)[3] = key[j];
479 ((byte *) & data)[2] = key[(j + 1) % keylen];
480 ((byte *) & data)[1] = key[(j + 2) % keylen];
481 ((byte *) & data)[0] = key[(j + 3) % keylen];
482#endif
483 bc.p[i] ^= data;
484 j = (j + 4) % keylen;
485 }
486
487 datal = datar = 0;
488 for (i = 0; i < BLOWFISH_ROUNDS + 2; i += 2) {
489 do_encrypt(&datal, &datar);
490 bc.p[i] = datal;
491 bc.p[i + 1] = datar;
492 }
493 for (i = 0; i < 256; i += 2) {
494 do_encrypt(&datal, &datar);
495 bc.s0[i] = datal;
496 bc.s0[i + 1] = datar;
497 }
498 for (i = 0; i < 256; i += 2) {
499 do_encrypt(&datal, &datar);
500 bc.s1[i] = datal;
501 bc.s1[i + 1] = datar;
502 }
503 for (i = 0; i < 256; i += 2) {
504 do_encrypt(&datal, &datar);
505 bc.s2[i] = datal;
506 bc.s2[i + 1] = datar;
507 }
508 for (i = 0; i < 256; i += 2) {
509 do_encrypt(&datal, &datar);
510 bc.s3[i] = datal;
511 bc.s3[i + 1] = datar;
512 }
513
514 /* Check for weak key. A weak key is a key in which a value in */
515 /* the P-array (here c) occurs more than once per table. */
516 for (i = 0; i < 255; ++i) {
517 for (j = i + 1; j < 256; ++j) {
518 if ((bc.s0[i] == bc.s0[j]) || (bc.s1[i] == bc.s1[j]) ||
519 (bc.s2[i] == bc.s2[j]) || (bc.s3[i] == bc.s3[j]))
520 return 1;
521 }
522 }
523
524 return 0;
525}
526
527int Blowfish::bf_setkey(byte * key, unsigned int keylen)
528{
529 int rc = do_bf_setkey(key, keylen);
530 burn_stack(64);
531 return rc;
532}
533
534int Blowfish::bf_encrypt(byte * outbuf, byte * inbuf, unsigned int inbuf_len)
535{
536 if (unlikely(inbuf_len % 8))
537 return 1;
538
539 unsigned int i = 0;
540 while (i < inbuf_len) {
541 encrypt_block(outbuf + i, inbuf + i);
542 i += 8;
543 }
544 return 0;
545}
546
547int Blowfish::bf_decrypt(byte * outbuf, byte * inbuf, unsigned int inbuf_len)
548{
549 if (unlikely(inbuf_len % 8))
550 return 1;
551
552 unsigned int i = 0;
553 while (i < inbuf_len) {
554 decrypt_block(outbuf + i, inbuf + i);
555 i += 8;
556 }
557 return 0;
558}
559
560void Blowfish::padNull(string *buf)
561{
562 buf->append(1, (char)0x01);
563 string::size_type append_null = 8 - (buf->length() % 8);
564 buf->append(append_null, (char)0x00);
565}
566
567bool Blowfish::unpadNull(string *buf)
568{
569 if (unlikely(buf->size() % 8))
570 return false;
571 string::size_type pos = buf->length() - 1;
572 while ((*buf)[pos] != (char)0x01) {
573 if (unlikely(pos == 0))
574 return false;
575 --pos;
576 }
577 buf->erase(pos, buf->length() - pos);
578 return true;
579}
diff --git a/pwmanager/pwmanager/blowfish.h b/pwmanager/pwmanager/blowfish.h
new file mode 100644
index 0000000..c05de77
--- a/dev/null
+++ b/pwmanager/pwmanager/blowfish.h
@@ -0,0 +1,120 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * blowfish.c - Blowfish encryption *
7 * Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc. *
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License version 2 *
11 * as published by the Free Software Foundation. *
12 * *
13 ***************************************************************************/
14
15/***************************************************************************
16 * copyright (C) 2004 by Ulf Schenk
17 * This file is originaly based on version 1.0.1 of pwmanager
18 * and was modified to run on embedded devices that run microkde
19 *
20 * $Id$
21 **************************************************************************/
22
23#ifndef BLOWFISH_H
24#define BLOWFISH_H
25
26#include "pwmexception.h"
27
28#include <stdint.h>
29#include <string>
30using std::string;
31
32 #define BLOWFISH_BLOCKSIZE8
33 #define BLOWFISH_ROUNDS 16
34 #define CIPHER_ALGO_BLOWFISH 4/* blowfish 128 bit key */
35
36 typedef uint8_t byte;
37
38/** blowfish encryption algorithm.
39 * Derived from libgcrypt-1.1.12
40 */
41class Blowfish
42{
43 struct BLOWFISH_context
44 {
45 uint32_t s0[256];
46 uint32_t s1[256];
47 uint32_t s2[256];
48 uint32_t s3[256];
49 uint32_t p[BLOWFISH_ROUNDS+2];
50 };
51
52public:
53 Blowfish() {}
54 static bool selfTest();
55
56 /** set key to encrypt. if return == 1, it is a weak key. */
57 int bf_setkey( byte *key, unsigned int keylen );
58 /** encrypt inbuf and return it in outbuf.
59 * inbuf and outbuf have to be: buf % 8 == 0
60 * You may check this with getPaddedLen() and pad with NULL.
61 */
62 int bf_encrypt( byte *outbuf, byte *inbuf, unsigned int inbuf_len );
63 /** decrypt inbuf and return it in outbuf.
64 * inbuf and outbuf have to be: buf % 8 == 0
65 * You may check this with getPaddedLen() and pad with NULL.
66 */
67 int bf_decrypt( byte *outbuf, byte *inbuf, unsigned int inbuf_len );
68 /** returns the length, the sting has to be padded to */
69 static unsigned int getPaddedLen(unsigned int inLen)
70 { return ((8 - (inLen % 8)) + inLen); }
71 /** pad up to 8 bytes. */
72 static void padNull(string *buf);
73 /** remove padded data */
74 static bool unpadNull(string *buf);
75
76protected:
77#if BLOWFISH_ROUNDS != 16
78 uint32_t function_F( uint32_t x)
79 {
80 uint16_t a, b, c, d;
81 #ifdef BIG_ENDIAN_HOST
82 a = ((byte *) & x)[0];
83 b = ((byte *) & x)[1];
84 c = ((byte *) & x)[2];
85 d = ((byte *) & x)[3];
86 #else
87 a = ((byte *) & x)[3];
88 b = ((byte *) & x)[2];
89 c = ((byte *) & x)[1];
90 d = ((byte *) & x)[0];
91 #endif
92 return ((bc.s0[a] + bc.s1[b]) ^ bc.s2[c]) + bc.s3[d];
93 }
94#endif
95 void R(uint32_t &l, uint32_t &r, uint32_t i, uint32_t *p,
96 uint32_t *s0, uint32_t *s1, uint32_t *s2, uint32_t *s3)
97 {
98 l ^= p[i];
99 #ifdef BIG_ENDIAN_HOST
100 r ^= (( s0[((byte*)&l)[0]] + s1[((byte*)&l)[1]])
101 ^ s2[((byte*)&l)[2]]) + s3[((byte*)&l)[3]];
102 #else
103 r ^= (( s0[((byte*)&l)[3]] + s1[((byte*)&l)[2]])
104 ^ s2[((byte*)&l)[1]]) + s3[((byte*)&l)[0]];
105 #endif
106 }
107 void encrypt_block(byte *outbuf, byte *inbuf);
108 void decrypt_block(byte *outbuf, byte *inbuf);
109 void burn_stack(int bytes);
110 void do_encrypt(uint32_t *ret_xl, uint32_t *ret_xr);
111 void do_decrypt(uint32_t *ret_xl, uint32_t *ret_xr);
112 void do_encrypt_block(byte *outbuf, byte *inbuf);
113 void do_decrypt_block(byte *outbuf, byte *inbuf);
114 int do_bf_setkey(byte *key, unsigned int keylen);
115
116protected:
117 struct BLOWFISH_context bc;
118};
119
120#endif
diff --git a/pwmanager/pwmanager/commentbox.cpp b/pwmanager/pwmanager/commentbox.cpp
new file mode 100644
index 0000000..280b139
--- a/dev/null
+++ b/pwmanager/pwmanager/commentbox.cpp
@@ -0,0 +1,238 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "commentbox.h"
21#include "pwmexception.h"
22#include "htmlgen.h"
23
24#include <klocale.h>
25
26#ifndef PWM_EMBEDDED
27#include <khtml_part.h>
28#include <khtmlview.h>
29#include <qtextedit.h>
30#else
31#include <qmultilineedit.h>
32#endif
33
34CommentBox::CommentBox(QWidget *_parentWidget)
35{
36 PWM_ASSERT(_parentWidget);
37 parentWidget = _parentWidget;
38 textDta = 0;
39#ifndef PWM_EMBEDDED
40 htmlDta = 0;
41#endif
42 mode = mode_notSet;
43}
44
45CommentBox::~CommentBox()
46{
47 clearText();
48 clearHtml();
49}
50
51void CommentBox::clear()
52{
53 clearText();
54 clearHtml();
55 mode = mode_notSet;
56}
57
58void CommentBox::clearText()
59{
60 delete_ifnot_null(textDta);
61}
62
63void CommentBox::clearHtml()
64{
65#ifndef PWM_EMBEDDED
66 delete_ifnot_null(htmlDta);
67#endif
68}
69
70void CommentBox::setText(const QString &text)
71{
72 switchTo(mode_text);
73 PWM_ASSERT(textDta);
74 textDta->setText(i18n("Comment") + ": " + text);
75 if (!textDta->isVisible())
76 textDta->show();
77}
78
79bool CommentBox::getText(QString *text)
80{
81 if (mode != mode_text)
82 return false;
83 PWM_ASSERT(text);
84 if (!textDta) {
85 *text = "";
86 return true;
87 }
88 *text = textDta->text();
89 return true;
90}
91
92void CommentBox::setHtml(QString code)
93{
94#ifndef PWM_EMBEDDED
95 switchTo(mode_html);
96 PWM_ASSERT(htmlDta);
97 if (!HtmlGen::replaceSSDummy(&code))
98 printWarn("CommentBox::setHtml(): replaceSSDummy() failed!");
99 htmlDta->begin();
100 htmlDta->write(code);
101 htmlDta->end();
102 htmlDta->show();
103#endif
104}
105
106void CommentBox::setContent(const QString &dta)
107{
108 // if there's no data, hide the comment-box
109 if (dta.isEmpty()) {
110 clear();
111 return;
112 }
113#ifndef PWM_EMBEDDED
114 if (HtmlGen::isHtml(dta)) {
115 setHtml(dta);
116 return;
117 }
118#endif
119 // we assume it's plain text
120 setText(dta);
121}
122
123void CommentBox::switchTo(commentBoxMode newMode)
124{
125 if (newMode == mode)
126 return;
127
128 // cleanup old mode
129 switch (mode) {
130 case mode_text:
131 clearText();
132 break;
133 case mode_html:
134 clearHtml();
135 break;
136 default:
137 break;
138 }
139
140 // setup new mode
141 switch (newMode) {
142 case mode_text:
143#ifndef PWM_EMBEDDED
144 textDta = new QTextEdit(parentWidget);
145 textDta->setTextFormat(Qt::PlainText);
146#else
147 textDta = new QMultiLineEdit(parentWidget);
148#endif
149 textDta->setReadOnly(true);
150 textDta->show();
151 break;
152 case mode_html:
153#ifndef PWM_EMBEDDED
154 htmlDta = new KHTMLPart(parentWidget, 0,
155 parentWidget);
156 htmlDta->show();
157#endif
158 break;
159 default:
160 BUG();
161 break;
162 }
163
164 mode = newMode;
165}
166
167void CommentBox::show()
168{
169 switch (mode) {
170 case mode_text:
171 PWM_ASSERT(textDta);
172 textDta->show();
173 break;
174 case mode_html:
175#ifndef PWM_EMBEDDED
176 PWM_ASSERT(htmlDta);
177 htmlDta->show();
178#endif
179 break;
180 default:
181 break;
182 }
183}
184
185void CommentBox::hide()
186{
187 switch (mode) {
188 case mode_text:
189 PWM_ASSERT(textDta);
190 textDta->hide();
191 break;
192 case mode_html:
193#ifndef PWM_EMBEDDED
194 PWM_ASSERT(htmlDta);
195 htmlDta->hide();
196#endif
197 break;
198 default:
199 break;
200 }
201}
202
203void CommentBox::resize(const QSize &size)
204{
205 switch (mode) {
206 case mode_text:
207 PWM_ASSERT(textDta);
208 textDta->resize(size);
209 break;
210 case mode_html:
211#ifndef PWM_EMBEDDED
212 PWM_ASSERT(htmlDta);
213 htmlDta->view()->resize(size);
214#endif
215 break;
216 default:
217 break;
218 }
219}
220
221QSize CommentBox::size()
222{
223 switch (mode) {
224 case mode_text:
225 PWM_ASSERT(textDta);
226 return textDta->size();
227 break;
228 case mode_html:
229#ifndef PWM_EMBEDDED
230 PWM_ASSERT(htmlDta);
231 return htmlDta->view()->size();
232#endif
233 break;
234 default:
235 break;
236 }
237 return QSize();
238}
diff --git a/pwmanager/pwmanager/commentbox.h b/pwmanager/pwmanager/commentbox.h
new file mode 100644
index 0000000..a220acd
--- a/dev/null
+++ b/pwmanager/pwmanager/commentbox.h
@@ -0,0 +1,100 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef COMMENTBOX_H
21#define COMMENTBOX_H
22
23#include <qstring.h>
24#include <qsize.h>
25
26class QWidget;
27class QTextEdit;
28class QMultiLineEdit;
29class KHTMLPart;
30
31/** Implementation of the advanced HTML comment box */
32class CommentBox
33{
34protected:
35 enum commentBoxMode
36 {
37 mode_notSet = 0,
38 mode_text,
39 mode_html
40 };
41
42public:
43 CommentBox(QWidget *_parentWidget);
44 ~CommentBox();
45
46 /** clear all data in the comment box */
47 void clear();
48 /** show the comment box */
49 void show();
50 /** hide the comment box */
51 void hide();
52 /** resize the comment box */
53 void resize(const QSize &size);
54 void resize(int w, int h)
55 { resize(QSize(w, h)); }
56 /** get the size of the comment box */
57 QSize size();
58 /** if neccessary switch to text-mode and
59 * insert this text into the comment box
60 */
61 void setText(const QString &text);
62 /** get the text of the comment box.
63 * If it's not in text-mode it returns false
64 */
65 bool getText(QString *text);
66 /** if neccessary switch to HTML-mode and
67 * insert this html code into the comment box
68 */
69 void setHtml(QString code);
70 /** checks "dta" for its type, sets the correct
71 * mode and writes "dta" to the comment box
72 */
73 void setContent(const QString &dta);
74
75protected:
76 /** switch the current mode */
77 void switchTo(commentBoxMode newMode);
78 /** clear all text data */
79 void clearText();
80 /** clear all HTML data */
81 void clearHtml();
82
83protected:
84 /** parent widget for this comment box */
85 QWidget *parentWidget;
86 /** current comment box usage type */
87 commentBoxMode mode;
88#ifndef PWM_EMBEDDED
89 /** if the comment box is a normal textbox, data is stored here */
90 QTextEdit *textDta;
91 /** if the comment box is a HTML box, data is stored here */
92 KHTMLPart *htmlDta;
93#else
94 /** if the comment box is a normal textbox, data is stored here */
95 QMultiLineEdit *textDta;
96#endif
97
98};
99
100#endif
diff --git a/pwmanager/pwmanager/compiler.h b/pwmanager/pwmanager/compiler.h
new file mode 100644
index 0000000..be08c6d
--- a/dev/null
+++ b/pwmanager/pwmanager/compiler.h
@@ -0,0 +1,61 @@
1/***************************************************************************
2 * *
3 * Derived from the linux-2.6 tree *
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 version 2 *
7 * as published by the Free Software Foundation. *
8 * *
9 ***************************************************************************/
10
11#ifndef __PWMANAGER_COMPILER_H
12#define __PWMANAGER_COMPILER_H
13
14#ifdef __deprecated
15# undef __deprecated
16#endif
17#if __GNUC__ >= 3
18# if __GNUC_MINOR__ > 0
19 # define __deprecated__attribute__((deprecated))
20# endif
21#elif __GNUC__ == 2
22# if __GNUC_MINOR__ < 96
23# ifdef __builtin_expect
24# undef __builtin_expect
25# endif
26# define __builtin_expect(x, expected_value) (x)
27# endif
28#else
29# error "Sorry, your compiler is too old/not supported."
30#endif
31
32/*
33 * Allow us to mark functions as 'deprecated' and have gcc emit a nice
34 * warning for each use, in hopes of speeding the functions removal.
35 * Usage is:
36 * int __deprecated foo(void)
37 */
38#ifndef __deprecated
39 # define __deprecated /* unimplemented */
40#endif
41
42/* define likely() and unlikely() */
43#ifdef likely
44# undef likely
45#endif
46#ifdef unlikely
47# undef unlikely
48#endif
49 #define likely(x)__builtin_expect(!!(x), 1)
50 #define unlikely(x)__builtin_expect(!!(x), 0)
51
52#ifdef NOREGPARM
53# undef NOREGPARM
54#endif
55 #define NOREGPARM__attribute__((regparm(0)))
56#ifdef REGPARM
57# undef REGPARM
58#endif
59 #define REGPARM __attribute__((regparm(3)))
60
61#endif // __PWMANAGER_COMPILER_H
diff --git a/pwmanager/pwmanager/compressbzip2.cpp b/pwmanager/pwmanager/compressbzip2.cpp
new file mode 100644
index 0000000..c3a9edd
--- a/dev/null
+++ b/pwmanager/pwmanager/compressbzip2.cpp
@@ -0,0 +1,138 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "compressbzip2.h"
21
22#include <stdlib.h>
23
24#define BZ_NO_STDIO
25#include <bzlib.h>
26
27 #define BZ_BLOCK_SIZE 9
28 #define BZ_WORK_FACTOR 30
29 #define EXPAND_COMPRESS_DESTBUF_BYTES 1024
30 #define EXPAND_DECOMPRESS_DESTBUF_BYTES (1024 * 10)
31
32
33bool CompressBzip2::compress(string *d)
34{
35 int ret;
36 char *dest, *source;
37 unsigned int sourceLen, destLen;
38
39 sourceLen = d->length();
40 destLen = calcCompressDestLen(sourceLen);
41 source = static_cast<char *>(malloc(sourceLen));
42 if (!source)
43 return false;
44 memcpy(source, d->c_str(), sourceLen);
45 dest = static_cast<char *>(malloc(destLen));
46 if (!dest) {
47 free(source);
48 return false;
49 }
50 while (1) {
51 ret = BZ2_bzBuffToBuffCompress(dest,
52 &destLen,
53 source,
54 sourceLen,
55 BZ_BLOCK_SIZE,
56 0,
57 BZ_WORK_FACTOR);
58 switch (ret) {
59 case BZ_OK:
60 goto out;
61 case BZ_OUTBUFF_FULL:
62 /* we don't use realloc(), because it may
63 * (in this case) unneccessarily copy the old block
64 * to the new allocated block.
65 */
66 free(dest);
67 destLen += EXPAND_COMPRESS_DESTBUF_BYTES;
68 dest = static_cast<char *>(malloc(destLen));
69 if (!dest) {
70 free(source);
71 return false;
72 }
73 break;
74 default:
75 free(source),
76 free(dest);
77 return false;
78 }
79 }
80out:
81 free(source);
82 d->assign(dest, destLen);
83 free(dest);
84 return true;
85}
86
87bool CompressBzip2::decompress(string *d)
88{
89 int ret;
90 char *dest, *source;
91 unsigned int sourceLen, destLen;
92
93 sourceLen = d->length();
94 destLen = calcDecompressDestLen(sourceLen);
95 source = static_cast<char *>(malloc(sourceLen));
96 if (!source)
97 return false;
98 memcpy(source, d->c_str(), sourceLen);
99 dest = static_cast<char *>(malloc(destLen));
100 if (!dest) {
101 free(source);
102 return false;
103 }
104 while (1) {
105 ret = BZ2_bzBuffToBuffDecompress(dest,
106 &destLen,
107 source,
108 sourceLen,
109 0,
110 0);
111 switch (ret) {
112 case BZ_OK:
113 goto out;
114 case BZ_OUTBUFF_FULL:
115 /* we don't use realloc(), because it may
116 * (in this case) unneccessarily copy the old block
117 * to the new allocated block.
118 */
119 free(dest);
120 destLen += EXPAND_DECOMPRESS_DESTBUF_BYTES;
121 dest = static_cast<char *>(malloc(destLen));
122 if (!dest) {
123 free(source);
124 return false;
125 }
126 break;
127 default:
128 free(source),
129 free(dest);
130 return false;
131 }
132 }
133out:
134 free(source);
135 d->assign(dest, destLen);
136 free(dest);
137 return true;
138}
diff --git a/pwmanager/pwmanager/compressbzip2.h b/pwmanager/pwmanager/compressbzip2.h
new file mode 100644
index 0000000..4f4885c
--- a/dev/null
+++ b/pwmanager/pwmanager/compressbzip2.h
@@ -0,0 +1,50 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef COMPRESSBZIP2_H
21#define COMPRESSBZIP2_H
22
23#include <string>
24using std::string;
25
26/** bzip2 compression */
27class CompressBzip2
28{
29public:
30 CompressBzip2() {}
31
32 /** compress the string d */
33 bool compress(string *d);
34 /** decompress the string d */
35 bool decompress(string *d);
36
37protected:
38 /** calculates the length of the dest-buffer
39 * for compress() using the size of the source-buffer
40 */
41 unsigned int calcCompressDestLen(unsigned int sourceLen)
42 { return (sourceLen + (sourceLen / 100 + 600)); }
43 /** calculates the length of the dest-buffer
44 * for decompress() using the size of the source-buffer
45 */
46 unsigned int calcDecompressDestLen(unsigned int sourceLen)
47 { return (sourceLen * 2); }
48};
49
50#endif
diff --git a/pwmanager/pwmanager/compressgzip.cpp b/pwmanager/pwmanager/compressgzip.cpp
new file mode 100644
index 0000000..0a325c6
--- a/dev/null
+++ b/pwmanager/pwmanager/compressgzip.cpp
@@ -0,0 +1,115 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "compressgzip.h"
21
22#include <stdlib.h>
23#include <zlib.h>
24
25 #define COMPRESSION_LEVEL Z_BEST_COMPRESSION
26 #define EXPAND_COMPRESS_DESTBUF_BYTES 1024
27 #define EXPAND_DECOMPRESS_DESTBUF_BYTES (1024 * 10)
28
29
30bool CompressGzip::compress(string *d)
31{
32 int ret;
33 Bytef *dest;
34 const Bytef *source;
35 unsigned long sourceLen, destLen;
36
37 source = reinterpret_cast<const Bytef *>(d->c_str());
38 sourceLen = d->length();
39 destLen = calcCompressDestLen(sourceLen);
40 dest = static_cast<Bytef *>(malloc(destLen));
41 if (!dest)
42 return false;
43 while (1) {
44 ret = compress2(dest,
45 static_cast<uLongf *>(&destLen),
46 source,
47 static_cast<uLong>(sourceLen),
48 COMPRESSION_LEVEL);
49 switch (ret) {
50 case Z_OK:
51 goto out;
52 case Z_BUF_ERROR:
53 /* we don't use realloc(), because it may
54 * (in this case) unneccessarily copy the old block
55 * to the new allocated block.
56 */
57 free(dest);
58 destLen += EXPAND_COMPRESS_DESTBUF_BYTES;
59 dest = static_cast<Bytef *>(malloc(destLen));
60 if (!dest)
61 return false;
62 break;
63 default:
64 free(dest);
65 return false;
66 }
67 }
68out:
69 d->assign(reinterpret_cast<char *>(dest), destLen);
70 free(dest);
71 return true;
72}
73
74bool CompressGzip::decompress(string *d)
75{
76 int ret;
77 Bytef *dest;
78 const Bytef *source;
79 unsigned long sourceLen, destLen;
80
81 source = reinterpret_cast<const Bytef *>(d->c_str());
82 sourceLen = d->length();
83 destLen = calcDecompressDestLen(sourceLen);
84 dest = static_cast<Bytef *>(malloc(destLen));
85 if (!dest)
86 return false;
87 while (1) {
88 ret = uncompress(dest,
89 static_cast<uLongf *>(&destLen),
90 source,
91 static_cast<uLong>(sourceLen));
92 switch (ret) {
93 case Z_OK:
94 goto out;
95 case Z_BUF_ERROR:
96 /* we don't use realloc(), because it may
97 * (in this case) unneccessarily copy the old block
98 * to the new allocated block.
99 */
100 free(dest);
101 destLen += EXPAND_DECOMPRESS_DESTBUF_BYTES;
102 dest = static_cast<Bytef *>(malloc(destLen));
103 if (!dest)
104 return false;
105 break;
106 default:
107 free(dest);
108 return false;
109 }
110 }
111out:
112 d->assign(reinterpret_cast<char *>(dest), destLen);
113 free(dest);
114 return true;
115}
diff --git a/pwmanager/pwmanager/compressgzip.h b/pwmanager/pwmanager/compressgzip.h
new file mode 100644
index 0000000..78c71d4
--- a/dev/null
+++ b/pwmanager/pwmanager/compressgzip.h
@@ -0,0 +1,50 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef COMPRESSGZIP_H
21#define COMPRESSGZIP_H
22
23#include <string>
24using std::string;
25
26/** gzip compression */
27class CompressGzip
28{
29public:
30 CompressGzip() {}
31
32 /** compress the string d */
33 bool compress(string *d);
34 /** decompress the string d */
35 bool decompress(string *d);
36
37protected:
38 /** calculates the length of the dest-buffer
39 * for compress() using the size of the source-buffer
40 */
41 unsigned int calcCompressDestLen(unsigned int sourceLen)
42 { return (sourceLen + (sourceLen / 100 / 10 + 12)); }
43 /** calculates the length of the dest-buffer
44 * for decompress() using the size of the source-buffer
45 */
46 unsigned int calcDecompressDestLen(unsigned int sourceLen)
47 { return (sourceLen * 2); }
48};
49
50#endif
diff --git a/pwmanager/pwmanager/configuration.cpp b/pwmanager/pwmanager/configuration.cpp
new file mode 100644
index 0000000..8d67977
--- a/dev/null
+++ b/pwmanager/pwmanager/configuration.cpp
@@ -0,0 +1,459 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 2.0 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "configuration.h"
21#if KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0)
22
23#include <kconfigdialog.h>
24#include <kfiledialog.h>
25#include <klocale.h>
26#include <kfontrequester.h>
27
28#include <qcheckbox.h>
29#include <qcombobox.h>
30#include <qlabel.h>
31#include <qlineedit.h>
32#include <qpushbutton.h>
33#include <qgroupbox.h>
34#include <qfileinfo.h>
35#include <qfontdialog.h>
36#include <qspinbox.h>
37#include <qvalidator.h>
38#include <qsqlpropertymap.h>
39#include <qlayout.h>
40
41#include <stdlib.h>
42#include <stdio.h>
43
44 #define INITIAL_CONFWND_SIZE(QSize(600, 450))
45
46
47/*********************************************************
48 ** class Configuration **
49 *********************************************************/
50
51Configuration * Configuration::_obj (0);
52
53Configuration::Configuration()
54{
55 skel = new KConfigSkeleton;
56 initSkel();
57 readConfig();
58}
59
60Configuration::~Configuration()
61{
62 writeConfig();
63 delete_ifnot_null(skel);
64}
65
66void Configuration::initSkel()
67{
68 skel->setCurrentGroup("GLOBAL");
69 skel->addItemString("autoStart", cGlobAutoStart);
70 skel->addItemString("browserCommand", cGlobBrowserCommand, CONF_DEFAULT_BROWSERCOMMAND);
71 skel->addItemString("xtermCommand", cGlobXtermCommand, CONF_DEFAULT_XTERMCOMMAND);
72 skel->addItemFont("entryFont", cGlobEntryFont);
73 skel->addItemInt("pwTimeout", cGlobPwTimeout, CONF_DEFAULT_PWTIMEOUT);
74 skel->addItemInt("lockTimeout", cGlobLockTimeout, CONF_DEFAULT_LOCKTIMEOUT);
75 skel->addItemInt("compression", cGlobCompression, CONF_DEFAULT_COMPRESSION);
76 skel->addItemInt("filePermissions", cGlobFilePermissions, CONF_DEFAULT_FILEPERMISSIONS);
77 skel->addItemInt("minimizeLock", cGlobMinimizeLock, CONF_DEFAULT_MINIMIZELOCK);
78 skel->addItemBool("unlockOnOpen", cGlobUnlockOnOpen, CONF_DEFAULT_UNLOCKONOPEN);
79 skel->addItemBool("tray", cGlobTray, CONF_DEFAULT_TRAY);
80 skel->addItemBool("makeFileBackup", cGlobMakeFileBackup, CONF_DEFAULT_MAKEFILEBACKUP);
81 skel->addItemBool("autostartDeeplocked", cGlobAutostartDeepLocked, CONF_DEFAULT_AUTOSTART_DEEPL);
82 skel->addItemBool("autoDeepLock", cGlobAutoDeepLock, CONF_DEFAULT_AUTODEEPLOCK);
83 skel->addItemBool("kwalletEmu", cGlobKwalletEmu, CONF_DEFAULT_KWALLETEMU);
84 skel->addItemBool("newEntrLockStat", cGlobNewEntrLockStat, CONF_DEFAULT_NEWENTRLOCKSTAT);
85
86 skel->setCurrentGroup("WND");
87 skel->addItemSize("MainWndSize", cWndMainWndSize);
88 skel->addItemInt("MainViewStyle", cWndMainViewStyle, CONF_DEFAULT_MAINVIEWSTYLE);
89 skel->addItemBool("autoMinimizeOnStart", cWndAutoMinimizeOnStart, CONF_DEFAULT_AUTOMINIMIZE);
90 skel->addItemBool("close", cWndClose, CONF_DEFAULT_WNDCLOSE);
91}
92
93bool Configuration::showConfWnd(QWidget *parent)
94{
95 bool ret = true;
96 KConfigDialog *confDlg;
97 confDlg = new KConfigDialog(parent, i18n("Main configuration").latin1(), skel,
98 KDialogBase::IconList,
99 KConfigDialog::Default | KConfigDialog::Ok |
100 KConfigDialog::Cancel | KConfigDialog::Help,
101 KConfigDialog::Ok, true);
102 ConfPageGlobal *confPageGlobal = new ConfPageGlobal;
103 ConfPageLookNFeel *confPageLookNFeel = new ConfPageLookNFeel;
104 ConfPageFile *confPageFile = new ConfPageFile;
105 ConfPageTimeouts *confPageTimeouts = new ConfPageTimeouts;
106 ConfPageExtApps *confPageExtApps = new ConfPageExtApps;
107 ConfPageAutostart *confPageAutostart = new ConfPageAutostart;
108 confDlg->addPage(confPageGlobal, i18n("General"), "pwmanager");
109 confDlg->addPage(confPageLookNFeel, i18n("Look & Feel"), "fonts");
110 confDlg->addPage(confPageFile, i18n("Files"), "filesave");
111 confDlg->addPage(confPageTimeouts, i18n("Timeouts"), "clock");
112 confDlg->addPage(confPageExtApps, i18n("External Applications"), "gear");
113 confDlg->addPage(confPageAutostart, i18n("Autostart"), "fileopen");
114 confDlg->resize(INITIAL_CONFWND_SIZE);
115 if (confDlg->exec() == 0)
116 ret = false;
117 delete confPageGlobal;
118 delete confPageLookNFeel;
119 delete confPageFile;
120 delete confPageTimeouts;
121 delete confPageExtApps;
122 delete confPageAutostart;
123 return ret;
124}
125
126
127/*********************************************************
128 ** class OctLineEdit **
129 *********************************************************/
130
131OctLineEdit::OctLineEdit(QWidget *parent, const char *name)
132 : QLineEdit(parent, name)
133{
134}
135
136OctLineEdit::~OctLineEdit()
137{
138}
139
140void OctLineEdit::setText(const QString &t)
141{
142 bool ok;
143 int tmp = t.toInt(&ok, 10);
144 if (!ok)
145 return;
146 QString ret;
147 ret.setNum(tmp, 8);
148 QLineEdit::setText(ret);
149}
150
151QString OctLineEdit::text() const
152{
153 bool ok;
154 QString ret;
155 QString t(QLineEdit::text());
156 int tmp = t.toInt(&ok, 8);
157 if (!ok)
158 return ret;
159 ret.setNum(tmp, 10);
160 return ret;
161}
162
163void OctLineEdit::keyPressEvent(QKeyEvent *e)
164{
165 int key = e->key();
166 switch (key) {
167 case Qt::Key_0:
168 case Qt::Key_1:
169 case Qt::Key_2:
170 case Qt::Key_3:
171 case Qt::Key_4:
172 case Qt::Key_5:
173 case Qt::Key_6:
174 case Qt::Key_7:
175 case Qt::Key_Escape:
176 case Qt::Key_Backtab:
177 case Qt::Key_Backspace:
178 case Qt::Key_Return:
179 case Qt::Key_Enter:
180 case Qt::Key_Insert:
181 case Qt::Key_Delete:
182 case Qt::Key_Home:
183 case Qt::Key_End:
184 case Qt::Key_Left:
185 case Qt::Key_Up:
186 case Qt::Key_Right:
187 case Qt::Key_Down:
188 e->accept();
189 QLineEdit::keyPressEvent(e);
190 break;
191 default:
192 e->ignore();
193 }
194}
195
196
197/*********************************************************
198 ** class ConfPageGlobal **
199 *********************************************************/
200
201ConfPageGlobal::ConfPageGlobal(QWidget *parent, const char *name, WFlags f)
202 : QWidget(parent, name, f)
203{
204 QCheckBox *kcfg_tray;
205 QCheckBox *kcfg_autoMinimizeOnStart;
206 QCheckBox *kcfg_unlockOnOpen;
207 QCheckBox *kcfg_newEntrLockStat;
208 QCheckBox *kcfg_close;
209 QComboBox *kcfg_minimizeLock;
210 QLabel *kcfg_minimizeLock_label;
211
212 QBoxLayout *l = new QVBoxLayout(this);
213 l->setSpacing(4);
214 kcfg_tray = new QCheckBox(i18n("Show icon in system-tray"), this, "kcfg_tray");
215 l->addWidget(kcfg_tray);
216 kcfg_autoMinimizeOnStart = new QCheckBox(i18n("auto-minimize to tray on startup"),
217 this, "kcfg_autoMinimizeOnStart");
218 l->addWidget(kcfg_autoMinimizeOnStart);
219 kcfg_unlockOnOpen = new QCheckBox(i18n("Open document with passwords unlocked"),
220 this, "kcfg_unlockOnOpen");
221 l->addWidget(kcfg_unlockOnOpen);
222#ifdef CONFIG_KWALLETIF
223 QCheckBox *kcfg_kwalletEmu;
224 kcfg_kwalletEmu = new QCheckBox(i18n("KWallet emulation"),
225 this, "kcfg_kwalletEmu");
226 l->addWidget(kcfg_kwalletEmu);
227#endif // CONFIG_KWALLETIF
228 kcfg_newEntrLockStat = new QCheckBox(i18n("Automatically lock new entries"),
229 this, "kcfg_newEntrLockStat");
230 l->addWidget(kcfg_newEntrLockStat);
231 kcfg_close = new QCheckBox(i18n("Do not minimize windows into tray. (Close the window)"),
232 this, "kcfg_close");
233 l->addWidget(kcfg_close);
234 l->addSpacing(4);
235 QBoxLayout *hl = new QHBoxLayout(this);
236 hl->setSpacing(10);
237 kcfg_minimizeLock_label = new QLabel(i18n("auto-lock on minimize:"), this);
238 hl->addWidget(kcfg_minimizeLock_label);
239 kcfg_minimizeLock = new QComboBox(this, "kcfg_minimizeLock");
240 hl->addStretch();
241 hl->addWidget(kcfg_minimizeLock);
242 kcfg_minimizeLock->insertItem(i18n("don't lock"));
243 kcfg_minimizeLock->insertItem(i18n("normal lock"));
244 kcfg_minimizeLock->insertItem(i18n("deep-lock"));
245 l->addLayout(hl);
246 l->addStretch();
247}
248
249
250/*********************************************************
251 ** class ConfPageLookNFeel **
252 *********************************************************/
253
254ConfPageLookNFeel::ConfPageLookNFeel(QWidget *parent, const char *name, WFlags f)
255 : QWidget(parent, name, f)
256{
257 QComboBox *kcfg_MainViewStyle;
258 QLabel *kcfg_MainViewStyle_label;
259 KFontRequester *kcfg_entryFont;
260 QGroupBox *kcfg_entryFont_box;
261
262 QBoxLayout *l = new QVBoxLayout(this);
263 l->setSpacing(10);
264 // font
265 kcfg_entryFont_box = new QGroupBox(i18n("Font for the password entries:"), this);
266 l->addWidget(kcfg_entryFont_box);
267 kcfg_entryFont_box->setColumns(1);
268 kcfg_entryFont = new KFontRequester(kcfg_entryFont_box, "kcfg_entryFont", false);
269 // wnd style
270 QBoxLayout *hl = new QHBoxLayout(this);
271 hl->setSpacing(10);
272 kcfg_MainViewStyle_label = new QLabel(i18n("Window-style:"), this);
273 hl->addWidget(kcfg_MainViewStyle_label);
274 kcfg_MainViewStyle = new QComboBox(this, "kcfg_MainViewStyle");
275 hl->addStretch();
276 hl->addWidget(kcfg_MainViewStyle);
277 kcfg_MainViewStyle->insertItem(i18n("Category on top"));
278 kcfg_MainViewStyle->insertItem(i18n("Category-list left"));
279 l->addLayout(hl);
280 l->addStretch();
281}
282
283
284/*********************************************************
285 ** class ConfPageFile **
286 *********************************************************/
287
288ConfPageFile::ConfPageFile(QWidget *parent, const char *name, WFlags f)
289 : QWidget(parent, name, f)
290{
291 QComboBox *kcfg_compression;
292 QLabel *kcfg_compression_label;
293 OctLineEdit *kcfg_filePermissions;
294 QLabel *kcfg_filePermissions_label;
295 QCheckBox *kcfg_makeFileBackup;
296
297 QBoxLayout *l = new QVBoxLayout(this);
298 l->setSpacing(10);
299 // compression
300 QBoxLayout *hl = new QHBoxLayout(this);
301 hl->setSpacing(10);
302 kcfg_compression_label = new QLabel(i18n("*.pwm file compression:"), this);
303 hl->addWidget(kcfg_compression_label);
304 kcfg_compression = new QComboBox(this, "kcfg_compression");
305 hl->addStretch();
306 hl->addWidget(kcfg_compression);
307 kcfg_compression->insertItem(i18n("none"));
308 kcfg_compression->insertItem(i18n("gzip"));
309 kcfg_compression->insertItem(i18n("bzip2"));
310 l->addLayout(hl);
311 // permissions
312 hl = new QHBoxLayout(this);
313 hl->setSpacing(10);
314 kcfg_filePermissions_label = new QLabel(i18n("permissions:"), this);
315 hl->addWidget(kcfg_filePermissions_label);
316 kcfg_filePermissions = new OctLineEdit(this, "kcfg_filePermissions");
317 hl->addStretch();
318 hl->addWidget(kcfg_filePermissions);
319 kcfg_filePermissions->setMaxLength(3);
320 l->addLayout(hl);
321 // backup
322 kcfg_makeFileBackup = new QCheckBox(i18n("Make file backup before saving"),
323 this, "kcfg_makeFileBackup");
324 l->addWidget(kcfg_makeFileBackup);
325 l->addStretch();
326}
327
328
329/*********************************************************
330 ** class ConfPageTimeouts **
331 *********************************************************/
332
333ConfPageTimeouts::ConfPageTimeouts(QWidget *parent, const char *name, WFlags f)
334 : QWidget(parent, name, f)
335{
336 QSpinBox *kcfg_pwTimeout;
337 QLabel *kcfg_pwTimeout_label;
338 QSpinBox *kcfg_lockTimeout;
339 QLabel *kcfg_lockTimeout_label;
340 QCheckBox *kcfg_autoDeepLock;
341
342 QBoxLayout *l = new QVBoxLayout(this);
343 l->setSpacing(10);
344 // pw timeout
345 QBoxLayout *hl = new QHBoxLayout(this);
346 hl->setSpacing(10);
347 kcfg_pwTimeout_label = new QLabel(i18n("Password timeout (timeout to hold "
348 "password in memory, so you don't have "
349 "to re-enter it, if you already have "
350 "entered it) [set to 0 to disable]:"),
351 this);
352 hl->addWidget(kcfg_pwTimeout_label);
353 kcfg_pwTimeout_label->setAlignment(QLabel::WordBreak);
354 kcfg_pwTimeout = new QSpinBox(this, "kcfg_pwTimeout");
355 hl->addStretch();
356 hl->addWidget(kcfg_pwTimeout);
357 l->addLayout(hl);
358 // lock timeout
359 hl = new QHBoxLayout(this);
360 hl->setSpacing(10);
361 kcfg_lockTimeout_label = new QLabel(i18n("Auto-lock timeout (auto lock document "
362 "after this amount of seconds) "
363 "[set to 0 to disable]:"),
364 this);
365 hl->addWidget(kcfg_lockTimeout_label);
366 kcfg_lockTimeout_label->setAlignment(QLabel::WordBreak);
367 kcfg_lockTimeout = new QSpinBox(this, "kcfg_lockTimeout");
368 hl->addStretch();
369 hl->addWidget(kcfg_lockTimeout);
370 l->addLayout(hl);
371 // auto deep lock checkbox
372 kcfg_autoDeepLock = new QCheckBox(i18n("deep-lock on autolock"),
373 this, "kcfg_autoDeepLock");
374 l->addWidget(kcfg_autoDeepLock);
375 l->addStretch();
376}
377
378
379/*********************************************************
380 ** class ConfPageExtApps **
381 *********************************************************/
382
383ConfPageExtApps::ConfPageExtApps(QWidget *parent, const char *name, WFlags f)
384 : QWidget(parent, name, f)
385{
386 QLineEdit *kcfg_browserCommand;
387 QLabel *kcfg_browserCommand_label;
388 QLineEdit *kcfg_xtermCommand;
389 QLabel *kcfg_xtermCommand_label;
390
391 QBoxLayout *l = new QVBoxLayout(this);
392 l->setSpacing(4);
393 // browser command
394 QBoxLayout *hl = new QHBoxLayout(this);
395 hl->setSpacing(10);
396 kcfg_browserCommand_label = new QLabel(i18n("Favourite browser:"), this);
397 hl->addWidget(kcfg_browserCommand_label);
398 kcfg_browserCommand = new QLineEdit(this, "kcfg_browserCommand");
399 hl->addStretch();
400 hl->addWidget(kcfg_browserCommand);
401 l->addLayout(hl);
402 // xterm command
403 hl = new QHBoxLayout(this);
404 hl->setSpacing(10);
405 kcfg_xtermCommand_label = new QLabel(i18n("Favourite X-terminal:"), this);
406 hl->addWidget(kcfg_xtermCommand_label);
407 kcfg_xtermCommand = new QLineEdit(this, "kcfg_xtermCommand");
408 hl->addStretch();
409 hl->addWidget(kcfg_xtermCommand);
410 l->addLayout(hl);
411 l->addStretch();
412}
413
414
415/*********************************************************
416 ** class ConfPageAutostart **
417 *********************************************************/
418
419ConfPageAutostart::ConfPageAutostart(QWidget *parent, const char *name, WFlags f)
420 : QWidget(parent, name, f)
421{
422 QGroupBox *kcfg_autoStart_box;
423 QPushButton *kcfg_autoStart_button;
424 QCheckBox *kcfg_autostartDeeplocked;
425
426 QBoxLayout *l = new QVBoxLayout(this);
427 l->setSpacing(4);
428 // autostart
429 kcfg_autoStart_box = new QGroupBox(i18n("Open this file automatically on startup:"),
430 this);
431 l->addWidget(kcfg_autoStart_box);
432 kcfg_autoStart_box->setColumns(2);
433 kcfg_autoStart = new QLineEdit(kcfg_autoStart_box, "kcfg_autoStart");
434 kcfg_autoStart_button = new QPushButton("...", kcfg_autoStart_box);
435 kcfg_autostartDeeplocked = new QCheckBox(i18n("open deeplocked"),
436 kcfg_autoStart_box, "kcfg_autostartDeeplocked");
437 l->addStretch();
438 // connections
439 connect(kcfg_autoStart_button, SIGNAL(clicked()),
440 this, SLOT(browseButton_slot()));
441}
442
443void ConfPageAutostart::browseButton_slot()
444{
445 QString path(KFileDialog::getOpenFileName(QString::null,
446 i18n("*.pwm|PwM Password file\n"
447 "*|All files"), this));
448 if (path == QString::null)
449 return;
450 kcfg_autoStart->setText(path);
451}
452
453
454#include "configuration.moc"
455
456#else // KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0)
457 /* XXX: This is the code for KDE-3.1 compatibility. */
458# include "configuration_31compat.cpp"
459#endif // KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0)
diff --git a/pwmanager/pwmanager/configuration.h b/pwmanager/pwmanager/configuration.h
new file mode 100644
index 0000000..9001147
--- a/dev/null
+++ b/pwmanager/pwmanager/configuration.h
@@ -0,0 +1,336 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef __CONFIGURATION_H
21#define __CONFIGURATION_H
22
23 #define CONF_DEFAULT_PWTIMEOUT 10/* 10 sec */
24 #define CONF_DEFAULT_LOCKTIMEOUT 0/* 0 == disable */
25 #define CONF_DEFAULT_TRAY true
26 #define CONF_DEFAULT_UNLOCKONOPENfalse
27 #define CONF_DEFAULT_MAINVIEWSTYLE0
28 #define CONF_DEFAULT_COMPRESSION 0x01/* gzip */
29 #define CONF_DEFAULT_AUTOMINIMIZEfalse
30 #define CONF_DEFAULT_BROWSERCOMMAND""
31 #define CONF_DEFAULT_XTERMCOMMAND"konsole -e"
32 #define CONF_DEFAULT_FILEPERMISSIONS0600
33 #define CONF_DEFAULT_MAKEFILEBACKUPfalse
34 #define CONF_DEFAULT_AUTOSTART_DEEPLtrue
35 #define CONF_DEFAULT_AUTODEEPLOCKtrue
36 #define CONF_DEFAULT_KWALLETEMU true
37 #define CONF_DEFAULT_MINIMIZELOCK 2/* deep-lock */
38 #define CONF_DEFAULT_NEWENTRLOCKSTAT true/* locked */
39 #define CONF_DEFAULT_WNDCLOSE true/* don't minimize to tray */
40
41/** This is just because I'm too lazy to always
42 * type this loooong statement, when accessing
43 * configuration parameters.
44 */
45 #define conf()Configuration::obj()
46
47#include <kstandarddirs.h>
48
49#ifndef PWM_EMBEDDED
50#include <kdeversion.h>
51#else
52#define KDE_VERSION 310
53#define KDE_MAKE_VERSION( a,b,c ) (((a) << 16) | ((b) << 8) | (c))
54#endif
55
56// Set this to 1 to debug the 3.1 compatibility interface
57#if 0
58# warning configuration.h KDE_VERSION debugging enabled!
59# undef KDE_VERSION
60 # define KDE_VERSIONKDE_MAKE_VERSION(3, 1, 0)
61#endif
62
63#if !defined(KDE_VERSION) || !defined(KDE_MAKE_VERSION)
64# error "KDE_VERSION or KDE_MAKE_VERSION not defined"
65#endif
66#if KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0)
67
68#ifndef PWM_EMBEDDED
69//MOC_SKIP_BEGIN
70#endif
71
72#include <qstring.h>
73#include <qsize.h>
74#include <qfont.h>
75#include <qwidget.h>
76#include <qvbox.h>
77#include <qhbox.h>
78#include <qlineedit.h>
79
80#include <kconfigskeleton.h>
81
82#include "pwmexception.h"
83
84class QLabel;
85class QGroupBox;
86class QPushButton;
87class QResizeEvent;
88
89/** New global configuration file interface
90 * using KDE-3.2 KConfigSkeleton model.
91 */
92class Configuration
93{
94public:
95 Configuration();
96 ~Configuration();
97
98 static Configuration * obj()
99 {
100 PWM_ASSERT(_obj);
101 return _obj;
102 }
103 static void init()
104 {
105 PWM_ASSERT(!_obj);
106 _obj = new Configuration;
107 }
108 static void cleanup()
109 { delete_ifnot_null(_obj); }
110
111
112 /** Read the configuration from the file.
113 * Normally this function has not to be called manually.
114 */
115 void readConfig()
116 { skel->readConfig(); }
117 /** Write the configuration to the file.
118 * Normally this function has not to be called manually.
119 */
120 void writeConfig()
121 { skel->writeConfig(); }
122 /** reset the whole configuration to its defaults */
123 void resetConfig()
124 { skel->setDefaults(); }
125 /** show the configuration window */
126 bool showConfWnd(QWidget *parent);
127
128public:
129 /* functions for reading the configuration settings */
130 /* GLOBAL */
131 QString confGlobAutoStart()
132 { return cGlobAutoStart; }
133 QString confGlobBrowserCommand()
134 { return cGlobBrowserCommand; }
135 QString confGlobXtermCommand()
136 { return cGlobXtermCommand; }
137 QFont confGlobEntryFont()
138 { return cGlobEntryFont; }
139 int confGlobPwTimeout()
140 { return cGlobPwTimeout; }
141 int confGlobLockTimeout()
142 { return cGlobLockTimeout; }
143 int confGlobCompression()
144 { return cGlobCompression; }
145 int confGlobFilePermissions()
146 { return cGlobFilePermissions; }
147 int confGlobMinimizeLock()
148 { return cGlobMinimizeLock; }
149 bool confGlobUnlockOnOpen()
150 { return cGlobUnlockOnOpen; }
151 bool confGlobTray()
152 { return cGlobTray; }
153 bool confGlobMakeFileBackup()
154 { return cGlobMakeFileBackup; }
155 bool confGlobAutostartDeepLocked()
156 { return cGlobAutostartDeepLocked; }
157 bool confGlobAutoDeepLock()
158 { return cGlobAutoDeepLock; }
159 bool confGlobKwalletEmu()
160 { return cGlobKwalletEmu; }
161 bool confGlobNewEntrLockStat()
162 { return cGlobNewEntrLockStat; }
163 /* WND */
164 QSize confWndMainWndSize()
165 { return cWndMainWndSize; }
166 int confWndMainViewStyle()
167 { return cWndMainViewStyle; }
168 bool confWndAutoMinimizeOnStart()
169 { return cWndAutoMinimizeOnStart; }
170 bool confWndClose()
171 { return cWndClose; }
172
173public:
174 /* functions for writing the configuration settings */
175 /* GLOBAL */
176 void confGlobAutoStart(const QString &e)
177 { cGlobAutoStart = e; }
178 void confGlobBrowserCommand(const QString &e)
179 { cGlobBrowserCommand = e; }
180 void confGlobXtermCommand(const QString &e)
181 { cGlobXtermCommand = e; }
182 void confGlobEntryFont(const QFont &e)
183 { cGlobEntryFont = e; }
184 void confGlobPwTimeout(int e)
185 { cGlobPwTimeout = e; }
186 void confGlobLockTimeout(int e)
187 { cGlobLockTimeout = e; }
188 void confGlobCompression(int e)
189 { cGlobCompression = e; }
190 void confGlobFilePermissions(int e)
191 { cGlobFilePermissions = e; }
192 void confGlobMinimizeLock(int e)
193 { cGlobMinimizeLock = e; }
194 void confGlobUnlockOnOpen(bool e)
195 { cGlobUnlockOnOpen = e; }
196 void confGlobTray(bool e)
197 { cGlobTray = e; }
198 void confGlobMakeFileBackup(bool e)
199 { cGlobMakeFileBackup = e; }
200 void confGlobAutostartDeepLocked(bool e)
201 { cGlobAutostartDeepLocked = e; }
202 void confGlobAutoDeepLock(bool e)
203 { cGlobAutoDeepLock = e; }
204 void confGlobKwalletEmu(bool e)
205 { cGlobKwalletEmu = e; }
206 void confGlobNewEntrLockStat(bool e)
207 { cGlobNewEntrLockStat = e; }
208 /* WND */
209 void confWndMainWndSize(const QSize &e)
210 { cWndMainWndSize = e; }
211 void confWndMainViewStyle(int e)
212 { cWndMainViewStyle = e; }
213 void confWndAutoMinimizeOnStart(bool e)
214 { cWndAutoMinimizeOnStart = e; }
215 void confWndClose(bool e)
216 { cWndClose = e; }
217
218protected:
219 /** initialize the skeleton */
220 void initSkel();
221
222protected:
223 /** static instance of this class returned by obj() */
224 static Configuration *_obj;
225 /** main configuration access skeleton */
226 KConfigSkeleton *skel;
227
228protected:
229 /* configuration variables. All prefixed with 'c'. */
230 /* GLOBAL */
231 QString cGlobAutoStart;
232 QString cGlobBrowserCommand;
233 QString cGlobXtermCommand;
234 QFont cGlobEntryFont;
235 int cGlobPwTimeout;
236 int cGlobLockTimeout;
237 int cGlobCompression;
238 int cGlobFilePermissions;
239 int cGlobMinimizeLock;
240 bool cGlobUnlockOnOpen;
241 bool cGlobTray;
242 bool cGlobMakeFileBackup;
243 bool cGlobAutostartDeepLocked;
244 bool cGlobAutoDeepLock;
245 bool cGlobKwalletEmu;
246 bool cGlobNewEntrLockStat;
247 /* WND */
248 QSize cWndMainWndSize;
249 int cWndMainViewStyle;
250 bool cWndAutoMinimizeOnStart;
251 bool cWndClose;
252};
253
254/* Big fat note: Internal stuff follows.
255 * ============ Don't use the following classes outside of
256 * the Configuration code, because it's unavailable
257 * when compiled under KDE-3.1
258 */
259
260/** class for input of octal numbers (for example file permissions) */
261class OctLineEdit : public QLineEdit
262{
263 Q_OBJECT
264 Q_OVERRIDE( QString text READ text WRITE setText )
265
266public:
267 OctLineEdit(QWidget *parent, const char *name = 0);
268 ~OctLineEdit();
269
270 void setText(const QString &t);
271 QString text() const;
272
273protected:
274 void keyPressEvent(QKeyEvent *e);
275};
276
277/** global configuration page */
278class ConfPageGlobal : public QWidget
279{
280public:
281 ConfPageGlobal(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
282};
283
284/** configuration page for look&feel */
285class ConfPageLookNFeel : public QWidget
286{
287public:
288 ConfPageLookNFeel(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
289};
290
291/** file configuration page */
292class ConfPageFile : public QWidget
293{
294public:
295 ConfPageFile(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
296};
297
298/** timeouts configuration page */
299class ConfPageTimeouts : public QWidget
300{
301public:
302 ConfPageTimeouts(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
303};
304
305/** configuration page for external apps */
306class ConfPageExtApps : public QWidget
307{
308public:
309 ConfPageExtApps(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
310};
311
312/** autostart configuration page */
313class ConfPageAutostart : public QWidget
314{
315 Q_OBJECT
316public:
317 ConfPageAutostart(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
318
319protected slots:
320 void browseButton_slot();
321
322protected:
323 QLineEdit *kcfg_autoStart;
324};
325
326
327#ifndef PWM_EMBEDDED
328//MOC_SKIP_END
329#endif
330
331
332#else // KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0)
333 /* XXX: This is the code for KDE-3.1 compatibility. */
334# include "configuration_31compat.h"
335#endif // KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0)
336#endif // CONFIGURATION_H
diff --git a/pwmanager/pwmanager/configuration_31compat.cpp b/pwmanager/pwmanager/configuration_31compat.cpp
new file mode 100644
index 0000000..ffd522c
--- a/dev/null
+++ b/pwmanager/pwmanager/configuration_31compat.cpp
@@ -0,0 +1,365 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "configuration_31compat.h"
21#include "configwndimpl.h"
22#include "pwmexception.h"
23
24#include <kconfig.h>
25#include <kapplication.h>
26
27#include <qfileinfo.h>
28#include <qcheckbox.h>
29#include <qcombobox.h>
30#include <qspinbox.h>
31#include <qlineedit.h>
32#include <qlabel.h>
33
34#ifdef PWM_EMBEDDED
35#include <qfont.h>
36#include <kglobal.h>
37#endif
38
39Configuration_31compat * Configuration_31compat::_obj (0);
40
41Configuration_31compat::Configuration_31compat()
42{
43#ifndef PWM_EMBEDDED
44 conf = KApplication::kApplication()->config();
45#else
46 conf = KGlobal::config();
47#endif
48}
49
50Configuration_31compat::~Configuration_31compat()
51{
52}
53
54bool Configuration_31compat::showConfWnd(QWidget * /*parent*/)
55{
56 ConfigWndImpl cfgWnd;
57 cfgWnd.pwTimeoutSpinBox->setValue(confGlobPwTimeout());
58 cfgWnd.lockTimeoutSpinBox->setValue(confGlobLockTimeout());
59 cfgWnd.trayCheckBox->setChecked(confGlobTray());
60 cfgWnd.autoStartLineEdit->setText(confGlobAutoStart());
61 cfgWnd.openUnlockedCheckBox->setChecked(confGlobUnlockOnOpen());
62 cfgWnd.currentEntryFont = confGlobEntryFont();
63 cfgWnd.currEntrFont->setText(cfgWnd.currentEntryFont.family());
64 cfgWnd.currEntrFont->setFont(cfgWnd.currentEntryFont);
65 cfgWnd.windowStyleComboBox->setCurrentItem(confWndMainViewStyle());
66 cfgWnd.compressionComboBox->setCurrentItem(confGlobCompression());
67 cfgWnd.autoMinimizeCheckBox->setChecked(confWndAutoMinimizeOnStart());
68 cfgWnd.browserLineEdit->setText(confGlobBrowserCommand());
69 cfgWnd.xtermLineEdit->setText(confGlobXtermCommand());
70 cfgWnd.setFilePermissions(confGlobFilePermissions());
71 cfgWnd.fileBackupCheckBox->setChecked(confGlobMakeFileBackup());
72 cfgWnd.autostartDeeplockedCheckBox->setChecked(confGlobAutostartDeepLocked());
73 cfgWnd.autoDeepLockCheckBox->setChecked(confGlobAutoDeepLock());
74 cfgWnd.minimizeLockComboBox->setCurrentItem(confGlobMinimizeLock());
75 cfgWnd.wndCloseCheckBox->setChecked(confWndClose());
76#ifdef CONFIG_KWALLETIF
77 cfgWnd.kwalletEmuCheckBox->setChecked(confGlobKwalletEmu());
78#else // CONFIG_KWALLETIF
79 cfgWnd.kwalletEmuCheckBox->setChecked(false);
80 cfgWnd.kwalletEmuCheckBox->setEnabled(false);
81#endif // CONFIG_KWALLETIF
82
83 if (cfgWnd.exec())
84 return false;
85
86 confGlobPwTimeout(cfgWnd.pwTimeoutSpinBox->value());
87 confGlobLockTimeout(cfgWnd.lockTimeoutSpinBox->value());
88 confGlobTray(cfgWnd.trayCheckBox->isChecked());
89 confGlobAutoStart(cfgWnd.autoStartLineEdit->text());
90 confGlobUnlockOnOpen(cfgWnd.openUnlockedCheckBox->isChecked());
91 confGlobEntryFont(cfgWnd.currentEntryFont);
92 confWndMainViewStyle(cfgWnd.windowStyleComboBox->currentItem());
93 confGlobCompression(cfgWnd.compressionComboBox->currentItem());
94 confWndAutoMinimizeOnStart(cfgWnd.autoMinimizeCheckBox->isChecked());
95 confGlobBrowserCommand(cfgWnd.browserLineEdit->text());
96 confGlobXtermCommand(cfgWnd.xtermLineEdit->text());
97 confGlobFilePermissions(cfgWnd.getFilePermissions());
98 confGlobMakeFileBackup(cfgWnd.fileBackupCheckBox->isChecked());
99 confGlobAutostartDeepLocked(cfgWnd.
100 autostartDeeplockedCheckBox->isChecked());
101 confGlobAutoDeepLock(cfgWnd.autoDeepLockCheckBox->isChecked());
102 confGlobMinimizeLock(cfgWnd.minimizeLockComboBox->currentItem());
103 confWndClose(cfgWnd.wndCloseCheckBox->isChecked());
104#ifdef CONFIG_KWALLETIF
105 confGlobKwalletEmu(cfgWnd.kwalletEmuCheckBox->isChecked());
106#endif // CONFIG_KWALLETIF
107 return true;
108}
109
110/*******************************************************************
111 * functions for reading the configuration settings
112 *******************************************************************/
113
114QString Configuration_31compat::confGlobAutoStart()
115{
116 conf->setGroup("GLOBAL");
117 return conf->readEntry("autoStart");
118}
119
120QString Configuration_31compat::confGlobBrowserCommand()
121{
122 conf->setGroup("GLOBAL");
123 return conf->readEntry("browserCommand", CONF_DEFAULT_BROWSERCOMMAND);
124}
125
126QString Configuration_31compat::confGlobXtermCommand()
127{
128 conf->setGroup("GLOBAL");
129 return conf->readEntry("xtermCommand", CONF_DEFAULT_XTERMCOMMAND);
130}
131
132QFont Configuration_31compat::confGlobEntryFont()
133{
134 conf->setGroup("GLOBAL");
135#ifndef PWM_EMBEDDED
136 return conf->readFontEntry("entryFont");
137#else
138 QFont f;
139 return conf->readFontEntry("entryFont", &f);
140#endif
141}
142
143int Configuration_31compat::confGlobPwTimeout()
144{
145 conf->setGroup("GLOBAL");
146 return conf->readNumEntry("pwTimeout", CONF_DEFAULT_PWTIMEOUT);
147}
148
149int Configuration_31compat::confGlobLockTimeout()
150{
151 conf->setGroup("GLOBAL");
152 return conf->readNumEntry("lockTimeout", CONF_DEFAULT_LOCKTIMEOUT);
153}
154
155int Configuration_31compat::confGlobCompression()
156{
157 conf->setGroup("GLOBAL");
158 return conf->readNumEntry("compression", CONF_DEFAULT_COMPRESSION);
159}
160
161int Configuration_31compat::confGlobFilePermissions()
162{
163 conf->setGroup("GLOBAL");
164 return conf->readNumEntry("filePermissions", CONF_DEFAULT_FILEPERMISSIONS);
165}
166
167int Configuration_31compat::confGlobMinimizeLock()
168{
169 conf->setGroup("GLOBAL");
170 return conf->readNumEntry("minimizeLock", CONF_DEFAULT_MINIMIZELOCK);
171}
172
173bool Configuration_31compat::confGlobUnlockOnOpen()
174{
175 conf->setGroup("GLOBAL");
176 return conf->readBoolEntry("unlockOnOpen", CONF_DEFAULT_UNLOCKONOPEN);
177}
178
179bool Configuration_31compat::confGlobTray()
180{
181 conf->setGroup("GLOBAL");
182 return conf->readBoolEntry("tray", CONF_DEFAULT_TRAY);
183}
184
185bool Configuration_31compat::confGlobMakeFileBackup()
186{
187 conf->setGroup("GLOBAL");
188 return conf->readBoolEntry("makeFileBackup", CONF_DEFAULT_MAKEFILEBACKUP);
189}
190
191bool Configuration_31compat::confGlobAutostartDeepLocked()
192{
193 conf->setGroup("GLOBAL");
194 return conf->readBoolEntry("autostartDeeplocked", CONF_DEFAULT_AUTOSTART_DEEPL);
195}
196
197bool Configuration_31compat::confGlobAutoDeepLock()
198{
199 conf->setGroup("GLOBAL");
200 return conf->readBoolEntry("autoDeepLock", CONF_DEFAULT_AUTODEEPLOCK);
201}
202
203bool Configuration_31compat::confGlobKwalletEmu()
204{
205 conf->setGroup("GLOBAL");
206 return conf->readBoolEntry("kwalletEmu", CONF_DEFAULT_KWALLETEMU);
207}
208
209bool Configuration_31compat::confGlobNewEntrLockStat()
210{
211 conf->setGroup("GLOBAL");
212 return conf->readBoolEntry("newEntrLockStat", CONF_DEFAULT_NEWENTRLOCKSTAT);
213}
214
215QSize Configuration_31compat::confWndMainWndSize()
216{
217 conf->setGroup("WND");
218#ifndef PWM_EMBEDDED
219 return conf->readSizeEntry("MainWndSize");
220#else
221 return conf->readSizeEntry("MainWndSize", 0);
222#endif
223}
224
225int Configuration_31compat::confWndMainViewStyle()
226{
227 conf->setGroup("WND");
228 return conf->readNumEntry("MainViewStyle", CONF_DEFAULT_MAINVIEWSTYLE);
229}
230
231bool Configuration_31compat::confWndAutoMinimizeOnStart()
232{
233 conf->setGroup("WND");
234 return conf->readBoolEntry("autoMinimizeOnStart", CONF_DEFAULT_AUTOMINIMIZE);
235}
236
237bool Configuration_31compat::confWndClose()
238{
239 conf->setGroup("WND");
240 return conf->readBoolEntry("close", CONF_DEFAULT_WNDCLOSE);
241}
242
243/*******************************************************************
244 * functions for writing the configuration settings
245 *******************************************************************/
246
247void Configuration_31compat::confGlobAutoStart(const QString &e)
248{
249 conf->setGroup("GLOBAL");
250 conf->writeEntry("autoStart", e);
251}
252
253void Configuration_31compat::confGlobBrowserCommand(const QString &e)
254{
255 conf->setGroup("GLOBAL");
256 conf->writeEntry("browserCommand", e);
257}
258
259void Configuration_31compat::confGlobXtermCommand(const QString &e)
260{
261 conf->setGroup("GLOBAL");
262 conf->writeEntry("xtermCommand", e);
263}
264
265void Configuration_31compat::confGlobEntryFont(const QFont &e)
266{
267 conf->setGroup("GLOBAL");
268 conf->writeEntry("entryFont", e);
269}
270
271void Configuration_31compat::confGlobPwTimeout(int e)
272{
273 conf->setGroup("GLOBAL");
274 conf->writeEntry("pwTimeout", e);
275}
276
277void Configuration_31compat::confGlobLockTimeout(int e)
278{
279 conf->setGroup("GLOBAL");
280 conf->writeEntry("lockTimeout", e);
281}
282
283void Configuration_31compat::confGlobCompression(int e)
284{
285 conf->setGroup("GLOBAL");
286 conf->writeEntry("compression", e);
287}
288
289void Configuration_31compat::confGlobFilePermissions(int e)
290{
291 conf->setGroup("GLOBAL");
292 conf->writeEntry("filePermissions", e);
293}
294
295void Configuration_31compat::confGlobMinimizeLock(int e)
296{
297 conf->setGroup("GLOBAL");
298 conf->writeEntry("minimizeLock", e);
299}
300
301void Configuration_31compat::confGlobUnlockOnOpen(bool e)
302{
303 conf->setGroup("GLOBAL");
304 conf->writeEntry("unlockOnOpen", e);
305}
306
307void Configuration_31compat::confGlobTray(bool e)
308{
309 conf->setGroup("GLOBAL");
310 conf->writeEntry("tray", e);
311}
312
313void Configuration_31compat::confGlobMakeFileBackup(bool e)
314{
315 conf->setGroup("GLOBAL");
316 conf->writeEntry("makeFileBackup", e);
317}
318
319void Configuration_31compat::confGlobAutostartDeepLocked(bool e)
320{
321 conf->setGroup("GLOBAL");
322 conf->writeEntry("autostartDeeplocked", e);
323}
324
325void Configuration_31compat::confGlobAutoDeepLock(bool e)
326{
327 conf->setGroup("GLOBAL");
328 conf->writeEntry("autoDeepLock", e);
329}
330
331void Configuration_31compat::confGlobKwalletEmu(bool e)
332{
333 conf->setGroup("GLOBAL");
334 conf->writeEntry("kwalletEmu", e);
335}
336
337void Configuration_31compat::confGlobNewEntrLockStat(bool e)
338{
339 conf->setGroup("GLOBAL");
340 conf->writeEntry("newEntrLockStat", e);
341}
342
343void Configuration_31compat::confWndMainWndSize(const QSize &e)
344{
345 conf->setGroup("WND");
346 conf->writeEntry("MainWndSize", e);
347}
348
349void Configuration_31compat::confWndMainViewStyle(int e)
350{
351 conf->setGroup("WND");
352 conf->writeEntry("MainViewStyle", e);
353}
354
355void Configuration_31compat::confWndAutoMinimizeOnStart(bool e)
356{
357 conf->setGroup("WND");
358 conf->writeEntry("autoMinimizeOnStart", e);
359}
360
361void Configuration_31compat::confWndClose(bool e)
362{
363 conf->setGroup("WND");
364 conf->writeEntry("close", e);
365}
diff --git a/pwmanager/pwmanager/configuration_31compat.h b/pwmanager/pwmanager/configuration_31compat.h
new file mode 100644
index 0000000..8ad6e09
--- a/dev/null
+++ b/pwmanager/pwmanager/configuration_31compat.h
@@ -0,0 +1,146 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef CONFIGURATION_31COMPAT_H
21#define CONFIGURATION_31COMPAT_H
22
23#include "pwmexception.h"
24
25#include <qsize.h>
26#include <qfont.h>
27#include <qstring.h>
28
29#ifdef PWM_EMBEDDED
30#include <configuration.h>
31#endif
32
33class KConfig;
34
35/** This class is the compatibility layer for
36 * running the new KDE-3.2 Configuration interface on KDE-3.1.
37 * We have to keep this class in sync with the real configuration
38 * interface.
39 */
40class Configuration_31compat
41{
42public:
43 Configuration_31compat();
44 ~Configuration_31compat();
45
46 static Configuration_31compat * obj()
47 {
48 PWM_ASSERT(_obj);
49 return _obj;
50 }
51 static void init()
52 {
53 PWM_ASSERT(!_obj);
54 _obj = new Configuration_31compat;
55 }
56 static void cleanup()
57 { delete_ifnot_null(_obj); }
58
59
60 /** Read the configuration from the file.
61 * Normally this function has not to be called manually.
62 *
63 * This function is a NOP in KDE-3.1 compatibility layer.
64 */
65 void readConfig()
66 { }
67 /** Write the configuration to the file.
68 * Normally this function has not to be called manually.
69 *
70 * This function is a NOP in KDE-3.1 compatibility layer.
71 */
72 void writeConfig()
73 { }
74 /** reset the whole configuration to its defaults.
75 *
76 * This function is a NOP in KDE-3.1 compatibility layer.
77 * It should not be, but it is. :)
78 */
79 void resetConfig()
80 { }
81 /** show the configuration window */
82 bool showConfWnd(QWidget *parent);
83
84public:
85 /* functions for reading the configuration settings */
86 /* GLOBAL */
87 QString confGlobAutoStart();
88 QString confGlobBrowserCommand();
89 QString confGlobXtermCommand();
90 QFont confGlobEntryFont();
91 int confGlobPwTimeout();
92 int confGlobLockTimeout();
93 int confGlobCompression();
94 int confGlobFilePermissions();
95 int confGlobMinimizeLock();
96 bool confGlobUnlockOnOpen();
97 bool confGlobTray();
98 bool confGlobMakeFileBackup();
99 bool confGlobAutostartDeepLocked();
100 bool confGlobAutoDeepLock();
101 bool confGlobKwalletEmu();
102 bool confGlobNewEntrLockStat();
103 /* WND */
104 QSize confWndMainWndSize();
105 int confWndMainViewStyle();
106 bool confWndAutoMinimizeOnStart();
107 bool confWndClose();
108
109public:
110 /* functions for writing the configuration settings */
111 /* GLOBAL */
112 void confGlobAutoStart(const QString &e);
113 void confGlobBrowserCommand(const QString &e);
114 void confGlobXtermCommand(const QString &e);
115 void confGlobEntryFont(const QFont &e);
116 void confGlobPwTimeout(int e);
117 void confGlobLockTimeout(int e);
118 void confGlobCompression(int e);
119 void confGlobFilePermissions(int e);
120 void confGlobMinimizeLock(int e);
121 void confGlobUnlockOnOpen(bool e);
122 void confGlobTray(bool e);
123 void confGlobMakeFileBackup(bool e);
124 void confGlobAutostartDeepLocked(bool e);
125 void confGlobAutoDeepLock(bool e);
126 void confGlobKwalletEmu(bool e);
127 void confGlobNewEntrLockStat(bool e);
128 /* WND */
129 void confWndMainWndSize(const QSize &e);
130 void confWndMainViewStyle(int e);
131 void confWndAutoMinimizeOnStart(bool e);
132 void confWndClose(bool e);
133
134protected:
135 /** static instance of this class returned by obj() */
136 static Configuration_31compat *_obj;
137 /** configuration object */
138 KConfig *conf;
139};
140
141#ifdef Configuration
142# error "Configuration already defined!"
143#endif
144 #define ConfigurationConfiguration_31compat
145
146#endif
diff --git a/pwmanager/pwmanager/configwnd.cpp b/pwmanager/pwmanager/configwnd.cpp
new file mode 100644
index 0000000..230ca1b
--- a/dev/null
+++ b/pwmanager/pwmanager/configwnd.cpp
@@ -0,0 +1,264 @@
1/****************************************************************************
2** Form implementation generated from reading ui file 'configwnd.ui'
3**
4** Created: Tue Sep 14 15:20:58 2004
5** by: The User Interface Compiler ($Id$)
6**
7** WARNING! All changes made in this file will be lost!
8****************************************************************************/
9
10#include "configwnd.h"
11
12#include <qvariant.h>
13#include <qpushbutton.h>
14#include <qtabwidget.h>
15#include <qwidget.h>
16#include <qcombobox.h>
17#include <qlabel.h>
18#include <qlineedit.h>
19#include <qcheckbox.h>
20#include <qspinbox.h>
21#include <qlayout.h>
22#include <qtooltip.h>
23#include <qwhatsthis.h>
24
25/*
26 * Constructs a configWnd as a child of 'parent', with the
27 * name 'name' and widget flags set to 'f'.
28 *
29 * The dialog will by default be modeless, unless you set 'modal' to
30 * TRUE to construct a modal dialog.
31 */
32configWnd::configWnd( QWidget* parent, const char* name, bool modal, WFlags fl )
33 : QDialog( parent, name, modal, fl )
34{
35 if ( !name )
36 setName( "configWnd" );
37
38 okButton = new QPushButton( this, "okButton" );
39 okButton->setGeometry( QRect( 10, 280, 107, 27 ) );
40
41 cancelButton = new QPushButton( this, "cancelButton" );
42 cancelButton->setGeometry( QRect( 370, 280, 107, 27 ) );
43
44 tabWidget2 = new QTabWidget( this, "tabWidget2" );
45 tabWidget2->setGeometry( QRect( 10, 10, 470, 260 ) );
46
47 tab = new QWidget( tabWidget2, "tab" );
48
49 windowStyleComboBox = new QComboBox( FALSE, tab, "windowStyleComboBox" );
50 windowStyleComboBox->setGeometry( QRect( 220, 180, 210, 28 ) );
51
52 textLabel1_5 = new QLabel( tab, "textLabel1_5" );
53 textLabel1_5->setGeometry( QRect( 30, 180, 180, 20 ) );
54 textLabel1_5->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
55
56 textLabel1_4 = new QLabel( tab, "textLabel1_4" );
57 textLabel1_4->setGeometry( QRect( 30, 40, 400, 20 ) );
58
59 selEntrFontButton = new QPushButton( tab, "selEntrFontButton" );
60 selEntrFontButton->setGeometry( QRect( 30, 90, 160, 27 ) );
61
62 currEntrFont = new QLabel( tab, "currEntrFont" );
63 currEntrFont->setGeometry( QRect( 30, 70, 230, 20 ) );
64 tabWidget2->insertTab( tab, QString("") );
65
66 TabPage = new QWidget( tabWidget2, "TabPage" );
67
68 compressionComboBox = new QComboBox( FALSE, TabPage, "compressionComboBox" );
69 compressionComboBox->setGeometry( QRect( 290, 50, 150, 28 ) );
70
71 textLabel1_6 = new QLabel( TabPage, "textLabel1_6" );
72 textLabel1_6->setGeometry( QRect( 10, 50, 270, 20 ) );
73 textLabel1_6->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
74
75 textLabel1_8 = new QLabel( TabPage, "textLabel1_8" );
76 textLabel1_8->setGeometry( QRect( 10, 90, 270, 20 ) );
77 textLabel1_8->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
78
79 permissionLineEdit = new QLineEdit( TabPage, "permissionLineEdit" );
80 permissionLineEdit->setGeometry( QRect( 290, 90, 142, 27 ) );
81 permissionLineEdit->setMaxLength( 3 );
82
83 fileBackupCheckBox = new QCheckBox( TabPage, "fileBackupCheckBox" );
84 fileBackupCheckBox->setGeometry( QRect( 80, 140, 360, 23 ) );
85 tabWidget2->insertTab( TabPage, QString("") );
86
87 tab_2 = new QWidget( tabWidget2, "tab_2" );
88
89 pwTimeoutSpinBox = new QSpinBox( tab_2, "pwTimeoutSpinBox" );
90 pwTimeoutSpinBox->setGeometry( QRect( 390, 50, 55, 23 ) );
91
92 textLabel1 = new QLabel( tab_2, "textLabel1" );
93 textLabel1->setGeometry( QRect( 10, 20, 370, 80 ) );
94 textLabel1->setAlignment( int( QLabel::WordBreak | QLabel::AlignVCenter ) );
95
96 textLabel1_7 = new QLabel( tab_2, "textLabel1_7" );
97 textLabel1_7->setGeometry( QRect( 10, 110, 370, 80 ) );
98 textLabel1_7->setAlignment( int( QLabel::WordBreak | QLabel::AlignVCenter ) );
99
100 lockTimeoutSpinBox = new QSpinBox( tab_2, "lockTimeoutSpinBox" );
101 lockTimeoutSpinBox->setGeometry( QRect( 390, 140, 55, 23 ) );
102
103 autoDeepLockCheckBox = new QCheckBox( tab_2, "autoDeepLockCheckBox" );
104 autoDeepLockCheckBox->setGeometry( QRect( 60, 180, 380, 25 ) );
105 tabWidget2->insertTab( tab_2, QString("") );
106
107 tab_3 = new QWidget( tabWidget2, "tab_3" );
108
109 textLabel1_3 = new QLabel( tab_3, "textLabel1_3" );
110 textLabel1_3->setGeometry( QRect( 30, 30, 400, 20 ) );
111
112 autoStartLineEdit = new QLineEdit( tab_3, "autoStartLineEdit" );
113 autoStartLineEdit->setGeometry( QRect( 30, 50, 360, 20 ) );
114
115 browseAutoStButton = new QPushButton( tab_3, "browseAutoStButton" );
116 browseAutoStButton->setGeometry( QRect( 400, 50, 30, 20 ) );
117
118 autostartDeeplockedCheckBox = new QCheckBox( tab_3, "autostartDeeplockedCheckBox" );
119 autostartDeeplockedCheckBox->setGeometry( QRect( 40, 80, 390, 25 ) );
120 tabWidget2->insertTab( tab_3, QString("") );
121
122 tab_4 = new QWidget( tabWidget2, "tab_4" );
123
124 textLabel2 = new QLabel( tab_4, "textLabel2" );
125 textLabel2->setGeometry( QRect( 20, 40, 280, 20 ) );
126 textLabel2->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
127
128 browserLineEdit = new QLineEdit( tab_4, "browserLineEdit" );
129 browserLineEdit->setGeometry( QRect( 310, 40, 130, 27 ) );
130
131 xtermLineEdit = new QLineEdit( tab_4, "xtermLineEdit" );
132 xtermLineEdit->setGeometry( QRect( 310, 100, 130, 27 ) );
133
134 textLabel3 = new QLabel( tab_4, "textLabel3" );
135 textLabel3->setGeometry( QRect( 20, 100, 280, 20 ) );
136 textLabel3->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
137 tabWidget2->insertTab( tab_4, QString("") );
138
139 tab_5 = new QWidget( tabWidget2, "tab_5" );
140
141 trayCheckBox = new QCheckBox( tab_5, "trayCheckBox" );
142 trayCheckBox->setGeometry( QRect( 30, 30, 400, 20 ) );
143
144 openUnlockedCheckBox = new QCheckBox( tab_5, "openUnlockedCheckBox" );
145 openUnlockedCheckBox->setGeometry( QRect( 30, 80, 400, 20 ) );
146
147 autoMinimizeCheckBox = new QCheckBox( tab_5, "autoMinimizeCheckBox" );
148 autoMinimizeCheckBox->setEnabled( FALSE );
149 autoMinimizeCheckBox->setGeometry( QRect( 50, 50, 380, 25 ) );
150
151 minimizeLockComboBox = new QComboBox( FALSE, tab_5, "minimizeLockComboBox" );
152 minimizeLockComboBox->setGeometry( QRect( 310, 170, 120, 27 ) );
153
154 textLabel1_9 = new QLabel( tab_5, "textLabel1_9" );
155 textLabel1_9->setGeometry( QRect( 30, 180, 270, 20 ) );
156 textLabel1_9->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
157
158 kwalletEmuCheckBox = new QCheckBox( tab_5, "kwalletEmuCheckBox" );
159 kwalletEmuCheckBox->setGeometry( QRect( 30, 110, 400, 25 ) );
160
161 wndCloseCheckBox = new QCheckBox( tab_5, "wndCloseCheckBox" );
162 wndCloseCheckBox->setGeometry( QRect( 30, 140, 430, 24 ) );
163 tabWidget2->insertTab( tab_5, QString("") );
164 languageChange();
165 resize( QSize(490, 318).expandedTo(minimumSizeHint()) );
166 clearWState( WState_Polished );
167
168 // signals and slots connections
169 connect( okButton, SIGNAL( clicked() ), this, SLOT( okButton_slot() ) );
170 connect( cancelButton, SIGNAL( clicked() ), this, SLOT( cancelButton_slot() ) );
171 connect( browseAutoStButton, SIGNAL( clicked() ), this, SLOT( browseAutoStButton_slot() ) );
172 connect( selEntrFontButton, SIGNAL( clicked() ), this, SLOT( selEntrFontButton_slot() ) );
173 connect( trayCheckBox, SIGNAL( toggled(bool) ), autoMinimizeCheckBox, SLOT( setEnabled(bool) ) );
174
175 // tab order
176 setTabOrder( pwTimeoutSpinBox, trayCheckBox );
177 setTabOrder( trayCheckBox, okButton );
178 setTabOrder( okButton, cancelButton );
179}
180
181/*
182 * Destroys the object and frees any allocated resources
183 */
184configWnd::~configWnd()
185{
186 // no need to delete child widgets, Qt does it all for us
187}
188
189/*
190 * Sets the strings of the subwidgets using the current
191 * language.
192 */
193void configWnd::languageChange()
194{
195 setCaption( tr( "PwManager Configuration" ) );
196 okButton->setText( tr( "&OK" ) );
197 //US ENH okButton->setAccel( QKeySequence( tr( "Alt+O" ) ) );
198 cancelButton->setText( tr( "&Cancel" ) );
199 //US ENH cancelButton->setAccel( QKeySequence( tr( "Alt+C" ) ) );
200 windowStyleComboBox->clear();
201 windowStyleComboBox->insertItem( tr( "Category on top" ) );
202 windowStyleComboBox->insertItem( tr( "Category-list left" ) );
203 textLabel1_5->setText( tr( "Window-style:" ) );
204 textLabel1_4->setText( tr( "Font for the password entries:" ) );
205 selEntrFontButton->setText( tr( "select Font" ) );
206 currEntrFont->setText( QString::null );
207 tabWidget2->changeTab( tab, tr( "Look && feel" ) );
208 compressionComboBox->clear();
209 compressionComboBox->insertItem( tr( "none" ) );
210 compressionComboBox->insertItem( tr( "gzip" ) );
211 compressionComboBox->insertItem( tr( "bzip2" ) );
212 textLabel1_6->setText( tr( "*.pwm file compression:" ) );
213 textLabel1_8->setText( tr( "permissions:" ) );
214 fileBackupCheckBox->setText( tr( "Make file backup before saving" ) );
215 tabWidget2->changeTab( TabPage, tr( "File" ) );
216 textLabel1->setText( tr( "Password timeout (timeout to hold password in memory, so you don't have to re-enter it, if you already have entered it) [set to 0 to disable]:" ) );
217 textLabel1_7->setText( tr( "Auto-lock timeout (auto lock document after this amount of seconds) [set to 0 to disable]:" ) );
218 autoDeepLockCheckBox->setText( tr( "deep-lock on autolock" ) );
219 tabWidget2->changeTab( tab_2, tr( "Timeout" ) );
220 textLabel1_3->setText( tr( "Open this file automatically on startup:" ) );
221 browseAutoStButton->setText( tr( "..." ) );
222 autostartDeeplockedCheckBox->setText( tr( "open deeplocked" ) );
223 tabWidget2->changeTab( tab_3, tr( "Autostart" ) );
224 textLabel2->setText( tr( "Favourite browser:" ) );
225 textLabel3->setText( tr( "Favourite X-terminal:" ) );
226 tabWidget2->changeTab( tab_4, tr( "External apps" ) );
227 trayCheckBox->setText( tr( "Show icon in system-tray" ) );
228 openUnlockedCheckBox->setText( tr( "Open document with passwords unlocked" ) );
229 autoMinimizeCheckBox->setText( tr( "auto-minimize to tray on startup" ) );
230 minimizeLockComboBox->clear();
231 minimizeLockComboBox->insertItem( tr( "don't lock" ) );
232 minimizeLockComboBox->insertItem( tr( "normal lock" ) );
233 minimizeLockComboBox->insertItem( tr( "deep-lock" ) );
234 textLabel1_9->setText( tr( "auto-lock on minimize:" ) );
235 kwalletEmuCheckBox->setText( tr( "KWallet emulation" ) );
236 wndCloseCheckBox->setText( tr( "Do not minimize windows into tray. (Close the window)" ) );
237 tabWidget2->changeTab( tab_5, tr( "Miscellaneous" ) );
238}
239
240void configWnd::okButton_slot()
241{
242 qWarning( "configWnd::okButton_slot(): Not implemented yet" );
243}
244
245void configWnd::cancelButton_slot()
246{
247 qWarning( "configWnd::cancelButton_slot(): Not implemented yet" );
248}
249
250void configWnd::browseBgButton_slot()
251{
252 qWarning( "configWnd::browseBgButton_slot(): Not implemented yet" );
253}
254
255void configWnd::browseAutoStButton_slot()
256{
257 qWarning( "configWnd::browseAutoStButton_slot(): Not implemented yet" );
258}
259
260void configWnd::selEntrFontButton_slot()
261{
262 qWarning( "configWnd::selEntrFontButton_slot(): Not implemented yet" );
263}
264
diff --git a/pwmanager/pwmanager/configwnd.h b/pwmanager/pwmanager/configwnd.h
new file mode 100644
index 0000000..608a38b
--- a/dev/null
+++ b/pwmanager/pwmanager/configwnd.h
@@ -0,0 +1,91 @@
1/****************************************************************************
2** Form interface generated from reading ui file 'configwnd.ui'
3**
4** Created: Tue Sep 14 15:20:50 2004
5** by: The User Interface Compiler ($Id$)
6**
7** WARNING! All changes made in this file will be lost!
8****************************************************************************/
9
10#ifndef CONFIGWND_H
11#define CONFIGWND_H
12
13#include <qvariant.h>
14#include <qdialog.h>
15
16class QVBoxLayout;
17class QHBoxLayout;
18class QGridLayout;
19class QSpacerItem;
20class QPushButton;
21class QTabWidget;
22class QWidget;
23class QComboBox;
24class QLabel;
25class QLineEdit;
26class QCheckBox;
27class QSpinBox;
28
29class configWnd : public QDialog
30{
31 Q_OBJECT
32
33public:
34 configWnd( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
35 ~configWnd();
36
37 QPushButton* okButton;
38 QPushButton* cancelButton;
39 QTabWidget* tabWidget2;
40 QWidget* tab;
41 QComboBox* windowStyleComboBox;
42 QLabel* textLabel1_5;
43 QLabel* textLabel1_4;
44 QPushButton* selEntrFontButton;
45 QLabel* currEntrFont;
46 QWidget* TabPage;
47 QComboBox* compressionComboBox;
48 QLabel* textLabel1_6;
49 QLabel* textLabel1_8;
50 QLineEdit* permissionLineEdit;
51 QCheckBox* fileBackupCheckBox;
52 QWidget* tab_2;
53 QSpinBox* pwTimeoutSpinBox;
54 QLabel* textLabel1;
55 QLabel* textLabel1_7;
56 QSpinBox* lockTimeoutSpinBox;
57 QCheckBox* autoDeepLockCheckBox;
58 QWidget* tab_3;
59 QLabel* textLabel1_3;
60 QLineEdit* autoStartLineEdit;
61 QPushButton* browseAutoStButton;
62 QCheckBox* autostartDeeplockedCheckBox;
63 QWidget* tab_4;
64 QLabel* textLabel2;
65 QLineEdit* browserLineEdit;
66 QLineEdit* xtermLineEdit;
67 QLabel* textLabel3;
68 QWidget* tab_5;
69 QCheckBox* trayCheckBox;
70 QCheckBox* openUnlockedCheckBox;
71 QCheckBox* autoMinimizeCheckBox;
72 QComboBox* minimizeLockComboBox;
73 QLabel* textLabel1_9;
74 QCheckBox* kwalletEmuCheckBox;
75 QCheckBox* wndCloseCheckBox;
76
77public slots:
78 virtual void okButton_slot();
79 virtual void cancelButton_slot();
80 virtual void browseBgButton_slot();
81 virtual void browseAutoStButton_slot();
82 virtual void selEntrFontButton_slot();
83
84protected:
85
86protected slots:
87 virtual void languageChange();
88
89};
90
91#endif // CONFIGWND_H
diff --git a/pwmanager/pwmanager/configwnd.ui b/pwmanager/pwmanager/configwnd.ui
new file mode 100644
index 0000000..9e8d520
--- a/dev/null
+++ b/pwmanager/pwmanager/configwnd.ui
@@ -0,0 +1,687 @@
1<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
2<class>configWnd</class>
3<widget class="QDialog">
4 <property name="name">
5 <cstring>configWnd</cstring>
6 </property>
7 <property name="geometry">
8 <rect>
9 <x>0</x>
10 <y>0</y>
11 <width>490</width>
12 <height>318</height>
13 </rect>
14 </property>
15 <property name="caption">
16 <string>PwManager Configuration</string>
17 </property>
18 <widget class="QPushButton">
19 <property name="name">
20 <cstring>okButton</cstring>
21 </property>
22 <property name="geometry">
23 <rect>
24 <x>10</x>
25 <y>280</y>
26 <width>107</width>
27 <height>27</height>
28 </rect>
29 </property>
30 <property name="text">
31 <string>&amp;OK</string>
32 </property>
33 <property name="accel">
34 <string>Alt+O</string>
35 </property>
36 </widget>
37 <widget class="QPushButton">
38 <property name="name">
39 <cstring>cancelButton</cstring>
40 </property>
41 <property name="geometry">
42 <rect>
43 <x>370</x>
44 <y>280</y>
45 <width>107</width>
46 <height>27</height>
47 </rect>
48 </property>
49 <property name="text">
50 <string>&amp;Cancel</string>
51 </property>
52 <property name="accel">
53 <string>Alt+C</string>
54 </property>
55 </widget>
56 <widget class="QTabWidget">
57 <property name="name">
58 <cstring>tabWidget2</cstring>
59 </property>
60 <property name="geometry">
61 <rect>
62 <x>10</x>
63 <y>10</y>
64 <width>470</width>
65 <height>260</height>
66 </rect>
67 </property>
68 <widget class="QWidget">
69 <property name="name">
70 <cstring>tab</cstring>
71 </property>
72 <attribute name="title">
73 <string>Look &amp;&amp; feel</string>
74 </attribute>
75 <widget class="QComboBox">
76 <item>
77 <property name="text">
78 <string>Category on top</string>
79 </property>
80 </item>
81 <item>
82 <property name="text">
83 <string>Category-list left</string>
84 </property>
85 </item>
86 <property name="name">
87 <cstring>windowStyleComboBox</cstring>
88 </property>
89 <property name="geometry">
90 <rect>
91 <x>220</x>
92 <y>180</y>
93 <width>210</width>
94 <height>28</height>
95 </rect>
96 </property>
97 </widget>
98 <widget class="QLabel">
99 <property name="name">
100 <cstring>textLabel1_5</cstring>
101 </property>
102 <property name="geometry">
103 <rect>
104 <x>30</x>
105 <y>180</y>
106 <width>180</width>
107 <height>20</height>
108 </rect>
109 </property>
110 <property name="text">
111 <string>Window-style:</string>
112 </property>
113 <property name="alignment">
114 <set>AlignVCenter|AlignRight</set>
115 </property>
116 </widget>
117 <widget class="QLabel">
118 <property name="name">
119 <cstring>textLabel1_4</cstring>
120 </property>
121 <property name="geometry">
122 <rect>
123 <x>30</x>
124 <y>40</y>
125 <width>400</width>
126 <height>20</height>
127 </rect>
128 </property>
129 <property name="text">
130 <string>Font for the password entries:</string>
131 </property>
132 </widget>
133 <widget class="QPushButton">
134 <property name="name">
135 <cstring>selEntrFontButton</cstring>
136 </property>
137 <property name="geometry">
138 <rect>
139 <x>30</x>
140 <y>90</y>
141 <width>160</width>
142 <height>27</height>
143 </rect>
144 </property>
145 <property name="text">
146 <string>select Font</string>
147 </property>
148 </widget>
149 <widget class="QLabel">
150 <property name="name">
151 <cstring>currEntrFont</cstring>
152 </property>
153 <property name="geometry">
154 <rect>
155 <x>30</x>
156 <y>70</y>
157 <width>230</width>
158 <height>20</height>
159 </rect>
160 </property>
161 <property name="text">
162 <string></string>
163 </property>
164 </widget>
165 </widget>
166 <widget class="QWidget">
167 <property name="name">
168 <cstring>TabPage</cstring>
169 </property>
170 <attribute name="title">
171 <string>File</string>
172 </attribute>
173 <widget class="QComboBox">
174 <item>
175 <property name="text">
176 <string>none</string>
177 </property>
178 </item>
179 <item>
180 <property name="text">
181 <string>gzip</string>
182 </property>
183 </item>
184 <item>
185 <property name="text">
186 <string>bzip2</string>
187 </property>
188 </item>
189 <property name="name">
190 <cstring>compressionComboBox</cstring>
191 </property>
192 <property name="geometry">
193 <rect>
194 <x>290</x>
195 <y>50</y>
196 <width>150</width>
197 <height>28</height>
198 </rect>
199 </property>
200 </widget>
201 <widget class="QLabel">
202 <property name="name">
203 <cstring>textLabel1_6</cstring>
204 </property>
205 <property name="geometry">
206 <rect>
207 <x>10</x>
208 <y>50</y>
209 <width>270</width>
210 <height>20</height>
211 </rect>
212 </property>
213 <property name="text">
214 <string>*.pwm file compression:</string>
215 </property>
216 <property name="alignment">
217 <set>AlignVCenter|AlignRight</set>
218 </property>
219 </widget>
220 <widget class="QLabel">
221 <property name="name">
222 <cstring>textLabel1_8</cstring>
223 </property>
224 <property name="geometry">
225 <rect>
226 <x>10</x>
227 <y>90</y>
228 <width>270</width>
229 <height>20</height>
230 </rect>
231 </property>
232 <property name="text">
233 <string>permissions:</string>
234 </property>
235 <property name="alignment">
236 <set>AlignVCenter|AlignRight</set>
237 </property>
238 </widget>
239 <widget class="QLineEdit">
240 <property name="name">
241 <cstring>permissionLineEdit</cstring>
242 </property>
243 <property name="geometry">
244 <rect>
245 <x>290</x>
246 <y>90</y>
247 <width>142</width>
248 <height>27</height>
249 </rect>
250 </property>
251 <property name="maxLength">
252 <number>3</number>
253 </property>
254 </widget>
255 <widget class="QCheckBox">
256 <property name="name">
257 <cstring>fileBackupCheckBox</cstring>
258 </property>
259 <property name="geometry">
260 <rect>
261 <x>80</x>
262 <y>140</y>
263 <width>360</width>
264 <height>23</height>
265 </rect>
266 </property>
267 <property name="text">
268 <string>Make file backup before saving</string>
269 </property>
270 </widget>
271 </widget>
272 <widget class="QWidget">
273 <property name="name">
274 <cstring>tab</cstring>
275 </property>
276 <attribute name="title">
277 <string>Timeout</string>
278 </attribute>
279 <widget class="QSpinBox">
280 <property name="name">
281 <cstring>pwTimeoutSpinBox</cstring>
282 </property>
283 <property name="geometry">
284 <rect>
285 <x>390</x>
286 <y>50</y>
287 <width>55</width>
288 <height>23</height>
289 </rect>
290 </property>
291 </widget>
292 <widget class="QLabel">
293 <property name="name">
294 <cstring>textLabel1</cstring>
295 </property>
296 <property name="geometry">
297 <rect>
298 <x>10</x>
299 <y>20</y>
300 <width>370</width>
301 <height>80</height>
302 </rect>
303 </property>
304 <property name="text">
305 <string>Password timeout (timeout to hold password in memory, so you don't have to re-enter it, if you already have entered it) [set to 0 to disable]:</string>
306 </property>
307 <property name="alignment">
308 <set>WordBreak|AlignVCenter</set>
309 </property>
310 </widget>
311 <widget class="QLabel">
312 <property name="name">
313 <cstring>textLabel1_7</cstring>
314 </property>
315 <property name="geometry">
316 <rect>
317 <x>10</x>
318 <y>110</y>
319 <width>370</width>
320 <height>80</height>
321 </rect>
322 </property>
323 <property name="text">
324 <string>Auto-lock timeout (auto lock document after this amount of seconds) [set to 0 to disable]:</string>
325 </property>
326 <property name="alignment">
327 <set>WordBreak|AlignVCenter</set>
328 </property>
329 </widget>
330 <widget class="QSpinBox">
331 <property name="name">
332 <cstring>lockTimeoutSpinBox</cstring>
333 </property>
334 <property name="geometry">
335 <rect>
336 <x>390</x>
337 <y>140</y>
338 <width>55</width>
339 <height>23</height>
340 </rect>
341 </property>
342 </widget>
343 <widget class="QCheckBox">
344 <property name="name">
345 <cstring>autoDeepLockCheckBox</cstring>
346 </property>
347 <property name="geometry">
348 <rect>
349 <x>60</x>
350 <y>180</y>
351 <width>380</width>
352 <height>25</height>
353 </rect>
354 </property>
355 <property name="text">
356 <string>deep-lock on autolock</string>
357 </property>
358 </widget>
359 </widget>
360 <widget class="QWidget">
361 <property name="name">
362 <cstring>tab</cstring>
363 </property>
364 <attribute name="title">
365 <string>Autostart</string>
366 </attribute>
367 <widget class="QLabel">
368 <property name="name">
369 <cstring>textLabel1_3</cstring>
370 </property>
371 <property name="geometry">
372 <rect>
373 <x>30</x>
374 <y>30</y>
375 <width>400</width>
376 <height>20</height>
377 </rect>
378 </property>
379 <property name="text">
380 <string>Open this file automatically on startup:</string>
381 </property>
382 </widget>
383 <widget class="QLineEdit">
384 <property name="name">
385 <cstring>autoStartLineEdit</cstring>
386 </property>
387 <property name="geometry">
388 <rect>
389 <x>30</x>
390 <y>50</y>
391 <width>360</width>
392 <height>20</height>
393 </rect>
394 </property>
395 </widget>
396 <widget class="QPushButton">
397 <property name="name">
398 <cstring>browseAutoStButton</cstring>
399 </property>
400 <property name="geometry">
401 <rect>
402 <x>400</x>
403 <y>50</y>
404 <width>30</width>
405 <height>20</height>
406 </rect>
407 </property>
408 <property name="text">
409 <string>...</string>
410 </property>
411 </widget>
412 <widget class="QCheckBox">
413 <property name="name">
414 <cstring>autostartDeeplockedCheckBox</cstring>
415 </property>
416 <property name="geometry">
417 <rect>
418 <x>40</x>
419 <y>80</y>
420 <width>390</width>
421 <height>25</height>
422 </rect>
423 </property>
424 <property name="text">
425 <string>open deeplocked</string>
426 </property>
427 </widget>
428 </widget>
429 <widget class="QWidget">
430 <property name="name">
431 <cstring>tab</cstring>
432 </property>
433 <attribute name="title">
434 <string>External apps</string>
435 </attribute>
436 <widget class="QLabel">
437 <property name="name">
438 <cstring>textLabel2</cstring>
439 </property>
440 <property name="geometry">
441 <rect>
442 <x>20</x>
443 <y>40</y>
444 <width>280</width>
445 <height>20</height>
446 </rect>
447 </property>
448 <property name="text">
449 <string>Favourite browser:</string>
450 </property>
451 <property name="alignment">
452 <set>AlignVCenter|AlignRight</set>
453 </property>
454 </widget>
455 <widget class="QLineEdit">
456 <property name="name">
457 <cstring>browserLineEdit</cstring>
458 </property>
459 <property name="geometry">
460 <rect>
461 <x>310</x>
462 <y>40</y>
463 <width>130</width>
464 <height>27</height>
465 </rect>
466 </property>
467 </widget>
468 <widget class="QLineEdit">
469 <property name="name">
470 <cstring>xtermLineEdit</cstring>
471 </property>
472 <property name="geometry">
473 <rect>
474 <x>310</x>
475 <y>100</y>
476 <width>130</width>
477 <height>27</height>
478 </rect>
479 </property>
480 </widget>
481 <widget class="QLabel">
482 <property name="name">
483 <cstring>textLabel3</cstring>
484 </property>
485 <property name="geometry">
486 <rect>
487 <x>20</x>
488 <y>100</y>
489 <width>280</width>
490 <height>20</height>
491 </rect>
492 </property>
493 <property name="text">
494 <string>Favourite X-terminal:</string>
495 </property>
496 <property name="alignment">
497 <set>AlignVCenter|AlignRight</set>
498 </property>
499 </widget>
500 </widget>
501 <widget class="QWidget">
502 <property name="name">
503 <cstring>tab</cstring>
504 </property>
505 <attribute name="title">
506 <string>Miscellaneous</string>
507 </attribute>
508 <widget class="QCheckBox">
509 <property name="name">
510 <cstring>trayCheckBox</cstring>
511 </property>
512 <property name="geometry">
513 <rect>
514 <x>30</x>
515 <y>30</y>
516 <width>400</width>
517 <height>20</height>
518 </rect>
519 </property>
520 <property name="text">
521 <string>Show icon in system-tray</string>
522 </property>
523 </widget>
524 <widget class="QCheckBox">
525 <property name="name">
526 <cstring>openUnlockedCheckBox</cstring>
527 </property>
528 <property name="geometry">
529 <rect>
530 <x>30</x>
531 <y>80</y>
532 <width>400</width>
533 <height>20</height>
534 </rect>
535 </property>
536 <property name="text">
537 <string>Open document with passwords unlocked</string>
538 </property>
539 </widget>
540 <widget class="QCheckBox">
541 <property name="name">
542 <cstring>autoMinimizeCheckBox</cstring>
543 </property>
544 <property name="enabled">
545 <bool>false</bool>
546 </property>
547 <property name="geometry">
548 <rect>
549 <x>50</x>
550 <y>50</y>
551 <width>380</width>
552 <height>25</height>
553 </rect>
554 </property>
555 <property name="text">
556 <string>auto-minimize to tray on startup</string>
557 </property>
558 </widget>
559 <widget class="QComboBox">
560 <item>
561 <property name="text">
562 <string>don't lock</string>
563 </property>
564 </item>
565 <item>
566 <property name="text">
567 <string>normal lock</string>
568 </property>
569 </item>
570 <item>
571 <property name="text">
572 <string>deep-lock</string>
573 </property>
574 </item>
575 <property name="name">
576 <cstring>minimizeLockComboBox</cstring>
577 </property>
578 <property name="geometry">
579 <rect>
580 <x>310</x>
581 <y>170</y>
582 <width>120</width>
583 <height>27</height>
584 </rect>
585 </property>
586 </widget>
587 <widget class="QLabel">
588 <property name="name">
589 <cstring>textLabel1_9</cstring>
590 </property>
591 <property name="geometry">
592 <rect>
593 <x>30</x>
594 <y>180</y>
595 <width>270</width>
596 <height>20</height>
597 </rect>
598 </property>
599 <property name="text">
600 <string>auto-lock on minimize:</string>
601 </property>
602 <property name="alignment">
603 <set>AlignVCenter|AlignRight</set>
604 </property>
605 </widget>
606 <widget class="QCheckBox">
607 <property name="name">
608 <cstring>kwalletEmuCheckBox</cstring>
609 </property>
610 <property name="geometry">
611 <rect>
612 <x>30</x>
613 <y>110</y>
614 <width>400</width>
615 <height>25</height>
616 </rect>
617 </property>
618 <property name="text">
619 <string>KWallet emulation</string>
620 </property>
621 </widget>
622 <widget class="QCheckBox">
623 <property name="name">
624 <cstring>wndCloseCheckBox</cstring>
625 </property>
626 <property name="geometry">
627 <rect>
628 <x>30</x>
629 <y>140</y>
630 <width>430</width>
631 <height>24</height>
632 </rect>
633 </property>
634 <property name="text">
635 <string>Do not minimize windows into tray. (Close the window)</string>
636 </property>
637 </widget>
638 </widget>
639 </widget>
640</widget>
641<connections>
642 <connection>
643 <sender>okButton</sender>
644 <signal>clicked()</signal>
645 <receiver>configWnd</receiver>
646 <slot>okButton_slot()</slot>
647 </connection>
648 <connection>
649 <sender>cancelButton</sender>
650 <signal>clicked()</signal>
651 <receiver>configWnd</receiver>
652 <slot>cancelButton_slot()</slot>
653 </connection>
654 <connection>
655 <sender>browseAutoStButton</sender>
656 <signal>clicked()</signal>
657 <receiver>configWnd</receiver>
658 <slot>browseAutoStButton_slot()</slot>
659 </connection>
660 <connection>
661 <sender>selEntrFontButton</sender>
662 <signal>clicked()</signal>
663 <receiver>configWnd</receiver>
664 <slot>selEntrFontButton_slot()</slot>
665 </connection>
666 <connection>
667 <sender>trayCheckBox</sender>
668 <signal>toggled(bool)</signal>
669 <receiver>autoMinimizeCheckBox</receiver>
670 <slot>setEnabled(bool)</slot>
671 </connection>
672</connections>
673<tabstops>
674 <tabstop>pwTimeoutSpinBox</tabstop>
675 <tabstop>trayCheckBox</tabstop>
676 <tabstop>okButton</tabstop>
677 <tabstop>cancelButton</tabstop>
678</tabstops>
679<slots>
680 <slot>okButton_slot()</slot>
681 <slot>cancelButton_slot()</slot>
682 <slot>browseBgButton_slot()</slot>
683 <slot>browseAutoStButton_slot()</slot>
684 <slot>selEntrFontButton_slot()</slot>
685</slots>
686<layoutdefaults spacing="6" margin="11"/>
687</UI>
diff --git a/pwmanager/pwmanager/configwndimpl.cpp b/pwmanager/pwmanager/configwndimpl.cpp
new file mode 100644
index 0000000..5aa38d4
--- a/dev/null
+++ b/pwmanager/pwmanager/configwndimpl.cpp
@@ -0,0 +1,126 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12
13/***************************************************************************
14 * copyright (C) 2004 by Ulf Schenk
15 * This file is originaly based on version 1.0.1 of pwmanager
16 * and was modified to run on embedded devices that run microkde
17 *
18 * $Id$
19 **************************************************************************/
20
21#include "configwndimpl.h"
22#include "pwm.h"
23#include "configuration.h"
24
25#include <qfileinfo.h>
26#include <qlineedit.h>
27
28#include <kstandarddirs.h>
29#include <kfiledialog.h>
30#include <klocale.h>
31
32#include <stdlib.h>
33#include <stdio.h>
34
35#ifdef PWM_EMBEDDED
36#include <kfontdialog.h>
37#endif
38
39ConfigWndImpl::ConfigWndImpl()
40{
41}
42
43ConfigWndImpl::~ConfigWndImpl()
44{
45}
46
47void ConfigWndImpl::okButton_slot()
48{
49 done(0);
50}
51
52void ConfigWndImpl::cancelButton_slot()
53{
54 done(1);
55}
56
57void ConfigWndImpl::browseAutoStButton_slot()
58{
59 QString path(KFileDialog::getOpenFileName(QString::null,
60 i18n("*.pwm|PwM Password file\n"
61 "*|All files"), this));
62 if (path != QString::null)
63 autoStartLineEdit->setText(path);
64}
65
66void ConfigWndImpl::selEntrFontButton_slot()
67{
68 bool ok;
69#ifndef PWM_EMBEDDED
70 QFont fnt = QFontDialog::getFont(&ok, currentEntryFont, this);
71#else
72 QFont fnt = KFontDialog::getFont(currentEntryFont, ok);
73#endif
74 if (!ok)
75 return;
76 currEntrFont->setFont(fnt);
77 currEntrFont->setText(fnt.family());
78 currentEntryFont = fnt;
79}
80
81int ConfigWndImpl::getFilePermissions()
82{
83 char octalDigits[] = "01234567";
84 bool isOctal;
85 QString permString(permissionLineEdit->text());
86 int i, j, length = permString.length();
87 if (length != 3) {
88 printWarn("Wrong permission string length! Please enter "
89 "the string like the following example: 600");
90 return CONF_DEFAULT_FILEPERMISSIONS;
91 }
92 for (i = 0; i < length; ++i) {
93 isOctal = false;
94 for (j = 0; j < 8; ++j) {
95 if (permString.at(i) == octalDigits[j]) {
96 isOctal = true;
97 break;
98 }
99 }
100 if (!isOctal) {
101 printWarn("CONFIG: File-permissions: This is "
102 "not an octal number ");
103 return CONF_DEFAULT_FILEPERMISSIONS;
104 }
105 }
106
107 int ret = strtol(permString.latin1(), 0, 8);
108 if (ret == 0) {
109 /* either an error occured, or the user did really type 000 */
110 printWarn("CONFIG: File-permissions: Hm, either conversion error, "
111 "or you really typed 000. 8-)");
112 return CONF_DEFAULT_FILEPERMISSIONS;
113 }
114 return ret;
115}
116
117void ConfigWndImpl::setFilePermissions(int perm)
118{
119 char tmpBuf[30];
120 sprintf(tmpBuf, "%o", perm);
121 permissionLineEdit->setText(tmpBuf);
122}
123
124#ifndef PWM_EMBEDDED
125#include "configwndimpl.moc"
126#endif
diff --git a/pwmanager/pwmanager/configwndimpl.h b/pwmanager/pwmanager/configwndimpl.h
new file mode 100644
index 0000000..f67f459
--- a/dev/null
+++ b/pwmanager/pwmanager/configwndimpl.h
@@ -0,0 +1,55 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12
13/***************************************************************************
14 * copyright (C) 2004 by Ulf Schenk
15 * This file is originaly based on version 1.0.1 of pwmanager
16 * and was modified to run on embedded devices that run microkde
17 *
18 * $Id$
19 **************************************************************************/
20
21#ifndef CONFIGWNDIMPL_H
22#define CONFIGWNDIMPL_H
23
24#include <qfontdialog.h>
25
26#include "configwnd.h"
27
28/** "add" Window */
29class ConfigWndImpl : public configWnd
30{
31 Q_OBJECT
32public:
33 ConfigWndImpl();
34 ~ConfigWndImpl();
35
36 /** currently selected entry-font */
37 QFont currentEntryFont;
38
39 /** gets the content of permissionLineEdit */
40 int getFilePermissions();
41 /** sets the content of permissionLineEdit */
42 void setFilePermissions(int perm);
43
44public slots:
45 /** OK button pressed */
46 void okButton_slot();
47 /** cancel button pressed */
48 void cancelButton_slot();
49 /** browse autostart file button pressed */
50 void browseAutoStButton_slot();
51 /** select entry-font button pressed */
52 void selEntrFontButton_slot();
53};
54
55#endif
diff --git a/pwmanager/pwmanager/findwnd.cpp b/pwmanager/pwmanager/findwnd.cpp
new file mode 100644
index 0000000..7767665
--- a/dev/null
+++ b/pwmanager/pwmanager/findwnd.cpp
@@ -0,0 +1,153 @@
1/****************************************************************************
2** Form implementation generated from reading ui file 'findwnd.ui'
3**
4** Created: Tue Sep 14 15:25:08 2004
5** by: The User Interface Compiler ($Id$)
6**
7** WARNING! All changes made in this file will be lost!
8****************************************************************************/
9
10#include "findwnd.h"
11
12#include <qvariant.h>
13#include <qlabel.h>
14#include <qlineedit.h>
15#include <qpushbutton.h>
16#include <qcheckbox.h>
17#include <qbuttongroup.h>
18#include <qradiobutton.h>
19#include <qlayout.h>
20#include <qtooltip.h>
21#include <qwhatsthis.h>
22
23/*
24 * Constructs a findWnd as a child of 'parent', with the
25 * name 'name' and widget flags set to 'f'.
26 *
27 * The dialog will by default be modeless, unless you set 'modal' to
28 * TRUE to construct a modal dialog.
29 */
30findWnd::findWnd( QWidget* parent, const char* name, bool modal, WFlags fl )
31 : QDialog( parent, name, modal, fl )
32{
33 if ( !name )
34 setName( "findWnd" );
35
36 textLabel1 = new QLabel( this, "textLabel1" );
37 textLabel1->setGeometry( QRect( 20, 20, 340, 20 ) );
38 textLabel1->setFrameShape( QLabel::NoFrame );
39 textLabel1->setFrameShadow( QLabel::Plain );
40
41 findLineEdit = new QLineEdit( this, "findLineEdit" );
42 findLineEdit->setGeometry( QRect( 20, 40, 340, 20 ) );
43
44 findButton = new QPushButton( this, "findButton" );
45 findButton->setGeometry( QRect( 20, 230, 107, 27 ) );
46
47 closeButton = new QPushButton( this, "closeButton" );
48 closeButton->setGeometry( QRect( 250, 230, 107, 27 ) );
49
50 exactCheckBox = new QCheckBox( this, "exactCheckBox" );
51 exactCheckBox->setGeometry( QRect( 20, 200, 340, 20 ) );
52
53 caseSensCheckBox = new QCheckBox( this, "caseSensCheckBox" );
54 caseSensCheckBox->setGeometry( QRect( 20, 180, 340, 20 ) );
55
56 buttonGroup1 = new QButtonGroup( this, "buttonGroup1" );
57 buttonGroup1->setGeometry( QRect( 20, 70, 340, 90 ) );
58
59 descRadioButton = new QRadioButton( buttonGroup1, "descRadioButton" );
60 descRadioButton->setGeometry( QRect( 30, 20, 150, 20 ) );
61 descRadioButton->setChecked( TRUE );
62
63 pwRadioButton = new QRadioButton( buttonGroup1, "pwRadioButton" );
64 pwRadioButton->setGeometry( QRect( 180, 20, 150, 20 ) );
65
66 commentRadioButton = new QRadioButton( buttonGroup1, "commentRadioButton" );
67 commentRadioButton->setGeometry( QRect( 180, 40, 150, 20 ) );
68
69 nameRadioButton = new QRadioButton( buttonGroup1, "nameRadioButton" );
70 nameRadioButton->setGeometry( QRect( 30, 40, 150, 20 ) );
71
72 urlRadioButton = new QRadioButton( buttonGroup1, "urlRadioButton" );
73 urlRadioButton->setGeometry( QRect( 30, 60, 150, 20 ) );
74
75 launcherRadioButton = new QRadioButton( buttonGroup1, "launcherRadioButton" );
76 launcherRadioButton->setGeometry( QRect( 180, 60, 150, 20 ) );
77 languageChange();
78 resize( QSize(381, 269).expandedTo(minimumSizeHint()) );
79 clearWState( WState_Polished );
80
81 // signals and slots connections
82 connect( findButton, SIGNAL( clicked() ), this, SLOT( findButton_slot() ) );
83 connect( closeButton, SIGNAL( clicked() ), this, SLOT( closeButton_slot() ) );
84 connect( descRadioButton, SIGNAL( stateChanged(int) ), this, SLOT( selectionChanged_slot() ) );
85 connect( nameRadioButton, SIGNAL( stateChanged(int) ), this, SLOT( selectionChanged_slot() ) );
86 connect( pwRadioButton, SIGNAL( stateChanged(int) ), this, SLOT( selectionChanged_slot() ) );
87 connect( commentRadioButton, SIGNAL( stateChanged(int) ), this, SLOT( selectionChanged_slot() ) );
88 connect( findLineEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( selectionChanged_slot() ) );
89 connect( caseSensCheckBox, SIGNAL( stateChanged(int) ), this, SLOT( selectionChanged_slot() ) );
90 connect( exactCheckBox, SIGNAL( stateChanged(int) ), this, SLOT( selectionChanged_slot() ) );
91
92 // tab order
93 setTabOrder( findLineEdit, descRadioButton );
94 setTabOrder( descRadioButton, caseSensCheckBox );
95 setTabOrder( caseSensCheckBox, exactCheckBox );
96 setTabOrder( exactCheckBox, findButton );
97 setTabOrder( findButton, closeButton );
98 setTabOrder( closeButton, nameRadioButton );
99 setTabOrder( nameRadioButton, pwRadioButton );
100 setTabOrder( pwRadioButton, commentRadioButton );
101}
102
103/*
104 * Destroys the object and frees any allocated resources
105 */
106findWnd::~findWnd()
107{
108 // no need to delete child widgets, Qt does it all for us
109}
110
111/*
112 * Sets the strings of the subwidgets using the current
113 * language.
114 */
115void findWnd::languageChange()
116{
117 setCaption( tr( "Find" ) );
118 textLabel1->setText( tr( "Find:" ) );
119 findButton->setText( tr( "&Find" ) );
120 //US ENH findButton->setAccel( QKeySequence( tr( "Alt+F" ) ) );
121 closeButton->setText( tr( "&Close" ) );
122//US ENH closeButton->setAccel( QKeySequence( tr( "Alt+C" ) ) );
123 exactCheckBox->setText( tr( "&Exact match" ) );
124//US ENH exactCheckBox->setAccel( QKeySequence( tr( "Alt+E" ) ) );
125 caseSensCheckBox->setText( tr( "&Case sensitive" ) );
126//US ENH caseSensCheckBox->setAccel( QKeySequence( tr( "Alt+C" ) ) );
127 buttonGroup1->setTitle( tr( "Search in Column" ) );
128 descRadioButton->setText( tr( "&Description" ) );
129 pwRadioButton->setText( tr( "&Password" ) );
130 commentRadioButton->setText( tr( "C&omment" ) );
131 nameRadioButton->setText( tr( "&Username" ) );
132//US ENH nameRadioButton->setAccel( QKeySequence( tr( "Alt+U" ) ) );
133 urlRadioButton->setText( tr( "U&RL" ) );
134//US ENH urlRadioButton->setAccel( QKeySequence( tr( "Alt+R" ) ) );
135 launcherRadioButton->setText( tr( "&Launcher" ) );
136//US ENH launcherRadioButton->setAccel( QKeySequence( tr( "Alt+L" ) ) );
137}
138
139void findWnd::findButton_slot()
140{
141 qWarning( "findWnd::findButton_slot(): Not implemented yet" );
142}
143
144void findWnd::selectionChanged_slot()
145{
146 qWarning( "findWnd::selectionChanged_slot(): Not implemented yet" );
147}
148
149void findWnd::closeButton_slot()
150{
151 qWarning( "findWnd::closeButton_slot(): Not implemented yet" );
152}
153
diff --git a/pwmanager/pwmanager/findwnd.h b/pwmanager/pwmanager/findwnd.h
new file mode 100644
index 0000000..d4ac8e0
--- a/dev/null
+++ b/pwmanager/pwmanager/findwnd.h
@@ -0,0 +1,61 @@
1/****************************************************************************
2** Form interface generated from reading ui file 'findwnd.ui'
3**
4** Created: Mon Sep 13 13:45:42 2004
5** by: The User Interface Compiler ($Id$)
6**
7** WARNING! All changes made in this file will be lost!
8****************************************************************************/
9
10#ifndef FINDWND_H
11#define FINDWND_H
12
13#include <qvariant.h>
14#include <qdialog.h>
15
16class QVBoxLayout;
17class QHBoxLayout;
18class QGridLayout;
19class QSpacerItem;
20class QLabel;
21class QLineEdit;
22class QPushButton;
23class QCheckBox;
24class QButtonGroup;
25class QRadioButton;
26
27class findWnd : public QDialog
28{
29 Q_OBJECT
30
31public:
32 findWnd( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
33 ~findWnd();
34
35 QLabel* textLabel1;
36 QLineEdit* findLineEdit;
37 QPushButton* findButton;
38 QPushButton* closeButton;
39 QCheckBox* exactCheckBox;
40 QCheckBox* caseSensCheckBox;
41 QButtonGroup* buttonGroup1;
42 QRadioButton* descRadioButton;
43 QRadioButton* pwRadioButton;
44 QRadioButton* commentRadioButton;
45 QRadioButton* nameRadioButton;
46 QRadioButton* urlRadioButton;
47 QRadioButton* launcherRadioButton;
48
49public slots:
50 virtual void findButton_slot();
51 virtual void selectionChanged_slot();
52 virtual void closeButton_slot();
53
54protected:
55
56protected slots:
57 virtual void languageChange();
58
59};
60
61#endif // FINDWND_H
diff --git a/pwmanager/pwmanager/findwnd.ui b/pwmanager/pwmanager/findwnd.ui
new file mode 100644
index 0000000..4572e0a
--- a/dev/null
+++ b/pwmanager/pwmanager/findwnd.ui
@@ -0,0 +1,327 @@
1<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
2<class>findWnd</class>
3<widget class="QDialog">
4 <property name="name">
5 <cstring>findWnd</cstring>
6 </property>
7 <property name="geometry">
8 <rect>
9 <x>0</x>
10 <y>0</y>
11 <width>381</width>
12 <height>269</height>
13 </rect>
14 </property>
15 <property name="caption">
16 <string>Find</string>
17 </property>
18 <widget class="QLabel">
19 <property name="name">
20 <cstring>textLabel1</cstring>
21 </property>
22 <property name="geometry">
23 <rect>
24 <x>20</x>
25 <y>20</y>
26 <width>340</width>
27 <height>20</height>
28 </rect>
29 </property>
30 <property name="frameShape">
31 <enum>NoFrame</enum>
32 </property>
33 <property name="frameShadow">
34 <enum>Plain</enum>
35 </property>
36 <property name="text">
37 <string>Find:</string>
38 </property>
39 </widget>
40 <widget class="QLineEdit">
41 <property name="name">
42 <cstring>findLineEdit</cstring>
43 </property>
44 <property name="geometry">
45 <rect>
46 <x>20</x>
47 <y>40</y>
48 <width>340</width>
49 <height>20</height>
50 </rect>
51 </property>
52 </widget>
53 <widget class="QPushButton">
54 <property name="name">
55 <cstring>findButton</cstring>
56 </property>
57 <property name="geometry">
58 <rect>
59 <x>20</x>
60 <y>230</y>
61 <width>107</width>
62 <height>27</height>
63 </rect>
64 </property>
65 <property name="text">
66 <string>&amp;Find</string>
67 </property>
68 <property name="accel">
69 <string>Alt+F</string>
70 </property>
71 </widget>
72 <widget class="QPushButton">
73 <property name="name">
74 <cstring>closeButton</cstring>
75 </property>
76 <property name="geometry">
77 <rect>
78 <x>250</x>
79 <y>230</y>
80 <width>107</width>
81 <height>27</height>
82 </rect>
83 </property>
84 <property name="text">
85 <string>&amp;Close</string>
86 </property>
87 <property name="accel">
88 <string>Alt+C</string>
89 </property>
90 </widget>
91 <widget class="QCheckBox">
92 <property name="name">
93 <cstring>exactCheckBox</cstring>
94 </property>
95 <property name="geometry">
96 <rect>
97 <x>20</x>
98 <y>200</y>
99 <width>340</width>
100 <height>20</height>
101 </rect>
102 </property>
103 <property name="text">
104 <string>&amp;Exact match</string>
105 </property>
106 <property name="accel">
107 <string>Alt+E</string>
108 </property>
109 </widget>
110 <widget class="QCheckBox">
111 <property name="name">
112 <cstring>caseSensCheckBox</cstring>
113 </property>
114 <property name="geometry">
115 <rect>
116 <x>20</x>
117 <y>180</y>
118 <width>340</width>
119 <height>20</height>
120 </rect>
121 </property>
122 <property name="text">
123 <string>&amp;Case sensitive</string>
124 </property>
125 <property name="accel">
126 <string>Alt+C</string>
127 </property>
128 </widget>
129 <widget class="QButtonGroup">
130 <property name="name">
131 <cstring>buttonGroup1</cstring>
132 </property>
133 <property name="geometry">
134 <rect>
135 <x>20</x>
136 <y>70</y>
137 <width>340</width>
138 <height>90</height>
139 </rect>
140 </property>
141 <property name="title">
142 <string>Search in Column</string>
143 </property>
144 <widget class="QRadioButton">
145 <property name="name">
146 <cstring>descRadioButton</cstring>
147 </property>
148 <property name="geometry">
149 <rect>
150 <x>30</x>
151 <y>20</y>
152 <width>150</width>
153 <height>20</height>
154 </rect>
155 </property>
156 <property name="text">
157 <string>&amp;Description</string>
158 </property>
159 <property name="checked">
160 <bool>true</bool>
161 </property>
162 </widget>
163 <widget class="QRadioButton">
164 <property name="name">
165 <cstring>pwRadioButton</cstring>
166 </property>
167 <property name="geometry">
168 <rect>
169 <x>180</x>
170 <y>20</y>
171 <width>150</width>
172 <height>20</height>
173 </rect>
174 </property>
175 <property name="text">
176 <string>&amp;Password</string>
177 </property>
178 </widget>
179 <widget class="QRadioButton">
180 <property name="name">
181 <cstring>commentRadioButton</cstring>
182 </property>
183 <property name="geometry">
184 <rect>
185 <x>180</x>
186 <y>40</y>
187 <width>150</width>
188 <height>20</height>
189 </rect>
190 </property>
191 <property name="text">
192 <string>C&amp;omment</string>
193 </property>
194 </widget>
195 <widget class="QRadioButton">
196 <property name="name">
197 <cstring>nameRadioButton</cstring>
198 </property>
199 <property name="geometry">
200 <rect>
201 <x>30</x>
202 <y>40</y>
203 <width>150</width>
204 <height>20</height>
205 </rect>
206 </property>
207 <property name="text">
208 <string>&amp;Username</string>
209 </property>
210 <property name="accel">
211 <string>Alt+U</string>
212 </property>
213 </widget>
214 <widget class="QRadioButton">
215 <property name="name">
216 <cstring>urlRadioButton</cstring>
217 </property>
218 <property name="geometry">
219 <rect>
220 <x>30</x>
221 <y>60</y>
222 <width>150</width>
223 <height>20</height>
224 </rect>
225 </property>
226 <property name="text">
227 <string>U&amp;RL</string>
228 </property>
229 <property name="accel">
230 <string>Alt+R</string>
231 </property>
232 </widget>
233 <widget class="QRadioButton">
234 <property name="name">
235 <cstring>launcherRadioButton</cstring>
236 </property>
237 <property name="geometry">
238 <rect>
239 <x>180</x>
240 <y>60</y>
241 <width>150</width>
242 <height>20</height>
243 </rect>
244 </property>
245 <property name="text">
246 <string>&amp;Launcher</string>
247 </property>
248 <property name="accel">
249 <string>Alt+L</string>
250 </property>
251 </widget>
252 </widget>
253</widget>
254<connections>
255 <connection>
256 <sender>findButton</sender>
257 <signal>clicked()</signal>
258 <receiver>findWnd</receiver>
259 <slot>findButton_slot()</slot>
260 </connection>
261 <connection>
262 <sender>closeButton</sender>
263 <signal>clicked()</signal>
264 <receiver>findWnd</receiver>
265 <slot>closeButton_slot()</slot>
266 </connection>
267 <connection>
268 <sender>descRadioButton</sender>
269 <signal>stateChanged(int)</signal>
270 <receiver>findWnd</receiver>
271 <slot>selectionChanged_slot()</slot>
272 </connection>
273 <connection>
274 <sender>nameRadioButton</sender>
275 <signal>stateChanged(int)</signal>
276 <receiver>findWnd</receiver>
277 <slot>selectionChanged_slot()</slot>
278 </connection>
279 <connection>
280 <sender>pwRadioButton</sender>
281 <signal>stateChanged(int)</signal>
282 <receiver>findWnd</receiver>
283 <slot>selectionChanged_slot()</slot>
284 </connection>
285 <connection>
286 <sender>commentRadioButton</sender>
287 <signal>stateChanged(int)</signal>
288 <receiver>findWnd</receiver>
289 <slot>selectionChanged_slot()</slot>
290 </connection>
291 <connection>
292 <sender>findLineEdit</sender>
293 <signal>textChanged(const QString&amp;)</signal>
294 <receiver>findWnd</receiver>
295 <slot>selectionChanged_slot()</slot>
296 </connection>
297 <connection>
298 <sender>caseSensCheckBox</sender>
299 <signal>stateChanged(int)</signal>
300 <receiver>findWnd</receiver>
301 <slot>selectionChanged_slot()</slot>
302 </connection>
303 <connection>
304 <sender>exactCheckBox</sender>
305 <signal>stateChanged(int)</signal>
306 <receiver>findWnd</receiver>
307 <slot>selectionChanged_slot()</slot>
308 </connection>
309</connections>
310<tabstops>
311 <tabstop>findLineEdit</tabstop>
312 <tabstop>descRadioButton</tabstop>
313 <tabstop>caseSensCheckBox</tabstop>
314 <tabstop>exactCheckBox</tabstop>
315 <tabstop>findButton</tabstop>
316 <tabstop>closeButton</tabstop>
317 <tabstop>nameRadioButton</tabstop>
318 <tabstop>pwRadioButton</tabstop>
319 <tabstop>commentRadioButton</tabstop>
320</tabstops>
321<slots>
322 <slot>findButton_slot()</slot>
323 <slot>selectionChanged_slot()</slot>
324 <slot>closeButton_slot()</slot>
325</slots>
326<layoutdefaults spacing="6" margin="11"/>
327</UI>
diff --git a/pwmanager/pwmanager/findwndimpl.cpp b/pwmanager/pwmanager/findwndimpl.cpp
new file mode 100644
index 0000000..fec1a6a
--- a/dev/null
+++ b/pwmanager/pwmanager/findwndimpl.cpp
@@ -0,0 +1,125 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "findwndimpl.h"
21#include "pwmexception.h"
22#include "pwmdoc.h"
23#include "pwmview.h"
24
25#include <qradiobutton.h>
26#include <qlineedit.h>
27#include <qcheckbox.h>
28
29#include <kmessagebox.h>
30#include <klocale.h>
31
32FindWndImpl::FindWndImpl(PwMView * _parent)
33 : findWnd()
34{
35 parent = _parent;
36 fAt = 0;
37 refVal = 0;
38 currFoundPos = -1;
39 numEntries = parent->document()->numEntries(parent->getCurrentCategory());
40 connect(this, SIGNAL(foundAt(int)), parent, SLOT(selAt(int)));
41}
42
43FindWndImpl::~FindWndImpl()
44{
45}
46
47void FindWndImpl::findButton_slot()
48{
49 if (findLineEdit->text() == "")
50 return;
51 static vector<unsigned int> foundPositions;
52 PwMDoc *doc = parent->document();
53
54 if (currFoundPos < 0) {
55 bool unlockedTempoary = false;
56 foundPositions.clear();
57 PwMDataItem findThis;
58 unsigned int searchIn = 0;
59
60 if (descRadioButton->isChecked()) {
61 searchIn = SEARCH_IN_DESC;
62 findThis.desc = findLineEdit->text().latin1();
63 } else if (nameRadioButton->isChecked()) {
64 searchIn = SEARCH_IN_NAME;
65 findThis.name = findLineEdit->text().latin1();
66 } else if (pwRadioButton->isChecked()) {
67 searchIn = SEARCH_IN_PW;
68 findThis.pw = findLineEdit->text().latin1();
69 } else if (commentRadioButton->isChecked()) {
70 searchIn = SEARCH_IN_COMMENT;
71 findThis.comment = findLineEdit->text().latin1();
72 } else if (urlRadioButton->isChecked()) {
73 searchIn = SEARCH_IN_URL;
74 findThis.url = findLineEdit->text().latin1();
75 } else if (launcherRadioButton->isChecked()) {
76 searchIn = SEARCH_IN_LAUNCHER;
77 findThis.launcher = findLineEdit->text().latin1();
78 }
79
80 if (pwRadioButton->isChecked()) {
81 if (!doc->unlockAll_tempoary())
82 return;
83 unlockedTempoary = true;
84 }
85 doc->findEntry(parent->getCurrentCategory(), findThis,
86 searchIn, &foundPositions, false,
87 caseSensCheckBox->isChecked(),
88 exactCheckBox->isChecked(),
89 true);
90 if (unlockedTempoary) {
91 doc->unlockAll_tempoary(true);
92 }
93
94 if (!foundPositions.size()) {
95 KMessageBox::information(this,
96 i18n("No entry found."),
97 i18n("not found"));
98 return;
99 }
100 currFoundPos = 0;
101 }
102
103 int lvp = doc->getListViewPos(parent->getCurrentCategory(),
104 foundPositions[currFoundPos++]);
105 emit foundAt(numEntries - 1 - lvp);
106
107 if (currFoundPos + 1 > static_cast<int>(foundPositions.size()))
108 currFoundPos = 0;
109}
110
111void FindWndImpl::closeButton_slot()
112{
113 done(0);
114}
115
116void FindWndImpl::selectionChanged_slot()
117{
118 fAt = 0;
119 refVal = 0;
120 currFoundPos = -1;
121}
122
123#ifndef PWM_EMBEDDED
124#include "findwndimpl.moc"
125#endif
diff --git a/pwmanager/pwmanager/findwndimpl.h b/pwmanager/pwmanager/findwndimpl.h
new file mode 100644
index 0000000..d8cb65d
--- a/dev/null
+++ b/pwmanager/pwmanager/findwndimpl.h
@@ -0,0 +1,61 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef FINDWNDIMPL_H
21#define FINDWNDIMPL_H
22
23#include "findwnd.h"
24
25class PwMView;
26
27/** "add" Window */
28class FindWndImpl : public findWnd
29{
30 Q_OBJECT
31public:
32 FindWndImpl(PwMView *_parent);
33 ~FindWndImpl();
34
35signals:
36 void foundAt(int index);
37
38public slots:
39 /** find button pressed */
40 void findButton_slot();
41 /** close button pressed */
42 void closeButton_slot();
43 /** selection of one of the radio buttons changed */
44 void selectionChanged_slot();
45
46protected:
47 /** parent view */
48 PwMView *parent;
49 /** entry found at */
50 unsigned int fAt;
51 /** reference value */
52 unsigned int refVal;
53 /** current position in the found-items-vector */
54 int currFoundPos;
55 /** the number of entries in the current category */
56 unsigned int numEntries;
57 /** index number of the current category */
58 unsigned int catIndex;
59};
60
61#endif
diff --git a/pwmanager/pwmanager/genpasswd.cpp b/pwmanager/pwmanager/genpasswd.cpp
new file mode 100644
index 0000000..b0cceff
--- a/dev/null
+++ b/pwmanager/pwmanager/genpasswd.cpp
@@ -0,0 +1,192 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "genpasswd.h"
21#include "pwmexception.h"
22#include "randomizer.h"
23
24
25/* how often can a char of the same charset be reused in order */
26 #define FILTER_MAX_CHARSET_REUSE3
27/* re-randomize all charsets on every iteration (0/1) */
28 #define RERAND_CHARSET 0
29
30
31struct staticCharsetStruct
32{
33 const char *lower;
34 const char *upper;
35 const char *num;
36 const char *special;
37 const char *blank;
38};
39
40static struct staticCharsetStruct staticCharset = {
41 "abcdefghijklmnopqrstuvwxyz",
42 "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
43 "0123456789",
44 "!\"§$%&/()=?,.-;:_+",
45 " "
46};
47
48
49GenPasswd::GenPasswd()
50 : length (8)
51 , useFilter (true)
52{
53 dynCharset.setAutoDelete(true);
54}
55
56void GenPasswd::setCharset(bool lower,
57 bool upper,
58 bool num,
59 bool special,
60 bool blank,
61 QString user)
62{
63 unsigned int sanityCheck = 0;
64 dynCharset_element *tmpElement;
65 dynCharset.clear();
66 if (lower) {
67 tmpElement = new dynCharset_element;
68 tmpElement->refCnt = 0;
69 tmpElement->data = staticCharset.lower;
70 dynCharset.append(tmpElement);
71 ++sanityCheck;
72 }
73 if (upper) {
74 tmpElement = new dynCharset_element;
75 tmpElement->refCnt = 0;
76 tmpElement->data = staticCharset.upper;
77 dynCharset.append(tmpElement);
78 ++sanityCheck;
79 }
80 if (num) {
81 tmpElement = new dynCharset_element;
82 tmpElement->refCnt = 0;
83 tmpElement->data = staticCharset.num;
84 dynCharset.append(tmpElement);
85 ++sanityCheck;
86 }
87 if (special) {
88 tmpElement = new dynCharset_element;
89 tmpElement->refCnt = 0;
90 tmpElement->data = staticCharset.special;
91 dynCharset.append(tmpElement);
92 ++sanityCheck;
93 }
94 if (blank) {
95 tmpElement = new dynCharset_element;
96 tmpElement->refCnt = 0;
97 tmpElement->data = staticCharset.blank;
98 dynCharset.append(tmpElement);
99 }
100 if (!user.isEmpty()) {
101 tmpElement = new dynCharset_element;
102 tmpElement->refCnt = 0;
103 tmpElement->data = user;
104 dynCharset.append(tmpElement);
105 if (likely(user.length() >= 2))
106 ++sanityCheck;
107 }
108 BUG_ON(!sanityCheck);
109 rndDynCharset();
110}
111
112void GenPasswd::rndDynCharset()
113{
114 QString tmpData;
115 int pos;
116 Randomizer *rnd = Randomizer::obj();
117 // QPtrList<dynCharset_element>::iterator is not available in QT-3.1
118 unsigned int i, cnt = dynCharset.count();
119 dynCharset_element *p;
120 for (i = 0; i < cnt; ++i) {
121 p = dynCharset.at(i);
122 PWM_ASSERT(p);
123 tmpData = QString::null;
124 while (p->data.length()) {
125 pos = rnd->genRndInt() % p->data.length();
126 tmpData.append(p->data.at(pos));
127 p->data.remove(pos, 1);
128 }
129 p->data = tmpData;
130 }
131}
132
133QString GenPasswd::gen()
134{
135 BUG_ON(dynCharset.count() <= 0);
136 BUG_ON(length < 1);
137 dynCharset_element *curCharset;
138 QString ret;
139 int i;
140 for (i = 0; i < length; ++i) {
141 curCharset = selectNextCharset();
142#if RERAND_CHARSET != 0
143 rndDynCharset();
144#endif // RERAND_CHARSET
145 ret += genNewRandom(curCharset);
146 }
147 return ret;
148}
149
150GenPasswd::dynCharset_element * GenPasswd::selectNextCharset()
151{
152 dynCharset_element *ret;
153 int numCharsets = dynCharset.count();
154 BUG_ON(numCharsets <= 0);
155 if (numCharsets == 1)
156 return dynCharset.at(0);
157 Randomizer *rnd = Randomizer::obj();
158 if (useFilter) {
159 // find out which charsets are allowed (filtering)
160 QPtrList<dynCharset_element> allowedCharsets;
161 // QPtrList<dynCharset_element>::iterator is not available in QT-3.1
162 unsigned int i, cnt = dynCharset.count();
163 dynCharset_element *p;
164 for (i = 0; i < cnt; ++i) {
165 p = dynCharset.at(i);
166 PWM_ASSERT(p);
167 if (p->refCnt < FILTER_MAX_CHARSET_REUSE) {
168 allowedCharsets.append(p);
169 } else {
170 p->refCnt = 0;
171 }
172 }
173 int numAllowedCharsets = allowedCharsets.count();
174 BUG_ON(numAllowedCharsets <= 0);
175 // now get a random charset out of the allowed
176 unsigned int randomPos = rnd->genRndUInt() % numAllowedCharsets;
177 ret = allowedCharsets.at(randomPos);
178 ret->refCnt++;
179 return ret;
180 }
181 // all charsets are allowed here (no filtering). Get a random.
182 unsigned int randomPos = rnd->genRndUInt() % numCharsets;
183 ret = dynCharset.at(randomPos);
184 return ret;
185}
186
187QChar GenPasswd::genNewRandom(const dynCharset_element *charset)
188{
189 Randomizer *rnd = Randomizer::obj();
190 int pos = rnd->genRndInt() % charset->data.length();
191 return charset->data.at(pos);
192}
diff --git a/pwmanager/pwmanager/genpasswd.h b/pwmanager/pwmanager/genpasswd.h
new file mode 100644
index 0000000..3fa1607
--- a/dev/null
+++ b/pwmanager/pwmanager/genpasswd.h
@@ -0,0 +1,76 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef __GENPASSWD_H
21#define __GENPASSWD_H
22
23#include <qstring.h>
24#include <qptrlist.h>
25
26/** internal password generator of PwManager */
27class GenPasswd
28{
29protected:
30 struct dynCharset_element
31 {
32 /** charset data */
33 QString data;
34 /** reference counter for the filter */
35 unsigned int refCnt;
36 };
37
38public:
39 GenPasswd();
40
41 /** set the charset to use */
42 void setCharset(bool lower,
43 bool upper,
44 bool num,
45 bool special,
46 bool blank,
47 QString user);
48 /** set the password length */
49 void setLen(int len)
50 { length = len; }
51 /** use the filter? */
52 void setUseFilter(bool use)
53 { useFilter = use; }
54 /** start to generate a new password and return it.
55 * Returns an empty string on error.
56 */
57 QString gen();
58
59protected:
60 /** randomize the dynamic charset */
61 void rndDynCharset();
62 /** select the next charset (based on useFilter) */
63 dynCharset_element * selectNextCharset();
64 /** generate a new random char from the given charset */
65 QChar genNewRandom(const dynCharset_element *charset);
66
67protected:
68 /** password length to generate */
69 int length;
70 /** use the filter? */
71 bool useFilter;
72 /** dynamic charset used for generating the password */
73 QPtrList<dynCharset_element> dynCharset;
74};
75
76#endif // __GENPASSWD_H
diff --git a/pwmanager/pwmanager/getkeycardwnd.cpp b/pwmanager/pwmanager/getkeycardwnd.cpp
new file mode 100644
index 0000000..89dada2
--- a/dev/null
+++ b/pwmanager/pwmanager/getkeycardwnd.cpp
@@ -0,0 +1,67 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003 by Michael Buesch *
4 * email: fsdeveloper@yahoo.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "getkeycardwnd.h"
21
22#include <qmessagebox.h>
23
24#include <klocale.h>
25
26
27GetKeyCardWnd::GetKeyCardWnd(QWidget *parent,
28 const char *name, bool modal, WFlags f)
29 : QDialog(parent, name, modal, f)
30{
31 vbox1 = new QVBox(this);
32 text_label = new QLabel(vbox1);
33 hbox1 = new QHBox(vbox1);
34 okButton = new QPushButton(i18n("&Ok"), hbox1);
35 cancelButton = new QPushButton(i18n("&Cancel"), hbox1);
36
37 vbox1->setSpacing(10);
38 vbox1->setMargin(10);
39 hbox1->setSpacing(10);
40
41 resize(500, 100);
42
43 setCaption(i18n("Insert key-card"));
44 text_label->setText(i18n("Please insert the key-card "
45 "and press the OK button."));
46
47 connect(okButton, SIGNAL(clicked()), this, SLOT(okButton_slot()));
48 connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
49}
50
51GetKeyCardWnd::~GetKeyCardWnd()
52{
53}
54
55void GetKeyCardWnd::resizeEvent(QResizeEvent *)
56{
57 vbox1->resize(size());
58}
59
60void GetKeyCardWnd::okButton_slot()
61{
62 done(1);
63}
64
65#ifndef PWM_EMBEDDED
66#include "getkeycardwnd.moc"
67#endif
diff --git a/pwmanager/pwmanager/getkeycardwnd.h b/pwmanager/pwmanager/getkeycardwnd.h
new file mode 100644
index 0000000..fbe46ee
--- a/dev/null
+++ b/pwmanager/pwmanager/getkeycardwnd.h
@@ -0,0 +1,53 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003 by Michael Buesch *
4 * email: fsdeveloper@yahoo.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef GETKEYCARDWND_H
21#define GETKEYCARDWND_H
22
23#include <qvbox.h>
24#include <qhbox.h>
25#include <qdialog.h>
26#include <qlabel.h>
27#include <qpushbutton.h>
28#include <qevent.h>
29
30/** The equivalent to GetMasterPwWndImpl for chipcards */
31class GetKeyCardWnd : public QDialog
32{
33 Q_OBJECT
34public:
35 GetKeyCardWnd(QWidget *parent = 0, const char *name = 0,
36 bool modal = FALSE, WFlags f = 0);
37 ~GetKeyCardWnd();
38
39protected slots:
40 void okButton_slot();
41
42protected:
43 QVBox *vbox1;
44 QHBox *hbox1;
45 QLabel *text_label;
46 QPushButton *okButton;
47 QPushButton *cancelButton;
48
49protected:
50 void resizeEvent(QResizeEvent *);
51};
52
53#endif
diff --git a/pwmanager/pwmanager/getmasterpwwnd.cpp b/pwmanager/pwmanager/getmasterpwwnd.cpp
new file mode 100644
index 0000000..fb7c8b1
--- a/dev/null
+++ b/pwmanager/pwmanager/getmasterpwwnd.cpp
@@ -0,0 +1,88 @@
1/****************************************************************************
2** Form implementation generated from reading ui file 'getmasterpwwnd.ui'
3**
4** Created: Tue Sep 14 15:33:57 2004
5** by: The User Interface Compiler ($Id$)
6**
7** WARNING! All changes made in this file will be lost!
8****************************************************************************/
9
10#include "getmasterpwwnd.h"
11
12#include <qvariant.h>
13#include <qpushbutton.h>
14#include <qlabel.h>
15#include <qlineedit.h>
16#include <qlayout.h>
17#include <qtooltip.h>
18#include <qwhatsthis.h>
19
20/*
21 * Constructs a getMasterPwWnd as a child of 'parent', with the
22 * name 'name' and widget flags set to 'f'.
23 *
24 * The dialog will by default be modeless, unless you set 'modal' to
25 * TRUE to construct a modal dialog.
26 */
27getMasterPwWnd::getMasterPwWnd( QWidget* parent, const char* name, bool modal, WFlags fl )
28 : QDialog( parent, name, modal, fl )
29{
30 if ( !name )
31 setName( "getMasterPwWnd" );
32
33 okButton = new QPushButton( this, "okButton" );
34 okButton->setGeometry( QRect( 10, 80, 107, 27 ) );
35
36 cancelButton = new QPushButton( this, "cancelButton" );
37 cancelButton->setGeometry( QRect( 240, 80, 107, 27 ) );
38
39 textLabel1 = new QLabel( this, "textLabel1" );
40 textLabel1->setGeometry( QRect( 10, 20, 340, 20 ) );
41 textLabel1->setAlignment( int( QLabel::WordBreak | QLabel::AlignCenter ) );
42
43 pwLineEdit = new QLineEdit( this, "pwLineEdit" );
44 pwLineEdit->setGeometry( QRect( 10, 50, 340, 20 ) );
45 pwLineEdit->setEchoMode( QLineEdit::Password );
46 languageChange();
47 resize( QSize(361, 119).expandedTo(minimumSizeHint()) );
48 clearWState( WState_Polished );
49
50 // signals and slots connections
51 connect( okButton, SIGNAL( clicked() ), this, SLOT( okButton_slot() ) );
52 connect( cancelButton, SIGNAL( clicked() ), this, SLOT( cancelButton_slot() ) );
53
54 // tab order
55 setTabOrder( pwLineEdit, okButton );
56 setTabOrder( okButton, cancelButton );
57}
58
59/*
60 * Destroys the object and frees any allocated resources
61 */
62getMasterPwWnd::~getMasterPwWnd()
63{
64 // no need to delete child widgets, Qt does it all for us
65}
66
67/*
68 * Sets the strings of the subwidgets using the current
69 * language.
70 */
71void getMasterPwWnd::languageChange()
72{
73 setCaption( tr( "Master-password" ) );
74 okButton->setText( tr( "&OK" ) );
75 cancelButton->setText( tr( "&Cancel" ) );
76 textLabel1->setText( tr( "Please enter the master-password:" ) );
77}
78
79void getMasterPwWnd::okButton_slot()
80{
81 qWarning( "getMasterPwWnd::okButton_slot(): Not implemented yet" );
82}
83
84void getMasterPwWnd::cancelButton_slot()
85{
86 qWarning( "getMasterPwWnd::cancelButton_slot(): Not implemented yet" );
87}
88
diff --git a/pwmanager/pwmanager/getmasterpwwnd.h b/pwmanager/pwmanager/getmasterpwwnd.h
new file mode 100644
index 0000000..018628e
--- a/dev/null
+++ b/pwmanager/pwmanager/getmasterpwwnd.h
@@ -0,0 +1,48 @@
1/****************************************************************************
2** Form interface generated from reading ui file 'getmasterpwwnd.ui'
3**
4** Created: Tue Sep 14 15:32:37 2004
5** by: The User Interface Compiler ($Id$)
6**
7** WARNING! All changes made in this file will be lost!
8****************************************************************************/
9
10#ifndef GETMASTERPWWND_H
11#define GETMASTERPWWND_H
12
13#include <qvariant.h>
14#include <qdialog.h>
15
16class QVBoxLayout;
17class QHBoxLayout;
18class QGridLayout;
19class QSpacerItem;
20class QPushButton;
21class QLabel;
22class QLineEdit;
23
24class getMasterPwWnd : public QDialog
25{
26 Q_OBJECT
27
28public:
29 getMasterPwWnd( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
30 ~getMasterPwWnd();
31
32 QPushButton* okButton;
33 QPushButton* cancelButton;
34 QLabel* textLabel1;
35 QLineEdit* pwLineEdit;
36
37public slots:
38 virtual void okButton_slot();
39 virtual void cancelButton_slot();
40
41protected:
42
43protected slots:
44 virtual void languageChange();
45
46};
47
48#endif // GETMASTERPWWND_H
diff --git a/pwmanager/pwmanager/getmasterpwwnd.ui b/pwmanager/pwmanager/getmasterpwwnd.ui
new file mode 100644
index 0000000..78e3dec
--- a/dev/null
+++ b/pwmanager/pwmanager/getmasterpwwnd.ui
@@ -0,0 +1,110 @@
1<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
2<class>getMasterPwWnd</class>
3<widget class="QDialog">
4 <property name="name">
5 <cstring>getMasterPwWnd</cstring>
6 </property>
7 <property name="geometry">
8 <rect>
9 <x>0</x>
10 <y>0</y>
11 <width>361</width>
12 <height>119</height>
13 </rect>
14 </property>
15 <property name="caption">
16 <string>Master-password</string>
17 </property>
18 <widget class="QPushButton">
19 <property name="name">
20 <cstring>okButton</cstring>
21 </property>
22 <property name="geometry">
23 <rect>
24 <x>10</x>
25 <y>80</y>
26 <width>107</width>
27 <height>27</height>
28 </rect>
29 </property>
30 <property name="text">
31 <string>&amp;OK</string>
32 </property>
33 </widget>
34 <widget class="QPushButton">
35 <property name="name">
36 <cstring>cancelButton</cstring>
37 </property>
38 <property name="geometry">
39 <rect>
40 <x>240</x>
41 <y>80</y>
42 <width>107</width>
43 <height>27</height>
44 </rect>
45 </property>
46 <property name="text">
47 <string>&amp;Cancel</string>
48 </property>
49 </widget>
50 <widget class="QLabel">
51 <property name="name">
52 <cstring>textLabel1</cstring>
53 </property>
54 <property name="geometry">
55 <rect>
56 <x>10</x>
57 <y>20</y>
58 <width>340</width>
59 <height>20</height>
60 </rect>
61 </property>
62 <property name="text">
63 <string>Please enter the master-password:</string>
64 </property>
65 <property name="alignment">
66 <set>WordBreak|AlignCenter</set>
67 </property>
68 </widget>
69 <widget class="QLineEdit">
70 <property name="name">
71 <cstring>pwLineEdit</cstring>
72 </property>
73 <property name="geometry">
74 <rect>
75 <x>10</x>
76 <y>50</y>
77 <width>340</width>
78 <height>20</height>
79 </rect>
80 </property>
81 <property name="echoMode">
82 <enum>Password</enum>
83 </property>
84 </widget>
85</widget>
86<connections>
87 <connection>
88 <sender>okButton</sender>
89 <signal>clicked()</signal>
90 <receiver>getMasterPwWnd</receiver>
91 <slot>okButton_slot()</slot>
92 </connection>
93 <connection>
94 <sender>cancelButton</sender>
95 <signal>clicked()</signal>
96 <receiver>getMasterPwWnd</receiver>
97 <slot>cancelButton_slot()</slot>
98 </connection>
99</connections>
100<tabstops>
101 <tabstop>pwLineEdit</tabstop>
102 <tabstop>okButton</tabstop>
103 <tabstop>cancelButton</tabstop>
104</tabstops>
105<slots>
106 <slot>okButton_slot()</slot>
107 <slot>cancelButton_slot()</slot>
108</slots>
109<layoutdefaults spacing="6" margin="11"/>
110</UI>
diff --git a/pwmanager/pwmanager/getmasterpwwndimpl.cpp b/pwmanager/pwmanager/getmasterpwwndimpl.cpp
new file mode 100644
index 0000000..db0223e
--- a/dev/null
+++ b/pwmanager/pwmanager/getmasterpwwndimpl.cpp
@@ -0,0 +1,46 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "getmasterpwwndimpl.h"
21
22#include <qlineedit.h>
23
24GetMasterPwWndImpl::GetMasterPwWndImpl(QWidget * parent, const char *name)
25: getMasterPwWnd(parent, name)
26{
27}
28
29GetMasterPwWndImpl::~GetMasterPwWndImpl()
30{
31}
32
33void GetMasterPwWndImpl::okButton_slot()
34{
35 if (pwLineEdit->text() != "")
36 done(1);
37}
38
39void GetMasterPwWndImpl::cancelButton_slot()
40{
41 done(2);
42}
43
44#ifndef PWM_EMBEDDED
45#include "getmasterpwwndimpl.moc"
46#endif
diff --git a/pwmanager/pwmanager/getmasterpwwndimpl.h b/pwmanager/pwmanager/getmasterpwwndimpl.h
new file mode 100644
index 0000000..28aa427
--- a/dev/null
+++ b/pwmanager/pwmanager/getmasterpwwndimpl.h
@@ -0,0 +1,40 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef GETMASTERPWWNDIMPL_H
21#define GETMASTERPWWNDIMPL_H
22
23#include "getmasterpwwnd.h"
24
25/** set master pw wnd */
26class GetMasterPwWndImpl : public getMasterPwWnd
27{
28 Q_OBJECT
29public:
30 GetMasterPwWndImpl(QWidget* parent = 0, const char *name = 0);
31 ~GetMasterPwWndImpl();
32
33public slots:
34 /** ok button pressed */
35 void okButton_slot();
36 /** cancel button pressed */
37 void cancelButton_slot();
38};
39
40#endif
diff --git a/pwmanager/pwmanager/globalstuff.cpp b/pwmanager/pwmanager/globalstuff.cpp
new file mode 100644
index 0000000..b12d3a4
--- a/dev/null
+++ b/pwmanager/pwmanager/globalstuff.cpp
@@ -0,0 +1,35 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "globalstuff.h"
21
22#include <kmessagebox.h>
23#include <klocale.h>
24
25#ifndef CONFIG_KEYCARD
26void no_keycard_support_msg_box(QWidget *parentWidget)
27{
28 KMessageBox::error(parentWidget,
29 i18n("No Chipcard-support available!\n"
30 "If you want to use a chipcard, "
31 "you have to compile PwManager with the "
32 "configure option --enable-keycard ."),
33 i18n("No Chipcard-support"));
34}
35#endif // CONFIG_KEYCARD
diff --git a/pwmanager/pwmanager/globalstuff.h b/pwmanager/pwmanager/globalstuff.h
new file mode 100644
index 0000000..7bc4173
--- a/dev/null
+++ b/pwmanager/pwmanager/globalstuff.h
@@ -0,0 +1,113 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef __GLOBALSTUFF_H
21#define __GLOBALSTUFF_H
22
23#ifndef PWM_EMBEDDED
24#include "config.h"
25#endif
26
27#include "compiler.h"
28
29#include <string>
30#include <sstream>
31
32#ifndef CONFIG_KEYCARD
33class QWidget;
34void no_keycard_support_msg_box(QWidget *parentWidget);
35#endif // CONFIG_KEYCARD
36
37#ifdef PROG_NAME
38# undef PROG_NAME
39#endif
40 #define PROG_NAME"PwManager"
41
42#ifdef PACKAGE_NAME
43# undef PACKAGE_NAME
44#endif
45 #define PACKAGE_NAME"pwmanager"
46
47#ifdef PACKAGE_VER
48# undef PACKAGE_VER
49#endif
50 #define PACKAGE_VER"1.0.1"
51
52#ifdef CONFIG_DEBUG
53# define PWM_DEBUG
54#else
55# undef PWM_DEBUG
56#endif
57
58#ifdef QT_MAKE_VERSION
59# undef QT_MAKE_VERSION
60#endif
61 #define QT_MAKE_VERSION(a,b,c)(((a) << 16) | ((b) << 8) | (c))
62
63/** remove "unused parameter" warnings */
64#ifdef PARAM_UNUSED
65# undef PARAM_UNUSED
66#endif
67 #define PARAM_UNUSED(x)(void)x
68
69/** return the number of elements in an array */
70#ifdef array_size
71# undef array_size
72#endif
73 #define array_size(x)(sizeof(x) / sizeof((x)[0]))
74
75/** convert something to string using ostringstream */
76template <class T> inline
77std::string tostr(const T &t)
78{
79 std::ostringstream s;
80 s << t;
81 return s.str();
82}
83
84/** delete the memory and NULL the pointer */
85template<class T> inline
86void delete_and_null(T *&p)
87{
88 delete p;
89 p = 0;
90}
91/** delete the memory if the pointer isn't a NULL pointer */
92template<class T> inline
93void delete_ifnot_null(T *&p)
94{
95 if (p)
96 delete_and_null(p);
97}
98
99template<class T> inline
100void delete_and_null_array(T *&p)
101{
102 delete [] p;
103 p = 0;
104}
105
106template<class T> inline
107void delete_ifnot_null_array(T *&p)
108{
109 if (p)
110 delete_and_null_array(p);
111}
112
113#endif // GLOBALSTUFF_H
diff --git a/pwmanager/pwmanager/gpasmanfile.cpp b/pwmanager/pwmanager/gpasmanfile.cpp
new file mode 100644
index 0000000..f80bc13
--- a/dev/null
+++ b/pwmanager/pwmanager/gpasmanfile.cpp
@@ -0,0 +1,437 @@
1/* Gpasman, a password manager
2 Copyright (C) 1998-1999 Olivier Sessink, olivier@lx.student.wau.nl
3
4 file.c, handles file opening and closing
5
6 Other code contributors:
7 Dave Rudder
8 Chris Halverson
9 Matthew Palmer
10 Guide Berning
11 Jimmy Mason
12 website at http://www.student.wau.nl/~olivier/gpasman/
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27*/
28
29/* 2003/06/10:
30 * modified by Michael Buesch to work together
31 * with PwM as import/export module.
32 */
33
34/***************************************************************************
35 * copyright (C) 2004 by Ulf Schenk
36 * This file is originaly based on version 1.0.1 of pwmanager
37 * and was modified to run on embedded devices that run microkde
38 *
39 * $Id$
40 **************************************************************************/
41
42#include <sys/types.h>
43#include <sys/stat.h>
44#include <stdio.h>
45#include <fcntl.h>
46#include <stdlib.h>
47#include <unistd.h>
48#include <string.h>
49#include <errno.h>
50
51#include "gpasmanfile.h"
52#include "globalstuff.h"
53
54#define SAVE_BUFFER_LENGTH 1024
55#define LOAD_BUFFER_LENGTH 2048
56
57#ifndef S_IAMB
58#define S_IAMB 00777
59#endif
60
61// enable/disable debug output
62//#define GPASMANFILE_DEBUG
63#undef GPASMANFILE_DEBUG
64
65
66#if defined(PWM_DEBUG) && defined(GPASMANFILE_DEBUG)
67 # define DBG(msg,x...)do { fprintf(stderr, msg "\n" , ##x); } while (0)
68#else
69 # define DBG(msg,x...)do { } while (0)
70#endif
71
72#ifdef BIG_ENDIAN_HOST
73# define WORDS_BIGENDIAN
74#else
75# undef WORDS_BIGENDIAN
76#endif
77
78
79GpasmanFile::GpasmanFile()
80{
81}
82
83GpasmanFile::~GpasmanFile()
84{
85}
86
87int GpasmanFile::save_init(const char *filename, const char *password)
88{
89
90/*
91 * returncodes:
92 * 1 = success
93 * 0 = can't open filedescriptor / can't create file
94 * -1 = permissions are bad
95 * -2 = is a symlink
96 * -3 = can't get file status
97 */
98
99 unsigned char key[128];
100 unsigned int j = 0;
101 unsigned int keylength;
102 int val, count2;
103
104 /* first we should check the permissions of the filename */
105
106 if (file_exists(filename)) {
107 val = check_file(filename);
108 if (val != 1) {
109 DBG("save_init, return %d", val);
110 return val;
111 }
112 } else {
113 val = creat(filename, (S_IRUSR | S_IWUSR));
114 if (val == -1) {
115 DBG("%s", "save_init, return 0");
116 return 0;
117 } else {
118 close(val);
119 }
120 }
121
122 fd = fopen(filename, "wb");
123 if (fd == NULL) {
124 return 0;
125 }
126 buffer = (char*)malloc(SAVE_BUFFER_LENGTH);
127
128 /* make the key ready */
129 DBG("save_init, password=%s", password);
130 for (j = 0; password[j] != '\0'; j++) {
131 key[j] = password[j];
132 }
133 keylength = j;
134 rc2.rc2_expandkey((char*)key, (int)keylength, 128);
135
136 /* First, we make the IV */
137 for (count2 = 0; count2 < 4; count2++) {
138 iv[count2] = rand();
139 putc((unsigned char) (iv[count2] >> 8), fd);
140 putc((unsigned char) (iv[count2] & 0xff), fd);
141 }
142
143 bufferIndex = 0;
144 return 1;
145}
146
147int GpasmanFile::save_entry(char *entry[4])
148{
149
150 char *text1;
151 int count2, count3;
152 unsigned short ciphertext[4];
153
154 buffer = (char*)memset(buffer, '\0', SAVE_BUFFER_LENGTH);
155
156 for (count2 = 0; count2 < 4; count2++) {
157 text1 = entry[count2];
158 if (strlen(text1) == 0) {
159 strncpy(text1, " ", strlen(" "));
160 }
161 strncat(buffer, text1, strlen(text1));
162 /* Use 255 as the marker. \n is too tough to test for */
163 buffer[strlen(buffer)] = 255;
164
165 } /*for (count2 = 0; count2 < 4; count2++) */
166 DBG("save_entry, buffer contains %s", buffer);
167 count2 = 0;
168 /* I'm using CBC mode and encrypting the data straight from top down.
169 * At the bottom, encrypted, I will append an MD5 hash of the file, eventually.
170 * PKCS 5 padding (explained at the code section
171 */
172 while (count2 < (int)strlen(buffer)) {
173#ifndef WORDS_BIGENDIAN
174 plaintext[bufferIndex] = buffer[count2 + 1] << 8;
175 plaintext[bufferIndex] += buffer[count2] & 0xff;
176#else
177 plaintext[bufferIndex] = buffer[count2] << 8;
178 plaintext[bufferIndex] += buffer[count2 + 1] & 0xff;
179#endif
180 bufferIndex++;
181 if (bufferIndex == 4) {
182 rc2.rc2_encrypt(plaintext);
183
184 for (count3 = 0; count3 < 4; count3++) {
185 ciphertext[count3] =
186 iv[count3] ^ plaintext[count3];
187
188 /* Now store the ciphertext as the iv */
189 iv[count3] = plaintext[count3];
190
191 /* reset the buffer index */
192 bufferIndex = 0;
193 if (putc
194 ((unsigned char) (ciphertext[count3] >> 8),
195 fd) == EOF)
196 return -1;
197 if (putc
198 ((unsigned char) (ciphertext[count3] &
199 0xff), fd) == EOF)
200 return -1;
201 }/*for (count3 = 0; count3 < 4; count3++) */
202 }
203 /*if (bufferIndex == 4) */
204 /* increment a short, not a byte */
205 count2 += 2;
206 } /*while (count2 < strlen (buffer)) */
207 return 1;
208}
209
210int GpasmanFile::save_finalize(void)
211{
212
213 int count1, retval = 1;
214 unsigned short ciphertext[4];
215
216 /* Tack on the PKCS 5 padding
217 How it works is we fill up the last n bytes with the value n
218
219 So, if we have, say, 13 bytes, 8 of which are used, we have 5 left
220 over, leaving us 3 short, so we fill it in with 3's.
221
222 If we come out even, we fill it with 8 8s
223
224 um, except that in this instance we are using 4 shorts instead of 8 bytes.
225 so, half everything
226 */
227 for (count1 = bufferIndex; count1 < 4; count1++) {
228 plaintext[count1] = (4 - bufferIndex);
229 }
230 DBG("save_finalize, 4 - bufferIndex = %d",
231 4 - bufferIndex);
232 DBG("save_finalize, plaintext[3]=%c", plaintext[3]);
233 rc2.rc2_encrypt(plaintext);
234 for (count1 = 0; count1 < 4; count1++) {
235 ciphertext[count1] = iv[count1] ^ plaintext[count1];
236 if (putc((unsigned char) (ciphertext[count1] >> 8), fd) == EOF)
237 retval = -1;
238 if (putc((unsigned char) (ciphertext[count1] & 0xff), fd) ==
239 EOF)
240 retval = -1;
241 }
242
243 fclose(fd);
244 DBG("%s", "save_finalize, fd is closed");
245 free(buffer);
246 return retval;
247
248}
249
250int GpasmanFile::load_init(const char *filename, const char *password)
251{
252/*
253 * returncodes:
254 * 1 = success
255 * 0 = can't open filedescriptor / can't create file
256 * -1 = permissions are bad
257 * -2 = is a symlink
258 * -3 = can't get file status
259 */
260 unsigned int j = 0;
261 unsigned int keylength = 0;
262 int count = 0, count2 = 0, count3 = 0;
263 unsigned char charbuf[8];
264 unsigned short ciphertext[4];
265 int val = 0;
266 unsigned char key[128];
267
268 /* first we should check the file permissions */
269 if (file_exists(filename)) {
270 val = check_file(filename);
271 if (val != 1) {
272 return val;
273 }
274 } else {
275 return 0;
276 }
277
278 fd = fopen(filename, "rb");
279 if (fd == NULL) {
280 return 0;
281 }
282
283 buffer = (char*)malloc(LOAD_BUFFER_LENGTH);
284 DBG("load_init, password=\"%s\"", password);
285 for (j = 0; password[j] != '\0'; j++) {
286 key[j] = password[j];
287 }
288 keylength = j;
289 rc2.rc2_expandkey((char*)key, (int)keylength, 128);
290
291 size = read(fileno(fd), (unsigned char *) (charbuf + count), 8);
292 DBG("load_init, size=%d, keylength=%d", size, keylength);
293
294 if (size < 8) {
295 fclose(fd);
296 free(buffer);
297 return -1;
298 }
299
300 for (count = 0; count < 4; count++) {
301 count2 = count << 1;
302 iv[count] = charbuf[count2] << 8;
303 iv[count] += charbuf[count2 + 1];
304 DBG("load_init iv[%d]=%d", count, iv[count]);
305 }
306
307 size = 0;
308 bufferIndex = 0;
309 while ((count = read(fileno(fd), (unsigned char *) charbuf, 8)) > 0) {
310 DBG("load_init A, count=%d, count2=%d", count, count2);
311 while (count < 8) {
312 count2 = read(fileno(fd), (unsigned char *) (charbuf +
313 count), 8);
314 DBG("load_init B, count=%d, count2=%d",
315 count, count2);
316 if (count2 == 0) {
317 printf("bad EOF\n");
318 fclose(fd);
319 free(buffer);
320 return -1;
321 }
322 count += count2;
323 } /* while (count < 8) */
324
325 size += 8;
326 DBG("load_init charbuf[1]=%c", charbuf[1]);
327 for (count2 = 0; count2 < 8; count2 += 2) {
328 count3 = count2 >> 1;
329 ciphertext[count3] = charbuf[count2] << 8;
330 ciphertext[count3] += charbuf[count2 + 1];
331
332 plaintext[count3] = ciphertext[count3] ^ iv[count3];
333 iv[count3] = plaintext[count3];
334 }
335
336 rc2.rc2_decrypt(plaintext);
337 memcpy((unsigned char *) (buffer + bufferIndex), plaintext, 8);
338 bufferIndex += 8;
339 buffer[bufferIndex + 1] = '\0';
340 DBG("bufferIndex=%d, buffer=%s", bufferIndex,
341 buffer);
342 } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */
343 DBG("load_init, size=%d, buffer[size-1]=%d,", size,
344 buffer[size - 1]);
345 size -= buffer[size - 1];
346 DBG("size=%d", size);
347 lastcount = 0;
348
349 /* This will point to the starting index */
350 bufferIndex = 0;
351 return 1;
352}
353
354int GpasmanFile::load_entry(char *entry[4])
355{
356/* Strip off PKCS 5 padding
357 Should check to make sure it's good here
358 */
359 int count, count1 = 0;
360 DBG("load_entry, lastcount=%d, size=%d, entry=%p",
361 lastcount, size, entry);
362
363 for (count = lastcount; count < size; count++) {
364 if ((unsigned char) (buffer[count]) == 255) {
365 if (buffer[bufferIndex] == '\0') {
366 bufferIndex++;
367 }
368 entry[count1] =
369 (char *) malloc(count - bufferIndex + 1);
370 DBG("load_entry, entry[%d]=%p", count1,
371 entry[count1]);
372 memcpy(entry[count1],
373 (unsigned char *) (buffer + bufferIndex),
374 count - bufferIndex);
375 entry[count1][count - bufferIndex] = '\0';
376 DBG("load_entry, entry[%d]=%s", count1,
377 entry[count1]);
378 count++;
379 bufferIndex = count;
380 count1++;
381 if (count1 == 4) {
382 lastcount = count;
383 DBG("%s", "load_entry, return 1, entry ready");
384 return 1;
385 }
386 } /* if ((unsigned char) (buffer[count]) == 255) */
387 } /* for (count = 0; count < size; count++) */
388
389 DBG("%s", "load_entry, ended no entry anymore");
390 return 2;
391}
392
393void GpasmanFile::load_finalize(void)
394{
395 fclose(fd);
396 free(buffer);
397}
398
399int GpasmanFile::check_file(const char *filename)
400{
401 struct stat naamstat;
402
403 if (stat(filename, &naamstat) == -1) {
404 return (-3);
405 }
406
407 if (((naamstat.st_mode & S_IAMB) | (S_IRUSR | S_IWUSR)) != (S_IRUSR |
408 S_IWUSR)) {
409 DBG("%s perms are bad, they are: %ld, should be -rw------",
410 filename, (naamstat.st_mode & (S_IREAD | S_IWRITE)));
411 return (-1);
412 }
413
414 if (!S_ISREG(naamstat.st_mode)) {
415 lstat(filename, &naamstat);
416 if (S_ISLNK(naamstat.st_mode)) {
417 DBG("%s is a symlink", filename);
418 return (-2);
419 }
420 }
421
422 return (1);
423}
424
425int GpasmanFile::file_exists(const char *tfile)
426{
427 struct stat naamstat;
428
429 if ((stat(tfile, &naamstat) == -1) && (errno == ENOENT)) {
430 DBG("file_exists, %s does NOT exist", tfile);
431 return (0);
432 } else {
433 DBG("file_exists, %s DOES exist", tfile);
434 return (1);
435 }
436}
437
diff --git a/pwmanager/pwmanager/gpasmanfile.h b/pwmanager/pwmanager/gpasmanfile.h
new file mode 100644
index 0000000..d2b7dc5
--- a/dev/null
+++ b/pwmanager/pwmanager/gpasmanfile.h
@@ -0,0 +1,67 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * Gpasman, a password manager *
7 * Copyright (C) 1998-1999 Olivier Sessink, olivier@lx.student.wau.nl *
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License version 2 *
11 * as published by the Free Software Foundation. *
12 * *
13 ***************************************************************************/
14
15/***************************************************************************
16 * copyright (C) 2004 by Ulf Schenk
17 * This file is originaly based on version 1.0.1 of pwmanager
18 * and was modified to run on embedded devices that run microkde
19 *
20 * $Id$
21 **************************************************************************/
22
23#ifndef GPASMANFILE_H
24#define GPASMANFILE_H
25
26#include "rc2.h"
27
28#include <stdio.h>
29
30/** gpasman / kpasman file read/write module */
31class GpasmanFile
32{
33public:
34 GpasmanFile();
35 ~GpasmanFile();
36
37 /*
38 * one entry is a char *entry[4]
39 * this means we have 4 pointers to a char -->
40 * 0 = server
41 * 1 = username
42 * 2 = password
43 * 3 = comment
44 */
45
46 int save_init(const char *filename, const char *password);
47 int save_entry(char *entry[4]);
48 int save_finalize(void);
49 int load_init(const char *filename, const char *password);
50 int load_entry(char *entry[4]);
51 void load_finalize(void);
52
53protected:
54 int check_file(const char *filename);
55 int file_exists(const char *tfile);
56
57protected:
58 FILE *fd;
59 unsigned short iv[4];
60 char *buffer;
61 int bufferIndex;
62 unsigned short plaintext[4];
63 int lastcount, size;
64 Rc2 rc2;
65};
66
67#endif
diff --git a/pwmanager/pwmanager/htmlgen.cpp b/pwmanager/pwmanager/htmlgen.cpp
new file mode 100644
index 0000000..166b987
--- a/dev/null
+++ b/pwmanager/pwmanager/htmlgen.cpp
@@ -0,0 +1,248 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "htmlgen.h"
21#include "pwmexception.h"
22
23#include <kstandarddirs.h>
24
25/** enable/disable HTML-generator debugging (0/1) */
26 #define HTMLGEN_DEBUG0
27
28
29 #define HTML_DOCTYPE_HDR"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
30 #define HTML_PWM_HDR "<!-- PwManager generated HTML -->"
31 #define HTML_COMMENT_HDR"<!-- type: comment -->"
32 #define HTML_COMMENTVER_HDR"<!-- ver: 0.1 -->"
33 #define HTML_STYLESHEET_DUMMY"@STYLESHEET@"
34 #define HTML_GLOBTBL_CLASS"\"globtable\""
35 #define HTML_GLOBTITLE_CLASS"\"globtitle\""
36 #define HTML_SUBTBL_CLASS"\"subtable\""
37 #define HTML_SUBTITLE_CLASS"\"subtitle\""
38 #define HTML_ENTRY_CLASS"\"entry\""
39 #define HTML_VALUE_CLASS"\"value\""
40 #define PATH_COMMENTSTYLE_CSS"pwmanager/html/htmlcomment_style.css"
41#if defined(PWM_DEBUG) && HTMLGEN_DEBUG != 0
42 #define HTML_ENDL "\n"
43#else // defined(PWM_DEBUG) && ...
44 #define HTML_ENDL ""
45#endif // defined(PWM_DEBUG) && ...
46
47
48HtmlGen::HtmlGen()
49{
50 useSSDummy = true;
51}
52
53HtmlGen::~HtmlGen()
54{
55}
56
57QString HtmlGen::escapeHtmlText(const QString &str)
58{
59 QString ret;
60 unsigned int len = str.length(), i;
61 char c;
62 for (i = 0; i < len; ++i) {
63 c = str[i];
64 switch (c) {
65 case '<':
66 ret.append("&lt;");
67 break;
68 case '>':
69 ret.append("&gt;");
70 break;
71 case '&':
72 ret.append("&amp;");
73 break;
74 case '\"':
75 ret.append("&quot;");
76 break;
77 case 'ä':
78 ret.append("&auml;");
79 break;
80 case 'Ä':
81 ret.append("&Auml;");
82 break;
83 case 'ü':
84 ret.append("&uuml;");
85 break;
86 case 'Ü':
87 ret.append("&Uuml;");
88 break;
89 case 'ö':
90 ret.append("&ouml;");
91 break;
92 case 'Ö':
93 ret.append("&Ouml;");
94 break;
95 case 'ß':
96 ret.append("&szlig;");
97 break;
98 case '¿':
99 ret.append("&euro;");
100 break;
101 default:
102 ret.append(c);
103 }
104 }
105 return ret;
106}
107
108bool HtmlGen::isHtml(const QString &dta)
109{
110 int ret;
111 ret = dta.find("<html>", 0, false);
112 if (ret == -1)
113 return false;
114 ret = dta.find("<head>", ret, false);
115 if (ret == -1)
116 return false;
117 return true;
118}
119
120QString HtmlGen::getStyleSheetHtml()
121{
122 QString ret;
123 ret = "<link rel=\"stylesheet\" href=\"";
124 QString cssPath(::locate("data", PATH_COMMENTSTYLE_CSS));
125 if ((cssPath == QString::null) || (cssPath == "")) {
126 printDebug("HtmlGen::getStyleSheetHtml(): not found");
127 return "";
128 }
129 ret += cssPath;
130 ret += "\" type=\"text/css\">" HTML_ENDL;
131 return ret;
132}
133
134bool HtmlGen::replaceSSDummy(QString *doc)
135{
136 int beginPos = doc->find(HTML_STYLESHEET_DUMMY);
137 if (beginPos == -1) {
138 printDebug("HtmlGen::replaceSSDummy(): not found");
139 return false;
140 }
141 *doc = doc->replace(beginPos, strlen(HTML_STYLESHEET_DUMMY),
142 getStyleSheetHtml());
143 return true;
144}
145
146QString HtmlGen::genHtmlComment(const HtmlComment *dta)
147{
148 QString ret(HTML_DOCTYPE_HDR
149 HTML_PWM_HDRHTML_ENDL
150 HTML_COMMENT_HDRHTML_ENDL
151 HTML_COMMENTVER_HDRHTML_ENDL);
152 ret += "<html>" HTML_ENDL;
153 if (!appendCommentHeader(&ret))
154 return "";
155 if (!appendCommentBody(&ret, dta))
156 return "";
157 ret += "</html>" HTML_ENDL;
158
159#if defined(PWM_DEBUG) && HTMLGEN_DEBUG != 0
160 printDebug("<BEGIN HtmlGen::genHtmlComment() dump>");
161 cout << ret << endl;
162 printDebug("<END HtmlGen::genHtmlComment() dump>");
163#endif // DEBUG
164 return ret;
165}
166
167bool HtmlGen::appendCommentHeader(QString *str)
168{
169 *str += "<head>" HTML_ENDL;
170 if (useSSDummy) {
171 *str += HTML_STYLESHEET_DUMMYHTML_ENDL;
172 } else {
173 QString ssLine(getStyleSheetHtml());
174 if (ssLine.isEmpty())
175 return false;
176 *str += ssLine;
177 }
178 *str += "</head>" HTML_ENDL;
179 return true;
180}
181
182bool HtmlGen::appendCommentBody(QString *str,
183 const HtmlComment *dta)
184{
185 *str += "<body>" HTML_ENDL;
186 if (!appendCommentGlobTbl(str, dta))
187 return false;
188 *str += "</body>" HTML_ENDL;
189 return true;
190}
191
192bool HtmlGen::appendCommentGlobTbl(QString *str,
193 const HtmlComment *dta)
194{
195 *str += "<table class=" HTML_GLOBTBL_CLASS ">" HTML_ENDL;
196 *str += "<tr><th class=" HTML_GLOBTITLE_CLASS ">";
197 *str += escapeHtmlText(dta->getTitle());
198 *str += "</th></tr>" HTML_ENDL;
199
200 const vector<HtmlComment::SubTable> *subTbls = dta->getSubTableList();
201 vector<HtmlComment::SubTable>::const_iterator i = subTbls->begin(),
202 end = subTbls->end();
203 while (i != end) {
204 *str += "<tr><td>" HTML_ENDL;
205 if (!appendCommentSubTbl(str, &(*i)))
206 return false;
207 ++i;
208 *str += "</td></tr>" HTML_ENDL;
209 }
210
211 *str += "</table>" HTML_ENDL;
212 return true;
213}
214
215bool HtmlGen::appendCommentSubTbl(QString *str,
216 const HtmlComment::SubTable *dta)
217{
218 *str += "<table class=" HTML_SUBTBL_CLASS ">" HTML_ENDL;
219 *str += "<tr><th colspan=\"2\" class=" HTML_SUBTITLE_CLASS ">";
220 *str += escapeHtmlText(dta->getTitle());
221 *str += "</th></tr>" HTML_ENDL;
222
223 const vector< pair<QString, QString> > *entries = dta->getEntryList();
224 vector< pair<QString, QString> >::const_iterator i = entries->begin(),
225 end = entries->end();
226 while (i != end) {
227 *str += "<tr>" HTML_ENDL;
228 if (!appendCommentSubTblEntry(str, &(*i)))
229 return false;
230 *str += "</tr>" HTML_ENDL;
231 ++i;
232 }
233
234 *str += "</table>" HTML_ENDL;
235 return true;
236}
237
238bool HtmlGen::appendCommentSubTblEntry(QString *str,
239 const pair<QString, QString> *dta)
240{
241 *str += "<td class=" HTML_ENTRY_CLASS ">";
242 *str += escapeHtmlText(dta->first);
243 *str += "</td>" HTML_ENDL;
244 *str += "<td class=" HTML_VALUE_CLASS ">";
245 *str += escapeHtmlText(dta->second);
246 *str += "</td>" HTML_ENDL;
247 return true;
248}
diff --git a/pwmanager/pwmanager/htmlgen.h b/pwmanager/pwmanager/htmlgen.h
new file mode 100644
index 0000000..5ec9626
--- a/dev/null
+++ b/pwmanager/pwmanager/htmlgen.h
@@ -0,0 +1,136 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef HTMLGEN_H
21#define HTMLGEN_H
22
23#include <qstring.h>
24
25#include <utility>
26#include <vector>
27
28using std::vector;
29using std::pair;
30
31/** internal representation of the advanced HTML-comment */
32class HtmlComment
33{
34public:
35 class SubTable
36 {
37 public:
38 SubTable() {}
39 ~SubTable() {}
40
41 void clear()
42 {
43 title = "";
44 entries.clear();
45 }
46 void setTitle(const QString &_title)
47 { title = _title; }
48 QString getTitle() const
49 { return title; }
50 void addEntry(const pair<QString, QString> &entry)
51 { entries.push_back(entry); }
52 void setEntries(const vector< pair<QString, QString> > *_entries)
53 { entries = *_entries; }
54 const vector< pair<QString, QString> > * getEntryList() const
55 { return &entries; }
56
57 protected:
58 /** sub-title */
59 QString title;
60 /** list of entries */
61 vector< pair<QString, QString> > entries;
62 };
63
64public:
65 HtmlComment() {}
66 ~HtmlComment() {}
67
68 void clear()
69 {
70 title = "";
71 subTables.clear();
72 }
73 void setTitle(const QString &_title)
74 { title = _title; }
75 QString getTitle() const
76 { return title; }
77 void addSubtable(const SubTable &subTable)
78 { subTables.push_back(subTable); }
79 void eraseSubtable(int index)
80 { subTables.erase(subTables.begin() + index); }
81 const SubTable & subtableAt(int index)
82 { return subTables[index]; }
83 void setSubtblAt(int index, const SubTable &entry)
84 { subTables[index] = entry; }
85 const vector<SubTable> * getSubTableList() const
86 { return &subTables; }
87
88protected:
89 /** global title */
90 QString title;
91 /** list of sub-tables */
92 vector<SubTable> subTables;
93};
94
95/** HTML generator for the comment-box */
96class HtmlGen
97{
98public:
99 HtmlGen();
100 ~HtmlGen();
101
102 /** replace the @STYLESHEET@ dummy in the "doc" HTML document */
103 static bool replaceSSDummy(QString *doc);
104 /** check whether "dta" is HTML-code */
105 static bool isHtml(const QString &dta);
106
107 /** insert the stylesheet link as dummy? default is true */
108 void styleSheetDummy(bool dummy)
109 { useSSDummy = dummy; }
110 /** generate a new html-comment */
111 QString genHtmlComment(const HtmlComment *dta);
112
113protected:
114 /** converts the string "str" into HTML-text and ensures
115 * that there are no collisions with HTML-tags
116 */
117 QString escapeHtmlText(const QString &str);
118 /** get the "stylesheet-line" to import the CSS style in HTML */
119 static QString getStyleSheetHtml();
120 /** append the HTML header to the data stream */
121 bool appendCommentHeader(QString *str);
122 /** append the HTML body for the comment */
123 bool appendCommentBody(QString *str, const HtmlComment *dta);
124 /** append a global comment table */
125 bool appendCommentGlobTbl(QString *str, const HtmlComment *dta);
126 /** append a comment subtable */
127 bool appendCommentSubTbl(QString *str, const HtmlComment::SubTable *dta);
128 /** append a subtable entry */
129 bool appendCommentSubTblEntry(QString *str, const pair<QString, QString> *dta);
130
131protected:
132 /** use stylesheet dummy */
133 bool useSSDummy;
134};
135
136#endif
diff --git a/pwmanager/pwmanager/htmlparse.cpp b/pwmanager/pwmanager/htmlparse.cpp
new file mode 100644
index 0000000..acde2e3
--- a/dev/null
+++ b/pwmanager/pwmanager/htmlparse.cpp
@@ -0,0 +1,184 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12#include "htmlparse.h"
13#include "pwmexception.h"
14
15#include <dom/html_document.h>
16#include <dom/html_element.h>
17#include <dom/html_misc.h>
18
19
20/** enable/disable HTML-parser debugging (0/1) */
21 #define HTMLPARSE_DEBUG 1
22
23
24#if !defined(PWM_DEBUG) || HTMLPARSE_DEBUG == 0
25# undef printDebug
26 # define printDebug(x)do {} while (0)
27#endif
28
29HtmlParse::HtmlParse()
30{
31}
32
33HtmlParse::~HtmlParse()
34{
35}
36
37bool HtmlParse::parseHtmlComment(const QString &dta,
38 HtmlComment *ret)
39{
40 PWM_ASSERT(ret);
41 ret->clear();
42 DOM::HTMLDocument curDoc(static_cast<KHTMLView *>(0));
43 curDoc.open();
44 curDoc.write(dta);
45 curDoc.close();
46 DOM::HTMLElement body(curDoc.body());
47 DOM::HTMLCollection children(body.children());
48
49 unsigned long i, numCh = children.length();
50 if (numCh != 1) {
51 /* we currently support only one global table */
52 printDebug("HtmlParse::parseHtmlComment(): global children cnt != 1");
53 return false;
54 }
55 DOM::DOMString nodeName;
56 DOM::Node curNode;
57 for (i = 0; i < numCh; ++i) {
58 curNode = children.item(i);
59 nodeName = curNode.nodeName();
60 if (nodeName == "table") {
61 if (!parseCommentGlobTbl(curNode, ret))
62 return false;
63 } else {
64 // We don't support something else than tables, yet.
65 printDebug("HtmlParse::parseHtmlComment(): unknown node");
66 }
67 }
68 return true;
69}
70
71bool HtmlParse::parseCommentGlobTbl(const DOM::Node &node,
72 HtmlComment *ret)
73{
74 PWM_ASSERT(node.nodeName() == "table");
75 DOM::Node bodyNode(node.firstChild());
76 PWM_ASSERT(bodyNode.nodeName() == "tbody");
77 DOM::Node curNode(bodyNode.firstChild());
78 DOM::DOMString nodeName;
79 ret->clear();
80 while (!curNode.isNull()) {
81 nodeName = curNode.nodeName();
82 if (nodeName == "tr") {
83 if (!parseCommentGlobTblRow(curNode, ret))
84 return false;
85 } else {
86 printDebug("HtmlParse::parseCommentGlobTbl(): node unknown");
87 }
88 curNode = curNode.nextSibling();
89 }
90 return true;
91}
92
93bool HtmlParse::parseCommentGlobTblRow(const DOM::Node &node,
94 HtmlComment *ret)
95{
96 DOM::Node curNode(node.firstChild()), child;
97 DOM::DOMString nodeName;
98 HtmlComment::SubTable subTbl;
99 while (!curNode.isNull()) {
100 nodeName = curNode.nodeName();
101 if (nodeName == "th") {
102 // global title
103 ret->setTitle(curNode.firstChild().nodeValue().string());
104 } else if (nodeName == "td") {
105 child = curNode.firstChild();
106 if (child.nodeName() == "table" &&
107 child.firstChild().nodeName() == "tbody") {
108 // we have a sub-table
109 if (!parseCommentSubTbl(child.firstChild(), &subTbl))
110 return false;
111 ret->addSubtable(subTbl);
112 } else {
113 printDebug("HtmlParse::parseCommentGlobTblRow(): subelement unknown");
114 }
115 } else {
116 printDebug("HtmlParse::parseCommentGlobTblRow(): node unknown");
117 }
118 curNode = curNode.nextSibling();
119 }
120 return true;
121}
122
123bool HtmlParse::parseCommentSubTbl(const DOM::Node &node,
124 HtmlComment::SubTable *ret)
125{
126 PWM_ASSERT(node.nodeName() == "tbody");
127 DOM::Node curNode(node.firstChild());
128 DOM::DOMString nodeName;
129 ret->clear();
130 while (!curNode.isNull()) {
131 nodeName = curNode.nodeName();
132 if (nodeName == "tr") {
133 if (!parseCommentSubTblRow(curNode, ret))
134 return false;
135 } else {
136 printDebug("HtmlParse::parseCommentSubTbl(): node unknown");
137 }
138 curNode = curNode.nextSibling();
139 }
140 return true;
141}
142
143bool HtmlParse::parseCommentSubTblRow(const DOM::Node &node,
144 HtmlComment::SubTable *ret)
145{
146 DOM::Node curNode(node.firstChild()), child;
147 DOM::DOMString nodeName;
148 pair<QString, QString> curEntr;
149 while (!curNode.isNull()) {
150 nodeName = curNode.nodeName();
151 if (nodeName == "th") {
152 // sub title
153 ret->setTitle(curNode.firstChild().nodeValue().string());
154 } else if (nodeName == "td") {
155 child = curNode.firstChild();
156 if (child.nodeName() == "#text") {
157 if (!parseCommentSubTblEntry(curNode, &curEntr))
158 return false;
159 ret->addEntry(curEntr);
160 return true;
161 } else {
162 printDebug("HtmlParse::parseCommentSubTblRow(): subelement unknown");
163 }
164 } else {
165 printDebug("HtmlParse::parseCommentGlobTblRow(): node unknown");
166 }
167 curNode = curNode.nextSibling();
168 }
169 return true;
170}
171
172bool HtmlParse::parseCommentSubTblEntry(const DOM::Node &node,
173 pair<QString, QString> *ret)
174{
175 DOM::Node curChild(node);
176 if (curChild.isNull())
177 return false;
178 ret->first = curChild.firstChild().nodeValue().string();
179 curChild = curChild.nextSibling();
180 if (curChild.isNull())
181 return false;
182 ret->second = curChild.firstChild().nodeValue().string();
183 return true;
184}
diff --git a/pwmanager/pwmanager/htmlparse.h b/pwmanager/pwmanager/htmlparse.h
new file mode 100644
index 0000000..bd92d0b
--- a/dev/null
+++ b/pwmanager/pwmanager/htmlparse.h
@@ -0,0 +1,45 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12#ifndef HTMLPARSE_H
13#define HTMLPARSE_H
14
15#include "htmlgen.h"
16
17#include <dom/dom_node.h>
18
19#include <utility>
20
21using std::pair;
22
23class HtmlParse
24{
25public:
26 HtmlParse();
27 ~HtmlParse();
28
29 /** parse the given HTML data and return the HtmlComment */
30 bool parseHtmlComment(const QString &dta, HtmlComment *ret);
31
32protected:
33 /** parse a global html comment table */
34 bool parseCommentGlobTbl(const DOM::Node &node, HtmlComment *ret);
35 /** parse a row of the global table */
36 bool parseCommentGlobTblRow(const DOM::Node &node, HtmlComment *ret);
37 /** parse a comment sub table */
38 bool parseCommentSubTbl(const DOM::Node &node, HtmlComment::SubTable *ret);
39 /** parse a row of comment sub table */
40 bool parseCommentSubTblRow(const DOM::Node &node, HtmlComment::SubTable *ret);
41 /** parse a comment subtable entry */
42 bool parseCommentSubTblEntry(const DOM::Node &node, pair<QString, QString> *ret);
43};
44
45#endif
diff --git a/pwmanager/pwmanager/ipc.cpp b/pwmanager/pwmanager/ipc.cpp
new file mode 100644
index 0000000..7468357
--- a/dev/null
+++ b/pwmanager/pwmanager/ipc.cpp
@@ -0,0 +1,152 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "ipc.h"
21#include "pwmexception.h"
22
23#include <qsocketnotifier.h>
24
25#include <sys/types.h>
26#include <sys/socket.h>
27#include <stdio.h>
28
29 #define END_OF_LINE '\n'
30 #define INIT_LINEBUF_LEN64 /* byte */
31
32
33Ipc::Ipc()
34 : stream (0)
35 , notifier (0)
36 , rdBuf (0)
37{
38#ifndef PWM_EMBEDDED
39 if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) {
40 throw PwMException(PwMException::EX_GENERIC,
41 "Ipc: socketpair() failed");
42 }
43 rdBufSize = INIT_LINEBUF_LEN;
44 rdBuf = static_cast<char *>(malloc(rdBufSize));
45 if (!rdBuf) {
46 close(sock[0]);
47 close(sock[1]);
48 throw PwMException(PwMException::EX_GENERIC,
49 "Ipc: OOM");
50 }
51 stream = fdopen(sock[0], "r");
52 if (!stream) {
53 close(sock[0]);
54 close(sock[1]);
55 free(rdBuf);
56 throw PwMException(PwMException::EX_GENERIC,
57 "Ipc: fdopen() failed");
58 }
59#else
60 if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sock)) {
61 qDebug("Ipc: socketpair() failed");
62 }
63 rdBufSize = INIT_LINEBUF_LEN;
64 rdBuf = (char *)(malloc(rdBufSize));
65 if (!rdBuf) {
66 close(sock[0]);
67 close(sock[1]);
68 qDebug("Ipc: OOM");
69 }
70 stream = fdopen(sock[0], "r");
71 if (!stream) {
72 close(sock[0]);
73 close(sock[1]);
74 free(rdBuf);
75 qDebug("Ipc: fdopen() failed");
76 }
77#endif
78
79 notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read);
80 connect(notifier, SIGNAL(activated(int)),
81 this, SLOT(receiveData(int)));
82 host = true;
83}
84
85Ipc::Ipc(const Ipc *ipc)
86 : stream (0)
87 , notifier (0)
88 , rdBuf (0)
89{
90#ifndef PWM_EMBEDDED
91 rdBufSize = INIT_LINEBUF_LEN;
92 rdBuf = static_cast<char *>(malloc(rdBufSize));
93 if (!rdBuf) {
94 throw PwMException(PwMException::EX_GENERIC,
95 "Ipc: OOM");
96 }
97 sock[0] = ipc->sock[1];
98 sock[1] = ipc->sock[0];
99 stream = fdopen(sock[0], "r");
100 if (!stream) {
101 free(rdBuf);
102 throw PwMException(PwMException::EX_GENERIC,
103 "Ipc: fdopen() failed");
104 }
105#else
106 rdBufSize = INIT_LINEBUF_LEN;
107 rdBuf = (char *)(malloc(rdBufSize));
108 if (!rdBuf) {
109 qDebug("Ipc: OOM");
110 }
111 sock[0] = ipc->sock[1];
112 sock[1] = ipc->sock[0];
113 stream = fdopen(sock[0], "r");
114 if (!stream) {
115 free(rdBuf);
116 qDebug("Ipc: fdopen() failed");
117 }
118#endif
119 notifier = new QSocketNotifier(sock[0], QSocketNotifier::Read);
120 connect(notifier, SIGNAL(activated(int)),
121 this, SLOT(receiveData(int)));
122 host = false;
123}
124
125Ipc::~Ipc()
126{
127 delete_ifnot_null(notifier);
128 if (rdBuf)
129 free(rdBuf);
130 if (stream)
131 fclose(stream);
132 if (host) {
133 close(sock[0]);
134 close(sock[1]);
135 }
136}
137
138void Ipc::receiveData(int s)
139{
140 ssize_t rd;
141
142 PWM_ASSERT(s == sock[0]);
143 PARAM_UNUSED(s);
144 rd = getline(&rdBuf, &rdBufSize, stream);
145 if (likely(rd > 0)) {
146 emit lineAvailable(rdBuf, rd);
147 }
148}
149
150#ifndef PWM_EMBEDDED
151#include "ipc.moc"
152#endif
diff --git a/pwmanager/pwmanager/ipc.h b/pwmanager/pwmanager/ipc.h
new file mode 100644
index 0000000..ccdaafb
--- a/dev/null
+++ b/pwmanager/pwmanager/ipc.h
@@ -0,0 +1,73 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef __PWM_IPC_H
21#define __PWM_IPC_H
22
23#include <unistd.h>
24
25#include <qobject.h>
26#include <stdio.h>
27
28class QSocketNotifier;
29
30/** very simple interprocess communication class */
31class Ipc : public QObject
32{
33 Q_OBJECT
34public:
35 /** create a new Ipc communication object */
36 Ipc();
37 /** create a new Ipc communication object and
38 * connect it to "ipc"
39 */
40 Ipc(const Ipc *ipc);
41 /** destructor */
42 ~Ipc();
43
44 /** send data to the other socket end
45 * (To the connected ipc object)
46 */
47 void send(const char *buf, size_t size)
48 { write(sock[0], buf, size); }
49
50signals:
51 /** a line is available */
52 void lineAvailable(const char *buf, size_t size);
53
54protected slots:
55 /** received data on socket */
56 void receiveData(int s);
57
58protected:
59 /** full-duplex socket file desciptors */
60 int sock[2];
61 /** stream on "this" end of the socket (sock[0]) */
62 FILE *stream;
63 /** socket notifier */
64 QSocketNotifier *notifier;
65 /** are we the host or the client object? */
66 bool host;
67 /** receive buffer */
68 char *rdBuf;
69 /** current receive buffer size */
70 size_t rdBufSize;
71};
72
73#endif // __PWM_IPC_H
diff --git a/pwmanager/pwmanager/listobjselectwnd.cpp b/pwmanager/pwmanager/listobjselectwnd.cpp
new file mode 100644
index 0000000..59729f1
--- a/dev/null
+++ b/pwmanager/pwmanager/listobjselectwnd.cpp
@@ -0,0 +1,131 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "listobjselectwnd.h"
21
22#include <klocale.h>
23
24
25ListObjSelectWnd::ListObjSelectWnd(const QString &caption, const QString &titleText,
26 QWidget *parent, bool multiSel, const char *name,
27 bool modal, WFlags f)
28 : QDialog(parent, name, modal, f)
29{
30 vbox1 = new QVBox(this);
31 title = new QLabel(vbox1);
32 list = new QListBox(vbox1);
33 if (multiSel) {
34 hbox2 = new QHBox(vbox1);
35 selAllButton = new QPushButton(i18n("&Select all"), hbox2);
36 unselAllButton = new QPushButton(i18n("&Unselect all"), hbox2);
37 }
38 hbox1 = new QHBox(vbox1);
39 okButton = new QPushButton(i18n("&Ok"), hbox1);
40 cancelButton = new QPushButton(i18n("&Cancel"), hbox1);
41
42 vbox1->setSpacing(10);
43 vbox1->setMargin(10);
44 hbox1->setSpacing(10);
45 resize(250, 300);
46 setCaption(caption);
47 if (multiSel) {
48 list->setSelectionMode(QListBox::Multi);
49 }
50
51 title->setAlignment(Qt::AlignHCenter | Qt::WordBreak);
52 title->setText(titleText);
53
54 connect(okButton, SIGNAL(clicked()),
55 this, SLOT(okButton_slot()));
56 connect(cancelButton, SIGNAL(clicked()),
57 this, SLOT(cancelButton_slot()));
58 if (multiSel) {
59 connect(selAllButton, SIGNAL(clicked()),
60 this, SLOT(selAllButton_slot()));
61 connect(unselAllButton, SIGNAL(clicked()),
62 this, SLOT(unselAllButton_slot()));
63 }
64}
65
66ListObjSelectWnd::~ListObjSelectWnd()
67{
68}
69
70void ListObjSelectWnd::resizeEvent(QResizeEvent *)
71{
72 vbox1->resize(size());
73}
74
75void ListObjSelectWnd::okButton_slot()
76{
77 unsigned int cnt = list->count(), i;
78 for (i = 0; i < cnt; ++i) {
79 if (list->isSelected(i)) {
80 done(1);
81 return;
82 }
83 }
84}
85
86void ListObjSelectWnd::cancelButton_slot()
87{
88 done(2);
89}
90
91void ListObjSelectWnd::selAllButton_slot()
92{
93 unsigned int cnt = list->count(), i;
94 for (i = 0; i < cnt; ++i) {
95 list->setSelected(i, true);
96 }
97}
98
99void ListObjSelectWnd::unselAllButton_slot()
100{
101 unsigned int cnt = list->count(), i;
102 for (i = 0; i < cnt; ++i) {
103 list->setSelected(i, false);
104 }
105}
106
107QStringList ListObjSelectWnd::getSelectedList()
108{
109 QStringList ret;
110 unsigned int cnt = list->count(), i;
111 for (i = 0; i < cnt; ++i) {
112 if (list->isSelected(i)) {
113#ifndef PWM_EMBEDDED
114 ret.push_back(list->text(i));
115#else
116 ret.append(list->text(i));
117#endif
118 }
119 }
120 return ret;
121}
122
123void ListObjSelectWnd::setList(const QStringList &_list)
124{
125 list->clear();
126 list->insertStringList(_list);
127}
128
129#ifndef PWM_EMBEDDED
130#include "listobjselectwnd.moc"
131#endif
diff --git a/pwmanager/pwmanager/listobjselectwnd.h b/pwmanager/pwmanager/listobjselectwnd.h
new file mode 100644
index 0000000..3b5f1eb
--- a/dev/null
+++ b/pwmanager/pwmanager/listobjselectwnd.h
@@ -0,0 +1,85 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef LISTOBJSELECTWND_H
21#define LISTOBJSELECTWND_H
22
23#include <qdialog.h>
24#include <qvbox.h>
25#include <qhbox.h>
26#include <qlabel.h>
27#include <qlistbox.h>
28#include <qpushbutton.h>
29#include <qstringlist.h>
30
31
32/** Display a list-window for selection of some objects */
33class ListObjSelectWnd : public QDialog
34{
35 Q_OBJECT
36public:
37 ListObjSelectWnd(const QString &caption, const QString &titleText,
38 QWidget *parent = 0, bool multiSel = false,
39 const char *name = 0,
40 bool modal = FALSE, WFlags f = 0);
41 ~ListObjSelectWnd();
42
43 void setList(const QStringList &_list);
44 void addObj(const QString &name)
45 { list->insertItem(name); }
46 void selectObj(const QString &name)
47#ifndef PWM_EMBEDDED
48 { list->setCurrentItem(list->findItem(name, Qt::ExactMatch)); }
49#else
50 { list->setCurrentItem(list->findItem(name)); }
51#endif
52 QString getSelected()
53 { return list->currentText(); }
54 int getSelectedIndex()
55#ifndef PWM_EMBEDDED
56 { return list->index(list->selectedItem()); }
57#else
58 { return list->currentItem(); }
59#endif
60 QStringList getSelectedList();
61 void clearObjs()
62 { list->clear(); }
63
64protected:
65 QVBox *vbox1;
66 QHBox *hbox1;
67 QHBox *hbox2;
68 QLabel *title;
69 QListBox *list;
70 QPushButton *okButton;
71 QPushButton *cancelButton;
72 QPushButton *selAllButton;
73 QPushButton *unselAllButton;
74
75protected:
76 void resizeEvent(QResizeEvent *);
77
78protected slots:
79 void okButton_slot();
80 void cancelButton_slot();
81 void selAllButton_slot();
82 void unselAllButton_slot();
83};
84
85#endif
diff --git a/pwmanager/pwmanager/listviewpwm.cpp b/pwmanager/pwmanager/listviewpwm.cpp
new file mode 100644
index 0000000..b987c9e
--- a/dev/null
+++ b/pwmanager/pwmanager/listviewpwm.cpp
@@ -0,0 +1,86 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "listviewpwm.h"
21#include "pwmexception.h"
22
23#include <qpainter.h>
24#include <qpixmap.h>
25
26#include <kiconloader.h>
27
28
29ListViewPwM::ListViewPwM(QWidget *parent, const char *name)
30 : KListView(parent, name)
31{
32 //setResizeMode(QListView::AllColumns);
33}
34
35bool ListViewPwM::event(QEvent *e)
36{
37 if (e->type() == QEvent::LayoutHint)
38 emit layoutChanged();
39 return KListView::event(e);
40}
41
42
43QPixmap * ListViewItemPwM::onPix = 0;
44QPixmap * ListViewItemPwM::offPix = 0;
45
46ListViewItemPwM::ListViewItemPwM(QListView *parent)
47 : QCheckListItem(parent, "", QCheckListItem::CheckBox)
48{
49 if (!onPix) {
50 PWM_ASSERT(!offPix);
51 KIconLoader il;
52 static QPixmap onP(il.loadIcon("button_ok", KIcon::Small));
53 onPix = &onP;
54 static QPixmap offP(il.loadIcon("encrypted", KIcon::Small));
55 offPix = &offP;
56 }
57}
58
59void ListViewItemPwM::paintCell(QPainter *p, const QColorGroup &cg,
60 int column, int width, int align)
61{
62 if (!p)
63 return;
64 if (column != 0) {
65 QCheckListItem::paintCell(p, cg, column, width, align);
66 return;
67 }
68 QPixmap *curPix = isOn() ? onPix : offPix;
69 int pixSpace = curPix->width();
70 pixSpace += 4;
71#ifndef PWM_EMBEDDED
72 QRect window(p->viewport());
73 // clear the rectangle (we have to clear it first. see QT doc)
74 p->eraseRect(0, 0, pixSpace, window.height());
75 // now draw the pixmap
76 int y = (height() - curPix->height()) / 2;
77 p->drawPixmap(1, y, *curPix);
78 window.moveLeft(pixSpace);
79 p->setViewport(window);
80#endif
81 QListViewItem::paintCell(p, cg, column, width - pixSpace, align);
82}
83
84#ifndef PWM_EMBEDDED
85#include "listviewpwm.moc"
86#endif
diff --git a/pwmanager/pwmanager/listviewpwm.h b/pwmanager/pwmanager/listviewpwm.h
new file mode 100644
index 0000000..e6471c6
--- a/dev/null
+++ b/pwmanager/pwmanager/listviewpwm.h
@@ -0,0 +1,57 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef __LISTVIEW_H
21#define __LISTVIEW_H
22
23#include <klistview.h>
24
25/** PwManager implementation of the list view.
26 * Derived from KListView.
27 */
28class ListViewPwM : public KListView
29{
30 Q_OBJECT
31public:
32 ListViewPwM(QWidget *parent = 0, const char *name = 0);
33
34signals:
35 void layoutChanged();
36
37protected:
38 virtual bool event(QEvent *e);
39};
40
41class ListViewItemPwM : public QCheckListItem
42{
43public:
44 ListViewItemPwM(QListView *parent);
45
46protected:
47 void paintCell(QPainter *p, const QColorGroup &cg,
48 int column, int width, int align);
49
50protected:
51 /** pixmap to display for an item with state "on" */
52 static QPixmap *onPix;
53 /** pixmap to display for an item with state "off" */
54 static QPixmap *offPix;
55};
56
57#endif
diff --git a/pwmanager/pwmanager/main.cpp b/pwmanager/pwmanager/main.cpp
new file mode 100644
index 0000000..d720e1f
--- a/dev/null
+++ b/pwmanager/pwmanager/main.cpp
@@ -0,0 +1,210 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef PWM_EMBEDDED
21#include <kcmdlineargs.h>
22#include <kaboutdata.h>
23#else
24#include <qdir.h>
25#endif
26
27#include <klocale.h>
28#include <kstandarddirs.h>
29
30#include "pwmexception.h"
31#include "pwminit.h"
32
33 #define LICENSE_FILE(::locate("data", "pwmanager/pwmanager_license_text"))
34
35int PwMApplication::newInstance()
36{
37 static bool initial = true;
38 if (initial) {
39 initial = false;
40 init = new PwMInit(this);
41 init->initializeApp();
42 } else {
43 BUG_ON(!init);
44 printInfo("passing parameters to old instance.");
45 init->handleCmdLineArgs(false);
46 }
47 return EXIT_SUCCESS;
48}
49
50
51static const char *description = I18N_NOOP("PwManager\n"
52 "The convenient way of managing passwords");
53
54#ifndef PWM_EMBEDDED
55static KCmdLineOptions options[] =
56{
57 { "minimized", I18N_NOOP("Windows minimized"), 0 },
58 { "mintray", I18N_NOOP("Windows minimized to tray"),0 },
59 { "open-deeplocked", I18N_NOOP("Open all \"files\" deeplocked"),0 },
60 { "skip-self-test", I18N_NOOP("Don't run a self-test on startup"),0 },
61 { "+[files...]", I18N_NOOP("Files to open on startup"), 0 },
62 { 0, 0, 0 }
63};
64#endif
65
66#ifdef PWM_DEBUG
67static void printDebugConfigureInfo()
68{
69 cout << "================================" << endl;
70 cout << PROG_NAME " version " PACKAGE_VER << endl;
71#ifdef CONFIG_KEYCARD
72 cout << "CONFIG_KEYCARD: enabled" << endl;
73#else
74 cout << "CONFIG_KEYCARD: disabled" << endl;
75#endif
76#ifdef CONFIG_KWALLETIF
77 cout << "CONFIG_KWALLETIF: enabled" << endl;
78#else
79 cout << "CONFIG_KWALLETIF: disabled" << endl;
80#endif
81#ifdef BIG_ENDIAN_HOST
82 cout << "Endianess: big-endian" << endl;
83#else
84 cout << "Endianess: little-endian" << endl;
85#endif
86 cout << "sizeof(long): " << sizeof(long) << endl;
87 cout << "================================" << endl;
88}
89#else // PWM_DEBUG
90static inline void printDebugConfigureInfo() { /* nothing */ }
91#endif // PWM_DEBUG
92
93#ifndef PWM_EMBEDDED
94static void addAuthors(KAboutData *aboutData)
95{
96 aboutData->addAuthor("Michael Buesch",
97 I18N_NOOP(
98 "main programming and current maintainer"),
99 "mbuesch@freenet.de");
100 aboutData->addAuthor("Matt Scifo",
101 I18N_NOOP(
102 "original implementaion of \n"
103 "\"categories\" and the password-tree \n"
104 "in the system-tray. Original implementations of \n"
105 "numerous view-improvements."),
106 "mscifo@o1.com");
107 aboutData->addCredit("Elias Probst",
108 I18N_NOOP(
109 "Gentoo ebuild maintainer."),
110 "elias.probst@gmx.de");
111 aboutData->addCredit("George Staikos",
112 I18N_NOOP("KWallet"),
113 "staikos@kde.org");
114 aboutData->addCredit("Matthew Palmer",
115 I18N_NOOP("rc2 code"),
116 "mjp16@uow.edu.au");
117 aboutData->addCredit("Olivier Sessink",
118 I18N_NOOP("gpasman"),
119 "gpasman@nl.linux.org");
120 aboutData->addCredit("The libgcrypt developers",
121 I18N_NOOP("Blowfish and SHA1 algorithms"),
122 0, "ftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/");
123 aboutData->addCredit("Troy Engel",
124 I18N_NOOP("kpasman"),
125 "tengel@sonic.net");
126 aboutData->addCredit("Wickey",
127 I18N_NOOP("graphics-design in older versions."),
128 "wickey@gmx.at");
129 aboutData->addCredit("Ian MacGregor",
130 I18N_NOOP(
131 "original documentation author."));
132}
133#endif
134
135int main(int argc, char *argv[])
136{
137 printDebugConfigureInfo();
138#ifndef PWM_EMBEDDED
139 KAboutData aboutData(PACKAGE_NAME, PROG_NAME,
140 PACKAGE_VER, description, KAboutData::License_File,
141 "(c) 2003, 2004 Michael Buesch and the PwManager Team", 0,
142 "http://passwordmanager.sourceforge.net/",
143 "mbuesch@freenet.de");
144 addAuthors(&aboutData);
145
146 KCmdLineArgs::init(argc, argv, &aboutData);
147 KCmdLineArgs::addCmdLineOptions(options);
148
149 KUniqueApplication::addCmdLineOptions();
150 if (!KUniqueApplication::start()) {
151 printInfo("already running.");
152 return EXIT_SUCCESS;
153 }
154 PwMApplication a;
155 aboutData.setLicenseTextFile(LICENSE_FILE);
156 return a.exec();
157#else
158
159 bool exitHelp = false;
160 if ( argc > 1 ) {
161 QString command = argv[1];
162 if ( command == "-help" ){
163 printf("PWM/PI command line commands:\n");
164 printf(" no command: Start PWM/PI in usual way\n");
165 printf(" -help: This output\n");
166 printf(" PWM/PI is exiting now. Bye!\n");
167 exitHelp = true;
168 }
169 }
170 if ( ! exitHelp ) {
171
172 PwMApplication a(argc, argv);
173
174 KGlobal::setAppName( "pwmanager" );
175#ifndef DESKTOP_VERSION
176 //US if ( QApplication::desktop()->width() > 320 )
177 //US KGlobal::iconLoader()->setIconPath(QString(getenv("QPEDIR"))+"/pics/kdepim/pwmanager/icons22/");
178 //US else
179 KGlobal::iconLoader()->setIconPath(QString(getenv("QPEDIR"))+"/pics/kdepim/pwmanager/icons16/");
180#else
181 QString fileName ;
182 fileName = qApp->applicationDirPath () + "/kdepim/pwmanager/icons22/";
183 KGlobal::iconLoader()->setIconPath(QDir::convertSeparators(fileName));
184 QApplication::addLibraryPath ( qApp->applicationDirPath () );
185
186#endif
187 KStandardDirs::setAppDir( QDir::convertSeparators(locateLocal("data", "pwmanager")));
188
189 a.newInstance();
190
191 //US KAddressBookMain m ;
192
193 //US QObject::connect(&a, SIGNAL (appMessage ( const QCString &, const QByteArray & )), ExternalAppHandler::instance(), SLOT (appMessage ( const QCString &, const QByteArray & )));
194 /*US
195#ifndef DESKTOP_VERSION
196 a.showMainWidget( &m );
197#else
198 a.setMainWidget( &m );
199 m.resize (640, 480 );
200 m.show();
201#endif
202 */
203 a.exec();
204
205 }
206 qDebug("PWMPI: Bye! ");
207
208#endif
209
210}
diff --git a/pwmanager/pwmanager/printtext.cpp b/pwmanager/pwmanager/printtext.cpp
new file mode 100644
index 0000000..7590114
--- a/dev/null
+++ b/pwmanager/pwmanager/printtext.cpp
@@ -0,0 +1,107 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12#include "printtext.h"
13#include "pwmexception.h"
14
15#include <klocale.h>
16
17#include <qpen.h>
18
19
20PrintText::PrintText()
21{
22 curYPos = 0;
23 paint = new QPainter;
24 metrics = new QPaintDeviceMetrics(this);
25}
26
27PrintText::~PrintText()
28{
29 delete paint;
30 delete metrics;
31}
32
33void PrintText::beginPrint()
34{
35 PWM_ASSERT(paint && metrics);
36 curYPos = 0;
37 page = 1;
38 paint->begin(this);
39 ls = paint->fontMetrics().lineSpacing();
40
41 // set printing border
42 int border = (metrics->width() / metrics->widthMM()) * 15; // 15 mm border
43 topLeft.setX(border);
44 topLeft.setY(border);
45
46 // set body
47 body.setRect(topLeft.x(), ls * 2 + topLeft.y(),
48 metrics->width() - topLeft.x() * 2,
49 metrics->height() - ls * 2 - topLeft.y() * 2);
50 paint->setTabStops(paint->fontMetrics().width("M") * 8);
51
52 printHeader();
53}
54
55void PrintText::printLine(QString t)
56{
57 if (curYPos == 0)
58 curYPos = ls * 2 + topLeft.y(); // skip header
59 if (t == "")
60 t = " ";
61 QRect r = paint->boundingRect(topLeft.x(), curYPos, body.width(), body.height(),
62 QPainter::ExpandTabs | QPainter::WordBreak, t);
63 int height = r.height();
64 if (height + curYPos > metrics->height()) {
65 // next page
66 newPage();
67 ++page;
68 headerRight = "";
69 printHeader();
70 curYPos = ls * 2 + topLeft.y();
71 }
72 paint->drawText(topLeft.x(), curYPos, metrics->width(), metrics->height() - curYPos,
73 QPainter::ExpandTabs | QPainter::WordBreak, t);
74 curYPos += ls;
75}
76
77void PrintText::printHeader()
78{
79 if (headerRight == "")
80 headerRight = i18n("Page #") + QString::number(page);
81
82 paint->drawText(topLeft.x(), topLeft.y(), metrics->width() - topLeft.x() * 2,
83 ls, Qt::AlignLeft, headerLeft);
84 paint->drawText(topLeft.x(), topLeft.y(), metrics->width() - topLeft.x() * 2,
85 ls, Qt::AlignHCenter, headerMiddle);
86 paint->drawText(topLeft.x(), topLeft.y(), metrics->width() - topLeft.x() * 2,
87 ls, Qt::AlignRight, headerRight);
88
89 QPen pen;
90 pen.setWidth(3);
91 paint->setPen(pen);
92 paint->drawLine(topLeft.x(), (ls + ls / 2) + topLeft.y(),
93 metrics->width() - topLeft.x(),
94 (ls + ls / 2) + topLeft.y());
95}
96
97void PrintText::setHeader(const QString &left, const QString &middle)
98{
99 headerLeft = left;
100 headerMiddle = middle;
101}
102
103void PrintText::getHeader(QString *left, QString *middle)
104{
105 *left = headerLeft;
106 *middle = headerMiddle;
107}
diff --git a/pwmanager/pwmanager/printtext.h b/pwmanager/pwmanager/printtext.h
new file mode 100644
index 0000000..82e31b0
--- a/dev/null
+++ b/pwmanager/pwmanager/printtext.h
@@ -0,0 +1,68 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12#ifndef PRINTTEXT_H
13#define PRINTTEXT_H
14
15#include <kprinter.h>
16
17#include <qpainter.h>
18#include <qpaintdevicemetrics.h>
19#include <qrect.h>
20#include <qpoint.h>
21
22/** prints text "raw" to a printer */
23class PrintText : public KPrinter
24{
25public:
26 PrintText();
27 ~PrintText();
28
29 /** begin printing. Call this before drawing to the device! */
30 void beginPrint();
31 /** prints a line */
32 void printLine(QString t);
33 /** returns a pointer to the paint object */
34 QPainter* getPaint()
35 { return paint; }
36 /** sets the header-text */
37 void setHeader(const QString &left, const QString &middle);
38 /** returns the header-text */
39 void getHeader(QString *left, QString *middle);
40
41protected:
42 /** painter object */
43 QPainter *paint;
44 /** metrics */
45 QPaintDeviceMetrics *metrics;
46 /** left field of header */
47 QString headerLeft;
48 /** middle field of header */
49 QString headerMiddle;
50 /** right field of header */
51 QString headerRight;
52 /** current Y-Position */
53 int curYPos;
54 /** text-body rectangle */
55 QRect body;
56 /** line-spacing */
57 int ls;
58 /** top-left point for beginning printing */
59 QPoint topLeft;
60 /** current page number */
61 int page;
62
63protected:
64 /** prints the header on the page */
65 void printHeader();
66};
67
68#endif
diff --git a/pwmanager/pwmanager/pwgenwnd.cpp b/pwmanager/pwmanager/pwgenwnd.cpp
new file mode 100644
index 0000000..bb1ab92
--- a/dev/null
+++ b/pwmanager/pwmanager/pwgenwnd.cpp
@@ -0,0 +1,187 @@
1/****************************************************************************
2** Form implementation generated from reading ui file 'pwgenwnd.ui'
3**
4** Created: Tue Sep 14 15:34:41 2004
5** by: The User Interface Compiler ($Id$)
6**
7** WARNING! All changes made in this file will be lost!
8****************************************************************************/
9
10#include "pwgenwnd.h"
11
12#include <qvariant.h>
13#include <qpushbutton.h>
14#include <qgroupbox.h>
15#include <qcheckbox.h>
16#include <qlabel.h>
17#include <qlineedit.h>
18#include <qspinbox.h>
19#include <qlayout.h>
20#include <qtooltip.h>
21#include <qwhatsthis.h>
22
23/*
24 * Constructs a pwGenWnd as a child of 'parent', with the
25 * name 'name' and widget flags set to 'f'.
26 *
27 * The dialog will by default be modeless, unless you set 'modal' to
28 * TRUE to construct a modal dialog.
29 */
30pwGenWnd::pwGenWnd( QWidget* parent, const char* name, bool modal, WFlags fl )
31 : QDialog( parent, name, modal, fl )
32{
33 if ( !name )
34 setName( "pwGenWnd" );
35 pwGenWndLayout = new QVBoxLayout( this, 11, 6, "pwGenWndLayout");
36
37 groupBox1 = new QGroupBox( this, "groupBox1" );
38 groupBox1->setColumnLayout(0, Qt::Vertical );
39 groupBox1->layout()->setSpacing( 6 );
40 groupBox1->layout()->setMargin( 11 );
41 groupBox1Layout = new QVBoxLayout( groupBox1->layout() );
42 groupBox1Layout->setAlignment( Qt::AlignTop );
43
44 layout2 = new QHBoxLayout( 0, 0, 6, "layout2");
45
46 int_charLowerCheckBox = new QCheckBox( groupBox1, "int_charLowerCheckBox" );
47 int_charLowerCheckBox->setChecked( TRUE );
48 layout2->addWidget( int_charLowerCheckBox );
49 spacer1 = new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
50 layout2->addItem( spacer1 );
51
52 textLabel4 = new QLabel( groupBox1, "textLabel4" );
53 layout2->addWidget( textLabel4 );
54 groupBox1Layout->addLayout( layout2 );
55
56 layout3 = new QHBoxLayout( 0, 0, 6, "layout3");
57
58 int_charUpperCheckBox = new QCheckBox( groupBox1, "int_charUpperCheckBox" );
59 int_charUpperCheckBox->setChecked( TRUE );
60 layout3->addWidget( int_charUpperCheckBox );
61 spacer2 = new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
62 layout3->addItem( spacer2 );
63
64 textLabel5 = new QLabel( groupBox1, "textLabel5" );
65 layout3->addWidget( textLabel5 );
66 groupBox1Layout->addLayout( layout3 );
67
68 layout4 = new QHBoxLayout( 0, 0, 6, "layout4");
69
70 int_charNumCheckBox = new QCheckBox( groupBox1, "int_charNumCheckBox" );
71 int_charNumCheckBox->setChecked( TRUE );
72 layout4->addWidget( int_charNumCheckBox );
73 spacer3 = new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
74 layout4->addItem( spacer3 );
75
76 textLabel6 = new QLabel( groupBox1, "textLabel6" );
77 layout4->addWidget( textLabel6 );
78 groupBox1Layout->addLayout( layout4 );
79
80 layout6 = new QHBoxLayout( 0, 0, 6, "layout6");
81
82 int_charSpecCheckBox = new QCheckBox( groupBox1, "int_charSpecCheckBox" );
83 layout6->addWidget( int_charSpecCheckBox );
84 spacer4 = new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
85 layout6->addItem( spacer4 );
86
87 textLabel7 = new QLabel( groupBox1, "textLabel7" );
88 layout6->addWidget( textLabel7 );
89 groupBox1Layout->addLayout( layout6 );
90
91 int_charBlankCheckBox = new QCheckBox( groupBox1, "int_charBlankCheckBox" );
92 groupBox1Layout->addWidget( int_charBlankCheckBox );
93
94 layout7 = new QHBoxLayout( 0, 0, 6, "layout7");
95
96 int_charUserCheckBox = new QCheckBox( groupBox1, "int_charUserCheckBox" );
97 layout7->addWidget( int_charUserCheckBox );
98 spacer5 = new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
99 layout7->addItem( spacer5 );
100
101 int_userDefLineEdit = new QLineEdit( groupBox1, "int_userDefLineEdit" );
102 int_userDefLineEdit->setEnabled( FALSE );
103 layout7->addWidget( int_userDefLineEdit );
104 groupBox1Layout->addLayout( layout7 );
105 pwGenWndLayout->addWidget( groupBox1 );
106
107 layout8 = new QHBoxLayout( 0, 0, 6, "layout8");
108
109 textLabel2 = new QLabel( this, "textLabel2" );
110 layout8->addWidget( textLabel2 );
111
112 int_lenSpinBox = new QSpinBox( this, "int_lenSpinBox" );
113 int_lenSpinBox->setMaxValue( 9999 );
114 int_lenSpinBox->setMinValue( 1 );
115 int_lenSpinBox->setValue( 8 );
116 layout8->addWidget( int_lenSpinBox );
117 pwGenWndLayout->addLayout( layout8 );
118
119 int_filterCheckBox = new QCheckBox( this, "int_filterCheckBox" );
120 int_filterCheckBox->setChecked( TRUE );
121 pwGenWndLayout->addWidget( int_filterCheckBox );
122
123 layout1 = new QHBoxLayout( 0, 0, 6, "layout1");
124
125 genButton = new QPushButton( this, "genButton" );
126 layout1->addWidget( genButton );
127
128 cancelButton = new QPushButton( this, "cancelButton" );
129 layout1->addWidget( cancelButton );
130 pwGenWndLayout->addLayout( layout1 );
131 languageChange();
132 resize( QSize(450, 349).expandedTo(minimumSizeHint()) );
133 clearWState( WState_Polished );
134
135 // signals and slots connections
136 connect( int_charUserCheckBox, SIGNAL( toggled(bool) ), int_userDefLineEdit, SLOT( setEnabled(bool) ) );
137 connect( cancelButton, SIGNAL( clicked() ), this, SLOT( cancelButton_slot() ) );
138 connect( genButton, SIGNAL( clicked() ), this, SLOT( genButton_slot() ) );
139}
140
141/*
142 * Destroys the object and frees any allocated resources
143 */
144pwGenWnd::~pwGenWnd()
145{
146 // no need to delete child widgets, Qt does it all for us
147}
148
149/*
150 * Sets the strings of the subwidgets using the current
151 * language.
152 */
153void pwGenWnd::languageChange()
154{
155 setCaption( tr( "Password generator" ) );
156 groupBox1->setTitle( tr( "Character set:" ) );
157 int_charLowerCheckBox->setText( tr( "Lowercase:" ) );
158 textLabel4->setText( tr( "abc" ) );
159 int_charUpperCheckBox->setText( tr( "Uppercase:" ) );
160 textLabel5->setText( tr( "ABC" ) );
161 int_charNumCheckBox->setText( tr( "Numbers:" ) );
162 textLabel6->setText( tr( "123" ) );
163 int_charSpecCheckBox->setText( tr( "Special characters:" ) );
164#ifndef PWM_EMBEDDED
165 textLabel7->setText( trUtf8( "\x21\x22\xc2\xa7\x24\x25\x26\x2f\x28\x29\x3d\x3f\x2c\x2e\x2d\x3b\x3a\x5f\x2b" ) );
166#else
167 QString st("\x21\x22\xc2\xa7\x24\x25\x26\x2f\x28\x29\x3d\x3f\x2c\x2e\x2d\x3b\x3a\x5f\x2b");
168 textLabel7->setText( st.utf8() );
169#endif
170 int_charBlankCheckBox->setText( tr( "Spaces (blank characters)" ) );
171 int_charUserCheckBox->setText( tr( "User defined:" ) );
172 textLabel2->setText( tr( "Password Length:" ) );
173 int_filterCheckBox->setText( tr( "Enable Filtering to get better passwords" ) );
174 genButton->setText( tr( "&Generate now" ) );
175 cancelButton->setText( tr( "&Cancel" ) );
176}
177
178void pwGenWnd::cancelButton_slot()
179{
180 qWarning( "pwGenWnd::cancelButton_slot(): Not implemented yet" );
181}
182
183void pwGenWnd::genButton_slot()
184{
185 qWarning( "pwGenWnd::genButton_slot(): Not implemented yet" );
186}
187
diff --git a/pwmanager/pwmanager/pwgenwnd.h b/pwmanager/pwmanager/pwgenwnd.h
new file mode 100644
index 0000000..3403d78
--- a/dev/null
+++ b/pwmanager/pwmanager/pwgenwnd.h
@@ -0,0 +1,78 @@
1/****************************************************************************
2** Form interface generated from reading ui file 'pwgenwnd.ui'
3**
4** Created: Tue Sep 14 15:32:37 2004
5** by: The User Interface Compiler ($Id$)
6**
7** WARNING! All changes made in this file will be lost!
8****************************************************************************/
9
10#ifndef PWGENWND_H
11#define PWGENWND_H
12
13#include <qvariant.h>
14#include <qdialog.h>
15
16class QVBoxLayout;
17class QHBoxLayout;
18class QGridLayout;
19class QSpacerItem;
20class QGroupBox;
21class QCheckBox;
22class QLabel;
23class QLineEdit;
24class QSpinBox;
25class QPushButton;
26
27class pwGenWnd : public QDialog
28{
29 Q_OBJECT
30
31public:
32 pwGenWnd( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
33 ~pwGenWnd();
34
35 QGroupBox* groupBox1;
36 QCheckBox* int_charLowerCheckBox;
37 QLabel* textLabel4;
38 QCheckBox* int_charUpperCheckBox;
39 QLabel* textLabel5;
40 QCheckBox* int_charNumCheckBox;
41 QLabel* textLabel6;
42 QCheckBox* int_charSpecCheckBox;
43 QLabel* textLabel7;
44 QCheckBox* int_charBlankCheckBox;
45 QCheckBox* int_charUserCheckBox;
46 QLineEdit* int_userDefLineEdit;
47 QLabel* textLabel2;
48 QSpinBox* int_lenSpinBox;
49 QCheckBox* int_filterCheckBox;
50 QPushButton* genButton;
51 QPushButton* cancelButton;
52
53public slots:
54 virtual void cancelButton_slot();
55 virtual void genButton_slot();
56
57protected:
58 QVBoxLayout* pwGenWndLayout;
59 QVBoxLayout* groupBox1Layout;
60 QHBoxLayout* layout2;
61 QSpacerItem* spacer1;
62 QHBoxLayout* layout3;
63 QSpacerItem* spacer2;
64 QHBoxLayout* layout4;
65 QSpacerItem* spacer3;
66 QHBoxLayout* layout6;
67 QSpacerItem* spacer4;
68 QHBoxLayout* layout7;
69 QSpacerItem* spacer5;
70 QHBoxLayout* layout8;
71 QHBoxLayout* layout1;
72
73protected slots:
74 virtual void languageChange();
75
76};
77
78#endif // PWGENWND_H
diff --git a/pwmanager/pwmanager/pwgenwnd.ui b/pwmanager/pwmanager/pwgenwnd.ui
new file mode 100644
index 0000000..cde874b
--- a/dev/null
+++ b/pwmanager/pwmanager/pwgenwnd.ui
@@ -0,0 +1,363 @@
1<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
2<class>pwGenWnd</class>
3<widget class="QDialog">
4 <property name="name">
5 <cstring>pwGenWnd</cstring>
6 </property>
7 <property name="geometry">
8 <rect>
9 <x>0</x>
10 <y>0</y>
11 <width>450</width>
12 <height>349</height>
13 </rect>
14 </property>
15 <property name="caption">
16 <string>Password generator</string>
17 </property>
18 <vbox>
19 <property name="name">
20 <cstring>unnamed</cstring>
21 </property>
22 <widget class="QGroupBox">
23 <property name="name">
24 <cstring>groupBox1</cstring>
25 </property>
26 <property name="title">
27 <string>Character set:</string>
28 </property>
29 <vbox>
30 <property name="name">
31 <cstring>unnamed</cstring>
32 </property>
33 <widget class="QLayoutWidget">
34 <property name="name">
35 <cstring>layout2</cstring>
36 </property>
37 <hbox>
38 <property name="name">
39 <cstring>unnamed</cstring>
40 </property>
41 <widget class="QCheckBox">
42 <property name="name">
43 <cstring>int_charLowerCheckBox</cstring>
44 </property>
45 <property name="text">
46 <string>Lowercase:</string>
47 </property>
48 <property name="checked">
49 <bool>true</bool>
50 </property>
51 </widget>
52 <spacer>
53 <property name="name">
54 <cstring>spacer1</cstring>
55 </property>
56 <property name="orientation">
57 <enum>Horizontal</enum>
58 </property>
59 <property name="sizeType">
60 <enum>Expanding</enum>
61 </property>
62 <property name="sizeHint">
63 <size>
64 <width>40</width>
65 <height>20</height>
66 </size>
67 </property>
68 </spacer>
69 <widget class="QLabel">
70 <property name="name">
71 <cstring>textLabel4</cstring>
72 </property>
73 <property name="text">
74 <string>abc</string>
75 </property>
76 </widget>
77 </hbox>
78 </widget>
79 <widget class="QLayoutWidget">
80 <property name="name">
81 <cstring>layout3</cstring>
82 </property>
83 <hbox>
84 <property name="name">
85 <cstring>unnamed</cstring>
86 </property>
87 <widget class="QCheckBox">
88 <property name="name">
89 <cstring>int_charUpperCheckBox</cstring>
90 </property>
91 <property name="text">
92 <string>Uppercase:</string>
93 </property>
94 <property name="checked">
95 <bool>true</bool>
96 </property>
97 </widget>
98 <spacer>
99 <property name="name">
100 <cstring>spacer2</cstring>
101 </property>
102 <property name="orientation">
103 <enum>Horizontal</enum>
104 </property>
105 <property name="sizeType">
106 <enum>Expanding</enum>
107 </property>
108 <property name="sizeHint">
109 <size>
110 <width>40</width>
111 <height>20</height>
112 </size>
113 </property>
114 </spacer>
115 <widget class="QLabel">
116 <property name="name">
117 <cstring>textLabel5</cstring>
118 </property>
119 <property name="text">
120 <string>ABC</string>
121 </property>
122 </widget>
123 </hbox>
124 </widget>
125 <widget class="QLayoutWidget">
126 <property name="name">
127 <cstring>layout4</cstring>
128 </property>
129 <hbox>
130 <property name="name">
131 <cstring>unnamed</cstring>
132 </property>
133 <widget class="QCheckBox">
134 <property name="name">
135 <cstring>int_charNumCheckBox</cstring>
136 </property>
137 <property name="text">
138 <string>Numbers:</string>
139 </property>
140 <property name="checked">
141 <bool>true</bool>
142 </property>
143 </widget>
144 <spacer>
145 <property name="name">
146 <cstring>spacer3</cstring>
147 </property>
148 <property name="orientation">
149 <enum>Horizontal</enum>
150 </property>
151 <property name="sizeType">
152 <enum>Expanding</enum>
153 </property>
154 <property name="sizeHint">
155 <size>
156 <width>40</width>
157 <height>20</height>
158 </size>
159 </property>
160 </spacer>
161 <widget class="QLabel">
162 <property name="name">
163 <cstring>textLabel6</cstring>
164 </property>
165 <property name="text">
166 <string>123</string>
167 </property>
168 </widget>
169 </hbox>
170 </widget>
171 <widget class="QLayoutWidget">
172 <property name="name">
173 <cstring>layout6</cstring>
174 </property>
175 <hbox>
176 <property name="name">
177 <cstring>unnamed</cstring>
178 </property>
179 <widget class="QCheckBox">
180 <property name="name">
181 <cstring>int_charSpecCheckBox</cstring>
182 </property>
183 <property name="text">
184 <string>Special characters:</string>
185 </property>
186 </widget>
187 <spacer>
188 <property name="name">
189 <cstring>spacer4</cstring>
190 </property>
191 <property name="orientation">
192 <enum>Horizontal</enum>
193 </property>
194 <property name="sizeType">
195 <enum>Expanding</enum>
196 </property>
197 <property name="sizeHint">
198 <size>
199 <width>40</width>
200 <height>20</height>
201 </size>
202 </property>
203 </spacer>
204 <widget class="QLabel">
205 <property name="name">
206 <cstring>textLabel7</cstring>
207 </property>
208 <property name="text">
209 <string>!"§$%&amp;/()=?,.-;:_+</string>
210 </property>
211 </widget>
212 </hbox>
213 </widget>
214 <widget class="QCheckBox">
215 <property name="name">
216 <cstring>int_charBlankCheckBox</cstring>
217 </property>
218 <property name="text">
219 <string>Spaces (blank characters)</string>
220 </property>
221 </widget>
222 <widget class="QLayoutWidget">
223 <property name="name">
224 <cstring>layout7</cstring>
225 </property>
226 <hbox>
227 <property name="name">
228 <cstring>unnamed</cstring>
229 </property>
230 <widget class="QCheckBox">
231 <property name="name">
232 <cstring>int_charUserCheckBox</cstring>
233 </property>
234 <property name="text">
235 <string>User defined:</string>
236 </property>
237 </widget>
238 <spacer>
239 <property name="name">
240 <cstring>spacer5</cstring>
241 </property>
242 <property name="orientation">
243 <enum>Horizontal</enum>
244 </property>
245 <property name="sizeType">
246 <enum>Expanding</enum>
247 </property>
248 <property name="sizeHint">
249 <size>
250 <width>40</width>
251 <height>20</height>
252 </size>
253 </property>
254 </spacer>
255 <widget class="QLineEdit">
256 <property name="name">
257 <cstring>int_userDefLineEdit</cstring>
258 </property>
259 <property name="enabled">
260 <bool>false</bool>
261 </property>
262 </widget>
263 </hbox>
264 </widget>
265 </vbox>
266 </widget>
267 <widget class="QLayoutWidget">
268 <property name="name">
269 <cstring>layout8</cstring>
270 </property>
271 <hbox>
272 <property name="name">
273 <cstring>unnamed</cstring>
274 </property>
275 <widget class="QLabel">
276 <property name="name">
277 <cstring>textLabel2</cstring>
278 </property>
279 <property name="text">
280 <string>Password Length:</string>
281 </property>
282 </widget>
283 <widget class="QSpinBox">
284 <property name="name">
285 <cstring>int_lenSpinBox</cstring>
286 </property>
287 <property name="maxValue">
288 <number>9999</number>
289 </property>
290 <property name="minValue">
291 <number>1</number>
292 </property>
293 <property name="value">
294 <number>8</number>
295 </property>
296 </widget>
297 </hbox>
298 </widget>
299 <widget class="QCheckBox">
300 <property name="name">
301 <cstring>int_filterCheckBox</cstring>
302 </property>
303 <property name="text">
304 <string>Enable Filtering to get better passwords</string>
305 </property>
306 <property name="checked">
307 <bool>true</bool>
308 </property>
309 </widget>
310 <widget class="QLayoutWidget">
311 <property name="name">
312 <cstring>layout1</cstring>
313 </property>
314 <hbox>
315 <property name="name">
316 <cstring>unnamed</cstring>
317 </property>
318 <widget class="QPushButton">
319 <property name="name">
320 <cstring>genButton</cstring>
321 </property>
322 <property name="text">
323 <string>&amp;Generate now</string>
324 </property>
325 </widget>
326 <widget class="QPushButton">
327 <property name="name">
328 <cstring>cancelButton</cstring>
329 </property>
330 <property name="text">
331 <string>&amp;Cancel</string>
332 </property>
333 </widget>
334 </hbox>
335 </widget>
336 </vbox>
337</widget>
338<connections>
339 <connection>
340 <sender>int_charUserCheckBox</sender>
341 <signal>toggled(bool)</signal>
342 <receiver>int_userDefLineEdit</receiver>
343 <slot>setEnabled(bool)</slot>
344 </connection>
345 <connection>
346 <sender>cancelButton</sender>
347 <signal>clicked()</signal>
348 <receiver>pwGenWnd</receiver>
349 <slot>cancelButton_slot()</slot>
350 </connection>
351 <connection>
352 <sender>genButton</sender>
353 <signal>clicked()</signal>
354 <receiver>pwGenWnd</receiver>
355 <slot>genButton_slot()</slot>
356 </connection>
357</connections>
358<slots>
359 <slot>cancelButton_slot()</slot>
360 <slot>genButton_slot()</slot>
361</slots>
362<layoutdefaults spacing="6" margin="11"/>
363</UI>
diff --git a/pwmanager/pwmanager/pwgenwndimpl.cpp b/pwmanager/pwmanager/pwgenwndimpl.cpp
new file mode 100644
index 0000000..01f5740
--- a/dev/null
+++ b/pwmanager/pwmanager/pwgenwndimpl.cpp
@@ -0,0 +1,112 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "pwgenwndimpl.h"
21#include "pwmexception.h"
22#include "genpasswd.h"
23
24#include <qtabwidget.h>
25#include <qspinbox.h>
26#include <qcheckbox.h>
27#include <qlineedit.h>
28
29#include <klocale.h>
30#include <kmessagebox.h>
31
32
33PwGenWndImpl::PwGenWndImpl(QWidget *parent,
34 const char *name,
35 bool modal,
36 WFlags fl)
37 : pwGenWnd(parent, name, modal, fl)
38{
39}
40
41PwGenWndImpl::~PwGenWndImpl()
42{
43}
44
45void PwGenWndImpl::genButton_slot()
46{
47 // internal generator
48 if (!optionsSanityIntGen())
49 return;
50 if (startIntGen())
51 goto exit_success;
52 done(0);
53exit_success:
54 done(1);
55}
56
57void PwGenWndImpl::cancelButton_slot()
58{
59 done(0);
60}
61
62bool PwGenWndImpl::optionsSanityIntGen()
63{
64 if (int_charLowerCheckBox->isChecked())
65 return true;
66 if (int_charUpperCheckBox->isChecked())
67 return true;
68 if (int_charNumCheckBox->isChecked())
69 return true;
70 if (int_charSpecCheckBox->isChecked())
71 return true;
72 if (int_charUserCheckBox->isChecked()) {
73 if (int_userDefLineEdit->text().length() >= 2)
74 return true;
75 if (int_charBlankCheckBox->isChecked())
76 return true;
77 }
78 KMessageBox::error(this,
79 i18n("Incorrect Charset selection!\n"
80 "It's impossible to generate a sane "
81 "password with the selected charset(s).\n"
82 "Please select more charsets."),
83 i18n("Incorrect Charset selection"));
84 return false;
85}
86
87bool PwGenWndImpl::startIntGen()
88{
89 GenPasswd gen;
90 gen.setLen(int_lenSpinBox->value());
91 gen.setUseFilter(int_filterCheckBox->isChecked());
92 gen.setCharset(int_charLowerCheckBox->isChecked(),
93 int_charUpperCheckBox->isChecked(),
94 int_charNumCheckBox->isChecked(),
95 int_charSpecCheckBox->isChecked(),
96 int_charBlankCheckBox->isChecked(),
97 int_charUserCheckBox->isChecked() ?
98 int_userDefLineEdit->text() :
99 QString::null);
100 QString pw(gen.gen());
101 if (pw.isEmpty())
102 return false;
103 password = pw;
104 return true;
105}
106
107QString PwGenWndImpl::getPassword()
108{
109 QString ret(password);
110 password = QString::null;
111 return ret;
112}
diff --git a/pwmanager/pwmanager/pwgenwndimpl.h b/pwmanager/pwmanager/pwgenwndimpl.h
new file mode 100644
index 0000000..5c25643
--- a/dev/null
+++ b/pwmanager/pwmanager/pwgenwndimpl.h
@@ -0,0 +1,54 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef __PWGENWNDIMPL_H
21#define __PWGENWNDIMPL_H
22
23#include "pwgenwnd.h"
24
25class PwGenWndImpl : public pwGenWnd
26{
27public:
28 PwGenWndImpl(QWidget *parent = 0,
29 const char *name = 0,
30 bool modal = FALSE,
31 WFlags fl = 0);
32 ~PwGenWndImpl();
33
34 /** returns the generated password */
35 QString getPassword();
36
37protected slots:
38 /** generate button pressed */
39 void genButton_slot();
40 /** cancel button pressed */
41 void cancelButton_slot();
42
43protected:
44 /** start the internal generator */
45 bool startIntGen();
46 /** check all options of the internal generator */
47 bool optionsSanityIntGen();
48
49protected:
50 /** the generated password */
51 QString password;
52};
53
54#endif // __PWGENWNDIMPL_H
diff --git a/pwmanager/pwmanager/pwm.cpp b/pwmanager/pwmanager/pwm.cpp
new file mode 100644
index 0000000..0e57650
--- a/dev/null
+++ b/pwmanager/pwmanager/pwm.cpp
@@ -0,0 +1,1192 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include <klocale.h>
21#include <klistview.h>
22#include <ktoolbar.h>
23#include <kfiledialog.h>
24#include <kiconloader.h>
25#include <kmessagebox.h>
26
27#ifndef PWM_EMBEDDED
28#include <kmenubar.h>
29#include <kstatusbar.h>
30#include <dcopclient.h>
31#else
32#include <qmenubar.h>
33#endif
34
35#include <qpixmap.h>
36#include <qcheckbox.h>
37#include <qspinbox.h>
38#include <qlineedit.h>
39#include <qfileinfo.h>
40#include <qclipboard.h>
41
42
43#include <stdio.h>
44
45#include "pwm.h"
46#include "pwminit.h"
47#include "configwndimpl.h"
48#include "pwmprint.h"
49#include "addentrywndimpl.h"
50#include "globalstuff.h"
51#include "findwndimpl.h"
52#include "configuration.h"
53
54#ifdef CONFIG_KWALLETIF
55# include "kwalletif.h"
56# include "kwalletemu.h"
57#endif
58#ifdef CONFIG_KEYCARD
59# include "pwmkeycard.h"
60#endif
61
62
63 #define DEFAULT_SIZE (QSize(700, 400))
64
65// Button IDs for "file" popup menu
66enum {
67 BUTTON_POPUP_FILE_NEW = 0,
68 BUTTON_POPUP_FILE_OPEN,
69 BUTTON_POPUP_FILE_CLOSE,
70 BUTTON_POPUP_FILE_SAVE,
71 BUTTON_POPUP_FILE_SAVEAS,
72 BUTTON_POPUP_FILE_EXPORT,
73 BUTTON_POPUP_FILE_IMPORT,
74 BUTTON_POPUP_FILE_PRINT,
75 BUTTON_POPUP_FILE_QUIT
76};
77// Button IDs for "manage" popup menu
78enum {
79 BUTTON_POPUP_MANAGE_ADD = 0,
80 BUTTON_POPUP_MANAGE_EDIT,
81 BUTTON_POPUP_MANAGE_DEL,
82 BUTTON_POPUP_MANAGE_CHANGEMP
83};
84// Button IDs for chipcard popup menu
85enum {
86#ifdef CONFIG_KEYCARD
87 BUTTON_POPUP_CHIPCARD_GENNEW = 0,
88 BUTTON_POPUP_CHIPCARD_DEL,
89 BUTTON_POPUP_CHIPCARD_READID,
90 BUTTON_POPUP_CHIPCARD_SAVEBACKUP,
91 BUTTON_POPUP_CHIPCARD_REPLAYBACKUP
92#else // CONFIG_KEYCARD
93 BUTTON_POPUP_CHIPCARD_NO = 0
94#endif // CONFIG_KEYCARD
95};
96// Button IDs for "view" popup menu
97enum {
98 BUTTON_POPUP_VIEW_FIND = 0,
99 BUTTON_POPUP_VIEW_LOCK,
100 BUTTON_POPUP_VIEW_DEEPLOCK,
101 BUTTON_POPUP_VIEW_UNLOCK
102};
103// Button IDs for "options" popup menu
104enum {
105 BUTTON_POPUP_OPTIONS_CONFIG = 0
106};
107// Button IDs for "export" popup menu (in "file" popup menu)
108enum {
109 BUTTON_POPUP_EXPORT_TEXT = 0,
110 BUTTON_POPUP_EXPORT_GPASMAN
111#ifdef CONFIG_KWALLETIF
112 ,BUTTON_POPUP_EXPORT_KWALLET
113#endif
114};
115// Button IDs for "import" popup menu (in "file" popup menu)
116enum {
117 BUTTON_POPUP_IMPORT_TEXT = 0,
118 BUTTON_POPUP_IMPORT_GPASMAN
119#ifdef CONFIG_KWALLETIF
120 ,BUTTON_POPUP_IMPORT_KWALLET
121#endif
122};
123// Button IDs for toolbar
124enum {
125 BUTTON_TOOL_NEW = 0,
126 BUTTON_TOOL_OPEN,
127 BUTTON_TOOL_SAVE,
128 BUTTON_TOOL_SAVEAS,
129 BUTTON_TOOL_PRINT,
130 BUTTON_TOOL_ADD,
131 BUTTON_TOOL_EDIT,
132 BUTTON_TOOL_DEL,
133 BUTTON_TOOL_FIND,
134 BUTTON_TOOL_LOCK,
135 BUTTON_TOOL_DEEPLOCK,
136 BUTTON_TOOL_UNLOCK
137};
138
139
140PwM::PwM(PwMInit *_init, PwMDoc *doc,
141 bool virginity,
142 QWidget *parent, const char *name)
143 : KMainWindow(parent, name)
144 , forceQuit (false)
145 , forceMinimizeToTray (false)
146{
147 init = _init;
148 connect(doc, SIGNAL(docClosed(PwMDoc *)),
149 this, SLOT(docClosed(PwMDoc *)));
150 initMenubar();
151 initToolbar();
152 initMetrics();
153 setVirgin(virginity);
154 setFocusPolicy(QWidget::WheelFocus);
155#ifndef PWM_EMBEDDED
156 statusBar()->show();
157#endif
158 view = makeNewListView(doc);
159 setCentralWidget(view);
160 updateCaption();
161 showStatMsg(i18n("Ready."));
162}
163
164PwM::~PwM()
165{
166 disconnect(curDoc(), SIGNAL(docClosed(PwMDoc *)),
167 this, SLOT(docClosed(PwMDoc *)));
168 conf()->confWndMainWndSize(size());
169 emit closed(this);
170 delete view;
171}
172
173void PwM::initMenubar()
174{
175 KIconLoader icons;
176
177 filePopup = new KPopupMenu(this);
178 importPopup = new KPopupMenu(filePopup);
179 exportPopup = new KPopupMenu(filePopup);
180 managePopup = new KPopupMenu(this);
181#ifdef CONFIG_KEYCARD
182 chipcardPopup = new KPopupMenu(this);
183#endif // CONFIG_KEYCARD
184 viewPopup = new KPopupMenu(this);
185 optionsPopup = new KPopupMenu(this);
186
187// "file" popup menu
188 filePopup->insertItem(QIconSet(icons.loadIcon("filenew", KIcon::Small)),
189 i18n("&New"), this,
190 SLOT(new_slot()), 0, BUTTON_POPUP_FILE_NEW);
191 filePopup->insertItem(QIconSet(icons.loadIcon("fileopen", KIcon::Small)),
192 i18n("&Open"), this,
193 SLOT(open_slot()), 0, BUTTON_POPUP_FILE_OPEN);
194 filePopup->insertItem(QIconSet(icons.loadIcon("fileclose", KIcon::Small)),
195 i18n("&Close"), this,
196 SLOT(close_slot()), 0, BUTTON_POPUP_FILE_CLOSE);
197 filePopup->insertSeparator();
198 filePopup->insertItem(QIconSet(icons.loadIcon("filesave", KIcon::Small)),
199 i18n("&Save"), this,
200 SLOT(save_slot()), 0, BUTTON_POPUP_FILE_SAVE);
201 filePopup->insertItem(QIconSet(icons.loadIcon("filesaveas", KIcon::Small)),
202 i18n("Save &as..."),
203 this, SLOT(saveAs_slot()), 0,
204 BUTTON_POPUP_FILE_SAVEAS);
205 filePopup->insertSeparator();
206 // "file/export" popup menu
207 exportPopup->insertItem(i18n("&Text-file..."), this,
208 SLOT(exportToText()), 0, BUTTON_POPUP_EXPORT_TEXT);
209 exportPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this,
210 SLOT(exportToGpasman()), 0, BUTTON_POPUP_EXPORT_GPASMAN);
211#ifdef CONFIG_KWALLETIF
212 exportPopup->insertItem(i18n("&KWallet..."), this,
213 SLOT(exportToKWallet()), 0, BUTTON_POPUP_EXPORT_KWALLET);
214#endif
215 filePopup->insertItem(QIconSet(icons.loadIcon("fileexport", KIcon::Small)),
216 i18n("E&xport"), exportPopup,
217 BUTTON_POPUP_FILE_EXPORT);
218 // "file/import" popup menu
219 importPopup->insertItem(i18n("&Text-file..."), this,
220 SLOT(importFromText()), 0, BUTTON_POPUP_IMPORT_TEXT);
221 importPopup->insertItem(i18n("&Gpasman / Kpasman ..."), this,
222 SLOT(importFromGpasman()), 0, BUTTON_POPUP_IMPORT_GPASMAN);
223#ifdef CONFIG_KWALLETIF
224 importPopup->insertItem(i18n("&KWallet..."), this,
225 SLOT(importKWallet()), 0, BUTTON_POPUP_IMPORT_KWALLET);
226#endif
227 filePopup->insertItem(QIconSet(icons.loadIcon("fileimport", KIcon::Small)),
228 i18n("I&mport"), importPopup,
229 BUTTON_POPUP_FILE_IMPORT);
230 filePopup->insertSeparator();
231 filePopup->insertItem(QIconSet(icons.loadIcon("fileprint", KIcon::Small)),
232 i18n("&Print..."), this,
233 SLOT(print_slot()), 0, BUTTON_POPUP_FILE_PRINT);
234 filePopup->insertSeparator();
235 filePopup->insertItem(QIconSet(icons.loadIcon("exit", KIcon::Small)),
236 i18n("&Quit"), this,
237 SLOT(quitButton_slot()), 0, BUTTON_POPUP_FILE_QUIT);
238 menuBar()->insertItem(i18n("&File"), filePopup);
239// "manage" popup menu
240 managePopup->insertItem(QIconSet(icons.loadIcon("pencil", KIcon::Small)),
241 i18n("&Add password"), this,
242 SLOT(addPwd_slot()), 0,
243 BUTTON_POPUP_MANAGE_ADD);
244 managePopup->insertItem(QIconSet(icons.loadIcon("edit", KIcon::Small)),
245 i18n("&Edit"), this, SLOT(editPwd_slot()), 0,
246 BUTTON_POPUP_MANAGE_EDIT);
247 managePopup->insertItem(QIconSet(icons.loadIcon("editdelete", KIcon::Small)),
248 i18n("&Delete"), this, SLOT(deletePwd_slot()),
249 0, BUTTON_POPUP_MANAGE_DEL);
250 managePopup->insertSeparator();
251 managePopup->insertItem(QIconSet(icons.loadIcon("rotate", KIcon::Small)),
252 i18n("Change &Master Password"), this,
253 SLOT(changeMasterPwd_slot()), 0,
254 BUTTON_POPUP_MANAGE_CHANGEMP);
255 menuBar()->insertItem(i18n("&Manage"), managePopup);
256// "chipcard" popup menu
257#ifdef CONFIG_KEYCARD
258 chipcardPopup->insertItem(QIconSet(icons.loadIcon("filenew", KIcon::Small)),
259 i18n("&Generate new key-card"), this,
260 SLOT(genNewCard_slot()), 0,
261 BUTTON_POPUP_CHIPCARD_GENNEW);
262 chipcardPopup->insertItem(QIconSet(icons.loadIcon("editdelete", KIcon::Small)),
263 i18n("&Erase key-card"), this,
264 SLOT(eraseCard_slot()), 0,
265 BUTTON_POPUP_CHIPCARD_DEL);
266 chipcardPopup->insertItem(QIconSet(icons.loadIcon("", KIcon::Small)),
267 i18n("Read card-&ID"), this,
268 SLOT(readCardId_slot()), 0,
269 BUTTON_POPUP_CHIPCARD_READID);
270 chipcardPopup->insertSeparator();
271 chipcardPopup->insertItem(QIconSet(icons.loadIcon("2rightarrow", KIcon::Small)),
272 i18n("&Make card backup-image"), this,
273 SLOT(makeCardBackup_slot()), 0,
274 BUTTON_POPUP_CHIPCARD_SAVEBACKUP);
275 chipcardPopup->insertItem(QIconSet(icons.loadIcon("2leftarrow", KIcon::Small)),
276 i18n("&Replay card backup-image"), this,
277 SLOT(replayCardBackup_slot()), 0,
278 BUTTON_POPUP_CHIPCARD_REPLAYBACKUP);
279 menuBar()->insertItem(i18n("&Chipcard manager"), chipcardPopup);
280#endif // CONFIG_KEYCARD
281// "view" popup menu
282 viewPopup->insertItem(QIconSet(icons.loadIcon("find", KIcon::Small)),
283 i18n("&Find"), this,
284 SLOT(find_slot()), 0, BUTTON_POPUP_VIEW_FIND);
285 viewPopup->insertSeparator();
286 viewPopup->insertItem(QIconSet(icons.loadIcon("halfencrypted", KIcon::Small)),
287 i18n("&Lock all entries"), this,
288 SLOT(lockWnd_slot()), 0,
289 BUTTON_POPUP_VIEW_LOCK);
290 viewPopup->insertItem(QIconSet(icons.loadIcon("encrypted", KIcon::Small)),
291 i18n("&Deep-lock all entries"), this,
292 SLOT(deepLockWnd_slot()), 0,
293 BUTTON_POPUP_VIEW_DEEPLOCK);
294 viewPopup->insertItem(QIconSet(icons.loadIcon("decrypted", KIcon::Small)),
295 i18n("&Unlock all entries"), this,
296 SLOT(unlockWnd_slot()), 0,
297 BUTTON_POPUP_VIEW_UNLOCK);
298 menuBar()->insertItem(i18n("&View"), viewPopup);
299// "options" popup menu
300 optionsPopup->insertItem(QIconSet(icons.loadIcon("configure", KIcon::Small)),
301 i18n("&Configure..."), this,
302 SLOT(config_slot()),
303 BUTTON_POPUP_OPTIONS_CONFIG);
304 menuBar()->insertItem(i18n("&Options"), optionsPopup);
305// "help" popup menu
306#ifndef PWM_EMBEDDED
307 helpPopup = helpMenu(QString::null, false);
308 menuBar()->insertItem(i18n("&Help"), helpPopup);
309#endif
310}
311
312void PwM::initToolbar()
313{
314 KIconLoader icons;
315
316 toolBar()->insertButton(icons.loadIcon("filenew", KIcon::Toolbar),
317 BUTTON_TOOL_NEW, SIGNAL(clicked(int)), this,
318 SLOT(new_slot()), true, i18n("New"));
319 toolBar()->insertButton(icons.loadIcon("fileopen", KIcon::Toolbar),
320 BUTTON_TOOL_OPEN, SIGNAL(clicked(int)), this,
321 SLOT(open_slot()), true, i18n("Open"));
322 toolBar()->insertSeparator();
323 toolBar()->insertButton(icons.loadIcon("filesave", KIcon::Toolbar),
324 BUTTON_TOOL_SAVE, SIGNAL(clicked(int)), this,
325 SLOT(save_slot()), true, i18n("Save"));
326 toolBar()->insertButton(icons.loadIcon("filesaveas", KIcon::Toolbar),
327 BUTTON_TOOL_SAVEAS, SIGNAL(clicked(int)), this,
328 SLOT(saveAs_slot()), true, i18n("Save as"));
329 toolBar()->insertButton(icons.loadIcon("fileprint", KIcon::Toolbar),
330 BUTTON_TOOL_PRINT, SIGNAL(clicked(int)), this,
331 SLOT(print_slot()), true, i18n("Print..."));
332 toolBar()->insertSeparator();
333 toolBar()->insertButton(icons.loadIcon("pencil", KIcon::Toolbar),
334 BUTTON_TOOL_ADD, SIGNAL(clicked(int)), this,
335 SLOT(addPwd_slot()), true,
336 i18n("Add password"));
337 toolBar()->insertButton(icons.loadIcon("edit", KIcon::Toolbar),
338 BUTTON_TOOL_EDIT, SIGNAL(clicked(int)), this,
339 SLOT(editPwd_slot()), true,
340 i18n("Edit password"));
341 toolBar()->insertButton(icons.loadIcon("editdelete", KIcon::Toolbar),
342 BUTTON_TOOL_DEL, SIGNAL(clicked(int)), this,
343 SLOT(deletePwd_slot()), true,
344 i18n("Delete password"));
345 toolBar()->insertSeparator();
346 toolBar()->insertButton(icons.loadIcon("find", KIcon::Toolbar),
347 BUTTON_TOOL_FIND, SIGNAL(clicked(int)), this,
348 SLOT(find_slot()), true, i18n("Find entry"));
349 toolBar()->insertSeparator();
350 toolBar()->insertButton(icons.loadIcon("halfencrypted", KIcon::Toolbar),
351 BUTTON_TOOL_LOCK, SIGNAL(clicked(int)), this,
352 SLOT(lockWnd_slot()), true,
353 i18n("Lock all entries"));
354 toolBar()->insertButton(icons.loadIcon("encrypted", KIcon::Toolbar),
355 BUTTON_TOOL_DEEPLOCK, SIGNAL(clicked(int)), this,
356 SLOT(deepLockWnd_slot()), true,
357 i18n("Deep-Lock all entries"));
358 toolBar()->insertButton(icons.loadIcon("decrypted", KIcon::Toolbar),
359 BUTTON_TOOL_UNLOCK, SIGNAL(clicked(int)), this,
360 SLOT(unlockWnd_slot()), true,
361 i18n("Unlock all entries"));
362}
363
364void PwM::initMetrics()
365{
366 QSize s = conf()->confWndMainWndSize();
367 if (s.isValid())
368 resize(s);
369 else
370 resize(DEFAULT_SIZE);
371}
372
373void PwM::updateCaption()
374{
375 setPlainCaption(curDoc()->getTitle() + " - " PROG_NAME " " PACKAGE_VER);
376}
377
378void PwM::hideEvent(QHideEvent *)
379{
380 if (isMinimized()) {
381 if (init->tray()) {
382 forceMinimizeToTray = true;
383 close();
384 }
385 int mmlock = conf()->confGlobMinimizeLock();
386 switch (mmlock) {
387 case 0: // don't lock anything
388 break;
389 case 1: {// normal lock
390 curDoc()->lockAll(true);
391 break;
392 } case 2: {// deep-lock
393 curDoc()->deepLock();
394 break;
395 } default:
396 WARN();
397 }
398 }
399}
400
401void PwM::setVirgin(bool v)
402{
403 if (virgin == v)
404 return;
405 virgin = v;
406 filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVE, !v);
407 filePopup->setItemEnabled(BUTTON_POPUP_FILE_SAVEAS, !v);
408 filePopup->setItemEnabled(BUTTON_POPUP_FILE_EXPORT, !v);
409 filePopup->setItemEnabled(BUTTON_POPUP_FILE_PRINT, !v);
410 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_EDIT, !v);
411 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_DEL, !v);
412 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, !v);
413 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_LOCK, !v);
414 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_DEEPLOCK, !v);
415 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_UNLOCK, !v);
416 viewPopup->setItemEnabled(BUTTON_POPUP_VIEW_FIND, !v);
417 toolBar()->setItemEnabled(BUTTON_TOOL_SAVE, !v);
418 toolBar()->setItemEnabled(BUTTON_TOOL_SAVEAS, !v);
419 toolBar()->setItemEnabled(BUTTON_TOOL_PRINT, !v);
420 toolBar()->setItemEnabled(BUTTON_TOOL_EDIT, !v);
421 toolBar()->setItemEnabled(BUTTON_TOOL_DEL, !v);
422 toolBar()->setItemEnabled(BUTTON_TOOL_LOCK, !v);
423 toolBar()->setItemEnabled(BUTTON_TOOL_DEEPLOCK, !v);
424 toolBar()->setItemEnabled(BUTTON_TOOL_UNLOCK, !v);
425 toolBar()->setItemEnabled(BUTTON_TOOL_FIND, !v);
426}
427
428void PwM::new_slot()
429{
430 init->createMainWnd();
431}
432
433//US ENH
434void PwM::open_slot()
435{
436 open_slot("");
437}
438
439void PwM::open_slot(QString fn)
440{
441 openDoc(fn);
442}
443
444PwMDoc * PwM::openDoc(QString filename, bool openDeepLocked)
445{
446 if (!isVirgin()) {
447 // open the document in a new window.
448 PwM *newInstance = init->createMainWnd();
449 PwMDoc *newDoc = newInstance->openDoc(filename, openDeepLocked);
450 if (!newDoc) {
451 newInstance->setForceQuit(true);
452 delete_and_null(newInstance);
453 }
454 return newDoc;
455 }
456
457 if (!curDoc()->openDocUi(curDoc(), filename, openDeepLocked))
458 return 0;
459 showStatMsg(i18n("Successfully opened file."));
460 updateCaption();
461 setVirgin(false);
462 return curDoc();
463}
464
465PwMView * PwM::makeNewListView(PwMDoc *doc)
466{
467 PwMView *ret = new PwMView(this, this, doc);
468 ret->setFont(conf()->confGlobEntryFont());
469 ret->show();
470 return ret;
471}
472
473void PwM::close_slot()
474{
475 close();
476}
477
478void PwM::quitButton_slot()
479{
480 init->shutdownApp(0);
481}
482
483void PwM::save_slot()
484{
485 save();
486}
487
488bool PwM::save()
489{
490 if (!curDoc()->saveDocUi(curDoc()))
491 return false;
492 showStatMsg(i18n("Successfully saved data."));
493 updateCaption();
494 return true;
495}
496
497void PwM::saveAs_slot()
498{
499 saveAs();
500}
501
502bool PwM::saveAs()
503{
504 if (!curDoc()->saveAsDocUi(curDoc()))
505 return false;
506 showStatMsg(i18n("Successfully saved data."));
507 updateCaption();
508 return true;
509}
510
511//US ENH : changed code to run with older MOC
512void PwM::addPwd_slot()
513{
514 addPwd_slot(0, 0);
515}
516
517void PwM::addPwd_slot(QString *pw, PwMDoc *_doc)
518{
519 PwMDoc *doc;
520 if (_doc) {
521 doc = _doc;
522 } else {
523 doc = curDoc();
524 }
525 PWM_ASSERT(doc);
526 doc->timer()->getLock(DocTimer::id_autoLockTimer);
527 AddEntryWndImpl w;
528 vector<string> catList;
529 doc->getCategoryList(&catList);
530 unsigned i, size = catList.size();
531 for (i = 0; i < size; ++i) {
532 w.addCategory(catList[i].c_str());
533 }
534 w.setCurrCategory(view->getCurrentCategory());
535 if (pw)
536 w.pwLineEdit->setText(*pw);
537
538 tryAgain:
539 if (w.exec() == 1) {
540 PwMDataItem d;
541 d.desc = w.getDescription().latin1();
542 d.name = w.getUsername().latin1();
543 d.pw = w.getPassword().latin1();
544 d.comment = w.getComment().latin1();
545 d.url = w.getUrl().latin1();
546 d.launcher = w.getLauncher().latin1();
547 PwMerror ret = doc->addEntry(w.getCategory(), &d);
548 if (ret == e_entryExists) {
549 KMessageBox::error(this,
550 i18n
551 ("An entry with this \"Description\", "
552 "does already exist.\n"
553 "Please select another description."),
554 i18n("entry already exists."));
555 goto tryAgain;
556 } else if (ret == e_maxAllowedEntr) {
557 KMessageBox::error(this, i18n("The maximum possible number of entries "
558 "has been reached. You can't add more entries."),
559 i18n("maximum number of entries"));
560 doc->timer()->putLock(DocTimer::id_autoLockTimer);
561 return;
562 }
563 }
564 setVirgin(false);
565 doc->timer()->putLock(DocTimer::id_autoLockTimer);
566}
567
568//US ENH : changed code to run with older MOC
569void PwM::editPwd_slot()
570{
571 editPwd_slot(0,0,0);
572}
573
574void PwM::editPwd_slot(const QString *category)
575{
576 editPwd_slot(category, 0, 0);
577}
578
579void PwM::editPwd_slot(const QString *category, const int *index,
580 PwMDoc *_doc)
581{
582 PwMDoc *doc;
583 if (_doc) {
584 doc = _doc;
585 } else {
586 doc = curDoc();
587 }
588 PWM_ASSERT(doc);
589 if (doc->isDocEmpty())
590 return;
591 if (doc->isDeepLocked())
592 return;
593 doc->timer()->getLock(DocTimer::id_autoLockTimer);
594 unsigned int curEntryIndex;
595 if (index) {
596 curEntryIndex = *index;
597 } else {
598 if (!(view->getCurEntryIndex(&curEntryIndex))) {
599 printDebug("couldn't get index. Maybe we have a binary entry here.");
600 doc->timer()->putLock(DocTimer::id_autoLockTimer);
601 return;
602 }
603 }
604 QString curCategory;
605 if (category) {
606 curCategory = *category;
607 } else {
608 curCategory = view->getCurrentCategory();
609 }
610 PwMDataItem currItem;
611 if (!doc->getEntry(curCategory, curEntryIndex, &currItem, true)) {
612 doc->timer()->putLock(DocTimer::id_autoLockTimer);
613 return;
614 }
615 BUG_ON(currItem.binary);
616
617 AddEntryWndImpl w;
618 vector<string> catList;
619 doc->getCategoryList(&catList);
620 unsigned i, size = catList.size();
621 for (i = 0; i < size; ++i) {
622 w.addCategory(catList[i].c_str());
623 }
624 w.setCurrCategory(curCategory);
625 w.setDescription(currItem.desc.c_str());
626 w.setUsername(currItem.name.c_str());
627 w.setPassword(currItem.pw.c_str());
628 w.setUrl(currItem.url.c_str());
629 w.setLauncher(currItem.launcher.c_str());
630 w.setComment(currItem.comment.c_str());
631 if (w.exec() == 1) {
632 currItem.desc = w.getDescription().latin1();
633 currItem.name = w.getUsername().latin1();
634 currItem.pw = w.getPassword().latin1();
635 currItem.comment = w.getComment().latin1();
636 currItem.url = w.getUrl().latin1();
637 currItem.launcher = w.getLauncher().latin1();
638 if (!doc->editEntry(curCategory, w.getCategory(),
639 curEntryIndex, &currItem)) {
640 KMessageBox::error(this,
641 i18n("Couldn't edit the entry.\n"
642 "Maybe you changed the category and "
643 "this entry is already present in the new "
644 "category?"),
645 i18n("couldn't edit entry."));
646 doc->timer()->putLock(DocTimer::id_autoLockTimer);
647 return;
648 }
649 }
650 doc->timer()->putLock(DocTimer::id_autoLockTimer);
651}
652
653void PwM::deletePwd_slot()
654{
655 PWM_ASSERT(curDoc());
656 if (curDoc()->isDocEmpty())
657 return;
658 if (curDoc()->isDeepLocked())
659 return;
660 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
661 unsigned int curEntryIndex = 0;
662 if (!(view->getCurEntryIndex(&curEntryIndex))) {
663 printDebug("couldn't get index");
664 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
665 return;
666 }
667
668 PwMDataItem currItem;
669 QString curCategory = view->getCurrentCategory();
670 if (!curDoc()->getEntry(curCategory, curEntryIndex, &currItem)) {
671 printDebug("couldn't get entry");
672 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
673 return;
674 }
675 if (KMessageBox::
676 questionYesNo(this,
677 i18n
678 ("Do you really want to delete the selected entry") +
679 " \"" + QString(currItem.desc.c_str())
680 + "\" ?", i18n("delete?"))
681 == KMessageBox::Yes) {
682
683 curDoc()->delEntry(curCategory, curEntryIndex);
684 }
685 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
686}
687
688void PwM::changeMasterPwd_slot()
689{
690 PWM_ASSERT(curDoc());
691 curDoc()->changeCurrentPw();
692}
693
694void PwM::lockWnd_slot()
695{
696 PWM_ASSERT(curDoc());
697 curDoc()->lockAll(true);
698}
699
700void PwM::deepLockWnd_slot()
701{
702 PWM_ASSERT(curDoc());
703 curDoc()->deepLock();
704}
705
706void PwM::unlockWnd_slot()
707{
708 PWM_ASSERT(curDoc());
709 curDoc()->lockAll(false);
710}
711
712void PwM::config_slot()
713{
714 Configuration *conf = Configuration::obj();
715 int oldStyle = conf->confWndMainViewStyle();
716
717 // display the configuration window (modal mode)
718 if (!conf->showConfWnd(this))
719 return;
720
721 int newStyle = conf->confWndMainViewStyle();
722 // reinitialize tray
723 init->initTray();
724 // reinitialize KWallet emulation
725 init->initKWalletEmu();
726
727 PwMDocList *_dl = PwMDoc::getOpenDocList();
728 const vector<PwMDocList::listItem> *dl = _dl->getList();
729 vector<PwMDocList::listItem>::const_iterator i = dl->begin(),
730 end = dl->end();
731 PwMDoc *doc;
732 while (i != end) {
733 doc = (*i).doc;
734 // unlock-without-mpw timeout
735 doc->timer()->start(DocTimer::id_mpwTimer);
736 // auto-lock timeout
737 doc->timer()->start(DocTimer::id_autoLockTimer);
738 ++i;
739 }
740
741 const QValueList<PwM *> *ml = init->mainWndList();
742#ifndef PWM_EMBEDDED
743 QValueList<PwM *>::const_iterator i2 = ml->begin(),
744 end2 = ml->end();
745#else
746 QValueList<PwM *>::ConstIterator i2 = ml->begin(),
747 end2 = ml->end();
748#endif
749 PwM *pwm;
750 while (i2 != end2) {
751 pwm = *i2;
752 // reinitialize the window style.
753 if (oldStyle != newStyle)
754 pwm->curView()->initStyle(newStyle);
755 // set the new font
756 pwm->curView()->setFont(conf->confGlobEntryFont());
757 ++i2;
758 }
759}
760
761void PwM::activateMpButton(bool activate)
762{
763 managePopup->setItemEnabled(BUTTON_POPUP_MANAGE_CHANGEMP, activate);
764}
765
766void PwM::closeEvent(QCloseEvent *e)
767{
768 e->accept();
769}
770
771void PwM::docClosed(PwMDoc *doc)
772{
773 PARAM_UNUSED(doc);
774 PWM_ASSERT(doc == curDoc());
775 close();
776}
777
778void PwM::find_slot()
779{
780 PWM_ASSERT(curDoc());
781 if (curDoc()->isDocEmpty())
782 return;
783 if (curDoc()->isDeepLocked())
784 return;
785 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
786 FindWndImpl findWnd(view);
787 findWnd.exec();
788 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
789}
790
791void PwM::exportToText()
792{
793 PWM_ASSERT(curDoc());
794 if (curDoc()->isDocEmpty()) {
795 KMessageBox::information(this,
796 i18n
797 ("Sorry, there's nothing to export.\n"
798 "Please first add some passwords."),
799 i18n("nothing to do"));
800 return;
801 }
802 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
803 QString fn(KFileDialog::getSaveFileName(QString::null,
804 i18n("*|plain-text file"),
805 this));
806 if (fn == "") {
807 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
808 return;
809 }
810
811 PwMerror ret = curDoc()->exportToText(&fn);
812 if (ret != e_success) {
813 KMessageBox::error(this,
814 i18n("Error: Couldn't write to file.\n"
815 "Please check if you have permission to write "
816 "to the file in that directory."),
817 i18n("error while writing"));
818 } else
819 showStatMsg(i18n("Successfully exported data."));
820 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
821}
822
823bool PwM::importFromText()
824{
825 if (!isVirgin()) {
826 if (KMessageBox::questionYesNo(this,
827 i18n("Do you want to import the data "
828 "into the current document? (If you "
829 "select \"no\", a new document will be "
830 "opened.)"),
831 i18n("import into this document?"))
832 == KMessageBox::No) {
833 // import the data to a new window.
834 PwM *newInstance = init->createMainWnd();
835 bool ok = newInstance->importFromText();
836 if (!ok) {
837 newInstance->setForceQuit(true);
838 delete_and_null(newInstance);
839 }
840 return ok;
841 }
842 }
843
844 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
845 PwMerror ret;
846 QString path(KFileDialog::getOpenFileName(QString::null,
847 i18n("*|PWM-exported text file"),
848 this));
849 if (path == "")
850 goto cancelImport;
851
852 ret = curDoc()->importFromText(&path, 0);
853 if (ret == e_fileFormat) {
854 KMessageBox::error(this,
855 i18n("Could not read file-format.\n"
856 "This seems to be _not_ a valid file "
857 "exported by PwM."),
858 i18n("invalid file-format"));
859 goto cancelImport;
860 } else if (ret == e_invalidArg) {
861 BUG();
862 goto cancelImport;
863 } else if (ret != e_success) {
864 KMessageBox::error(this,
865 i18n("Could not import file!\n"
866 "Do you have permission to read this file? "
867 "Do you have enough free memory?"),
868 i18n("import failed"));
869 goto cancelImport;
870 }
871 setVirgin(false);
872 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
873 return true;
874
875cancelImport:
876 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
877 return false;
878}
879
880void PwM::exportToGpasman()
881{
882 PWM_ASSERT(curDoc());
883 if (curDoc()->isDocEmpty()) {
884 KMessageBox::information(this,
885 i18n
886 ("Sorry, there's nothing to export.\n"
887 "Please first add some passwords."),
888 i18n("nothing to do"));
889 return;
890 }
891 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
892 QString fn(KFileDialog::getSaveFileName(QString::null,
893 i18n("*|Gpasman or Kpasman file"),
894 this));
895 if (fn == "") {
896 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
897 return;
898 }
899
900 PwMerror ret = curDoc()->exportToGpasman(&fn);
901 if (ret != e_success) {
902 if (ret == e_noPw) {
903 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
904 return;
905 }
906 KMessageBox::error(this,
907 i18n("Error: Couldn't write to file.\n"
908 "Please check if you have permission to write "
909 "to the file in that directory."),
910 i18n("error while writing"));
911 } else
912 showStatMsg(i18n("Successfully exported data."));
913 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
914}
915
916void PwM::exportToKWallet()
917{
918#ifdef CONFIG_KWALLETIF
919 if (!checkAndAskForKWalletEmu())
920 return;
921 PWM_ASSERT(curDoc());
922 if (curDoc()->isDocEmpty()) {
923 KMessageBox::information(this,
924 i18n
925 ("Sorry, there's nothing to export.\n"
926 "Please first add some passwords."),
927 i18n("nothing to do"));
928 init->initKWalletEmu();
929 return;
930 }
931 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
932 KWalletIf walletIf(this);
933 if (walletIf.kwalletExport(curDoc())) {
934 KMessageBox::information(this,
935 i18n("Successfully exported the data of the current "
936 "document to KWallet."),
937 i18n("Successfully exported data."));
938 showStatMsg(i18n("Successfully exported data."));
939 }
940 init->initKWalletEmu();
941 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
942#endif // CONFIG_KWALLETIF
943}
944
945bool PwM::importFromGpasman()
946{
947 if (!isVirgin()) {
948 if (KMessageBox::questionYesNo(this,
949 i18n("Do you want to import the data "
950 "into the current document? (If you "
951 "select \"no\", a new document will be "
952 "opened.)"),
953 i18n("import into this document?"))
954 == KMessageBox::No) {
955 // import the data to a new window.
956 PwM *newInstance = init->createMainWnd();
957 bool ok = newInstance->importFromGpasman();
958 if (!ok) {
959 newInstance->setForceQuit(true);
960 delete_and_null(newInstance);
961 }
962 return ok;
963 }
964 }
965
966 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
967 PwMerror ret;
968 QString path(KFileDialog::getOpenFileName(QString::null,
969 i18n("*|Gpasman or Kpasman file"), this));
970 if (path == "")
971 goto cancelImport;
972 ret = curDoc()->importFromGpasman(&path);
973 if (ret == e_wrongPw) {
974 if (KMessageBox::questionYesNo(this,
975 i18n
976 ("This is probably the wrong master-password"
977 "you have typed in.\n"
978 "There is no real way to determine the "
979 "correctness of the password in the Gpasman "
980 "file-format. But I think this "
981 "password ist wrong.\n"
982 "Do you want to continue nevertheless?"),
983 i18n("password error"))
984 == KMessageBox::No) {
985 goto cancelImport;
986 }
987 } else if (ret != e_success) {
988 KMessageBox::error(this,
989 i18n("Could not import file!\n"
990 "Do you have permission to read this file?"),
991 i18n("import failed"));
992 goto cancelImport;
993 }
994 setVirgin(false);
995 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
996 return true;
997
998cancelImport:
999 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1000 return false;
1001}
1002
1003#ifdef CONFIG_KWALLETIF
1004bool PwM::checkAndAskForKWalletEmu()
1005{
1006 if (init->kwalletEmu()) {
1007 /* KWallet emulation is enabled. We can't import/export
1008 * data from/to it, while emulation is active.
1009 */
1010 if (KMessageBox::questionYesNo(this,
1011 i18n("KWallet emulation is enabled.\n"
1012 "You can't import or export data from/to "
1013 "the original KWallet, while the emulation "
1014 "is active.\n"
1015 "Do you want to tempoarly disable the KWallet emulation?"),
1016 i18n("Tempoarly disable KWallet emulation?"))
1017 == KMessageBox::Yes) {
1018 init->initKWalletEmu(true);
1019 PWM_ASSERT(!init->kwalletEmu());
1020 return true;
1021 }
1022 return false;
1023 }
1024 return true;
1025}
1026#endif // CONFIG_KWALLETIF
1027
1028bool PwM::importKWallet()
1029{
1030#ifdef CONFIG_KWALLETIF
1031 if (!checkAndAskForKWalletEmu())
1032 return false;
1033 KWalletIf walletIf(this);
1034 if (!isVirgin()) {
1035 if (KMessageBox::questionYesNo(this,
1036 i18n("Do you want to import the data "
1037 "into the current document? (If you "
1038 "select \"no\", a new document will be "
1039 "opened.)"),
1040 i18n("import into this document?"))
1041 == KMessageBox::No) {
1042 // import the data to a new window.
1043 PwM *newInstance = init->createMainWnd();
1044 bool ok = newInstance->importKWallet();
1045 if (!ok) {
1046 newInstance->setForceQuit(true);
1047 delete_and_null(newInstance);
1048 goto exit_fail;
1049 } else {
1050 goto exit_ok;
1051 }
1052 }
1053 }
1054 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1055 if (!walletIf.kwalletImport(curDoc())) {
1056 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1057 showStatMsg(i18n("KWallet import failed"));
1058 goto exit_fail;
1059 }
1060 KMessageBox::information(this,
1061 i18n("Successfully imported the KWallet data "
1062 "into the current document."),
1063 i18n("successfully imported"));
1064 showStatMsg(i18n("successfully imported"));
1065 setVirgin(false);
1066 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1067
1068exit_ok:
1069 init->initKWalletEmu();
1070 return true;
1071
1072exit_fail:
1073 init->initKWalletEmu();
1074#endif // CONFIG_KWALLETIF
1075 return false;
1076}
1077
1078void PwM::print_slot()
1079{
1080 curDoc()->timer()->getLock(DocTimer::id_autoLockTimer);
1081#ifndef PWM_EMBEDDED
1082 PwMPrint p(curDoc(), this);
1083 p.printNow();
1084#else
1085 qDebug("PwM::print_slot , PRINTING IS NOT IMPLEMENTED");
1086#endif
1087 curDoc()->timer()->putLock(DocTimer::id_autoLockTimer);
1088}
1089
1090void PwM::genNewCard_slot()
1091{
1092#ifdef CONFIG_KEYCARD
1093 init->keycard()->genNewCard();
1094#endif
1095}
1096
1097void PwM::eraseCard_slot()
1098{
1099#ifdef CONFIG_KEYCARD
1100 init->keycard()->eraseCard();
1101#endif
1102}
1103
1104void PwM::readCardId_slot()
1105{
1106#ifdef CONFIG_KEYCARD
1107 init->keycard()->displayKey();
1108#endif
1109}
1110
1111void PwM::makeCardBackup_slot()
1112{
1113#ifdef CONFIG_KEYCARD
1114 init->keycard()->makeBackupImage();
1115#endif
1116}
1117
1118void PwM::replayCardBackup_slot()
1119{
1120#ifdef CONFIG_KEYCARD
1121 init->keycard()->replayBackupImage();
1122#endif
1123}
1124
1125void PwM::execLauncher_slot()
1126{
1127 PWM_ASSERT(curDoc());
1128 if (curDoc()->isDeepLocked())
1129 return;
1130 unsigned int curEntryIndex;
1131 if (!view->getCurEntryIndex(&curEntryIndex))
1132 return;
1133 bool ret = curDoc()->execLauncher(view->getCurrentCategory(),
1134 curEntryIndex);
1135 if (ret)
1136 showStatMsg(i18n("Executed the \"Launcher\"."));
1137 else
1138 showStatMsg(i18n("ERROR: Couldn't execute the \"Launcher\"!"));
1139}
1140
1141void PwM::goToURL_slot()
1142{
1143 PWM_ASSERT(curDoc());
1144 if (curDoc()->isDeepLocked())
1145 return;
1146 unsigned int curEntryIndex;
1147 if (!view->getCurEntryIndex(&curEntryIndex))
1148 return;
1149 bool ret = curDoc()->goToURL(view->getCurrentCategory(),
1150 curEntryIndex);
1151 if (ret)
1152 showStatMsg(i18n("started browser with current URL."));
1153 else
1154 showStatMsg(i18n("ERROR: Couldn't start browser! Maybe invalid URL?"));
1155}
1156
1157void PwM::copyToClipboard(const QString &s)
1158{
1159 QClipboard *cb = QApplication::clipboard();
1160#ifndef PWM_EMBEDDED
1161 if (cb->supportsSelection())
1162 cb->setText(s, QClipboard::Selection);
1163 cb->setText(s, QClipboard::Clipboard);
1164#else
1165 cb->setText(s);
1166
1167#endif
1168
1169}
1170
1171void PwM::showStatMsg(const QString &msg)
1172{
1173#ifndef PWM_EMBEDDED
1174 KStatusBar *statBar = statusBar();
1175 statBar->message(msg, STATUSBAR_MSG_TIMEOUT * 1000);
1176#else
1177 qDebug("Statusbar : %s",msg.latin1());
1178#endif
1179}
1180
1181void PwM::focusInEvent(QFocusEvent *e)
1182{
1183 if (e->gotFocus()) {
1184 emit gotFocus(this);
1185 } else if (e->lostFocus()) {
1186 emit lostFocus(this);
1187 }
1188}
1189
1190#ifndef PWM_EMBEDDED
1191#include "pwm.moc"
1192#endif
diff --git a/pwmanager/pwmanager/pwm.h b/pwmanager/pwmanager/pwm.h
new file mode 100644
index 0000000..3a79e67
--- a/dev/null
+++ b/pwmanager/pwmanager/pwm.h
@@ -0,0 +1,255 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef __PWM_H
21#define __PWM_H
22
23
24#include <kpopupmenu.h>
25#include <klistview.h>
26#include <kmainwindow.h>
27
28#ifndef PWM_EMBEDDED
29#include <kwin.h>
30#include <kapp.h>
31#include <kdeversion.h>
32#else
33#endif
34
35#include <kaction.h>
36
37
38#include <qglobal.h>
39
40#include "pwmview.h"
41#include "pwmexception.h"
42
43
44/** timeout for displaying a message on the status-bar (in seconds) */
45 #define STATUSBAR_MSG_TIMEOUT5
46
47
48class PwMInit;
49
50/** PwM is the base class of the project */
51class PwM : public KMainWindow
52{
53 Q_OBJECT
54public:
55 friend class PwMView;
56 /** construtor */
57 PwM(PwMInit *_init, PwMDoc *doc,
58 bool virginity = true,
59 QWidget* parent = 0, const char *name = 0);
60 /** destructor */
61 ~PwM();
62
63 /** copy some text to the global clipboard */
64 static void copyToClipboard(const QString &s);
65
66 /** returns pointer to the view */
67 PwMView * curView()
68 { return view; }
69 /** returns pointer to the currently using document. */
70 PwMDoc * curDoc()
71 { return curView()->document(); }
72 /** open a new doc with the given filename */
73 PwMDoc * openDoc(QString filename, bool openDeepLocked = false);
74 /** show a message on the global status bar.
75 * The message times out after some seconds.
76 */
77 void showStatMsg(const QString &msg);
78 /** ask the user where to save the doc (if it has not been saved, yet)
79 * and write the data to disk.
80 */
81 bool save();
82 /** ask the user where to save the doc
83 * and write the data to disk.
84 */
85 bool saveAs();
86 /** force quit. Quit this window, always! Don't minimize it */
87 bool isForceQuit()
88 { return forceQuit; }
89 /** set forceQuit */
90 void setForceQuit(bool force)
91 { forceQuit = force; }
92 /** force minimize this window */
93 bool isForceMinimizeToTray()
94 { return forceMinimizeToTray; }
95 /** set forceMinimizeToTray */
96 void setForceMinimizeToTray(bool force)
97 { forceMinimizeToTray = force; }
98
99public slots:
100 /** file/new triggered */
101 void new_slot();
102 /** file/open triggered */
103//US ENH
104 void open_slot();
105 void open_slot(QString fn);
106 /** file/close triggered */
107 void close_slot();
108 /** file/quit triggered */
109 void quitButton_slot();
110 /** file/save triggered */
111 void save_slot();
112 /** file/saveAs triggered */
113 void saveAs_slot();
114 /** file/export/text triggered */
115 void exportToText();
116 /** file/export/gpasman triggered */
117 void exportToGpasman();
118 /** file/export/kwallet triggered */
119 void exportToKWallet();
120 /** file/import/text triggered */
121 bool importFromText();
122 /** file/import/gpasman triggered */
123 bool importFromGpasman();
124 /** file/import/kwallet triggered */
125 bool importKWallet();
126 /** file/print triggered */
127 void print_slot();
128 /** manage/add triggered */
129 //US ENH : changed code to run with older MOC
130 void addPwd_slot();
131 void addPwd_slot(QString *pw, PwMDoc *_doc);
132 /** manage/edit triggered */
133 //US ENH : changed code to run with older MOC
134 void editPwd_slot();
135 void editPwd_slot(const QString *category);
136 void editPwd_slot(const QString *category = 0, const int *index = 0,
137 PwMDoc *_doc = 0);
138 /** manage/delete triggered */
139 void deletePwd_slot();
140 /** execute the "Launcher" entry */
141 void execLauncher_slot();
142 /** open browser with URL entry */
143 void goToURL_slot();
144 /** manage/changeMasterPwd triggered */
145 void changeMasterPwd_slot();
146 /** lock current document */
147 void lockWnd_slot();
148 /** deeplock current document */
149 void deepLockWnd_slot();
150 /** window/unlock triggered */
151 void unlockWnd_slot();
152 /** find item */
153 void find_slot();
154 /** configure clicked */
155 void config_slot();
156 /** (de)activate the "change master pw" button in the menu-bar */
157 void activateMpButton(bool activate = true);
158 /** generate a new chipcard */
159 void genNewCard_slot();
160 /** completely erase the current card */
161 void eraseCard_slot();
162 /** returns the ID number of the current card */
163 void readCardId_slot();
164 /** make backup image of the current card */
165 void makeCardBackup_slot();
166 /** write backup image to current card */
167 void replayCardBackup_slot();
168
169protected:
170 /** is this window virgin? */
171 bool isVirgin()
172 { return virgin; }
173 /** add/remove virginity */
174 void setVirgin(bool v);
175 /** initialize the menubar */
176 void initMenubar();
177 /** initialize the toolbar */
178 void initToolbar();
179 /** initialize the window-metrics */
180 void initMetrics();
181 /** close-event */
182 void closeEvent(QCloseEvent *e);
183 /** creates a new PwM-ListView and returns it */
184 PwMView * makeNewListView(PwMDoc *doc);
185 /** Window hide-event */
186 void hideEvent(QHideEvent *);
187 /** is this window minimized? */
188 bool isMinimized()
189 {
190#ifndef PWM_EMBEDDED
191 #if KDE_VERSION >= KDE_MAKE_VERSION(3, 2, 0)
192 return KWin::windowInfo(winId()).isMinimized();
193 #else // KDE_VERSION
194 return KWin::info(winId()).isIconified();
195 #endif // KDE_VERSION
196#else
197 return false;
198#endif
199 }
200 /** window got the focus */
201 void focusInEvent(QFocusEvent *e);
202 /** update the caption string */
203 void updateCaption();
204#ifdef CONFIG_KWALLETIF
205 /** check if kwalletemu is enabled and ask the user what to do */
206 bool checkAndAskForKWalletEmu();
207#endif // CONFIG_KWALLETIF
208
209protected slots:
210 /** doc got closed */
211 void docClosed(PwMDoc *doc);
212
213signals:
214 /** window got closed (by user or someone else) */
215 void closed(PwM *wnd);
216 /** window got the focus (was brought to foreground) */
217 void gotFocus(PwM *wnd);
218 /** window lost the focus */
219 void lostFocus(PwM *wnd);
220
221protected:
222 /** pointer to the view active in this KMainWindow */
223 PwMView *view;
224 /** pointer to the init class */
225 PwMInit *init;
226 /** has this window already lost its virginity?
227 * Means is there an open working document
228 */
229 bool virgin;
230 /** "file" popup-menu */
231 KPopupMenu *filePopup;
232
233 /** "manage" popup-menu */
234 KPopupMenu *managePopup;
235#ifdef CONFIG_KEYCARD
236 /** "chipcard" popup-menu */
237 KPopupMenu *chipcardPopup;
238#endif // CONFIG_KEYCARD
239 /** "view" popup-menu */
240 KPopupMenu *viewPopup;
241 /** "options" popup-menu */
242 KPopupMenu *optionsPopup;
243 /** "help" popup-menu */
244 KPopupMenu *helpPopup;
245 /** "export" popup-menu */
246 KPopupMenu *exportPopup;
247 /** "import" popup-menu */
248 KPopupMenu *importPopup;
249 /** force quit this window? */
250 bool forceQuit;
251 /** force minimize this window to the tray */
252 bool forceMinimizeToTray;
253};
254
255#endif
diff --git a/pwmanager/pwmanager/pwmanagerE.pro b/pwmanager/pwmanager/pwmanagerE.pro
new file mode 100644
index 0000000..3fa91ba
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmanagerE.pro
@@ -0,0 +1,143 @@
1 TEMPLATE= app
2 CONFIG += qt warn_on
3
4
5 TARGET = pwmpi
6OBJECTS_DIR = obj/$(PLATFORM)
7MOC_DIR = moc/$(PLATFORM)
8DESTDIR=$(QPEDIR)/bin
9
10INCLUDEPATH += . ../../qtcompat ../../qtcompat/xml ../../microkde ../../microkde/kdecore ../../microkde/kdeui $(QPEDIR)/include
11DEFINES += PWM_EMBEDDED PWM_DEBUG
12LIBS += -lmicrokde
13LIBS += -lmicroqtcompat
14LIBS += -L$(QPEDIR)/lib
15LIBS += -lqpe
16LIBS += -lbz2
17
18#INTERFACES = \
19#addentrywnd.ui \
20#configwnd.ui \
21#findwnd.ui \
22#getmasterpwwnd.ui \
23#pwgenwnd.ui \
24#setmasterpwwnd.ui \
25#subtbledit.ui
26
27#INTERFACES = \
28#subtbledit.ui \
29
30
31
32#HEADERS = \
33#selftest.h
34
35HEADERS = \
36addentrywnd.h \
37addentrywndimpl.h \
38base64.h \
39binentrygen.h \
40blowfish.h \
41commentbox.h \
42compiler.h \
43compressbzip2.h \
44compressgzip.h \
45configuration_31compat.h \
46configuration.h \
47configwnd.h \
48configwndimpl.h \
49findwnd.h \
50findwndimpl.h \
51genpasswd.h \
52getkeycardwnd.h \
53getmasterpwwnd.h \
54getmasterpwwndimpl.h \
55globalstuff.h \
56gpasmanfile.h \
57htmlgen.h \
58htmlparse.h \
59ipc.h \
60listobjselectwnd.h \
61listviewpwm.h \
62printtext.h \
63pwgenwnd.h \
64pwgenwndimpl.h \
65pwmdoc.h \
66pwmdocui.h \
67pwmexception.h \
68pwm.h \
69pwminit.h \
70pwmprint.h \
71pwmtray.h \
72pwmview.h \
73pwmviewstyle_0.h \
74pwmviewstyle_1.h \
75pwmviewstyle.h \
76randomizer.h \
77rc2.h \
78rencatwnd.h \
79serializer.h \
80setmasterpwwnd.h \
81setmasterpwwndimpl.h \
82sha1.h \
83subtbledit.h \
84subtbleditimpl.h \
85waitwnd.h
86
87#SOURCES = \
88#advcommeditimpl.cpp \
89#configuration_31compat.cpp \
90#htmlparse.cpp \
91#printtext.cpp \
92#selftest.cpp \
93#pwmprint.cpp \
94#spinforsignal.cpp
95
96SOURCES = \
97addentrywnd.cpp \
98addentrywndimpl.cpp \
99base64.cpp \
100binentrygen.cpp \
101blowfish.cpp \
102commentbox.cpp \
103compressbzip2.cpp \
104compressgzip.cpp \
105configuration.cpp \
106configwnd.cpp \
107configwndimpl.cpp \
108findwnd.cpp \
109findwndimpl.cpp \
110genpasswd.cpp \
111getkeycardwnd.cpp \
112getmasterpwwnd.cpp \
113getmasterpwwndimpl.cpp \
114globalstuff.cpp \
115gpasmanfile.cpp \
116htmlgen.cpp \
117ipc.cpp \
118listobjselectwnd.cpp \
119listviewpwm.cpp \
120main.cpp \
121pwgenwnd.cpp \
122pwgenwndimpl.cpp \
123pwm.cpp \
124pwmdoc.cpp \
125pwmdocui.cpp \
126pwmexception.cpp \
127pwminit.cpp \
128pwmtray.cpp \
129pwmview.cpp \
130pwmviewstyle_0.cpp \
131pwmviewstyle_1.cpp \
132pwmviewstyle.cpp \
133randomizer.cpp \
134rc2.cpp \
135rencatwnd.cpp \
136serializer.cpp \
137setmasterpwwnd.cpp \
138setmasterpwwndimpl.cpp \
139sha1.cpp \
140subtbledit.cpp \
141subtbleditimpl.cpp \
142waitwnd.cpp \
143
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
new file mode 100644
index 0000000..04af360
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -0,0 +1,2775 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 2.0 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "pwmdoc.h"
21#include "pwmview.h"
22#include "blowfish.h"
23#include "sha1.h"
24#include "globalstuff.h"
25#include "gpasmanfile.h"
26#include "serializer.h"
27#include "compressgzip.h"
28#include "compressbzip2.h"
29#include "randomizer.h"
30#include "pwminit.h"
31#ifndef PWM_EMBEDDED
32//US #include "libgryptif.h"
33#else
34#endif
35
36#ifdef CONFIG_KWALLETIF
37# include "kwalletemu.h"
38#endif // CONFIG_KWALLETIF
39
40#include <qdatetime.h>
41#include <qsize.h>
42#include <qfileinfo.h>
43#include <qfile.h>
44
45#include <stdio.h>
46#include <stdlib.h>
47#include <errno.h>
48#include <string.h>
49#include <iostream>
50#include <algorithm>
51#include <sys/types.h>
52#include <sys/stat.h>
53#include <unistd.h>
54#include <stdint.h>
55
56//TODO: reset to its normal value.
57 #define META_CHECK_TIMER_INTERVAL10/*300*/ /* sek */
58
59using namespace std;
60
61
62void PwMDocList::add(PwMDoc *doc, const string &id)
63{
64#ifdef PWM_DEBUG
65 // check for existance of object in debug mode only.
66 vector<listItem>::iterator begin = docList.begin(),
67 end = docList.end(),
68 i = begin;
69 while (i != end) {
70 if (i->doc == doc) {
71 BUG();
72 return;
73 }
74 ++i;
75 }
76#endif
77 listItem newItem;
78 newItem.doc = doc;
79 newItem.docId = id;
80 docList.push_back(newItem);
81}
82
83void PwMDocList::edit(PwMDoc *doc, const string &newId)
84{
85 vector<listItem>::iterator begin = docList.begin(),
86 end = docList.end(),
87 i = begin;
88 while (i != end) {
89 if (i->doc == doc) {
90 i->docId = newId;
91 return;
92 }
93 ++i;
94 }
95}
96
97void PwMDocList::del(PwMDoc *doc)
98{
99 vector<listItem>::iterator begin = docList.begin(),
100 end = docList.end(),
101 i = begin;
102 while (i != end) {
103 if (i->doc == doc) {
104 docList.erase(i);
105 return;
106 }
107 ++i;
108 }
109}
110
111bool PwMDocList::find(const string &id, listItem *ret)
112{
113 vector<listItem>::iterator begin = docList.begin(),
114 end = docList.end(),
115 i = begin;
116 while (i != end) {
117 if (i->docId == id) {
118 if (ret)
119 *ret = *i;
120 return true;
121 }
122 ++i;
123 }
124 return false;
125}
126
127
128
129DocTimer::DocTimer(PwMDoc *_doc)
130 : doc (_doc)
131 , mpwLock (0)
132 , autoLockLock (0)
133 , metaCheckLock (0)
134{
135 mpwTimer = new QTimer;
136 autoLockTimer = new QTimer;
137 metaCheckTimer = new QTimer;
138 connect(mpwTimer, SIGNAL(timeout()),
139 this, SLOT(mpwTimeout()));
140 connect(autoLockTimer, SIGNAL(timeout()),
141 this, SLOT(autoLockTimeout()));
142 connect(metaCheckTimer, SIGNAL(timeout()),
143 this, SLOT(metaCheckTimeout()));
144}
145
146DocTimer::~DocTimer()
147{
148 delete mpwTimer;
149 delete autoLockTimer;
150 delete metaCheckTimer;
151}
152
153void DocTimer::start(TimerIDs timer)
154{
155 switch (timer) {
156 case id_mpwTimer:
157 if (mpwTimer->isActive())
158 mpwTimer->stop();
159 doc->setDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW);
160 mpwTimer->start(conf()->confGlobPwTimeout() * 1000, true);
161 break;
162 case id_autoLockTimer:
163 if (autoLockTimer->isActive())
164 autoLockTimer->stop();
165 if (conf()->confGlobLockTimeout() > 0)
166 autoLockTimer->start(conf()->confGlobLockTimeout() * 1000, true);
167 break;
168 case id_metaCheckTimer:
169 if (metaCheckTimer->isActive())
170 metaCheckTimer->stop();
171 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
172 break;
173 }
174}
175
176void DocTimer::stop(TimerIDs timer)
177{
178 switch (timer) {
179 case id_mpwTimer:
180 mpwTimer->stop();
181 break;
182 case id_autoLockTimer:
183 autoLockTimer->stop();
184 break;
185 case id_metaCheckTimer:
186 metaCheckTimer->stop();
187 break;
188 }
189}
190
191void DocTimer::getLock(TimerIDs timer)
192{
193 switch (timer) {
194 case id_mpwTimer:
195 ++mpwLock;
196 break;
197 case id_autoLockTimer:
198 ++autoLockLock;
199 break;
200 case id_metaCheckTimer:
201 ++metaCheckLock;
202 break;
203 }
204}
205
206void DocTimer::putLock(TimerIDs timer)
207{
208 switch (timer) {
209 case id_mpwTimer:
210 if (mpwLock)
211 --mpwLock;
212 break;
213 case id_autoLockTimer:
214 if (autoLockLock)
215 --autoLockLock;
216 break;
217 case id_metaCheckTimer:
218 if (metaCheckLock)
219 --metaCheckLock;
220 break;
221 }
222}
223
224void DocTimer::mpwTimeout()
225{
226 if (mpwLock) {
227 mpwTimer->start(1000, true);
228 return;
229 }
230 doc->unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW);
231}
232
233void DocTimer::autoLockTimeout()
234{
235 if (autoLockLock) {
236 autoLockTimer->start(1000, true);
237 return;
238 }
239 if (conf()->confGlobAutoDeepLock() &&
240 doc->filename != QString::null &&
241 doc->filename != "") {
242 doc->deepLock(true);
243 } else {
244 doc->lockAll(true);
245 }
246}
247
248void DocTimer::metaCheckTimeout()
249{
250 if (metaCheckLock) {
251 // check again in one second.
252 metaCheckTimer->start(1000, true);
253 return;
254 }
255 if (doc->isDeepLocked()) {
256 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
257 return;
258 }
259 if (doc->isDocEmpty()) {
260 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
261 return;
262 }
263#ifdef CONFIG_KWALLETIF
264 KWalletEmu *kwlEmu = doc->init->kwalletEmu();
265 if (kwlEmu)
266 kwlEmu->suspendDocSignals();
267#endif // CONFIG_KWALLETIF
268 /* We simply trigger all views to update their
269 * displayed values. This way they have a chance
270 * to get notified when some meta changes over time.
271 * (for example an entry expired).
272 * The _view_ is responsive for not updating its
273 * contents if nothing really changed!
274 */
275 emit doc->dataChanged(doc);
276#ifdef CONFIG_KWALLETIF
277 if (kwlEmu)
278 kwlEmu->resumeDocSignals();
279#endif // CONFIG_KWALLETIF
280 metaCheckTimer->start(META_CHECK_TIMER_INTERVAL * 1000, true);
281}
282
283
284
285PwMDocList PwMDoc::openDocList;
286unsigned int PwMDocList::unnamedDocCnt = 1;
287
288PwMDoc::PwMDoc(QObject *parent, const char *name)
289 : PwMDocUi(parent, name)
290 , dataChangedLock (0)
291{
292 deleted = false;
293 unnamedNum = 0;
294 getOpenDocList()->add(this, getTitle().latin1());
295 curDocStat = 0;
296 setMaxNumEntries();
297 _timer = new DocTimer(this);
298 timer()->start(DocTimer::id_mpwTimer);
299 timer()->start(DocTimer::id_autoLockTimer);
300 timer()->start(DocTimer::id_metaCheckTimer);
301 addCategory(DEFAULT_CATEGORY, 0, false);
302 listView = 0;
303 emit docCreated(this);
304}
305
306PwMDoc::~PwMDoc()
307{
308 emit docClosed(this);
309 getOpenDocList()->del(this);
310 delete _timer;
311}
312
313PwMerror PwMDoc::saveDoc(char compress, const QString *file)
314{
315 PwMerror ret, e;
316 if (!file) {
317 if (filename == "")
318 return e_filename;
319 } else {
320 if (*file == "" && filename == "")
321 return e_filename;
322 if (*file != "")
323 filename = *file;
324 }
325
326 bool wasDeepLocked = isDeepLocked();
327 if (wasDeepLocked) {
328 if (deepLock(false) != e_success)
329 return e_noPw;
330 }
331
332 if (!isPwAvailable()) {
333 /* password is not available. This means, the
334 * document wasn't saved, yet.
335 */
336 bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD);
337 QString pw(requestNewMpw(&useChipcard));
338 if (pw != "") {
339 currentPw = pw;
340 } else {
341 return e_noPw;
342 }
343 if (useChipcard) {
344 setDocStatFlag(DOC_STAT_USE_CHIPCARD);
345 } else {
346 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD);
347 }
348 }
349#ifndef PWM_EMBEDDED
350 int _cryptAlgo = conf()->confGlobCryptAlgo();
351 int _hashAlgo = conf()->confGlobHashAlgo();
352#else
353 int _cryptAlgo = PWM_CRYPT_BLOWFISH;
354 int _hashAlgo = PWM_HASH_SHA1;
355#endif
356
357 // sanity check for the selected algorithms
358 if (_cryptAlgo < PWM_CRYPT_BLOWFISH ||
359 _cryptAlgo > PWM_CRYPT_TWOFISH128) {
360 printWarn("Invalid Crypto-Algorithm selected! "
361 "Config-file seems to be corrupt. "
362 "Falling back to Blowfish.");
363 _cryptAlgo = PWM_CRYPT_BLOWFISH;
364 }
365 if (_hashAlgo < PWM_HASH_SHA1 ||
366 _hashAlgo > PWM_HASH_TIGER) {
367 printWarn("Invalid Hash-Algorithm selected! "
368 "Config-file seems to be corrupt. "
369 "Falling back to SHA1.");
370 _hashAlgo = PWM_HASH_SHA1;
371 }
372 char cryptAlgo = static_cast<char>(_cryptAlgo);
373 char hashAlgo = static_cast<char>(_hashAlgo);
374
375 if (conf()->confGlobMakeFileBackup()) {
376 if (!backupFile(filename))
377 return e_fileBackup;
378 }
379 QString tmpFileMoved(QString::null);
380 if (QFile::exists(filename)) {
381 /* Move the existing file to some tmp file.
382 * When saving file succeeds, delete tmp file. Otherwise
383 * move tmp file back. See below.
384 */
385 Randomizer *rnd = Randomizer::obj();
386 char rnd_buf[5];
387 sprintf(rnd_buf, "%X%X%X%X", rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF,
388 rnd->genRndChar() & 0xFF, rnd->genRndChar() & 0xFF);
389 tmpFileMoved = filename + "." + rnd_buf + ".mv";
390 if (!copyFile(filename, tmpFileMoved))
391 return e_openFile;
392 if (!QFile::remove(filename)) {
393 printWarn(string("removing orig file ")
394 + filename.latin1()
395 + " failed!");
396 }
397 }
398 QFile f(filename);
399 string serialized;
400 if (!f.open(IO_ReadWrite)) {
401 ret = e_openFile;
402 goto out_moveback;
403 }
404 e = writeFileHeader(hashAlgo, hashAlgo,
405 cryptAlgo, compress,
406 &currentPw, &f);
407 if (e == e_hashNotImpl) {
408 printDebug("PwMDoc::saveDoc(): writeFileHeader() failed: e_hashNotImpl");
409 f.close();
410 ret = e_hashNotImpl;
411 goto out_moveback;
412 } else if (e != e_success) {
413 printDebug("PwMDoc::saveDoc(): writeFileHeader() failed");
414 f.close();
415 ret = e_writeHeader;
416 goto out_moveback;
417 }
418 if (!serializeDta(&serialized)) {
419 printDebug("PwMDoc::saveDoc(): serializeDta() failed");
420 f.close();
421 ret = e_serializeDta;
422 goto out_moveback;
423 }
424 e = writeDataHash(hashAlgo, &serialized, &f);
425 if (e == e_hashNotImpl) {
426 printDebug("PwMDoc::saveDoc(): writeDataHash() failed: e_hashNotImpl");
427 f.close();
428 ret = e_hashNotImpl;
429 goto out_moveback;
430 } else if (e != e_success) {
431 printDebug("PwMDoc::saveDoc(): writeDataHash() failed");
432 f.close();
433 ret = e_writeHeader;
434 goto out_moveback;
435 }
436 if (!compressDta(&serialized, compress)) {
437 printDebug("PwMDoc::saveDoc(): compressDta() failed");
438 f.close();
439 ret = e_enc;
440 goto out_moveback;
441 }
442 e = encrypt(&serialized, &currentPw, &f, cryptAlgo);
443 if (e == e_weakPw) {
444 printDebug("PwMDoc::saveDoc(): encrypt() failed: e_weakPw");
445 f.close();
446 ret = e_weakPw;
447 goto out_moveback;
448 } else if (e == e_cryptNotImpl) {
449 printDebug("PwMDoc::saveDoc(): encrypt() failed: e_cryptNotImpl");
450 f.close();
451 ret = e_cryptNotImpl;
452 goto out_moveback;
453 } else if (e != e_success) {
454 printDebug("PwMDoc::saveDoc(): encrypt() failed");
455 f.close();
456 ret = e_enc;
457 goto out_moveback;
458 }
459 unsetDocStatFlag(DOC_STAT_DISK_DIRTY);
460 f.close();
461 if (chmod(filename.latin1(),
462 conf()->confGlobFilePermissions())) {
463 printWarn(string("chmod failed: ") + strerror(errno));
464 }
465 openDocList.edit(this, getTitle().latin1());
466 if (wasDeepLocked)
467 deepLock(true);
468 if (tmpFileMoved != QString::null) {
469 // now remove the moved file.
470 if (!QFile::remove(tmpFileMoved)) {
471 printWarn(string("removing file ")
472 + tmpFileMoved.latin1()
473 + " failed!");
474 }
475 }
476 ret = e_success;
477 printDebug(string("writing file { compress: ")
478 + tostr(static_cast<int>(compress)) + " cryptAlgo: "
479 + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: "
480 + tostr(static_cast<int>(hashAlgo))
481 + " }");
482 goto out;
483out_moveback:
484 if (tmpFileMoved != QString::null) {
485 if (copyFile(tmpFileMoved, filename)) {
486 if (!QFile::remove(tmpFileMoved)) {
487 printWarn(string("removing tmp file ")
488 + filename.latin1()
489 + " failed!");
490 }
491 } else {
492 printWarn(string("couldn't copy file ")
493 + tmpFileMoved.latin1()
494 + " back to "
495 + filename.latin1());
496 }
497 }
498out:
499 return ret;
500}
501
502PwMerror PwMDoc::openDoc(const QString *file, int openLocked)
503{
504 PWM_ASSERT(file);
505 PWM_ASSERT(openLocked == 0 || openLocked == 1 || openLocked == 2);
506 string decrypted, dataHash;
507 PwMerror ret;
508 char cryptAlgo, dataHashType, compress;
509 unsigned int headerLen;
510
511 if (*file == "")
512 return e_readFile;
513 filename = *file;
514 /* check if this file is already open.
515 * This does not catch symlinks!
516 */
517 if (!isDeepLocked()) {
518 if (getOpenDocList()->find(filename.latin1()))
519 return e_alreadyOpen;
520 }
521 QFile f(filename);
522
523 if (openLocked == 2) {
524 // open deep-locked
525 if (!QFile::exists(filename))
526 return e_openFile;
527 if (deepLock(true, false) != e_success)
528 return e_openFile;
529 goto out_success;
530 }
531
532 if (!f.open(IO_ReadOnly))
533 return e_openFile;
534
535 ret = checkHeader(&cryptAlgo, &currentPw, &compress, &headerLen,
536 &dataHashType, &dataHash, &f);
537 if (ret != e_success) {
538 printDebug("PwMDoc::openDoc(): checkHeader() failed");
539 f.close();
540 if (ret == e_wrongPw) {
541 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
542 return ret;
543 } else if (ret == e_noPw ||
544 ret == e_fileVer ||
545 ret == e_fileFormat ||
546 ret == e_hashNotImpl) {
547 return ret;
548 } else
549 return e_readFile;
550 }
551 ret = decrypt(&decrypted, headerLen, &currentPw, cryptAlgo, &f);
552 if (ret == e_cryptNotImpl) {
553 printDebug("PwMDoc::openDoc(): decrypt() failed: e_cryptNotImpl");
554 f.close();
555 return e_cryptNotImpl;
556 } else if (ret != e_success) {
557 printDebug("PwMDoc::openDoc(): decrypt() failed");
558 f.close();
559 return e_readFile;
560 }
561 if (!decompressDta(&decrypted, compress)) {
562 printDebug("PwMDoc::openDoc(): decompressDta() failed");
563 f.close();
564 return e_fileCorrupt;
565 }
566 ret = checkDataHash(dataHashType, &dataHash, &decrypted);
567 if (ret == e_hashNotImpl) {
568 printDebug("PwMDoc::openDoc(): checkDataHash() failed: e_hashNotImpl");
569 f.close();
570 return e_hashNotImpl;
571 } else if (ret != e_success) {
572 printDebug("PwMDoc::openDoc(): checkDataHash() failed");
573 f.close();
574 return e_fileCorrupt;
575 }
576 if (!deSerializeDta(&decrypted, openLocked == 1)) {
577 printDebug("PwMDoc::openDoc(): deSerializeDta() failed");
578 f.close();
579 return e_readFile;
580 }
581 f.close();
582 timer()->start(DocTimer::id_mpwTimer);
583 timer()->start(DocTimer::id_autoLockTimer);
584out_success:
585 openDocList.edit(this, getTitle().latin1());
586 emit docOpened(this);
587 return e_success;
588}
589
590PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress,
591 QString *pw, QFile *f)
592{
593 PWM_ASSERT(pw);
594 PWM_ASSERT(f);
595 PWM_ASSERT(listView);
596#ifndef PWM_EMBEDDED
597 if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) !=
598 static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) {
599 return e_writeFile;
600 }
601 if (f->putch(PWM_FILE_VER) == -1 ||
602 f->putch(keyHash) == -1 ||
603 f->putch(dataHash) == -1 ||
604 f->putch(crypt) == -1 ||
605 f->putch(compress) == -1 ||
606 f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ?
607 (static_cast<char>(0x01)) : (static_cast<char>(0x00))) == -1) {
608 return e_writeFile;
609 }
610
611#else
612 if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) !=
613 (long)(strlen(FILE_ID_HEADER))) {
614 return e_writeFile;
615 }
616 if (f->putch(PWM_FILE_VER) == -1 ||
617 f->putch(keyHash) == -1 ||
618 f->putch(dataHash) == -1 ||
619 f->putch(crypt) == -1 ||
620 f->putch(compress) == -1 ||
621 f->putch((getDocStatFlag(DOC_STAT_USE_CHIPCARD)) ?
622 ((char)(0x01)) : ((char)(0x00))) == -1) {
623 return e_writeFile;
624 }
625#endif
626 // write bytes of NUL-data. These bytes are reserved for future-use.
627 const int bufSize = 64;
628 char tmp_buf[bufSize];
629 memset(tmp_buf, 0x00, bufSize);
630 if (f->writeBlock(tmp_buf, bufSize) != bufSize)
631 return e_writeFile;
632
633 switch (keyHash) {
634 case PWM_HASH_SHA1: {
635 const int hashlen = SHA1_HASH_LEN_BYTE;
636 Sha1 hash;
637 hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length());
638 string ret = hash.sha1_read();
639 if (f->writeBlock(ret.c_str(), hashlen) != hashlen)
640 return e_writeFile;
641 break;
642 }
643#ifndef PWM_EMBEDDED
644 case PWM_HASH_SHA256:
645 /*... fall through */
646 case PWM_HASH_SHA384:
647 case PWM_HASH_SHA512:
648 case PWM_HASH_MD5:
649 case PWM_HASH_RMD160:
650 case PWM_HASH_TIGER:
651 {
652 if (!LibGCryptIf::available())
653 return e_hashNotImpl;
654 LibGCryptIf gc;
655 PwMerror err;
656 unsigned char *buf;
657 size_t hashLen;
658 err = gc.hash(&buf,
659 &hashLen,
660 reinterpret_cast<const unsigned char *>(pw->latin1()),
661 pw->length(),
662 keyHash);
663 if (err != e_success)
664 return e_hashNotImpl;
665 if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen)
666 != static_cast<Q_LONG>(hashLen)) {
667 delete [] buf;
668 return e_hashNotImpl;
669 }
670 delete [] buf;
671 break;
672 }
673#endif
674 default: {
675 return e_hashNotImpl;
676 } }
677 return e_success;
678}
679
680PwMerror PwMDoc::checkHeader(char *cryptAlgo, QString *pw, char *compress,
681 unsigned int *headerLength, char *dataHashType,
682 string *dataHash, QFile *f)
683{
684 PWM_ASSERT(cryptAlgo);
685 PWM_ASSERT(pw);
686 PWM_ASSERT(headerLength);
687 PWM_ASSERT(dataHashType);
688 PWM_ASSERT(dataHash);
689 PWM_ASSERT(f);
690 int tmpRet;
691 // check "magic" header
692 const char magicHdr[] = FILE_ID_HEADER;
693 const int hdrLen = array_size(magicHdr) - 1;
694 char tmp[hdrLen];
695 if (f->readBlock(tmp, hdrLen) != hdrLen)
696 return e_readFile;
697 if (memcmp(tmp, magicHdr, hdrLen) != 0)
698 return e_fileFormat;
699 // read and check file ver
700 int fileV = f->getch();
701 if (fileV == -1)
702 return e_fileFormat;
703 if (fileV != PWM_FILE_VER)
704 return e_fileVer;
705 // read hash hash type
706 int keyHash = f->getch();
707 if (keyHash == -1)
708 return e_fileFormat;
709 // read data hash type
710 tmpRet = f->getch();
711 if (tmpRet == -1)
712 return e_fileFormat;
713 *dataHashType = tmpRet;
714 // read crypt algo
715 tmpRet = f->getch();
716 if (tmpRet == -1)
717 return e_fileFormat;
718 *cryptAlgo = tmpRet;
719 // get compression-algo
720 tmpRet = f->getch();
721 if (tmpRet == -1)
722 return e_fileFormat;
723 *compress = tmpRet;
724 // get the MPW-flag
725 int mpw_flag = f->getch();
726 if (mpw_flag == -1)
727 return e_fileFormat;
728 if (mpw_flag == 0x01)
729 setDocStatFlag(DOC_STAT_USE_CHIPCARD);
730 else
731 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD);
732 // skip the "RESERVED"-bytes
733 if (!(f->at(f->at() + 64)))
734 return e_fileFormat;
735
736 *pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
737 if (*pw == "") {
738 /* the user didn't give a master-password
739 * or didn't insert a chipcard
740 */
741 return e_noPw;
742 }
743 // verify key-hash
744 switch (keyHash) {
745 case PWM_HASH_SHA1: {
746 // read hash from header
747 const int hashLen = SHA1_HASH_LEN_BYTE;
748 string readHash;
749 int i;
750 for (i = 0; i < hashLen; ++i)
751 readHash.push_back(f->getch());
752 Sha1 hash;
753 hash.sha1_write(reinterpret_cast<const byte *>(pw->latin1()), pw->length());
754 string ret = hash.sha1_read();
755 if (ret != readHash)
756 return e_wrongPw;// hash doesn't match (wrong key)
757 break;
758 }
759#ifndef PWM_EMBEDDED
760 case PWM_HASH_SHA256:
761 /*... fall through */
762 case PWM_HASH_SHA384:
763 case PWM_HASH_SHA512:
764 case PWM_HASH_MD5:
765 case PWM_HASH_RMD160:
766 case PWM_HASH_TIGER: {
767 if (!LibGCryptIf::available())
768 return e_hashNotImpl;
769 LibGCryptIf gc;
770 PwMerror err;
771 unsigned char *buf;
772 size_t hashLen;
773 err = gc.hash(&buf,
774 &hashLen,
775 reinterpret_cast<const unsigned char *>(pw->latin1()),
776 pw->length(),
777 keyHash);
778 if (err != e_success)
779 return e_hashNotImpl;
780 string calcHash(reinterpret_cast<const char *>(buf),
781 static_cast<string::size_type>(hashLen));
782 delete [] buf;
783 // read hash from header
784 string readHash;
785 size_t i;
786 for (i = 0; i < hashLen; ++i)
787 readHash.push_back(f->getch());
788 if (calcHash != readHash)
789 return e_wrongPw;// hash doesn't match (wrong key)
790 break;
791 }
792#endif
793 default: {
794 return e_hashNotImpl;
795 } }
796 // read the data-hash from the file
797 unsigned int hashLen, i;
798 switch (*dataHashType) {
799 case PWM_HASH_SHA1:
800 hashLen = SHA1_HASH_LEN_BYTE;
801 break;
802#ifndef PWM_EMBEDDED
803 case PWM_HASH_SHA256:
804 /*... fall through */
805 case PWM_HASH_SHA384:
806 case PWM_HASH_SHA512:
807 case PWM_HASH_MD5:
808 case PWM_HASH_RMD160:
809 case PWM_HASH_TIGER: {
810 if (!LibGCryptIf::available())
811 return e_hashNotImpl;
812 LibGCryptIf gc;
813 hashLen = gc.hashLength(*dataHashType);
814 if (hashLen == 0)
815 return e_hashNotImpl;
816 break;
817 }
818#endif
819 default:
820 return e_hashNotImpl;
821 }
822 *dataHash = "";
823 for (i = 0; i < hashLen; ++i) {
824 tmpRet = f->getch();
825 if (tmpRet == -1)
826 return e_fileFormat;
827 dataHash->push_back(static_cast<char>(tmpRet));
828 }
829 *headerLength = f->at();
830#ifndef PWM_EMBEDDED
831 printDebug(string("opening file { compress: ")
832 + tostr(static_cast<int>(*compress)) + " cryptAlgo: "
833 + tostr(static_cast<int>(*cryptAlgo)) + " keyHashAlgo: "
834 + tostr(static_cast<int>(keyHash))
835 + " }");
836#else
837 printDebug(string("opening file { compress: ")
838 + tostr((int)(*compress)) + " cryptAlgo: "
839 + tostr((int)(*cryptAlgo)) + " keyHashAlgo: "
840 + tostr((int)(keyHash))
841 + " }");
842#endif
843
844 return e_success;
845}
846
847PwMerror PwMDoc::writeDataHash(char dataHash, string *d, QFile *f)
848{
849 PWM_ASSERT(d);
850 PWM_ASSERT(f);
851
852 switch (dataHash) {
853 case PWM_HASH_SHA1: {
854 const int hashLen = SHA1_HASH_LEN_BYTE;
855 Sha1 h;
856 h.sha1_write(reinterpret_cast<const byte *>(d->c_str()), d->size());
857 string hRet = h.sha1_read();
858 if (f->writeBlock(hRet.c_str(), hashLen) != hashLen)
859 return e_writeFile;
860 break;
861 }
862 #ifndef PWM_EMBEDDED
863 case PWM_HASH_SHA256:
864 /*... fall through */
865 case PWM_HASH_SHA384:
866 case PWM_HASH_SHA512:
867 case PWM_HASH_MD5:
868 case PWM_HASH_RMD160:
869 case PWM_HASH_TIGER: {
870 if (!LibGCryptIf::available())
871 return e_hashNotImpl;
872 LibGCryptIf gc;
873 PwMerror err;
874 unsigned char *buf;
875 size_t hashLen;
876 err = gc.hash(&buf,
877 &hashLen,
878 reinterpret_cast<const unsigned char *>(d->c_str()),
879 d->size(),
880 dataHash);
881 if (err != e_success)
882 return e_hashNotImpl;
883 if (f->writeBlock(reinterpret_cast<const char *>(buf), hashLen)
884 != static_cast<Q_LONG>(hashLen)) {
885 delete [] buf;
886 return e_hashNotImpl;
887 }
888 delete [] buf;
889 break;
890 }
891#endif
892 default: {
893 return e_hashNotImpl;
894 } }
895
896 return e_success;
897}
898
899bool PwMDoc::backupFile(const QString &filePath)
900{
901 QFileInfo fi(filePath);
902 if (!fi.exists())
903 return true; // Yes, true is correct.
904 QString pathOnly(fi.dirPath(true));
905 QString nameOnly(fi.fileName());
906 QString backupPath = pathOnly
907 + "/~"
908 + nameOnly
909 + ".backup";
910 return copyFile(filePath, backupPath);
911}
912
913bool PwMDoc::copyFile(const QString &src, const QString &dst)
914{
915 QFileInfo fi(src);
916 if (!fi.exists())
917 return false;
918 if (QFile::exists(dst)) {
919 if (!QFile::remove(dst))
920 return false;
921 }
922 QFile srcFd(src);
923 if (!srcFd.open(IO_ReadOnly))
924 return false;
925 QFile dstFd(dst);
926 if (!dstFd.open(IO_ReadWrite)) {
927 srcFd.close();
928 return false;
929 }
930 const int tmpBuf_size = 512;
931 char tmpBuf[tmpBuf_size];
932#ifndef PWM_EMBEDDED
933 Q_LONG bytesRead, bytesWritten;
934#else
935 long bytesRead, bytesWritten;
936#endif
937 while (!srcFd.atEnd()) {
938#ifndef PWM_EMBEDDED
939 bytesRead = srcFd.readBlock(tmpBuf,
940 static_cast<Q_ULONG>(tmpBuf_size));
941#else
942 bytesRead = srcFd.readBlock(tmpBuf,
943 (unsigned long)(tmpBuf_size));
944#endif
945 if (bytesRead == -1) {
946 srcFd.close();
947 dstFd.close();
948 return false;
949 }
950#ifndef PWM_EMBEDDED
951 bytesWritten = dstFd.writeBlock(tmpBuf,
952 static_cast<Q_ULONG>(bytesRead));
953#else
954 bytesWritten = dstFd.writeBlock(tmpBuf,
955 (unsigned long)(bytesRead));
956#endif
957 if (bytesWritten != bytesRead) {
958 srcFd.close();
959 dstFd.close();
960 return false;
961 }
962 }
963 srcFd.close();
964 dstFd.close();
965 return true;
966}
967
968PwMerror PwMDoc::addEntry(const QString &category, PwMDataItem *d,
969 bool dontFlagDirty, bool updateMeta)
970{
971 PWM_ASSERT(d);
972 unsigned int cat = 0;
973
974 if (isDeepLocked()) {
975 PwMerror ret;
976 ret = deepLock(false);
977 if (ret != e_success)
978 return e_lock;
979 }
980
981 addCategory(category, &cat);
982
983 if (numEntries(category) >= maxEntries)
984 return e_maxAllowedEntr;
985
986 vector<unsigned int> foundPositions;
987 /* historically this was:
988 *const int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME |
989 * SEARCH_IN_URL | SEARCH_IN_LAUNCHER;
990 * But for now we only search in desc.
991 * That's a tweak to be KWallet compatible. But it should not add
992 * usability-drop onto PwManager, does it?
993 * (And yes, "int" was a bug. Correct is "unsigned int")
994 */
995 const unsigned int searchIn = SEARCH_IN_DESC;
996 findEntry(cat, *d, searchIn, &foundPositions, true);
997 if (foundPositions.size()) {
998 // DOH! We found this entry.
999 return e_entryExists;
1000 }
1001
1002 d->listViewPos = -1;
1003 d->lockStat = conf()->confGlobNewEntrLockStat();
1004 if (updateMeta) {
1005 d->meta.create = QDateTime::currentDateTime();
1006 d->meta.update = d->meta.create;
1007 }
1008 dta[cat].d.push_back(*d);
1009
1010 delAllEmptyCat(true);
1011
1012 if (!dontFlagDirty)
1013 flagDirty();
1014 return e_success;
1015}
1016
1017PwMerror PwMDoc::addCategory(const QString &category, unsigned int *categoryIndex,
1018 bool checkIfExist)
1019{
1020 if (isDeepLocked()) {
1021 PwMerror ret;
1022 ret = deepLock(false);
1023 if (ret != e_success)
1024 return e_lock;
1025 }
1026 if (checkIfExist) {
1027 if (findCategory(category, categoryIndex))
1028 return e_categoryExists;
1029 }
1030 PwMCategoryItem item;
1031 item.name = category.latin1();
1032 dta.push_back(item);
1033 if (categoryIndex)
1034 *categoryIndex = dta.size() - 1;
1035 return e_success;
1036}
1037
1038bool PwMDoc::delEntry(const QString &category, unsigned int index, bool dontFlagDirty)
1039{
1040 unsigned int cat = 0;
1041
1042 if (!findCategory(category, &cat)) {
1043 BUG();
1044 return false;
1045 }
1046
1047 return delEntry(cat, index, dontFlagDirty);
1048}
1049
1050bool PwMDoc::delEntry(unsigned int category, unsigned int index, bool dontFlagDirty)
1051{
1052 if (isDeepLocked())
1053 return false;
1054 if (index > dta[category].d.size() - 1)
1055 return false;
1056 getDataChangedLock();
1057 if (!lockAt(category, index, false)) {
1058 putDataChangedLock();
1059 return false;
1060 }
1061 putDataChangedLock();
1062 int lvPos = dta[category].d[index].listViewPos;
1063
1064 // delete entry
1065 dta[category].d.erase(dta[category].d.begin() + index);
1066
1067 unsigned int i, entries = numEntries(category);
1068 if (!entries) {
1069 // no more entries in this category, so
1070 // we can delete it, too.
1071 BUG_ON(!delCategory(category));
1072 // delCategory() flags it dirty, so we need not to do so.
1073 return true;
1074 }
1075 for (i = 0; i < entries; ++i) {
1076 // decrement all listViewPositions that are greater than the deleted.
1077 if (dta[category].d[i].listViewPos > lvPos)
1078 --dta[category].d[i].listViewPos;
1079 }
1080
1081 if (!dontFlagDirty)
1082 flagDirty();
1083 return true;
1084}
1085
1086bool PwMDoc::editEntry(const QString &oldCategory, const QString &newCategory,
1087 unsigned int index, PwMDataItem *d, bool updateMeta)
1088{
1089 PWM_ASSERT(d);
1090 unsigned int oldCat = 0;
1091
1092 if (!findCategory(oldCategory, &oldCat)) {
1093 BUG();
1094 return false;
1095 }
1096
1097 return editEntry(oldCat, newCategory, index, d, updateMeta);
1098}
1099
1100bool PwMDoc::editEntry(unsigned int oldCategory, const QString &newCategory,
1101 unsigned int index, PwMDataItem *d, bool updateMeta)
1102{
1103 if (isDeepLocked())
1104 return false;
1105 if (updateMeta) {
1106 d->meta.update = QDateTime::currentDateTime();
1107 if (d->meta.create.isNull()) {
1108 d->meta.create = d->meta.update;
1109 }
1110 }
1111 if (dta[oldCategory].name != newCategory.latin1()) {
1112 // the user changed the category.
1113 PwMerror ret;
1114 d->rev = 0;
1115 ret = addEntry(newCategory, d, true, false);
1116 if (ret != e_success)
1117 return false;
1118 if (!delEntry(oldCategory, index, true))
1119 return false;
1120 } else {
1121 d->rev = dta[oldCategory].d[index].rev + 1; // increment revision counter.
1122 dta[oldCategory].d[index] = *d;
1123 }
1124 flagDirty();
1125 return true;
1126}
1127
1128unsigned int PwMDoc::numEntries(const QString &category)
1129{
1130 unsigned int cat = 0;
1131
1132 if (!findCategory(category, &cat)) {
1133 BUG();
1134 return 0;
1135 }
1136
1137 return numEntries(cat);
1138}
1139
1140bool PwMDoc::serializeDta(string *d)
1141{
1142 PWM_ASSERT(d);
1143 Serializer ser;
1144 if (!ser.serialize(dta))
1145 return false;
1146 d->assign(ser.getXml());
1147 if (!d->size())
1148 return false;
1149 return true;
1150}
1151
1152bool PwMDoc::deSerializeDta(const string *d, bool entriesLocked)
1153{
1154 PWM_ASSERT(d);
1155 try {
1156 Serializer ser(d->c_str());
1157 ser.setDefaultLockStat(entriesLocked);
1158 if (!ser.deSerialize(&dta))
1159 return false;
1160 } catch (PwMException) {
1161 return false;
1162 }
1163 emitDataChanged(this);
1164 return true;
1165}
1166
1167bool PwMDoc::getEntry(const QString &category, unsigned int index,
1168 PwMDataItem * d, bool unlockIfLocked)
1169{
1170 PWM_ASSERT(d);
1171 unsigned int cat = 0;
1172
1173 if (!findCategory(category, &cat)) {
1174 BUG();
1175 return false;
1176 }
1177
1178 return getEntry(cat, index, d, unlockIfLocked);
1179}
1180
1181bool PwMDoc::getEntry(unsigned int category, unsigned int index,
1182 PwMDataItem *d, bool unlockIfLocked)
1183{
1184 if (index > dta[category].d.size() - 1)
1185 return false;
1186
1187 bool locked = isLocked(category, index);
1188 if (locked) {
1189 /* this entry is locked. We don't return a password,
1190 * until it's unlocked by the user by inserting
1191 * chipcard or entering the mpw
1192 */
1193 if (unlockIfLocked) {
1194 if (!lockAt(category, index, false)) {
1195 return false;
1196 }
1197 locked = false;
1198 }
1199 }
1200
1201 *d = dta[category].d[index];
1202 if (locked)
1203 d->pw = LOCKED_STRING.latin1();
1204
1205 return true;
1206}
1207
1208PwMerror PwMDoc::getCommentByLvp(const QString &category, int listViewPos,
1209 string *foundComment)
1210{
1211 PWM_ASSERT(foundComment);
1212 unsigned int cat = 0;
1213
1214 if (!findCategory(category, &cat))
1215 return e_invalidArg;
1216
1217 unsigned int i, entries = numEntries(cat);
1218 for (i = 0; i < entries; ++i) {
1219 if (dta[cat].d[i].listViewPos == listViewPos) {
1220 *foundComment = dta[cat].d[i].comment;
1221 if (dta[cat].d[i].binary)
1222 return e_binEntry;
1223 return e_normalEntry;
1224 }
1225 }
1226 BUG();
1227 return e_generic;
1228}
1229
1230bool PwMDoc::compressDta(string *d, char algo)
1231{
1232 PWM_ASSERT(d);
1233 switch (algo) {
1234 case PWM_COMPRESS_GZIP: {
1235 CompressGzip comp;
1236 return comp.compress(d);
1237 } case PWM_COMPRESS_BZIP2: {
1238 CompressBzip2 comp;
1239 return comp.compress(d);
1240 } case PWM_COMPRESS_NONE: {
1241 return true;
1242 } default: {
1243 BUG();
1244 }
1245 }
1246 return false;
1247}
1248
1249bool PwMDoc::decompressDta(string *d, char algo)
1250{
1251 PWM_ASSERT(d);
1252 switch (algo) {
1253 case PWM_COMPRESS_GZIP: {
1254 CompressGzip comp;
1255 return comp.decompress(d);
1256 } case PWM_COMPRESS_BZIP2: {
1257 CompressBzip2 comp;
1258 return comp.decompress(d);
1259 } case PWM_COMPRESS_NONE: {
1260 return true;
1261 }
1262 }
1263 return false;
1264}
1265
1266PwMerror PwMDoc::encrypt(string *d, const QString *pw, QFile *f, char algo)
1267{
1268 PWM_ASSERT(d);
1269 PWM_ASSERT(pw);
1270 PWM_ASSERT(f);
1271
1272 size_t encSize;
1273 byte *encrypted = 0;
1274
1275 switch (algo) {
1276 case PWM_CRYPT_BLOWFISH: {
1277 Blowfish::padNull(d);
1278 encSize = d->length();
1279 encrypted = new byte[encSize];
1280 Blowfish bf;
1281 if (bf.bf_setkey((byte *) pw->latin1(), pw->length())) {
1282 delete [] encrypted;
1283 return e_weakPw;
1284 }
1285 bf.bf_encrypt((byte *) encrypted, (byte *) d->c_str(), encSize);
1286 break;
1287 }
1288 #ifndef PWM_EMBEDDED
1289 case PWM_CRYPT_AES128:
1290 /*... fall through */
1291 case PWM_CRYPT_AES192:
1292 case PWM_CRYPT_AES256:
1293 case PWM_CRYPT_3DES:
1294 case PWM_CRYPT_TWOFISH:
1295 case PWM_CRYPT_TWOFISH128: {
1296 if (!LibGCryptIf::available())
1297 return e_cryptNotImpl;
1298 LibGCryptIf gc;
1299 PwMerror err;
1300 unsigned char *plain = new unsigned char[d->length() + 1024];
1301 memcpy(plain, d->c_str(), d->length());
1302 err = gc.encrypt(&encrypted,
1303 &encSize,
1304 plain,
1305 d->length(),
1306 reinterpret_cast<const unsigned char *>(pw->latin1()),
1307 pw->length(),
1308 algo);
1309 delete [] plain;
1310 if (err != e_success)
1311 return e_cryptNotImpl;
1312 break;
1313 }
1314#endif
1315 default: {
1316 delete_ifnot_null_array(encrypted);
1317 return e_cryptNotImpl;
1318 } }
1319
1320 // write encrypted data to file
1321#ifndef PWM_EMBEDDED
1322 if (f->writeBlock(reinterpret_cast<const char *>(encrypted),
1323 static_cast<Q_ULONG>(encSize))
1324 != static_cast<Q_LONG>(encSize)) {
1325 delete_ifnot_null_array(encrypted);
1326 return e_writeFile;
1327 }
1328#else
1329 if (f->writeBlock((const char *)(encrypted),
1330 (unsigned long)(encSize))
1331 != (long)(encSize)) {
1332 delete_ifnot_null_array(encrypted);
1333 return e_writeFile;
1334 }
1335#endif
1336 delete_ifnot_null_array(encrypted);
1337 return e_success;
1338}
1339
1340PwMerror PwMDoc::decrypt(string *d, unsigned int pos, const QString *pw,
1341 char algo, QFile *f)
1342{
1343 PWM_ASSERT(d);
1344 PWM_ASSERT(pw);
1345 PWM_ASSERT(f);
1346
1347 unsigned int cryptLen = f->size() - pos;
1348 byte *encrypted = new byte[cryptLen];
1349 byte *decrypted = new byte[cryptLen];
1350
1351 f->at(pos);
1352#ifndef PWM_EMBEDDED
1353 if (f->readBlock(reinterpret_cast<char *>(encrypted),
1354 static_cast<Q_ULONG>(cryptLen))
1355 != static_cast<Q_LONG>(cryptLen)) {
1356 delete [] encrypted;
1357 delete [] decrypted;
1358 return e_readFile;
1359 }
1360#else
1361 if (f->readBlock((char *)(encrypted),
1362 (unsigned long)(cryptLen))
1363 != (long)(cryptLen)) {
1364 delete [] encrypted;
1365 delete [] decrypted;
1366 return e_readFile;
1367 }
1368#endif
1369 switch (algo) {
1370 case PWM_CRYPT_BLOWFISH: {
1371 Blowfish bf;
1372 bf.bf_setkey((byte *) pw->latin1(), pw->length());
1373 bf.bf_decrypt(decrypted, encrypted, cryptLen);
1374 break;
1375 }
1376#ifndef PWM_EMBEDDED
1377 case PWM_CRYPT_AES128:
1378 /*... fall through */
1379 case PWM_CRYPT_AES192:
1380 case PWM_CRYPT_AES256:
1381 case PWM_CRYPT_3DES:
1382 case PWM_CRYPT_TWOFISH:
1383 case PWM_CRYPT_TWOFISH128: {
1384 if (!LibGCryptIf::available())
1385 return e_cryptNotImpl;
1386 LibGCryptIf gc;
1387 PwMerror err;
1388 err = gc.decrypt(&decrypted,
1389 &cryptLen,
1390 encrypted,
1391 cryptLen,
1392 reinterpret_cast<const unsigned char *>(pw->latin1()),
1393 pw->length(),
1394 algo);
1395 if (err != e_success) {
1396 delete [] encrypted;
1397 delete [] decrypted;
1398 return e_cryptNotImpl;
1399 }
1400 break;
1401 }
1402#endif
1403 default: {
1404 delete [] encrypted;
1405 delete [] decrypted;
1406 return e_cryptNotImpl;
1407 } }
1408 delete [] encrypted;
1409#ifndef PWM_EMBEDDED
1410 d->assign(reinterpret_cast<const char *>(decrypted),
1411 static_cast<string::size_type>(cryptLen));
1412#else
1413 d->assign((const char *)(decrypted),
1414 (string::size_type)(cryptLen));
1415#endif
1416 delete [] decrypted;
1417 if (algo == PWM_CRYPT_BLOWFISH) {
1418 if (!Blowfish::unpadNull(d)) {
1419 BUG();
1420 return e_readFile;
1421 }
1422 }
1423 return e_success;
1424}
1425
1426PwMerror PwMDoc::checkDataHash(char dataHashType, const string *dataHash,
1427 const string *dataStream)
1428{
1429 PWM_ASSERT(dataHash);
1430 PWM_ASSERT(dataStream);
1431 switch(dataHashType) {
1432 case PWM_HASH_SHA1: {
1433 Sha1 hash;
1434 hash.sha1_write((byte*)dataStream->c_str(), dataStream->length());
1435 string ret = hash.sha1_read();
1436 if (ret != *dataHash)
1437 return e_fileCorrupt;
1438 break;
1439 }
1440#ifndef PWM_EMBEDDED
1441 case PWM_HASH_SHA256:
1442 /*... fall through */
1443 case PWM_HASH_SHA384:
1444 case PWM_HASH_SHA512:
1445 case PWM_HASH_MD5:
1446 case PWM_HASH_RMD160:
1447 case PWM_HASH_TIGER: {
1448 if (!LibGCryptIf::available())
1449 return e_hashNotImpl;
1450 LibGCryptIf gc;
1451 PwMerror err;
1452 unsigned char *buf;
1453 size_t hashLen;
1454 err = gc.hash(&buf,
1455 &hashLen,
1456 reinterpret_cast<const unsigned char *>(dataStream->c_str()),
1457 dataStream->length(),
1458 dataHashType);
1459 if (err != e_success)
1460 return e_hashNotImpl;
1461 string calcHash(reinterpret_cast<const char *>(buf),
1462 static_cast<string::size_type>(hashLen));
1463 delete [] buf;
1464 if (calcHash != *dataHash)
1465 return e_fileCorrupt;
1466 break;
1467 }
1468#endif
1469 default:
1470 return e_hashNotImpl;
1471 }
1472 return e_success;
1473}
1474
1475bool PwMDoc::lockAt(unsigned int category, unsigned int index,
1476 bool lock)
1477{
1478 if (index >= numEntries(category)) {
1479 BUG();
1480 return false;
1481 }
1482 if (lock == dta[category].d[index].lockStat)
1483 return true;
1484
1485 if (!lock && currentPw != "") {
1486 // "unlocking" and "password is already set"
1487 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) {
1488 // unlocking without pw not allowed
1489 QString pw;
1490 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1491 if (pw != "") {
1492 if (pw != currentPw) {
1493 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1494 return false;
1495 } else {
1496 timer()->start(DocTimer::id_mpwTimer);
1497 }
1498 } else {
1499 return false;
1500 }
1501 } else {
1502 timer()->start(DocTimer::id_mpwTimer);
1503 }
1504 }
1505
1506 dta[category].d[index].lockStat = lock;
1507 dta[category].d[index].rev++; // increment revision counter.
1508
1509 emitDataChanged(this);
1510 if (!lock)
1511 timer()->start(DocTimer::id_autoLockTimer);
1512
1513 return true;
1514
1515}
1516
1517bool PwMDoc::lockAt(const QString &category,unsigned int index,
1518 bool lock)
1519{
1520 unsigned int cat = 0;
1521
1522 if (!findCategory(category, &cat)) {
1523 BUG();
1524 return false;
1525 }
1526
1527 return lockAt(cat, index, lock);
1528}
1529
1530bool PwMDoc::lockAll(bool lock)
1531{
1532 if (!lock && isDeepLocked()) {
1533 PwMerror ret;
1534 ret = deepLock(false);
1535 if (ret != e_success)
1536 return false;
1537 return true;
1538 }
1539 if (isDocEmpty()) {
1540 return true;
1541 }
1542 if (!lock && currentPw != "") {
1543 // unlocking and password is already set
1544 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW)) {
1545 // unlocking without pw not allowed
1546 QString pw;
1547 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1548 if (pw != "") {
1549 if (pw != currentPw) {
1550 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1551 return false;
1552 } else {
1553 timer()->start(DocTimer::id_mpwTimer);
1554 }
1555 } else {
1556 return false;
1557 }
1558 } else {
1559 timer()->start(DocTimer::id_mpwTimer);
1560 }
1561 }
1562
1563 vector<PwMCategoryItem>::iterator catBegin = dta.begin(),
1564 catEnd = dta.end(),
1565 catI = catBegin;
1566 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1567 while (catI != catEnd) {
1568 entrBegin = catI->d.begin();
1569 entrEnd = catI->d.end();
1570 entrI = entrBegin;
1571 while (entrI != entrEnd) {
1572 entrI->lockStat = lock;
1573 entrI->rev++; // increment revision counter.
1574 ++entrI;
1575 }
1576 ++catI;
1577 }
1578
1579 emitDataChanged(this);
1580 if (lock)
1581 timer()->stop(DocTimer::id_autoLockTimer);
1582 else
1583 timer()->start(DocTimer::id_autoLockTimer);
1584
1585 return true;
1586}
1587
1588bool PwMDoc::isLocked(const QString &category, unsigned int index)
1589{
1590 unsigned int cat = 0;
1591
1592 if (!findCategory(category, &cat)) {
1593 BUG();
1594 return false;
1595 }
1596
1597 return isLocked(cat, index);
1598}
1599
1600bool PwMDoc::unlockAll_tempoary(bool revert)
1601{
1602 static vector< vector<bool> > *oldLockStates = 0;
1603 static bool wasDeepLocked;
1604
1605 if (revert) {// revert the unlocking
1606 if (oldLockStates) {
1607 /* we actually _have_ unlocked something, because
1608 * we have allocated space for the oldLockStates.
1609 * So, go on and revert them!
1610 */
1611 if (wasDeepLocked) {
1612 PwMerror ret = deepLock(true);
1613 if (ret == e_success) {
1614 /* deep-lock succeed. We are save.
1615 * (but if it failed, just go on
1616 * lock them normally)
1617 */
1618 delete_and_null(oldLockStates);
1619 timer()->start(DocTimer::id_autoLockTimer);
1620 printDebug("tempoary unlocking of dta "
1621 "reverted by deep-locking.");
1622 return true;
1623 }
1624 printDebug("deep-lock failed while reverting! "
1625 "Falling back to normal-lock.");
1626 }
1627 if (unlikely(!wasDeepLocked &&
1628 numCategories() != oldLockStates->size())) {
1629 /* DOH! We have modified "dta" while
1630 * it was unlocked tempoary. DON'T DO THIS!
1631 */
1632 BUG();
1633 delete_and_null(oldLockStates);
1634 timer()->start(DocTimer::id_autoLockTimer);
1635 return false;
1636 }
1637 vector<PwMCategoryItem>::iterator catBegin = dta.begin(),
1638 catEnd = dta.end(),
1639 catI = catBegin;
1640 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1641 vector< vector<bool> >::iterator oldCatStatI = oldLockStates->begin();
1642 vector<bool>::iterator oldEntrStatBegin,
1643 oldEntrStatEnd,
1644 oldEntrStatI;
1645 while (catI != catEnd) {
1646 entrBegin = catI->d.begin();
1647 entrEnd = catI->d.end();
1648 entrI = entrBegin;
1649 if (likely(!wasDeepLocked)) {
1650 oldEntrStatBegin = oldCatStatI->begin();
1651 oldEntrStatEnd = oldCatStatI->end();
1652 oldEntrStatI = oldEntrStatBegin;
1653 if (unlikely(catI->d.size() != oldCatStatI->size())) {
1654 /* DOH! We have modified "dta" while
1655 * it was unlocked tempoary. DON'T DO THIS!
1656 */
1657 BUG();
1658 delete_and_null(oldLockStates);
1659 timer()->start(DocTimer::id_autoLockTimer);
1660 return false;
1661 }
1662 }
1663 while (entrI != entrEnd) {
1664 if (wasDeepLocked) {
1665 /* this is an error-fallback if
1666 * deeplock didn't succeed
1667 */
1668 entrI->lockStat = true;
1669 } else {
1670 entrI->lockStat = *oldEntrStatI;
1671 }
1672 ++entrI;
1673 if (likely(!wasDeepLocked))
1674 ++oldEntrStatI;
1675 }
1676 ++catI;
1677 if (likely(!wasDeepLocked))
1678 ++oldCatStatI;
1679 }
1680 delete_and_null(oldLockStates);
1681 if (unlikely(wasDeepLocked)) {
1682 /* error fallback... */
1683 unsetDocStatFlag(DOC_STAT_DEEPLOCKED);
1684 emitDataChanged(this);
1685 printDebug("WARNING: unlockAll_tempoary(true) "
1686 "deeplock fallback!");
1687 }
1688 printDebug("tempoary unlocking of dta reverted.");
1689 } else {
1690 printDebug("unlockAll_tempoary(true): nothing to do.");
1691 }
1692 timer()->start(DocTimer::id_autoLockTimer);
1693 } else {// unlock all data tempoary
1694 if (unlikely(oldLockStates != 0)) {
1695 /* DOH! We have already unlocked the data tempoarly.
1696 * No need to do it twice. ;)
1697 */
1698 BUG();
1699 return false;
1700 }
1701 wasDeepLocked = false;
1702 bool mustUnlock = false;
1703 if (isDeepLocked()) {
1704 PwMerror ret;
1705 while (1) {
1706 ret = deepLock(false);
1707 if (ret == e_success) {
1708 break;
1709 } else if (ret == e_wrongPw) {
1710 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1711 } else {
1712 printDebug("deep-unlocking failed while "
1713 "tempoary unlocking!");
1714 return false;
1715 }
1716 }
1717 wasDeepLocked = true;
1718 mustUnlock = true;
1719 } else {
1720 // first check if it's needed to unlock some entries
1721 vector<PwMCategoryItem>::iterator catBegin = dta.begin(),
1722 catEnd = dta.end(),
1723 catI = catBegin;
1724 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1725 while (catI != catEnd) {
1726 entrBegin = catI->d.begin();
1727 entrEnd = catI->d.end();
1728 entrI = entrBegin;
1729 while (entrI != entrEnd) {
1730 if (entrI->lockStat == true) {
1731 mustUnlock = true;
1732 break;
1733 }
1734 ++entrI;
1735 }
1736 if (mustUnlock)
1737 break;
1738 ++catI;
1739 }
1740 }
1741 if (!mustUnlock) {
1742 // nothing to do.
1743 timer()->stop(DocTimer::id_autoLockTimer);
1744 printDebug("unlockAll_tempoary(): nothing to do.");
1745 return true;
1746 } else if (!wasDeepLocked) {
1747 if (!getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW) &&
1748 currentPw != "") {
1749 /* we can't unlock without mpw, so
1750 * we need to ask for it.
1751 */
1752 QString pw;
1753 while (1) {
1754 pw = requestMpw(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1755 if (pw == "") {
1756 return false;
1757 } else if (pw == currentPw) {
1758 break;
1759 }
1760 wrongMpwMsgBox(getDocStatFlag(DOC_STAT_USE_CHIPCARD));
1761 }
1762 }
1763 }
1764 timer()->stop(DocTimer::id_autoLockTimer);
1765 oldLockStates = new vector< vector<bool> >;
1766 vector<bool> tmp_vec;
1767 vector<PwMCategoryItem>::iterator catBegin = dta.begin(),
1768 catEnd = dta.end(),
1769 catI = catBegin;
1770 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
1771 while (catI != catEnd) {
1772 entrBegin = catI->d.begin();
1773 entrEnd = catI->d.end();
1774 entrI = entrBegin;
1775 while (entrI != entrEnd) {
1776 if (!wasDeepLocked) {
1777 tmp_vec.push_back(entrI->lockStat);
1778 }
1779 entrI->lockStat = false;
1780 ++entrI;
1781 }
1782 if (!wasDeepLocked) {
1783 oldLockStates->push_back(tmp_vec);
1784 tmp_vec.clear();
1785 }
1786 ++catI;
1787 }
1788 printDebug("tempoary unlocked dta.");
1789 }
1790
1791 return true;
1792}
1793
1794PwMerror PwMDoc::deepLock(bool lock, bool saveToFile)
1795{
1796 PwMerror ret;
1797
1798 if (lock) {
1799 if (isDeepLocked())
1800 return e_lock;
1801 if (saveToFile) {
1802 if (isDocEmpty())
1803 return e_docIsEmpty;
1804 ret = saveDoc(conf()->confGlobCompression());
1805 if (ret == e_filename) {
1806 /* the doc wasn't saved to a file
1807 * by the user, yet.
1808 */
1809 cantDeeplock_notSavedMsgBox();
1810 return e_docNotSaved;
1811 } else if (ret != e_success) {
1812 return e_lock;
1813 }
1814 }
1815 timer()->stop(DocTimer::id_autoLockTimer);
1816 clearDoc();
1817 PwMDataItem d;
1818 d.desc = IS_DEEPLOCKED_SHORTMSG.latin1();
1819 d.comment = IS_DEEPLOCKED_MSG.latin1();
1820 d.listViewPos = 0;
1821 addEntry(DEFAULT_CATEGORY, &d, true);
1822 lockAt(DEFAULT_CATEGORY, 0, true);
1823 unsetDocStatFlag(DOC_STAT_DISK_DIRTY);
1824 setDocStatFlag(DOC_STAT_DEEPLOCKED);
1825 } else {
1826 if (!isDeepLocked())
1827 return e_lock;
1828 ret = openDoc(&filename, (conf()->confGlobUnlockOnOpen())
1829 ? 0 : 1);
1830 if (ret == e_wrongPw) {
1831 return e_wrongPw;
1832 } else if (ret != e_success) {
1833 printDebug(string("PwMDoc::deepLock(false): ERR! openDoc() == ")
1834 + tostr(static_cast<int>(ret)));
1835 return e_lock;
1836 }
1837 unsetDocStatFlag(DOC_STAT_DEEPLOCKED);
1838 timer()->start(DocTimer::id_autoLockTimer);
1839 }
1840
1841 emitDataChanged(this);
1842 return e_success;
1843}
1844
1845void PwMDoc::_deepUnlock()
1846{
1847 deepLock(false);
1848}
1849
1850void PwMDoc::clearDoc()
1851{
1852 dta.clear();
1853 PwMCategoryItem d;
1854 d.name = DEFAULT_CATEGORY.latin1();
1855 dta.push_back(d);
1856 currentPw = "";
1857 unsetDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW);
1858}
1859
1860void PwMDoc::changeCurrentPw()
1861{
1862 if (currentPw == "")
1863 return; // doc hasn't been saved. No mpw available.
1864 bool useChipcard = getDocStatFlag(DOC_STAT_USE_CHIPCARD);
1865 QString pw = requestMpwChange(&currentPw, &useChipcard);
1866 if (pw == "")
1867 return;
1868 if (useChipcard)
1869 setDocStatFlag(DOC_STAT_USE_CHIPCARD);
1870 else
1871 unsetDocStatFlag(DOC_STAT_USE_CHIPCARD);
1872 setCurrentPw(pw);
1873}
1874
1875void PwMDoc::setListViewPos(const QString &category, unsigned int index,
1876 int pos)
1877{
1878 unsigned int cat = 0;
1879
1880 if (!findCategory(category, &cat)) {
1881 BUG();
1882 return;
1883 }
1884 setListViewPos(cat, index, pos);
1885}
1886
1887void PwMDoc::setListViewPos(unsigned int category, unsigned int index,
1888 int pos)
1889{
1890 dta[category].d[index].listViewPos = pos;
1891
1892/* FIXME workaround: don't flag dirty, because this function sometimes
1893 * get's called when it shouldn't. It's because PwMView assumes
1894 * the user resorted the UI on behalf of signal layoutChanged().
1895 * This is somewhat broken and incorrect, but I've no other
1896 * solution for now.
1897 */
1898 //setDocStatFlag(DOC_STAT_DISK_DIRTY);
1899}
1900
1901int PwMDoc::getListViewPos(const QString &category, unsigned int index)
1902{
1903 unsigned int cat = 0;
1904
1905 if (!findCategory(category, &cat)) {
1906 BUG();
1907 return -1;
1908 }
1909
1910 return dta[cat].d[index].listViewPos;
1911}
1912
1913void PwMDoc::findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn,
1914 vector<unsigned int> *foundPositions, bool breakAfterFound,
1915 bool caseSensitive, bool exactWordMatch, bool sortByLvp)
1916{
1917 PWM_ASSERT(foundPositions);
1918 PWM_ASSERT(searchIn);
1919 foundPositions->clear();
1920
1921 unsigned int i, entries = numEntries(category);
1922 for (i = 0; i < entries; ++i) {
1923 if (searchIn & SEARCH_IN_DESC) {
1924 if (!compareString(find.desc, dta[category].d[i].desc,
1925 caseSensitive, exactWordMatch)) {
1926 continue;
1927 }
1928 }
1929 if (searchIn & SEARCH_IN_NAME) {
1930 if (!compareString(find.name, dta[category].d[i].name,
1931 caseSensitive, exactWordMatch)) {
1932 continue;
1933 }
1934 }
1935 if (searchIn & SEARCH_IN_PW) {
1936 bool wasLocked = isLocked(category, i);
1937 getDataChangedLock();
1938 lockAt(category, i, false);
1939 if (!compareString(find.pw, dta[category].d[i].pw,
1940 caseSensitive, exactWordMatch)) {
1941 lockAt(category, i, wasLocked);
1942 putDataChangedLock();
1943 continue;
1944 }
1945 lockAt(category, i, wasLocked);
1946 putDataChangedLock();
1947 }
1948 if (searchIn & SEARCH_IN_COMMENT) {
1949 if (!compareString(find.comment, dta[category].d[i].comment,
1950 caseSensitive, exactWordMatch)) {
1951 continue;
1952 }
1953 }
1954 if (searchIn & SEARCH_IN_URL) {
1955 if (!compareString(find.url, dta[category].d[i].url,
1956 caseSensitive, exactWordMatch)) {
1957 continue;
1958 }
1959 }
1960 if (searchIn & SEARCH_IN_LAUNCHER) {
1961 if (!compareString(find.launcher, dta[category].d[i].launcher,
1962 caseSensitive, exactWordMatch)) {
1963 continue;
1964 }
1965 }
1966
1967 // all selected "searchIn" matched.
1968 foundPositions->push_back(i);
1969 if (breakAfterFound)
1970 break;
1971 }
1972
1973 if (sortByLvp && foundPositions->size() > 1) {
1974 vector< pair<unsigned int /* foundPosition (real doc pos) */,
1975 unsigned int /* lvp-pos */> > tmp_vec;
1976
1977 unsigned int i, items = foundPositions->size();
1978 pair<unsigned int, unsigned int> tmp_pair;
1979 for (i = 0; i < items; ++i) {
1980 tmp_pair.first = (*foundPositions)[i];
1981 tmp_pair.second = dta[category].d[(*foundPositions)[i]].listViewPos;
1982 tmp_vec.push_back(tmp_pair);
1983 }
1984 sort(tmp_vec.begin(), tmp_vec.end(), dta_lvp_greater());
1985 foundPositions->clear();
1986 for (i = 0; i < items; ++i) {
1987 foundPositions->push_back(tmp_vec[i].first);
1988 }
1989 }
1990}
1991
1992void PwMDoc::findEntry(const QString &category, PwMDataItem find, unsigned int searchIn,
1993 vector<unsigned int> *foundPositions, bool breakAfterFound,
1994 bool caseSensitive, bool exactWordMatch, bool sortByLvp)
1995{
1996 PWM_ASSERT(foundPositions);
1997 unsigned int cat = 0;
1998
1999 if (!findCategory(category, &cat)) {
2000 foundPositions->clear();
2001 return;
2002 }
2003
2004 findEntry(cat, find, searchIn, foundPositions, breakAfterFound,
2005 caseSensitive, exactWordMatch, sortByLvp);
2006}
2007
2008bool PwMDoc::compareString(const string &s1, const string &s2, bool caseSensitive,
2009 bool exactWordMatch)
2010{
2011 QString _s1(s1.c_str());
2012 QString _s2(s2.c_str());
2013 if (!caseSensitive) {
2014 _s1 = _s1.lower();
2015 _s2 = _s2.lower();
2016 }
2017 if (exactWordMatch ? (_s1 == _s2) : (_s2.find(_s1) != -1))
2018 return true;
2019 return false;
2020}
2021
2022bool PwMDoc::findCategory(const QString &name, unsigned int *index)
2023{
2024 vector<PwMCategoryItem>::iterator i = dta.begin(),
2025 end = dta.end();
2026 while (i != end) {
2027 if ((*i).name == name.latin1()) {
2028 if (index) {
2029 *index = i - dta.begin();
2030 }
2031 return true;
2032 }
2033 ++i;
2034 }
2035 return false;
2036}
2037
2038bool PwMDoc::renameCategory(const QString &category, const QString &newName)
2039{
2040 unsigned int cat = 0;
2041
2042 if (!findCategory(category, &cat))
2043 return false;
2044
2045 return renameCategory(cat, newName);
2046}
2047
2048bool PwMDoc::renameCategory(unsigned int category, const QString &newName,
2049 bool dontFlagDirty)
2050{
2051 if (category > numCategories() - 1)
2052 return false;
2053
2054 dta[category].name = newName.latin1();
2055 if (!dontFlagDirty)
2056 flagDirty();
2057
2058 return true;
2059}
2060
2061bool PwMDoc::delCategory(const QString &category)
2062{
2063 unsigned int cat = 0;
2064
2065 if (!findCategory(category, &cat))
2066 return false;
2067
2068 return delCategory(cat);
2069}
2070
2071bool PwMDoc::delCategory(unsigned int category, bool dontFlagDirty)
2072{
2073 if (category > numCategories() - 1)
2074 return false;
2075
2076 // We don't delete it, if it is the last existing
2077 // category! Instead we rename it to "Default".
2078 if (numCategories() > 1) {
2079 dta.erase(dta.begin() + category);
2080 } else {
2081 renameCategory(category, DEFAULT_CATEGORY, dontFlagDirty);
2082 return true;
2083 }
2084 if (!dontFlagDirty)
2085 flagDirty();
2086
2087 return true;
2088}
2089
2090void PwMDoc::delAllEmptyCat(bool dontFlagDirty)
2091{
2092 vector<PwMCategoryItem>::iterator begin = dta.begin(),
2093 end = dta.end(),
2094 i = begin;
2095 while (i != end) {
2096 if (i->d.empty()) {
2097 delCategory(begin - i, dontFlagDirty);
2098 }
2099 ++i;
2100 }
2101}
2102
2103void PwMDoc::getCategoryList(vector<string> *list)
2104{
2105 PWM_ASSERT(list);
2106 list->clear();
2107 vector<PwMCategoryItem>::iterator i = dta.begin(),
2108 end = dta.end();
2109 while (i != end) {
2110 list->push_back(i->name);
2111 ++i;
2112 }
2113}
2114
2115void PwMDoc::getCategoryList(QStringList *list)
2116{
2117 PWM_ASSERT(list);
2118 list->clear();
2119 vector<PwMCategoryItem>::iterator i = dta.begin(),
2120 end = dta.end();
2121 while (i != end) {
2122#ifndef PWM_EMBEDDED
2123 list->push_back(i->name.c_str());
2124#else
2125 list->append(i->name.c_str());
2126#endif
2127 ++i;
2128 }
2129}
2130
2131void PwMDoc::getEntryList(const QString &category, QStringList *list)
2132{
2133 PWM_ASSERT(list);
2134 unsigned int cat = 0;
2135 if (!findCategory(category, &cat)) {
2136 list->clear();
2137 return;
2138 }
2139 getEntryList(cat, list);
2140}
2141
2142void PwMDoc::getEntryList(const QString &category, vector<string> *list)
2143{
2144 PWM_ASSERT(list);
2145 unsigned int cat = 0;
2146 if (!findCategory(category, &cat)) {
2147 list->clear();
2148 return;
2149 }
2150 getEntryList(cat, list);
2151}
2152
2153void PwMDoc::getEntryList(unsigned int category, vector<string> *list)
2154{
2155 PWM_ASSERT(list);
2156 list->clear();
2157 vector<PwMDataItem>::iterator begin = dta[category].d.begin(),
2158 end = dta[category].d.end(),
2159 i = begin;
2160 while (i != end) {
2161 list->push_back(i->desc);
2162 ++i;
2163 }
2164}
2165
2166void PwMDoc::getEntryList(unsigned int category, QStringList *list)
2167{
2168 PWM_ASSERT(list);
2169 list->clear();
2170 vector<PwMDataItem>::iterator begin = dta[category].d.begin(),
2171 end = dta[category].d.end(),
2172 i = begin;
2173 while (i != end) {
2174#ifndef PWM_EMBEDDED
2175 list->push_back(i->desc.c_str());
2176#else
2177 list->append(i->desc.c_str());
2178#endif
2179 ++i;
2180 }
2181}
2182
2183bool PwMDoc::execLauncher(const QString &category, unsigned int entryIndex)
2184{
2185 unsigned int cat = 0;
2186
2187 if (!findCategory(category, &cat))
2188 return false;
2189
2190 return execLauncher(cat, entryIndex);
2191}
2192
2193bool PwMDoc::execLauncher(unsigned int category, unsigned int entryIndex)
2194{
2195 if (geteuid() == 0) {
2196 rootAlertMsgBox();
2197 return false;
2198 }
2199 QString command(dta[category].d[entryIndex].launcher.c_str());
2200 bool wasLocked = isLocked(category, entryIndex);
2201
2202 if (command.find("$p") != -1) {
2203 /* the user requested the password to be included
2204 * into the command. We have to ask for the password,
2205 * if it's locked. We do that by unlocking the entry
2206 */
2207 if (!lockAt(category, entryIndex, false))
2208 return false;
2209 }
2210#ifndef PWM_EMBEDDED
2211 command.replace("$d", dta[category].d[entryIndex].desc.c_str());
2212 command.replace("$n", dta[category].d[entryIndex].name.c_str());
2213 command.replace("$p", dta[category].d[entryIndex].pw.c_str());
2214 command.replace("$u", dta[category].d[entryIndex].url.c_str());
2215 command.replace("$c", dta[category].d[entryIndex].comment.c_str());
2216#else
2217 command.replace(QRegExp("$d"), dta[category].d[entryIndex].desc.c_str());
2218 command.replace(QRegExp("$n"), dta[category].d[entryIndex].name.c_str());
2219 command.replace(QRegExp("$p"), dta[category].d[entryIndex].pw.c_str());
2220 command.replace(QRegExp("$u"), dta[category].d[entryIndex].url.c_str());
2221 command.replace(QRegExp("$c"), dta[category].d[entryIndex].comment.c_str());
2222#endif
2223 command.append(" &");
2224
2225 QString customXterm(conf()->confGlobXtermCommand());
2226 if (!customXterm.isEmpty())
2227 command = customXterm + " " + command;
2228
2229 system(command.latin1());
2230
2231 lockAt(category, entryIndex, wasLocked);
2232 return true;
2233}
2234
2235bool PwMDoc::goToURL(const QString &category, unsigned int entryIndex)
2236{
2237 unsigned int cat = 0;
2238
2239 if (!findCategory(category, &cat))
2240 return false;
2241
2242 return goToURL(cat, entryIndex);
2243}
2244
2245bool PwMDoc::goToURL(unsigned int category, unsigned int entryIndex)
2246{
2247 if (geteuid() == 0) {
2248 rootAlertMsgBox();
2249 return false;
2250 }
2251 QString url(dta[category].d[entryIndex].url.c_str());
2252 if (url.isEmpty())
2253 return false;
2254
2255 QString customBrowser(conf()->confGlobBrowserCommand());
2256 if (!customBrowser.isEmpty()) {
2257 browserProc.clearArguments();
2258 browserProc << customBrowser << url;
2259 if (browserProc.start(KProcess::DontCare))
2260 return true;
2261 }
2262
2263 browserProc.clearArguments();
2264 browserProc << "konqueror" << url;
2265 if (browserProc.start(KProcess::DontCare))
2266 return true;
2267
2268 browserProc.clearArguments();
2269 browserProc << "mozilla" << url;
2270 if (browserProc.start(KProcess::DontCare))
2271 return true;
2272
2273 browserProc.clearArguments();
2274 browserProc << "opera" << url;
2275 if (browserProc.start(KProcess::DontCare))
2276 return true;
2277 return false;
2278}
2279
2280PwMerror PwMDoc::exportToText(const QString *file)
2281{
2282 PWM_ASSERT(file);
2283 if (QFile::exists(*file)) {
2284 if (!QFile::remove(*file))
2285 return e_accessFile;
2286 }
2287 QFile f(*file);
2288 if (!f.open(IO_ReadWrite))
2289 return e_openFile;
2290
2291 if (!unlockAll_tempoary()) {
2292 f.close();
2293 return e_lock;
2294 }
2295
2296 // write header
2297 string header = i18n("Password table generated by\nPwM v").latin1();
2298 header += PACKAGE_VER;
2299 header += i18n("\non ").latin1();
2300 QDate currDate = QDate::currentDate();
2301 QTime currTime = QTime::currentTime();
2302
2303#ifndef PWM_EMBEDDED
2304 header += currDate.toString("ddd MMMM d ").latin1();
2305 header += currTime.toString("hh:mm:ss ").latin1();
2306#else
2307 QString dfs = KGlobal::locale()->dateFormatShort();
2308 bool ampm = KGlobal::locale()->use12Clock();
2309 KGlobal::locale()->setDateFormatShort("%A %B %d");
2310 KGlobal::locale()->setHore24Format(true);
2311
2312 header += KGlobal::locale()->formatDate(currDate, true, KLocale::Userdefined);
2313 header += KGlobal::locale()->formatTime(currTime, true);
2314 KGlobal::locale()->setDateFormatShort(dfs);
2315 KGlobal::locale()->setHore24Format(!ampm);
2316
2317#endif
2318 header += tostr(currDate.year());
2319 header += "\n==============================\n\n";
2320
2321
2322#ifndef PWM_EMBEDDED
2323 if (f.writeBlock(header.c_str(), header.length()) != (Q_LONG)header.length()) {
2324 unlockAll_tempoary(true);
2325 f.close();
2326 return e_writeFile;
2327 }
2328#else
2329 if (f.writeBlock(header.c_str(), header.length()) != (long)header.length()) {
2330 unlockAll_tempoary(true);
2331 f.close();
2332 return e_writeFile;
2333 }
2334#endif
2335 unsigned int i, numCat = numCategories();
2336 unsigned int j, numEnt;
2337 string exp;
2338 for (i = 0; i < numCat; ++i) {
2339 numEnt = numEntries(i);
2340
2341 exp = "\n== Category: ";
2342 exp += dta[i].name;
2343 exp += " ==\n";
2344#ifndef PWM_EMBEDDED
2345 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) {
2346 unlockAll_tempoary(true);
2347 f.close();
2348 return e_writeFile;
2349 }
2350#else
2351 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) {
2352 unlockAll_tempoary(true);
2353 f.close();
2354 return e_writeFile;
2355 }
2356#endif
2357 for (j = 0; j < numEnt; ++j) {
2358 exp = "\n-- ";
2359 exp += dta[i].d[j].desc;
2360 exp += " --\n";
2361
2362 exp += i18n("Username: ").latin1();
2363 exp += dta[i].d[j].name;
2364 exp += "\n";
2365
2366 exp += i18n("Password: ").latin1();
2367 exp += dta[i].d[j].pw;
2368 exp += "\n";
2369
2370 exp += i18n("Comment: ").latin1();
2371 exp += dta[i].d[j].comment;
2372 exp += "\n";
2373
2374 exp += i18n("URL: ").latin1();
2375 exp += dta[i].d[j].url;
2376 exp += "\n";
2377
2378 exp += i18n("Launcher: ").latin1();
2379 exp += dta[i].d[j].launcher;
2380 exp += "\n";
2381
2382#ifndef PWM_EMBEDDED
2383 if (f.writeBlock(exp.c_str(), exp.length()) != (Q_LONG)exp.length()) {
2384 unlockAll_tempoary(true);
2385 f.close();
2386 return e_writeFile;
2387 }
2388#else
2389 if (f.writeBlock(exp.c_str(), exp.length()) != (long)exp.length()) {
2390 unlockAll_tempoary(true);
2391 f.close();
2392 return e_writeFile;
2393 }
2394#endif
2395 }
2396 }
2397 unlockAll_tempoary(true);
2398 f.close();
2399
2400 return e_success;
2401}
2402
2403PwMerror PwMDoc::importFromText(const QString *file, int format)
2404{
2405 PWM_ASSERT(file);
2406 if (format == 0)
2407 return importText_PwM(file);
2408 else if (format == -1) {
2409 // probe for all formats
2410 if (importText_PwM(file) == e_success)
2411 return e_success;
2412 dta.clear();
2413 emitDataChanged(this);
2414 // add next format here...
2415 return e_fileFormat;
2416 }
2417 return e_invalidArg;
2418}
2419
2420PwMerror PwMDoc::importText_PwM(const QString *file)
2421{
2422 PWM_ASSERT(file);
2423 FILE *f;
2424 int tmp;
2425 ssize_t ret;
2426 string curCat;
2427 unsigned int entriesRead = 0;
2428 PwMDataItem currItem;
2429 f = fopen(file->latin1(), "r");
2430 if (!f)
2431 return e_openFile;
2432 size_t ch_tmp_size = 1024;
2433 char *ch_tmp = (char*)malloc(ch_tmp_size);
2434 if (!ch_tmp) {
2435 fclose(f);
2436 return e_outOfMem;
2437 }
2438
2439 // - check header
2440 if (getline(&ch_tmp, &ch_tmp_size, f) == -1) // skip first line.
2441 goto formatError;
2442 // check version-string and return version in "ch_tmp".
2443 if (fscanf(f, "PwM v%s", ch_tmp) != 1) {
2444 // header not recognized as PwM generated header
2445 goto formatError;
2446 }
2447 // set filepointer behind version-string-line previously checked
2448 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2449 goto formatError;
2450 // skip next line containing the build-date
2451 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2452 goto formatError;
2453 // read header termination line
2454 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2455 goto formatError;
2456 if (strcmp(ch_tmp, "==============================\n"))
2457 goto formatError;
2458
2459 // - read entries
2460 do {
2461 // find beginning of next category
2462 do {
2463 tmp = fgetc(f);
2464 } while (tmp == '\n' && tmp != EOF);
2465 if (tmp == EOF)
2466 break;
2467
2468 // decrement filepos by one
2469 fseek(f, -1, SEEK_CUR);
2470 // read cat-name
2471 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2472 goto formatError;
2473 // check cat-name format
2474 if (memcmp(ch_tmp, "== Category: ", 13) != 0)
2475 goto formatError;
2476 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " ==", 3) != 0)
2477 goto formatError;
2478 // copy cat-name
2479 curCat.assign(ch_tmp + 13, strlen(ch_tmp) - 1 - 16);
2480
2481 do {
2482 // find beginning of next entry
2483 do {
2484 tmp = fgetc(f);
2485 } while (tmp == '\n' && tmp != EOF && tmp != '=');
2486 if (tmp == EOF)
2487 break;
2488 if (tmp == '=') {
2489 fseek(f, -1, SEEK_CUR);
2490 break;
2491 }
2492 // decrement filepos by one
2493 fseek(f, -1, SEEK_CUR);
2494 // read desc-line
2495 if (getline(&ch_tmp, &ch_tmp_size, f) == -1)
2496 goto formatError;
2497 // check desc-line format
2498 if (memcmp(ch_tmp, "-- ", 3) != 0)
2499 goto formatError;
2500 if (memcmp(ch_tmp + (strlen(ch_tmp) - 1 - 3), " --", 3) != 0)
2501 goto formatError;
2502 // add desc-line
2503 currItem.desc.assign(ch_tmp + 3, strlen(ch_tmp) - 1 - 6);
2504
2505 // read username-line
2506 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2507 goto formatError;
2508 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.name))
2509 goto formatError;
2510
2511 // read pw-line
2512 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2513 goto formatError;
2514 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.pw))
2515 goto formatError;
2516
2517 // read comment-line
2518 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2519 goto formatError;
2520 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.comment))
2521 goto formatError;
2522
2523 // read URL-line
2524 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2525 goto formatError;
2526 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.url))
2527 goto formatError;
2528
2529 // read launcher-line
2530 if ((ret = getline(&ch_tmp, &ch_tmp_size, f)) == -1)
2531 goto formatError;
2532 if (!textExtractEntry_PwM(ch_tmp, ret, &currItem.launcher))
2533 goto formatError;
2534
2535 currItem.lockStat = true;
2536 currItem.listViewPos = -1;
2537 addEntry(curCat.c_str(), &currItem, true);
2538 ++entriesRead;
2539 } while (1);
2540 } while (1);
2541 if (!entriesRead)
2542 goto formatError;
2543
2544 free(ch_tmp);
2545 fclose(f);
2546 flagDirty();
2547 return e_success;
2548
2549 formatError:
2550 free(ch_tmp);
2551 fclose(f);
2552 return e_fileFormat;
2553}
2554
2555bool PwMDoc::textExtractEntry_PwM(const char *in, ssize_t in_size, string *out)
2556{
2557 PWM_ASSERT(in && out);
2558 ssize_t i = 0, len = in_size - 1;
2559 while (i < len) {
2560 if (in[i] == ':')
2561 break;
2562 ++i;
2563 }
2564 i += 2;
2565 *out = "";
2566 out->append(in + i, in_size - i - 1);
2567 return true;
2568}
2569
2570PwMerror PwMDoc::exportToGpasman(const QString *file)
2571{
2572 PWM_ASSERT(file);
2573 GpasmanFile gp;
2574 int ret;
2575
2576 if (!unlockAll_tempoary())
2577 return e_lock;
2578
2579 QString gpmPassword;
2580 while (1) {
2581 gpmPassword = requestNewMpw(0);
2582 if (gpmPassword == "") {
2583 unlockAll_tempoary(true);
2584 return e_noPw;
2585 }
2586 if (gpmPassword.length() < 4) {
2587 gpmPwLenErrMsgBox();
2588 } else {
2589 break;
2590 }
2591 }
2592
2593 ret = gp.save_init(file->latin1(), gpmPassword.latin1());
2594 if (ret != 1) {
2595 unlockAll_tempoary(true);
2596 return e_accessFile;
2597 }
2598
2599 char *entry[4];
2600 unsigned int numCat = numCategories(), i;
2601 unsigned int numEntr, j;
2602 int descLen, nameLen, pwLen, commentLen;
2603 for (i = 0; i < numCat; ++i) {
2604 numEntr = numEntries(i);
2605 for (j = 0; j < numEntr; ++j) {
2606 descLen = dta[i].d[j].desc.length();
2607 nameLen = dta[i].d[j].name.length();
2608 pwLen = dta[i].d[j].pw.length();
2609 commentLen = dta[i].d[j].comment.length();
2610 entry[0] = new char[descLen + 1];
2611 entry[1] = new char[nameLen + 1];
2612 entry[2] = new char[pwLen + 1];
2613 entry[3] = new char[commentLen + 1];
2614 strcpy(entry[0], descLen == 0 ? " " : dta[i].d[j].desc.c_str());
2615 strcpy(entry[1], nameLen == 0 ? " " : dta[i].d[j].name.c_str());
2616 strcpy(entry[2], pwLen == 0 ? " " : dta[i].d[j].pw.c_str());
2617 strcpy(entry[3], commentLen == 0 ? " " : dta[i].d[j].comment.c_str());
2618 entry[0][descLen == 0 ? descLen + 1 : descLen] = '\0';
2619 entry[1][nameLen == 0 ? nameLen + 1 : nameLen] = '\0';
2620 entry[2][pwLen == 0 ? pwLen + 1 : pwLen] = '\0';
2621 entry[3][commentLen == 0 ? commentLen + 1 : commentLen] = '\0';
2622
2623 ret = gp.save_entry(entry);
2624 if (ret == -1){
2625 delete [] entry[0];
2626 delete [] entry[1];
2627 delete [] entry[2];
2628 delete [] entry[3];
2629 gp.save_finalize();
2630 unlockAll_tempoary(true);
2631 return e_writeFile;
2632 }
2633
2634 delete [] entry[0];
2635 delete [] entry[1];
2636 delete [] entry[2];
2637 delete [] entry[3];
2638 }
2639 }
2640 unlockAll_tempoary(true);
2641 if (gp.save_finalize() == -1)
2642 return e_writeFile;
2643
2644 return e_success;
2645}
2646
2647PwMerror PwMDoc::importFromGpasman(const QString *file)
2648{
2649 PWM_ASSERT(file);
2650 QString pw = requestMpw(false);
2651 if (pw == "")
2652 return e_noPw;
2653 GpasmanFile gp;
2654 int ret, i;
2655 PwMerror ret2;
2656 char *entry[4];
2657 PwMDataItem tmpData;
2658 ret = gp.load_init(file->latin1(), pw.latin1());
2659 if (ret != 1)
2660 return e_accessFile;
2661
2662 do {
2663 ret = gp.load_entry(entry);
2664 if(ret != 1)
2665 break;
2666 tmpData.desc = entry[0];
2667 tmpData.name = entry[1];
2668 tmpData.pw = entry[2];
2669 tmpData.comment = entry[3];
2670 tmpData.lockStat = true;
2671 tmpData.listViewPos = -1;
2672 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true);
2673 for (i = 0; i < 4; ++i)
2674 free(entry[i]);
2675 if (ret2 == e_maxAllowedEntr) {
2676 gp.load_finalize();
2677 return e_maxAllowedEntr;
2678 }
2679 } while (1);
2680 gp.load_finalize();
2681 if (isDocEmpty())
2682 return e_wrongPw; // we assume this.
2683
2684 flagDirty();
2685 return e_success;
2686}
2687
2688void PwMDoc::ensureLvp()
2689{
2690 if (isDocEmpty())
2691 return;
2692
2693 vector< vector<PwMDataItem>::iterator > undefined;
2694 vector< vector<PwMDataItem>::iterator >::iterator undefBegin,
2695 undefEnd,
2696 undefI;
2697 vector<PwMCategoryItem>::iterator catBegin = dta.begin(),
2698 catEnd = dta.end(),
2699 catI = catBegin;
2700 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
2701 int lvpTop, tmpLvp;
2702
2703 while (catI != catEnd) {
2704 lvpTop = -1;
2705 undefined.clear();
2706
2707 entrBegin = catI->d.begin();
2708 entrEnd = catI->d.end();
2709 entrI = entrBegin;
2710
2711 while (entrI != entrEnd) {
2712 tmpLvp = entrI->listViewPos;
2713 if (tmpLvp == -1)
2714 undefined.push_back(entrI);
2715 else if (tmpLvp > lvpTop)
2716 lvpTop = tmpLvp;
2717 ++entrI;
2718 }
2719 undefBegin = undefined.begin();
2720 undefEnd = undefined.end();
2721 undefI = undefBegin;
2722 while (undefI != undefEnd) {
2723 (*undefI)->listViewPos = ++lvpTop;
2724 ++undefI;
2725 }
2726 ++catI;
2727 }
2728}
2729
2730QString PwMDoc::getTitle()
2731{
2732 /* NOTE: We have to ensure, that the returned title
2733 * is unique and not reused somewhere else while
2734 * this document is valid (open).
2735 */
2736 QString title(getFilename());
2737 if (title.isEmpty()) {
2738 if (unnamedNum == 0) {
2739 unnamedNum = PwMDocList::getNewUnnamedNumber();
2740 PWM_ASSERT(unnamedNum != 0);
2741 }
2742 title = DEFAULT_TITLE;
2743 title += " ";
2744 title += tostr(unnamedNum).c_str();
2745 }
2746 return title;
2747}
2748
2749bool PwMDoc::tryDelete()
2750{
2751 if (deleted)
2752 return true;
2753 int ret;
2754 if (isDirty()) {
2755 ret = dirtyAskSave(getTitle());
2756 if (ret == 0) { // save to disk
2757 if (!saveDocUi(this))
2758 goto out_ignore;
2759 } else if (ret == 1) { // don't save and delete
2760 goto out_accept;
2761 } else { // cancel operation
2762 goto out_ignore;
2763 }
2764 }
2765out_accept:
2766 deleted = true;
2767 delete this;
2768 return true;
2769out_ignore:
2770 return false;
2771}
2772
2773#ifndef PWM_EMBEDDED
2774#include "pwmdoc.moc"
2775#endif
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h
new file mode 100644
index 0000000..9650d55
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmdoc.h
@@ -0,0 +1,701 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 2.0 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef __PWMDOC_H
21#define __PWMDOC_H
22
23 #define PWM_FILE_VER (static_cast<char>(0x05))
24
25 #define PWM_HASH_SHA1 (static_cast<char>(0x01))
26 #define PWM_HASH_SHA256 (static_cast<char>(0x02))
27 #define PWM_HASH_SHA384 (static_cast<char>(0x03))
28 #define PWM_HASH_SHA512 (static_cast<char>(0x04))
29 #define PWM_HASH_MD5 (static_cast<char>(0x05))
30 #define PWM_HASH_RMD160 (static_cast<char>(0x06))
31 #define PWM_HASH_TIGER (static_cast<char>(0x07))
32
33 #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01))
34 #define PWM_CRYPT_AES128(static_cast<char>(0x02))
35 #define PWM_CRYPT_AES192(static_cast<char>(0x03))
36 #define PWM_CRYPT_AES256(static_cast<char>(0x04))
37 #define PWM_CRYPT_3DES (static_cast<char>(0x05))
38 #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06))
39 #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07))
40
41 #define PWM_COMPRESS_NONE(static_cast<char>(0x00))
42 #define PWM_COMPRESS_GZIP(static_cast<char>(0x01))
43 #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02))
44
45 #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0)))
46 #define FILE_ID_HEADER "PWM_PASSWORD_FILE"
47
48
49#include "pwmexception.h"
50#include "pwmdocui.h"
51#include "configuration.h"
52
53#include <qobject.h>
54#include <qtimer.h>
55#include <qdatetime.h>
56
57#include <kprocess.h>
58
59#ifndef PWM_EMBEDDED
60#else
61#include <kapplication.h>
62#endif
63
64#include <string>
65#include <vector>
66#include <utility>
67
68using std::vector;
69using std::string;
70using std::pair;
71
72/* used in findEntry() function */
73 #define SEARCH_IN_DESC (1)
74 #define SEARCH_IN_NAME (1 << 1)
75 #define SEARCH_IN_PW (1 << 2)
76 #define SEARCH_IN_COMMENT(1 << 3)
77 #define SEARCH_IN_URL (1 << 4)
78 #define SEARCH_IN_LAUNCHER(1 << 5)
79 #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \
80 SEARCH_IN_PW | SEARCH_IN_COMMENT| \
81 SEARCH_IN_URL| SEARCH_IN_LAUNCHER)
82
83/** document deeplocked. Data is out for lunch to disk */
84 #define DOC_STAT_DEEPLOCKED (1)
85/** encrypted document on disk is dirty. data has to go to disk. */
86 #define DOC_STAT_DISK_DIRTY (1 << 1)
87/** we are using a chipcard to encrypt the data */
88 #define DOC_STAT_USE_CHIPCARD (1 << 2)
89/** use "currentPw" to unlock. (This flag is set/unset by a timer) */
90 #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3)
91
92class PwMDoc;
93class PwMView;
94class QFile;
95
96/* meta data for a PwMDataItem */
97struct PwMMetaData
98{
99 PwMMetaData()
100 : updateInt (0)
101 { }
102 /** creation date of the PwMDataItem to which
103 * this meta data belongs.
104 */
105 QDateTimecreate;
106 /** becomes valid on this date */
107 QDateTimevalid;
108 /** expire date */
109 QDateTimeexpire;
110 /** update date (last updated at this date) */
111 QDateTimeupdate;
112 /** update interval (in minutes). Time since the
113 * last update to remind the user to update the item.
114 * 0 disables.
115 */
116 unsigned long updateInt;
117
118 //US ENH: enhancements of the filestructure
119 /* each entry gets a unique id assigned */
120 QString uniqueid;
121
122
123 void clear()
124 {
125 create = QDateTime();
126 expire = QDateTime();
127 update = QDateTime();
128 updateInt = 0;
129 uniqueid = KApplication::randomString(8);
130 }
131 inline bool isValid() const
132 {
133 if (valid.isNull())
134 return true;
135 return (valid < QDateTime::currentDateTime());
136 }
137 inline bool isExpired() const
138 {
139 if (expire.isNull())
140 return false;
141 return (expire < QDateTime::currentDateTime());
142 }
143 inline bool isUpdateIntOver() const
144 {
145 if (updateInt == 0 ||
146 update.isNull())
147 return false;
148 QDateTime d(update);
149 return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime());
150 }
151};
152
153struct PwMDataItem
154{
155 PwMDataItem()
156 : lockStat (true)
157 , listViewPos (-1)
158 , binary (false)
159 , rev (0)
160 { }
161
162 /** password description */
163 stringdesc;
164 /** user-name */
165 stringname;
166 /** the password itself */
167 stringpw;
168 /** some comment */
169 stringcomment;
170 /** an URL string */
171 stringurl;
172 /** launcher. Can be executed as a system() command */
173 stringlauncher;
174 /** locking status. If locked (true), pw is not emitted through getEntry() */
175 boollockStat;
176 /** position of this item in main "list-view"
177 * If -1, the position is not yet specified and should be appended to the list
178 */
179 intlistViewPos;
180 /** does this entry contain binary data? */
181 bool binary;
182 /** meta data for this data item. */
183 PwMMetaData meta;
184 /** data revision counter. This counter can be used
185 * to easily, efficiently determine if this data item
186 * has changed since some time.
187 * This counter is incremented on every update.
188 */
189 unsigned int rev;
190
191 void clear(bool clearMeta = true)
192 {
193 /* NOTE: Don't use .clear() here to be
194 * backward compatible with gcc-2 (Debian Woody)
195 */
196 desc = "";
197 name = "";
198 pw = "";
199 comment = "";
200 url = "";
201 launcher = "";
202 lockStat = true;
203 listViewPos = -1;
204 binary = false;
205 if (clearMeta)
206 meta.clear();
207 }
208};
209
210struct PwMCategoryItem
211{
212 /** all PwMDataItems (all passwords) within this category */
213 vector<PwMDataItem>d;
214 /** category name/description */
215 string name;
216
217 void clear()
218 {
219 d.clear();
220 name = "";
221 }
222};
223
224/** "Function Object" for sort()ing PwMDataItem::listViewPos */
225class dta_lvp_greater
226{
227public:
228 bool operator() (const pair<unsigned int, unsigned int> &d1,
229 const pair<unsigned int, unsigned int> &d2)
230 {
231 return d1.second > d2.second;
232 }
233};
234
235/** list of PwMDoc documents and it's IDs */
236class PwMDocList
237{
238public:
239 struct listItem
240 {
241 /** document filename (known as ID, here) */
242 string docId;
243 /** pointer to the document class */
244 PwMDoc *doc;
245 };
246
247 PwMDocList() {}
248
249 /** add a new item to the list */
250 void add(PwMDoc *doc, const string &id);
251 /** changes the contents of an existing item */
252 void edit(PwMDoc *doc, const string &newId);
253 /** remove the given item */
254 void del(PwMDoc *doc);
255 /** get the item at index */
256 listItem getAt(int index)
257 { return docList[index]; }
258 /** find an entry with this id */
259 bool find(const string &id, listItem *ret = 0);
260 /** returns a copy of the list */
261 const vector<listItem>* getList() const
262 { return &docList; }
263
264
265 /** returns a new unique number to extend the name of
266 * an unnamed document.
267 */
268 static unsigned int getNewUnnamedNumber()
269 { return unnamedDocCnt++; }
270
271protected:
272 /* Hm, I think we shouldn't really use a "list" here, should we?
273 * So I decided to actually use a vector.
274 */
275 vector<listItem> docList;
276 /** This value is used to get a new number for yet unnamed
277 * documents. It is incremented on every request. So it's
278 * theoretically possible to overflow it, but... :)
279 */
280 static unsigned int unnamedDocCnt;
281};
282
283/** implements timers for the document */
284class DocTimer : public QObject
285{
286 Q_OBJECT
287public:
288 enum TimerIDs
289 {
290 id_mpwTimer,
291 id_autoLockTimer,
292 id_metaCheckTimer
293 };
294
295public:
296 DocTimer(PwMDoc *_doc);
297 ~DocTimer();
298
299 /** start the timer */
300 void start(TimerIDs timer);
301 /** stop the timer */
302 void stop(TimerIDs timer);
303 /** get the lock for a timer.
304 * This lock is a recursive lock. When a lock is
305 * held, the timer will be stopped and timeout is
306 * guaranteed to not happen
307 */
308 void getLock(TimerIDs timer);
309 /** put a recursive timer lock */
310 void putLock(TimerIDs timer);
311
312protected slots:
313 /** timeout slot for the mpw timer */
314 void mpwTimeout();
315 /** timeout slot for the autoLock timer */
316 void autoLockTimeout();
317 /** timeout slot for the metaCheck timer */
318 void metaCheckTimeout();
319
320protected:
321 /** pointer to the document associated with this timer. */
322 PwMDoc *doc;
323 /** timer object for mpw timer */
324 QTimer *mpwTimer;
325 /** timer object for the autoLock timer */
326 QTimer *autoLockTimer;
327 /** timer object for the metaCheck timer */
328 QTimer *metaCheckTimer;
329 /** lock counter for the mpw timer */
330 unsigned int mpwLock;
331 /** lock counter for the autoLock timer */
332 unsigned int autoLockLock;
333 /** lock counter for the metaCheck timer */
334 unsigned int metaCheckLock;
335};
336
337/** Document class for PwM */
338class PwMDoc : public PwMDocUi
339{
340 Q_OBJECT
341 friend class DocTimer;
342
343public:
344 /** construtor */
345 PwMDoc(QObject* parent = 0, const char *name = 0);
346 /** destructor */
347 ~PwMDoc();
348
349 /** returns a pointer to a list of all open documents */
350 static PwMDocList* getOpenDocList()
351 { return &openDocList; }
352
353 /** flag document dirty. dta changed */
354 void flagDirty()
355 {
356 setDocStatFlag(DOC_STAT_DISK_DIRTY);
357 emitDataChanged(this);
358 }
359 /** modified? */
360 bool isDirty()
361 { return getDocStatFlag(DOC_STAT_DISK_DIRTY); }
362 /** save document to disk */
363 PwMerror saveDoc(char compress, const QString *file = 0);
364 /** read document from file.
365 * "openLocked is must be set to either of these values:
366 * 0 == open with all entries unlocked
367 * 1 == open with all entries locked
368 * 2 == open deep-locked
369 */
370 PwMerror openDoc(const QString *file, int openLocked);
371 /** export document to ascii-textfile */
372 PwMerror exportToText(const QString *file);
373 /** export document to gpasman / kpasman file */
374 PwMerror exportToGpasman(const QString *file);
375 /** import document from ascii-textfile */
376 PwMerror importFromText(const QString *file, int format = -1);
377 /** import document from gpasman / kpasman file */
378 PwMerror importFromGpasman(const QString *file);
379 /** add new entry */
380 PwMerror addEntry(const QString &category, PwMDataItem *d,
381 bool dontFlagDirty = false, bool updateMeta = true);
382 /** add new category. This function doesn't flag the document dirty! */
383 PwMerror addCategory(const QString &category, unsigned int *categoryIndex,
384 bool checkIfExist = true);
385 /** rename an existing category */
386 bool renameCategory(const QString &category, const QString &newName);
387 /** rename an existing category */
388 bool renameCategory(unsigned int category, const QString &newName,
389 bool dontFlagDirty = false);
390 /** delete an existing category */
391 bool delCategory(const QString &category);
392 /** delete an existing category */
393 bool delCategory(unsigned int category, bool dontFlagDirty = false);
394 /** returns a list of all category-names */
395 void getCategoryList(vector<string> *list);
396 /** returns a list of all category-names */
397 void getCategoryList(QStringList *list);
398 /** returns a list of all entry-descs in the given category */
399 void getEntryList(const QString &category, QStringList *list);
400 /** returns a list of all entry-descs in the given category */
401 void getEntryList(const QString &category, vector<string> *list);
402 /** returns a list of all entry-descs in the given category */
403 void getEntryList(unsigned int category, vector<string> *list);
404 /** returns a list of all entry-descs in the given category */
405 void getEntryList(unsigned int category, QStringList *list);
406 /** delete entry */
407 bool delEntry(const QString &category, unsigned int index, bool dontFlagDirty = false);
408 /** delete entry */
409 bool delEntry(unsigned int category, unsigned int index, bool dontFlagDirty = false);
410 /** edit entry */
411 bool editEntry(const QString &oldCategory, const QString &newCategory,
412 unsigned int index, PwMDataItem *d, bool updateMeta = true);
413 /** edit entry */
414 bool editEntry(unsigned int oldCategory, const QString &newCategory,
415 unsigned int index, PwMDataItem *d, bool updateMeta = true);
416 /** finds the category with the "name" and return it's index */
417 bool findCategory(const QString &name, unsigned int *index);
418 /** search for an entry "find" and check while searching only for
419 * the data-fields specified by "searchIn". To set the "searchIn"
420 * value, we may use one or more of the SEARCH_IN_* defines at
421 * the top of this header-file. It returns the positions of all
422 * matched entries in "foundPositions". If "breakAfterFound" is true,
423 * the function terminates after the first occurence of the entry
424 * and doesn't go on searching. So foundPositions->size() is never
425 * > 1 if breakAfterFound is true.
426 */
427 void findEntry(unsigned int category, PwMDataItem find, unsigned int searchIn,
428 vector<unsigned int> *foundPositions, bool breakAfterFound = false,
429 bool caseSensitive = true, bool exactWordMatch = true,
430 bool sortByLvp = false);
431 /** see the above funtion. This function allows to set the category by name. */
432 void findEntry(const QString &category, PwMDataItem find, unsigned int searchIn,
433 vector<unsigned int> *foundPositions, bool breakAfterFound = false,
434 bool caseSensitive = true, bool exactWordMatch = true,
435 bool sortByLvp = false);
436 /** returns number of entries */
437 unsigned int numEntries(const QString &category);
438 unsigned int numEntries(unsigned int category)
439 { return dta[category].d.size(); }
440 /** returns number of categories */
441 unsigned int numCategories()
442 { return dta.size(); }
443 /** returns the name of the category at "index" */
444 const string* getCategory(unsigned int index)
445 { return (&(dta[index].name)); }
446 /** returns the data of item at "index".
447 * It unlocks the entry if it's locked and unlockIfLocked is true.
448 * If the entry is locked, but unlockIfLocked is false, it'll not return
449 * the pw.
450 */
451 bool getEntry(const QString &category, unsigned int index,
452 PwMDataItem *d, bool unlockIfLocked = false);
453 bool getEntry(unsigned int category, unsigned int index,
454 PwMDataItem *d, bool unlockIfLocked = false);
455 /** returns the comment-string by looking at the category
456 * and the listViewPos
457 */
458 PwMerror getCommentByLvp(const QString &category, int listViewPos,
459 string *foundComment);
460 /** checks if a password is already available. (currentPw) */
461 bool isPwAvailable()
462 { return (currentPw != ""); }
463 /** un/lock entry at "index". If needed, ask for password. */
464 bool lockAt(const QString &category, unsigned int index,
465 bool lock = true);
466 bool lockAt(unsigned int category, unsigned int index,
467 bool lock = true);
468 /** returns the lock-status at "index" */
469 bool isLocked(const QString &category, unsigned int index);
470 bool isLocked(unsigned int category, unsigned int index)
471 { return dta[category].d[index].lockStat; }
472 /** returns the deeplock status */
473 bool isDeepLocked()
474 { return getDocStatFlag(DOC_STAT_DEEPLOCKED); }
475 /** (un)lock all entries */
476 bool lockAll(bool lock);
477 /** unlocks all entries tempoarly.
478 * 1st NOTE: Be very careful with this function! :)
479 * 2nd NOTE: After you have called unlockAll_Tempoary(); ,
480 * please DON'T forget to call unlockAll_Tempoary(true);
481 * _before_ the user (or someone else) is able to change
482 * the document!
483 * 3rd NOTE: Please DON'T change "dta" while the data is tempoary
484 * unlocked! This will cause corruption.
485 */
486 bool unlockAll_tempoary(bool revert = false);
487 /** deep-(un)locks the document.
488 * deep-locking writes all data to the file, deletes all data
489 * in memory, but doesn't close the document.
490 * deep-locking is only available, if the user previously saved
491 * the doc to a file (with a password).
492 * If "saveToFile" is false, it does NOT write the data to the file!
493 */
494 PwMerror deepLock(bool lock = true, bool saveToFile = true);
495 /** is unlockable without pw? */
496 bool unlockWoPw()
497 { return getDocStatFlag(DOC_STAT_UNLOCK_WITHOUT_PW); }
498 /** get the "currentPassword" */
499 const QString& getCurrentPw()
500 { return currentPw; }
501 /** open a window and request the user to change the mpw */
502 void changeCurrentPw();
503 /** set the "listViewPos" variable of "dta" */
504 void setListViewPos(const QString &category, unsigned int index,
505 int pos);
506 /** set the "listViewPos" variable of "dta" */
507 void setListViewPos(unsigned int category, unsigned int index,
508 int pos);
509 /** get the "listViewPos" variable of "dta" */
510 int getListViewPos(const QString &category, unsigned int index);
511 /** set the maximum number of entries allowed */
512 void setMaxNumEntries(unsigned int num = DEFAULT_MAX_ENTRIES)
513 { maxEntries = num; }
514 /** get the maximum number of entries allowed */
515 unsigned int getMaxNumEntries()
516 { return maxEntries; }
517 /** ensure all listViewPos of all dta items are set. (are ! -1).
518 * If there are some undefined entries, add them to the end of
519 * the listViewPos(itions). */
520 void ensureLvp();
521 /** execute the "launcher" of this entry */
522 bool execLauncher(const QString &category, unsigned int entryIndex);
523 /** see above */
524 bool execLauncher(unsigned int category, unsigned int entryIndex);
525 /** open a browser with the URL-section of the given entry */
526 bool goToURL(const QString &category, unsigned int entryIndex);
527 /** see above */
528 bool goToURL(unsigned int category, unsigned int entryIndex);
529 /** returns true if there is no entry present in the document.
530 * Note: The "default" Category is present everytime, so
531 * it's checked for it's entries.
532 */
533 bool isDocEmpty()
534 {
535 if (numCategories() > 1)
536 return false;
537 if (numEntries(0))
538 return false;
539 return true;
540 }
541 /** returns the filename of this doc */
542 const QString& getFilename()
543 { return filename; }
544 /** returns the title of the doc */
545 QString getTitle();
546 /** sets the list-view-pointer hold in the doc */
547 void setListViewPointer(PwMView *_listView)
548 { listView = _listView; }
549 /** returns the list-view-pointer */
550 PwMView * getListViewPointer()
551 { return listView; }
552 /** try to delete the doc. The user may be asked to save
553 * the data. The user may cancel the whole operation.
554 * false is returned, then.
555 */
556 bool tryDelete();
557 /** is the doc deleted? (with tryDelete() ) */
558 bool isDeleted()
559 { return deleted; }
560 /** returns the document timer object */
561 DocTimer * timer()
562 { return _timer; }
563 /** get a lock on the dataChanged signal.
564 * If someone is holding a lock, the signal is not emitted.
565 */
566 void getDataChangedLock()
567 { ++dataChangedLock; }
568 /** put the dataChanged lock */
569 void putDataChangedLock()
570 { --dataChangedLock; }
571 /** returns the revision count of the item at cat/index */
572 unsigned int getEntryRevCnt(unsigned int category, unsigned int index)
573 { return dta[category].d[index].rev; }
574 /** returns a const pointer to the entries meta */
575 const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index)
576 { return &(dta[category].d[index].meta); }
577 /** is the entry at "category" "index" a binary entry? */
578 bool isBinEntry(unsigned int category, unsigned int index)
579 { return dta[category].d[index].binary; }
580
581public slots:
582 /** wrapper for PwMTray */
583 void _deepUnlock();
584
585signals:
586 /** the data of the document has changed and must be updated
587 * in all views.
588 * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal!
589 */
590 void dataChanged(PwMDoc *document);
591 /** the document class is going to close. This signal may be
592 * used to nofify all views, that the user closed the document,
593 * so the views can go down, too.
594 */
595 void docClosed(PwMDoc *document);
596 /** somebody just opened the document */
597 void docOpened(PwMDoc *document);
598 /** this document object just got created */
599 void docCreated(PwMDoc *document);
600
601public:
602 /** emit the dataChanged signal after checking for a lock */
603 void emitDataChanged(PwMDoc *document)
604 {
605 if (!dataChangedLock)
606 emit dataChanged(document);
607 }
608
609protected:
610 /** current file for this doc */
611 QString filename;
612 /** holds all data */
613 vector<PwMCategoryItem> dta;
614 /** maximum number of entries */
615 unsigned int maxEntries;
616 /** currently used password to encrypt data */
617 QString currentPw;
618 /** current global document status flags */
619 unsigned int curDocStat;
620 /** browser process for goToURL() */
621 KProcess browserProc;
622 /** pointer to the list-view, using this document.
623 * As there can only be one list-view per doc, we
624 * don't need a list here.
625 */
626 PwMView *listView;
627 /** unnamedNum is used to store the "unnamed counter"
628 * for this document, while it's unnamed. If it's 0,
629 * we have to get a new unique one.
630 */
631 unsigned int unnamedNum;
632 /** is this doc going to be deleted (executing in destructor context) */
633 bool deleted;
634 /** document timer */
635 DocTimer *_timer;
636 /** lock counter for the "dataChanged" signal */
637 unsigned int dataChangedLock;
638
639 /** list of all open documents */
640 static PwMDocList openDocList;
641
642protected:
643 /** serialize "dta" and return it in "d". */
644 bool serializeDta(string *d);
645 /** de-serialize "d" and overwrite "dta" */
646 bool deSerializeDta(const string *d, bool entriesLocked);
647 /** write header to file */
648 PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress,
649 QString *pw, QFile *f);
650 /** write data-hash to file */
651 PwMerror writeDataHash(char dataHash, string *d, QFile *f);
652 /** check header. Read header info and verify key-hash and filever.
653 * returns length of header in "headerLength" */
654 PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress,
655 unsigned int *headerLength, char *dataHashType,
656 string *dataHash, QFile *f);
657 /** check the data-hash */
658 PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream);
659 /** encrypt data "d" and write to "filename" */
660 PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo);
661 /** read data from file beginning at "pos", decrypt and return it */
662 PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f);
663 /** compress the data */
664 bool compressDta(string *d, char algo);
665 /** uncompress the data */
666 bool decompressDta(string *d, char algo);
667 /** internal import function for a text-file generated by PwM.
668 * If this is not a valid PwM-exported file, it returns e_fileFormat */
669 PwMerror importText_PwM(const QString *file);
670 /** PwM-text-import helper function to extract the name/pw/comment out
671 * of one entry-line */
672 bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out);
673 /** compare two strings */
674 bool compareString(const string &s1, const string &s2, bool caseSensitive,
675 bool exactWordMatch);
676 /** clears all document-data */
677 void clearDoc();
678 /** delete all empty categories */
679 void delAllEmptyCat(bool dontFlagDirty);
680 /** set a document status flag */
681 void setDocStatFlag(unsigned int statFlag)
682 { curDocStat |= statFlag; }
683 /** unset a document status flag */
684 void unsetDocStatFlag(unsigned int statFlag)
685 { curDocStat &= ~statFlag; }
686 /** get a document status flag */
687 bool getDocStatFlag(unsigned int statFlag) const
688 { return (curDocStat & statFlag); }
689 /** set the "currentPassword" */
690 void setCurrentPw(const QString &pw)
691 {
692 currentPw = pw;
693 setDocStatFlag(DOC_STAT_DISK_DIRTY);
694 }
695 /** make a backup-copy of the given file */
696 bool backupFile(const QString &filePath);
697 /** copy a file from src to dst */
698 bool copyFile(const QString &src, const QString &dst);
699};
700
701#endif
diff --git a/pwmanager/pwmanager/pwmdocui.cpp b/pwmanager/pwmanager/pwmdocui.cpp
new file mode 100644
index 0000000..66a1b59
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmdocui.cpp
@@ -0,0 +1,436 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "pwmdocui.h"
21#include "setmasterpwwndimpl.h"
22#include "getmasterpwwndimpl.h"
23#include "pwmexception.h"
24#include "getkeycardwnd.h"
25#include "pwm.h"
26#include "globalstuff.h"
27#include "spinforsignal.h"
28
29#include <qlineedit.h>
30#include <qtabwidget.h>
31
32#include <kmessagebox.h>
33#include <kfiledialog.h>
34
35#ifndef PWM_EMBEDDED
36#include <kwin.h>
37#else
38#endif
39
40
41#ifdef CONFIG_KEYCARD
42# include "pwmkeycard.h"
43#endif
44
45
46PwMDocUi::PwMDocUi(QObject *parent, const char *name)
47 : QObject(parent, name)
48{
49 currentView = 0;
50 keyCard = 0;
51}
52
53PwMDocUi::~PwMDocUi()
54{
55}
56
57QString PwMDocUi::requestMpw(bool chipcard)
58{
59 QString pw;
60
61 if (chipcard) {
62#ifdef CONFIG_KEYCARD
63 PWM_ASSERT(keyCard);
64 uint32_t id;
65 string ret;
66 SpinForSignal *spinner = keyCard->getSpinner();
67 connect(keyCard, SIGNAL(keyAvailable(uint32_t, const string &)),
68 spinner, SLOT(u32_str_slot(uint32_t, const string &)));
69 keyCard->getKey();
70 spinner->spin(&id, &ret);
71 disconnect(keyCard, SIGNAL(keyAvailable(uint32_t, const string &)),
72 spinner, SLOT(u32_str_slot(uint32_t, const string &)));
73 if (ret == "")
74 return "";
75 pw = ret.c_str();
76#else // CONFIG_KEYCARD
77 no_keycard_support_msg_box(currentView);
78#endif // CONFIG_KEYCARD
79 } else {
80 GetMasterPwWndImpl pwWnd;
81#ifndef PWM_EMBEDDED
82 KWin::setState(pwWnd.winId(), NET::StaysOnTop);
83#endif
84 if (pwWnd.exec() != 1)
85 return "";
86 pw = pwWnd.pwLineEdit->text();
87 }
88
89 return pw;
90}
91
92QString PwMDocUi::requestNewMpw(bool *chipcard)
93{
94 QString pw;
95 SetMasterPwWndImpl pwWnd(currentView);
96 pwWnd.setPwMKeyCard(keyCard);
97#ifndef PWM_EMBEDDED
98 if (!chipcard) {
99 pwWnd.mainTab->removePage(pwWnd.mainTab->page(1));
100 }
101#else
102 qDebug("PwMDocUi::requestNewMpw must be implemented");
103#endif
104
105 if (pwWnd.exec() != 1)
106 return "";
107 pw = pwWnd.getPw(chipcard).c_str();
108
109 return pw;
110}
111
112QString PwMDocUi::requestMpwChange(const QString *currentPw, bool *chipcard)
113{
114 QString pw(requestMpw(*chipcard));
115 if (pw == "")
116 return "";
117 if (pw != *currentPw) {
118 wrongMpwMsgBox(*chipcard);
119 return "";
120 }
121
122 pw = requestNewMpw(chipcard);
123 if (pw == "")
124 return "";
125 return pw;
126}
127
128void PwMDocUi::wrongMpwMsgBox(bool chipcard, QString prefix, QString postfix)
129{
130 QString msg;
131 if (prefix != "") {
132 msg += prefix;
133 msg += "\n";
134 }
135
136 if (chipcard) {
137 msg += i18n("Wrong key-card!\n"
138 "Please try again with the "
139 "correct key-card.");
140 } else {
141 msg += i18n("Wrong master-password!\n"
142 "Please try again.");
143 }
144
145 if (postfix != "") {
146 msg += "\n";
147 msg += postfix;
148 }
149 KMessageBox::error(currentView, msg,
150 (chipcard) ? (i18n("wrong chipcard"))
151 : (i18n("password error")));
152}
153
154void PwMDocUi::noMpwMsgBox(bool chipcard, QString prefix, QString postfix)
155{
156 QString msg;
157 if (prefix != "") {
158 msg += prefix;
159 msg += "\n";
160 }
161
162 if (chipcard) {
163 msg += i18n("No key-card found!\n"
164 "Please insert the "
165 "correct key-card.");
166 } else {
167 msg += i18n("No master-password given!");
168 }
169
170 if (postfix != "") {
171 msg += "\n";
172 msg += postfix;
173 }
174 KMessageBox::error(currentView, msg,
175 (chipcard) ? (i18n("no chipcard"))
176 : (i18n("password error")));
177}
178
179void PwMDocUi::rootAlertMsgBox()
180{
181 KMessageBox::error(currentView,
182 i18n("This feature is not available, "
183 "if you execute PwM with \"root\" "
184 "UID 0 privileges, for security reasons!"),
185 i18n("not allowed as root!"));
186}
187
188void PwMDocUi::cantDeeplock_notSavedMsgBox()
189{
190 KMessageBox::error(currentView,
191 i18n("Can't deep-lock, because the document "
192 "hasn't been saved, yet. Please save "
193 "to a file and try again."),
194 i18n("not saved, yet"));
195}
196
197void PwMDocUi::gpmPwLenErrMsgBox()
198{
199 KMessageBox::error(currentView,
200 i18n("GPasman does not support passwords "
201 "shorter than 4 characters! Please try "
202 "again with a longer password."),
203 i18n("password too short"));
204}
205
206int PwMDocUi::dirtyAskSave(const QString &docTitle)
207{
208 int ret;
209#ifndef PWM_EMBEDDED
210 ret = KMessageBox::questionYesNoCancel(currentView,
211 i18n("The list \"") +
212 docTitle +
213 i18n
214 ("\" has been modified.\n"
215 "Do you want to save it?"),
216 i18n("save?"));
217 if (ret == KMessageBox::Yes) {
218 return 0;
219 } else if (ret == KMessageBox::No) {
220 return 1;
221 }
222#else
223 ret = KMessageBox::warningYesNoCancel(currentView,
224 i18n("The list \"") +
225 docTitle +
226 i18n
227 ("\" has been modified.\n"
228 "Do you want to save it?"),
229 i18n("save?"));
230 if (ret == KMessageBox::Yes) {
231 return 0;
232 } else if (ret == KMessageBox::No) {
233 return 1;
234 }
235
236#endif
237
238 // cancel
239 return -1;
240}
241
242bool PwMDocUi::saveDocUi(PwMDoc *doc)
243{
244 PWM_ASSERT(doc);
245 doc->timer()->getLock(DocTimer::id_autoLockTimer);
246 if (doc->isDocEmpty()) {
247 KMessageBox::information(currentView,
248 i18n
249 ("Sorry, there's nothing to save.\n"
250 "Please first add some passwords."),
251 i18n("nothing to do"));
252 doc->timer()->putLock(DocTimer::id_autoLockTimer);
253 return true;
254 }
255 PwMerror ret = doc->saveDoc(conf()->confGlobCompression());
256 if (ret == e_filename) {
257 doc->timer()->putLock(DocTimer::id_autoLockTimer);
258 return saveAsDocUi(doc);
259 } else if (ret == e_weakPw) {
260 KMessageBox::error(currentView,
261 i18n("Error: This is a weak password.\n"
262 "Please select another password."),
263 i18n("weak password"));
264 doc->timer()->putLock(DocTimer::id_autoLockTimer);
265 return false;
266 } else if (ret == e_fileBackup) {
267 KMessageBox::error(currentView,
268 i18n("Error: Couldn't make backup-file!"),
269 i18n("backup failed"));
270 doc->timer()->putLock(DocTimer::id_autoLockTimer);
271 return false;
272 } else if (ret != e_success) {
273 KMessageBox::error(currentView,
274 i18n("Error: Couldn't write to file.\n"
275 "Please check if you have permission to "
276 "write to the file in that directory."),
277 i18n("error while writing"));
278 doc->timer()->putLock(DocTimer::id_autoLockTimer);
279 return false;
280 }
281 doc->timer()->putLock(DocTimer::id_autoLockTimer);
282 return true;
283}
284
285bool PwMDocUi::saveAsDocUi(PwMDoc *doc)
286{
287 PWM_ASSERT(doc);
288 doc->timer()->getLock(DocTimer::id_autoLockTimer);
289 if (doc->isDocEmpty()) {
290 KMessageBox::information(currentView,
291 i18n
292 ("Sorry, there's nothing to save.\n"
293 "Please first add some passwords."),
294 i18n("nothing to do"));
295 doc->timer()->putLock(DocTimer::id_autoLockTimer);
296 return true;
297 }
298 QString fn(KFileDialog::getSaveFileName(QString::null,
299 i18n("*.pwm|PwManager Password file"),
300 currentView));
301 if (fn == "") {
302 doc->timer()->putLock(DocTimer::id_autoLockTimer);
303 return false;
304 }
305 if (fn.right(4) != ".pwm")
306 fn += ".pwm";
307
308 PwMerror ret = doc->saveDoc(conf()->confGlobCompression(), &fn);
309 if (ret != e_success) {
310 KMessageBox::error(currentView,
311 i18n("Error: Couldn't write to file.\n"
312 "Please check if you have permission to "
313 "write to the file in that directory."),
314 i18n("error while writing"));
315 doc->timer()->putLock(DocTimer::id_autoLockTimer);
316 return false;
317 }
318 doc->timer()->putLock(DocTimer::id_autoLockTimer);
319 return true;
320}
321
322bool PwMDocUi::openDocUi(PwMDoc *doc,
323 QString filename,
324 bool openDeepLocked)
325{
326 if (filename.isEmpty())
327 filename = KFileDialog::getOpenFileName(QString::null,
328 i18n("*.pwm|PwManager Password file\n"
329 "*|All files"), getCurrentView());
330 if (filename.isEmpty())
331 goto cancelOpen;
332 PwMerror ret;
333 while (true) {
334 int lockStat = -1;
335 if (openDeepLocked) {
336 lockStat = 2;
337 } else {
338 if (conf()->confGlobUnlockOnOpen()) {
339 lockStat = 0;
340 } else {
341 lockStat = 1;
342 }
343 }
344 ret = doc->openDoc(&filename, lockStat);
345 if (ret != e_success) {
346 if (ret == e_readFile || ret == e_openFile) {
347 KMessageBox::error(getCurrentView(),
348 i18n("Could not read file!")
349 + "\n"
350 + filename,
351 i18n("file error"));
352 goto cancelOpen;
353 }
354 if (ret == e_alreadyOpen) {
355 KMessageBox::error(getCurrentView(),
356 i18n("This file is already open."),
357 i18n("already open"));
358 goto cancelOpen;
359 }
360 if (ret == e_fileVer) {
361 KMessageBox::error(getCurrentView(),
362 i18n
363 ("File-version is not supported!\n"
364 "Did you create this file with an older or newer version of PwM?"),
365 i18n
366 ("incompatible version"));
367 goto cancelOpen;
368 }
369 if (ret == e_wrongPw) {
370 continue;
371 }
372 if (ret == e_noPw) {
373 goto cancelOpen;
374 }
375 if (ret == e_fileFormat) {
376 KMessageBox::error(getCurrentView(),
377 i18n
378 ("Sorry, this file has not been recognized "
379 "as a PwM Password file.\n"
380 "Probably you have selected the wrong file."),
381 i18n
382 ("no PwM password-file"));
383 goto cancelOpen;
384 }
385 if (ret == e_fileCorrupt) {
386 KMessageBox::error(getCurrentView(),
387 i18n
388 ("File corrupt!\n"
389 "Maybe the media, you stored this file on, "
390 "had bad sectors?"),
391 i18n
392 ("checksum error"));
393 goto cancelOpen;
394 }
395 }
396 break;
397 }
398 return true;
399
400 cancelOpen:
401 return false;
402}
403
404QString PwMDocUi::string_defaultCategory()
405{
406 return i18n("Default");
407}
408
409QString PwMDocUi::string_locked()
410{
411 return i18n("<LOCKED>");
412}
413
414QString PwMDocUi::string_deepLockedShort()
415{
416 return i18n("DEEP-LOCKED");
417}
418
419QString PwMDocUi::string_deepLockedLong()
420{
421 return i18n("This file is DEEP-LOCKED!\n"
422 "That means all data has been encrypted "
423 "and written out to the file. If you want "
424 "to see the entries, please UNLOCK the file. "
425 "While unlocking, you will be prompted for the "
426 "master-password or the key-card.");
427}
428
429QString PwMDocUi::string_defaultTitle()
430{
431 return i18n("Untitled");
432}
433
434#ifndef PWM_EMBEDDED
435#include "pwmdocui.moc"
436#endif
diff --git a/pwmanager/pwmanager/pwmdocui.h b/pwmanager/pwmanager/pwmdocui.h
new file mode 100644
index 0000000..4ee0ad4
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmdocui.h
@@ -0,0 +1,129 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef __PWMDOCUI_H
21#define __PWMDOCUI_H
22
23#include <qwidget.h>
24#include <klocale.h>
25
26/** string to display, if the pw-entry
27 * is locked, in place of the password.
28 */
29 #define LOCKED_STRING PwMDocUi::string_locked()
30
31/** The name of the "default" category */
32 #define DEFAULT_CATEGORYPwMDocUi::string_defaultCategory()
33
34/** deep-lock message to display in main-view, if it's locked */
35 #define IS_DEEPLOCKED_SHORTMSGPwMDocUi::string_deepLockedShort()
36 #define IS_DEEPLOCKED_MSGPwMDocUi::string_deepLockedLong()
37
38/** default title. Display if the doc has no title, yet */
39 #define DEFAULT_TITLE PwMDocUi::string_defaultTitle()
40
41class PwMKeyCard;
42class PwMDoc;
43
44/** User-interface layer for PwMDoc.
45 * This class handles for example all Master-password related things (asking
46 * the user for the password od the chipcard) and some
47 * other UI-things, that PwMDoc is not allowed to
48 * handle. (PwMDoc is _NOT_ allowed to handle anything
49 * UI related.)
50 */
51class PwMDocUi : public QObject
52{
53 Q_OBJECT
54public:
55 PwMDocUi(QObject* parent = 0, const char *name = 0);
56 ~PwMDocUi();
57
58 /** when a new view is activated, call this to
59 * inform the Master-password-layer about this.
60 */
61 void setCurrentView(QWidget *view)
62 { currentView = view; }
63 /** return the currentView pointer */
64 QWidget* getCurrentView()
65 { return currentView; }
66 /** set pointer to the keycard-access object */
67 void setPwMKeyCard(PwMKeyCard *_keyCard)
68 { keyCard = _keyCard; }
69 /** saves the document (with user dialog) */
70 bool saveDocUi(PwMDoc *doc);
71 /** save as (with user dialog) */
72 bool saveAsDocUi(PwMDoc *doc);
73 /** opens a new document (with user dialog) */
74 bool openDocUi(PwMDoc *doc,
75 QString filename = QString::null,
76 bool openDeepLocked = false);
77
78 static QString string_defaultCategory();
79 static QString string_locked();
80 static QString string_deepLockedShort();
81 static QString string_deepLockedLong();
82 static QString string_defaultTitle();
83
84protected:
85 /** request the user to enter the master-password or
86 * to insert his chipcard.
87 * If forcePw is true, it will always ask for a pw
88 * and never for a chipcard.
89 */
90 QString requestMpw(bool chipcard);
91 /** request the user to enter a new master-password of
92 * to create a new chipcard.
93 * It "chipcard" is a NULL pointer, chipcards will not be
94 * allowed.
95 */
96 QString requestNewMpw(bool *chipcard);
97 /** request a master-pw change.(or chipcard change).
98 * This function asks the user and requests the pw
99 */
100 QString requestMpwChange(const QString *currentPw, bool *chipcard);
101 /** informs the user, that he entered the wrong mpw.
102 * It opens a message-box
103 */
104 void wrongMpwMsgBox(bool chipcard,
105 QString prefix = "",
106 QString postfix = "");
107 /** informs the user, that the mpw is needed, but he
108 * didn't enter one
109 */
110 void noMpwMsgBox(bool chipcard,
111 QString prefix = "",
112 QString postfix = "");
113 /** display "feature not availavle while UID 0" msg box */
114 void rootAlertMsgBox();
115 /** display "can't deeplock, because not saved yet" msg box */
116 void cantDeeplock_notSavedMsgBox();
117 /** gpasman-export password length error */
118 void gpmPwLenErrMsgBox();
119 /** ask for saving */
120 int dirtyAskSave(const QString &docTitle);
121
122private:
123 /** the currently active view */
124 QWidget *currentView;
125 /** pointer to the keycard-access object */
126 PwMKeyCard *keyCard;
127};
128
129#endif
diff --git a/pwmanager/pwmanager/pwmexception.cpp b/pwmanager/pwmanager/pwmexception.cpp
new file mode 100644
index 0000000..4c00b04
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmexception.cpp
@@ -0,0 +1,58 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20
21#include "pwmexception.h"
22
23#include <kmessagebox.h>
24
25
26void pwmFatal(const char *id,
27 const char *file,
28 int line)
29{
30 cerr << PROG_NAME " " << id << " at "
31 << file << ":" << line
32 << endl;
33}
34
35void __printError(const string &msg)
36{
37 QString __msg(PROG_NAME " generated a fatal fault:\n");
38 __msg += msg.c_str();
39 cerr << "\n\n" << __msg.latin1() << endl;
40 KMessageBox::error(0, __msg, PROG_NAME " fatal ERROR!");
41}
42
43void __printInfo(const string &msg)
44{
45 cout << PROG_NAME " INFO: " << msg << endl;
46}
47
48void __printWarn(const string &msg)
49{
50 cerr << PROG_NAME " WARNING: " << msg << endl;
51}
52
53#ifdef PWM_DEBUG
54void __printDebug(const string &msg)
55{
56 cout << PROG_NAME " DEBUG: " << msg << endl;
57}
58#endif // PWM_DEBUG
diff --git a/pwmanager/pwmanager/pwmexception.h b/pwmanager/pwmanager/pwmexception.h
new file mode 100644
index 0000000..c8a8c0f
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmexception.h
@@ -0,0 +1,216 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef __PWMEXCEPTION_H
21#define __PWMEXCEPTION_H
22
23#include "globalstuff.h"
24
25#include <iostream>
26#include <string>
27using std::string;
28using std::cerr;
29using std::cout;
30using std::endl;
31
32/* This is an internal function to reduce code-overhead
33 * of the BUG(), WARN(), TOD0() and FiXME() macros. Please use
34 * these macros instead of calling this function directly.
35 */
36void pwmFatal(const char *id,
37 const char *file,
38 int line);
39
40/** Use PWM_ASSERT(condition) for debugging assertions.
41 * "condition" is eaten up and replaced with a NOP
42 * when debugging is disabled.
43 *
44 * PWM_ASSERT_NOEAT(condition) is the same as PWM_ASSERT(condition),
45 * but it does _not_ eat up "condition" and ensures that
46 * condition is always evaluated.
47 */
48#ifdef PWM_ASSERT
49# undef PWM_ASSERT
50#endif
51#ifdef PWM_ASSERT_NOEAT
52# undef PWM_ASSERT_NOEAT
53#endif
54#ifdef PWM_DEBUG
55 # define PWM_ASSERT(x) do { \
56 if (unlikely(!(x))) { \
57 cerr << "PWM_ASSERT failed: (" << #x\
58 << ") in " << __FILE__ \
59 << ":" << __LINE__ \
60 << endl; \
61 } \
62 } while (0)
63 # define PWM_ASSERT_NOEAT(x)do { PWM_ASSERT(x); } while (0)
64#else // PWM_DEBUG
65 # define PWM_ASSERT(x) do { } while (0)
66 # define PWM_ASSERT_NOEAT(x)do { if (x) ; } while (0)
67#endif // PWM_DEBUG
68
69/** Insert a BUG() into code paths which clearly show
70 * a bug in the code and which should, under normal
71 * circumstances, never execute.
72 */
73#ifdef BUG
74# undef BUG
75#endif
76 #define BUG()do { pwmFatal("BUG", __FILE__, __LINE__); } while (0)
77
78/** Use BUG_ON(condition) to print a bug-message if "condition"
79 * is true. This is also enabled in non-debugging code.
80 */
81#ifdef BUG_ON
82# undef BUG_ON
83#endif
84 #define BUG_ON(x) do { if (unlikely(x))BUG(); } while (0)
85
86/** Insert a WARN() into code-paths which should not
87 * execute normally, but if they do it's non-fatal.
88 */
89#ifdef WARN
90# undef WARN
91#endif
92 #define WARN()do { pwmFatal("badness", __FILE__, __LINE__); } while (0)
93
94/** Same as BUG_ON() but prints a warning-message */
95#ifdef WARN_ON
96# undef WARN_ON
97#endif
98 #define WARN_ON(x) do { if (unlikely(x))WARN(); } while (0)
99
100/** Insert this into code which is incomplete */
101#ifdef TODO
102# undef TODO
103#endif
104 #define TODO()do { pwmFatal("TODO", __FILE__, __LINE__); } while (0)
105
106/** Insert this into code which likely contains bugs */
107#ifdef FIXME
108# undef FIXME
109#endif
110 #define FIXME()do { pwmFatal("FIXME", __FILE__, __LINE__); } while (0)
111
112
113/** PwM error codes */
114enum PwMerror {
115 e_success = 0,
116
117 // file access errors
118 e_filename,
119 e_readFile,
120 e_writeFile,
121 e_openFile,
122 e_accessFile, // permission error, etc...
123 e_fileGeneric,
124 e_alreadyOpen,
125
126 // other file errors
127 e_fileVer,
128 e_fileFormat, // format error
129 e_unsupportedFormat,// completely unsupported format
130 e_setFilePointer,
131 e_fileBackup,
132 e_fileCorrupt, // file data has correct format,
133 // but is corrupt (checksum error, etc)
134
135 // password errors
136 e_wrongPw,
137 e_getPw,
138 e_weakPw,
139 e_noPw,
140
141 // action not implemented errors
142 e_hashNotImpl,
143 e_cryptNotImpl,
144
145 // argument/parameter errors
146 e_incompleteArg,
147 e_invalidArg,
148
149 // misc
150 e_writeHeader,
151 e_serializeDta,
152 e_enc,
153 e_entryExists,
154 e_categoryExists,
155 e_maxAllowedEntr,// no more entries can be added.
156 e_outOfMem,
157 e_lock, // error while (un)locking
158 e_docNotSaved, // doc wasn't saved to a file, yet.
159 e_docIsEmpty,
160 e_binEntry,
161 e_normalEntry,
162
163 e_generic
164};
165
166/** can be used for general exception faults */
167class PwMException
168{
169public:
170 enum exceptionId
171 {
172 EX_GENERIC = 0,
173 EX_OPEN,
174 EX_CLOSE,
175 EX_READ,
176 EX_WRITE,
177 EX_LOAD_MODULE,
178 EX_PARSE
179 };
180
181public:
182 PwMException(exceptionId id = EX_GENERIC,
183 const char *message = "")
184 {
185 exId = id;
186 exMsg = message;
187 }
188
189 exceptionId getId()
190 { return exId; }
191 const char* getMessage()
192 { return exMsg; }
193
194protected:
195 /** ID of this exception */
196 exceptionId exId;
197 /** additional error-message for this exception */
198 const char *exMsg;
199};
200
201void __printInfo(const string &msg);
202void __printWarn(const string &msg);
203void __printError(const string &msg);
204
205#ifdef PWM_DEBUG
206 void __printDebug(const string &msg);
207 # define printDebug(x)__printDebug(x)
208#else
209 # define printDebug(x)do { } while (0)
210#endif
211
212 #define printInfo(x)__printInfo(x)
213 #define printWarn(x)__printWarn(x)
214 #define printError(x)__printError(x)
215
216#endif // __PWMEXCEPTION_H
diff --git a/pwmanager/pwmanager/pwminit.cpp b/pwmanager/pwmanager/pwminit.cpp
new file mode 100644
index 0000000..b0a78c2
--- a/dev/null
+++ b/pwmanager/pwmanager/pwminit.cpp
@@ -0,0 +1,617 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "pwminit.h"
21#include "configuration.h"
22#include "randomizer.h"
23
24#ifndef PWM_EMBEDDED
25#include "selftest.h"
26#endif
27
28#include "pwm.h"
29#include "pwmexception.h"
30#include "pwmtray.h"
31#include "pwmdoc.h"
32
33#ifdef CONFIG_KWALLETIF
34# include "kwalletemu.h"
35#endif // CONFIG_KWALLETIF
36#ifdef CONFIG_KEYCARD
37# include "pwmkeycard.h"
38#endif // CONFIG_KEYCARD
39
40#include <qmessagebox.h>
41
42#include <kmessagebox.h>
43#ifndef PWM_EMBEDDED
44#include <kcmdlineargs.h>
45#include <kwin.h>
46#include <dcopclient.h>
47#endif
48
49#include <kapplication.h>
50#include <kiconloader.h>
51
52#include <signal.h>
53
54static PwMInit *sig_init_pointer;
55static NOREGPARM void sig_handler(int signum)
56{
57 switch (signum) {
58 case SIGINT:
59 case SIGTERM:
60 sig_init_pointer->shutdownApp(20 + signum);
61 break;
62 default:
63 printDebug(string("unhandled signal ")
64 + tostr(signum));
65 }
66}
67
68
69
70
71PwMInit::PwMInit(PwMApplication *_app)
72 : runStatus (unknown)
73 , _curWidget (0)
74 , _dcopClient (0)
75 , _kwalletEmu (0)
76 , _keycard (0)
77 , _tray (0)
78{
79 sig_init_pointer = this;
80 app = _app;
81}
82
83PwMInit::~PwMInit()
84{
85#ifndef PWM_EMBEDDED
86 SelfTest::cancel();
87 // close all open mainwnds
88 QValueList<PwM *>::iterator i = _mainWndList.begin(),
89 end = _mainWndList.end();
90
91#else
92 // close all open mainwnds
93 QValueList<PwM *>::Iterator i = _mainWndList.begin(),
94 end = _mainWndList.end();
95#endif
96 while (i != end) {
97 disconnect(*i, SIGNAL(closed(PwM *)),
98 this, SLOT(mainWndClosed(PwM *)));
99 delete *i;
100 ++i;
101 }
102 _mainWndList.clear();
103 // close all remaining open documents
104 PwMDocList *_dl = PwMDoc::getOpenDocList();
105 vector<PwMDocList::listItem> dl = *(_dl->getList());
106 vector<PwMDocList::listItem>::iterator i2 = dl.begin(),
107 end2 = dl.end();
108 while (i2 != end2) {
109 delete (*i2).doc;
110 ++i2;
111 }
112
113#ifdef CONFIG_KWALLETIF
114 delete_ifnot_null(_kwalletEmu);
115#endif // CONFIG_KWALLETIF
116#ifdef CONFIG_KEYCARD
117 delete_ifnot_null(_keycard);
118#endif // CONFIG_KEYCARD
119 delete_ifnot_null(_tray);
120
121 Randomizer::cleanup();
122 Configuration::cleanup();
123}
124
125void PwMInit::initializeApp()
126{
127 PWM_ASSERT(runStatus == unknown);
128 runStatus = init;
129 initPosixSignalHandler();
130 Randomizer::init();
131 Configuration::init();
132 initDCOP();
133 initKWalletEmu();
134 initKeycard();
135 initTray();
136 handleCmdLineArgs();
137
138 bool openDeeplocked = false;
139 if (conf()->confGlobAutostartDeepLocked() ||
140 savedCmd.open_deeplocked)
141 openDeeplocked = true;
142 if (conf()->confWndAutoMinimizeOnStart() ||
143 savedCmd.minToTray) {
144 PwMDoc *newDoc = createDoc();
145 if (!newDoc->openDocUi(newDoc,
146 conf()->confGlobAutoStart(),
147 openDeeplocked)) {
148 delete newDoc;
149 }
150 } else {
151 createMainWnd(conf()->confGlobAutoStart(),
152 openDeeplocked,
153 true,
154 0,
155 savedCmd.minimized);
156 }
157
158 runStatus = running;
159}
160
161void PwMInit::shutdownApp(int exitStatus)
162{
163 printDebug(string("PwMInit::shutdownApp(")
164 + tostr(exitStatus) + ") called.");
165 PWM_ASSERT((runStatus == running) || (runStatus == init));
166 runStatus = shutdown;
167 QApplication::exit(exitStatus);
168 /* The destructor of PwMInit is called when control
169 * leaves main()
170 */
171}
172
173void PwMInit::initPosixSignalHandler()
174{
175 signal(SIGINT, sig_handler);
176 signal(SIGTERM, sig_handler);
177}
178
179void PwMInit::initDCOP()
180{
181#ifndef PWM_EMBEDDED
182 _dcopClient = app->dcopClient();
183 _dcopClient->setNotifications(true);
184#else
185 qDebug("PwMInit::initDCOP() has to be implemented");
186#endif
187
188}
189
190void PwMInit::initKWalletEmu(bool forceDisable, bool forceReload)
191{
192#ifdef CONFIG_KWALLETIF
193 if (!conf()->confGlobKwalletEmu() ||
194 forceDisable) {
195 delete_ifnot_null(_kwalletEmu);
196 return;
197 }
198 try {
199 if (_kwalletEmu && forceReload)
200 delete_and_null(_kwalletEmu);
201 if (!_kwalletEmu)
202 _kwalletEmu = new KWalletEmu(this);
203 } catch (PwMException e) {
204 string errMsg("initializing KWallet emulation failed. ID: ");
205 errMsg += tostr(static_cast<int>(e.getId()));
206 errMsg += " err-message: ";
207 errMsg += e.getMessage();
208 printWarn(errMsg);
209 return;
210 }
211#else // CONFIG_KWALLETIF
212 PARAM_UNUSED(forceDisable);
213 PARAM_UNUSED(forceReload);
214#endif // CONFIG_KWALLETIF
215}
216
217void PwMInit::initKeycard()
218{
219#ifdef CONFIG_KEYCARD
220 PWM_ASSERT(!_keycard);
221 _keycard = new PwMKeyCard(this);
222#endif // CONFIG_KEYCARD
223}
224
225void PwMInit::initTray()
226{
227#ifdef PWM_EMBEDDED
228 //US ENH : embedded version does not support a tray
229 return;
230#endif
231
232 if (!conf()->confGlobTray()) {
233 if (!_tray)
234 return;
235 _tray->hide();
236 delete_and_null(_tray);
237 return;
238 }
239 if (_tray)
240 return;
241 _tray = new PwMTray(this);
242 connect(_tray, SIGNAL(quitSelected()),
243 this, SLOT(removeTrayAndQuit()));
244 connect(_tray, SIGNAL(closed(PwMTray *)),
245 this, SLOT(trayIconClosed(PwMTray *)));
246 KIconLoader icons;
247#ifndef PWM_EMBEDDED
248 _tray->setPixmap(icons.loadIcon(PACKAGE_NAME, KIcon::Small));
249#endif
250 _tray->show();
251 // connect the signals of all open documents.
252 const vector<PwMDocList::listItem> *dl = PwMDoc::getOpenDocList()->getList();
253 vector<PwMDocList::listItem>::const_iterator i = dl->begin(),
254 end = dl->end();
255 while (i != end) {
256 _tray->connectDocToTray((*i).doc);
257 ++i;
258 }
259}
260
261void PwMInit::removeTrayAndQuit()
262{
263 PWM_ASSERT(_tray);
264 // _tray is deleted in ~PwMInit
265 shutdownApp(0);
266}
267
268PwM * PwMInit::createMainWnd(const QString &loadFile,
269 bool loadFileDeepLocked,
270 bool virginity,
271 PwMDoc *doc,
272 bool minimized)
273{
274 PwM *newWnd;
275 if (!doc)
276 doc = createDoc();
277 newWnd = new PwM(this, doc, virginity);
278#ifndef PWM_EMBEDDED
279 _mainWndList.push_back(newWnd);
280#else
281 _mainWndList.append(newWnd);
282#endif
283 connect(newWnd, SIGNAL(closed(PwM *)),
284 this, SLOT(mainWndClosed(PwM *)));
285 connect(newWnd, SIGNAL(gotFocus(PwM *)),
286 this, SLOT(setCurWidget(PwM *)));
287 connect(newWnd, SIGNAL(lostFocus(PwM *)),
288 this, SLOT(resetCurWidget()));
289
290 //US ENH
291#ifndef PWM_EMBEDDED
292 if (minimized)
293 newWnd->showMinimized();
294 else
295 newWnd->show();
296
297#else //PWM_EMBEDDED
298
299#ifndef DESKTOP_VERSION
300 app->showMainWidget( newWnd );
301#else //DESKTOP_VERSION
302 app->setMainWidget( newWnd );
303 newWnd->resize (640, 480 );
304 newWnd->show();
305#endif //DESKTOP_VERSION
306
307#endif //PWM_EMBEDDED
308
309 if (loadFile != QString::null &&
310 loadFile != "") {
311 newWnd->openDoc(loadFile, loadFileDeepLocked);
312 }
313 return newWnd;
314}
315
316PwMDoc * PwMInit::createDoc()
317{
318 PwMDoc *doc = new PwMDoc(this);
319#ifdef CONFIG_KEYCARD
320 doc->setPwMKeyCard(keycard());
321#endif
322#ifdef CONFIG_KWALLETIF
323 if (kwalletEmu())
324 kwalletEmu()->connectDocSignals(doc);
325#endif
326
327 if (_tray)
328 _tray->connectDocToTray(doc);
329
330 return doc;
331
332}
333
334void PwMInit::mainWndClosed(PwM *wnd)
335{
336 bool doMinimizeToTray = false;
337 bool doDeleteDoc = false;
338#ifndef PWM_EMBEDDED
339 dcopClient()->suspend();
340 dcopClient()->setAcceptCalls(false);
341#endif
342again:
343
344 if (wnd->isForceMinimizeToTray()) {
345 if (unlikely(!_tray)) {
346 /* This should not happen! If we set forceMinimizeToTray ,
347 * we must be sure that _tray exists.
348 */
349 BUG();
350 wnd->setForceMinimizeToTray(false);
351 goto again;
352 }
353 doMinimizeToTray = true;
354 } else {
355 // Ask to minimize to tray. If not, delete doc.
356 if (_tray &&
357 runStatus != shutdown &&
358 !wnd->isForceQuit() &&
359 !wnd->curDoc()->isDeleted()) {
360 if (conf()->confWndClose())
361 doDeleteDoc = true;
362 else
363 doMinimizeToTray = true;
364 } else {
365 doDeleteDoc = true;
366 }
367 }
368
369 if (doMinimizeToTray) {
370
371 PWM_ASSERT(_tray);
372 int mmlock = conf()->confGlobMinimizeLock();
373 switch (mmlock) {
374 case 0: // don't lock anything
375 break;
376 case 1: // normal lock
377 wnd->curDoc()->lockAll(true);
378 break;
379 case 2: // deep-lock
380 wnd->curDoc()->deepLock();
381 break;
382 default:
383 WARN();
384 }
385 } else if (doDeleteDoc) {
386 if (!wnd->curDoc()->tryDelete()) {
387 /* We failed deleting the doc,
388 * so open a new window with it, again.
389 */
390 createMainWnd(QString::null, false,
391 false, wnd->curDoc());
392 }
393 }
394#ifndef PWM_EMBEDDED
395 // find the closed window in the "mainWndList" and delete it.
396 QValueList<PwM *>::iterator i = _mainWndList.begin(),
397 end = _mainWndList.end();
398#else
399 // find the closed window in the "mainWndList" and delete it.
400 QValueList<PwM *>::Iterator i = _mainWndList.begin(),
401 end = _mainWndList.end();
402#endif
403 while (i != end) {
404 if (*i == wnd) {
405#ifndef PWM_EMBEDDED
406 _mainWndList.erase(i);
407#else
408 _mainWndList.remove(i);
409#endif
410 goto out_success;
411 }
412 ++i;
413 }
414 BUG();
415out_success:
416#ifndef PWM_EMBEDDED
417 if (!_mainWndList.size())
418#else
419 if (!_mainWndList.count())
420#endif
421
422 {
423 /* If there's no main window and no tray icon
424 * left, we have no user interface, so we can
425 * shut down the application.
426 */
427 if (!_tray) {
428#ifndef PWM_EMBEDDED
429 dcopClient()->setAcceptCalls(true);
430 dcopClient()->resume();
431#endif
432 shutdownApp(0);
433 return;
434 }
435 /* There is no widget left, so set
436 * _curWidget to 0
437 */
438 resetCurWidget();
439 }
440#ifndef PWM_EMBEDDED
441 dcopClient()->setAcceptCalls(true);
442 dcopClient()->resume();
443#endif
444}
445
446void PwMInit::trayIconClosed(PwMTray *tray)
447{
448 if (runStatus != running)
449 return;
450 PARAM_UNUSED(tray);
451 PWM_ASSERT(tray == _tray);
452 /* If there's no main wnd left we have to
453 * shutdown the app (same as in mainWndClosed())
454 */
455#ifndef PWM_EMBEDDED
456 if (!_mainWndList.size())
457 shutdownApp(0);
458#else
459 if (!_mainWndList.count())
460 shutdownApp(0);
461#endif
462}
463
464void PwMInit::handleCmdLineArgs(bool initial)
465{
466#ifndef PWM_EMBEDDED
467 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
468 PWM_ASSERT(args);
469 int i, numArgs = args->count();
470 const char *curArg;
471
472 // read all cmdline options
473 savedCmd.open_deeplocked = args->isSet("open-deeplocked");
474 savedCmd.minimized = args->isSet("minimized");
475 savedCmd.minToTray = args->isSet("mintray");
476 savedCmd.skipSelfTest = args->isSet("skip-self-test");
477 if (savedCmd.minimized &&
478 savedCmd.minToTray) {
479 printInfo(i18n("Commandline option \"--minimized\" and "
480 "\"--mintray\" selected. These are incompatible. "
481 "\"--mintray\" will be selected.").latin1());
482 }
483 /* Iterate through all non-option arguments.
484 * Every non-option arg is a filename to open.
485 */
486 for (i = 0; i < numArgs; ++i) {
487 curArg = args->arg(i);
488 PWM_ASSERT(curArg);
489 if (savedCmd.minToTray) {
490 PwMDoc *newDoc = createDoc();
491 if (!newDoc->openDocUi(newDoc,
492 curArg,
493 savedCmd.open_deeplocked)) {
494 delete newDoc;
495 }
496 } else {
497 PwM *newInstance = createMainWnd(QString::null,
498 false,
499 true,
500 0,
501 savedCmd.minimized);
502 PwMDoc *newDoc = newInstance->openDoc(curArg,
503 savedCmd.open_deeplocked);
504 if (!newDoc) {
505 newInstance->setForceQuit(true);
506 delete_and_null(newInstance);
507 }
508 }
509 }
510
511 if (savedCmd.minToTray) {
512 minimizeAllMainWnd(true);
513 } else if (savedCmd.minimized) {
514 minimizeAllMainWnd(false);
515 }
516 if (!savedCmd.skipSelfTest && initial) {
517 SelfTest::schedule();
518 }
519 args->clear();
520#endif
521}
522
523void PwMInit::minimizeAllMainWnd(bool toTray)
524{
525#ifndef PWM_EMBEDDED
526 if (!_mainWndList.size())
527 return;
528#else
529 if (!_mainWndList.count())
530 return;
531#endif
532 const QValueList<PwM *> *ml = mainWndList();
533#ifndef PWM_EMBEDDED
534 QValueList<PwM *>::const_iterator it = ml->begin(),
535 end = ml->end();
536#else
537 QValueList<PwM *>::ConstIterator it = ml->begin(),
538 end = ml->end();
539#endif
540 PwM *wnd;
541 if (toTray && _tray) {
542 /* minimize to tray.
543 * close all mainWnd.
544 */
545 while (it != end) {
546 wnd = *it;
547 wnd->setForceMinimizeToTray(true);
548 wnd->close_slot();
549 ++it;
550 }
551 } else {
552 // normal minimize
553 while (it != end) {
554 wnd = *it;
555 wnd->hide();
556 wnd->showMinimized();
557 ++it;
558 }
559 }
560}
561
562#ifdef PWM_EMBEDDED
563
564#ifndef DESKTOP_VERSION
565
566PwMApplication::PwMApplication(int & argc, char ** argv)
567 : QPEApplication( argc, argv )
568 , init (0)
569{
570 this->setKeepRunning ();
571}
572
573PwMApplication::~PwMApplication()
574{
575 delete_ifnot_null(init);
576}
577#else //DESKTOP_VERSION
578
579PwMApplication::PwMApplication(int & argc, char ** argv)
580 : QApplication( argc, argv )
581 , init (0)
582{
583 setStyle( new QPlatinumStyle ());
584 QString hdir = QDir::homeDirPath();
585 // there is a bug when creating dirs for WIN 98
586 // it is difficult to fix, because we have no WIN 98 runnung
587 // such that we try it to create the dirs at startup here
588 if ( hdir == "C:\\" )
589 {
590 // win 98 or ME
591 QDir app_dir;
592 if ( !app_dir.exists("C:\\kdepim") )
593 app_dir.mkdir ("C:\\kdepim");
594 if ( !app_dir.exists("C:\\kdepim\\apps") )
595 app_dir.mkdir ("C:\\kdepim\\apps");
596 if ( !app_dir.exists("C:\\kdepim\\config") )
597 app_dir.mkdir ("C:\\kdepim\\config");
598 if ( !app_dir.exists("C:\\kdepim\\apps\\pwmanager") )
599 app_dir.mkdir ("C:\\kdepim\\apps\\pwmanager");
600 }
601}
602
603PwMApplication::~PwMApplication()
604{
605 delete_ifnot_null(init);
606}
607
608#endif //DESKTOP_VERSION
609
610#endif //PWM_EMBEDDED
611
612
613
614
615#ifndef PWM_EMBEDDED
616#include "pwminit.moc"
617#endif
diff --git a/pwmanager/pwmanager/pwminit.h b/pwmanager/pwmanager/pwminit.h
new file mode 100644
index 0000000..bf72093
--- a/dev/null
+++ b/pwmanager/pwmanager/pwminit.h
@@ -0,0 +1,222 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef __PWMINIT_H
21#define __PWMINIT_H
22
23#include <qvaluelist.h>
24#include <qobject.h>
25#ifndef PWM_EMBEDDED
26#include <kuniqueapplication.h>
27#else //PWM_EMBEDDED
28
29#ifndef DESKTOP_VERSION
30#include <qpe/qpeapplication.h>
31#else //DESKTOP_VERSION
32#include <qapplication.h>
33#include <qplatinumstyle.h>
34#endif //DESKTOP_VERSION
35
36#include <kapplication.h>
37#endif //PWM_EMBEDDED
38
39#include "globalstuff.h"
40
41class DCOPClient;
42class KWalletEmu;
43class PwMKeyCard;
44class KApplication;
45class QWidget;
46class PwM;
47class PwMTray;
48class PwMDoc;
49class PwMInit;
50
51/** main application class */
52#ifndef PWM_EMBEDDED
53//MOC_SKIP_BEGIN
54class PwMApplication : public KUniqueApplication
55{
56public:
57 PwMApplication(bool allowStyles=true,
58 bool GUIenabled=true,
59 bool configUnique=false)
60 : KUniqueApplication(allowStyles, GUIenabled, configUnique)
61 , init (0)
62 { }
63 ~PwMApplication()
64 { delete_ifnot_null(init); }
65
66 int newInstance();
67
68protected:
69 PwMInit *init;
70};
71//MOC_SKIP_END
72#else //PWM_EMBEDDED
73
74#ifndef DESKTOP_VERSION
75class PwMApplication : public QPEApplication
76{
77public:
78 PwMApplication(int & argc, char ** argv);
79 ~PwMApplication();
80
81 int newInstance();
82
83protected:
84 PwMInit *init;
85};
86#else //DESKTOP_VERSION
87
88class PwMApplication : public QApplication
89{
90public:
91 PwMApplication(int & argc, char ** argv);
92 ~PwMApplication();
93
94 int newInstance();
95
96protected:
97 PwMInit *init;
98};
99
100#endif
101#endif
102
103/** PwManager initialisation class.
104 * This class sets up a new instance of PwManager and finally
105 * starts the user interface.
106 */
107class PwMInit : public QObject
108{
109 Q_OBJECT
110 friend class PwMApplication;
111
112protected:
113 enum RunStatus
114 {
115 unknown,
116 init,
117 running,
118 shutdown,
119 };
120
121 /* saved command line options. */
122 class savedCmd_t
123 {
124 public:
125 bool open_deeplocked;
126 bool minimized;
127 bool minToTray;
128 bool skipSelfTest;
129 // initial open paths are not saved here.
130 };
131
132public:
133 PwMInit(PwMApplication *_app);
134 ~PwMInit();
135
136 /** Initialize the application. */
137 void initializeApp();
138 /** shutdown PwManager */
139 void shutdownApp(int exitStatus);
140
141 /** returns a pointer to the current widget */
142 QWidget * curWidget()
143 { return _curWidget; }
144 /** returns a pointer to the dcop client */
145 DCOPClient * dcopClient()
146 { return _dcopClient; }
147 /** returns a pointer to the KWallet emulation */
148 KWalletEmu * kwalletEmu()
149 { return _kwalletEmu; }
150 /** returns a pointer to the keycard interface */
151 PwMKeyCard * keycard()
152 { return _keycard; }
153 /** returns a pointer to the tray icon */
154 PwMTray * tray()
155 { return _tray; }
156 /** returns a list of all open main windows */
157 const QValueList<PwM *> * mainWndList()
158 { return &_mainWndList; }
159 /** create a new document */
160 PwMDoc * createDoc();
161 /** create a new PwM main window */
162 PwM * createMainWnd(const QString &loadFile = QString::null,
163 bool loadFileDeepLocked = false,
164 bool virginity = true,
165 PwMDoc *doc = 0,
166 bool minimized = false);
167
168 /** (re)initialize the KWallet emulation */
169 void initKWalletEmu(bool forceDisable = false, bool forceReload = false);
170 /** (re)initialize the tray icon */
171 void initTray();
172
173protected:
174 /** initialize the DCOP connection */
175 void initDCOP();
176 /** initialize the keycard interface */
177 void initKeycard();
178 /** initialize posix signal handling */
179 void initPosixSignalHandler();
180 /** handle the commandline args */
181 void handleCmdLineArgs(bool initial = true);
182 /** minimize all open mainWnds to tray (or if
183 * no tray is present, minimize them the normal way)
184 */
185 void minimizeAllMainWnd(bool toTray);
186
187protected slots:
188 /** a main window got closed */
189 void mainWndClosed(PwM *wnd);
190 /** the tray icon got closed */
191 void trayIconClosed(PwMTray *tray);
192 /** sets _curWidget on behalf of a PwM signal */
193 void setCurWidget(PwM *w)
194 { _curWidget = reinterpret_cast<QWidget *>(w); }
195 /** resets _curWidget to nothing */
196 void resetCurWidget()
197 { _curWidget = 0; }
198 /** remove the tray and quit the app */
199 void removeTrayAndQuit();
200
201protected:
202 /** run-status of the app */
203 RunStatus runStatus;
204 /** PwMApplication pointer */
205 PwMApplication *app;
206 /** pointer to the current widget the user is dealing with */
207 QWidget *_curWidget;
208 /** pointer to the dcop client */
209 DCOPClient *_dcopClient;
210 /** pointer to the KWallet emulation */
211 KWalletEmu *_kwalletEmu;
212 /** pointer to the keycard interface */
213 PwMKeyCard *_keycard;
214 /** pointer to the tray icon */
215 PwMTray *_tray;
216 /** list of all open main windows */
217 QValueList<PwM *> _mainWndList;
218 /** saved command line options. */
219 savedCmd_t savedCmd;
220};
221
222#endif // __PWMINIT_H
diff --git a/pwmanager/pwmanager/pwmprint.cpp b/pwmanager/pwmanager/pwmprint.cpp
new file mode 100644
index 0000000..1d26b10
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmprint.cpp
@@ -0,0 +1,188 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "pwmprint.h"
21#include "pwmexception.h"
22#include "pwm.h"
23#include "pwmdoc.h"
24#include "configuration.h"
25#include "printtext.h"
26#include "globalstuff.h"
27#include "listobjselectwnd.h"
28
29#include <kprinter.h>
30#include <kmessagebox.h>
31#include <kdialogbase.h>
32#include <qdatetime.h>
33
34
35PwMPrint::PwMPrint(PwMDoc *_doc, QWidget *_parent)
36{
37 PWM_ASSERT(_doc);
38 PWM_ASSERT(_parent);
39 doc = _doc;
40 parent = _parent;
41}
42
43PwMPrint::~PwMPrint()
44{
45}
46
47void PwMPrint::printNow()
48{
49 QString docTitle(doc->getTitle());
50 if (!doc->unlockAll_tempoary())
51 return;
52 if (doc->isDocEmpty()) {
53 KMessageBox::information(parent,
54 i18n("Sorry, there are no entries to print "
55 "in the document \"") +
56 docTitle + "\".",
57 i18n("nothing to do"));
58 doc->unlockAll_tempoary(true);
59 return;
60 }
61 QStringList printCategories(selCategories());
62 if (printCategories.isEmpty()) {
63 doc->unlockAll_tempoary(true);
64 return;
65 }
66 doc->ensureLvp();
67
68 PrintText prn;
69 if (!prn.setup(parent)) {
70 doc->unlockAll_tempoary(true);
71 return;
72 }
73 prn.setFullPage(false);
74 prn.setCreator(PROG_NAME);
75 prn.setDocName(docTitle);
76
77 prn.setHeader(genDateString(), docTitle);
78 prn.beginPrint();
79
80 prn.printLine("");
81 prn.printLine(QString(PROG_NAME " v" PACKAGE_VER " ") + i18n("password table:"));
82 prn.printLine("");
83
84 vector<PwMCategoryItem> tmp;
85 PwMCategoryItem catItem;
86 catItem.clear();
87 PwMDataItem item;
88 item.clear();
89 unsigned int numEntr, j, i = 0;
90 QStringList::iterator catI = printCategories.begin(),
91 catEnd = printCategories.end();
92 // Sort items on lvp and store them in tempoary "tmp".
93 while (catI != catEnd) {
94 catItem.clear();
95 catItem.name = (*catI).latin1();
96 tmp.push_back(catItem);
97 item.clear();
98 numEntr = doc->numEntries(*catI);
99 tmp[i].d.insert(tmp[i].d.begin(), numEntr, item);
100 for (j = 0; j < numEntr; ++j) {
101 doc->getEntry(*catI, j, &item);
102 tmp[i].d[numEntr - item.listViewPos - 1] = item;
103 }
104 ++catI;
105 ++i;
106 }
107 doc->unlockAll_tempoary(true);
108
109 QString currLine;
110 vector<PwMCategoryItem>::iterator cat_it = tmp.begin(),
111 cat_end = tmp.end();
112 unsigned int size;
113 while (cat_it != cat_end) {
114 i = 0;
115 size = cat_it->d.size();
116 prn.printLine("");
117 currLine = "== ";
118 currLine += i18n("Category: ");
119 currLine += cat_it->name.c_str();
120 currLine += " ==";
121 prn.printLine(currLine);
122 prn.printLine("");
123 while (true) {
124 item = cat_it->d[i];
125 currLine = "-- ";
126 currLine += item.desc.c_str();
127 currLine += " --";
128 prn.printLine(currLine);
129 if (item.name.size()) {
130 currLine = i18n("Username");
131 currLine += ": ";
132 currLine += item.name.c_str();
133 prn.printLine(currLine);
134 }
135 if (item.pw.size()) {
136 currLine = i18n("Password");
137 currLine += ": ";
138 currLine += item.pw.c_str();
139 prn.printLine(currLine);
140 }
141 if (item.comment.size()) {
142 currLine = i18n("Comment");
143 currLine += ": ";
144 currLine += item.comment.c_str();
145 prn.printLine(currLine);
146 }
147 if (item.url.size()) {
148 currLine = i18n("URL");
149 currLine += ": ";
150 currLine += item.url.c_str();
151 prn.printLine(currLine);
152 }
153 if (item.launcher.size()) {
154 currLine = i18n("Launcher");
155 currLine += ": ";
156 currLine += item.launcher.c_str();
157 prn.printLine(currLine);
158 }
159
160 ++i;
161 if (i >= size)
162 break;
163 prn.printLine("");
164 }
165 ++cat_it;
166 }
167}
168
169QString PwMPrint::genDateString()
170{
171 QDateTime dt = QDateTime::currentDateTime();
172 QString ret(dt.toString(Qt::LocalDate));
173 return ret;
174}
175
176QStringList PwMPrint::selCategories()
177{
178 ListObjSelectWnd selWnd(i18n("Print categories"),
179 i18n("Please select the categories "
180 "you want to print."),
181 parent, true);
182 QStringList catList;
183 doc->getCategoryList(&catList);
184 selWnd.setList(catList);
185 if (selWnd.exec() != 1)
186 return QStringList();
187 return selWnd.getSelectedList();
188}
diff --git a/pwmanager/pwmanager/pwmprint.h b/pwmanager/pwmanager/pwmprint.h
new file mode 100644
index 0000000..4b7c4d2
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmprint.h
@@ -0,0 +1,55 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef PWMPRINT_H
21#define PWMPRINT_H
22
23#include <kconfig.h>
24
25#include <qwidget.h>
26#include <qstringlist.h>
27
28class PwMDoc;
29
30class PwMPrint
31{
32public:
33 PwMPrint(PwMDoc *_doc, QWidget *_parent);
34 ~PwMPrint();
35
36 /** start printing now */
37 void printNow();
38 /** set document */
39 void setDoc(PwMDoc *_doc)
40 { doc = _doc; }
41
42protected:
43 /** generate a date-string */
44 QString genDateString();
45 /** request the user to select all categories to print */
46 QStringList selCategories();
47
48protected:
49 /** document */
50 PwMDoc *doc;
51 /** parent widget */
52 QWidget *parent;
53};
54
55#endif
diff --git a/pwmanager/pwmanager/pwmtray.cpp b/pwmanager/pwmanager/pwmtray.cpp
new file mode 100644
index 0000000..0f286c1
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmtray.cpp
@@ -0,0 +1,482 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * Original implementation of the tray-tree *
7 * (c) by Matt Scifo <mscifo@o1.com> *
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License version 2 *
11 * as published by the Free Software Foundation. *
12 * *
13 ***************************************************************************/
14
15/***************************************************************************
16 * copyright (C) 2004 by Ulf Schenk
17 * This file is originaly based on version 1.0.1 of pwmanager
18 * and was modified to run on embedded devices that run microkde
19 *
20 * $Id$
21 **************************************************************************/
22
23#include "pwmtray.h"
24#include "pwmexception.h"
25#include "pwm.h"
26#include "pwmdoc.h"
27#include "pwminit.h"
28#include "configuration.h"
29
30#include <klocale.h>
31
32
33void ActiveTreeItem::execIt()
34{
35#ifndef PWM_EMBEDDED
36 unsigned int entr = static_cast<unsigned int>(entry);
37 unsigned int cat = static_cast<unsigned int>(category);
38#else
39 unsigned int entr = (unsigned int)(entry);
40 unsigned int cat = (unsigned int)(category);
41#endif
42 switch (task) {
43 case pwToClipboard: {
44 PwMDataItem d;
45 doc->getDataChangedLock();
46 bool wasLocked = doc->isLocked(cat, entr);
47 doc->getEntry(cat, entr, &d, true);
48 if (wasLocked)
49 doc->lockAt(cat, entr, true);
50 doc->putDataChangedLock();
51 PwM::copyToClipboard(d.pw.c_str());
52 break;
53 } case nameToClipboard: {
54 PwMDataItem d;
55 doc->getEntry(cat, entr, &d);
56 PwM::copyToClipboard(d.name.c_str());
57 break;
58 } case descToClipboard: {
59 PwMDataItem d;
60 doc->getEntry(cat, entr, &d);
61 PwM::copyToClipboard(d.desc.c_str());
62 break;
63 } case urlToClipboard: {
64 PwMDataItem d;
65 doc->getEntry(cat, entr, &d);
66 PwM::copyToClipboard(d.url.c_str());
67 break;
68 } case launcherToClipboard: {
69 PwMDataItem d;
70 doc->getEntry(cat, entr, &d);
71 PwM::copyToClipboard(d.launcher.c_str());
72 break;
73 } case commentToClipboard: {
74 PwMDataItem d;
75 doc->getEntry(cat, entr, &d);
76 PwM::copyToClipboard(d.comment.c_str());
77 break;
78 } case execLauncher: {
79 doc->execLauncher(cat, entr);
80 break;
81 } case goToURL: {
82 doc->goToURL(cat, entr);
83 break;
84 } case openMainWnd: {
85 // search if there is already an open window.
86 const QValueList<PwM *> *wl = tray->init->mainWndList();
87#ifndef PWM_EMBEDDED
88 QValueList<PwM *>::const_iterator i = wl->begin(),
89 end = wl->end();
90#else
91 QValueList<PwM *>::ConstIterator i = wl->begin(),
92 end = wl->end();
93#endif
94 PwM *wnd;
95 while (i != end) {
96 wnd = *i;
97 if (wnd->curDoc() == doc) {
98 // now bring this window to the foreground.
99 if (!wnd->hasFocus()) {
100 wnd->hide();
101 wnd->showNormal();
102 wnd->setFocus();
103 }
104 return;
105 }
106 ++i;
107 }
108 // there is no open window, so open a new one.
109 tray->init->createMainWnd(QString::null, false, false, doc);
110 break;
111 } case closeDoc: {
112 doc->tryDelete();
113 break;
114 } case lock: {
115 doc->lockAll(true);
116 break;
117 } case deepLock: {
118 doc->deepLock();
119 break;
120 } case unlock: {
121 doc->lockAll(false);
122 break;
123 } default: {
124 BUG();
125 }
126 }
127}
128
129
130
131#ifndef PWM_EMBEDDED
132PwMTray::PwMTray(PwMInit *_init, QWidget * parent, const char *name)
133 : KSystemTray(parent, name)
134#else
135PwMTray::PwMTray(PwMInit *_init, QWidget * parent, const char *name)
136 : QWidget(parent, name)
137#endif
138{
139 init = _init;
140 buildMain();
141}
142
143PwMTray::~PwMTray()
144{
145 emit closed(this);
146}
147
148//US ENH for embedded tray class
149KPopupMenu* PwMTray::contextMenu()
150{
151 if (m_ctxMenu == 0)
152 {
153 m_ctxMenu = new KPopupMenu();
154 }
155
156 return m_ctxMenu;
157}
158
159
160void PwMTray::buildMain()
161{
162 KPopupMenu *ctxMenu = contextMenu();
163
164 ctxMenu->insertSeparator();
165 ctxMenu->insertItem(i18n("&New main window..."), this,
166 SLOT(newMainWnd()));
167 ctxMenu->insertItem(i18n("&Open file..."), this,
168 SLOT(openDoc()));
169 ctxMenu->insertSeparator();
170 ctxMenu->insertItem(i18n("&Remove from tray"), this,
171 SLOT(undock()));
172}
173
174void PwMTray::insertActiveTreeItem(KPopupMenu *insertIn, const QString &text,
175 ActiveTreeItem::Task task, PwMDoc *doc,
176 int docCategory, int docEntry,
177 QValueList<int> *activeItemsList)
178{
179 ActiveTreeItem *activeItem;
180 int id;
181
182 activeItem = new ActiveTreeItem(text, insertIn->font(), task,
183 doc, docCategory, docEntry,
184 this);
185 id = insertIn->insertItem(activeItem);
186 insertIn->connectItem(id, activeItem, SLOT(execIt()));
187#ifndef PWM_EMBEDDED
188 activeItemsList->push_back(id);
189#else
190 activeItemsList->append(id);
191#endif
192}
193
194void PwMTray::rebuildTree(KPopupMenu *popup, PwMDoc *doc,
195 QValueList<int> *activeItems)
196{
197 PWM_ASSERT(doc);
198 PWM_ASSERT(popup);
199 activeItems->clear();
200 popup->clear();
201#ifndef PWM_EMBEDDED
202 popup->insertTitle(i18n("Categories:"));
203#endif
204 vector<string> catList;
205 vector<string> entrList;
206 doc->getCategoryList(&catList);
207 KPopupMenu *newCatMenu;
208 KPopupMenu *newEntrMenu;
209 int i, size = catList.size();
210 int j, entries;
211 for (i = 0; i < size; ++i) {
212 newCatMenu = new KPopupMenu(popup);
213 popup->insertItem(catList[i].c_str(), newCatMenu);
214 doc->getEntryList(i, &entrList);
215
216 entries = entrList.size();
217 for (j = 0; j < entries; ++j) {
218 newEntrMenu = new KPopupMenu(newCatMenu);
219 newCatMenu->insertItem(entrList[j].c_str(), newEntrMenu);
220
221 if (doc->isBinEntry(i, j)) {
222 /* This is a binary entry. Don't insert the usual
223 * menu items.
224 */
225#ifndef PWM_EMBEDDED
226 newEntrMenu->insertTitle(i18n("This is a binary entry.\n"
227 "It is not a normal password-entry, as it contains "
228 "binary data, which PwManager can't display here."));
229#endif
230 continue;
231 }
232
233 insertActiveTreeItem(newEntrMenu,
234 i18n("copy password to clipboard"),
235 ActiveTreeItem::pwToClipboard, doc, i, j,
236 activeItems);
237
238 insertActiveTreeItem(newEntrMenu,
239 i18n("copy username to clipboard"),
240 ActiveTreeItem::nameToClipboard, doc, i, j,
241 activeItems);
242
243 insertActiveTreeItem(newEntrMenu,
244 i18n("copy description to clipboard"),
245 ActiveTreeItem::descToClipboard, doc, i, j,
246 activeItems);
247
248 insertActiveTreeItem(newEntrMenu,
249 i18n("copy url to clipboard"),
250 ActiveTreeItem::urlToClipboard, doc, i, j,
251 activeItems);
252
253 insertActiveTreeItem(newEntrMenu,
254 i18n("copy launcher to clipboard"),
255 ActiveTreeItem::launcherToClipboard, doc, i, j,
256 activeItems);
257
258 insertActiveTreeItem(newEntrMenu,
259 i18n("copy comment to clipboard"),
260 ActiveTreeItem::commentToClipboard, doc, i, j,
261 activeItems);
262
263 newEntrMenu->insertSeparator();
264
265 insertActiveTreeItem(newEntrMenu,
266 i18n("Execute \"Launcher\""),
267 ActiveTreeItem::execLauncher, doc, i, j,
268 activeItems);
269
270 insertActiveTreeItem(newEntrMenu,
271 i18n("Go to \"URL\""),
272 ActiveTreeItem::goToURL, doc, i, j,
273 activeItems);
274 }
275 }
276 insertMainWndCtrl(popup, doc);
277}
278
279void PwMTray::insertMainWndCtrl(KPopupMenu *menu, PwMDoc *doc)
280{
281 ActiveTreeItem *activeItem;
282 int id;
283
284#ifndef PWM_EMBEDDED
285 menu->insertTitle(i18n("Manager:"));
286#endif
287 activeItem = new ActiveTreeItem(i18n("&Open main manager window ..."),
288 menu->font(), ActiveTreeItem::openMainWnd,
289 doc, 0, 0, this);
290 id = menu->insertItem(activeItem);
291 menu->connectItem(id, activeItem, SLOT(execIt()));
292
293 activeItem = new ActiveTreeItem(i18n("&Close this document ..."),
294 menu->font(), ActiveTreeItem::closeDoc,
295 doc, 0, 0, this);
296 id = menu->insertItem(activeItem);
297 menu->connectItem(id, activeItem, SLOT(execIt()));
298
299 menu->insertSeparator();
300
301 activeItem = new ActiveTreeItem(i18n("&Lock all entries"),
302 menu->font(), ActiveTreeItem::lock,
303 doc, 0, 0, this);
304 id = menu->insertItem(activeItem);
305 menu->connectItem(id, activeItem, SLOT(execIt()));
306
307 activeItem = new ActiveTreeItem(i18n("&Deep-lock all entries"),
308 menu->font(), ActiveTreeItem::deepLock,
309 doc, 0, 0, this);
310 id = menu->insertItem(activeItem);
311 menu->connectItem(id, activeItem, SLOT(execIt()));
312
313 activeItem = new ActiveTreeItem(i18n("&Unlock all entries"),
314 menu->font(), ActiveTreeItem::unlock,
315 doc, 0, 0, this);
316 id = menu->insertItem(activeItem);
317 menu->connectItem(id, activeItem, SLOT(execIt()));
318}
319
320void PwMTray::updateTree(PwMDoc *document)
321{
322 PWM_ASSERT(document);
323 KPopupMenu *treeEntry;
324 int treeItemNum = -1;
325 int id = findTreeEntry(document, &treeEntry, &treeItemNum);
326 if (id == -1) {
327 // tree-entry doesn't exist, yet.
328 id = insertTreeEntry(document, &treeEntry);
329 }
330 if (treeItemNum != -1) {
331 // delete all *old* active items
332 KPopupMenu *ctxMenu = contextMenu();
333 QValueList<int> *oldItems = &tree[treeItemNum].activeItems;
334#ifndef PWM_EMBEDDED
335 QValueList<int>::iterator i = oldItems->begin();
336#else
337 QValueList<int>::Iterator i = oldItems->begin();
338#endif
339 while (i != oldItems->end()) {
340 ctxMenu->removeItem(*i);
341 ++i;
342 }
343 oldItems->clear();
344 ctxMenu->changeItem(id, document->getTitle());
345 }
346
347 treeItem newTreeItem;
348 if (document->isDeepLocked()) {
349 treeEntry->clear();
350 #ifndef PWM_EMBEDDED
351 treeEntry->insertTitle(i18n("Categories:"));
352#endif
353 QString msg(IS_DEEPLOCKED_SHORTMSG);
354 msg += " ";
355 msg += i18n("(Click here to unlock)");
356 treeEntry->insertItem(msg, document,
357 SLOT(_deepUnlock()));
358 insertMainWndCtrl(treeEntry, document);
359 } else {
360 rebuildTree(treeEntry, document, &newTreeItem.activeItems);
361 }
362 newTreeItem.menuId = id;
363 newTreeItem.doc = document;
364 newTreeItem.menu = treeEntry;
365 if (treeItemNum == -1) {
366#ifndef PWM_EMBEDDED
367 tree.push_back(newTreeItem);
368#else
369 tree.append(newTreeItem);
370#endif
371 } else {
372 tree[treeItemNum] = newTreeItem;
373 }
374}
375
376void PwMTray::closeTreeEntry(PwMDoc *document)
377{
378 KPopupMenu *menu;
379 int treeItem;
380 int id = findTreeEntry(document, &menu, &treeItem);
381 if (id != -1) {
382 removeTreeEntry(id, treeItem, &menu);
383 }
384}
385
386int PwMTray::findTreeEntry(PwMDoc *doc, KPopupMenu **menu, int *treeItem)
387{
388 PWM_ASSERT(doc);
389#ifndef PWM_EMBEDDED
390 int i, count = tree.size();
391#else
392 int i, count = tree.count();
393#endif
394 for (i = 0; i < count; ++i) {
395 if (tree[i].doc == doc) {
396 if (menu)
397 *menu = tree[i].menu;
398 if (treeItem)
399 *treeItem = i;
400 return tree[i].menuId;
401 }
402 }
403 if (menu)
404 *menu = 0;
405 if (treeItem)
406 *treeItem = -1;
407 return -1;
408}
409
410int PwMTray::insertTreeEntry(PwMDoc *doc, KPopupMenu **popup)
411{
412 PWM_ASSERT(doc);
413 PWM_ASSERT(popup);
414 KPopupMenu *ctxMenu = contextMenu();
415 *popup = new KPopupMenu(ctxMenu);
416 return ctxMenu->insertItem(doc->getTitle(), *popup, -1, 1);
417}
418
419void PwMTray::removeTreeEntry(int menuId, int treeItem, KPopupMenu **menu)
420{
421 PWM_ASSERT(menu);
422 KPopupMenu *ctxMenu = contextMenu();
423 ctxMenu->removeItem(menuId);
424 delete_and_null(*menu);
425#ifndef PWM_EMBEDDED
426 tree.erase(tree.at(treeItem));
427#else
428 tree.remove(tree.at(treeItem));
429#endif
430}
431
432void PwMTray::mouseReleaseEvent(QMouseEvent *e)
433{
434 QWidget *curWnd = init->curWidget();
435 KPopupMenu *ctxMenu = contextMenu();
436 // give focus to init->curWidget()
437 if (curWnd && !curWnd->hasFocus()) {
438 curWnd->hide();
439 curWnd->showNormal();
440 curWnd->setFocus();
441 }
442 // popup the context menu
443 ctxMenu->popup(e->globalPos());
444 emit clickedIcon(this);
445}
446
447void PwMTray::connectDocToTray(PwMDoc *doc)
448{
449 connect(doc, SIGNAL(dataChanged(PwMDoc *)),
450 this, SLOT(updateTree(PwMDoc *)));
451 connect(doc, SIGNAL(docClosed(PwMDoc *)),
452 this, SLOT(closeTreeEntry(PwMDoc *)));
453 // fake a dataChanged signal for this doc to update the tray tree.
454 updateTree(doc);
455}
456
457void PwMTray::openDoc()
458{
459 // open the document in a new window.
460 PwM *newInstance = init->createMainWnd();
461 PwMDoc *newDoc = newInstance->openDoc("");
462 if (!newDoc) {
463 newInstance->setForceQuit(true);
464 delete_and_null(newInstance);
465 }
466}
467
468void PwMTray::newMainWnd()
469{
470 init->createMainWnd();
471}
472
473void PwMTray::undock()
474{
475 conf()->confGlobTray(false);
476 init->initTray();
477 // Attention! "this" is already deleted here!
478}
479
480#ifndef PWM_EMBEDDED
481#include "pwmtray.moc"
482#endif
diff --git a/pwmanager/pwmanager/pwmtray.h b/pwmanager/pwmanager/pwmtray.h
new file mode 100644
index 0000000..ffb625e
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmtray.h
@@ -0,0 +1,292 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef __PWMTRAY_H
21#define __PWMTRAY_H
22
23#ifndef PWM_EMBEDDED
24#include <ksystemtray.h>
25#endif
26
27#include <kpopupmenu.h>
28
29#include <qpainter.h>
30#include <qvaluelist.h>
31
32//#include "pwmexception.h"
33
34class PwMInit;
35class PwMDoc;
36class PwMTray;
37
38/* wrapper to workaround MOC problems */
39class __ActiveTreeItem : public QCustomMenuItem
40 , public QObject
41{
42public:
43 __ActiveTreeItem() {}
44};
45
46/** implements the "active" part of the tree */
47class ActiveTreeItem : public __ActiveTreeItem
48{
49 Q_OBJECT
50
51public:
52 enum Task
53 {
54 pwToClipboard,
55 nameToClipboard,
56 descToClipboard,
57 urlToClipboard,
58 launcherToClipboard,
59 commentToClipboard,
60 execLauncher,
61 goToURL,
62 openMainWnd,
63 closeDoc,
64 lock,
65 deepLock,
66 unlock
67 };
68
69public:
70 ActiveTreeItem(const QString &_text, const QFont &_font,
71 Task _task, PwMDoc * _doc,
72 int _category, int _entry,
73 PwMTray *_tray)
74 : text (_text)
75 , font (_font)
76 , task (_task)
77 , doc (_doc)
78 , category (_category)
79 , entry (_entry)
80 , tray (_tray)
81 { }
82
83 /*~ActiveTreeItem()
84 { cout << "deleted \"" << text << "\"" << endl; } */
85
86 void paint(QPainter *p, const QColorGroup & /*cg*/, bool /*act*/,
87 bool /*enabled*/, int x, int y, int w, int h)
88 {
89 p->setFont(font);
90 p->drawText(x, y, w, h, AlignLeft | AlignVCenter |
91 DontClip | ShowPrefix, text);
92 }
93
94 QSize sizeHint()
95 {
96 return QFontMetrics(font).size(AlignLeft | AlignVCenter |
97 ShowPrefix | DontClip, text);
98 }
99
100 bool fullSpan() const
101 { return false; }
102
103 bool isSeparator() const
104 { return false; }
105
106 void setFont(const QFont &f)
107 { font = f; }
108
109public slots:
110 /** this is the executive part, that is triggered, when the user clicks it */
111 void execIt();
112
113protected:
114 QString text;
115 QFont font;
116 Task task;
117 PwMDoc *doc;
118 int category;
119 int entry;
120 PwMTray *tray;
121};
122
123/** tray icon implementation */
124#ifndef PWM_EMBEDDED
125//MOC_SKIP_BEGIN
126class PwMTray : public KSystemTray
127{
128 Q_OBJECT
129
130 friend class ActiveTreeItem;
131
132 struct treeItem
133 {
134 int menuId;
135 PwMDoc *doc;
136 KPopupMenu *menu;
137 QValueList<int> activeItems; // ids of all active items
138 };
139
140public:
141 PwMTray(PwMInit *_init, QWidget* parent = 0, const char* name = 0);
142 ~PwMTray();
143
144 /** connect all signals for this document to the tray */
145 void connectDocToTray(PwMDoc *doc);
146
147public slots:
148 /** for update-notification from all open documents */
149 void updateTree(PwMDoc *document);
150 /** when a document has been closed, call this func
151 * to delete its tray-entry
152 */
153 void closeTreeEntry(PwMDoc *document);
154
155protected slots:
156 /** open a new document */
157 void openDoc();
158 /** open a new mainwnd */
159 void newMainWnd();
160 /** undock this tray icon */
161 void undock();
162
163signals:
164 /** this icon got deleted */
165 void closed(PwMTray *);
166 /** the user clicked on the tray icon */
167 void clickedIcon(PwMTray *);
168
169protected:
170 /** holds a list of all open files, its documents and
171 * its menuIDs
172 */
173 QValueList<struct treeItem> tree;
174 /** pointer to init */
175 PwMInit *init;
176
177protected:
178 /** search if an entry with for the given document
179 * exists and resturn its ID and a pointer to the main
180 * KPopupMenu. If no item is found,
181 * it returns -1 as ID and a NULL-pointer.
182 */
183 int findTreeEntry(PwMDoc *doc, KPopupMenu **menu, int *treeItem);
184 /** build the main menu-items */
185 void buildMain();
186 /** rebuilds the tree for the given KPopupMenu entry */
187 void rebuildTree(KPopupMenu *popup, PwMDoc *doc,
188 QValueList<int> *activeItems);
189 /** insert a new tree-entry for the given doc and returns the ID.*/
190 int insertTreeEntry(PwMDoc *doc, KPopupMenu **popup);
191 /** removes a tree entry */
192 void removeTreeEntry(int menuId, int treeItem, KPopupMenu **menu);
193 /** inserts a new active-tree-item into the given tree entry */
194 void insertActiveTreeItem(KPopupMenu *insertIn, const QString &text,
195 ActiveTreeItem::Task task, PwMDoc *doc,
196 int docCategory, int docEntry,
197 QValueList<int> *activeItemsList);
198 /** mouse event on icon */
199 void mouseReleaseEvent(QMouseEvent *e);
200 /** inserts the items for the main window control
201 * into the popup menu.
202 */
203 void insertMainWndCtrl(KPopupMenu *menu, PwMDoc *doc);
204};
205//MOC_SKIP_END
206#else
207class PwMTray : public QWidget
208{
209 Q_OBJECT
210
211 friend class ActiveTreeItem;
212
213 struct treeItem
214 {
215 int menuId;
216 PwMDoc *doc;
217 KPopupMenu *menu;
218 QValueList<int> activeItems; // ids of all active items
219 };
220
221public:
222 PwMTray(PwMInit *_init, QWidget* parent = 0, const char* name = 0);
223 ~PwMTray();
224
225 //US ENH needed for embedde version.
226 KPopupMenu* contextMenu();
227 KPopupMenu* m_ctxMenu;
228
229 /** connect all signals for this document to the tray */
230 void connectDocToTray(PwMDoc *doc);
231
232public slots:
233 /** for update-notification from all open documents */
234 void updateTree(PwMDoc *document);
235 /** when a document has been closed, call this func
236 * to delete its tray-entry
237 */
238 void closeTreeEntry(PwMDoc *document);
239
240protected slots:
241 /** open a new document */
242 void openDoc();
243 /** open a new mainwnd */
244 void newMainWnd();
245 /** undock this tray icon */
246 void undock();
247
248signals:
249 /** this icon got deleted */
250 void closed(PwMTray *);
251 /** the user clicked on the tray icon */
252 void clickedIcon(PwMTray *);
253
254protected:
255 /** holds a list of all open files, its documents and
256 * its menuIDs
257 */
258 QValueList<struct treeItem> tree;
259 /** pointer to init */
260 PwMInit *init;
261
262protected:
263 /** search if an entry with for the given document
264 * exists and resturn its ID and a pointer to the main
265 * KPopupMenu. If no item is found,
266 * it returns -1 as ID and a NULL-pointer.
267 */
268 int findTreeEntry(PwMDoc *doc, KPopupMenu **menu, int *treeItem);
269 /** build the main menu-items */
270 void buildMain();
271 /** rebuilds the tree for the given KPopupMenu entry */
272 void rebuildTree(KPopupMenu *popup, PwMDoc *doc,
273 QValueList<int> *activeItems);
274 /** insert a new tree-entry for the given doc and returns the ID.*/
275 int insertTreeEntry(PwMDoc *doc, KPopupMenu **popup);
276 /** removes a tree entry */
277 void removeTreeEntry(int menuId, int treeItem, KPopupMenu **menu);
278 /** inserts a new active-tree-item into the given tree entry */
279 void insertActiveTreeItem(KPopupMenu *insertIn, const QString &text,
280 ActiveTreeItem::Task task, PwMDoc *doc,
281 int docCategory, int docEntry,
282 QValueList<int> *activeItemsList);
283 /** mouse event on icon */
284 void mouseReleaseEvent(QMouseEvent *e);
285 /** inserts the items for the main window control
286 * into the popup menu.
287 */
288 void insertMainWndCtrl(KPopupMenu *menu, PwMDoc *doc);
289};
290#endif
291
292#endif
diff --git a/pwmanager/pwmanager/pwmview.cpp b/pwmanager/pwmanager/pwmview.cpp
new file mode 100644
index 0000000..c09fbf5
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmview.cpp
@@ -0,0 +1,452 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "pwmview.h"
21#include "pwmexception.h"
22#include "globalstuff.h"
23#include "pwm.h"
24#include "rencatwnd.h"
25#include "configuration.h"
26#include "commentbox.h"
27
28#include <kmessagebox.h>
29#include <klocale.h>
30
31#include <qlineedit.h>
32#include <qpoint.h>
33#include <qapplication.h>
34
35 #define COLUMN_DESC 0
36 #define COLUMN_NAME 1
37 #define COLUMN_PW 2
38 #define COLUMN_URL 3
39 #define COLUMN_LAUNCHER 4
40
41
42PwMView::PwMView(PwM *_mainClass,
43 QWidget *parent, PwMDoc *_doc,
44 const char *name)
45 : PwMViewStyle(parent, name)
46{
47 PWM_ASSERT(_mainClass);
48 PWM_ASSERT(parent);
49 PWM_ASSERT(_doc);
50 setView(this);
51 doc = _doc;
52 doc->setListViewPointer(this);
53 mainClass = _mainClass;
54 resize(_mainClass->size());
55 initStyle(conf()->confWndMainViewStyle());
56 initCtxMenu();
57 doc->setCurrentView(this);
58 connect(doc, SIGNAL(dataChanged(PwMDoc *)), this, SLOT(updateView()));
59}
60
61PwMView::~PwMView()
62{
63}
64
65void PwMView::initCtxMenu()
66{
67 ctxMenu = new QPopupMenu(this);
68 ctxMenu->insertItem(i18n("&Add password"), mainClass, SLOT(addPwd_slot()));
69 ctxMenu->insertSeparator();
70 ctxMenu->insertItem(i18n("&Edit"), mainClass, SLOT(editPwd_slot()));
71 ctxMenu->insertItem(i18n("&Delete"), mainClass, SLOT(deletePwd_slot()));
72 ctxMenu->insertSeparator();
73 ctxMenu->insertItem(i18n("copy password to clipboard"),
74 this, SLOT(copyPwToClip()));
75 ctxMenu->insertItem(i18n("copy username to clipboard"),
76 this, SLOT(copyNameToClip()));
77 ctxMenu->insertItem(i18n("copy description to clipboard"),
78 this, SLOT(copyDescToClip()));
79 ctxMenu->insertItem(i18n("copy url to clipboard"),
80 this, SLOT(copyUrlToClip()));
81 ctxMenu->insertItem(i18n("copy launcher to clipboard"),
82 this, SLOT(copyLauncherToClip()));
83 ctxMenu->insertItem(i18n("copy comment to clipboard"),
84 this, SLOT(copyCommentToClip()));
85 ctxMenu->insertSeparator();
86 ctxMenu->insertItem(i18n("Execute \"Launcher\""), mainClass,
87 SLOT(execLauncher_slot()));
88 ctxMenu->insertItem(i18n("Go to \"URL\""), mainClass,
89 SLOT(goToURL_slot()));
90}
91
92void PwMView::resizeEvent(QResizeEvent *)
93{
94 resizeView(size());
95}
96
97void PwMView::refreshCommentTextEdit(QListViewItem *curItem)
98{
99 PWM_ASSERT(commentBox);
100 if (!curItem)
101 return;
102 string comment;
103 PwMerror ret;
104 ret = document()->getCommentByLvp(getCurrentCategory(),
105 lv->childCount() - lv->itemIndex(curItem) - 1,
106 &comment);
107 if (ret == e_binEntry) {
108 commentBox->setContent(i18n("This is a binary entry.\n"
109 "It is not a normal password-entry, as it contains "
110 "binary data, which PwManager can't display here."));
111 } else if (ret == e_normalEntry) {
112 commentBox->setContent(comment.c_str());
113 } else {
114 BUG();
115 return;
116 }
117 lv->ensureItemVisible(curItem);
118}
119
120void PwMView::keyReleaseEvent(QKeyEvent * /*e*/)
121{
122 refreshCommentTextEdit(lv->currentItem());
123}
124
125bool PwMView::getCurEntryIndex(unsigned int *index)
126{
127 QListViewItem *current = lv->currentItem();
128 if (!current)
129 return false;
130 return getDocEntryIndex(index, current);
131}
132
133bool PwMView::getDocEntryIndex(unsigned int *index,
134 const QListViewItem *item)
135{
136 vector<unsigned int> foundPositions;
137 PwMDataItem curItem;
138 curItem.desc = item->text(COLUMN_DESC).latin1();
139 curItem.name = item->text(COLUMN_NAME).latin1();
140 document()->getCommentByLvp(getCurrentCategory(),
141 lv->childCount() - lv->itemIndex(item) - 1,
142 &curItem.comment);
143 curItem.url = item->text(COLUMN_URL).latin1();
144 curItem.launcher = item->text(COLUMN_LAUNCHER).latin1();
145 document()->findEntry(getCurrentCategory(), curItem, SEARCH_IN_DESC |
146 SEARCH_IN_NAME | SEARCH_IN_COMMENT | SEARCH_IN_URL |
147 SEARCH_IN_LAUNCHER,
148 &foundPositions, true);
149 if (foundPositions.size()) {
150 *index = foundPositions[0];
151 return true;
152 }
153
154 return false;
155}
156
157void PwMView::handleToggle(QListViewItem *item)
158{
159 PWM_ASSERT(doc);
160 if (!item)
161 return;
162 QCheckListItem *clItem = (QCheckListItem *)item;
163 QString curCat(getCurrentCategory());
164
165 // find document position of this entry.
166 unsigned int curEntryDocIndex;
167 if (!getDocEntryIndex(&curEntryDocIndex, item))
168 return;
169
170 // hack to refresh the comment, if only one item is present
171 if (lv->childCount() == 1)
172 refreshCommentTextEdit(lv->currentItem());
173
174 if (doc->isLocked(curCat, curEntryDocIndex) != clItem->isOn())
175 return; // this is just a click somewhere on the entry
176 if (doc->isDeepLocked()) {
177 PwMerror ret;
178 ret = doc->deepLock(false);
179 if (ret != e_success)
180 clItem->setOn(false);
181 return;
182 }
183 doc->lockAt(curCat, curEntryDocIndex, !clItem->isOn());
184}
185
186void PwMView::handleRightClick(QListViewItem *item, const QPoint &point, int)
187{
188 if (!item)
189 return;
190 ctxMenu->move(point);
191 /* don't use ctxMenu->exec() here, as it generates race conditions
192 * with the card interface code. Believe it or not. :)
193 */
194 ctxMenu->show();
195}
196
197void PwMView::updateCategories()
198{
199 QString oldSel(getCurrentCategory());
200 delAllCategories();
201 QStringList catList;
202 document()->getCategoryList(&catList);
203 catList.sort();
204#ifndef PWM_EMBEDDED
205 QStringList::iterator i = catList.begin(),
206 end = catList.end();
207#else
208 QStringList::Iterator i = catList.begin(),
209 end = catList.end();
210#endif
211 while (i != end) {
212 addCategory(*i);
213 ++i;
214 }
215 selectCategory(oldSel);
216}
217
218void PwMView::shiftToView()
219{
220 int cX = lv->contentsX();
221 int cY = lv->contentsY();
222 commentBox->clear();
223
224 unsigned int catDocIndex;
225 if (unlikely(
226 !(document()->findCategory(getCurrentCategory(),
227 &catDocIndex)))) {
228 BUG();
229 }
230
231 // ensure all listViewPos are set
232 doc->ensureLvp();
233
234 // clear all tmp-data vectors
235 unsigned int i, entries = doc->numEntries(catDocIndex);
236 if (entries) {
237 mainClass->setVirgin(false);
238 }
239 vector<PwMDataItem> tmpSorted;
240 PwMDataItem currItem;
241 currItem.clear();
242 tmpSorted.insert(tmpSorted.begin(), entries, currItem);
243
244 // Sort items and store them in tempoary tmpSorted.
245 for (i = 0; i < entries; ++i) {
246 doc->getEntry(catDocIndex, i, &currItem);
247 tmpSorted[currItem.listViewPos] = currItem;
248 }
249
250 // shift tempoary data to ListView.
251 tmpDisableSort();
252 lv->clear();
253 QCheckListItem *newItem;
254 vector<PwMDataItem>::iterator it = tmpSorted.begin(),
255 end = tmpSorted.end();
256 while (it != end) {
257 newItem = new ListViewItemPwM(lv);
258 newItem->setText(COLUMN_DESC, (*it).desc.c_str());
259 if ((*it).binary) {
260 newItem->setText(COLUMN_NAME, "");
261 newItem->setText(COLUMN_PW, i18n("<BINARY ENTRY>"));
262 newItem->setText(COLUMN_URL, "");
263 newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str());
264 } else {
265 newItem->setText(COLUMN_NAME, (*it).name.c_str());
266 if ((*it).lockStat) {
267 newItem->setText(COLUMN_PW, QString((*it).pw.c_str())
268 + " "
269 + i18n("To unlock click the icon on the left."));
270 } else {
271 newItem->setText(COLUMN_PW, (*it).pw.c_str());
272 }
273 newItem->setText(COLUMN_URL, (*it).url.c_str());
274 newItem->setText(COLUMN_LAUNCHER, (*it).launcher.c_str());
275 }
276 newItem->setOn(!((*it).lockStat));
277 lv->insertItem(newItem);
278 ++it;
279 }
280 tmpReEnableSort();
281
282 if (cY || cX)
283 lv->setContentsPos(cX, cY);
284}
285
286void PwMView::reorgLp()
287{
288 if (!lv->childCount())
289 return;
290 PWM_ASSERT(doc);
291 PWM_ASSERT(!doc->isDocEmpty());
292 QListViewItem *currItem;
293 vector<unsigned int> foundPos;
294 /* This searchIn _should_ be:
295 *const unsigned int searchIn = SEARCH_IN_DESC;
296 * But we want backward compatibility (see comment in PwMDoc::addEntry()).
297 * So we need to search again, if we don't find the entry. (see below)
298 */
299 const unsigned int searchIn = SEARCH_IN_DESC | SEARCH_IN_NAME |
300 SEARCH_IN_URL | SEARCH_IN_LAUNCHER;
301 QString curCat(getCurrentCategory());
302 PwMDataItem findThis;
303 unsigned int i, cnt = lv->childCount();
304 for (i = 0; i < cnt; ++i) {
305 currItem = lv->itemAtIndex(i);
306 findThis.desc = currItem->text(COLUMN_DESC).latin1();
307 findThis.name = currItem->text(COLUMN_NAME).latin1();
308 findThis.url = currItem->text(COLUMN_URL).latin1();
309 findThis.launcher = currItem->text(COLUMN_LAUNCHER).latin1();
310 doc->findEntry(curCat, findThis, searchIn,
311 &foundPos, true);
312 if (!foundPos.size()) {
313 /* Did not find the entry. We seem to have a binary
314 * entry here (pray for it!). So search again with
315 * the "correct" searchIn flags.
316 */
317 const unsigned int searchIn2 = SEARCH_IN_DESC;
318 doc->findEntry(curCat, findThis, searchIn2,
319 &foundPos, true);
320 if (unlikely(!foundPos.size())) {
321 BUG();
322 continue;
323 }
324 /* We assert that it's a binary entry, now.
325 * No chance to efficiently verify it here.
326 */
327 }
328 doc->setListViewPos(curCat, foundPos[0], cnt - i - 1);
329 }
330}
331
332void PwMView::selAt(int index)
333{
334 QListViewItem *item = lv->itemAtIndex(index);
335 if (!item)
336 return;
337 lv->setCurrentItem(item);
338 lv->ensureItemVisible(item);
339}
340
341void PwMView::renCatButton_slot()
342{
343 if (doc->isDeepLocked())
344 return;
345 RenCatWnd wnd(this);
346 if (wnd.exec() == 1) {
347 QString newName(wnd.getNewName());
348 if (newName == "")
349 return;
350 document()->renameCategory(getCurrentCategory(),
351 newName);
352 }
353}
354
355void PwMView::delCatButton_slot()
356{
357 if (doc->isDeepLocked())
358 return;
359 if (numCategories() <= 1) {
360 mainClass->showStatMsg(i18n("Can't remove the last category."));
361 return;
362 }
363 if (KMessageBox::questionYesNo(this,
364 i18n("Do you really want to "
365 "delete the selected "
366 "category? All password-"
367 "entries will be lost in "
368 "this category!"),
369 i18n("Delete category?"))
370 == KMessageBox::No) {
371 return;
372 }
373 document()->delCategory(getCurrentCategory());
374}
375
376void PwMView::copyPwToClip()
377{
378 if (doc->isDeepLocked())
379 return;
380 unsigned int curIndex = 0;
381 if (!getCurEntryIndex(&curIndex))
382 return;
383 PwMDataItem d;
384 document()->getDataChangedLock();
385 document()->getEntry(getCurrentCategory(), curIndex, &d, true);
386 document()->putDataChangedLock();
387 PwM::copyToClipboard(d.pw.c_str());
388}
389
390void PwMView::copyNameToClip()
391{
392 if (doc->isDeepLocked())
393 return;
394 unsigned int curIndex = 0;
395 if (!getCurEntryIndex(&curIndex))
396 return;
397 PwMDataItem d;
398 document()->getEntry(getCurrentCategory(), curIndex, &d);
399 PwM::copyToClipboard(d.name.c_str());
400}
401
402void PwMView::copyDescToClip()
403{
404 if (doc->isDeepLocked())
405 return;
406 unsigned int curIndex = 0;
407 if (!getCurEntryIndex(&curIndex))
408 return;
409 PwMDataItem d;
410 document()->getEntry(getCurrentCategory(), curIndex, &d);
411 PwM::copyToClipboard(d.desc.c_str());
412}
413
414void PwMView::copyUrlToClip()
415{
416 if (doc->isDeepLocked())
417 return;
418 unsigned int curIndex = 0;
419 if (!getCurEntryIndex(&curIndex))
420 return;
421 PwMDataItem d;
422 document()->getEntry(getCurrentCategory(), curIndex, &d);
423 PwM::copyToClipboard(d.url.c_str());
424}
425
426void PwMView::copyLauncherToClip()
427{
428 if (doc->isDeepLocked())
429 return;
430 unsigned int curIndex = 0;
431 if (!getCurEntryIndex(&curIndex))
432 return;
433 PwMDataItem d;
434 document()->getEntry(getCurrentCategory(), curIndex, &d);
435 PwM::copyToClipboard(d.launcher.c_str());
436}
437
438void PwMView::copyCommentToClip()
439{
440 if (doc->isDeepLocked())
441 return;
442 unsigned int curIndex = 0;
443 if (!getCurEntryIndex(&curIndex))
444 return;
445 PwMDataItem d;
446 document()->getEntry(getCurrentCategory(), curIndex, &d);
447 PwM::copyToClipboard(d.comment.c_str());
448}
449
450#ifndef PWM_EMBEDDED
451#include "pwmview.moc"
452#endif
diff --git a/pwmanager/pwmanager/pwmview.h b/pwmanager/pwmanager/pwmview.h
new file mode 100644
index 0000000..b4cec65
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmview.h
@@ -0,0 +1,140 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef PWMVIEW_H
21#define PWMVIEW_H
22
23#include "listviewpwm.h"
24#include "pwmdoc.h"
25#include "pwmviewstyle.h"
26
27#include <kconfig.h>
28#include <klocale.h>
29
30#include <qevent.h>
31#include <qfont.h>
32#include <qobject.h>
33
34#include <vector>
35#include <string>
36
37using std::string;
38using std::vector;
39
40class PwM;
41class ConfFile;
42class PwMStatusBar;
43
44
45/** View class for PwM */
46class PwMView : public PwMViewStyle
47{
48 Q_OBJECT
49 friend class PwMViewStyle;
50public:
51 /** construtor */
52 PwMView(PwM *_mainClass, QWidget* parent, PwMDoc *_doc,
53 const char *name = 0);
54 /** destructor */
55 ~PwMView();
56
57 /** returns pointer to the document */
58 PwMDoc* document()
59 { return doc; }
60 /** returns the index of the currently selected entry.
61 * (index as represented in PwMDoc !)
62 */
63 bool getCurEntryIndex(unsigned int *index);
64 /** returns the position of the given item in the document
65 * Note: This func only serches in the current category.
66 */
67 bool getDocEntryIndex(unsigned int *index,
68 const QListViewItem *item);
69
70public slots:
71 /** update the view (call if dirty) */
72 void updateView()
73 {
74 updateCategories();
75 shiftToView();
76 }
77 /** (re)sort all items and (re)shift them to listView. */
78 void shiftToView();
79 /** handle clicking on an item */
80 void handleToggle(QListViewItem *item);
81 /** handle right-clicking on an item */
82 void handleRightClick(QListViewItem *item, const QPoint &point, int);
83 /** selects the item at "index" */
84 void selAt(int index);
85 /** rename category button pressed */
86 void renCatButton_slot();
87 /** delete category button pressed */
88 void delCatButton_slot();
89
90protected:
91 /** right-click context-menu */
92 QPopupMenu *ctxMenu;
93
94protected:
95 /** update the categories from document */
96 void updateCategories();
97 /** widget resize event */
98 void resizeEvent(QResizeEvent *);
99 /** initialize context-menu */
100 void initCtxMenu();
101 /** tempoarly disable auto-sorting and user-sorting */
102 void tmpDisableSort()
103 { lv->setSorting(-1); }
104 /** re-enable tempoarly disabled sorting */
105 void tmpReEnableSort()
106 {
107 lv->setSorting(lv->columns() + 1,
108 true/*lv->sortOrder() == Qt::Ascending*/);
109 }
110 /** The user pressed and released a key. */
111 void keyReleaseEvent(QKeyEvent *e);
112
113protected slots:
114 /** changes the comment text-edit, because a new item has been selected */
115 void refreshCommentTextEdit(QListViewItem *curItem);
116 /** copy pw to clipboard */
117 void copyPwToClip();
118 /** copy name to clipboard */
119 void copyNameToClip();
120 /** copy desc to clipboard */
121 void copyDescToClip();
122 /** copy url to clipboard */
123 void copyUrlToClip();
124 /** copy launcher to clipboard */
125 void copyLauncherToClip();
126 /** copy comment to clipboard */
127 void copyCommentToClip();
128 /** reorganize the "listViewPos" positions in the document
129 * (for the current category only!)
130 */
131 void reorgLp();
132
133private:
134 /** document */
135 PwMDoc *doc;
136 /** pointer to the main class "PwM" */
137 PwM *mainClass;
138};
139
140#endif
diff --git a/pwmanager/pwmanager/pwmviewstyle.cpp b/pwmanager/pwmanager/pwmviewstyle.cpp
new file mode 100644
index 0000000..67b5197
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmviewstyle.cpp
@@ -0,0 +1,205 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12
13/***************************************************************************
14 * copyright (C) 2004 by Ulf Schenk
15 * This file is originaly based on version 1.0.1 of pwmanager
16 * and was modified to run on embedded devices that run microkde
17 *
18 * $Id$
19 **************************************************************************/
20
21#include "pwmviewstyle.h"
22#include "pwmexception.h"
23#include "pwmviewstyle_0.h"
24#include "pwmviewstyle_1.h"
25#include "listviewpwm.h"
26#include "pwmview.h"
27#include "commentbox.h"
28
29
30PwMViewStyle::PwMViewStyle(QWidget *parent, const char *name)
31 : QWidget(parent, name)
32{
33 curStyle = style_notset;
34 s0 = 0;
35 s1 = 0;
36}
37
38PwMViewStyle::~PwMViewStyle()
39{
40 delete_ifnot_null(s0);
41 delete_ifnot_null(s1);
42}
43
44void PwMViewStyle::initStyle(style_t style)
45{
46 printDebug(string("initializing style ") + tostr(style));
47 bool wasMaximized = v->isMaximized();
48 if (v->isVisible())
49 v->hide();
50 switch (style) {
51 case style_0:
52 delete_ifnot_null(s0);
53 delete_ifnot_null(s1);
54 s0 = new PwMViewStyle_0(v);
55 lv = s0->getLv();
56 commentBox = s0->getCommentBox();
57 break;
58 case style_1:
59 delete_ifnot_null(s0);
60 delete_ifnot_null(s1);
61 s1 = new PwMViewStyle_1(v);
62 lv = s1->getLv();
63 commentBox = s1->getCommentBox();
64 break;
65 default:
66 BUG();
67 return;
68 }
69 curStyle = style;
70 connect(lv, SIGNAL(pressed(QListViewItem *)),
71 v, SLOT(handleToggle(QListViewItem *)));
72 connect(lv, SIGNAL(rightButtonClicked(QListViewItem *, const QPoint &, int)),
73 v, SLOT(handleRightClick(QListViewItem *, const QPoint &, int)));
74 connect(lv, SIGNAL(clicked(QListViewItem *)),
75 v, SLOT(refreshCommentTextEdit(QListViewItem *)));
76 lv->addColumn(i18n("Description"), 180);
77 lv->addColumn(i18n("Username"), 150);
78 lv->addColumn(i18n("Password"), 150);
79 lv->addColumn(i18n("URL"), 180);
80 lv->addColumn(i18n("Launcher"), 120);
81 v->tmpReEnableSort();
82 resizeView(v->size());
83 v->updateView();
84 if (wasMaximized) {
85 v->showMaximized();
86 } else {
87 v->show();
88 }
89 connect(lv, SIGNAL(layoutChanged()),
90 v, SLOT(reorgLp()));
91}
92
93void PwMViewStyle::resizeView(const QSize &size)
94{
95 switch (curStyle) {
96 case style_0:
97 PWM_ASSERT(s0);
98 s0->resize(size);
99 return;
100 case style_1:
101 PWM_ASSERT(s1);
102 s1->resize(size);
103 return;
104 default:
105 BUG();
106 }
107}
108
109QString PwMViewStyle::getCurrentCategory()
110{
111 switch (curStyle) {
112 case style_0:
113 PWM_ASSERT(s0);
114 return s0->getCurrentCategory();
115 case style_1:
116 PWM_ASSERT(s1);
117 return s1->getCurrentCategory();
118 default:
119 BUG();
120 }
121 return "";
122}
123
124void PwMViewStyle::addCategory(const QString &cat)
125{
126 switch (curStyle) {
127 case style_0:
128 PWM_ASSERT(s0);
129 s0->addCategory(cat);
130 return;
131 case style_1:
132 PWM_ASSERT(s1);
133 s1->addCategory(cat);
134 return;
135 default:
136 BUG();
137 }
138}
139
140void PwMViewStyle::delCategory(const QString &cat)
141{
142 switch (curStyle) {
143 case style_0:
144 PWM_ASSERT(s0);
145 s0->delCategory(cat);
146 return;
147 case style_1:
148 PWM_ASSERT(s1);
149 s1->delCategory(cat);
150 return;
151 default:
152 BUG();
153 }
154}
155
156void PwMViewStyle::delAllCategories()
157{
158 switch (curStyle) {
159 case style_0:
160 PWM_ASSERT(s0);
161 s0->delAllCategories();
162 return;
163 case style_1:
164 PWM_ASSERT(s1);
165 s1->delAllCategories();
166 return;
167 default:
168 BUG();
169 }
170}
171
172void PwMViewStyle::selectCategory(const QString &cat)
173{
174 switch (curStyle) {
175 case style_0:
176 PWM_ASSERT(s0);
177 s0->selectCategory(cat);
178 return;
179 case style_1:
180 PWM_ASSERT(s1);
181 s1->selectCategory(cat);
182 return;
183 default:
184 BUG();
185 }
186}
187
188int PwMViewStyle::numCategories()
189{
190 switch (curStyle) {
191 case style_0:
192 PWM_ASSERT(s0);
193 return s0->numCategories();
194 case style_1:
195 PWM_ASSERT(s1);
196 return s1->numCategories();
197 default:
198 BUG();
199 }
200 return 0;
201}
202
203#ifndef PWM_EMBEDDED
204#include "pwmviewstyle.moc"
205#endif
diff --git a/pwmanager/pwmanager/pwmviewstyle.h b/pwmanager/pwmanager/pwmviewstyle.h
new file mode 100644
index 0000000..bf5ce91
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmviewstyle.h
@@ -0,0 +1,108 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12
13/***************************************************************************
14 * copyright (C) 2004 by Ulf Schenk
15 * This file is originaly based on version 1.0.1 of pwmanager
16 * and was modified to run on embedded devices that run microkde
17 *
18 * $Id$
19 **************************************************************************/
20
21#ifndef PWMVIEWSTYLE_H
22#define PWMVIEWSTYLE_H
23
24#include <qwidget.h>
25#include <qsplitter.h>
26#include <qhbox.h>
27#include <qvbox.h>
28#include <qpushbutton.h>
29#include <qpopupmenu.h>
30#ifndef PWM_EMBEDDED
31#include <qtextedit.h>
32#else
33#include <qmultilineedit.h>
34#endif
35
36#include <qlabel.h>
37#include <qlistbox.h>
38#include <qcombobox.h>
39#include <qsize.h>
40
41class ListViewPwM;
42class PwMViewStyle_0;
43class PwMViewStyle_1;
44class PwMView;
45class CommentBox;
46
47class PwMViewStyle : public QWidget
48{
49 Q_OBJECT
50
51public:
52 enum style_t
53 {
54 style_notset= -1,
55 style_0 = 0,
56 style_1 = 1
57 };
58
59public:
60 PwMViewStyle(QWidget *parent = 0, const char *name = 0);
61 ~PwMViewStyle();
62
63 /** initialize a new style */
64 void initStyle(style_t style);
65 void initStyle(int style)
66 { initStyle(static_cast<style_t>(style)); }
67 /** returns the currently used style */
68 style_t getCurStyle()
69 { return curStyle; }
70 void setView(PwMView *view)
71 { v = view; }
72
73 /** returns the currently selected category */
74 QString getCurrentCategory();
75
76protected:
77 /** add Category to the view */
78 void addCategory(const QString &cat);
79 /** delete Category from view */
80 void delCategory(const QString &cat);
81 /** delete all categories from view */
82 void delAllCategories();
83 /** select the specified category */
84 void selectCategory(const QString &cat);
85 /** returns the number of categories in this view.
86 * This value dosn't say anything about the number of
87 * categories in the document.
88 */
89 int numCategories();
90 /** resize the view */
91 void resizeView(const QSize &size);
92
93private:
94 /** which style has the view?
95 * KListBox on the left,
96 * or QComboBox on the top?
97 */
98 style_t curStyle;
99
100 PwMViewStyle_0 *s0;
101 PwMViewStyle_1 *s1;
102 PwMView *v;
103
104protected:
105 ListViewPwM *lv;
106 CommentBox *commentBox;
107};
108#endif
diff --git a/pwmanager/pwmanager/pwmviewstyle_0.cpp b/pwmanager/pwmanager/pwmviewstyle_0.cpp
new file mode 100644
index 0000000..6d46ac6
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmviewstyle_0.cpp
@@ -0,0 +1,93 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "pwmviewstyle_0.h"
21#include "pwmview.h"
22#include "listviewpwm.h"
23#include "commentbox.h"
24
25#include <klocale.h>
26
27
28PwMViewStyle_0::PwMViewStyle_0(PwMView *view)
29 : QObject()
30{
31 vbox1 = new QVBox(view);
32 vbox1->setSpacing(3);
33 hbox1 = new QHBox(vbox1);
34 hbox1->setSpacing(10);
35 categoriesTitle = new QLabel(hbox1);
36 categoriesTitle->setText(i18n("Categories:"));
37 categoriesCombo = new QComboBox(hbox1);
38 renCatButton = new QPushButton(i18n("&Rename"), hbox1);
39 delCatButton = new QPushButton(i18n("&Delete"), hbox1);
40#ifndef PWM_EMBEDDED
41 splitter1 = new QSplitter(vbox1);
42 splitter1->setOrientation(Qt::Vertical);
43#else
44 splitter1 = new KDGanttMinimizeSplitter( Qt::Vertical, vbox1);
45 splitter1->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
46
47 //US topLayout->addWidget(mMiniSplitter );
48#endif
49 lv = new ListViewPwM(splitter1);
50 commentBox = new CommentBox(splitter1);
51 // set sizes and styles
52 commentBox->resize(commentBox->size().width(), 60);
53 categoriesTitle->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
54 // connections
55 connect(categoriesCombo, SIGNAL(activated(int)),
56 view, SLOT(shiftToView()));
57 connect(renCatButton, SIGNAL(clicked()),
58 view, SLOT(renCatButton_slot()));
59 connect(delCatButton, SIGNAL(clicked()),
60 view, SLOT(delCatButton_slot()));
61}
62
63PwMViewStyle_0::~PwMViewStyle_0()
64{
65 delete vbox1;
66}
67
68void PwMViewStyle_0::delCategory(const QString &cat)
69{
70 PWM_ASSERT(categoriesCombo);
71 int i, count = categoriesCombo->count();
72 for (i = 0; i < count; ++i) {
73 if (categoriesCombo->text(i) == cat) {
74 categoriesCombo->removeItem(i);
75 return;
76 }
77 }
78 BUG();
79}
80
81void PwMViewStyle_0::selectCategory(const QString &cat)
82{
83 PWM_ASSERT(categoriesCombo);
84 int i, count = categoriesCombo->count();
85 for (i = 0; i < count; ++i) {
86 if (categoriesCombo->text(i) == cat) {
87 categoriesCombo->setCurrentItem(i);
88 return;
89 }
90 }
91 // fall back to 0
92 categoriesCombo->setCurrentItem(0);
93}
diff --git a/pwmanager/pwmanager/pwmviewstyle_0.h b/pwmanager/pwmanager/pwmviewstyle_0.h
new file mode 100644
index 0000000..cc564c3
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmviewstyle_0.h
@@ -0,0 +1,99 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef PWMVIEWSTYLE_0_H
21#define PWMVIEWSTYLE_0_H
22
23#include <qhbox.h>
24#include <qvbox.h>
25#include <qpushbutton.h>
26#ifndef PWM_EMBEDDED
27#include <qtextedit.h>
28#include <qsplitter.h>
29#else
30#include <qmultilineedit.h>
31#include <KDGanttMinimizeSplitter.h>
32#endif
33#include <qlabel.h>
34#include <qcombobox.h>
35
36class PwMView;
37class ListViewPwM;
38class CommentBox;
39
40class PwMViewStyle_0 : public QObject
41{
42public:
43 PwMViewStyle_0(PwMView *view);
44 ~PwMViewStyle_0();
45
46 ListViewPwM * getLv()
47 { return lv; }
48 CommentBox * getCommentBox()
49 { return commentBox; }
50
51 /** returns the currently selected category */
52 QString getCurrentCategory()
53 { return categoriesCombo->currentText(); }
54 /** add Category to the view */
55 void addCategory(const QString &cat)
56 { categoriesCombo->insertItem(cat); }
57 /** delete Category from view */
58 void delCategory(const QString &cat);
59 /** delete all categories from view */
60 void delAllCategories()
61 { categoriesCombo->clear(); }
62 /** select the specified category */
63 void selectCategory(const QString &cat);
64 /** returns the number of categories in this view.
65 * This value dosn't say anything about the number of
66 * categories in the document.
67 */
68 int numCategories()
69 { return categoriesCombo->count(); }
70 /** resize the view */
71 void resize(const QSize &size)
72 { vbox1->resize(size); }
73
74protected:
75 /** main list view */
76 ListViewPwM *lv;
77 /** categories combo-box */
78 QComboBox *categoriesCombo;
79 /** title string for the categories combo or list box */
80 QLabel *categoriesTitle;
81 /** hbox1 for widget style */
82 QHBox *hbox1;
83 /** vbox1 for widget style */
84 QVBox *vbox1;
85 /** splitter for commentTextEdit */
86 #ifndef PWM_EMBEDDED
87 QSplitter *splitter1;
88#else
89 KDGanttMinimizeSplitter * splitter1;
90#endif
91 /** push button to change the category name */
92 QPushButton *renCatButton;
93 /** push button to delete the category */
94 QPushButton *delCatButton;
95 /** comment box */
96 CommentBox *commentBox;
97};
98
99#endif
diff --git a/pwmanager/pwmanager/pwmviewstyle_1.cpp b/pwmanager/pwmanager/pwmviewstyle_1.cpp
new file mode 100644
index 0000000..4c24bc4
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmviewstyle_1.cpp
@@ -0,0 +1,130 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "pwmviewstyle_1.h"
21#include "pwmview.h"
22#include "listviewpwm.h"
23#include "commentbox.h"
24
25#include <klocale.h>
26
27 #define INITIAL_CATEGORIES_WIDTH100
28
29PwMViewStyle_1::PwMViewStyle_1(PwMView *view)
30 : QObject()
31{
32#ifndef PWM_EMBEDDED
33 splitter = new QSplitter(view);
34#else
35 splitter = new KDGanttMinimizeSplitter( Qt::Horizontal, view);
36 splitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
37
38 //US topLayout->addWidget(mMiniSplitter );
39#endif
40
41 vbox1 = new QVBox(splitter);
42 categoriesTitle = new QLabel(vbox1);
43 categoriesList = new QListBox(vbox1);
44#ifndef PWM_EMBEDDED
45 splitter2 = new QSplitter(splitter);
46 splitter2->setOrientation(Qt::Vertical);
47#else
48 splitter2 = new KDGanttMinimizeSplitter( Qt::Vertical, splitter);
49 splitter2->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
50
51 //US topLayout->addWidget(mMiniSplitter );
52#endif
53 lv = new ListViewPwM(splitter2);
54 commentBox = new CommentBox(splitter2);
55 // set sizes and styles
56 commentBox->resize(commentBox->size().width(), 60);
57 QValueList<int> sizes;
58#ifndef PWM_EMBEDDED
59 sizes.push_back(INITIAL_CATEGORIES_WIDTH);
60 sizes.push_back(view->height() - INITIAL_CATEGORIES_WIDTH);
61#else
62 sizes.append(INITIAL_CATEGORIES_WIDTH);
63 sizes.append(view->height() - INITIAL_CATEGORIES_WIDTH);
64#endif
65 splitter->setSizes(sizes);
66 categoriesTitle->setAlignment(Qt::AlignHCenter);
67#ifndef PWM_EMBEDDED
68 categoriesTitle->setFrameShape(QFrame::MenuBarPanel);
69#else
70 categoriesTitle->setFrameShape(QFrame::StyledPanel);
71#endif
72 categoriesTitle->setText(i18n("Categories:"));
73 catCtxMenu = new QPopupMenu(view);
74 catCtxMenu->insertItem(i18n("&Rename"),
75 view, SLOT(renCatButton_slot()));
76 catCtxMenu->insertItem(i18n("&Delete"),
77 view, SLOT(delCatButton_slot()));
78 // connections
79 connect(categoriesList, SIGNAL(highlighted(int)),
80 view, SLOT(shiftToView()));
81 connect(categoriesList,
82 SIGNAL(rightButtonClicked(QListBoxItem *, const QPoint &)),
83 this,
84 SLOT(catRightClick(QListBoxItem *, const QPoint &)));
85}
86
87PwMViewStyle_1::~PwMViewStyle_1()
88{
89 delete catCtxMenu;
90 delete splitter;
91}
92
93void PwMViewStyle_1::catRightClick(QListBoxItem *item, const QPoint &point)
94{
95 if (!item)
96 return;
97 catCtxMenu->move(point);
98 catCtxMenu->show();
99}
100
101void PwMViewStyle_1::delCategory(const QString &cat)
102{
103 PWM_ASSERT(categoriesList);
104 int i, count = categoriesList->count();
105 for (i = 0; i < count; ++i) {
106 if (categoriesList->text(i) == cat) {
107 categoriesList->removeItem(i);
108 return;
109 }
110 }
111 BUG();
112}
113
114void PwMViewStyle_1::selectCategory(const QString &cat)
115{
116 PWM_ASSERT(categoriesList);
117 int i, count = categoriesList->count();
118 for (i = 0; i < count; ++i) {
119 if (categoriesList->text(i) == cat) {
120 categoriesList->setCurrentItem(i);
121 return;
122 }
123 }
124 // fall back to 0
125 categoriesList->setCurrentItem(0);
126}
127
128#ifndef PWM_EMBEDDED
129#include "pwmviewstyle_1.moc"
130#endif
diff --git a/pwmanager/pwmanager/pwmviewstyle_1.h b/pwmanager/pwmanager/pwmviewstyle_1.h
new file mode 100644
index 0000000..a50f587
--- a/dev/null
+++ b/pwmanager/pwmanager/pwmviewstyle_1.h
@@ -0,0 +1,107 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef PWMVIEWSTYLE_1_H
21#define PWMVIEWSTYLE_1_H
22
23#include <qvbox.h>
24
25#ifndef PWM_EMBEDDED
26#include <qtextedit.h>
27#include <qsplitter.h>
28#else
29#include <qmultilineedit.h>
30#include <KDGanttMinimizeSplitter.h>
31#endif
32
33#include <qlabel.h>
34#include <qlistbox.h>
35#include <qpopupmenu.h>
36
37class PwMView;
38class ListViewPwM;
39class CommentBox;
40
41class PwMViewStyle_1 : public QObject
42{
43 Q_OBJECT
44public:
45 PwMViewStyle_1(PwMView *view);
46 ~PwMViewStyle_1();
47
48 ListViewPwM * getLv()
49 { return lv; }
50 CommentBox * getCommentBox()
51 { return commentBox; }
52
53 /** returns the currently selected category */
54 QString getCurrentCategory()
55 { return categoriesList->currentText(); }
56 /** add Category to the view */
57 void addCategory(const QString &cat)
58 { categoriesList->insertItem(cat); }
59 /** delete Category from view */
60 void delCategory(const QString &cat);
61 /** delete all categories from view */
62 void delAllCategories()
63 { categoriesList->clear(); }
64 /** select the specified category */
65 void selectCategory(const QString &cat);
66 /** returns the number of categories in this view.
67 * This value dosn't say anything about the number of
68 * categories in the document.
69 */
70 int numCategories()
71 { return categoriesList->count(); }
72 /** resize the view */
73 void resize(const QSize &size)
74 { splitter->resize(size); }
75
76protected slots:
77 /** user clicked right button in category list */
78 void catRightClick(QListBoxItem *item, const QPoint &point);
79
80protected:
81 /** main list view */
82 ListViewPwM *lv;
83#ifndef PWM_EMBEDDED
84 /** main splitter widget */
85 QSplitter *splitter;
86 /** commentTextEdit splitter */
87 QSplitter *splitter2;
88#else
89 /** main splitter widget */
90 KDGanttMinimizeSplitter *splitter;
91 /** commentTextEdit splitter */
92 KDGanttMinimizeSplitter *splitter2;
93#endif
94
95 /** categories list-box */
96 QListBox *categoriesList;
97 /** title string for the categories combo or list box */
98 QLabel *categoriesTitle;
99 /** hbox1 for widget style */
100 QVBox *vbox1;
101 /** text-edit to display the comment */
102 CommentBox *commentBox;
103 /** category list context menu */
104 QPopupMenu *catCtxMenu;
105};
106
107#endif
diff --git a/pwmanager/pwmanager/randomizer.cpp b/pwmanager/pwmanager/randomizer.cpp
new file mode 100644
index 0000000..e623f51
--- a/dev/null
+++ b/pwmanager/pwmanager/randomizer.cpp
@@ -0,0 +1,124 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "randomizer.h"
21#include "pwmexception.h"
22
23#include <stdlib.h>
24#include <time.h>
25
26
27Randomizer * Randomizer::rndObj (0);
28
29Randomizer::Randomizer()
30{
31 // probe for random devices
32 rndDev = fopen("/dev/urandom", "r");
33 if (rndDev)
34 return;
35 rndDev = fopen("/dev/random", "r");
36 if (rndDev)
37 return;
38 // fall back to rand_r()
39 seed = time(0);
40}
41
42Randomizer::~Randomizer()
43{
44 if (rndDev) {
45 if (fclose(rndDev)) {
46 printWarn("failed closing the random-device!");
47 }
48 }
49}
50
51char Randomizer::genRndChar()
52{
53 if (rndDev) {
54 /* we have a rand-device-node */
55 return (getc(rndDev));
56 } else {
57 /* we don't have a random-device-node.
58 * so fall back to rand_r()
59 */
60 return (rand_r(&seed) % 0xFF);
61 }
62}
63
64int Randomizer::genRndInt()
65{
66 if(rndDev) {
67 int ret;
68 if (sizeof(int) == 4) {
69 (reinterpret_cast<char *>(&ret))[0] = getc(rndDev);
70 (reinterpret_cast<char *>(&ret))[1] = getc(rndDev);
71 (reinterpret_cast<char *>(&ret))[2] = getc(rndDev);
72 (reinterpret_cast<char *>(&ret))[3] = getc(rndDev);
73 } else if (sizeof(int) == 8) {
74 (reinterpret_cast<char *>(&ret))[0] = getc(rndDev);
75 (reinterpret_cast<char *>(&ret))[1] = getc(rndDev);
76 (reinterpret_cast<char *>(&ret))[2] = getc(rndDev);
77 (reinterpret_cast<char *>(&ret))[3] = getc(rndDev);
78 (reinterpret_cast<char *>(&ret))[4] = getc(rndDev);
79 (reinterpret_cast<char *>(&ret))[5] = getc(rndDev);
80 (reinterpret_cast<char *>(&ret))[6] = getc(rndDev);
81 (reinterpret_cast<char *>(&ret))[7] = getc(rndDev);
82 } else {
83 printWarn(string(__FILE__) + ":" + tostr(__LINE__)
84 + ": sizeof(int) != 4 && sizeof(int) != 8");
85 rndDev = 0;
86 seed = time(0);
87 return genRndInt();
88 }
89 return ret;
90 } else {
91 return rand_r(&seed);
92 }
93}
94
95unsigned int Randomizer::genRndUInt()
96{
97 if(rndDev) {
98 unsigned int ret;
99 if (sizeof(unsigned int) == 4) {
100 (reinterpret_cast<char *>(&ret))[0] = getc(rndDev);
101 (reinterpret_cast<char *>(&ret))[1] = getc(rndDev);
102 (reinterpret_cast<char *>(&ret))[2] = getc(rndDev);
103 (reinterpret_cast<char *>(&ret))[3] = getc(rndDev);
104 } else if (sizeof(unsigned int) == 8) {
105 (reinterpret_cast<char *>(&ret))[0] = getc(rndDev);
106 (reinterpret_cast<char *>(&ret))[1] = getc(rndDev);
107 (reinterpret_cast<char *>(&ret))[2] = getc(rndDev);
108 (reinterpret_cast<char *>(&ret))[3] = getc(rndDev);
109 (reinterpret_cast<char *>(&ret))[4] = getc(rndDev);
110 (reinterpret_cast<char *>(&ret))[5] = getc(rndDev);
111 (reinterpret_cast<char *>(&ret))[6] = getc(rndDev);
112 (reinterpret_cast<char *>(&ret))[7] = getc(rndDev);
113 } else {
114 printWarn(string(__FILE__) + ":" + tostr(__LINE__)
115 + ": sizeof(unsigned int) != 4 && sizeof(unsigned int) != 8");
116 rndDev = 0;
117 seed = time(0);
118 return genRndUInt();
119 }
120 return ret;
121 } else {
122 return static_cast<unsigned int>(rand_r(&seed));
123 }
124}
diff --git a/pwmanager/pwmanager/randomizer.h b/pwmanager/pwmanager/randomizer.h
new file mode 100644
index 0000000..db17334
--- a/dev/null
+++ b/pwmanager/pwmanager/randomizer.h
@@ -0,0 +1,67 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef RANDOMIZER_H
21#define RANDOMIZER_H
22
23#include "pwmexception.h"
24
25#include <stdio.h>
26
27/** simple randomizer
28 * This class is *NOT* reentrant save!
29 */
30class Randomizer
31{
32public:
33 Randomizer();
34 ~Randomizer();
35
36 static Randomizer * obj()
37 {
38 PWM_ASSERT(rndObj);
39 return rndObj;
40 }
41 static void init()
42 {
43 PWM_ASSERT(!rndObj);
44 rndObj = new Randomizer;
45 }
46 static void cleanup()
47 {
48 delete_ifnot_null(rndObj);
49 }
50
51 /** generate random char */
52 char genRndChar();
53 /** generate random int */
54 int genRndInt();
55 /** generate random unsigned int */
56 unsigned int genRndUInt();
57
58protected:
59 /** random-device-node (if available. Otherwise NULL) */
60 FILE *rndDev;
61 /** seed value for fallback - rand_r() */
62 unsigned int seed;
63 /** static Randomier object returned by obj() */
64 static Randomizer *rndObj;
65};
66
67#endif
diff --git a/pwmanager/pwmanager/rc2.cpp b/pwmanager/pwmanager/rc2.cpp
new file mode 100644
index 0000000..3b85a3c
--- a/dev/null
+++ b/pwmanager/pwmanager/rc2.cpp
@@ -0,0 +1,222 @@
1/***************************************************************************
2 * *
3 * C implementation of RC2 encryption algorithm, as described in RFC2268 *
4 * By Matthew Palmer <mjp16@uow.edu.au> *
5 * *
6 * 2003/06/10: *
7 * Converted to C++ and modified to run with PwM *
8 * By Michael Buesch <mbuesch@freenet.de> *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License version 2 *
12 * as published by the Free Software Foundation. *
13 * *
14 ***************************************************************************/
15
16/***************************************************************************
17 * copyright (C) 2004 by Ulf Schenk
18 * This file is originaly based on version 1.0.1 of pwmanager
19 * and was modified to run on embedded devices that run microkde
20 *
21 * $Id$
22 **************************************************************************/
23
24#include "rc2.h"
25
26static const unsigned char
27_rc2_pitable[] = { 0xd9, 0x78, 0xf9, 0xc4, 0x19, 0xdd, 0xb5, 0xed,
28 0x28, 0xe9, 0xfd, 0x79, 0x4a, 0xa0, 0xd8, 0x9d,
29 0xc6, 0x7e, 0x37, 0x83, 0x2b, 0x76, 0x53, 0x8e,
30 0x62, 0x4c, 0x64, 0x88, 0x44, 0x8b, 0xfb, 0xa2,
31 0x17, 0x9a, 0x59, 0xf5, 0x87, 0xb3, 0x4f, 0x13,
32 0x61, 0x45, 0x6d, 0x8d, 0x09, 0x81, 0x7d, 0x32,
33 0xbd, 0x8f, 0x40, 0xeb, 0x86, 0xb7, 0x7b, 0x0b,
34 0xf0, 0x95, 0x21, 0x22, 0x5c, 0x6b, 0x4e, 0x82,
35 0x54, 0xd6, 0x65, 0x93, 0xce, 0x60, 0xb2, 0x1c,
36 0x73, 0x56, 0xc0, 0x14, 0xa7, 0x8c, 0xf1, 0xdc,
37 0x12, 0x75, 0xca, 0x1f, 0x3b, 0xbe, 0xe4, 0xd1,
38 0x42, 0x3d, 0xd4, 0x30, 0xa3, 0x3c, 0xb6, 0x26,
39 0x6f, 0xbf, 0x0e, 0xda, 0x46, 0x69, 0x07, 0x57,
40 0x27, 0xf2, 0x1d, 0x9b, 0xbc, 0x94, 0x43, 0x03,
41 0xf8, 0x11, 0xc7, 0xf6, 0x90, 0xef, 0x3e, 0xe7,
42 0x06, 0xc3, 0xd5, 0x2f, 0xc8, 0x66, 0x1e, 0xd7,
43 0x08, 0xe8, 0xea, 0xde, 0x80, 0x52, 0xee, 0xf7,
44 0x84, 0xaa, 0x72, 0xac, 0x35, 0x4d, 0x6a, 0x2a,
45 0x96, 0x1a, 0xd2, 0x71, 0x5a, 0x15, 0x49, 0x74,
46 0x4b, 0x9f, 0xd0, 0x5e, 0x04, 0x18, 0xa4, 0xec,
47 0xc2, 0xe0, 0x41, 0x6e, 0x0f, 0x51, 0xcb, 0xcc,
48 0x24, 0x91, 0xaf, 0x50, 0xa1, 0xf4, 0x70, 0x39,
49 0x99, 0x7c, 0x3a, 0x85, 0x23, 0xb8, 0xb4, 0x7a,
50 0xfc, 0x02, 0x36, 0x5b, 0x25, 0x55, 0x97, 0x31,
51 0x2d, 0x5d, 0xfa, 0x98, 0xe3, 0x8a, 0x92, 0xae,
52 0x05, 0xdf, 0x29, 0x10, 0x67, 0x6c, 0xba, 0xc9,
53 0xd3, 0x00, 0xe6, 0xcf, 0xe1, 0x9e, 0xa8, 0x2c,
54 0x63, 0x16, 0x01, 0x3f, 0x58, 0xe2, 0x89, 0xa9,
55 0x0d, 0x38, 0x34, 0x1b, 0xab, 0x33, 0xff, 0xb0,
56 0xbb, 0x48, 0x0c, 0x5f, 0xb9, 0xb1, 0xcd, 0x2e,
57 0xc5, 0xf3, 0xdb, 0x47, 0xe5, 0xa5, 0x9c, 0x77,
58 0x0a, 0xa6, 0x20, 0x68, 0xfe, 0x7f, 0xc1, 0xad
59 };
60
61static const int _rc2_s[] = { 1, 2, 3, 5 };
62
63Rc2::Rc2()
64{
65}
66
67Rc2::~Rc2()
68{
69}
70
71void Rc2::rc2_expandkey(char key[], int length, int ekl)
72{
73 int ekl8, keymask, i;
74
75 /* Put supplied key into first length - 1 bytes of the key buffer */
76 for (i = 0; i < length; i++) {
77 _rc2_expkey[i] = key[i];
78 }
79
80 ekl8 = (ekl + 7) / 8;
81 i = _rc2_pow(2, (8 + ekl - 8 * ekl8));
82 keymask = 255 % i;
83
84 /* First expansion step */
85 for (i = length; i < 128; i++) {
86 _rc2_expkey[i] = _rc2_pitable[(_rc2_expkey[i - 1] + _rc2_expkey[i - length]) % 256];
87 }
88
89 /* Expansion intermediate step */
90 _rc2_expkey[128 - ekl8] = _rc2_pitable[_rc2_expkey[128 - ekl8] & keymask];
91
92 /* Third Expansion step */
93 for (i = 127 - ekl8; i >= 0; i--) {
94 _rc2_expkey[i] = _rc2_pitable[_rc2_expkey[i + 1] ^ _rc2_expkey[i + ekl8]];
95 }
96}
97
98void Rc2::rc2_encrypt(unsigned short input[4])
99{
100 int i;
101
102 _rc2_counter = 0;
103 for (i = 0; i < 5; i++) {
104 _rc2_mix(input);
105 }
106 _rc2_mash(input);
107 for (i = 0; i < 6; i++) {
108 _rc2_mix(input);
109 }
110 _rc2_mash(input);
111 for (i = 0; i < 5; i++) {
112 _rc2_mix(input);
113 }
114}
115
116void Rc2::_rc2_mix(unsigned short input[])
117{
118 unsigned short K, i;
119
120 for (i = 0; i < 4; i++) {
121 K = _rc2_expkey[_rc2_counter * 2] + 256 * _rc2_expkey[_rc2_counter * 2 + 1];
122 input[i] = input[i] + K + (input[(i + 3) % 4] & input[(i + 2) % 4]) + ((~input[(i + 3) % 4]) & input[(i + 1) % 4]);
123 _rc2_counter++;
124 input[i] = _rc2_rol(input[i], _rc2_s[i]);
125 }
126}
127
128void Rc2::_rc2_mash(unsigned short input[])
129{
130 unsigned short K, i, x;
131
132 for (i = 0; i < 4; i++) {
133 x = input[(i + 3) % 4] & 63;
134 K = _rc2_expkey[2 * x] + 256 * _rc2_expkey[2 * x + 1];
135 input[i] = input[i] + K;
136 }
137}
138
139void Rc2::rc2_decrypt(unsigned short input[4])
140{
141 int i;
142
143 _rc2_counter = 63;
144 for (i = 0; i < 5; i++) {
145 _rc2_rmix(input);
146 }
147 _rc2_rmash(input);
148 for (i = 0; i < 6; i++) {
149 _rc2_rmix(input);
150 }
151 _rc2_rmash(input);
152 for (i = 0; i < 5; i++) {
153 _rc2_rmix(input);
154 }
155}
156
157void Rc2::_rc2_rmix(unsigned short input[])
158{
159 unsigned short K;
160 int i;
161
162 for (i = 3; i >= 0; i--) {
163 input[i] = _rc2_ror(input[i], _rc2_s[i]);
164 K = _rc2_expkey[_rc2_counter * 2] + 256 * _rc2_expkey[_rc2_counter * 2 + 1];
165 input[i] = input[i] - K - (input[(i + 3) % 4] & input[(i + 2) % 4]) - ((~input[(i + 3) % 4]) & input[(i + 1) % 4]);
166 _rc2_counter--;
167 }
168}
169
170void Rc2::_rc2_rmash(unsigned short input[])
171{
172 unsigned short K, x;
173 int i;
174
175 for (i = 3; i >= 0; i--) {
176 x = input[(i + 3) % 4] & 63;
177 K = _rc2_expkey[2 * x] + 256 * _rc2_expkey[2 * x + 1];
178 input[i] = input[i] - K;
179 }
180}
181int Rc2::_rc2_pow(int base, int exponent)
182{
183 int i, result;
184
185 if (exponent == 0) {
186 return 1;
187 }
188 result = 1;
189 for (i = 0; i < exponent; i++) {
190 result = result * base;
191 }
192 return result;
193}
194
195unsigned short Rc2::_rc2_rol(unsigned short input, int places)
196{
197 unsigned short temp, i;
198
199 for (i = 0; i < places; i++) {
200 temp = input & 0x8000;
201 input = input << 1;
202 if (temp) {
203 input++;
204 }
205 }
206 return input;
207}
208
209unsigned short Rc2::_rc2_ror(unsigned short input, int places)
210{
211 unsigned short temp, i;
212
213 for (i = 0; i < places; i++) {
214 temp = input & 0x1;
215 input = input >> 1;
216 if (temp) {
217 input = input + 0x8000;
218 }
219 }
220 return input;
221}
222
diff --git a/pwmanager/pwmanager/rc2.h b/pwmanager/pwmanager/rc2.h
new file mode 100644
index 0000000..d321da6
--- a/dev/null
+++ b/pwmanager/pwmanager/rc2.h
@@ -0,0 +1,50 @@
1/***************************************************************************
2 * *
3 * Header file for rc2 implementation by Matthew Palmer <mjp16@uow.edu.au> *
4 * Modified to run with PwM by Michael Buesch <mbuesch@freenet.de> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef RC2_H
21#define RC2_H
22
23/** implementation of the RC2 encryption algorithm. */
24class Rc2
25{
26public:
27 Rc2();
28 ~Rc2();
29
30 void rc2_expandkey(char key[], int length, int ekl);
31 void rc2_encrypt(unsigned short input[4]);
32 void rc2_decrypt(unsigned short input[4]);
33
34protected:
35 void _rc2_mix(unsigned short *);
36 void _rc2_mash(unsigned short *);
37 void _rc2_rmix(unsigned short *);
38 void _rc2_rmash(unsigned short *);
39 int _rc2_pow(int, int);
40 unsigned short _rc2_ror(unsigned short, int);
41 unsigned short _rc2_rol(unsigned short, int);
42
43protected:
44 /** Expanded Key */
45 unsigned char _rc2_expkey[128];
46 /** global integer variable used in mixing */
47 int _rc2_counter;
48};
49
50#endif
diff --git a/pwmanager/pwmanager/rencatwnd.cpp b/pwmanager/pwmanager/rencatwnd.cpp
new file mode 100644
index 0000000..1e8f9e9
--- a/dev/null
+++ b/pwmanager/pwmanager/rencatwnd.cpp
@@ -0,0 +1,70 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "rencatwnd.h"
21
22#include <klocale.h>
23
24
25RenCatWnd::RenCatWnd(QWidget *parent,
26 const char *name, bool modal, WFlags f)
27 : QDialog(parent, name, modal, f)
28{
29 vbox1 = new QVBox(this);
30 label = new QLabel(vbox1);
31 newName = new QLineEdit(vbox1);
32 hbox1 = new QHBox(vbox1);
33 okButton = new QPushButton(i18n("&Ok"), hbox1);
34 cancelButton = new QPushButton(i18n("&Cancel"), hbox1);
35
36 vbox1->setSpacing(10);
37 vbox1->setMargin(10);
38 hbox1->setSpacing(10);
39
40 resize(400, 100);
41
42 setCaption(i18n("rename category"));
43 label->setText(i18n("New category name:"));
44
45 connect(okButton, SIGNAL(clicked()), this, SLOT(okButton_slot()));
46 connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelButton_slot()));
47}
48
49RenCatWnd::~RenCatWnd()
50{
51}
52
53void RenCatWnd::resizeEvent(QResizeEvent *)
54{
55 vbox1->resize(size());
56}
57
58void RenCatWnd::okButton_slot()
59{
60 done(1);
61}
62
63void RenCatWnd::cancelButton_slot()
64{
65 done(2);
66}
67
68#ifndef PWM_EMBEDDED
69#include "rencatwnd.moc"
70#endif
diff --git a/pwmanager/pwmanager/rencatwnd.h b/pwmanager/pwmanager/rencatwnd.h
new file mode 100644
index 0000000..37b6725
--- a/dev/null
+++ b/pwmanager/pwmanager/rencatwnd.h
@@ -0,0 +1,60 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef RENCATWND_H
21#define RENCATWND_H
22
23#include <qvbox.h>
24#include <qhbox.h>
25#include <qdialog.h>
26#include <qlabel.h>
27#include <qlineedit.h>
28#include <qpushbutton.h>
29#include <qevent.h>
30
31
32/** rename category window */
33class RenCatWnd : public QDialog
34{
35 Q_OBJECT
36public:
37 RenCatWnd(QWidget *parent = 0, const char *name = 0,
38 bool modal = FALSE, WFlags f = 0);
39 ~RenCatWnd();
40
41 QString getNewName()
42 { return newName->text(); }
43
44protected slots:
45 void okButton_slot();
46 void cancelButton_slot();
47
48protected:
49 QVBox *vbox1;
50 QHBox *hbox1;
51 QLabel *label;
52 QLineEdit *newName;
53 QPushButton *okButton;
54 QPushButton *cancelButton;
55
56protected:
57 void resizeEvent(QResizeEvent *);
58};
59
60#endif
diff --git a/pwmanager/pwmanager/selftest.cpp b/pwmanager/pwmanager/selftest.cpp
new file mode 100644
index 0000000..45179d8
--- a/dev/null
+++ b/pwmanager/pwmanager/selftest.cpp
@@ -0,0 +1,105 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12#include "selftest.h"
13#include "pwmexception.h"
14#include "sha1.h"
15#include "blowfish.h"
16#include "base64.h"
17
18#include <pthread.h>
19
20
21static SelfTest *st = 0;
22static pthread_mutex_t st_mutex = PTHREAD_MUTEX_INITIALIZER;
23
24
25SelfTest::SelfTest()
26{
27 connect(&schedTimer, SIGNAL(timeout()),
28 this, SLOT(doSelfTest()));
29}
30
31SelfTest::~SelfTest()
32{
33}
34
35void SelfTest::run()
36{
37 //printDebug("running self-test...");
38 if (unlikely(!Sha1::selfTest())) {
39 failed("SHA1");
40 return;
41 }
42 if (unlikely(!Blowfish::selfTest())) {
43 failed("BLOWFISH");
44 return;
45 }
46 if (unlikely(!Base64::selfTest())) {
47 failed("BASE64");
48 return;
49 }
50 //printDebug("self-test done.");
51 if (!pthread_mutex_trylock(&st_mutex)) {
52 /* only cancel (delete) this thread, if there's currently
53 * noone else doing this job. Otherwise we will deadlock.
54 * we use a timer here, to do some kind of context-switch.
55 */
56 QTimer::singleShot(0, st, SLOT(doCancel()));
57 }
58}
59
60void SelfTest::failed(const char *algo)
61{
62 string msg("\n\n\n"
63 "PwManager FATAL ERROR:\n"
64 "Self-test for algorithm \"");
65 msg += algo;
66 msg += "\" failed!\n\n";
67 msg += "It's likely to be either a PwManager BUG or "
68 "bad hardware in your machine. Please contact the "
69 "maintainer of PwManager for this issue.";
70 std::cerr << msg << std::endl;
71 ::exit(1);
72}
73
74void SelfTest::schedule()
75{
76 if (pthread_mutex_lock(&st_mutex))
77 return;
78 if (st)
79 goto out;
80 st = new SelfTest;
81 st->startTimer();
82out:
83 pthread_mutex_unlock(&st_mutex);
84}
85
86void SelfTest::cancel()
87{
88 if (pthread_mutex_lock(&st_mutex))
89 return;
90 if (!st) {
91 pthread_mutex_unlock(&st_mutex);
92 return;
93 }
94 st->doCancel();
95}
96
97void SelfTest::doCancel()
98{
99 st->stopTimer();
100 st->wait();
101 delete_and_null(st);
102 pthread_mutex_unlock(&st_mutex);
103}
104
105#include "selftest.moc"
diff --git a/pwmanager/pwmanager/selftest.h b/pwmanager/pwmanager/selftest.h
new file mode 100644
index 0000000..4f3ea51
--- a/dev/null
+++ b/pwmanager/pwmanager/selftest.h
@@ -0,0 +1,67 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12#ifndef __SELFTEST_H
13#define __SELFTEST_H
14
15#include <qthread.h>
16#include <qtimer.h>
17#include <qobject.h>
18
19// timeout in seconds
20 #define SCHEDULE_TIMEOUT3
21
22/* internal wrapper to workaround MOC issues */
23class __SelfTest : public QThread
24 , public QObject
25{
26public:
27 __SelfTest() {}
28};
29
30/** PwManager algorithm selftest */
31class SelfTest : public __SelfTest
32{
33 Q_OBJECT
34public:
35 SelfTest();
36 ~SelfTest();
37
38 /** schedule a new test. Only one test can run at once! */
39 static void schedule();
40 /** cancel the running test (if there is one) */
41 static void cancel();
42
43protected:
44 /** start the sched timer */
45 void startTimer()
46 { schedTimer.start(SCHEDULE_TIMEOUT * 1000, true); }
47 /** stop the sched timer */
48 void stopTimer()
49 { schedTimer.stop(); }
50
51protected slots:
52 void doSelfTest()
53 { start(); }
54 void doCancel();
55
56protected:
57 /** print the "failed" message and exit the app */
58 void failed(const char *algo);
59 /** worker thread */
60 void run();
61
62protected:
63 /** schedule timer */
64 QTimer schedTimer;
65};
66
67#endif
diff --git a/pwmanager/pwmanager/serializer.cpp b/pwmanager/pwmanager/serializer.cpp
new file mode 100644
index 0000000..65e442d
--- a/dev/null
+++ b/pwmanager/pwmanager/serializer.cpp
@@ -0,0 +1,664 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12
13/***************************************************************************
14 * copyright (C) 2004 by Ulf Schenk
15 * This file is originaly based on version 2.0 of pwmanager
16 * and was modified to run on embedded devices that run microkde
17 *
18 * $Id$
19 **************************************************************************/
20
21#include "serializer.h"
22#include "pwmexception.h"
23
24#ifdef PWM_EMBEDDED
25#include <klocale.h>
26#endif
27
28/* enable/disable serializer debugging (0/1) */
29 #define SERIALIZER_DEBUG0
30/* use the old xml tags for writing (0/1) */
31 #define USE_OLD_TAGS 0
32/* write a CDATA section (0/1) */
33 #define WRITE_CDATA_SEC 0
34
35
36 #define META_CREATE_DATE"c"
37 #define META_VALID_DATE "v"
38 #define META_EXPIRE_DATE"e"
39 #define META_UPDATE_DATE"u"
40 #define META_UPDATE_INT "i"
41//US ENH : uniqueid
42#define META_UNIQUEID "n"
43
44/* This is compatibility stuff.
45 * The names of the entries have changed and here are the
46 * new and old ones
47 */
48 #define ROOT_MAGIC_OLD "PwM-xml-dat"
49 #define VER_STR_OLD "ver"
50 #define COMPAT_VER_OLD "0x02"
51 #define CAT_ROOT_OLD "categories"
52 #define CAT_PREFIX_OLD "cat_"
53 #define CAT_NAME_OLD "name"
54 #define ENTRY_PREFIX_OLD"entry_"
55 #define ENTRY_DESC_OLD "desc"
56 #define ENTRY_NAME_OLD "name"
57 #define ENTRY_PW_OLD "pw"
58 #define ENTRY_COMMENT_OLD"comment"
59 #define ENTRY_URL_OLD "url"
60 #define ENTRY_LAUNCHER_OLD"launcher"
61 #define ENTRY_LVP_OLD "listViewPos"
62 #define ENTRY_BIN_OLD "b"
63 #define ENTRY_META_OLD "m"
64
65 #define ROOT_MAGIC_NEW "P"
66 #define VER_STR_NEW "v"
67 #define COMPAT_VER_NEW "2"
68 #define CAT_ROOT_NEW "c"
69 #define CAT_PREFIX_NEW "c"
70 #define CAT_NAME_NEW "n"
71 #define ENTRY_PREFIX_NEW"e"
72 #define ENTRY_DESC_NEW "d"
73 #define ENTRY_NAME_NEW "n"
74 #define ENTRY_PW_NEW "p"
75 #define ENTRY_COMMENT_NEW"c"
76 #define ENTRY_URL_NEW "u"
77 #define ENTRY_LAUNCHER_NEW"l"
78 #define ENTRY_LVP_NEW "v"
79 #define ENTRY_BIN_NEW ENTRY_BIN_OLD
80 #define ENTRY_META_NEW ENTRY_META_OLD
81
82#if USE_OLD_TAGS != 0
83 # define ROOT_MAGIC_WR ROOT_MAGIC_OLD
84 # define VER_STR_WR VER_STR_OLD
85 # define COMPAT_VER_WR COMPAT_VER_OLD
86 # define CAT_ROOT_WR CAT_ROOT_OLD
87 # define CAT_PREFIX_WR CAT_PREFIX_OLD
88 # define CAT_NAME_WR CAT_NAME_OLD
89 # define ENTRY_PREFIX_WRENTRY_PREFIX_OLD
90 # define ENTRY_DESC_WR ENTRY_DESC_OLD
91 # define ENTRY_NAME_WR ENTRY_NAME_OLD
92 # define ENTRY_PW_WR ENTRY_PW_OLD
93 # define ENTRY_COMMENT_WRENTRY_COMMENT_OLD
94 # define ENTRY_URL_WR ENTRY_URL_OLD
95 # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_OLD
96 # define ENTRY_LVP_WR ENTRY_LVP_OLD
97 # define ENTRY_BIN_WR ENTRY_BIN_OLD
98 # define ENTRY_META_WR ENTRY_META_OLD
99#else
100 # define ROOT_MAGIC_WR ROOT_MAGIC_NEW
101 # define VER_STR_WR VER_STR_NEW
102 # define COMPAT_VER_WR COMPAT_VER_NEW
103 # define CAT_ROOT_WR CAT_ROOT_NEW
104 # define CAT_PREFIX_WR CAT_PREFIX_NEW
105 # define CAT_NAME_WR CAT_NAME_NEW
106 # define ENTRY_PREFIX_WRENTRY_PREFIX_NEW
107 # define ENTRY_DESC_WR ENTRY_DESC_NEW
108 # define ENTRY_NAME_WR ENTRY_NAME_NEW
109 # define ENTRY_PW_WR ENTRY_PW_NEW
110 # define ENTRY_COMMENT_WRENTRY_COMMENT_NEW
111 # define ENTRY_URL_WR ENTRY_URL_NEW
112 # define ENTRY_LAUNCHER_WRENTRY_LAUNCHER_NEW
113 # define ENTRY_LVP_WR ENTRY_LVP_NEW
114 # define ENTRY_BIN_WR ENTRY_BIN_NEW
115 # define ENTRY_META_WR ENTRY_META_NEW
116#endif
117
118
119Serializer::Serializer()
120{
121 defaultLockStat = true;
122 domDoc = new QDomDocument;
123}
124
125Serializer::Serializer(const QCString &buffer)
126{
127 defaultLockStat = true;
128 domDoc = new QDomDocument;
129 if (!parseXml(buffer)) {
130 delete domDoc;
131#ifndef PWM_EMBEDDED
132 throw PwMException(PwMException::EX_PARSE);
133#else
134 qDebug("Serializer::Serializer : Parse Exception ");
135#endif
136 }
137}
138
139Serializer::~Serializer()
140{
141 delete_ifnot_null(domDoc);
142}
143
144void Serializer::clear()
145{
146 delete_ifnot_null(domDoc);
147 domDoc = new QDomDocument;
148}
149
150bool Serializer::parseXml(const QCString &buffer)
151{
152 PWM_ASSERT(domDoc);
153#ifndef PWM_EMBEDDED
154 if (!domDoc->setContent(buffer, true))
155 return false;
156#else
157 if (!domDoc->setContent(buffer))
158 return false;
159#endif
160 if (!checkValid())
161 return false;
162 return true;
163}
164
165QCString Serializer::getXml()
166{
167 PWM_ASSERT(domDoc);
168
169#ifndef PWM_EMBEDDED
170#if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0
171 QCString tmp(domDoc->toCString(8));
172 printDebug("<BEGIN Serializer::getXml() dump>\n");
173 cout << tmp << endl;
174 printDebug("<END Serializer::getXml() dump>");
175#endif // DEBUG
176
177 QCString ret(domDoc->toCString(0));
178 ret.replace('\n', "");
179 return ret;
180#else
181
182#if defined(PWM_DEBUG) && SERIALIZER_DEBUG != 0
183 QCString tmp(" " + domDoc->toCString());
184 printDebug("<BEGIN Serializer::getXml() dump>\n");
185 cout << tmp << endl;
186 printDebug("<END Serializer::getXml() dump>");
187#endif // DEBUG
188
189 QCString ret(domDoc->toCString());
190 ret.replace(QRegExp("\n"), "");
191 return ret;
192
193#endif
194}
195
196bool Serializer::serialize(const vector<PwMCategoryItem> &dta)
197{
198 PWM_ASSERT(domDoc);
199 QDomElement root(genNewRoot());
200 QDomElement catNode(domDoc->createElement(CAT_ROOT_WR));
201 root.appendChild(catNode);
202 if (!addCategories(&catNode, dta))
203 return false;
204 return true;
205}
206
207bool Serializer::deSerialize(vector<PwMCategoryItem> *dta)
208{
209 PWM_ASSERT(domDoc);
210 PWM_ASSERT(dta);
211 QDomElement root(domDoc->documentElement());
212 QDomNode n;
213
214 dta->clear();
215 for (n = root.firstChild(); !n.isNull(); n = n.nextSibling()) {
216 // find <categories> ... </categories>
217 // <c> ... </c>
218 if (n.nodeName() == CAT_ROOT_NEW ||
219 n.nodeName() == CAT_ROOT_OLD) {
220 if (!readCategories(n, dta)) {
221 return false;
222 }
223
224 /* NOTE: We can stop processing here, as we
225 * don't have more nodes in root, yet.
226 */
227 return true;
228 }
229 }
230 return false;
231}
232
233bool Serializer::readCategories(const QDomNode &n,
234 vector<PwMCategoryItem> *dta)
235{
236 QDomNodeList nl(n.childNodes());
237 QDomNode cur;
238 QString name;
239 unsigned int numCat = nl.count(), i;
240 PwMCategoryItem curCat;
241 vector<PwMDataItem> curEntr;
242
243 if (!numCat) {
244 printDebug("Serializer::readCategories(): empty");
245 return false;
246 }
247 for (i = 0; i < numCat; ++i) {
248 cur = nl.item(i);
249 if (cur.nodeName().left(1) == CAT_PREFIX_NEW ||
250 cur.nodeName().left(4) == CAT_PREFIX_OLD) {
251 name = cur.toElement().attribute(CAT_NAME_NEW);
252 if (name == QString::null)
253 name = cur.toElement().attribute(CAT_NAME_OLD);
254 PWM_ASSERT(name != QString::null);
255 PWM_ASSERT(name != "");
256 curCat.clear();
257 curCat.name = name.latin1();
258 if (!readEntries(cur, &curEntr)) {
259 dta->clear();
260 return false;
261 }
262 curCat.d = curEntr;
263 dta->push_back(curCat);
264 } else {
265 printDebug("Serializer::readCategories(): uh? not a category?");
266 }
267 }
268 return true;
269}
270
271bool Serializer::readEntries(const QDomNode &n,
272 vector<PwMDataItem> *dta)
273{
274 QDomNodeList nl(n.childNodes());
275 QDomNode cur;
276 unsigned int numEntr = nl.count(), i;
277 PwMDataItem curEntr;
278
279 dta->clear();
280 for (i = 0; i < numEntr; ++i) {
281 cur = nl.item(i);
282 if (cur.nodeName().left(1) == ENTRY_PREFIX_NEW ||
283 cur.nodeName().left(6) == ENTRY_PREFIX_OLD) {
284 if (!extractEntry(cur, &curEntr)) {
285 return false;
286 }
287 dta->push_back(curEntr);
288 } else {
289 printDebug("Serializer::readEntries(): hm? not an entry?");
290 }
291 }
292 return true;
293}
294
295bool Serializer::extractEntry(const QDomNode &n,
296 PwMDataItem *dta)
297{
298 QDomNodeList nl(n.childNodes());
299 QDomNode cur, cdata;
300 unsigned int cnt = nl.count(), i;
301 QString name, text;
302
303 if (!cnt) {
304 printDebug("Serializer::extractEntry(): empty");
305 return false;
306 }
307 dta->clear();
308 for (i = 0; i < cnt; ++i) {
309 cur = nl.item(i);
310 name = cur.nodeName();
311 cdata = cur.firstChild();
312 if (unlikely(cdata.isCDATASection())) {
313 text = cdata.toCDATASection().data();
314 } else if (likely(cur.isElement())) {
315 text = cur.toElement().text();
316 } else {
317 printDebug("Serializer::extractEntry(): neither CDATA nor element.");
318 return false;
319 }
320 if (text == " ")
321 text = ""; // for backward compatibility.
322 if (name == ENTRY_DESC_NEW ||
323 name == ENTRY_DESC_OLD) {
324 dta->desc = unescapeEntryData(text).latin1();
325 } else if (name == ENTRY_NAME_NEW ||
326 name == ENTRY_NAME_OLD) {
327 dta->name = unescapeEntryData(text).latin1();
328 } else if (name == ENTRY_PW_NEW ||
329 name == ENTRY_PW_OLD) {
330 dta->pw = unescapeEntryData(text).latin1();
331 } else if (name == ENTRY_COMMENT_NEW ||
332 name == ENTRY_COMMENT_OLD) {
333 dta->comment = unescapeEntryData(text).latin1();
334 } else if (name == ENTRY_URL_NEW ||
335 name == ENTRY_URL_OLD) {
336 dta->url = unescapeEntryData(text).latin1();
337 } else if (name == ENTRY_LAUNCHER_NEW ||
338 name == ENTRY_LAUNCHER_OLD) {
339 dta->launcher = unescapeEntryData(text).latin1();
340 } else if (name == ENTRY_LVP_NEW ||
341 name == ENTRY_LVP_OLD) {
342 dta->listViewPos = strtol(text.latin1(), 0, 10);
343 } else if (name == ENTRY_BIN_NEW) {
344 // ENTRY_BIN_NEW == ENTRY_BIN_OLD
345 if (text == "0") {
346 dta->binary = false;
347 } else {
348 dta->binary = true;
349 }
350 } else if (name == ENTRY_META_NEW) {
351 // ENTRY_META_NEW == ENTRY_META_OLD
352 if (!extractMeta(cur, &dta->meta))
353 return false;
354 } else {
355 printDebug(string("Serializer::extractEntry(): invalid: ")
356 + name.latin1());
357 }
358 }
359 dta->lockStat = defaultLockStat;
360 return true;
361}
362
363bool Serializer::extractMeta(const QDomNode &n,
364 PwMMetaData *dta)
365{
366 QDomNode cur(n.firstChild());
367 QString name, val;
368 while (!cur.isNull()) {
369 name = cur.nodeName();
370 val = cur.toElement().text();
371 if (val == "") {
372 cur = cur.nextSibling();
373 continue;
374 }
375#ifndef PWM_EMBEDDED
376 if (name == META_CREATE_DATE) {
377 dta->create = QDateTime::fromString(val, Qt::ISODate);
378 } else if (name == META_VALID_DATE) {
379 dta->valid = QDateTime::fromString(val, Qt::ISODate);
380 } else if (name == META_EXPIRE_DATE) {
381 dta->expire = QDateTime::fromString(val, Qt::ISODate);
382 } else if (name == META_UPDATE_DATE) {
383 dta->update = QDateTime::fromString(val, Qt::ISODate);
384 } else if (name == META_UPDATE_INT) {
385 dta->updateInt = strtoul(val.latin1(), 0, 10);
386 } else if (name == META_UNIQUEID) {
387 dta->uniqueid = unescapeEntryData(val).latin1();
388 } else {
389 printDebug(string("extractMeta(): invalid: ")
390 + name.latin1());
391 }
392#else
393
394 QDateTime m_dt;
395
396 if ((name == META_CREATE_DATE) ||
397 (name == META_VALID_DATE) ||
398 (name == META_EXPIRE_DATE) ||
399 (name == META_UPDATE_DATE))
400 {
401 int pos = val.find("T");
402 QString date = val.left(pos);
403 QString time = val.mid(pos+1);
404 qDebug("Serializer::extractMeta : date=%s ,time=%s",date.latin1(), time.latin1() );
405 bool ok1, ok2;
406
407 QDate m_date = KGlobal::locale()->readDate(date, &ok1);
408 QTime m_time = KGlobal::locale()->readTime(time, &ok2);
409 if ((ok1 == false) || (ok2 == false))
410 qDebug("Serializer::extractMeta invalid date or time !!!!!!!!!!!!!");
411 m_dt.setDate(m_date);
412 m_dt.setTime(m_time);
413 }
414
415
416 if (name == META_CREATE_DATE) {
417 dta->create = m_dt;
418 } else if (name == META_VALID_DATE) {
419 dta->valid = m_dt;
420 } else if (name == META_EXPIRE_DATE) {
421 dta->expire = m_dt;
422 } else if (name == META_UPDATE_DATE) {
423 dta->update = m_dt;
424 } else if (name == META_UPDATE_INT) {
425 dta->updateInt = strtoul(val.latin1(), 0, 10);
426 } else if (name == META_UNIQUEID) {
427 dta->uniqueid = unescapeEntryData(val).latin1();
428 } else {
429 printDebug(string("extractMeta(): invalid: ")
430 + name.latin1());
431 }
432#endif
433 cur = cur.nextSibling();
434 }
435 return true;
436}
437
438bool Serializer::checkValid()
439{
440 PWM_ASSERT(domDoc);
441 QDomElement root(domDoc->documentElement());
442 if (root.nodeName() != ROOT_MAGIC_NEW &&
443 root.nodeName() != ROOT_MAGIC_OLD) {
444 printDebug("Serializer: wrong magic");
445 return false;
446 }
447 if (root.attribute(VER_STR_NEW) != COMPAT_VER_NEW &&
448 root.attribute(VER_STR_OLD) != COMPAT_VER_OLD) {
449 printDebug("Serializer: wrong version");
450 return false;
451 }
452 return true;
453}
454
455QDomElement Serializer::genNewRoot()
456{
457 PWM_ASSERT(domDoc);
458 QDomElement root(domDoc->createElement(ROOT_MAGIC_WR));
459 root.setAttribute(VER_STR_WR, COMPAT_VER_WR);
460 domDoc->appendChild(root);
461 return root;
462}
463
464bool Serializer::addCategories(QDomElement *e,
465 const vector<PwMCategoryItem> &dta)
466{
467 unsigned int numCat = dta.size(), i;
468 QString curId, curName;
469 QDomElement curCat;
470
471 for (i = 0; i < numCat; ++i) {
472 curId = CAT_PREFIX_WR;
473 curId += tostr(i).c_str();
474 curName = dta[i].name.c_str();
475 curCat = domDoc->createElement(curId);
476 curCat.setAttribute(CAT_NAME_WR, curName);
477 if (!addEntries(&curCat, dta[i].d)) {
478 return false;
479 }
480 e->appendChild(curCat);
481 }
482 return true;
483}
484
485bool Serializer::addEntries(QDomElement *e,
486 const vector<PwMDataItem> &dta)
487{
488 unsigned int numEntr = dta.size(), i;
489 QString curId;
490 QDomElement curEntr;
491
492 for (i = 0; i < numEntr; ++i) {
493 curId = ENTRY_PREFIX_WR;
494 curId += tostr(i).c_str();
495 curEntr = domDoc->createElement(curId);
496 if (!writeEntry(&curEntr, dta[i])) {
497 return false;
498 }
499 e->appendChild(curEntr);
500 }
501 return true;
502}
503
504bool Serializer::writeEntry(QDomElement *e,
505 const PwMDataItem &_dta)
506{
507#if WRITE_CDATA_SEC != 0
508 # define new_text(x)domDoc->createCDATASection(x)
509 QDomCDATASection curText;
510#else
511 # define new_text(x)domDoc->createTextNode(x)
512 QDomText curText;
513#endif
514
515 QDomText plainText;
516 QDomElement tag;
517
518 // begin -- This is for compatibility with the old serializer
519 PwMDataItem dta = _dta;
520 if (!dta.desc.size())
521 dta.desc = " ";
522 if (!dta.name.size())
523 dta.name = " ";
524 if (!dta.pw.size())
525 dta.pw = " ";
526 if (!dta.comment.size())
527 dta.comment = " ";
528 if (!dta.url.size())
529 dta.url = " ";
530 if (!dta.launcher.size())
531 dta.launcher = " ";
532 // end -- This is for compatibility with the old serializer
533
534 tag = domDoc->createElement(ENTRY_DESC_WR);
535 curText = new_text(escapeEntryData(dta.desc.c_str()));
536 tag.appendChild(curText);
537 e->appendChild(tag);
538
539 tag = domDoc->createElement(ENTRY_NAME_WR);
540 curText = new_text(escapeEntryData(dta.name.c_str()));
541 tag.appendChild(curText);
542 e->appendChild(tag);
543
544 tag = domDoc->createElement(ENTRY_PW_WR);
545 curText = new_text(escapeEntryData(dta.pw.c_str()));
546 tag.appendChild(curText);
547 e->appendChild(tag);
548
549 tag = domDoc->createElement(ENTRY_COMMENT_WR);
550 curText = new_text(escapeEntryData(dta.comment.c_str()));
551 tag.appendChild(curText);
552 e->appendChild(tag);
553
554 tag = domDoc->createElement(ENTRY_URL_WR);
555 curText = new_text(escapeEntryData(dta.url.c_str()));
556 tag.appendChild(curText);
557 e->appendChild(tag);
558
559 tag = domDoc->createElement(ENTRY_LAUNCHER_WR);
560 curText = new_text(escapeEntryData(dta.launcher.c_str()));
561 tag.appendChild(curText);
562 e->appendChild(tag);
563
564 tag = domDoc->createElement(ENTRY_LVP_WR);
565 plainText = domDoc->createTextNode(tostr(dta.listViewPos).c_str());
566 tag.appendChild(plainText);
567 e->appendChild(tag);
568
569 tag = domDoc->createElement(ENTRY_BIN_WR);
570 if (dta.binary)
571 plainText = domDoc->createTextNode("1");
572 else
573 plainText = domDoc->createTextNode("0");
574 tag.appendChild(plainText);
575 e->appendChild(tag);
576
577 tag = domDoc->createElement(ENTRY_META_WR);
578 if (!writeMeta(&tag, dta.meta))
579 return false;
580 e->appendChild(tag);
581
582#undef new_text
583 return true;
584}
585
586bool Serializer::writeMeta(QDomElement *e,
587 const PwMMetaData &dta)
588{
589 QDomText text;
590 QDomElement tag;
591
592 tag = domDoc->createElement(META_CREATE_DATE);
593#ifndef PWM_EMBEDDED
594 text = domDoc->createTextNode(dta.create.toString(Qt::ISODate));
595#else
596 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.create, KLocale::ISODate));
597#endif
598 tag.appendChild(text);
599 e->appendChild(tag);
600
601 tag = domDoc->createElement(META_VALID_DATE);
602#ifndef PWM_EMBEDDED
603 text = domDoc->createTextNode(dta.valid.toString(Qt::ISODate));
604#else
605 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.valid, KLocale::ISODate));
606#endif
607 tag.appendChild(text);
608 e->appendChild(tag);
609
610 tag = domDoc->createElement(META_EXPIRE_DATE);
611#ifndef PWM_EMBEDDED
612 text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate));
613#else
614 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate));
615#endif
616 tag.appendChild(text);
617 e->appendChild(tag);
618
619 tag = domDoc->createElement(META_UPDATE_DATE);
620#ifndef PWM_EMBEDDED
621 text = domDoc->createTextNode(dta.update.toString(Qt::ISODate));
622#else
623 text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate));
624#endif
625 tag.appendChild(text);
626 e->appendChild(tag);
627
628 tag = domDoc->createElement(META_UPDATE_INT);
629 text = domDoc->createTextNode(tostr(dta.updateInt).c_str());
630 tag.appendChild(text);
631 e->appendChild(tag);
632
633 tag = domDoc->createElement(META_UNIQUEID);
634 text = domDoc->createTextNode(escapeEntryData(dta.uniqueid));
635 tag.appendChild(text);
636 e->appendChild(tag);
637
638#undef new_text
639 return true;
640}
641
642QString Serializer::escapeEntryData(QString dta)
643{
644#ifndef PWM_EMBEDDED
645 dta.replace('\n', "$>--endl--<$");
646 dta.replace("]]>", "||>");
647#else
648 dta.replace(QRegExp("\n"), "$>--endl--<$");
649 dta.replace(QRegExp("]]>"), "||>");
650#endif
651 return dta;
652}
653
654QString Serializer::unescapeEntryData(QString dta)
655{
656#ifndef PWM_EMBEDDED
657 dta.replace("$>--endl--<$", "\n");
658 dta.replace("||>", "]]>");
659#else
660 dta.replace(QRegExp("$>--endl--<$"), "\n");
661 dta.replace(QRegExp("||>"), "]]>");
662#endif
663 return dta;
664}
diff --git a/pwmanager/pwmanager/serializer.h b/pwmanager/pwmanager/serializer.h
new file mode 100644
index 0000000..245fcee
--- a/dev/null
+++ b/pwmanager/pwmanager/serializer.h
@@ -0,0 +1,102 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12
13/***************************************************************************
14 * copyright (C) 2004 by Ulf Schenk
15 * This file is originaly based on version 2.0 of pwmanager
16 * and was modified to run on embedded devices that run microkde
17 *
18 * $Id$
19 **************************************************************************/
20
21#ifndef __SERIALIZER_H
22#define __SERIALIZER_H
23
24#include "pwmdoc.h"
25
26#include <qcstring.h>
27#include <qdom.h>
28
29#include <vector>
30
31using std::vector;
32
33/** This serializes its input data into
34 * the PwManager-XML-datastream, that becomes
35 * encrypted and maybe compressed
36 */
37class Serializer
38{
39public:
40 /** construct an empty serializer document */
41 Serializer();
42 /** construct a serializer document and parse "buffer" */
43 Serializer(const QCString &buffer);
44 /** destructor */
45 virtual ~Serializer();
46
47 /** clears all data */
48 void clear();
49 /** parse the given data buffer */
50 bool parseXml(const QCString &buffer);
51 /** returns the current XML data */
52 QCString getXml();
53 /** serialize "dta" and store it as XML data */
54 bool serialize(const vector<PwMCategoryItem> &dta);
55 /** deserialize the (parsed) XML data and store it in "dta" */
56 bool deSerialize(vector<PwMCategoryItem> *dta);
57 /** sets the initial default lockStat we should assign */
58 void setDefaultLockStat(bool stat)
59 { defaultLockStat = stat; }
60
61protected:
62 /** main data holder */
63 QDomDocument *domDoc;
64 /** default lockStat to assign */
65 bool defaultLockStat;
66
67protected:
68 /** check if this is valid PwManager XML data */
69 bool checkValid();
70 /** read the categories in the node "n" */
71 bool readCategories(const QDomNode &n,
72 vector<PwMCategoryItem> *dta);
73 /** read the entries in the node "n" */
74 bool readEntries(const QDomNode &n,
75 vector<PwMDataItem> *dta);
76 /** extract the data out of the given item at "n" */
77 bool extractEntry(const QDomNode &n,
78 PwMDataItem *dta);
79 /** extract the meta-data */
80 bool extractMeta(const QDomNode &n,
81 PwMMetaData *dta);
82 /** generates a new root node and sets all initial parameters */
83 QDomElement genNewRoot();
84 /** add new categories to the XML data stream in e */
85 bool addCategories(QDomElement *e,
86 const vector<PwMCategoryItem> &dta);
87 /** add the given new entries to the XML data stream in e */
88 bool addEntries(QDomElement *e,
89 const vector<PwMDataItem> &dta);
90 /** do serialize and write the given entry to the XML stream */
91 bool writeEntry(QDomElement *e,
92 const PwMDataItem &_dta);
93 /** write the entry meta data to the xml stream */
94 bool writeMeta(QDomElement *e,
95 const PwMMetaData &dta);
96 /** escape illegal characters out of the given entry data string */
97 QString escapeEntryData(QString dta);
98 /** un-escape illegal characters out of the given entry data string */
99 QString unescapeEntryData(QString dta);
100};
101
102#endif // __SERIALIZER_H
diff --git a/pwmanager/pwmanager/setmasterpwwnd.cpp b/pwmanager/pwmanager/setmasterpwwnd.cpp
new file mode 100644
index 0000000..c7e0bad
--- a/dev/null
+++ b/pwmanager/pwmanager/setmasterpwwnd.cpp
@@ -0,0 +1,150 @@
1/****************************************************************************
2** Form implementation generated from reading ui file 'setmasterpwwnd.ui'
3**
4** Created: Tue Sep 14 15:43:34 2004
5** by: The User Interface Compiler ($Id$)
6**
7** WARNING! All changes made in this file will be lost!
8****************************************************************************/
9
10#include "setmasterpwwnd.h"
11
12#include <qvariant.h>
13#include <qpushbutton.h>
14#include <qtabwidget.h>
15#include <qwidget.h>
16#include <qlabel.h>
17#include <qlineedit.h>
18#include <qlayout.h>
19#include <qtooltip.h>
20#include <qwhatsthis.h>
21
22/*
23 * Constructs a setMasterPwWnd as a child of 'parent', with the
24 * name 'name' and widget flags set to 'f'.
25 *
26 * The dialog will by default be modeless, unless you set 'modal' to
27 * TRUE to construct a modal dialog.
28 */
29setMasterPwWnd::setMasterPwWnd( QWidget* parent, const char* name, bool modal, WFlags fl )
30 : QDialog( parent, name, modal, fl )
31{
32 if ( !name )
33 setName( "setMasterPwWnd" );
34
35 okButton = new QPushButton( this, "okButton" );
36 okButton->setGeometry( QRect( 10, 280, 107, 27 ) );
37
38 cancelButton = new QPushButton( this, "cancelButton" );
39 cancelButton->setGeometry( QRect( 290, 280, 107, 27 ) );
40
41 mainTab = new QTabWidget( this, "mainTab" );
42 mainTab->setGeometry( QRect( 10, 10, 390, 260 ) );
43
44 tab = new QWidget( mainTab, "tab" );
45
46 textLabel2 = new QLabel( tab, "textLabel2" );
47 textLabel2->setGeometry( QRect( 20, 90, 340, 20 ) );
48
49 textLabel3 = new QLabel( tab, "textLabel3" );
50 textLabel3->setGeometry( QRect( 20, 160, 340, 20 ) );
51
52 textLabel1 = new QLabel( tab, "textLabel1" );
53 textLabel1->setGeometry( QRect( 10, 20, 370, 40 ) );
54 textLabel1->setFrameShape( QLabel::Box );
55 textLabel1->setAlignment( int( QLabel::WordBreak | QLabel::AlignCenter ) );
56
57 pwEdit_1 = new QLineEdit( tab, "pwEdit_1" );
58 pwEdit_1->setGeometry( QRect( 20, 120, 340, 20 ) );
59 pwEdit_1->setEchoMode( QLineEdit::Password );
60
61 pwEdit_2 = new QLineEdit( tab, "pwEdit_2" );
62 pwEdit_2->setGeometry( QRect( 20, 190, 340, 20 ) );
63 pwEdit_2->setEchoMode( QLineEdit::Password );
64 mainTab->insertTab( tab, QString("") );
65
66 tab_2 = new QWidget( mainTab, "tab_2" );
67
68 textLabel1_2 = new QLabel( tab_2, "textLabel1_2" );
69 textLabel1_2->setGeometry( QRect( 10, 20, 370, 40 ) );
70 textLabel1_2->setFrameShape( QLabel::Box );
71 textLabel1_2->setAlignment( int( QLabel::WordBreak | QLabel::AlignCenter ) );
72
73 textLabel2_2 = new QLabel( tab_2, "textLabel2_2" );
74 textLabel2_2->setGeometry( QRect( 20, 190, 170, 20 ) );
75 textLabel2_2->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
76
77 selCardButton = new QPushButton( tab_2, "selCardButton" );
78 selCardButton->setGeometry( QRect( 20, 130, 350, 40 ) );
79
80 genCardButton = new QPushButton( tab_2, "genCardButton" );
81 genCardButton->setGeometry( QRect( 80, 90, 230, 28 ) );
82
83 curCardIdLabel = new QLabel( tab_2, "curCardIdLabel" );
84 curCardIdLabel->setGeometry( QRect( 200, 190, 170, 20 ) );
85 mainTab->insertTab( tab_2, QString("") );
86 languageChange();
87 resize( QSize(411, 313).expandedTo(minimumSizeHint()) );
88 clearWState( WState_Polished );
89
90 // signals and slots connections
91 connect( okButton, SIGNAL( clicked() ), this, SLOT( okButton_slot() ) );
92 connect( cancelButton, SIGNAL( clicked() ), this, SLOT( cancelButton_slot() ) );
93 connect( genCardButton, SIGNAL( clicked() ), this, SLOT( genCardButton_slot() ) );
94 connect( selCardButton, SIGNAL( clicked() ), this, SLOT( selCardButton_slot() ) );
95
96 // tab order
97 setTabOrder( pwEdit_1, pwEdit_2 );
98 setTabOrder( pwEdit_2, okButton );
99 setTabOrder( okButton, cancelButton );
100}
101
102/*
103 * Destroys the object and frees any allocated resources
104 */
105setMasterPwWnd::~setMasterPwWnd()
106{
107 // no need to delete child widgets, Qt does it all for us
108}
109
110/*
111 * Sets the strings of the subwidgets using the current
112 * language.
113 */
114void setMasterPwWnd::languageChange()
115{
116 setCaption( tr( "Set master-password" ) );
117 okButton->setText( tr( "&OK" ) );
118 cancelButton->setText( tr( "&Cancel" ) );
119 textLabel2->setText( tr( "Please enter the new master-password:" ) );
120 textLabel3->setText( tr( "Please enter the password again:" ) );
121 textLabel1->setText( tr( "Using a normal password-string to encrypt the data." ) );
122 mainTab->changeTab( tab, tr( "Normal password" ) );
123 textLabel1_2->setText( tr( "Using a PwM key-card to encrypt the data." ) );
124 textLabel2_2->setText( tr( "selected card:" ) );
125 selCardButton->setText( tr( "&Select the currently inserted card as key-card" ) );
126 genCardButton->setText( tr( "&generate new key-card" ) );
127 curCardIdLabel->setText( QString::null );
128 mainTab->changeTab( tab_2, tr( "Key-card (chipcard)" ) );
129}
130
131void setMasterPwWnd::okButton_slot()
132{
133 qWarning( "setMasterPwWnd::okButton_slot(): Not implemented yet" );
134}
135
136void setMasterPwWnd::cancelButton_slot()
137{
138 qWarning( "setMasterPwWnd::cancelButton_slot(): Not implemented yet" );
139}
140
141void setMasterPwWnd::genCardButton_slot()
142{
143 qWarning( "setMasterPwWnd::genCardButton_slot(): Not implemented yet" );
144}
145
146void setMasterPwWnd::selCardButton_slot()
147{
148 qWarning( "setMasterPwWnd::selCardButton_slot(): Not implemented yet" );
149}
150
diff --git a/pwmanager/pwmanager/setmasterpwwnd.h b/pwmanager/pwmanager/setmasterpwwnd.h
new file mode 100644
index 0000000..c0b1a27
--- a/dev/null
+++ b/pwmanager/pwmanager/setmasterpwwnd.h
@@ -0,0 +1,63 @@
1/****************************************************************************
2** Form interface generated from reading ui file 'setmasterpwwnd.ui'
3**
4** Created: Tue Sep 14 15:32:37 2004
5** by: The User Interface Compiler ($Id$)
6**
7** WARNING! All changes made in this file will be lost!
8****************************************************************************/
9
10#ifndef SETMASTERPWWND_H
11#define SETMASTERPWWND_H
12
13#include <qvariant.h>
14#include <qdialog.h>
15
16class QVBoxLayout;
17class QHBoxLayout;
18class QGridLayout;
19class QSpacerItem;
20class QPushButton;
21class QTabWidget;
22class QWidget;
23class QLabel;
24class QLineEdit;
25
26class setMasterPwWnd : public QDialog
27{
28 Q_OBJECT
29
30public:
31 setMasterPwWnd( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
32 ~setMasterPwWnd();
33
34 QPushButton* okButton;
35 QPushButton* cancelButton;
36 QTabWidget* mainTab;
37 QWidget* tab;
38 QLabel* textLabel2;
39 QLabel* textLabel3;
40 QLabel* textLabel1;
41 QLineEdit* pwEdit_1;
42 QLineEdit* pwEdit_2;
43 QWidget* tab_2;
44 QLabel* textLabel1_2;
45 QLabel* textLabel2_2;
46 QPushButton* selCardButton;
47 QPushButton* genCardButton;
48 QLabel* curCardIdLabel;
49
50public slots:
51 virtual void okButton_slot();
52 virtual void cancelButton_slot();
53 virtual void genCardButton_slot();
54 virtual void selCardButton_slot();
55
56protected:
57
58protected slots:
59 virtual void languageChange();
60
61};
62
63#endif // SETMASTERPWWND_H
diff --git a/pwmanager/pwmanager/setmasterpwwnd.ui b/pwmanager/pwmanager/setmasterpwwnd.ui
new file mode 100644
index 0000000..4f6cd5d
--- a/dev/null
+++ b/pwmanager/pwmanager/setmasterpwwnd.ui
@@ -0,0 +1,294 @@
1<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
2<class>setMasterPwWnd</class>
3<widget class="QDialog">
4 <property name="name">
5 <cstring>setMasterPwWnd</cstring>
6 </property>
7 <property name="geometry">
8 <rect>
9 <x>0</x>
10 <y>0</y>
11 <width>411</width>
12 <height>313</height>
13 </rect>
14 </property>
15 <property name="caption">
16 <string>Set master-password</string>
17 </property>
18 <widget class="QPushButton">
19 <property name="name">
20 <cstring>okButton</cstring>
21 </property>
22 <property name="geometry">
23 <rect>
24 <x>10</x>
25 <y>280</y>
26 <width>107</width>
27 <height>27</height>
28 </rect>
29 </property>
30 <property name="text">
31 <string>&amp;OK</string>
32 </property>
33 </widget>
34 <widget class="QPushButton">
35 <property name="name">
36 <cstring>cancelButton</cstring>
37 </property>
38 <property name="geometry">
39 <rect>
40 <x>290</x>
41 <y>280</y>
42 <width>107</width>
43 <height>27</height>
44 </rect>
45 </property>
46 <property name="text">
47 <string>&amp;Cancel</string>
48 </property>
49 </widget>
50 <widget class="QTabWidget">
51 <property name="name">
52 <cstring>mainTab</cstring>
53 </property>
54 <property name="geometry">
55 <rect>
56 <x>10</x>
57 <y>10</y>
58 <width>390</width>
59 <height>260</height>
60 </rect>
61 </property>
62 <widget class="QWidget">
63 <property name="name">
64 <cstring>tab</cstring>
65 </property>
66 <attribute name="title">
67 <string>Normal password</string>
68 </attribute>
69 <widget class="QLabel">
70 <property name="name">
71 <cstring>textLabel2</cstring>
72 </property>
73 <property name="geometry">
74 <rect>
75 <x>20</x>
76 <y>90</y>
77 <width>340</width>
78 <height>20</height>
79 </rect>
80 </property>
81 <property name="text">
82 <string>Please enter the new master-password:</string>
83 </property>
84 </widget>
85 <widget class="QLabel">
86 <property name="name">
87 <cstring>textLabel3</cstring>
88 </property>
89 <property name="geometry">
90 <rect>
91 <x>20</x>
92 <y>160</y>
93 <width>340</width>
94 <height>20</height>
95 </rect>
96 </property>
97 <property name="text">
98 <string>Please enter the password again:</string>
99 </property>
100 </widget>
101 <widget class="QLabel">
102 <property name="name">
103 <cstring>textLabel1</cstring>
104 </property>
105 <property name="geometry">
106 <rect>
107 <x>10</x>
108 <y>20</y>
109 <width>370</width>
110 <height>40</height>
111 </rect>
112 </property>
113 <property name="frameShape">
114 <enum>Box</enum>
115 </property>
116 <property name="text">
117 <string>Using a normal password-string to encrypt the data.</string>
118 </property>
119 <property name="alignment">
120 <set>WordBreak|AlignCenter</set>
121 </property>
122 </widget>
123 <widget class="QLineEdit">
124 <property name="name">
125 <cstring>pwEdit_1</cstring>
126 </property>
127 <property name="geometry">
128 <rect>
129 <x>20</x>
130 <y>120</y>
131 <width>340</width>
132 <height>20</height>
133 </rect>
134 </property>
135 <property name="echoMode">
136 <enum>Password</enum>
137 </property>
138 </widget>
139 <widget class="QLineEdit">
140 <property name="name">
141 <cstring>pwEdit_2</cstring>
142 </property>
143 <property name="geometry">
144 <rect>
145 <x>20</x>
146 <y>190</y>
147 <width>340</width>
148 <height>20</height>
149 </rect>
150 </property>
151 <property name="echoMode">
152 <enum>Password</enum>
153 </property>
154 </widget>
155 </widget>
156 <widget class="QWidget">
157 <property name="name">
158 <cstring>tab</cstring>
159 </property>
160 <attribute name="title">
161 <string>Key-card (chipcard)</string>
162 </attribute>
163 <widget class="QLabel">
164 <property name="name">
165 <cstring>textLabel1_2</cstring>
166 </property>
167 <property name="geometry">
168 <rect>
169 <x>10</x>
170 <y>20</y>
171 <width>370</width>
172 <height>40</height>
173 </rect>
174 </property>
175 <property name="frameShape">
176 <enum>Box</enum>
177 </property>
178 <property name="text">
179 <string>Using a PwM key-card to encrypt the data.</string>
180 </property>
181 <property name="alignment">
182 <set>WordBreak|AlignCenter</set>
183 </property>
184 </widget>
185 <widget class="QLabel">
186 <property name="name">
187 <cstring>textLabel2_2</cstring>
188 </property>
189 <property name="geometry">
190 <rect>
191 <x>20</x>
192 <y>190</y>
193 <width>170</width>
194 <height>20</height>
195 </rect>
196 </property>
197 <property name="text">
198 <string>selected card:</string>
199 </property>
200 <property name="alignment">
201 <set>AlignVCenter|AlignRight</set>
202 </property>
203 </widget>
204 <widget class="QPushButton">
205 <property name="name">
206 <cstring>selCardButton</cstring>
207 </property>
208 <property name="geometry">
209 <rect>
210 <x>20</x>
211 <y>130</y>
212 <width>350</width>
213 <height>40</height>
214 </rect>
215 </property>
216 <property name="text">
217 <string>&amp;Select the currently inserted card as key-card</string>
218 </property>
219 </widget>
220 <widget class="QPushButton">
221 <property name="name">
222 <cstring>genCardButton</cstring>
223 </property>
224 <property name="geometry">
225 <rect>
226 <x>80</x>
227 <y>90</y>
228 <width>230</width>
229 <height>28</height>
230 </rect>
231 </property>
232 <property name="text">
233 <string>&amp;generate new key-card</string>
234 </property>
235 </widget>
236 <widget class="QLabel">
237 <property name="name">
238 <cstring>curCardIdLabel</cstring>
239 </property>
240 <property name="geometry">
241 <rect>
242 <x>200</x>
243 <y>190</y>
244 <width>170</width>
245 <height>20</height>
246 </rect>
247 </property>
248 <property name="text">
249 <string></string>
250 </property>
251 </widget>
252 </widget>
253 </widget>
254</widget>
255<connections>
256 <connection>
257 <sender>okButton</sender>
258 <signal>clicked()</signal>
259 <receiver>setMasterPwWnd</receiver>
260 <slot>okButton_slot()</slot>
261 </connection>
262 <connection>
263 <sender>cancelButton</sender>
264 <signal>clicked()</signal>
265 <receiver>setMasterPwWnd</receiver>
266 <slot>cancelButton_slot()</slot>
267 </connection>
268 <connection>
269 <sender>genCardButton</sender>
270 <signal>clicked()</signal>
271 <receiver>setMasterPwWnd</receiver>
272 <slot>genCardButton_slot()</slot>
273 </connection>
274 <connection>
275 <sender>selCardButton</sender>
276 <signal>clicked()</signal>
277 <receiver>setMasterPwWnd</receiver>
278 <slot>selCardButton_slot()</slot>
279 </connection>
280</connections>
281<tabstops>
282 <tabstop>pwEdit_1</tabstop>
283 <tabstop>pwEdit_2</tabstop>
284 <tabstop>okButton</tabstop>
285 <tabstop>cancelButton</tabstop>
286</tabstops>
287<slots>
288 <slot>okButton_slot()</slot>
289 <slot>cancelButton_slot()</slot>
290 <slot>genCardButton_slot()</slot>
291 <slot>selCardButton_slot()</slot>
292</slots>
293<layoutdefaults spacing="6" margin="11"/>
294</UI>
diff --git a/pwmanager/pwmanager/setmasterpwwndimpl.cpp b/pwmanager/pwmanager/setmasterpwwndimpl.cpp
new file mode 100644
index 0000000..aac0408
--- a/dev/null
+++ b/pwmanager/pwmanager/setmasterpwwndimpl.cpp
@@ -0,0 +1,152 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12
13/***************************************************************************
14 * copyright (C) 2004 by Ulf Schenk
15 * This file is originaly based on version 1.0.1 of pwmanager
16 * and was modified to run on embedded devices that run microkde
17 *
18 * $Id$
19 **************************************************************************/
20
21#include "setmasterpwwndimpl.h"
22#include "pwm.h"
23#include "globalstuff.h"
24
25#include <kmessagebox.h>
26
27#include <qlineedit.h>
28#include <qlabel.h>
29#include <qtabwidget.h>
30
31#include <stdio.h>
32
33#ifdef CONFIG_KEYCARD
34# include "pwmkeycard.h"
35#endif
36
37 #define STRING_CARD_NONE(SetMasterPwWndImpl::string_cardNone())
38
39
40SetMasterPwWndImpl::SetMasterPwWndImpl(QWidget * parent, const char *name)
41: setMasterPwWnd(parent, name)
42{
43#ifdef CONFIG_KEYCARD
44 curCardIdLabel->setText(STRING_CARD_NONE);
45#else // CONFIG_KEYCARD
46#ifndef PWM_EMBEDDED
47 mainTab->removePage(mainTab->page(1));
48#else
49 qDebug("SetMasterPwWndImpl::SetMasterPwWndImpl has to be fixed");
50#endif
51#endif // CONFIG_KEYCARD
52 keyCard = 0;
53}
54
55SetMasterPwWndImpl::~SetMasterPwWndImpl()
56{
57}
58
59void SetMasterPwWndImpl::okButton_slot()
60{
61 int index = mainTab->currentPageIndex();
62 if (index == 0) {
63 // normal password
64 if (pwEdit_1->text() != pwEdit_2->text()) {
65 KMessageBox::error(this,
66 i18n
67 ("The two passwords you have entered don't match.\n"
68 "Please try entering them again."),
69 i18n("Different passwords"));
70 return;
71 }
72 if (pwEdit_1->text() == "") {
73 KMessageBox::error(this,
74 i18n("No password entered. "
75 "Please type in a password, that "
76 "you want to use for the encryption."),
77 i18n("no password"));
78 return;
79 }
80 } else {
81 // key-card
82 if (curCardIdLabel->text() == STRING_CARD_NONE) {
83 KMessageBox::error(this,
84 i18n("You didn't select a card as "
85 "PwM-key-card."),
86 i18n("no card"));
87 return;
88 }
89 }
90 done(1);
91}
92
93void SetMasterPwWndImpl::cancelButton_slot()
94{
95 done(2);
96}
97
98void SetMasterPwWndImpl::genCardButton_slot()
99{
100#ifdef CONFIG_KEYCARD
101 PWM_ASSERT(keyCard);
102 keyCard->genNewCard();
103#endif // CONFIG_KEYCARD
104}
105
106void SetMasterPwWndImpl::selCardButton_slot()
107{
108#ifdef CONFIG_KEYCARD
109 PWM_ASSERT(keyCard);
110 connect(keyCard, SIGNAL(keyAvailable(uint32_t, const string &)),
111 this, SLOT(keyAvailable_slot(uint32_t, const string &)));
112 keyCard->getKey();
113#endif // CONFIG_KEYCARD
114}
115
116void SetMasterPwWndImpl::keyAvailable_slot(uint32_t cardId,
117 const string &key)
118{
119 if (key == "")
120 return;
121 curCardKey = key;
122 char id_buf[(sizeof(cardId) * 2) + 2 /* "0x" */ + 1 /* NULL */];
123 memcpy(id_buf, "0x", 2);
124 sprintf(id_buf + 2, "%X", cardId);
125 curCardIdLabel->setText(id_buf);
126}
127
128string SetMasterPwWndImpl::getPw(bool *useCard)
129{
130 int index = mainTab->currentPageIndex();
131 if (index == 0) {
132 // normal password
133 if (useCard)
134 *useCard = false;
135 PWM_ASSERT(pwEdit_1->text() == pwEdit_2->text());
136 return pwEdit_1->text().latin1();
137 } else {
138#ifdef CONFIG_KEYCARD
139 // key-card
140 if (useCard)
141 *useCard = true;
142 PWM_ASSERT(curCardKey != "");
143 PWM_ASSERT(curCardIdLabel->text() != STRING_CARD_NONE);
144 return curCardKey;
145#endif // CONFIG_KEYCARD
146 }
147 return "";
148}
149
150#ifndef PWM_EMBEDDED
151#include "setmasterpwwndimpl.moc"
152#endif
diff --git a/pwmanager/pwmanager/setmasterpwwndimpl.h b/pwmanager/pwmanager/setmasterpwwndimpl.h
new file mode 100644
index 0000000..56effc1
--- a/dev/null
+++ b/pwmanager/pwmanager/setmasterpwwndimpl.h
@@ -0,0 +1,72 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12
13/***************************************************************************
14 * copyright (C) 2004 by Ulf Schenk
15 * This file is originaly based on version 1.0.1 of pwmanager
16 * and was modified to run on embedded devices that run microkde
17 *
18 * $Id$
19 **************************************************************************/
20
21#ifndef SETMASTERPWWNDIMPL_H
22#define SETMASTERPWWNDIMPL_H
23
24#include "setmasterpwwnd.h"
25
26#include <klocale.h>
27
28#include <stdint.h>
29#include <string>
30using std::string;
31
32class PwMKeyCard;
33
34/** set master pw wnd */
35class SetMasterPwWndImpl : public setMasterPwWnd
36{
37 Q_OBJECT
38public:
39 SetMasterPwWndImpl(QWidget* parent = 0, const char *name = 0);
40 ~SetMasterPwWndImpl();
41
42 static QString string_cardNone()
43 { return i18n("NONE"); }
44
45 /** returns the selected pw (or the key on the card) */
46 string getPw(bool *useCard);
47 /** set pointer to the keycard-access object */
48 void setPwMKeyCard(PwMKeyCard *_keyCard)
49 { keyCard = _keyCard; }
50
51public slots:
52 /** ok button pressed */
53 void okButton_slot();
54 /** cancel button pressed */
55 void cancelButton_slot();
56 /** "generate a new card" button pressed */
57 void genCardButton_slot();
58 /** "select current card" button pressed */
59 void selCardButton_slot();
60
61protected slots:
62 /** key from PwMKeyCard is available */
63 void keyAvailable_slot(uint32_t cardId, const string &key);
64
65protected:
66 /** key of currently inserted card */
67 string curCardKey;
68 /** pointer to the keycard-access object */
69 PwMKeyCard *keyCard;
70};
71
72#endif
diff --git a/pwmanager/pwmanager/sha1.cpp b/pwmanager/pwmanager/sha1.cpp
new file mode 100644
index 0000000..b2eeb4d
--- a/dev/null
+++ b/pwmanager/pwmanager/sha1.cpp
@@ -0,0 +1,355 @@
1/* 2003.05.02: Derived from libgcrypt-1.1.12 by Michael Buesch */
2
3/* sha1.c - SHA1 hash function
4 *Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc.
5 *
6 * This file is part of Libgcrypt.
7 *
8 * Libgcrypt is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as
10 * published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
12 *
13 * Libgcrypt is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 */
22
23/* Test vectors:
24 *
25 * "abc"
26 * A999 3E36 4706 816A BA3E 2571 7850 C26C 9CD0 D89D
27 *
28 * "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
29 * 8498 3E44 1C3B D26E BAAE 4AA1 F951 29E5 E546 70F1
30 */
31
32/***************************************************************************
33 * copyright (C) 2004 by Ulf Schenk
34 * This file is originaly based on version 1.0.1 of pwmanager
35 * and was modified to run on embedded devices that run microkde
36 *
37 * $Id$
38 **************************************************************************/
39
40#include "sha1.h"
41#include "pwmexception.h"
42
43#include <string.h>
44#include <stdlib.h>
45
46
47void Sha1::burn_stack(int bytes)
48{
49 char buf[128];
50
51 memset(buf, 0, sizeof buf);
52 bytes -= sizeof buf;
53 if (bytes > 0)
54 burn_stack(bytes);
55}
56
57void Sha1::sha1_init()
58{
59 ctx.h0 = 0x67452301;
60 ctx.h1 = 0xefcdab89;
61 ctx.h2 = 0x98badcfe;
62 ctx.h3 = 0x10325476;
63 ctx.h4 = 0xc3d2e1f0;
64 ctx.nblocks = 0;
65 ctx.count = 0;
66}
67
68/****************
69 * Transform the message X which consists of 16 32-bit-words
70 */
71void Sha1::transform(const byte *data)
72{
73 register uint32_t a, b, c, d, e, tm;
74 uint32_t x[16];
75
76 /* get values from the chaining vars */
77 a = ctx.h0;
78 b = ctx.h1;
79 c = ctx.h2;
80 d = ctx.h3;
81 e = ctx.h4;
82
83#ifdef BIG_ENDIAN_HOST
84 memcpy(x, data, 64);
85#else
86 {
87 int i;
88 byte *p2;
89 for (i = 0, p2 = (byte *) x; i < 16; i++, p2 += 4) {
90 p2[3] = *data++;
91 p2[2] = *data++;
92 p2[1] = *data++;
93 p2[0] = *data++;
94 }
95 }
96#endif
97
98#define K1 0x5A827999L
99#define K2 0x6ED9EBA1L
100#define K3 0x8F1BBCDCL
101#define K4 0xCA62C1D6L
102#define F1(x,y,z) ( z ^ ( x & ( y ^ z ) ) )
103#define F2(x,y,z) ( x ^ y ^ z )
104#define F3(x,y,z) ( ( x & y ) | ( z & ( x | y ) ) )
105#define F4(x,y,z) ( x ^ y ^ z )
106
107#define M(i) ( tm = x[i&0x0f] ^ x[(i-14)&0x0f] \
108 ^ x[(i-8)&0x0f] ^ x[(i-3)&0x0f] \
109 , (x[i&0x0f] = rol(tm, 1)) )
110
111#define R(a,b,c,d,e,f,k,m) do { e += rol( a, 5 ) \
112 + f( b, c, d ) \
113 + k \
114 + m; \
115 b = rol( b, 30 ); \
116 } while(0)
117 R(a, b, c, d, e, F1, K1, x[0]);
118 R(e, a, b, c, d, F1, K1, x[1]);
119 R(d, e, a, b, c, F1, K1, x[2]);
120 R(c, d, e, a, b, F1, K1, x[3]);
121 R(b, c, d, e, a, F1, K1, x[4]);
122 R(a, b, c, d, e, F1, K1, x[5]);
123 R(e, a, b, c, d, F1, K1, x[6]);
124 R(d, e, a, b, c, F1, K1, x[7]);
125 R(c, d, e, a, b, F1, K1, x[8]);
126 R(b, c, d, e, a, F1, K1, x[9]);
127 R(a, b, c, d, e, F1, K1, x[10]);
128 R(e, a, b, c, d, F1, K1, x[11]);
129 R(d, e, a, b, c, F1, K1, x[12]);
130 R(c, d, e, a, b, F1, K1, x[13]);
131 R(b, c, d, e, a, F1, K1, x[14]);
132 R(a, b, c, d, e, F1, K1, x[15]);
133 R(e, a, b, c, d, F1, K1, M(16));
134 R(d, e, a, b, c, F1, K1, M(17));
135 R(c, d, e, a, b, F1, K1, M(18));
136 R(b, c, d, e, a, F1, K1, M(19));
137 R(a, b, c, d, e, F2, K2, M(20));
138 R(e, a, b, c, d, F2, K2, M(21));
139 R(d, e, a, b, c, F2, K2, M(22));
140 R(c, d, e, a, b, F2, K2, M(23));
141 R(b, c, d, e, a, F2, K2, M(24));
142 R(a, b, c, d, e, F2, K2, M(25));
143 R(e, a, b, c, d, F2, K2, M(26));
144 R(d, e, a, b, c, F2, K2, M(27));
145 R(c, d, e, a, b, F2, K2, M(28));
146 R(b, c, d, e, a, F2, K2, M(29));
147 R(a, b, c, d, e, F2, K2, M(30));
148 R(e, a, b, c, d, F2, K2, M(31));
149 R(d, e, a, b, c, F2, K2, M(32));
150 R(c, d, e, a, b, F2, K2, M(33));
151 R(b, c, d, e, a, F2, K2, M(34));
152 R(a, b, c, d, e, F2, K2, M(35));
153 R(e, a, b, c, d, F2, K2, M(36));
154 R(d, e, a, b, c, F2, K2, M(37));
155 R(c, d, e, a, b, F2, K2, M(38));
156 R(b, c, d, e, a, F2, K2, M(39));
157 R(a, b, c, d, e, F3, K3, M(40));
158 R(e, a, b, c, d, F3, K3, M(41));
159 R(d, e, a, b, c, F3, K3, M(42));
160 R(c, d, e, a, b, F3, K3, M(43));
161 R(b, c, d, e, a, F3, K3, M(44));
162 R(a, b, c, d, e, F3, K3, M(45));
163 R(e, a, b, c, d, F3, K3, M(46));
164 R(d, e, a, b, c, F3, K3, M(47));
165 R(c, d, e, a, b, F3, K3, M(48));
166 R(b, c, d, e, a, F3, K3, M(49));
167 R(a, b, c, d, e, F3, K3, M(50));
168 R(e, a, b, c, d, F3, K3, M(51));
169 R(d, e, a, b, c, F3, K3, M(52));
170 R(c, d, e, a, b, F3, K3, M(53));
171 R(b, c, d, e, a, F3, K3, M(54));
172 R(a, b, c, d, e, F3, K3, M(55));
173 R(e, a, b, c, d, F3, K3, M(56));
174 R(d, e, a, b, c, F3, K3, M(57));
175 R(c, d, e, a, b, F3, K3, M(58));
176 R(b, c, d, e, a, F3, K3, M(59));
177 R(a, b, c, d, e, F4, K4, M(60));
178 R(e, a, b, c, d, F4, K4, M(61));
179 R(d, e, a, b, c, F4, K4, M(62));
180 R(c, d, e, a, b, F4, K4, M(63));
181 R(b, c, d, e, a, F4, K4, M(64));
182 R(a, b, c, d, e, F4, K4, M(65));
183 R(e, a, b, c, d, F4, K4, M(66));
184 R(d, e, a, b, c, F4, K4, M(67));
185 R(c, d, e, a, b, F4, K4, M(68));
186 R(b, c, d, e, a, F4, K4, M(69));
187 R(a, b, c, d, e, F4, K4, M(70));
188 R(e, a, b, c, d, F4, K4, M(71));
189 R(d, e, a, b, c, F4, K4, M(72));
190 R(c, d, e, a, b, F4, K4, M(73));
191 R(b, c, d, e, a, F4, K4, M(74));
192 R(a, b, c, d, e, F4, K4, M(75));
193 R(e, a, b, c, d, F4, K4, M(76));
194 R(d, e, a, b, c, F4, K4, M(77));
195 R(c, d, e, a, b, F4, K4, M(78));
196 R(b, c, d, e, a, F4, K4, M(79));
197
198 /* update chainig vars */
199 ctx.h0 += a;
200 ctx.h1 += b;
201 ctx.h2 += c;
202 ctx.h3 += d;
203 ctx.h4 += e;
204#undef K1
205#undef K2
206#undef K3
207#undef K4
208#undef F1
209#undef F2
210#undef F3
211#undef F4
212#undef M
213#undef R
214}
215
216/* Update the message digest with the contents
217 * of INBUF with length INLEN.
218 */
219void Sha1::sha1_write(const byte * inbuf, uint32_t inlen)
220{
221 if (ctx.count == 64) {/* flush the buffer */
222 transform(ctx.buf);
223 burn_stack(88 + 4 * sizeof(void *));
224 ctx.count = 0;
225 ctx.nblocks++;
226 }
227 if (!inbuf)
228 return;
229 if (ctx.count) {
230 for (; inlen && ctx.count < 64; inlen--)
231 ctx.buf[ctx.count++] = *inbuf++;
232 sha1_write(NULL, 0);
233 if (!inlen)
234 return;
235 }
236
237 while (inlen >= 64) {
238 transform(inbuf);
239 ctx.count = 0;
240 ctx.nblocks++;
241 inlen -= 64;
242 inbuf += 64;
243 }
244 burn_stack(88 + 4 * sizeof(void *));
245 for (; inlen && ctx.count < 64; inlen--)
246 ctx.buf[ctx.count++] = *inbuf++;
247}
248
249/* The routine final terminates the computation and
250 * returns the digest.
251 * The handle is prepared for a new cycle, but adding bytes to the
252 * handle will the destroy the returned buffer.
253 * Returns: 20 bytes representing the digest.
254 */
255
256void Sha1::sha1_final()
257{
258 uint32_t t, msb, lsb;
259 byte *p;
260
261 sha1_write(NULL, 0); /* flush */ ;
262
263 t = ctx.nblocks;
264 /* multiply by 64 to make a byte count */
265 lsb = t << 6;
266 msb = t >> 26;
267 /* add the count */
268 t = lsb;
269 if ((lsb += ctx.count) < t)
270 msb++;
271 /* multiply by 8 to make a bit count */
272 t = lsb;
273 lsb <<= 3;
274 msb <<= 3;
275 msb |= t >> 29;
276
277 if (ctx.count < 56) {/* enough room */
278 ctx.buf[ctx.count++] = 0x80;/* pad */
279 while (ctx.count < 56)
280 ctx.buf[ctx.count++] = 0;/* pad */
281 } else { /* need one extra block */
282 ctx.buf[ctx.count++] = 0x80;/* pad character */
283 while (ctx.count < 64)
284 ctx.buf[ctx.count++] = 0;
285 sha1_write(NULL, 0); /* flush */ ;
286 memset(ctx.buf, 0, 56);/* fill next block with zeroes */
287 }
288 /* append the 64 bit count */
289 ctx.buf[56] = msb >> 24;
290 ctx.buf[57] = msb >> 16;
291 ctx.buf[58] = msb >> 8;
292 ctx.buf[59] = msb;
293 ctx.buf[60] = lsb >> 24;
294 ctx.buf[61] = lsb >> 16;
295 ctx.buf[62] = lsb >> 8;
296 ctx.buf[63] = lsb;
297 transform(ctx.buf);
298 burn_stack(88 + 4 * sizeof(void *));
299
300 p = ctx.buf;
301#ifdef BIG_ENDIAN_HOST
302#define X(a) do { *(uint32_t*)p = ctx.h##a ; p += 4; } while(0)
303 #else /* little endian */
304 #define X(a) do { *p++ = ctx.h##a >> 24; *p++ = ctx.h##a >> 16; \
305 *p++ = ctx.h##a >> 8; *p++ = ctx.h##a; } while(0)
306#endif
307 X(0);
308 X(1);
309 X(2);
310 X(3);
311 X(4);
312#undef X
313
314}
315
316string Sha1::sha1_read()
317{
318 sha1_final();
319 string ret;
320 ret.assign((const char*)ctx.buf, SHA1_HASH_LEN_BYTE);
321 sha1_init();
322 return ret;
323}
324
325bool Sha1::selfTest()
326{
327 const char test1[] = { 'a', 'b', 'c' };
328 const uint32_t test1_len = array_size(test1);
329 const char test1_md[] = { 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E,
330 0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D };
331 const char test2[] = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
332 const uint32_t test2_len = array_size(test2) - 1;
333 const char test2_md[] = { 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE,
334 0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1 };
335 const uint32_t test3_len = 640;
336 const char test3_single[] = { '0', '1', '2', '3', '4', '5', '6', '7' };
337 const uint32_t test3_single_len = array_size(test3_single);
338 char test3[test3_len];
339 uint32_t i;
340 for (i = 0; i < test3_len / test3_single_len; ++i)
341 memcpy(test3 + (i * test3_single_len), test3_single, test3_single_len);
342 const char test3_md[] = { 0xDE, 0xA3, 0x56, 0xA2, 0xCD, 0xDD, 0x90, 0xC7, 0xA7, 0xEC,
343 0xED, 0xC5, 0xEB, 0xB5, 0x63, 0x93, 0x4F, 0x46, 0x04, 0x52 };
344 Sha1 sha1;
345 sha1.sha1_write(reinterpret_cast<const byte *>(test1), test1_len);
346 if (unlikely(memcmp(sha1.sha1_read().c_str(), test1_md, SHA1_HASH_LEN_BYTE)))
347 return false;
348 sha1.sha1_write(reinterpret_cast<const byte *>(test2), test2_len);
349 if (unlikely(memcmp(sha1.sha1_read().c_str(), test2_md, SHA1_HASH_LEN_BYTE)))
350 return false;
351 sha1.sha1_write(reinterpret_cast<const byte *>(test3), test3_len);
352 if (unlikely(memcmp(sha1.sha1_read().c_str(), test3_md, SHA1_HASH_LEN_BYTE)))
353 return false;
354 return true;
355}
diff --git a/pwmanager/pwmanager/sha1.h b/pwmanager/pwmanager/sha1.h
new file mode 100644
index 0000000..29442a7
--- a/dev/null
+++ b/pwmanager/pwmanager/sha1.h
@@ -0,0 +1,75 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef SHA1_H
21#define SHA1_H
22
23#include <stdint.h>
24#include <string>
25using std::string;
26
27 typedef uint8_t byte;
28
29 #define SHA1_HASH_LEN_BIT160
30 #define SHA1_HASH_LEN_BYTE(SHA1_HASH_LEN_BIT / 8)
31
32/** sha1 hash algorithm.
33 * Derived from libgcrypt-1.1.12
34 */
35class Sha1
36{
37 struct SHA1_CONTEXT
38 {
39 uint32_t h0,h1,h2,h3,h4;
40 uint32_t nblocks;
41 byte buf[64];
42 int count;
43 };
44
45public:
46 Sha1() { sha1_init(); }
47 static bool selfTest();
48
49 void sha1_write(const byte *inbuf, uint32_t inlen);
50 string sha1_read();
51
52protected:
53 void sha1_init();
54 void sha1_final();
55 void burn_stack (int bytes);
56 void transform(const byte *data);
57
58 /** Rotate a 32 bit integer by n bytes */
59 uint32_t rol(uint32_t x, int n)
60 {
61#if defined(__GNUC__) && defined(__i386__)
62 __asm__("roll %%cl,%0"
63 :"=r" (x)
64 :"0" (x),"c" (n));
65 return x;
66#else
67 return ((x) << (n)) | ((x) >> (32-(n)));
68#endif
69 }
70
71protected:
72 struct SHA1_CONTEXT ctx;
73};
74
75#endif
diff --git a/pwmanager/pwmanager/spinforsignal.cpp b/pwmanager/pwmanager/spinforsignal.cpp
new file mode 100644
index 0000000..0401d43
--- a/dev/null
+++ b/pwmanager/pwmanager/spinforsignal.cpp
@@ -0,0 +1,91 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "spinforsignal.h"
21#include "pwmexception.h"
22
23#ifndef PWM_EMBEDDED
24#include <kapp.h>
25#endif
26
27#include <time.h>
28#include <pthread.h>
29
30static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
31
32
33SpinForSignal::SpinForSignal()
34 : QObject()
35{
36 doSpin = false;
37}
38
39void SpinForSignal::spinSleep()
40{
41 const struct timespec t = { 0, 100 };
42 nanosleep(&t, 0);
43}
44
45void SpinForSignal::_spin()
46{
47 doSpin = true;
48 printDebug("spinning for signal.");
49 do {
50 kapp->processEvents();
51 spinSleep();
52 } while (doSpin);
53 printDebug("spinning stopped.");
54}
55
56void SpinForSignal::spin(uint32_t *u32, string *str)
57{
58 _spin();
59 if (pthread_mutex_lock(&mutex)) {
60 printError("spin(uint32_t *u32, string *str): pthread_mutex_lock failed");
61 return;
62 }
63 *u32 = u32_storage;
64 *str = str_storage;
65 pthread_mutex_unlock(&mutex);
66}
67
68void SpinForSignal::u32_str_slot(uint32_t u32, const string &str)
69{
70 if (doSpin) {
71 printDebug("ul_str_slot(unsigned long ul, const string &str)");
72 u32_storage = u32;
73 str_storage = str;
74 doSpin = false;
75 }
76}
77
78void SpinForSignal::cancelSpin()
79{
80 if (pthread_mutex_lock(&mutex)) {
81 printError("cancelSpin(): pthread_mutex_lock failed");
82 return;
83 }
84 printDebug("spinning cancelled.");
85 u32_storage = 0;
86 str_storage = "";
87 doSpin = false;
88 pthread_mutex_unlock(&mutex);
89}
90
91#include "spinforsignal.moc"
diff --git a/pwmanager/pwmanager/spinforsignal.h b/pwmanager/pwmanager/spinforsignal.h
new file mode 100644
index 0000000..ec6103b
--- a/dev/null
+++ b/pwmanager/pwmanager/spinforsignal.h
@@ -0,0 +1,55 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef SPINFORSIGNAL_H
21#define SPINFORSIGNAL_H
22
23#include <qobject.h>
24
25#include <stdint.h>
26#include <string>
27using std::string;
28
29/** non-ui-blocking spin for a QT-signal */
30class SpinForSignal : public QObject
31{
32 Q_OBJECT
33public:
34 SpinForSignal();
35 ~SpinForSignal() {}
36
37 /** do spin for signal */
38 void spin(uint32_t *u32, string *str);
39 /** cancel spinning */
40 void cancelSpin();
41
42public slots:
43 void u32_str_slot(uint32_t u32, const string &str);
44
45protected:
46 volatile bool doSpin;
47 uint32_t u32_storage;
48 string str_storage;
49
50protected:
51 inline void spinSleep();
52 void _spin();
53};
54
55#endif
diff --git a/pwmanager/pwmanager/subtbledit.cpp b/pwmanager/pwmanager/subtbledit.cpp
new file mode 100644
index 0000000..e4d805c
--- a/dev/null
+++ b/pwmanager/pwmanager/subtbledit.cpp
@@ -0,0 +1,140 @@
1/****************************************************************************
2** Form implementation generated from reading ui file 'subtbledit.ui'
3**
4** Created: Tue Sep 14 15:44:17 2004
5** by: The User Interface Compiler ($Id$)
6**
7** WARNING! All changes made in this file will be lost!
8****************************************************************************/
9
10#include "subtbledit.h"
11
12#include <qvariant.h>
13#include <qlabel.h>
14#include <qlineedit.h>
15#include <qpushbutton.h>
16#include <qgroupbox.h>
17#include <qlistbox.h>
18#include <qlayout.h>
19#include <qtooltip.h>
20#include <qwhatsthis.h>
21
22/*
23 * Constructs a subTblEdit as a child of 'parent', with the
24 * name 'name' and widget flags set to 'f'.
25 *
26 * The dialog will by default be modeless, unless you set 'modal' to
27 * TRUE to construct a modal dialog.
28 */
29subTblEdit::subTblEdit( QWidget* parent, const char* name, bool modal, WFlags fl )
30 : QDialog( parent, name, modal, fl )
31{
32 if ( !name )
33 setName( "subTblEdit" );
34
35 textLabel4 = new QLabel( this, "textLabel4" );
36 textLabel4->setGeometry( QRect( 20, 10, 310, 20 ) );
37 textLabel4->setAlignment( int( QLabel::AlignCenter ) );
38
39 textLabel5 = new QLabel( this, "textLabel5" );
40 textLabel5->setGeometry( QRect( 20, 70, 310, 20 ) );
41 textLabel5->setAlignment( int( QLabel::AlignCenter ) );
42
43 titleLineEdit = new QLineEdit( this, "titleLineEdit" );
44 titleLineEdit->setGeometry( QRect( 20, 30, 310, 26 ) );
45
46 okButton = new QPushButton( this, "okButton" );
47 okButton->setGeometry( QRect( 20, 420, 140, 31 ) );
48
49 cancelButton = new QPushButton( this, "cancelButton" );
50 cancelButton->setGeometry( QRect( 190, 420, 140, 31 ) );
51
52 groupBox3 = new QGroupBox( this, "groupBox3" );
53 groupBox3->setGeometry( QRect( 20, 210, 310, 200 ) );
54
55 textLabel6 = new QLabel( groupBox3, "textLabel6" );
56 textLabel6->setGeometry( QRect( 20, 30, 270, 20 ) );
57
58 textLabel7 = new QLabel( groupBox3, "textLabel7" );
59 textLabel7->setGeometry( QRect( 20, 90, 270, 20 ) );
60
61 addButton = new QPushButton( groupBox3, "addButton" );
62 addButton->setGeometry( QRect( 30, 150, 250, 31 ) );
63
64 valueLineEdit = new QLineEdit( groupBox3, "valueLineEdit" );
65 valueLineEdit->setGeometry( QRect( 20, 110, 270, 26 ) );
66
67 nameLineEdit = new QLineEdit( groupBox3, "nameLineEdit" );
68 nameLineEdit->setGeometry( QRect( 20, 50, 270, 26 ) );
69
70 entryListBox = new QListBox( this, "entryListBox" );
71 entryListBox->setGeometry( QRect( 20, 90, 310, 80 ) );
72
73 delButton = new QPushButton( this, "delButton" );
74 delButton->setGeometry( QRect( 110, 170, 130, 31 ) );
75 languageChange();
76 resize( QSize(351, 464).expandedTo(minimumSizeHint()) );
77 clearWState( WState_Polished );
78
79 // signals and slots connections
80 connect( okButton, SIGNAL( clicked() ), this, SLOT( okButton_slot() ) );
81 connect( cancelButton, SIGNAL( clicked() ), this, SLOT( cancelButton_slot() ) );
82 connect( addButton, SIGNAL( clicked() ), this, SLOT( addButton_slot() ) );
83 connect( delButton, SIGNAL( clicked() ), this, SLOT( delButton_slot() ) );
84
85 // tab order
86 setTabOrder( titleLineEdit, entryListBox );
87 setTabOrder( entryListBox, delButton );
88 setTabOrder( delButton, nameLineEdit );
89 setTabOrder( nameLineEdit, valueLineEdit );
90 setTabOrder( valueLineEdit, addButton );
91 setTabOrder( addButton, okButton );
92 setTabOrder( okButton, cancelButton );
93}
94
95/*
96 * Destroys the object and frees any allocated resources
97 */
98subTblEdit::~subTblEdit()
99{
100 // no need to delete child widgets, Qt does it all for us
101}
102
103/*
104 * Sets the strings of the subwidgets using the current
105 * language.
106 */
107void subTblEdit::languageChange()
108{
109 setCaption( tr( "HTML-comment subtable editor" ) );
110 textLabel4->setText( tr( "Sub-title:" ) );
111 textLabel5->setText( tr( "Current subtable-entries:" ) );
112 okButton->setText( tr( "&OK" ) );
113 cancelButton->setText( tr( "&Cancel" ) );
114 groupBox3->setTitle( tr( "New entry" ) );
115 textLabel6->setText( tr( "Entry name:" ) );
116 textLabel7->setText( tr( "Entry value:" ) );
117 addButton->setText( tr( "Add..." ) );
118 delButton->setText( tr( "Delete" ) );
119}
120
121void subTblEdit::okButton_slot()
122{
123 qWarning( "subTblEdit::okButton_slot(): Not implemented yet" );
124}
125
126void subTblEdit::cancelButton_slot()
127{
128 qWarning( "subTblEdit::cancelButton_slot(): Not implemented yet" );
129}
130
131void subTblEdit::addButton_slot()
132{
133 qWarning( "subTblEdit::addButton_slot(): Not implemented yet" );
134}
135
136void subTblEdit::delButton_slot()
137{
138 qWarning( "subTblEdit::delButton_slot(): Not implemented yet" );
139}
140
diff --git a/pwmanager/pwmanager/subtbledit.h b/pwmanager/pwmanager/subtbledit.h
new file mode 100644
index 0000000..601621d
--- a/dev/null
+++ b/pwmanager/pwmanager/subtbledit.h
@@ -0,0 +1,62 @@
1/****************************************************************************
2** Form interface generated from reading ui file 'subtbledit.ui'
3**
4** Created: Tue Sep 14 15:32:37 2004
5** by: The User Interface Compiler ($Id$)
6**
7** WARNING! All changes made in this file will be lost!
8****************************************************************************/
9
10#ifndef SUBTBLEDIT_H
11#define SUBTBLEDIT_H
12
13#include <qvariant.h>
14#include <qdialog.h>
15
16class QVBoxLayout;
17class QHBoxLayout;
18class QGridLayout;
19class QSpacerItem;
20class QLabel;
21class QLineEdit;
22class QPushButton;
23class QGroupBox;
24class QListBox;
25class QListBoxItem;
26
27class subTblEdit : public QDialog
28{
29 Q_OBJECT
30
31public:
32 subTblEdit( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
33 ~subTblEdit();
34
35 QLabel* textLabel4;
36 QLabel* textLabel5;
37 QLineEdit* titleLineEdit;
38 QPushButton* okButton;
39 QPushButton* cancelButton;
40 QGroupBox* groupBox3;
41 QLabel* textLabel6;
42 QLabel* textLabel7;
43 QPushButton* addButton;
44 QLineEdit* valueLineEdit;
45 QLineEdit* nameLineEdit;
46 QListBox* entryListBox;
47 QPushButton* delButton;
48
49public slots:
50 virtual void okButton_slot();
51 virtual void cancelButton_slot();
52 virtual void addButton_slot();
53 virtual void delButton_slot();
54
55protected:
56
57protected slots:
58 virtual void languageChange();
59
60};
61
62#endif // SUBTBLEDIT_H
diff --git a/pwmanager/pwmanager/subtbledit.ui b/pwmanager/pwmanager/subtbledit.ui
new file mode 100644
index 0000000..1cf1826
--- a/dev/null
+++ b/pwmanager/pwmanager/subtbledit.ui
@@ -0,0 +1,264 @@
1<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
2<class>subTblEdit</class>
3<widget class="QDialog">
4 <property name="name">
5 <cstring>subTblEdit</cstring>
6 </property>
7 <property name="geometry">
8 <rect>
9 <x>0</x>
10 <y>0</y>
11 <width>351</width>
12 <height>464</height>
13 </rect>
14 </property>
15 <property name="caption">
16 <string>HTML-comment subtable editor</string>
17 </property>
18 <widget class="QLabel">
19 <property name="name">
20 <cstring>textLabel4</cstring>
21 </property>
22 <property name="geometry">
23 <rect>
24 <x>20</x>
25 <y>10</y>
26 <width>310</width>
27 <height>20</height>
28 </rect>
29 </property>
30 <property name="text">
31 <string>Sub-title:</string>
32 </property>
33 <property name="alignment">
34 <set>AlignCenter</set>
35 </property>
36 </widget>
37 <widget class="QLabel">
38 <property name="name">
39 <cstring>textLabel5</cstring>
40 </property>
41 <property name="geometry">
42 <rect>
43 <x>20</x>
44 <y>70</y>
45 <width>310</width>
46 <height>20</height>
47 </rect>
48 </property>
49 <property name="text">
50 <string>Current subtable-entries:</string>
51 </property>
52 <property name="alignment">
53 <set>AlignCenter</set>
54 </property>
55 </widget>
56 <widget class="QLineEdit">
57 <property name="name">
58 <cstring>titleLineEdit</cstring>
59 </property>
60 <property name="geometry">
61 <rect>
62 <x>20</x>
63 <y>30</y>
64 <width>310</width>
65 <height>26</height>
66 </rect>
67 </property>
68 </widget>
69 <widget class="QPushButton">
70 <property name="name">
71 <cstring>okButton</cstring>
72 </property>
73 <property name="geometry">
74 <rect>
75 <x>20</x>
76 <y>420</y>
77 <width>140</width>
78 <height>31</height>
79 </rect>
80 </property>
81 <property name="text">
82 <string>&amp;OK</string>
83 </property>
84 </widget>
85 <widget class="QPushButton">
86 <property name="name">
87 <cstring>cancelButton</cstring>
88 </property>
89 <property name="geometry">
90 <rect>
91 <x>190</x>
92 <y>420</y>
93 <width>140</width>
94 <height>31</height>
95 </rect>
96 </property>
97 <property name="text">
98 <string>&amp;Cancel</string>
99 </property>
100 </widget>
101 <widget class="QGroupBox">
102 <property name="name">
103 <cstring>groupBox3</cstring>
104 </property>
105 <property name="geometry">
106 <rect>
107 <x>20</x>
108 <y>210</y>
109 <width>310</width>
110 <height>200</height>
111 </rect>
112 </property>
113 <property name="title">
114 <string>New entry</string>
115 </property>
116 <widget class="QLabel">
117 <property name="name">
118 <cstring>textLabel6</cstring>
119 </property>
120 <property name="geometry">
121 <rect>
122 <x>20</x>
123 <y>30</y>
124 <width>270</width>
125 <height>20</height>
126 </rect>
127 </property>
128 <property name="text">
129 <string>Entry name:</string>
130 </property>
131 </widget>
132 <widget class="QLabel">
133 <property name="name">
134 <cstring>textLabel7</cstring>
135 </property>
136 <property name="geometry">
137 <rect>
138 <x>20</x>
139 <y>90</y>
140 <width>270</width>
141 <height>20</height>
142 </rect>
143 </property>
144 <property name="text">
145 <string>Entry value:</string>
146 </property>
147 </widget>
148 <widget class="QPushButton">
149 <property name="name">
150 <cstring>addButton</cstring>
151 </property>
152 <property name="geometry">
153 <rect>
154 <x>30</x>
155 <y>150</y>
156 <width>250</width>
157 <height>31</height>
158 </rect>
159 </property>
160 <property name="text">
161 <string>Add...</string>
162 </property>
163 </widget>
164 <widget class="QLineEdit">
165 <property name="name">
166 <cstring>valueLineEdit</cstring>
167 </property>
168 <property name="geometry">
169 <rect>
170 <x>20</x>
171 <y>110</y>
172 <width>270</width>
173 <height>26</height>
174 </rect>
175 </property>
176 </widget>
177 <widget class="QLineEdit">
178 <property name="name">
179 <cstring>nameLineEdit</cstring>
180 </property>
181 <property name="geometry">
182 <rect>
183 <x>20</x>
184 <y>50</y>
185 <width>270</width>
186 <height>26</height>
187 </rect>
188 </property>
189 </widget>
190 </widget>
191 <widget class="QListBox">
192 <property name="name">
193 <cstring>entryListBox</cstring>
194 </property>
195 <property name="geometry">
196 <rect>
197 <x>20</x>
198 <y>90</y>
199 <width>310</width>
200 <height>80</height>
201 </rect>
202 </property>
203 </widget>
204 <widget class="QPushButton">
205 <property name="name">
206 <cstring>delButton</cstring>
207 </property>
208 <property name="geometry">
209 <rect>
210 <x>110</x>
211 <y>170</y>
212 <width>130</width>
213 <height>31</height>
214 </rect>
215 </property>
216 <property name="text">
217 <string>Delete</string>
218 </property>
219 </widget>
220</widget>
221<connections>
222 <connection>
223 <sender>okButton</sender>
224 <signal>clicked()</signal>
225 <receiver>subTblEdit</receiver>
226 <slot>okButton_slot()</slot>
227 </connection>
228 <connection>
229 <sender>cancelButton</sender>
230 <signal>clicked()</signal>
231 <receiver>subTblEdit</receiver>
232 <slot>cancelButton_slot()</slot>
233 </connection>
234 <connection>
235 <sender>addButton</sender>
236 <signal>clicked()</signal>
237 <receiver>subTblEdit</receiver>
238 <slot>addButton_slot()</slot>
239 </connection>
240 <connection>
241 <sender>delButton</sender>
242 <signal>clicked()</signal>
243 <receiver>subTblEdit</receiver>
244 <slot>delButton_slot()</slot>
245 </connection>
246</connections>
247<tabstops>
248 <tabstop>titleLineEdit</tabstop>
249 <tabstop>entryListBox</tabstop>
250 <tabstop>delButton</tabstop>
251 <tabstop>nameLineEdit</tabstop>
252 <tabstop>valueLineEdit</tabstop>
253 <tabstop>addButton</tabstop>
254 <tabstop>okButton</tabstop>
255 <tabstop>cancelButton</tabstop>
256</tabstops>
257<slots>
258 <slot>okButton_slot()</slot>
259 <slot>cancelButton_slot()</slot>
260 <slot>addButton_slot()</slot>
261 <slot>delButton_slot()</slot>
262</slots>
263<layoutdefaults spacing="6" margin="11"/>
264</UI>
diff --git a/pwmanager/pwmanager/subtbleditimpl.cpp b/pwmanager/pwmanager/subtbleditimpl.cpp
new file mode 100644
index 0000000..cfc66dd
--- a/dev/null
+++ b/pwmanager/pwmanager/subtbleditimpl.cpp
@@ -0,0 +1,138 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "subtbleditimpl.h"
21#include "pwmexception.h"
22
23#include <qmessagebox.h>
24
25#include <klocale.h>
26
27
28SubTblEditImpl::SubTblEditImpl(QWidget* parent,
29 const char* name,
30 WFlags fl)
31 : subTblEdit(parent, name, fl)
32{
33 prevSelection = -1;
34 connect(entryListBox, SIGNAL(currentChanged(QListBoxItem *)),
35 this, SLOT(selectedEntry_slot()));
36}
37
38SubTblEditImpl::~SubTblEditImpl()
39{
40}
41
42void SubTblEditImpl::okButton_slot()
43{
44 if (getTitle().isEmpty()) {
45 QMessageBox::information(this,
46 i18n("no title"),
47 i18n("Please enter a title."));
48 return;
49 }
50 if (!entries.size()) {
51 QMessageBox::information(this,
52 i18n("no entries"),
53 i18n("Please add some entries."));
54 return;
55 }
56 int index = curIndex();
57 if (index != -1) {
58 entries[index].first = nameLineEdit->text();
59 entries[index].second = valueLineEdit->text();
60 }
61 done(0);
62}
63
64void SubTblEditImpl::cancelButton_slot()
65{
66 done(1);
67}
68
69void SubTblEditImpl::addButton_slot()
70{
71 QString name(nameLineEdit->text());
72 if (name.isEmpty())
73 return;
74 QString value(valueLineEdit->text());
75 prevSelection = -1;
76 nameLineEdit->clear();
77 valueLineEdit->clear();
78#ifndef PWM_EMBEDDED
79 entryListBox->setSelected(entryListBox->index(
80 entryListBox->selectedItem()),
81 false);
82#else
83 entryListBox->setSelected(entryListBox->currentItem(),
84 false);
85#endif
86 pair<QString, QString> p;
87 p.first = name;
88 p.second = value;
89 entries.push_back(p);
90 entryListBox->insertItem(name);
91}
92
93void SubTblEditImpl::delButton_slot()
94{
95 int index = curIndex();
96 if (index == -1)
97 return;
98 entries.erase(entries.begin() + index);
99 entryListBox->removeItem(index);
100}
101
102void SubTblEditImpl::selectedEntry_slot()
103{
104 int index = curIndex();
105 if (index == -1)
106 return;
107 disconnect(entryListBox, SIGNAL(currentChanged(QListBoxItem *)),
108 this, SLOT(selectedEntry_slot()));
109 if ((prevSelection != -1) && (prevSelection != index)) {
110 entries[prevSelection].first = nameLineEdit->text();
111 entries[prevSelection].second = valueLineEdit->text();
112 entryListBox->changeItem(nameLineEdit->text(), prevSelection);
113 }
114 pair<QString, QString> p(entries[index]);
115 nameLineEdit->setText(p.first);
116 valueLineEdit->setText(p.second);
117 prevSelection = index;
118 entryListBox->setSelected(index, true);
119 connect(entryListBox, SIGNAL(currentChanged(QListBoxItem *)),
120 this, SLOT(selectedEntry_slot()));
121}
122
123void SubTblEditImpl::setContent(const QString &title,
124 const vector< pair<QString, QString> > *_entries)
125{
126 entries = *_entries;
127 titleLineEdit->setText(title);
128 vector< pair<QString, QString> >::iterator i = entries.begin(),
129 end = entries.end();
130 while (i != end) {
131 entryListBox->insertItem(i->first);
132 ++i;
133 }
134}
135
136#ifndef PWM_EMBEDDED
137#include "subtbleditimpl.moc"
138#endif
diff --git a/pwmanager/pwmanager/subtbleditimpl.h b/pwmanager/pwmanager/subtbleditimpl.h
new file mode 100644
index 0000000..0755fbf
--- a/dev/null
+++ b/pwmanager/pwmanager/subtbleditimpl.h
@@ -0,0 +1,84 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef SUBTBLEDITIMPL_H
21#define SUBTBLEDITIMPL_H
22
23#include "subtbledit.h"
24
25#include <qlineedit.h>
26#include <qlistbox.h>
27
28#include <vector>
29#include <utility>
30
31using std::vector;
32using std::pair;
33
34
35class SubTblEditImpl : public subTblEdit
36{
37 Q_OBJECT
38public:
39 SubTblEditImpl(QWidget* parent = 0,
40 const char* name = 0,
41 WFlags fl = 0);
42 ~SubTblEditImpl();
43
44 /** returns the title */
45 QString getTitle() const
46 { return titleLineEdit->text(); }
47 /** returns a pointer to the data */
48 const vector< pair<QString, QString> > * getEntries() const
49 { return &entries; }
50 /** sets the content of the subtable editor */
51 void setContent(const QString &title,
52 const vector< pair<QString, QString> > *_entries);
53
54public slots:
55 /** on button pressed */
56 void okButton_slot();
57 /** cancel button pressed */
58 void cancelButton_slot();
59 /** add button pressed */
60 void addButton_slot();
61 /** delete button pressed */
62 void delButton_slot();
63
64protected slots:
65 /** the user selected another entry */
66 void selectedEntry_slot();
67
68protected:
69 /** returns the index of the currently selected entry */
70 int curIndex()
71#ifndef PWM_EMBEDDED
72 { return entryListBox->index(entryListBox->selectedItem()); }
73#else
74 { return entryListBox->currentItem(); }
75#endif
76
77protected:
78 /** internal storage for all entries */
79 vector< pair<QString, QString> > entries;
80 /** stores the previous selection */
81 int prevSelection;
82};
83
84#endif
diff --git a/pwmanager/pwmanager/waitwnd.cpp b/pwmanager/pwmanager/waitwnd.cpp
new file mode 100644
index 0000000..a3f25cc
--- a/dev/null
+++ b/pwmanager/pwmanager/waitwnd.cpp
@@ -0,0 +1,94 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#include "waitwnd.h"
21#include "globalstuff.h"
22#include "pwmexception.h"
23
24#include <qmessagebox.h>
25
26#include <klocale.h>
27
28
29WaitWnd::WaitWnd(QString caption, QString _staticText,
30 bool showCancelButton, bool showGenericText,
31 QWidget *parent,
32 const char *name, bool modal, WFlags f)
33 : QDialog(parent, name, modal, f)
34{
35 canClose = false;
36 vbox1 = new QVBox(this);
37 staticText = new QLabel(vbox1);
38 if (showGenericText) {
39 genericText = new QLabel(vbox1);
40 genericText->setAlignment(Qt::AlignHCenter | Qt::WordBreak);
41 } else {
42 genericText = 0;
43 }
44 if (showCancelButton) {
45 cancelButton = new QPushButton(vbox1);
46 connect(cancelButton, SIGNAL(clicked()),
47 this, SLOT(cancel_slot()));
48 cancelButton->setText(i18n("&Cancel"));
49 } else {
50 cancelButton = 0;
51 }
52
53 vbox1->setSpacing(10);
54 vbox1->setMargin(10);
55 resize(300, 150);
56 setCaption(caption);
57 staticText->setText(_staticText);
58 staticText->setAlignment(Qt::AlignHCenter | Qt::WordBreak);
59}
60
61WaitWnd::~WaitWnd()
62{
63}
64
65void WaitWnd::resizeEvent(QResizeEvent *)
66{
67 vbox1->resize(size());
68}
69
70void WaitWnd::closeEvent(QCloseEvent *e)
71{
72 if (canClose) {
73 emit goingToClose();
74 e->accept();
75 } else {
76 e->ignore();
77 }
78}
79
80void WaitWnd::cancel_slot()
81{
82 canClose = true;
83 close();
84}
85
86void WaitWnd::updateGenericText(const QString &text)
87{
88 if (genericText)
89 genericText->setText(text);
90}
91
92#ifndef PWM_EMBEDDED
93#include "waitwnd.moc"
94#endif
diff --git a/pwmanager/pwmanager/waitwnd.h b/pwmanager/pwmanager/waitwnd.h
new file mode 100644
index 0000000..ae86c8b
--- a/dev/null
+++ b/pwmanager/pwmanager/waitwnd.h
@@ -0,0 +1,61 @@
1/***************************************************************************
2 * *
3 * copyright (C) 2003 by Michael Buesch *
4 * email: mbuesch@freenet.de *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. *
9 * *
10 ***************************************************************************/
11
12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde
16 *
17 * $Id$
18 **************************************************************************/
19
20#ifndef WAITWND_H
21#define WAITWND_H
22
23#include <qvbox.h>
24#include <qdialog.h>
25#include <qlabel.h>
26#include <qpushbutton.h>
27#include <qevent.h>
28
29/** window to ask the user to wait */
30class WaitWnd : public QDialog
31{
32 Q_OBJECT
33public:
34 WaitWnd(QString caption, QString _staticText,
35 bool showCancelButton, bool showGenericText,
36 QWidget *parent = 0, const char *name = 0,
37 bool modal = FALSE, WFlags f = 0);
38 ~WaitWnd();
39
40 void updateGenericText(const QString &text);
41
42signals:
43 void goingToClose();
44
45protected slots:
46 void cancel_slot();
47
48protected:
49 QVBox *vbox1;
50 QLabel *staticText;
51 QLabel *genericText;
52 QPushButton *cancelButton;
53 /** can we safely close the widget? */
54 bool canClose;
55
56protected:
57 void resizeEvent(QResizeEvent *);
58 void closeEvent(QCloseEvent *e);
59};
60
61#endif