1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html lang=
"et" xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"et">
5 <meta http-equiv=
"CONTENT-TYPE" content=
"text/html; charset=utf-8" />
6 <title>eVaf Tutorial -
10 - GUI Module
</title>
7 <meta name=
"Author" content=
"Enar Väikene" />
8 <meta name=
"description" content=
"eVaf Tutorial" />
9 <meta name=
"keywords" content=
"evaf c++ application development framework tutorial password generator" />
10 <link rel=
"StyleSheet" href=
"evaf.css" type=
"text/css" media=
"all" />
11 <link rel=
"StyleSheet" href=
"highlight.css" type=
"text/css" media=
"all" />
16 <p>Next:
<a href=
"pswgen11.html">11 - Building GUI Module
</a>, Previous:
<a href=
"pswgen09.html">09 - GUI Module
</a></p>
18 <h1>eVaf Tutorial
</h1>
20 <h2>10 - GUI Module
</h2>
22 <p>Create the
<tt>gui.cpp
</tt> file in the
<tt>src/apps/PswGen/GUI
</tt> directory:
</p>
24 <pre class=
"hl"><span class=
"hl com">/**
</span>
25 <span class=
"hl com"> *
@file PswGen/GUI/gui.cpp
</span>
26 <span class=
"hl com"> */
</span>
28 <span class=
"hl ppc">#include
</span> <span class=
"hl pps">"gui.h
"</span><span class=
"hl ppc"></span>
30 <span class=
"hl ppc">#include
<QtGui
></span></pre>
32 <p>Copy version information files from the
<tt>Storage
</tt> module:
</p>
34 <pre>evaf/src/apps/PswGen/GUI $
<code>cp ../Storage/version.{h,rc} .
</code></pre>
36 <p>Modify the
<tt>version.h
</tt> file:
</p>
38 <pre class=
"hl"><span class=
"hl com">/**
</span>
39 <span class=
"hl com"> *
@file PswGen/GUI/version.h
</span>
40 <span class=
"hl com"> */
</span>
42 <span class=
"hl ppc">#ifndef __PSWGEN_GUI_VERSION_H
</span>
43 <span class=
"hl ppc"># define __PSWGEN_GUI_VERSION_H
</span>
45 <span class=
"hl ppc">#include
<version_rc.h
></span>
47 <span class=
"hl com">/**
</span>
48 <span class=
"hl com"> * Module/library version number in the form major,minor,release,build
</span>
49 <span class=
"hl com"> */
</span>
50 <span class=
"hl ppc">#define VER_FILE_VERSION
0,
1,
1,
1</span>
52 <span class=
"hl com">/**
</span>
53 <span class=
"hl com"> * Module/library version number in the string format (shall end with \
0)
</span>
54 <span class=
"hl com"> */
</span>
55 <span class=
"hl ppc">#define VER_FILE_VERSION_STR
</span> <span class=
"hl pps">"0.1.1.2\
0"</span><span class=
"hl ppc"></span>
57 <span class=
"hl com">/**
</span>
58 <span class=
"hl com"> * Module/library name (shall end with \
0)
</span>
59 <span class=
"hl com"> */
</span>
60 <span class=
"hl ppc">#define VER_MODULE_NAME_STR
</span> <span class=
"hl pps">"PswGui\
0"</span><span class=
"hl ppc"></span>
62 <span class=
"hl com">/**
</span>
63 <span class=
"hl com"> * Module type (see version_rc.h for all the types)
</span>
64 <span class=
"hl com"> */
</span>
65 <span class=
"hl ppc">#define VER_MODULE_TYPE MT_GENERIC
</span>
67 <span class=
"hl com">/**
</span>
68 <span class=
"hl com"> * Module type in the string format (see version_rc for all the types)
</span>
69 <span class=
"hl com"> */
</span>
70 <span class=
"hl ppc">#define VER_MODULE_TYPE_STR MT_GENERIC
</span>
72 <span class=
"hl com">/**
</span>
73 <span class=
"hl com"> * Original file name for windows (shall end with \
0)
</span>
74 <span class=
"hl com"> */
</span>
75 <span class=
"hl ppc">#define VER_ORIGINAL_FILE_NAME_STR
</span> <span class=
"hl pps">"PswGui.dll\
0"</span><span class=
"hl ppc"></span>
77 <span class=
"hl com">/**
</span>
78 <span class=
"hl com"> * Description of the module/library (shall end with \
0)
</span>
79 <span class=
"hl com"> */
</span>
80 <span class=
"hl ppc">#define VER_FILE_DESCRIPTION_STR
</span> <span class=
"hl pps">"User interface for the PswGen application.\
0"</span><span class=
"hl ppc"></span>
82 <span class=
"hl ppc">#endif
</span> <span class=
"hl slc">// version.h
</span><span class=
"hl ppc"></span></pre>
84 <p>Include the
<tt>version.h
</tt> header file in the
<tt>gui.cpp
</tt> file and export version information:
</p>
86 <pre class=
"hl"><span class=
"hl ppc">#include
</span> <span class=
"hl pps">"version.h
"</span><span class=
"hl ppc"></span>
87 <span class=
"hl kwd">VER_EXPORT_VERSION_INFO
</span><span class=
"hl opt">()
</span></pre>
89 <p>Use the
<tt>Q_EXPORT_PLUGIN2()
</tt> macro to make it a Qt plugin:
</p>
91 <pre class=
"hl"><span class=
"hl kwd">Q_EXPORT_PLUGIN2
</span><span class=
"hl opt">(
</span>VER_MODULE_NAME_STR
<span class=
"hl opt">,
</span> eVaf
<span class=
"hl opt">::
</span>PswGen
<span class=
"hl opt">::
</span>GUI
<span class=
"hl opt">::
</span>Module
<span class=
"hl opt">)
</span></pre>
93 <p>The main job of setting up the user interface is done in the
<tt>init()
</tt> function and our constructor and destructor are
96 <pre class=
"hl">Module
<span class=
"hl opt">::
</span><span class=
"hl kwd">Module
</span><span class=
"hl opt">()
</span>
97 <span class=
"hl opt">:
</span> Plugins
<span class=
"hl opt">::
</span><span class=
"hl kwd">iPlugin
</span><span class=
"hl opt">()
</span>
98 <span class=
"hl opt">,
</span> <span class=
"hl kwd">mReady
</span><span class=
"hl opt">(
</span><span class=
"hl kwa">false
</span><span class=
"hl opt">)
</span>
99 <span class=
"hl opt">,
</span> <span class=
"hl kwd">mGenerator
</span><span class=
"hl opt">(
</span><span class=
"hl num">0</span><span class=
"hl opt">)
</span>
100 <span class=
"hl opt">,
</span> <span class=
"hl kwd">mStorage
</span><span class=
"hl opt">(
</span><span class=
"hl num">0</span><span class=
"hl opt">)
</span>
101 <span class=
"hl opt">{
</span>
102 <span class=
"hl kwd">setObjectName
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">QString
</span><span class=
"hl opt">(
</span><span class=
"hl str">"%
1.%
2"</span><span class=
"hl opt">).
</span><span class=
"hl kwd">arg
</span><span class=
"hl opt">(
</span>VER_MODULE_NAME_STR
<span class=
"hl opt">).
</span><span class=
"hl kwd">arg
</span><span class=
"hl opt">(
</span>__FUNCTION__
<span class=
"hl opt">));
</span>
104 <span class=
"hl kwd">EVAF_INFO
</span><span class=
"hl opt">(
</span><span class=
"hl str">"%s created
"</span><span class=
"hl opt">,
</span> <span class=
"hl kwd">qPrintable
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">objectName
</span><span class=
"hl opt">()));
</span>
105 <span class=
"hl opt">}
</span>
107 Module
<span class=
"hl opt">::~
</span><span class=
"hl kwd">Module
</span><span class=
"hl opt">()
</span>
108 <span class=
"hl opt">{
</span>
109 <span class=
"hl kwd">EVAF_INFO
</span><span class=
"hl opt">(
</span><span class=
"hl str">"%s destroyed
"</span><span class=
"hl opt">,
</span> <span class=
"hl kwd">qPrintable
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">objectName
</span><span class=
"hl opt">()));
</span>
110 <span class=
"hl opt">}
</span></pre>
112 <p>The
<tt>init()
</tt> function:
</p>
115 <li>Queries and stores interfaces implemented in other modules. The
<tt>iGenerator
</tt> interface must be implemented;
116 the
<tt>iStorage
</tt> interface is optional and we can work without it.
</li>
117 <li>Gets the main window interface
<tt>iSdiWindow
</tt>.
</li>
118 <li>Adds our widgets to the main window layout.
</li>
119 <li>Connects signals on widgets to slots in this class.
</li>
120 <li>Uses actions
<tt>QAction
</tt> to add keyboard shortcuts --
<tt>Enter
</tt> key generates a password and
<tt>Esc
</tt> key
121 quits the application.
</li>
122 <li>Sets the
<tt>mReady
</tt> flag to true when all this is done.
</li>
125 <p>The main window has an empty
<tt>QVBoxLayout
</tt> layout and we could add our widgets directly to this layout, but for keyboard
126 shortcuts to work properly, we need a widget that fills the main window. We create a master widget, add it to the main window
127 layout and then fill the master widget with other widgets.
</p>
129 <pre class=
"hl"><span class=
"hl kwb">bool
</span> Module
<span class=
"hl opt">::
</span><span class=
"hl kwd">init
</span><span class=
"hl opt">(
</span>QString
<span class=
"hl kwb">const
</span> <span class=
"hl opt">&</span> args
<span class=
"hl opt">)
</span>
130 <span class=
"hl opt">{
</span>
131 <span class=
"hl kwd">Q_UNUSED
</span><span class=
"hl opt">(
</span>args
<span class=
"hl opt">);
</span>
133 <span class=
"hl slc">// Get the iGenerator interface
</span>
134 <span class=
"hl kwd">EVAF_TEST_X
</span><span class=
"hl opt">((
</span>mGenerator
<span class=
"hl opt">=
</span> evafQueryInterface
<span class=
"hl opt"><</span>PswGen
<span class=
"hl opt">::
</span>iGenerator
<span class=
"hl opt">>(
</span><span class=
"hl str">"iGenerator
"</span><span class=
"hl opt">)),
</span> <span class=
"hl str">"No iGenerator interface
"</span><span class=
"hl opt">);
</span>
136 <span class=
"hl slc">// Get the iStorage interface (can be null)
</span>
137 mStorage
<span class=
"hl opt">=
</span> evafQueryInterface
<span class=
"hl opt"><</span>PswGen
<span class=
"hl opt">::
</span>iStorage
<span class=
"hl opt">>(
</span><span class=
"hl str">"iStorage
"</span><span class=
"hl opt">);
</span>
138 <span class=
"hl kwa">if
</span> <span class=
"hl opt">(!
</span>mStorage
<span class=
"hl opt">)
</span>
139 <span class=
"hl kwd">EVAF_WARNING
</span><span class=
"hl opt">(
</span><span class=
"hl str">"No iStorage interface
"</span><span class=
"hl opt">);
</span>
141 <span class=
"hl slc">// Get the main window interface and fill it with the widgets
</span>
142 SdiWindow
<span class=
"hl opt">::
</span>iSdiWindow
<span class=
"hl opt">*
</span> win
<span class=
"hl opt">=
</span> evafQueryInterface
<span class=
"hl opt"><</span>SdiWindow
<span class=
"hl opt">::
</span>iSdiWindow
<span class=
"hl opt">>(
</span><span class=
"hl str">"iSdiWindow
"</span><span class=
"hl opt">);
</span>
143 <span class=
"hl kwd">EVAF_TEST_X
</span><span class=
"hl opt">(
</span>win
<span class=
"hl opt">,
</span> <span class=
"hl str">"No iSdiWindow interface
"</span><span class=
"hl opt">);
</span>
145 QWidget
<span class=
"hl opt">*
</span> masterWidget
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> QWidget
<span class=
"hl opt">;
</span>
146 win
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>masterWidget
<span class=
"hl opt">);
</span>
148 QVBoxLayout
<span class=
"hl opt">*
</span> v
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> QVBoxLayout
<span class=
"hl opt">;
</span>
149 masterWidget
<span class=
"hl opt">-
></span><span class=
"hl kwd">setLayout
</span><span class=
"hl opt">(
</span>v
<span class=
"hl opt">);
</span>
151 QGridLayout
<span class=
"hl opt">*
</span> g
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> QGridLayout
<span class=
"hl opt">;
</span>
152 v
<span class=
"hl opt">-
></span><span class=
"hl kwd">addLayout
</span><span class=
"hl opt">(
</span>g
<span class=
"hl opt">);
</span>
153 g
<span class=
"hl opt">-
></span><span class=
"hl kwd">setColumnStretch
</span><span class=
"hl opt">(
</span><span class=
"hl num">2</span><span class=
"hl opt">,
</span> <span class=
"hl num">2</span><span class=
"hl opt">);
</span>
155 QLabel
<span class=
"hl opt">*
</span> l
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> <span class=
"hl kwd">QLabel
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">tr
</span><span class=
"hl opt">(
</span><span class=
"hl str">"Master
&password:
"</span><span class=
"hl opt">,
</span> VER_MODULE_NAME_STR
<span class=
"hl opt">));
</span>
156 l
<span class=
"hl opt">-
></span><span class=
"hl kwd">setAlignment
</span><span class=
"hl opt">(
</span>Qt
<span class=
"hl opt">::
</span>AlignRight
<span class=
"hl opt">);
</span>
157 g
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>l
<span class=
"hl opt">,
</span> <span class=
"hl num">0</span><span class=
"hl opt">,
</span> <span class=
"hl num">0</span><span class=
"hl opt">);
</span>
159 wMasterPassword
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> QLineEdit
<span class=
"hl opt">;
</span>
160 l
<span class=
"hl opt">-
></span><span class=
"hl kwd">setBuddy
</span><span class=
"hl opt">(
</span>wMasterPassword
<span class=
"hl opt">);
</span>
161 <span class=
"hl kwd">connect
</span><span class=
"hl opt">(
</span>wMasterPassword
<span class=
"hl opt">,
</span> <span class=
"hl kwd">SIGNAL
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">textChanged
</span><span class=
"hl opt">(
</span>QString
<span class=
"hl opt">)),
</span> <span class=
"hl kwa">this
</span><span class=
"hl opt">,
</span> <span class=
"hl kwd">SLOT
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">textChanged
</span><span class=
"hl opt">(
</span>QString
<span class=
"hl opt">)));
</span>
162 wMasterPassword
<span class=
"hl opt">-
></span><span class=
"hl kwd">setEchoMode
</span><span class=
"hl opt">(
</span>QLineEdit
<span class=
"hl opt">::
</span>Password
<span class=
"hl opt">);
</span>
163 g
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>wMasterPassword
<span class=
"hl opt">,
</span> <span class=
"hl num">0</span><span class=
"hl opt">,
</span> <span class=
"hl num">1</span><span class=
"hl opt">,
</span> <span class=
"hl num">1</span><span class=
"hl opt">,
</span> <span class=
"hl num">2</span><span class=
"hl opt">);
</span>
165 l
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> <span class=
"hl kwd">QLabel
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">tr
</span><span class=
"hl opt">(
</span><span class=
"hl str">"Web site or application
&name:
"</span><span class=
"hl opt">,
</span> VER_MODULE_NAME_STR
<span class=
"hl opt">));
</span>
166 l
<span class=
"hl opt">-
></span><span class=
"hl kwd">setAlignment
</span><span class=
"hl opt">(
</span>Qt
<span class=
"hl opt">::
</span>AlignRight
<span class=
"hl opt">);
</span>
167 g
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>l
<span class=
"hl opt">,
</span> <span class=
"hl num">1</span><span class=
"hl opt">,
</span> <span class=
"hl num">0</span><span class=
"hl opt">);
</span>
169 wName
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> QLineEdit
<span class=
"hl opt">;
</span>
170 l
<span class=
"hl opt">-
></span><span class=
"hl kwd">setBuddy
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">);
</span>
171 <span class=
"hl kwa">if
</span> <span class=
"hl opt">(
</span>mStorage
<span class=
"hl opt">) {
</span>
172 QCompleter
<span class=
"hl opt">*
</span> completer
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> <span class=
"hl kwd">QCompleter
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">);
</span>
173 completer
<span class=
"hl opt">-
></span><span class=
"hl kwd">setModel
</span><span class=
"hl opt">(
</span>mStorage
<span class=
"hl opt">-
></span><span class=
"hl kwd">autoCompletionModel
</span><span class=
"hl opt">());
</span>
174 completer
<span class=
"hl opt">-
></span><span class=
"hl kwd">setCompletionMode
</span><span class=
"hl opt">(
</span>QCompleter
<span class=
"hl opt">::
</span>InlineCompletion
<span class=
"hl opt">);
</span>
175 wName
<span class=
"hl opt">-
></span><span class=
"hl kwd">setCompleter
</span><span class=
"hl opt">(
</span>completer
<span class=
"hl opt">);
</span>
176 <span class=
"hl opt">}
</span>
177 <span class=
"hl kwd">connect
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">,
</span> <span class=
"hl kwd">SIGNAL
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">textChanged
</span><span class=
"hl opt">(
</span>QString
<span class=
"hl opt">)),
</span> <span class=
"hl kwa">this
</span><span class=
"hl opt">,
</span> <span class=
"hl kwd">SLOT
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">textChanged
</span><span class=
"hl opt">(
</span>QString
<span class=
"hl opt">)));
</span>
178 g
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">,
</span> <span class=
"hl num">1</span><span class=
"hl opt">,
</span> <span class=
"hl num">1</span><span class=
"hl opt">,
</span> <span class=
"hl num">1</span><span class=
"hl opt">,
</span> <span class=
"hl num">2</span><span class=
"hl opt">);
</span>
179 masterWidget
<span class=
"hl opt">-
></span><span class=
"hl kwd">setFocusProxy
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">);
</span>
181 l
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> <span class=
"hl kwd">QLabel
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">tr
</span><span class=
"hl opt">(
</span><span class=
"hl str">"&Length of the password:
"</span><span class=
"hl opt">,
</span> VER_MODULE_NAME_STR
<span class=
"hl opt">));
</span>
182 l
<span class=
"hl opt">-
></span><span class=
"hl kwd">setAlignment
</span><span class=
"hl opt">(
</span>Qt
<span class=
"hl opt">::
</span>AlignRight
<span class=
"hl opt">);
</span>
183 g
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>l
<span class=
"hl opt">,
</span> <span class=
"hl num">2</span><span class=
"hl opt">,
</span> <span class=
"hl num">0</span><span class=
"hl opt">);
</span>
185 wLength
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> QSpinBox
<span class=
"hl opt">;
</span>
186 l
<span class=
"hl opt">-
></span><span class=
"hl kwd">setBuddy
</span><span class=
"hl opt">(
</span>wLength
<span class=
"hl opt">);
</span>
187 wLength
<span class=
"hl opt">-
></span><span class=
"hl kwd">setRange
</span><span class=
"hl opt">(
</span><span class=
"hl num">0</span><span class=
"hl opt">,
</span> mGenerator
<span class=
"hl opt">-
></span><span class=
"hl kwd">maxLength
</span><span class=
"hl opt">());
</span>
188 wLength
<span class=
"hl opt">-
></span><span class=
"hl kwd">setValue
</span><span class=
"hl opt">(
</span>DefaultPasswordLength
<span class=
"hl opt">);
</span>
189 wLength
<span class=
"hl opt">-
></span><span class=
"hl kwd">setSpecialValueText
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">tr
</span><span class=
"hl opt">(
</span><span class=
"hl str">"Maximum
"</span><span class=
"hl opt">,
</span> VER_MODULE_NAME_STR
<span class=
"hl opt">));
</span>
190 g
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>wLength
<span class=
"hl opt">,
</span> <span class=
"hl num">2</span><span class=
"hl opt">,
</span> <span class=
"hl num">1</span><span class=
"hl opt">);
</span>
192 l
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> <span class=
"hl kwd">QLabel
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">tr
</span><span class=
"hl opt">(
</span><span class=
"hl str">"Password:
"</span><span class=
"hl opt">));
</span>
193 l
<span class=
"hl opt">-
></span><span class=
"hl kwd">setAlignment
</span><span class=
"hl opt">(
</span>Qt
<span class=
"hl opt">::
</span>AlignRight
<span class=
"hl opt">);
</span>
194 g
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>l
<span class=
"hl opt">,
</span> <span class=
"hl num">3</span><span class=
"hl opt">,
</span> <span class=
"hl num">0</span><span class=
"hl opt">);
</span>
196 wPassword
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> QLineEdit
<span class=
"hl opt">;
</span>
197 wPassword
<span class=
"hl opt">-
></span><span class=
"hl kwd">setReadOnly
</span><span class=
"hl opt">(
</span><span class=
"hl kwa">true
</span><span class=
"hl opt">);
</span>
198 g
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>wPassword
<span class=
"hl opt">,
</span> <span class=
"hl num">3</span><span class=
"hl opt">,
</span> <span class=
"hl num">1</span><span class=
"hl opt">,
</span> <span class=
"hl num">1</span><span class=
"hl opt">,
</span> <span class=
"hl num">2</span><span class=
"hl opt">);
</span>
200 v
<span class=
"hl opt">-
></span><span class=
"hl kwd">addStretch
</span><span class=
"hl opt">();
</span>
202 QHBoxLayout
<span class=
"hl opt">*
</span> h
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> QHBoxLayout
<span class=
"hl opt">;
</span>
203 h
<span class=
"hl opt">-
></span><span class=
"hl kwd">addStretch
</span><span class=
"hl opt">();
</span>
204 v
<span class=
"hl opt">-
></span><span class=
"hl kwd">addLayout
</span><span class=
"hl opt">(
</span>h
<span class=
"hl opt">);
</span>
206 wGenerate
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> <span class=
"hl kwd">QPushButton
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">tr
</span><span class=
"hl opt">(
</span><span class=
"hl str">"&Generate
"</span><span class=
"hl opt">,
</span> VER_MODULE_NAME_STR
<span class=
"hl opt">));
</span>
207 wGenerate
<span class=
"hl opt">-
></span><span class=
"hl kwd">setDisabled
</span><span class=
"hl opt">(
</span><span class=
"hl kwa">true
</span><span class=
"hl opt">);
</span>
208 wGenerate
<span class=
"hl opt">-
></span><span class=
"hl kwd">setDefault
</span><span class=
"hl opt">(
</span><span class=
"hl kwa">true
</span><span class=
"hl opt">);
</span>
209 <span class=
"hl kwd">connect
</span><span class=
"hl opt">(
</span>wGenerate
<span class=
"hl opt">,
</span> <span class=
"hl kwd">SIGNAL
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">clicked
</span><span class=
"hl opt">()),
</span> <span class=
"hl kwa">this
</span><span class=
"hl opt">,
</span> <span class=
"hl kwd">SLOT
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">generateClicked
</span><span class=
"hl opt">()));
</span>
210 h
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>wGenerate
<span class=
"hl opt">);
</span>
212 wCopy
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> <span class=
"hl kwd">QPushButton
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">tr
</span><span class=
"hl opt">(
</span><span class=
"hl str">"&Copy to Clipboard
"</span><span class=
"hl opt">,
</span> VER_MODULE_NAME_STR
<span class=
"hl opt">));
</span>
213 wCopy
<span class=
"hl opt">-
></span><span class=
"hl kwd">setDisabled
</span><span class=
"hl opt">(
</span><span class=
"hl kwa">true
</span><span class=
"hl opt">);
</span>
214 <span class=
"hl kwd">connect
</span><span class=
"hl opt">(
</span>wCopy
<span class=
"hl opt">,
</span> <span class=
"hl kwd">SIGNAL
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">clicked
</span><span class=
"hl opt">()),
</span> <span class=
"hl kwa">this
</span><span class=
"hl opt">,
</span> <span class=
"hl kwd">SLOT
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">copyClicked
</span><span class=
"hl opt">()));
</span>
215 h
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>wCopy
<span class=
"hl opt">);
</span>
217 QAction
<span class=
"hl opt">*
</span> a
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> <span class=
"hl kwd">QAction
</span><span class=
"hl opt">(
</span>masterWidget
<span class=
"hl opt">);
</span>
218 a
<span class=
"hl opt">-
></span><span class=
"hl kwd">setShortcut
</span><span class=
"hl opt">(
</span>Qt
<span class=
"hl opt">::
</span>Key_Return
<span class=
"hl opt">);
</span>
219 <span class=
"hl kwd">connect
</span><span class=
"hl opt">(
</span>a
<span class=
"hl opt">,
</span> <span class=
"hl kwd">SIGNAL
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">triggered
</span><span class=
"hl opt">()),
</span> <span class=
"hl kwa">this
</span><span class=
"hl opt">,
</span> <span class=
"hl kwd">SLOT
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">generateClicked
</span><span class=
"hl opt">()));
</span>
220 masterWidget
<span class=
"hl opt">-
></span><span class=
"hl kwd">addAction
</span><span class=
"hl opt">(
</span>a
<span class=
"hl opt">);
</span>
222 a
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> <span class=
"hl kwd">QAction
</span><span class=
"hl opt">(
</span>masterWidget
<span class=
"hl opt">);
</span>
223 a
<span class=
"hl opt">-
></span><span class=
"hl kwd">setShortcut
</span><span class=
"hl opt">(
</span>Qt
<span class=
"hl opt">::
</span>Key_Escape
<span class=
"hl opt">);
</span>
224 <span class=
"hl kwd">connect
</span><span class=
"hl opt">(
</span>a
<span class=
"hl opt">,
</span> <span class=
"hl kwd">SIGNAL
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">triggered
</span><span class=
"hl opt">()),
</span> qApp
<span class=
"hl opt">,
</span> <span class=
"hl kwd">SLOT
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">quit
</span><span class=
"hl opt">()));
</span>
225 masterWidget
<span class=
"hl opt">-
></span><span class=
"hl kwd">addAction
</span><span class=
"hl opt">(
</span>a
<span class=
"hl opt">);
</span>
227 mReady
<span class=
"hl opt">=
</span> <span class=
"hl kwa">true
</span><span class=
"hl opt">;
</span>
229 <span class=
"hl kwd">EVAF_INFO
</span><span class=
"hl opt">(
</span><span class=
"hl str">"%s initialized
"</span><span class=
"hl opt">,
</span> <span class=
"hl kwd">qPrintable
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">objectName
</span><span class=
"hl opt">()));
</span>
231 <span class=
"hl kwa">return true
</span><span class=
"hl opt">;
</span>
232 <span class=
"hl opt">}
</span></pre>
234 <p>The
<tt>done()
</tt> function simply sets the
<tt>mReady
</tt> flag back to
<tt>false
</tt>:
</p>
236 <pre class=
"hl"><span class=
"hl kwb">void
</span> Module
<span class=
"hl opt">::
</span><span class=
"hl kwd">done
</span><span class=
"hl opt">()
</span>
237 <span class=
"hl opt">{
</span>
238 mReady
<span class=
"hl opt">=
</span> <span class=
"hl kwa">false
</span><span class=
"hl opt">;
</span>
240 <span class=
"hl kwd">EVAF_INFO
</span><span class=
"hl opt">(
</span><span class=
"hl str">"%s finalized
"</span><span class=
"hl opt">,
</span> <span class=
"hl kwd">qPrintable
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">objectName
</span><span class=
"hl opt">()));
</span>
241 <span class=
"hl opt">}
</span></pre>
243 <p>The
<tt>Generate
</tt> push button is disabled by default. We connected
<tt>textChanged()
</tt> signals to the
<tt>textChanged()
</tt> slot, where we enable the
<tt>Generate
</tt> push button if master password and name fields are not empty.
</p>
245 <p>We can also query for stored passwords and update fields on the window with data from the storage. The
<tt>iStorage::query()
</tt>
246 method can return an empty shared data pointer and we have to check for it before using fields in the shared data object.
</p>
248 <pre class=
"hl"><span class=
"hl kwb">void
</span> Module
<span class=
"hl opt">::
</span><span class=
"hl kwd">textChanged
</span><span class=
"hl opt">(
</span>QString
<span class=
"hl kwb">const
</span> <span class=
"hl opt">&)
</span>
249 <span class=
"hl opt">{
</span>
250 wGenerate
<span class=
"hl opt">-
></span><span class=
"hl kwd">setDisabled
</span><span class=
"hl opt">(
</span>wMasterPassword
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">().
</span><span class=
"hl kwd">isEmpty
</span><span class=
"hl opt">() ||
</span> wName
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">().
</span><span class=
"hl kwd">isEmpty
</span><span class=
"hl opt">());
</span>
251 <span class=
"hl kwa">if
</span> <span class=
"hl opt">(!
</span>wName
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">().
</span><span class=
"hl kwd">isEmpty
</span><span class=
"hl opt">()
&&</span> mStorage
<span class=
"hl opt">) {
</span>
252 QExplicitlySharedDataPointer
<span class=
"hl opt"><</span>PswGen
<span class=
"hl opt">::
</span>Storage
<span class=
"hl opt">::
</span>Data
<span class=
"hl opt">></span> data
<span class=
"hl opt">=
</span> mStorage
<span class=
"hl opt">-
></span><span class=
"hl kwd">query
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">());
</span>
253 <span class=
"hl kwa">if
</span> <span class=
"hl opt">(
</span>data
<span class=
"hl opt">)
</span>
254 wLength
<span class=
"hl opt">-
></span><span class=
"hl kwd">setValue
</span><span class=
"hl opt">(
</span>data
<span class=
"hl opt">-
></span><span class=
"hl kwd">length
</span><span class=
"hl opt">());
</span>
255 <span class=
"hl opt">}
</span>
256 <span class=
"hl opt">}
</span></pre>
258 <p>The
<tt>generateClicked()
</tt> slot is connected to the
<tt>Generate
</tt> push button and also to the
<tt>Enter
</tt> key
259 action. The push button is disabled if master password or name fields are empty, but not the
<tt>Enter
</tt> key action and
260 we need to check for it once more.
</p>
262 <p>Then we generate the password using the
<tt>iGenerator::generatePassword()
</tt> method and show it on the window. We also
263 enable the
<tt>Copy to Clipboard
</tt> push button.
</p>
265 <p>If we have the
<tt>iStorage
</tt>, we either store the new data record or update an existing one in the storage.
</p>
267 <pre class=
"hl"><span class=
"hl kwb">void
</span> Module
<span class=
"hl opt">::
</span><span class=
"hl kwd">generateClicked
</span><span class=
"hl opt">()
</span>
268 <span class=
"hl opt">{
</span>
269 <span class=
"hl kwa">if
</span> <span class=
"hl opt">(
</span>wMasterPassword
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">().
</span><span class=
"hl kwd">isEmpty
</span><span class=
"hl opt">() ||
</span> wName
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">().
</span><span class=
"hl kwd">isEmpty
</span><span class=
"hl opt">())
</span>
270 <span class=
"hl kwa">return
</span><span class=
"hl opt">;
</span>
271 wPassword
<span class=
"hl opt">-
></span><span class=
"hl kwd">setText
</span><span class=
"hl opt">(
</span>mGenerator
<span class=
"hl opt">-
></span><span class=
"hl kwd">generatePassword
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">(),
</span> wMasterPassword
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">(),
</span> wLength
<span class=
"hl opt">-
></span><span class=
"hl kwd">value
</span><span class=
"hl opt">()));
</span>
272 wCopy
<span class=
"hl opt">-
></span><span class=
"hl kwd">setEnabled
</span><span class=
"hl opt">(
</span><span class=
"hl kwa">true
</span><span class=
"hl opt">);
</span>
273 <span class=
"hl kwa">if
</span> <span class=
"hl opt">(
</span>mStorage
<span class=
"hl opt">) {
</span>
274 QExplicitlySharedDataPointer
<span class=
"hl opt"><</span>PswGen
<span class=
"hl opt">::
</span>Storage
<span class=
"hl opt">::
</span>Data
<span class=
"hl opt">></span> data
<span class=
"hl opt">=
</span> mStorage
<span class=
"hl opt">-
></span><span class=
"hl kwd">query
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">());
</span>
275 <span class=
"hl kwa">if
</span> <span class=
"hl opt">(!
</span>data
<span class=
"hl opt">)
</span>
276 data
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> Storage
<span class=
"hl opt">::
</span><span class=
"hl kwd">Data
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">(),
</span> wLength
<span class=
"hl opt">-
></span><span class=
"hl kwd">value
</span><span class=
"hl opt">());
</span>
277 <span class=
"hl kwa">else
</span>
278 data
<span class=
"hl opt">-
></span><span class=
"hl kwd">setLength
</span><span class=
"hl opt">(
</span>wLength
<span class=
"hl opt">-
></span><span class=
"hl kwd">value
</span><span class=
"hl opt">());
</span>
279 mStorage
<span class=
"hl opt">-
></span><span class=
"hl kwd">save
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">(),
</span> data
<span class=
"hl opt">);
</span>
280 <span class=
"hl opt">}
</span>
281 <span class=
"hl opt">}
</span></pre>
283 <p>The final method in our module is the
<tt>copyClicked()
</tt> slot, which simply copies anything from the generated password
284 field to the clipboard:
</p>
286 <pre class=
"hl"><span class=
"hl kwb">void
</span> Module
<span class=
"hl opt">::
</span><span class=
"hl kwd">copyClicked
</span><span class=
"hl opt">()
</span>
287 <span class=
"hl opt">{
</span>
288 QClipboard
<span class=
"hl opt">*
</span> clipboard
<span class=
"hl opt">=
</span> QApplication
<span class=
"hl opt">::
</span><span class=
"hl kwd">clipboard
</span><span class=
"hl opt">();
</span>
289 <span class=
"hl kwa">if
</span> <span class=
"hl opt">(
</span>clipboard
<span class=
"hl opt">)
</span>
290 clipboard
<span class=
"hl opt">-
></span><span class=
"hl kwd">setText
</span><span class=
"hl opt">(
</span>wPassword
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">());
</span>
291 <span class=
"hl opt">}
</span></pre>
293 <p>Here is the final
<tt>gui.cpp
</tt> file:
</p>
295 <pre class=
"hl"><span class=
"hl com">/**
</span>
296 <span class=
"hl com"> *
@file PswGen/GUI/gui.cpp
</span>
297 <span class=
"hl com"> */
</span>
299 <span class=
"hl ppc">#include
</span> <span class=
"hl pps">"gui.h
"</span><span class=
"hl ppc"></span>
300 <span class=
"hl ppc">#include
</span> <span class=
"hl pps">"version.h
"</span><span class=
"hl ppc"></span>
302 <span class=
"hl ppc">#include
</span> <span class=
"hl pps">"Generator/iGenerator
"</span><span class=
"hl ppc"></span>
303 <span class=
"hl ppc">#include
</span> <span class=
"hl pps">"Storage/iStorage
"</span><span class=
"hl ppc"></span>
305 <span class=
"hl ppc">#include
<Common/Globals
></span>
306 <span class=
"hl ppc">#include
<Common/iLogger
></span>
307 <span class=
"hl ppc">#include
<Common/iRegistry
></span>
308 <span class=
"hl ppc">#include
<SdiWindow/iSdiWindow
></span>
310 <span class=
"hl ppc">#include
<QtGui
></span>
312 <span class=
"hl kwd">VER_EXPORT_VERSION_INFO
</span><span class=
"hl opt">()
</span>
313 <span class=
"hl kwd">Q_EXPORT_PLUGIN2
</span><span class=
"hl opt">(
</span>VER_MODULE_NAME_STR
<span class=
"hl opt">,
</span> eVaf
<span class=
"hl opt">::
</span>PswGen
<span class=
"hl opt">::
</span>GUI
<span class=
"hl opt">::
</span>Module
<span class=
"hl opt">)
</span>
315 <span class=
"hl kwa">using namespace
</span> eVaf
<span class=
"hl opt">;
</span>
316 <span class=
"hl kwa">using namespace
</span> eVaf
<span class=
"hl opt">::
</span>PswGen
<span class=
"hl opt">::
</span>GUI
<span class=
"hl opt">;
</span>
318 <span class=
"hl kwb">int const
</span> Module
<span class=
"hl opt">::
</span>DefaultPasswordLength
<span class=
"hl opt">=
</span> <span class=
"hl num">16</span><span class=
"hl opt">;
</span>
320 Module
<span class=
"hl opt">::
</span><span class=
"hl kwd">Module
</span><span class=
"hl opt">()
</span>
321 <span class=
"hl opt">:
</span> Plugins
<span class=
"hl opt">::
</span><span class=
"hl kwd">iPlugin
</span><span class=
"hl opt">()
</span>
322 <span class=
"hl opt">,
</span> <span class=
"hl kwd">mReady
</span><span class=
"hl opt">(
</span><span class=
"hl kwa">false
</span><span class=
"hl opt">)
</span>
323 <span class=
"hl opt">,
</span> <span class=
"hl kwd">mGenerator
</span><span class=
"hl opt">(
</span><span class=
"hl num">0</span><span class=
"hl opt">)
</span>
324 <span class=
"hl opt">,
</span> <span class=
"hl kwd">mStorage
</span><span class=
"hl opt">(
</span><span class=
"hl num">0</span><span class=
"hl opt">)
</span>
325 <span class=
"hl opt">{
</span>
326 <span class=
"hl kwd">setObjectName
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">QString
</span><span class=
"hl opt">(
</span><span class=
"hl str">"%
1.%
2"</span><span class=
"hl opt">).
</span><span class=
"hl kwd">arg
</span><span class=
"hl opt">(
</span>VER_MODULE_NAME_STR
<span class=
"hl opt">).
</span><span class=
"hl kwd">arg
</span><span class=
"hl opt">(
</span>__FUNCTION__
<span class=
"hl opt">));
</span>
328 <span class=
"hl kwd">EVAF_INFO
</span><span class=
"hl opt">(
</span><span class=
"hl str">"%s created
"</span><span class=
"hl opt">,
</span> <span class=
"hl kwd">qPrintable
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">objectName
</span><span class=
"hl opt">()));
</span>
329 <span class=
"hl opt">}
</span>
331 Module
<span class=
"hl opt">::~
</span><span class=
"hl kwd">Module
</span><span class=
"hl opt">()
</span>
332 <span class=
"hl opt">{
</span>
333 <span class=
"hl kwd">EVAF_INFO
</span><span class=
"hl opt">(
</span><span class=
"hl str">"%s destroyed
"</span><span class=
"hl opt">,
</span> <span class=
"hl kwd">qPrintable
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">objectName
</span><span class=
"hl opt">()));
</span>
334 <span class=
"hl opt">}
</span>
336 <span class=
"hl kwb">bool
</span> Module
<span class=
"hl opt">::
</span><span class=
"hl kwd">init
</span><span class=
"hl opt">(
</span>QString
<span class=
"hl kwb">const
</span> <span class=
"hl opt">&</span> args
<span class=
"hl opt">)
</span>
337 <span class=
"hl opt">{
</span>
338 <span class=
"hl kwd">Q_UNUSED
</span><span class=
"hl opt">(
</span>args
<span class=
"hl opt">);
</span>
340 <span class=
"hl slc">// Get the iGenerator interface
</span>
341 <span class=
"hl kwd">EVAF_TEST_X
</span><span class=
"hl opt">((
</span>mGenerator
<span class=
"hl opt">=
</span> evafQueryInterface
<span class=
"hl opt"><</span>PswGen
<span class=
"hl opt">::
</span>iGenerator
<span class=
"hl opt">>(
</span><span class=
"hl str">"iGenerator
"</span><span class=
"hl opt">)),
</span> <span class=
"hl str">"No iGenerator interface
"</span><span class=
"hl opt">);
</span>
343 <span class=
"hl slc">// Get the iStorage interface (can be null)
</span>
344 mStorage
<span class=
"hl opt">=
</span> evafQueryInterface
<span class=
"hl opt"><</span>PswGen
<span class=
"hl opt">::
</span>iStorage
<span class=
"hl opt">>(
</span><span class=
"hl str">"iStorage
"</span><span class=
"hl opt">);
</span>
345 <span class=
"hl kwa">if
</span> <span class=
"hl opt">(!
</span>mStorage
<span class=
"hl opt">)
</span>
346 <span class=
"hl kwd">EVAF_WARNING
</span><span class=
"hl opt">(
</span><span class=
"hl str">"No iStorage interface
"</span><span class=
"hl opt">);
</span>
348 <span class=
"hl slc">// Get the main window interface and fill it with the widgets
</span>
349 SdiWindow
<span class=
"hl opt">::
</span>iSdiWindow
<span class=
"hl opt">*
</span> win
<span class=
"hl opt">=
</span> evafQueryInterface
<span class=
"hl opt"><</span>SdiWindow
<span class=
"hl opt">::
</span>iSdiWindow
<span class=
"hl opt">>(
</span><span class=
"hl str">"iSdiWindow
"</span><span class=
"hl opt">);
</span>
350 <span class=
"hl kwd">EVAF_TEST_X
</span><span class=
"hl opt">(
</span>win
<span class=
"hl opt">,
</span> <span class=
"hl str">"No iSdiWindow interface
"</span><span class=
"hl opt">);
</span>
352 QWidget
<span class=
"hl opt">*
</span> masterWidget
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> QWidget
<span class=
"hl opt">;
</span>
353 win
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>masterWidget
<span class=
"hl opt">);
</span>
355 QVBoxLayout
<span class=
"hl opt">*
</span> v
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> QVBoxLayout
<span class=
"hl opt">;
</span>
356 masterWidget
<span class=
"hl opt">-
></span><span class=
"hl kwd">setLayout
</span><span class=
"hl opt">(
</span>v
<span class=
"hl opt">);
</span>
358 QGridLayout
<span class=
"hl opt">*
</span> g
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> QGridLayout
<span class=
"hl opt">;
</span>
359 v
<span class=
"hl opt">-
></span><span class=
"hl kwd">addLayout
</span><span class=
"hl opt">(
</span>g
<span class=
"hl opt">);
</span>
360 g
<span class=
"hl opt">-
></span><span class=
"hl kwd">setColumnStretch
</span><span class=
"hl opt">(
</span><span class=
"hl num">2</span><span class=
"hl opt">,
</span> <span class=
"hl num">2</span><span class=
"hl opt">);
</span>
362 QLabel
<span class=
"hl opt">*
</span> l
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> <span class=
"hl kwd">QLabel
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">tr
</span><span class=
"hl opt">(
</span><span class=
"hl str">"Master
&password:
"</span><span class=
"hl opt">,
</span> VER_MODULE_NAME_STR
<span class=
"hl opt">));
</span>
363 l
<span class=
"hl opt">-
></span><span class=
"hl kwd">setAlignment
</span><span class=
"hl opt">(
</span>Qt
<span class=
"hl opt">::
</span>AlignRight
<span class=
"hl opt">);
</span>
364 g
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>l
<span class=
"hl opt">,
</span> <span class=
"hl num">0</span><span class=
"hl opt">,
</span> <span class=
"hl num">0</span><span class=
"hl opt">);
</span>
366 wMasterPassword
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> QLineEdit
<span class=
"hl opt">;
</span>
367 l
<span class=
"hl opt">-
></span><span class=
"hl kwd">setBuddy
</span><span class=
"hl opt">(
</span>wMasterPassword
<span class=
"hl opt">);
</span>
368 <span class=
"hl kwd">connect
</span><span class=
"hl opt">(
</span>wMasterPassword
<span class=
"hl opt">,
</span> <span class=
"hl kwd">SIGNAL
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">textChanged
</span><span class=
"hl opt">(
</span>QString
<span class=
"hl opt">)),
</span> <span class=
"hl kwa">this
</span><span class=
"hl opt">,
</span> <span class=
"hl kwd">SLOT
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">textChanged
</span><span class=
"hl opt">(
</span>QString
<span class=
"hl opt">)));
</span>
369 wMasterPassword
<span class=
"hl opt">-
></span><span class=
"hl kwd">setEchoMode
</span><span class=
"hl opt">(
</span>QLineEdit
<span class=
"hl opt">::
</span>Password
<span class=
"hl opt">);
</span>
370 g
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>wMasterPassword
<span class=
"hl opt">,
</span> <span class=
"hl num">0</span><span class=
"hl opt">,
</span> <span class=
"hl num">1</span><span class=
"hl opt">,
</span> <span class=
"hl num">1</span><span class=
"hl opt">,
</span> <span class=
"hl num">2</span><span class=
"hl opt">);
</span>
372 l
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> <span class=
"hl kwd">QLabel
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">tr
</span><span class=
"hl opt">(
</span><span class=
"hl str">"Web site or application
&name:
"</span><span class=
"hl opt">,
</span> VER_MODULE_NAME_STR
<span class=
"hl opt">));
</span>
373 l
<span class=
"hl opt">-
></span><span class=
"hl kwd">setAlignment
</span><span class=
"hl opt">(
</span>Qt
<span class=
"hl opt">::
</span>AlignRight
<span class=
"hl opt">);
</span>
374 g
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>l
<span class=
"hl opt">,
</span> <span class=
"hl num">1</span><span class=
"hl opt">,
</span> <span class=
"hl num">0</span><span class=
"hl opt">);
</span>
376 wName
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> QLineEdit
<span class=
"hl opt">;
</span>
377 l
<span class=
"hl opt">-
></span><span class=
"hl kwd">setBuddy
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">);
</span>
378 <span class=
"hl kwa">if
</span> <span class=
"hl opt">(
</span>mStorage
<span class=
"hl opt">) {
</span>
379 QCompleter
<span class=
"hl opt">*
</span> completer
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> <span class=
"hl kwd">QCompleter
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">);
</span>
380 completer
<span class=
"hl opt">-
></span><span class=
"hl kwd">setModel
</span><span class=
"hl opt">(
</span>mStorage
<span class=
"hl opt">-
></span><span class=
"hl kwd">autoCompletionModel
</span><span class=
"hl opt">());
</span>
381 completer
<span class=
"hl opt">-
></span><span class=
"hl kwd">setCompletionMode
</span><span class=
"hl opt">(
</span>QCompleter
<span class=
"hl opt">::
</span>InlineCompletion
<span class=
"hl opt">);
</span>
382 wName
<span class=
"hl opt">-
></span><span class=
"hl kwd">setCompleter
</span><span class=
"hl opt">(
</span>completer
<span class=
"hl opt">);
</span>
383 <span class=
"hl opt">}
</span>
384 <span class=
"hl kwd">connect
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">,
</span> <span class=
"hl kwd">SIGNAL
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">textChanged
</span><span class=
"hl opt">(
</span>QString
<span class=
"hl opt">)),
</span> <span class=
"hl kwa">this
</span><span class=
"hl opt">,
</span> <span class=
"hl kwd">SLOT
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">textChanged
</span><span class=
"hl opt">(
</span>QString
<span class=
"hl opt">)));
</span>
385 g
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">,
</span> <span class=
"hl num">1</span><span class=
"hl opt">,
</span> <span class=
"hl num">1</span><span class=
"hl opt">,
</span> <span class=
"hl num">1</span><span class=
"hl opt">,
</span> <span class=
"hl num">2</span><span class=
"hl opt">);
</span>
386 masterWidget
<span class=
"hl opt">-
></span><span class=
"hl kwd">setFocusProxy
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">);
</span>
388 l
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> <span class=
"hl kwd">QLabel
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">tr
</span><span class=
"hl opt">(
</span><span class=
"hl str">"&Length of the password:
"</span><span class=
"hl opt">,
</span> VER_MODULE_NAME_STR
<span class=
"hl opt">));
</span>
389 l
<span class=
"hl opt">-
></span><span class=
"hl kwd">setAlignment
</span><span class=
"hl opt">(
</span>Qt
<span class=
"hl opt">::
</span>AlignRight
<span class=
"hl opt">);
</span>
390 g
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>l
<span class=
"hl opt">,
</span> <span class=
"hl num">2</span><span class=
"hl opt">,
</span> <span class=
"hl num">0</span><span class=
"hl opt">);
</span>
392 wLength
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> QSpinBox
<span class=
"hl opt">;
</span>
393 l
<span class=
"hl opt">-
></span><span class=
"hl kwd">setBuddy
</span><span class=
"hl opt">(
</span>wLength
<span class=
"hl opt">);
</span>
394 wLength
<span class=
"hl opt">-
></span><span class=
"hl kwd">setRange
</span><span class=
"hl opt">(
</span><span class=
"hl num">0</span><span class=
"hl opt">,
</span> mGenerator
<span class=
"hl opt">-
></span><span class=
"hl kwd">maxLength
</span><span class=
"hl opt">());
</span>
395 wLength
<span class=
"hl opt">-
></span><span class=
"hl kwd">setValue
</span><span class=
"hl opt">(
</span>DefaultPasswordLength
<span class=
"hl opt">);
</span>
396 wLength
<span class=
"hl opt">-
></span><span class=
"hl kwd">setSpecialValueText
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">tr
</span><span class=
"hl opt">(
</span><span class=
"hl str">"Maximum
"</span><span class=
"hl opt">,
</span> VER_MODULE_NAME_STR
<span class=
"hl opt">));
</span>
397 g
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>wLength
<span class=
"hl opt">,
</span> <span class=
"hl num">2</span><span class=
"hl opt">,
</span> <span class=
"hl num">1</span><span class=
"hl opt">);
</span>
399 l
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> <span class=
"hl kwd">QLabel
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">tr
</span><span class=
"hl opt">(
</span><span class=
"hl str">"Password:
"</span><span class=
"hl opt">));
</span>
400 l
<span class=
"hl opt">-
></span><span class=
"hl kwd">setAlignment
</span><span class=
"hl opt">(
</span>Qt
<span class=
"hl opt">::
</span>AlignRight
<span class=
"hl opt">);
</span>
401 g
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>l
<span class=
"hl opt">,
</span> <span class=
"hl num">3</span><span class=
"hl opt">,
</span> <span class=
"hl num">0</span><span class=
"hl opt">);
</span>
403 wPassword
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> QLineEdit
<span class=
"hl opt">;
</span>
404 wPassword
<span class=
"hl opt">-
></span><span class=
"hl kwd">setReadOnly
</span><span class=
"hl opt">(
</span><span class=
"hl kwa">true
</span><span class=
"hl opt">);
</span>
405 g
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>wPassword
<span class=
"hl opt">,
</span> <span class=
"hl num">3</span><span class=
"hl opt">,
</span> <span class=
"hl num">1</span><span class=
"hl opt">,
</span> <span class=
"hl num">1</span><span class=
"hl opt">,
</span> <span class=
"hl num">2</span><span class=
"hl opt">);
</span>
407 v
<span class=
"hl opt">-
></span><span class=
"hl kwd">addStretch
</span><span class=
"hl opt">();
</span>
409 QHBoxLayout
<span class=
"hl opt">*
</span> h
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> QHBoxLayout
<span class=
"hl opt">;
</span>
410 h
<span class=
"hl opt">-
></span><span class=
"hl kwd">addStretch
</span><span class=
"hl opt">();
</span>
411 v
<span class=
"hl opt">-
></span><span class=
"hl kwd">addLayout
</span><span class=
"hl opt">(
</span>h
<span class=
"hl opt">);
</span>
413 wGenerate
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> <span class=
"hl kwd">QPushButton
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">tr
</span><span class=
"hl opt">(
</span><span class=
"hl str">"&Generate
"</span><span class=
"hl opt">,
</span> VER_MODULE_NAME_STR
<span class=
"hl opt">));
</span>
414 wGenerate
<span class=
"hl opt">-
></span><span class=
"hl kwd">setDisabled
</span><span class=
"hl opt">(
</span><span class=
"hl kwa">true
</span><span class=
"hl opt">);
</span>
415 wGenerate
<span class=
"hl opt">-
></span><span class=
"hl kwd">setDefault
</span><span class=
"hl opt">(
</span><span class=
"hl kwa">true
</span><span class=
"hl opt">);
</span>
416 <span class=
"hl kwd">connect
</span><span class=
"hl opt">(
</span>wGenerate
<span class=
"hl opt">,
</span> <span class=
"hl kwd">SIGNAL
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">clicked
</span><span class=
"hl opt">()),
</span> <span class=
"hl kwa">this
</span><span class=
"hl opt">,
</span> <span class=
"hl kwd">SLOT
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">generateClicked
</span><span class=
"hl opt">()));
</span>
417 h
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>wGenerate
<span class=
"hl opt">);
</span>
419 wCopy
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> <span class=
"hl kwd">QPushButton
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">tr
</span><span class=
"hl opt">(
</span><span class=
"hl str">"&Copy to Clipboard
"</span><span class=
"hl opt">,
</span> VER_MODULE_NAME_STR
<span class=
"hl opt">));
</span>
420 wCopy
<span class=
"hl opt">-
></span><span class=
"hl kwd">setDisabled
</span><span class=
"hl opt">(
</span><span class=
"hl kwa">true
</span><span class=
"hl opt">);
</span>
421 <span class=
"hl kwd">connect
</span><span class=
"hl opt">(
</span>wCopy
<span class=
"hl opt">,
</span> <span class=
"hl kwd">SIGNAL
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">clicked
</span><span class=
"hl opt">()),
</span> <span class=
"hl kwa">this
</span><span class=
"hl opt">,
</span> <span class=
"hl kwd">SLOT
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">copyClicked
</span><span class=
"hl opt">()));
</span>
422 h
<span class=
"hl opt">-
></span><span class=
"hl kwd">addWidget
</span><span class=
"hl opt">(
</span>wCopy
<span class=
"hl opt">);
</span>
424 QAction
<span class=
"hl opt">*
</span> a
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> <span class=
"hl kwd">QAction
</span><span class=
"hl opt">(
</span>masterWidget
<span class=
"hl opt">);
</span>
425 a
<span class=
"hl opt">-
></span><span class=
"hl kwd">setShortcut
</span><span class=
"hl opt">(
</span>Qt
<span class=
"hl opt">::
</span>Key_Return
<span class=
"hl opt">);
</span>
426 <span class=
"hl kwd">connect
</span><span class=
"hl opt">(
</span>a
<span class=
"hl opt">,
</span> <span class=
"hl kwd">SIGNAL
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">triggered
</span><span class=
"hl opt">()),
</span> <span class=
"hl kwa">this
</span><span class=
"hl opt">,
</span> <span class=
"hl kwd">SLOT
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">generateClicked
</span><span class=
"hl opt">()));
</span>
427 masterWidget
<span class=
"hl opt">-
></span><span class=
"hl kwd">addAction
</span><span class=
"hl opt">(
</span>a
<span class=
"hl opt">);
</span>
429 a
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> <span class=
"hl kwd">QAction
</span><span class=
"hl opt">(
</span>masterWidget
<span class=
"hl opt">);
</span>
430 a
<span class=
"hl opt">-
></span><span class=
"hl kwd">setShortcut
</span><span class=
"hl opt">(
</span>Qt
<span class=
"hl opt">::
</span>Key_Escape
<span class=
"hl opt">);
</span>
431 <span class=
"hl kwd">connect
</span><span class=
"hl opt">(
</span>a
<span class=
"hl opt">,
</span> <span class=
"hl kwd">SIGNAL
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">triggered
</span><span class=
"hl opt">()),
</span> qApp
<span class=
"hl opt">,
</span> <span class=
"hl kwd">SLOT
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">quit
</span><span class=
"hl opt">()));
</span>
432 masterWidget
<span class=
"hl opt">-
></span><span class=
"hl kwd">addAction
</span><span class=
"hl opt">(
</span>a
<span class=
"hl opt">);
</span>
434 mReady
<span class=
"hl opt">=
</span> <span class=
"hl kwa">true
</span><span class=
"hl opt">;
</span>
436 <span class=
"hl kwd">EVAF_INFO
</span><span class=
"hl opt">(
</span><span class=
"hl str">"%s initialized
"</span><span class=
"hl opt">,
</span> <span class=
"hl kwd">qPrintable
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">objectName
</span><span class=
"hl opt">()));
</span>
438 <span class=
"hl kwa">return true
</span><span class=
"hl opt">;
</span>
439 <span class=
"hl opt">}
</span>
441 <span class=
"hl kwb">void
</span> Module
<span class=
"hl opt">::
</span><span class=
"hl kwd">done
</span><span class=
"hl opt">()
</span>
442 <span class=
"hl opt">{
</span>
443 mReady
<span class=
"hl opt">=
</span> <span class=
"hl kwa">false
</span><span class=
"hl opt">;
</span>
445 <span class=
"hl kwd">EVAF_INFO
</span><span class=
"hl opt">(
</span><span class=
"hl str">"%s finalized
"</span><span class=
"hl opt">,
</span> <span class=
"hl kwd">qPrintable
</span><span class=
"hl opt">(
</span><span class=
"hl kwd">objectName
</span><span class=
"hl opt">()));
</span>
446 <span class=
"hl opt">}
</span>
448 <span class=
"hl kwb">void
</span> Module
<span class=
"hl opt">::
</span><span class=
"hl kwd">textChanged
</span><span class=
"hl opt">(
</span>QString
<span class=
"hl kwb">const
</span> <span class=
"hl opt">&)
</span>
449 <span class=
"hl opt">{
</span>
450 wGenerate
<span class=
"hl opt">-
></span><span class=
"hl kwd">setDisabled
</span><span class=
"hl opt">(
</span>wMasterPassword
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">().
</span><span class=
"hl kwd">isEmpty
</span><span class=
"hl opt">() ||
</span> wName
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">().
</span><span class=
"hl kwd">isEmpty
</span><span class=
"hl opt">());
</span>
451 <span class=
"hl kwa">if
</span> <span class=
"hl opt">(!
</span>wName
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">().
</span><span class=
"hl kwd">isEmpty
</span><span class=
"hl opt">()
&&</span> mStorage
<span class=
"hl opt">) {
</span>
452 QExplicitlySharedDataPointer
<span class=
"hl opt"><</span>PswGen
<span class=
"hl opt">::
</span>Storage
<span class=
"hl opt">::
</span>Data
<span class=
"hl opt">></span> data
<span class=
"hl opt">=
</span> mStorage
<span class=
"hl opt">-
></span><span class=
"hl kwd">query
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">());
</span>
453 <span class=
"hl kwa">if
</span> <span class=
"hl opt">(
</span>data
<span class=
"hl opt">)
</span>
454 wLength
<span class=
"hl opt">-
></span><span class=
"hl kwd">setValue
</span><span class=
"hl opt">(
</span>data
<span class=
"hl opt">-
></span><span class=
"hl kwd">length
</span><span class=
"hl opt">());
</span>
455 <span class=
"hl opt">}
</span>
456 <span class=
"hl opt">}
</span>
458 <span class=
"hl kwb">void
</span> Module
<span class=
"hl opt">::
</span><span class=
"hl kwd">generateClicked
</span><span class=
"hl opt">()
</span>
459 <span class=
"hl opt">{
</span>
460 <span class=
"hl kwa">if
</span> <span class=
"hl opt">(
</span>wMasterPassword
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">().
</span><span class=
"hl kwd">isEmpty
</span><span class=
"hl opt">() ||
</span> wName
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">().
</span><span class=
"hl kwd">isEmpty
</span><span class=
"hl opt">())
</span>
461 <span class=
"hl kwa">return
</span><span class=
"hl opt">;
</span>
462 wPassword
<span class=
"hl opt">-
></span><span class=
"hl kwd">setText
</span><span class=
"hl opt">(
</span>mGenerator
<span class=
"hl opt">-
></span><span class=
"hl kwd">generatePassword
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">(),
</span> wMasterPassword
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">(),
</span> wLength
<span class=
"hl opt">-
></span><span class=
"hl kwd">value
</span><span class=
"hl opt">()));
</span>
463 wCopy
<span class=
"hl opt">-
></span><span class=
"hl kwd">setEnabled
</span><span class=
"hl opt">(
</span><span class=
"hl kwa">true
</span><span class=
"hl opt">);
</span>
464 <span class=
"hl kwa">if
</span> <span class=
"hl opt">(
</span>mStorage
<span class=
"hl opt">) {
</span>
465 QExplicitlySharedDataPointer
<span class=
"hl opt"><</span>PswGen
<span class=
"hl opt">::
</span>Storage
<span class=
"hl opt">::
</span>Data
<span class=
"hl opt">></span> data
<span class=
"hl opt">=
</span> mStorage
<span class=
"hl opt">-
></span><span class=
"hl kwd">query
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">());
</span>
466 <span class=
"hl kwa">if
</span> <span class=
"hl opt">(!
</span>data
<span class=
"hl opt">)
</span>
467 data
<span class=
"hl opt">=
</span> <span class=
"hl kwa">new
</span> Storage
<span class=
"hl opt">::
</span><span class=
"hl kwd">Data
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">(),
</span> wLength
<span class=
"hl opt">-
></span><span class=
"hl kwd">value
</span><span class=
"hl opt">());
</span>
468 <span class=
"hl kwa">else
</span>
469 data
<span class=
"hl opt">-
></span><span class=
"hl kwd">setLength
</span><span class=
"hl opt">(
</span>wLength
<span class=
"hl opt">-
></span><span class=
"hl kwd">value
</span><span class=
"hl opt">());
</span>
470 mStorage
<span class=
"hl opt">-
></span><span class=
"hl kwd">save
</span><span class=
"hl opt">(
</span>wName
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">(),
</span> data
<span class=
"hl opt">);
</span>
471 <span class=
"hl opt">}
</span>
472 <span class=
"hl opt">}
</span>
474 <span class=
"hl kwb">void
</span> Module
<span class=
"hl opt">::
</span><span class=
"hl kwd">copyClicked
</span><span class=
"hl opt">()
</span>
475 <span class=
"hl opt">{
</span>
476 QClipboard
<span class=
"hl opt">*
</span> clipboard
<span class=
"hl opt">=
</span> QApplication
<span class=
"hl opt">::
</span><span class=
"hl kwd">clipboard
</span><span class=
"hl opt">();
</span>
477 <span class=
"hl kwa">if
</span> <span class=
"hl opt">(
</span>clipboard
<span class=
"hl opt">)
</span>
478 clipboard
<span class=
"hl opt">-
></span><span class=
"hl kwd">setText
</span><span class=
"hl opt">(
</span>wPassword
<span class=
"hl opt">-
></span><span class=
"hl kwd">text
</span><span class=
"hl opt">());
</span>
479 <span class=
"hl opt">}
</span></pre>
481 <p>Build the
<a href=
"pswgen11.html">PswGen application
</a>.
</p>