summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/pwmprint.cpp
Unidiff
Diffstat (limited to 'pwmanager/pwmanager/pwmprint.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmprint.cpp188
1 files changed, 188 insertions, 0 deletions
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}