Wt examples 3.3.12
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 new WText("Subject: \"" + composer_->subject() + "\"", PlainText, horiz);
91
92 std::vector<Attachment> attachments = composer_->attachments();
93 if (!attachments.empty())
94 horiz = new WContainerWidget(feedback);
95 for (unsigned i = 0; i < attachments.size(); ++i) {
96 new WText(L"Attachment: \""
97 + attachments[i].fileName
98 + L"\" (" + attachments[i].contentDescription
99 + L")", PlainText, horiz);
100
101 unlink(attachments[i].spoolFileName.c_str());
102
103 new WText(", was in spool file: "
104 + attachments[i].spoolFileName, horiz);
105 new WBreak(horiz);
106 }
107
108 std::wstring message = composer_->message();
109
110 horiz = new WContainerWidget(feedback);
111 new WText("Message body: ", horiz);
112 new WBreak(horiz);
113
114 if (!message.empty()) {
115 new WText(message, PlainText, horiz);
116 } else
117 new WText("<i>(empty)</i>", horiz);
118
119 delete composer_;
120 delete details_;
121
122 wApp->quit();
123}
124
126{
127 WContainerWidget *feedback = new WContainerWidget(this);
128 feedback->setStyleClass("feedback");
129
130 WContainerWidget *horiz = new WContainerWidget(feedback);
131 new WText("<p>Wise decision! Everyone's mailbox is already full anyway.</p>",
132 horiz);
133
134 delete composer_;
135 delete details_;
136
137 wApp->quit();
138}
139
141{
142 WApplication *app = new WApplication(env);
143
144 // The following assumes composer.xml is in the webserver working directory
145 // (but does not need to be deployed within docroot):
146 app->messageResourceBundle().use(WApplication::appRoot() + "composer");
147
148 // The following assumes composer.css is deployed in the seb server at the
149 // same location as the application:
150 app->useStyleSheet("composer.css");
151
152 app->setTitle("Composer example");
153
154 app->root()->addWidget(new ComposeExample());
155
156 return app;
157}
158
159int main(int argc, char **argv)
160{
161 return WRun(argc, argv, &createApplication);
162}
163
WApplication * createApplication(const WEnvironment &env)
int main(int argc, char **argv)
Main widget of the Composer example.
WContainerWidget * details_
Composer * composer_
ComposeExample(WContainerWidget *parent=0)
create a new Composer example.
An E-mail composer widget.
Definition Composer.h:41
std::vector< Contact > bcc() const
Get the Bc: contacts.
Definition Composer.C:60
const WString & message() const
Get the message.
Definition Composer.C:88
Wt::Signal< void > send
The message is ready to be sent...
Definition Composer.h:93
std::vector< Contact > to() const
Get the To: contacts.
Definition Composer.C:50
void setTo(const std::vector< Contact > &to)
Set message To: contacts.
Definition Composer.C:35
Wt::Signal< void > discard
The message must be discarded.
Definition Composer.h:97
void setSubject(const WString &subject)
Set subject.
Definition Composer.C:40
const WString & subject() const
Get the subject.
Definition Composer.C:70
void setAddressBook(const std::vector< Contact > &addressBook)
Set the address book, for autocomplete suggestions.
Definition Composer.C:65
std::vector< Contact > cc() const
Get the Cc: contacts.
Definition Composer.C:55
std::vector< Attachment > attachments() const
Get the list of attachments.
Definition Composer.C:75
virtual Wt::Signals::connection connect(WObject *target, WObject::Method method)
WMessageResourceBundle & messageResourceBundle()
WContainerWidget * root() const
void setTitle(const WString &title)
void useStyleSheet(const WLink &link, const std::string &media="all")
virtual void addWidget(WWidget *widget)
void use(const std::string &path, bool loadInMemory=true)
virtual void setStyleClass(const WString &styleClass)
PlainText
An email contact.
Definition Contact.h:20

Generated on Fri May 17 2024 for the C++ Web Toolkit (Wt) by doxygen 1.9.8