00001
00002
00003
00004
00005
00006
00007 #include <WApplication>
00008 #include <WBreak>
00009 #include <WText>
00010 #include <WPushButton>
00011 #include <WContainerWidget>
00012 #include <WStringUtil>
00013 #ifndef WIN32
00014 #include <unistd.h>
00015 #endif
00016
00017 #include "Composer.h"
00018 #include "ComposeExample.h"
00019 #include "Contact.h"
00020
00021 ComposeExample::ComposeExample(WContainerWidget *parent)
00022 : WContainerWidget(parent)
00023 {
00024 composer_ = new Composer(this);
00025
00026 std::vector<Contact> addressBook;
00027 addressBook.push_back(Contact(L"Koen Deforche",
00028 L"koen.deforche@gmail.com"));
00029 addressBook.push_back(Contact(L"Koen alias1",
00030 L"koen.alias1@yahoo.com"));
00031 addressBook.push_back(Contact(L"Koen alias2",
00032 L"koen.alias2@yahoo.com"));
00033 addressBook.push_back(Contact(L"Koen alias3",
00034 L"koen.alias3@yahoo.com"));
00035 addressBook.push_back(Contact(L"Bartje",
00036 L"jafar@hotmail.com"));
00037 composer_->setAddressBook(addressBook);
00038
00039 std::vector<Contact> contacts;
00040 contacts.push_back(Contact(L"Koen Deforche", L"koen.deforche@gmail.com"));
00041
00042 composer_->setTo(contacts);
00043 composer_->setSubject("That's cool! Want to start your own google?");
00044
00045 composer_->send.connect(SLOT(this, ComposeExample::send));
00046 composer_->discard.connect(SLOT(this, ComposeExample::discard));
00047
00048 details_ = new WContainerWidget(this);
00049
00050 new WText(tr("example.info"), details_);
00051 }
00052
00053 void ComposeExample::send()
00054 {
00055 WContainerWidget *feedback = new WContainerWidget(this);
00056 feedback->setStyleClass(L"feedback");
00057
00058 WContainerWidget *horiz = new WContainerWidget(feedback);
00059 new WText(L"<p>We could have, but did not send the following email:</p>",
00060 horiz);
00061
00062 std::vector<Contact> contacts = composer_->to();
00063 if (!contacts.empty())
00064 horiz = new WContainerWidget(feedback);
00065 for (unsigned i = 0; i < contacts.size(); ++i) {
00066 WText *t = new WText(L"To: \"" + contacts[i].name + L"\" <"
00067 + contacts[i].email + L">", horiz);
00068 t->setFormatting(WText::PlainFormatting);
00069 new WBreak(horiz);
00070 }
00071
00072 contacts = composer_->cc();
00073 if (!contacts.empty())
00074 horiz = new WContainerWidget(feedback);
00075 for (unsigned i = 0; i < contacts.size(); ++i) {
00076 WText *t = new WText(L"Cc: \"" + contacts[i].name + L"\" <"
00077 + contacts[i].email + L">", horiz);
00078 t->setFormatting(WText::PlainFormatting);
00079 new WBreak(horiz);
00080 }
00081
00082 contacts = composer_->bcc();
00083 if (!contacts.empty())
00084 horiz = new WContainerWidget(feedback);
00085 for (unsigned i = 0; i < contacts.size(); ++i) {
00086 WText *t = new WText(L"Bcc: \"" + contacts[i].name + L"\" <"
00087 + contacts[i].email + L">", horiz);
00088 t->setFormatting(WText::PlainFormatting);
00089 new WBreak(horiz);
00090 }
00091
00092 horiz = new WContainerWidget(feedback);
00093 WText *t = new WText("Subject: \"" + composer_->subject() + "\"", horiz);
00094 t->setFormatting(WText::PlainFormatting);
00095
00096 std::vector<Attachment> attachments = composer_->attachments();
00097 if (!attachments.empty())
00098 horiz = new WContainerWidget(feedback);
00099 for (unsigned i = 0; i < attachments.size(); ++i) {
00100 WText *t = new WText(L"Attachment: \""
00101 + attachments[i].fileName
00102 + L"\" (" + attachments[i].contentDescription
00103 + L")", horiz);
00104 t->setFormatting(WText::PlainFormatting);
00105
00106 unlink(attachments[i].spoolFileName.c_str());
00107
00108 t = new WText(", was in spool file: "
00109 + attachments[i].spoolFileName, horiz);
00110 new WBreak(horiz);
00111 }
00112
00113 std::wstring message = composer_->message();
00114
00115 horiz = new WContainerWidget(feedback);
00116 t = new WText("Message body: ", horiz);
00117 new WBreak(horiz);
00118
00119 if (!message.empty()) {
00120 t = new WText(message, horiz);
00121 t->setFormatting(WText::PlainFormatting);
00122 } else
00123 t = new WText("<i>(empty)</i>", horiz);
00124
00125 delete composer_;
00126 delete details_;
00127
00128 wApp->quit();
00129 }
00130
00131 void ComposeExample::discard()
00132 {
00133 WContainerWidget *feedback = new WContainerWidget(this);
00134 feedback->setStyleClass("feedback");
00135
00136 WContainerWidget *horiz = new WContainerWidget(feedback);
00137 new WText("<p>Wise decision! Everyone's mailbox is already full anyway.</p>",
00138 horiz);
00139
00140 delete composer_;
00141 delete details_;
00142
00143 wApp->quit();
00144 }
00145
00146 WApplication *createApplication(const WEnvironment& env)
00147 {
00148 WApplication *app = new WApplication(env);
00149 app->messageResourceBundle().use("composer");
00150 app->setTitle("Composer example");
00151 app->useStyleSheet("composer.css");
00152
00153 app->root()->addWidget(new ComposeExample());
00154
00155 return app;
00156 }
00157
00158 int main(int argc, char **argv)
00159 {
00160 return WRun(argc, argv, &createApplication);
00161 }
00162