Wt examples 4.6.1
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ComposeExample Class Reference

Main widget of the Composer example. More...

#include <ComposeExample.h>

Inheritance diagram for ComposeExample:
Inheritance graph
[legend]

Public Member Functions

 ComposeExample ()
 create a new Composer example. More...
 

Private Member Functions

void send ()
 
void discard ()
 

Private Attributes

Composercomposer_
 
WContainerWidget * details_
 

Detailed Description

Main widget of the Composer example.

Definition at line 27 of file ComposeExample.h.

Constructor & Destructor Documentation

◆ ComposeExample()

ComposeExample::ComposeExample ( )

create a new Composer example.

Definition at line 21 of file ComposeExample.C.

22 : WContainerWidget()
23{
24 composer_ = this->addWidget(std::make_unique<Composer>());
25
26 std::vector<Contact> addressBook;
27 addressBook.push_back(Contact(U"Koen Deforche",
28 U"koen.deforche@gmail.com"));
29 addressBook.push_back(Contact(U"Koen alias1",
30 U"koen.alias1@yahoo.com"));
31 addressBook.push_back(Contact(U"Koen alias2",
32 U"koen.alias2@yahoo.com"));
33 addressBook.push_back(Contact(U"Koen alias3",
34 U"koen.alias3@yahoo.com"));
35 addressBook.push_back(Contact(U"Bartje",
36 U"jafar@hotmail.com"));
37 composer_->setAddressBook(addressBook);
38
39 std::vector<Contact> contacts;
40 contacts.push_back(Contact(U"Koen Deforche", U"koen.deforche@gmail.com"));
41
42 composer_->setTo(contacts);
43 composer_->setSubject("That's cool! Want to start your own google?");
44
45 composer_->send.connect(this, &ComposeExample::send);
47
48 details_ = this->addWidget(std::make_unique<WContainerWidget>());
49
50 details_->addWidget(std::make_unique<WText>(tr("example.info")));
51}
WContainerWidget * details_
Composer * composer_
Wt::Signal send
The message is ready to be sent...
Definition: Composer.h:93
Wt::Signal discard
The message must be discarded.
Definition: Composer.h:97
void setTo(const std::vector< Contact > &to)
Set message To: contacts.
Definition: Composer.C:40
void setSubject(const WString &subject)
Set subject.
Definition: Composer.C:45
void setAddressBook(const std::vector< Contact > &addressBook)
Set the address book, for autocomplete suggestions.
Definition: Composer.C:70
An email contact.
Definition: Contact.h:20

Member Function Documentation

◆ discard()

void ComposeExample::discard ( )
private

Definition at line 126 of file ComposeExample.C.

127{
128 WContainerWidget *feedback = this->addWidget(std::make_unique<WContainerWidget>());
129 feedback->setStyleClass("feedback");
130
131 WContainerWidget *horiz = feedback->addWidget(std::make_unique<WContainerWidget>());
132 horiz->addWidget(std::make_unique<WText>("<p>Wise decision! Everyone's mailbox is already full anyway.</p>"));
133
134 removeWidget(composer_);
135 composer_ = nullptr;
136 removeWidget(details_);
137 details_ = nullptr;
138
139 wApp->quit();
140}

◆ send()

void ComposeExample::send ( )
private

Definition at line 53 of file ComposeExample.C.

54{
55 WContainerWidget *feedback = this->addWidget(std::make_unique<WContainerWidget>());
56 feedback->setStyleClass(U"feedback");
57
58 WContainerWidget *horiz = feedback->addWidget(std::make_unique<WContainerWidget>());
59 horiz->addWidget(std::make_unique<WText>(U"<p>We could have, but did not send the following email:</p>"));
60
61 std::vector<Contact> contacts = composer_->to();
62 if (!contacts.empty())
63 horiz = feedback->addWidget(std::make_unique<WContainerWidget>());
64 for (unsigned i = 0; i < contacts.size(); ++i) {
65 horiz->addWidget(std::make_unique<WText>(U"To: \"" + contacts[i].name + U"\" <"
66 + contacts[i].email + U">", TextFormat::Plain));
67 horiz->addWidget(std::make_unique<WBreak>());
68 }
69
70 contacts = composer_->cc();
71 if (!contacts.empty())
72 horiz = feedback->addWidget(std::make_unique<WContainerWidget>());
73 for (unsigned i = 0; i < contacts.size(); ++i) {
74 horiz->addWidget(std::make_unique<WText>(U"Cc: \"" + contacts[i].name + U"\" <"
75 + contacts[i].email + U">", TextFormat::Plain));
76 horiz->addWidget(std::make_unique<WBreak>());
77 }
78
79 contacts = composer_->bcc();
80 if (!contacts.empty())
81 horiz = feedback->addWidget(std::make_unique<WContainerWidget>());
82 for (unsigned i = 0; i < contacts.size(); ++i) {
83 horiz->addWidget(std::make_unique<WText>(U"Bcc: \"" + contacts[i].name + U"\" <"
84 + contacts[i].email + U">", TextFormat::Plain));
85 horiz->addWidget(std::make_unique<WBreak>());
86 }
87
88 horiz = feedback->addWidget(std::make_unique<WContainerWidget>());
89 horiz->addWidget(std::make_unique<WText>("Subject: \"" + composer_->subject() + "\"", TextFormat::Plain));
90
91 std::vector<Attachment> attachments = composer_->attachments();
92 if (!attachments.empty())
93 horiz = feedback->addWidget(std::make_unique<WContainerWidget>());
94 for (unsigned i = 0; i < attachments.size(); ++i) {
95 horiz->addWidget(std::make_unique<WText>(U"Attachment: \""
96 + attachments[i].fileName
97 + U"\" (" + attachments[i].contentDescription
98 + U")", TextFormat::Plain));
99
100 unlink(attachments[i].spoolFileName.c_str());
101
102 horiz->addWidget(std::make_unique<WText>(", was in spool file: "
103 + attachments[i].spoolFileName));
104 horiz->addWidget(std::make_unique<WBreak>());
105 }
106
107 std::u32string message = composer_->message();
108
109 horiz = feedback->addWidget(std::make_unique<WContainerWidget>());
110 horiz->addWidget(std::make_unique<WText>("Message body: "));
111 horiz->addWidget(std::make_unique<WBreak>());
112
113 if (!message.empty()) {
114 horiz->addWidget(std::make_unique<WText>(message, TextFormat::Plain));
115 } else
116 horiz->addWidget(std::make_unique<WText>("<i>(empty)</i>"));
117
118 removeWidget(composer_);
119 composer_ = nullptr;
120 removeWidget(details_);
121 details_ = nullptr;
122
123 wApp->quit();
124}
std::vector< Contact > bcc() const
Get the Bc: contacts.
Definition: Composer.C:65
const WString & message() const
Get the message.
Definition: Composer.C:93
std::vector< Contact > to() const
Get the To: contacts.
Definition: Composer.C:55
const WString & subject() const
Get the subject.
Definition: Composer.C:75
std::vector< Contact > cc() const
Get the Cc: contacts.
Definition: Composer.C:60
std::vector< Attachment > attachments() const
Get the list of attachments.
Definition: Composer.C:80

Member Data Documentation

◆ composer_

Composer* ComposeExample::composer_
private

Definition at line 35 of file ComposeExample.h.

◆ details_

WContainerWidget* ComposeExample::details_
private

Definition at line 36 of file ComposeExample.h.


The documentation for this class was generated from the following files:

Generated on Fri Jan 28 2022 for the C++ Web Toolkit (Wt) by doxygen 1.9.3