Wt examples  3.3.0
ComposeExample.C
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
3  *
4  * See the LICENSE file for terms of use.
5  */
6 
7 #include <Wt/WApplication>
8 #include <Wt/WBreak>
9 #include <Wt/WText>
10 #include <Wt/WPushButton>
11 #include <Wt/WContainerWidget>
12 #include <Wt/WStringUtil>
13 #ifndef _MSC_VER
14 #include <unistd.h>
15 #endif
16 
17 #include "Composer.h"
18 #include "ComposeExample.h"
19 #include "Contact.h"
20 
22  : WContainerWidget(parent)
23 {
24  composer_ = new Composer(this);
25 
26  std::vector<Contact> addressBook;
27  addressBook.push_back(Contact(L"Koen Deforche",
28  L"koen.deforche@gmail.com"));
29  addressBook.push_back(Contact(L"Koen alias1",
30  L"koen.alias1@yahoo.com"));
31  addressBook.push_back(Contact(L"Koen alias2",
32  L"koen.alias2@yahoo.com"));
33  addressBook.push_back(Contact(L"Koen alias3",
34  L"koen.alias3@yahoo.com"));
35  addressBook.push_back(Contact(L"Bartje",
36  L"jafar@hotmail.com"));
37  composer_->setAddressBook(addressBook);
38 
39  std::vector<Contact> contacts;
40  contacts.push_back(Contact(L"Koen Deforche", L"koen.deforche@gmail.com"));
41 
42  composer_->setTo(contacts);
43  composer_->setSubject("That's cool! Want to start your own google?");
44 
47 
48  details_ = new WContainerWidget(this);
49 
50  new WText(tr("example.info"), details_);
51 }
52 
54 {
55  WContainerWidget *feedback = new WContainerWidget(this);
56  feedback->setStyleClass(L"feedback");
57 
58  WContainerWidget *horiz = new WContainerWidget(feedback);
59  new WText(L"<p>We could have, but did not send the following email:</p>",
60  horiz);
61 
62  std::vector<Contact> contacts = composer_->to();
63  if (!contacts.empty())
64  horiz = new WContainerWidget(feedback);
65  for (unsigned i = 0; i < contacts.size(); ++i) {
66  new WText(L"To: \"" + contacts[i].name + L"\" <"
67  + contacts[i].email + L">", PlainText, horiz);
68  new WBreak(horiz);
69  }
70 
71  contacts = composer_->cc();
72  if (!contacts.empty())
73  horiz = new WContainerWidget(feedback);
74  for (unsigned i = 0; i < contacts.size(); ++i) {
75  new WText(L"Cc: \"" + contacts[i].name + L"\" <"
76  + contacts[i].email + L">", PlainText, horiz);
77  new WBreak(horiz);
78  }
79 
80  contacts = composer_->bcc();
81  if (!contacts.empty())
82  horiz = new WContainerWidget(feedback);
83  for (unsigned i = 0; i < contacts.size(); ++i) {
84  new WText(L"Bcc: \"" + contacts[i].name + L"\" <"
85  + contacts[i].email + L">", PlainText, horiz);
86  new WBreak(horiz);
87  }
88 
89  horiz = new WContainerWidget(feedback);
90  WText *t = new WText("Subject: \"" + composer_->subject() + "\"",
91  PlainText, horiz);
92 
93  std::vector<Attachment> attachments = composer_->attachments();
94  if (!attachments.empty())
95  horiz = new WContainerWidget(feedback);
96  for (unsigned i = 0; i < attachments.size(); ++i) {
97  new WText(L"Attachment: \""
98  + attachments[i].fileName
99  + L"\" (" + attachments[i].contentDescription
100  + L")", PlainText, horiz);
101 
102  unlink(attachments[i].spoolFileName.c_str());
103 
104  new WText(", was in spool file: "
105  + attachments[i].spoolFileName, horiz);
106  new WBreak(horiz);
107  }
108 
109  std::wstring message = composer_->message();
110 
111  horiz = new WContainerWidget(feedback);
112  t = new WText("Message body: ", horiz);
113  new WBreak(horiz);
114 
115  if (!message.empty()) {
116  t = new WText(message, PlainText, horiz);
117  } else
118  t = new WText("<i>(empty)</i>", horiz);
119 
120  delete composer_;
121  delete details_;
122 
123  wApp->quit();
124 }
125 
127 {
128  WContainerWidget *feedback = new WContainerWidget(this);
129  feedback->setStyleClass("feedback");
130 
131  WContainerWidget *horiz = new WContainerWidget(feedback);
132  new WText("<p>Wise decision! Everyone's mailbox is already full anyway.</p>",
133  horiz);
134 
135  delete composer_;
136  delete details_;
137 
138  wApp->quit();
139 }
140 
142 {
143  WApplication *app = new WApplication(env);
144 
145  // The following assumes composer.xml is in the webserver working directory
146  // (but does not need to be deployed within docroot):
147  app->messageResourceBundle().use(WApplication::appRoot() + "composer");
148 
149  // The following assumes composer.css is deployed in the seb server at the
150  // same location as the application:
151  app->useStyleSheet("composer.css");
152 
153  app->setTitle("Composer example");
154 
155  app->root()->addWidget(new ComposeExample());
156 
157  return app;
158 }
159 
160 int main(int argc, char **argv)
161 {
162  return WRun(argc, argv, &createApplication);
163 }
164 

Generated on Fri May 31 2013 for the C++ Web Toolkit (Wt) by doxygen 1.8.3.1