1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML
><HEAD
><TITLE
>Chapter 11</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.54"/><LINK
REL="HOME"
TITLE="KDE 2.0 Development"
HREF="index.html"/><LINK
REL="UP"
TITLE="Answers"
HREF="ap-c.html"/><LINK
REL="PREVIOUS"
TITLE="Chapter 10"
HREF="appc17.html"/><LINK
REL="NEXT"
TITLE="Chapter 12"
HREF="appc21.html"/><META
HTTP-EQUIV="Content-Style-Type"
CONTENT="text/css"/><LINK
REL="stylesheet"
HREF="kde-common.css"
TYPE="text/css"/><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=iso-8859-1"/><META
HTTP-EQUIV="Content-Language"
CONTENT="en"/><LINK
REL="stylesheet"
HREF="kde-localised.css"
TYPE="text/css"
TITLE="KDE-English"/><LINK
REL="stylesheet"
HREF="kde-default.css"
TYPE="text/css"
TITLE="KDE-Default"/></HEAD
><BODY
CLASS="section"
LINK="#336699"
VLINK="#336699"
ALINK="#336699"
BGCOLOR="#FFFFFF"
><DIV
ALIGN="RIGHT"
CLASS="NAVBAR"
><P
><A
HREF="appc17.html"
>Prev</A
> <A
HREF="appc21.html"
>Next</A
> <A
HREF="index.html"
>Table of Contents</A
></P
></DIV
><DIV
CLASS="section"
><TABLE
WIDTH="100%"
CELLPADDING="0"
CELLSPACING="0"
BORDER="0"
ALIGN="CENTER"
><TR
><TD
WIDTH="90%"
><H1
CLASS="section"
><A
NAME="appC19"
>C.11. <A
HREF="ch11.html"
>Chapter 11</A
></A
></H1
><P
></P
><DIV
CLASS="section"
><TABLE
WIDTH="100%"
CELLPADDING="0"
CELLSPACING="0"
BORDER="0"
ALIGN="CENTER"
><TR
><TD
WIDTH="90%"
><H2
CLASS="section"
><A
NAME="appC20"
>C.11.1. Exercises</A
></H2
><DIV
CLASS="qandaset"
><DL
><DT
>C.11.1.1. <A
HREF="appc19.html#AEN28299"
>Suppose you would like to have only one instance of your panel applet running at a time. (Who would want, for example, two pagers in their panel?) Combine <TT
CLASS="literal"
>KWeather</TT
> and <TT
CLASS="literal"
>KUnique</TT
> into one application that runs only once and displays a <SPAN
CLASS="QUOTE"
>"sorry"</SPAN
> message if the user tries to start it a second time. See Listings C.35–C.37 for the answers.</A
></DT
></DL
><DIV
CLASS="qandaentry"
><DIV
CLASS="question"
><P
><A
NAME="AEN28299"
></A
><B
>C.11.1.1. </B
>Suppose you would like to have only one instance of your panel applet running at a time. (Who would want, for example, two pagers in their panel?) Combine <TT
CLASS="literal"
>KWeather</TT
> and <TT
CLASS="literal"
>KUnique</TT
> into one application that runs only once and displays a <SPAN
CLASS="QUOTE"
>"sorry"</SPAN
> message if the user tries to start it a second time. See Listings C.35–C.37 for the answers.</P
></DIV
><DIV
CLASS="answer"
><P
><B
> </B
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
> 1
2 1: #ifndef __KUNIQUEWEATHER_H__
3 2: #define __KUNIQUEWEATHER_H__
4 3:
5 4: #include <kuniqueapp.h>
6 5: #include <kpanelapplet.h>
7 6:
8 7: class KUniqueWeather : public KUniqueApplication, KPanelApplet
9 8: {
10 9: public:
11 10: KUniqueWeather (int& argc, char** argv,
12 11: const QCString& rAppName = 0, QWidget *parent=0);
13 12:
14 13: protected:
15 14: void preferences();
16 15:
17 16: };
18 17:
19 18: #endif
20 </PRE
></TD
></TR
></TABLE
></P
><DIV
CLASS="example"
><HR/><A
NAME="ap-clist36"
></A
><P
><B
>Example C.36. kuniqueweather.cpp: Class Definition for <TT
CLASS="literal"
>KUniqueWeather</TT
>, a Single-Instance Panel Applet</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
> 1
2 1: #include <stdio.h>
3 2:
4 3: #include <qlabel.h>
5 4:
6 5: #include "kuniqueweather.h"
7 6:
8 7: KUniqueWeather::KUniqueWeather (int& argc, char** argv,
9 8: const QCString& rAppName, QWidget *parent) :
10 9: KUniqueApplication (argc, argv, rAppName),
11 10: KPanelApplet (parent)
12 11: {
13 12: QLabel *qlabel = new QLabel ("Rainy\n 48F", this);
14 13: qlabel->setAlignment (Qt::AlignVCenter);
15 14: setMinimumSize (qlabel->sizeHint());
16 15:
17 16: setActions (Preferences);
18 17:
19 18: dock("kweather");
20 19: }
21 20:
22 21: void
23 22: KUniqueWeather::preferences()
24 23: {
25 24: printf ("Here we let the user configure the panel applet.\n");
26 25: }
27 </PRE
></TD
></TR
></TABLE
><HR/></DIV
><DIV
CLASS="example"
><HR/><A
NAME="ap-clist37"
></A
><P
><B
>Example C.37. main.cpp: The <TT
CLASS="literal"
>main()</TT
> Function Used to Start <TT
CLASS="literal"
>KUniqueWeather</TT
></B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
> 1
2 1: #include <kapp.h>
3 2: #include <kmessagebox.h>
4 3:
5 4: #include "kuniqueweather.h"
6 5:
7 6: int
8 7: main (int argc, char *argv[])
9 8: {
10 9: if (!KUniqueWeather::start(argc, argv, "kuniqueweather"))
11 10: {
12 11: KApplication a (argc, argv, "kuniqueweather");
13 12: KMessageBox::sorry (0, "Cannot start more that one instance of "
14 13: "KUniqueWeather.");
15 14: exit (0);
16 15: }
17 16:
18 17:
19 18: KUniqueWeather kuniqueweather (argc, argv, "kuniqueweather");
20 19:
21 20: return kuniqueweather.exec();
22 21: }
23 </PRE
></TD
></TR
></TABLE
><HR/></DIV
></DIV
></DIV
></DIV
></TD
><TD
WIDTH="10%"
VALIGN="BOTTOM"
ALIGN="CENTER"
><ANNMARK
NAME="appC20"/></TD
></TR
><ANNOTATION
NAME="appC20"
TITLE="Exercises"/></TABLE
></DIV
></TD
><TD
WIDTH="10%"
VALIGN="BOTTOM"
ALIGN="CENTER"
><ANNMARK
NAME="appC19"/></TD
></TR
><ANNOTATION
NAME="appC19"
TITLE="Chapter 11"/></TABLE
></DIV
><DIV
ALIGN="RIGHT"
CLASS="NAVBAR"
><P
><A
HREF="appc17.html"
>Prev</A
> <A
HREF="appc21.html"
>Next</A
> <A
HREF="index.html"
>Table of Contents</A
></P
></DIV
><HR
WIDTH="100%"
SIZE="2"
ALIGN="CENTER"
NOSHADE="NOSHADE"/></BODY
></HTML
>
|