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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Wt examples: /home/koen/project/wt/public-git/wt/examples/composer/AttachmentEdit.C Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td style="padding-left: 0.5em;">
<div id="projectname">Wt examples
 <span id="projectnumber">3.2.1</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Generated by Doxygen 1.7.5.1 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div id="navrow2" class="tabs2">
<ul class="tablist">
<li><a href="files.html"><span>File List</span></a></li>
<li><a href="globals.html"><span>File Members</span></a></li>
</ul>
</div>
<div class="header">
<div class="headertitle">
<div class="title">/home/koen/project/wt/public-git/wt/examples/composer/AttachmentEdit.C</div> </div>
</div>
<div class="contents">
<a href="AttachmentEdit_8C.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * See the LICENSE file for terms of use.</span>
<a name="l00005"></a>00005 <span class="comment"> */</span>
<a name="l00006"></a>00006
<a name="l00007"></a>00007 <span class="preprocessor">#include <fstream></span>
<a name="l00008"></a>00008 <span class="preprocessor">#ifndef WIN32</span>
<a name="l00009"></a>00009 <span class="preprocessor"></span><span class="preprocessor">#include <unistd.h></span>
<a name="l00010"></a>00010 <span class="preprocessor">#endif</span>
<a name="l00011"></a>00011 <span class="preprocessor"></span><span class="preprocessor">#include <boost/lexical_cast.hpp></span>
<a name="l00012"></a>00012
<a name="l00013"></a>00013 <span class="preprocessor">#include <iostream></span>
<a name="l00014"></a>00014
<a name="l00015"></a>00015 <span class="preprocessor">#include <Wt/WAnchor></span>
<a name="l00016"></a>00016 <span class="preprocessor">#include <Wt/WApplication></span>
<a name="l00017"></a>00017 <span class="preprocessor">#include <Wt/WCheckBox></span>
<a name="l00018"></a>00018 <span class="preprocessor">#include <Wt/WCssDecorationStyle></span>
<a name="l00019"></a>00019 <span class="preprocessor">#include <Wt/WFileResource></span>
<a name="l00020"></a>00020 <span class="preprocessor">#include <Wt/WFileUpload></span>
<a name="l00021"></a>00021 <span class="preprocessor">#include <Wt/WProgressBar></span>
<a name="l00022"></a>00022 <span class="preprocessor">#include <Wt/WText></span>
<a name="l00023"></a>00023
<a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="Attachment_8h.html">Attachment.h</a>"</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="AttachmentEdit_8h.html">AttachmentEdit.h</a>"</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="Composer_8h.html">Composer.h</a>"</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include "<a class="code" href="Option_8h.html">Option.h</a>"</span>
<a name="l00028"></a>00028
<a name="l00029"></a><a class="code" href="classAttachmentEdit_1_1UploadInfo.html#ae6266b6977a64a366fddd9fc94a277ff">00029</a> <a class="code" href="classAttachmentEdit_1_1UploadInfo.html#ae6266b6977a64a366fddd9fc94a277ff">AttachmentEdit::UploadInfo::UploadInfo</a>(<span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Http_1_1UploadedFile.html">Http::UploadedFile</a>& f,
<a name="l00030"></a>00030 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html">WContainerWidget</a> *parent)
<a name="l00031"></a>00031 : <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html">WContainerWidget</a>(parent),
<a name="l00032"></a>00032 info_(f)
<a name="l00033"></a>00033 {
<a name="l00034"></a>00034 <span class="comment">/*</span>
<a name="l00035"></a>00035 <span class="comment"> * Include the file ?</span>
<a name="l00036"></a>00036 <span class="comment"> */</span>
<a name="l00037"></a>00037 <a class="code" href="classAttachmentEdit_1_1UploadInfo.html#a2bdc455790096d63d594a0dd7fe47a6f" title="The check box to keep or discard the uploaded file.">keep_</a> = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WCheckBox.html">WCheckBox</a>(<span class="keyword">this</span>);
<a name="l00038"></a>00038 <a class="code" href="classAttachmentEdit_1_1UploadInfo.html#a2bdc455790096d63d594a0dd7fe47a6f" title="The check box to keep or discard the uploaded file.">keep_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractToggleButton.html#a6838c9a37f3e9e3c466e9f48bde55e62">setChecked</a>();
<a name="l00039"></a>00039
<a name="l00040"></a>00040 <span class="comment">/*</span>
<a name="l00041"></a>00041 <span class="comment"> * Give information on the file uploaded.</span>
<a name="l00042"></a>00042 <span class="comment"> */</span>
<a name="l00043"></a>00043 std::streamsize fsize = 0;
<a name="l00044"></a>00044 {
<a name="l00045"></a>00045 std::ifstream theFile(<a class="code" href="classAttachmentEdit_1_1UploadInfo.html#acc43ca5ce401f8320154638602f3b536">info_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Http_1_1UploadedFile.html#a80453ce8dc7a06e12b5c1f622c027320">spoolFileName</a>().c_str());
<a name="l00046"></a>00046 theFile.seekg(0, std::ios_base::end);
<a name="l00047"></a>00047 fsize = theFile.tellg();
<a name="l00048"></a>00048 theFile.seekg(0);
<a name="l00049"></a>00049 }
<a name="l00050"></a>00050 std::wstring size;
<a name="l00051"></a>00051 <span class="keywordflow">if</span> (fsize < 1024)
<a name="l00052"></a>00052 size = boost::lexical_cast<std::wstring>(fsize) + L<span class="stringliteral">" bytes"</span>;
<a name="l00053"></a>00053 <span class="keywordflow">else</span>
<a name="l00054"></a>00054 size = boost::lexical_cast<std::wstring>((int)(fsize / 1024))
<a name="l00055"></a>00055 + L<span class="stringliteral">"kb"</span>;
<a name="l00056"></a>00056
<a name="l00057"></a>00057 std::wstring fn = <span class="keyword">static_cast<</span>std::wstring<span class="keyword">></span>
<a name="l00058"></a>00058 (<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#a6cd1b8a84c7aaf72e5d44cb47ae90e9c">escapeText</a>(WString::fromUTF8(<a class="code" href="classAttachmentEdit_1_1UploadInfo.html#acc43ca5ce401f8320154638602f3b536">info_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Http_1_1UploadedFile.html#a6548081a259f55d572bf049d576bb2a3">clientFileName</a>())));
<a name="l00059"></a>00059
<a name="l00060"></a>00060 <a class="code" href="classAttachmentEdit_1_1UploadInfo.html#ab7eba6ca0f514142e96fe3a4845f0361" title="Anchor referencing the file.">downloadLink_</a>
<a name="l00061"></a>00061 = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAnchor.html">WAnchor</a>(<span class="stringliteral">""</span>, fn + L<span class="stringliteral">" (<i>"</span> + WString::fromUTF8(<a class="code" href="classAttachmentEdit_1_1UploadInfo.html#acc43ca5ce401f8320154638602f3b536">info_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Http_1_1UploadedFile.html#a165bc88288a19a1134ecdf3922f86f25">contentType</a>())
<a name="l00062"></a>00062 + L<span class="stringliteral">"</i>) "</span> + size, <span class="keyword">this</span>);
<a name="l00063"></a>00063
<a name="l00064"></a>00064 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WFileResource.html">WFileResource</a> *res = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WFileResource.html">WFileResource</a>(<a class="code" href="classAttachmentEdit_1_1UploadInfo.html#acc43ca5ce401f8320154638602f3b536">info_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Http_1_1UploadedFile.html#a165bc88288a19a1134ecdf3922f86f25">contentType</a>(),
<a name="l00065"></a>00065 <a class="code" href="classAttachmentEdit_1_1UploadInfo.html#acc43ca5ce401f8320154638602f3b536">info_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Http_1_1UploadedFile.html#a80453ce8dc7a06e12b5c1f622c027320">spoolFileName</a>(),
<a name="l00066"></a>00066 <span class="keyword">this</span>);
<a name="l00067"></a>00067 res-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WResource.html#a30a0736f36f44b2a47ab25e9aa164851">suggestFileName</a>(<a class="code" href="classAttachmentEdit_1_1UploadInfo.html#acc43ca5ce401f8320154638602f3b536">info_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Http_1_1UploadedFile.html#a6548081a259f55d572bf049d576bb2a3">clientFileName</a>());
<a name="l00068"></a>00068 <a class="code" href="classAttachmentEdit_1_1UploadInfo.html#ab7eba6ca0f514142e96fe3a4845f0361" title="Anchor referencing the file.">downloadLink_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAnchor.html#a90d1aa41c061bdc9e61fa42eb36b27d8">setLink</a>(res);
<a name="l00069"></a>00069 }
<a name="l00070"></a>00070
<a name="l00071"></a><a class="code" href="classAttachmentEdit.html#aedd19941ecf64ef030eaa164eb34b85a">00071</a> <a class="code" href="classAttachmentEdit.html#aedd19941ecf64ef030eaa164eb34b85a" title="Creates an attachment edit field.">AttachmentEdit::AttachmentEdit</a>(<a class="code" href="classComposer.html" title="An E-mail composer widget.">Composer</a> *composer, <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html">WContainerWidget</a> *<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html#a3461e31818c4d2f516641bdaf508312a">parent</a>)
<a name="l00072"></a>00072 : <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html">WContainerWidget</a>(parent),
<a name="l00073"></a>00073 <a class="code" href="classAttachmentEdit.html#a403927978e9c841e64b62421458790e8">composer_</a>(composer),
<a name="l00074"></a>00074 <a class="code" href="classAttachmentEdit.html#a24ee0aca670036a7491a1c0114188cc7">uploadDone_</a>(this),
<a name="l00075"></a>00075 <a class="code" href="classAttachmentEdit.html#a6a19f364e7a82797bc5c18adb6a01530" title="The state of the last upload process.">uploadFailed_</a>(false)
<a name="l00076"></a>00076 {
<a name="l00077"></a>00077 <span class="comment">/*</span>
<a name="l00078"></a>00078 <span class="comment"> * The file upload itself.</span>
<a name="l00079"></a>00079 <span class="comment"> */</span>
<a name="l00080"></a>00080 <a class="code" href="classAttachmentEdit.html#aa9a3945293cf0a30d35e8bc56312d430" title="The WFileUpload control.">upload_</a> = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WFileUpload.html">WFileUpload</a>(<span class="keyword">this</span>);
<a name="l00081"></a>00081 <a class="code" href="classAttachmentEdit.html#aa9a3945293cf0a30d35e8bc56312d430" title="The WFileUpload control.">upload_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WFileUpload.html#a17f8e368c2ffc9836c65e470b311de9d">setMultiple</a>(<span class="keyword">true</span>);
<a name="l00082"></a>00082 <a class="code" href="classAttachmentEdit.html#aa9a3945293cf0a30d35e8bc56312d430" title="The WFileUpload control.">upload_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WFileUpload.html#ac7ad1324c86d378da9da9740a631a662">setFileTextSize</a>(40);
<a name="l00083"></a>00083
<a name="l00084"></a>00084 <span class="comment">/*</span>
<a name="l00085"></a>00085 <span class="comment"> * A progress bar</span>
<a name="l00086"></a>00086 <span class="comment"> */</span>
<a name="l00087"></a>00087 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WProgressBar.html">WProgressBar</a> *progress = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WProgressBar.html">WProgressBar</a>();
<a name="l00088"></a>00088 progress-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WProgressBar.html#a6fb308103fbdad5d58c90450c657678a">setFormat</a>(WString::Empty);
<a name="l00089"></a>00089 progress-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#ac90979eca6488814ac3d44194ba9ac79">setVerticalAlignment</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#ab8f772c69bc8180c31f9e4f4593b143fa2ed90f01dbf74049f428d33769d48e3f">AlignMiddle</a>);
<a name="l00090"></a>00090 <a class="code" href="classAttachmentEdit.html#aa9a3945293cf0a30d35e8bc56312d430" title="The WFileUpload control.">upload_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WFileUpload.html#a6600c5a1232057418b3fe63d5db1c004">setProgressBar</a>(progress);
<a name="l00091"></a>00091
<a name="l00092"></a>00092 <span class="comment">/*</span>
<a name="l00093"></a>00093 <span class="comment"> * The 'remove' option.</span>
<a name="l00094"></a>00094 <span class="comment"> */</span>
<a name="l00095"></a>00095 <a class="code" href="classAttachmentEdit.html#a55484424d37b196d07035e245399ffae" title="The option to cancel the file upload.">remove_</a> = <span class="keyword">new</span> <a class="code" href="classOption.html" title="A clickable option.">Option</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html#aa651f107ec7cf080faef6c435705fc44">tr</a>(<span class="stringliteral">"msg.remove"</span>), <span class="keyword">this</span>);
<a name="l00096"></a>00096 <a class="code" href="classAttachmentEdit.html#aa9a3945293cf0a30d35e8bc56312d430" title="The WFileUpload control.">upload_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#a9defbf26c8bc2310963e858613f25518">decorationStyle</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WCssDecorationStyle.html#a5e552350f0955212ea237994a98638dc">font</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WFont.html#ab67fd247c1541c18a6b97f41007e5f4b">setSize</a>(WFont::Smaller);
<a name="l00097"></a>00097 <a class="code" href="classAttachmentEdit.html#aa9a3945293cf0a30d35e8bc56312d430" title="The WFileUpload control.">upload_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#ac90979eca6488814ac3d44194ba9ac79">setVerticalAlignment</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#ab8f772c69bc8180c31f9e4f4593b143fa2ed90f01dbf74049f428d33769d48e3f">AlignMiddle</a>);
<a name="l00098"></a>00098 <a class="code" href="classAttachmentEdit.html#a55484424d37b196d07035e245399ffae" title="The option to cancel the file upload.">remove_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#a9795c18e926b26b97fcbabc62a1dd4e3">setMargin</a>(5, <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#a5a6f4636bcc6ab3c075165d249b3a5a3a6568fecac7c7d7223afaed240bcfdd9e">Left</a>);
<a name="l00099"></a>00099 <a class="code" href="classAttachmentEdit.html#a55484424d37b196d07035e245399ffae" title="The option to cancel the file upload.">remove_</a>-><a class="code" href="classOption.html#a31cd766f28605ceba53642d7d4e68c9e" title="Returns the clickable part.">item</a>()-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WInteractWidget.html#ae11e050cce0d4a8f742afa3ef92bfe8c">clicked</a>().connect(<span class="keyword">this</span>, &WWidget::hide);
<a name="l00100"></a>00100 <a class="code" href="classAttachmentEdit.html#a55484424d37b196d07035e245399ffae" title="The option to cancel the file upload.">remove_</a>-><a class="code" href="classOption.html#a31cd766f28605ceba53642d7d4e68c9e" title="Returns the clickable part.">item</a>()-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WInteractWidget.html#ae11e050cce0d4a8f742afa3ef92bfe8c">clicked</a>().connect(<span class="keyword">this</span>, &<a class="code" href="classAttachmentEdit.html#a27277be62832ebbda987707b7a2d814e" title="Slot triggered when the users wishes to remove this attachment edit.">AttachmentEdit::remove</a>);
<a name="l00101"></a>00101
<a name="l00102"></a>00102 <span class="comment">// The error message.</span>
<a name="l00103"></a>00103 <a class="code" href="classAttachmentEdit.html#a2c3fa5d63ec5feedc63f95295989cd4d" title="The text box to display an error (empty or too big file)">error_</a> = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html">WText</a>(<span class="stringliteral">""</span>, <span class="keyword">this</span>);
<a name="l00104"></a>00104 <a class="code" href="classAttachmentEdit.html#a2c3fa5d63ec5feedc63f95295989cd4d" title="The text box to display an error (empty or too big file)">error_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#afd3a3b359681111460a93d13979d17dd">setStyleClass</a>(<span class="stringliteral">"error"</span>);
<a name="l00105"></a>00105 <a class="code" href="classAttachmentEdit.html#a2c3fa5d63ec5feedc63f95295989cd4d" title="The text box to display an error (empty or too big file)">error_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#a9795c18e926b26b97fcbabc62a1dd4e3">setMargin</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WLength.html">WLength</a>(5), <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#a5a6f4636bcc6ab3c075165d249b3a5a3a6568fecac7c7d7223afaed240bcfdd9e">Left</a>);
<a name="l00106"></a>00106
<a name="l00107"></a>00107 <span class="comment">/*</span>
<a name="l00108"></a>00108 <span class="comment"> * React to events.</span>
<a name="l00109"></a>00109 <span class="comment"> */</span>
<a name="l00110"></a>00110
<a name="l00111"></a>00111 <span class="comment">// Try to catch the fileupload change signal to trigger an upload.</span>
<a name="l00112"></a>00112 <span class="comment">// We could do like google and at a delay with a WTimer as well...</span>
<a name="l00113"></a>00113 <a class="code" href="classAttachmentEdit.html#aa9a3945293cf0a30d35e8bc56312d430" title="The WFileUpload control.">upload_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WFileUpload.html#a3abaf94bdba04e7833aa18bc7e8d0f40">changed</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1EventSignal.html#a36896f54a4db342af24efa6e9d703455">connect</a>(<a class="code" href="classAttachmentEdit.html#aa9a3945293cf0a30d35e8bc56312d430" title="The WFileUpload control.">upload_</a>, &WFileUpload::upload);
<a name="l00114"></a>00114
<a name="l00115"></a>00115 <span class="comment">// React to a succesfull upload.</span>
<a name="l00116"></a>00116 <a class="code" href="classAttachmentEdit.html#aa9a3945293cf0a30d35e8bc56312d430" title="The WFileUpload control.">upload_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WFileUpload.html#aacb4622c8cd83d1635a8c0db13c8c0fe">uploaded</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1EventSignal.html#a36896f54a4db342af24efa6e9d703455">connect</a>(<span class="keyword">this</span>, &<a class="code" href="classAttachmentEdit.html#a85d6892fe9c38394d17dc350ce678acd" title="Slot triggered when the WFileUpload completed an upload.">AttachmentEdit::uploaded</a>);
<a name="l00117"></a>00117
<a name="l00118"></a>00118 <span class="comment">// React to a fileupload problem.</span>
<a name="l00119"></a>00119 <a class="code" href="classAttachmentEdit.html#aa9a3945293cf0a30d35e8bc56312d430" title="The WFileUpload control.">upload_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WFileUpload.html#a84fd55ba7c74134970369d1f2cb8aae1">fileTooLarge</a>().connect(<span class="keyword">this</span>, &<a class="code" href="classAttachmentEdit.html#ae2435ee247748851f9b02ae217260766" title="Slot triggered when the WFileUpload received an oversized file.">AttachmentEdit::fileTooLarge</a>);
<a name="l00120"></a>00120
<a name="l00121"></a>00121 <span class="comment">/*</span>
<a name="l00122"></a>00122 <span class="comment"> * Connect the uploadDone signal to the Composer's attachmentDone,</span>
<a name="l00123"></a>00123 <span class="comment"> * so that the Composer can keep track of attachment upload progress,</span>
<a name="l00124"></a>00124 <span class="comment"> * if it wishes.</span>
<a name="l00125"></a>00125 <span class="comment"> */</span>
<a name="l00126"></a>00126 <a class="code" href="classAttachmentEdit.html#a24ee0aca670036a7491a1c0114188cc7">uploadDone_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Signal.html#a15d1150af031537b492674ee651bf4a3">connect</a>(composer, &<a class="code" href="classComposer.html#aaa2db4aef750f6533c53af1189c92144" title="Slotcalled when an attachment has been uploaded.">Composer::attachmentDone</a>);
<a name="l00127"></a>00127 }
<a name="l00128"></a>00128
<a name="l00129"></a><a class="code" href="classAttachmentEdit.html#a172fff67913dc3e3adf8c1e4198d6ea6">00129</a> <span class="keywordtype">bool</span> <a class="code" href="classAttachmentEdit.html#a172fff67913dc3e3adf8c1e4198d6ea6" title="Updates the file now.">AttachmentEdit::uploadNow</a>()
<a name="l00130"></a>00130 {
<a name="l00131"></a>00131 <span class="comment">/*</span>
<a name="l00132"></a>00132 <span class="comment"> * See if this attachment still needs to be uploaded,</span>
<a name="l00133"></a>00133 <span class="comment"> * and return if a new asynchronous upload is started.</span>
<a name="l00134"></a>00134 <span class="comment"> */</span>
<a name="l00135"></a>00135 <span class="keywordflow">if</span> (<a class="code" href="classAttachmentEdit.html#aa9a3945293cf0a30d35e8bc56312d430" title="The WFileUpload control.">upload_</a>) {
<a name="l00136"></a>00136 <span class="keywordflow">if</span> (<a class="code" href="classAttachmentEdit.html#aa9a3945293cf0a30d35e8bc56312d430" title="The WFileUpload control.">upload_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WFileUpload.html#a66376fb4668a037760a91abad9f83f8a">canUpload</a>()) {
<a name="l00137"></a>00137 <a class="code" href="classAttachmentEdit.html#aa9a3945293cf0a30d35e8bc56312d430" title="The WFileUpload control.">upload_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WFileUpload.html#ac17094f2fd6ae8cac1035161f7d80b9c">upload</a>();
<a name="l00138"></a>00138 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00139"></a>00139 } <span class="keywordflow">else</span>
<a name="l00140"></a>00140 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00141"></a>00141 } <span class="keywordflow">else</span>
<a name="l00142"></a>00142 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00143"></a>00143 }
<a name="l00144"></a>00144
<a name="l00145"></a><a class="code" href="classAttachmentEdit.html#a85d6892fe9c38394d17dc350ce678acd">00145</a> <span class="keywordtype">void</span> <a class="code" href="classAttachmentEdit.html#a85d6892fe9c38394d17dc350ce678acd" title="Slot triggered when the WFileUpload completed an upload.">AttachmentEdit::uploaded</a>()
<a name="l00146"></a>00146 {
<a name="l00147"></a>00147 std::vector<Http::UploadedFile> files = <a class="code" href="classAttachmentEdit.html#aa9a3945293cf0a30d35e8bc56312d430" title="The WFileUpload control.">upload_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WFileUpload.html#ab1ffd4c3c203e6772f4a1b2e235888e3">uploadedFiles</a>();
<a name="l00148"></a>00148
<a name="l00149"></a>00149 <span class="keywordflow">if</span> (!files.empty()) {
<a name="l00150"></a>00150 <span class="comment">/*</span>
<a name="l00151"></a>00151 <span class="comment"> * Delete this widgets since we have a succesfull upload.</span>
<a name="l00152"></a>00152 <span class="comment"> */</span>
<a name="l00153"></a>00153 <span class="keyword">delete</span> <a class="code" href="classAttachmentEdit.html#aa9a3945293cf0a30d35e8bc56312d430" title="The WFileUpload control.">upload_</a>;
<a name="l00154"></a>00154 <a class="code" href="classAttachmentEdit.html#aa9a3945293cf0a30d35e8bc56312d430" title="The WFileUpload control.">upload_</a> = 0;
<a name="l00155"></a>00155 <span class="keyword">delete</span> <a class="code" href="classAttachmentEdit.html#a55484424d37b196d07035e245399ffae" title="The option to cancel the file upload.">remove_</a>;
<a name="l00156"></a>00156 <a class="code" href="classAttachmentEdit.html#a55484424d37b196d07035e245399ffae" title="The option to cancel the file upload.">remove_</a> = 0;
<a name="l00157"></a>00157 <span class="keyword">delete</span> <a class="code" href="classAttachmentEdit.html#a2c3fa5d63ec5feedc63f95295989cd4d" title="The text box to display an error (empty or too big file)">error_</a>;
<a name="l00158"></a>00158 <a class="code" href="classAttachmentEdit.html#a2c3fa5d63ec5feedc63f95295989cd4d" title="The text box to display an error (empty or too big file)">error_</a> = 0;
<a name="l00159"></a>00159
<a name="l00160"></a>00160 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i < files.size(); ++i)
<a name="l00161"></a>00161 <a class="code" href="classAttachmentEdit.html#ad3f98e98d3e5502fc275446dc5c6b762">uploadInfo_</a>.push_back(<span class="keyword">new</span> <a class="code" href="classAttachmentEdit_1_1UploadInfo.html">UploadInfo</a>(files[i], <span class="keyword">this</span>));
<a name="l00162"></a>00162 } <span class="keywordflow">else</span> {
<a name="l00163"></a>00163 <a class="code" href="classAttachmentEdit.html#a2c3fa5d63ec5feedc63f95295989cd4d" title="The text box to display an error (empty or too big file)">error_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html#a2f788aa524d51b3962642c9f565e66e6">setText</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html#aa651f107ec7cf080faef6c435705fc44">tr</a>(<span class="stringliteral">"msg.file-empty"</span>));
<a name="l00164"></a>00164 <a class="code" href="classAttachmentEdit.html#a6a19f364e7a82797bc5c18adb6a01530" title="The state of the last upload process.">uploadFailed_</a> = <span class="keyword">true</span>;
<a name="l00165"></a>00165 }
<a name="l00166"></a>00166
<a name="l00167"></a>00167 <span class="comment">/*</span>
<a name="l00168"></a>00168 <span class="comment"> * Signal to the Composer that a new asynchronous file upload was processed.</span>
<a name="l00169"></a>00169 <span class="comment"> */</span>
<a name="l00170"></a>00170 <a class="code" href="classAttachmentEdit.html#a24ee0aca670036a7491a1c0114188cc7">uploadDone_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Signal.html#a8d9cf8a1e83634462fe2b492b3beb1c5">emit</a>();
<a name="l00171"></a>00171 }
<a name="l00172"></a>00172
<a name="l00173"></a><a class="code" href="classAttachmentEdit.html#a27277be62832ebbda987707b7a2d814e">00173</a> <span class="keywordtype">void</span> <a class="code" href="classAttachmentEdit.html#a27277be62832ebbda987707b7a2d814e" title="Slot triggered when the users wishes to remove this attachment edit.">AttachmentEdit::remove</a>()
<a name="l00174"></a>00174 {
<a name="l00175"></a>00175 <a class="code" href="classAttachmentEdit.html#a403927978e9c841e64b62421458790e8">composer_</a>-><a class="code" href="classComposer.html#ab142f49c8de59da0f84185165eb6c1c1" title="Remove the given attachment edit.">removeAttachment</a>(<span class="keyword">this</span>);
<a name="l00176"></a>00176 }
<a name="l00177"></a>00177
<a name="l00178"></a><a class="code" href="classAttachmentEdit.html#ae2435ee247748851f9b02ae217260766">00178</a> <span class="keywordtype">void</span> <a class="code" href="classAttachmentEdit.html#ae2435ee247748851f9b02ae217260766" title="Slot triggered when the WFileUpload received an oversized file.">AttachmentEdit::fileTooLarge</a>(::int64_t size)
<a name="l00179"></a>00179 {
<a name="l00180"></a>00180 <a class="code" href="classAttachmentEdit.html#a2c3fa5d63ec5feedc63f95295989cd4d" title="The text box to display an error (empty or too big file)">error_</a>-><a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html#a2f788aa524d51b3962642c9f565e66e6">setText</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html#aa651f107ec7cf080faef6c435705fc44">tr</a>(<span class="stringliteral">"msg.file-too-large"</span>)
<a name="l00181"></a>00181 .arg(size / 1024)
<a name="l00182"></a>00182 .arg(WApplication::instance()->maximumRequestSize() / 1024));
<a name="l00183"></a>00183 <a class="code" href="classAttachmentEdit.html#a6a19f364e7a82797bc5c18adb6a01530" title="The state of the last upload process.">uploadFailed_</a> = <span class="keyword">true</span>;
<a name="l00184"></a>00184
<a name="l00185"></a>00185 <span class="comment">/*</span>
<a name="l00186"></a>00186 <span class="comment"> * Signal to the Composer that a new asyncrhonous file upload was processed.</span>
<a name="l00187"></a>00187 <span class="comment"> */</span>
<a name="l00188"></a>00188 <a class="code" href="classAttachmentEdit.html#a24ee0aca670036a7491a1c0114188cc7">uploadDone_</a>.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Signal.html#a8d9cf8a1e83634462fe2b492b3beb1c5">emit</a>();
<a name="l00189"></a>00189 }
<a name="l00190"></a>00190
<a name="l00191"></a><a class="code" href="classAttachmentEdit.html#aa6037eafc345a6a3358da421fc04045a">00191</a> std::vector<Attachment> <a class="code" href="classAttachmentEdit.html#aa6037eafc345a6a3358da421fc04045a" title="Returns the attachment.">AttachmentEdit::attachments</a>()
<a name="l00192"></a>00192 {
<a name="l00193"></a>00193 std::vector<Attachment> result;
<a name="l00194"></a>00194
<a name="l00195"></a>00195 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i < <a class="code" href="classAttachmentEdit.html#ad3f98e98d3e5502fc275446dc5c6b762">uploadInfo_</a>.size(); ++i) {
<a name="l00196"></a>00196 <span class="keywordflow">if</span> (<a class="code" href="classAttachmentEdit.html#ad3f98e98d3e5502fc275446dc5c6b762">uploadInfo_</a>[i]->keep_->isChecked()) {
<a name="l00197"></a>00197 <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Http_1_1UploadedFile.html">Http::UploadedFile</a>& f = <a class="code" href="classAttachmentEdit.html#ad3f98e98d3e5502fc275446dc5c6b762">uploadInfo_</a>[i]->info_;
<a name="l00198"></a>00198 f.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Http_1_1UploadedFile.html#ab8cdd14724b871e71d3ec7d9530f9e29">stealSpoolFile</a>();
<a name="l00199"></a>00199 result.push_back(<a class="code" href="classAttachment.html" title="An email attachment.">Attachment</a>
<a name="l00200"></a>00200 (WString::fromUTF8(f.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Http_1_1UploadedFile.html#a6548081a259f55d572bf049d576bb2a3">clientFileName</a>()),
<a name="l00201"></a>00201 WString::fromUTF8(f.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Http_1_1UploadedFile.html#a165bc88288a19a1134ecdf3922f86f25">contentType</a>()),
<a name="l00202"></a>00202 f.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Http_1_1UploadedFile.html#a80453ce8dc7a06e12b5c1f622c027320">spoolFileName</a>()));
<a name="l00203"></a>00203 }
<a name="l00204"></a>00204 }
<a name="l00205"></a>00205
<a name="l00206"></a>00206 <span class="keywordflow">return</span> result;
<a name="l00207"></a>00207 }
</pre></div></div>
</div>
<hr size="1"><address style="text-align: right; margin: 3px"><small>
Generated on Fri Mar 30 2012 for <a href="http://www.webtoolkit.eu/wt">the
C++ Web Toolkit (Wt)</a> by <a
href="http://www.doxygen.org/index.html"><img src="doxygen.png"
alt="doxygen" border="0" style="vertical-align: middle; display:
inline-block; height: 2em"></a> 1.7.5.1</small></address>
</body>
</html>
|