Wt examples
3.2.3
|
00001 /* 00002 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium. 00003 * 00004 * See the LICENSE file for terms of use. 00005 */ 00006 00007 #include <Wt/WApplication> 00008 #include <Wt/WBreak> 00009 #include <Wt/WText> 00010 #include <Wt/WPushButton> 00011 #include <Wt/WContainerWidget> 00012 #include <Wt/WStringUtil> 00013 #ifndef _MSC_VER 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(this, &ComposeExample::send); 00046 composer_->discard.connect(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 new WText(L"To: \"" + contacts[i].name + L"\" <" 00067 + contacts[i].email + L">", PlainText, horiz); 00068 new WBreak(horiz); 00069 } 00070 00071 contacts = composer_->cc(); 00072 if (!contacts.empty()) 00073 horiz = new WContainerWidget(feedback); 00074 for (unsigned i = 0; i < contacts.size(); ++i) { 00075 new WText(L"Cc: \"" + contacts[i].name + L"\" <" 00076 + contacts[i].email + L">", PlainText, horiz); 00077 new WBreak(horiz); 00078 } 00079 00080 contacts = composer_->bcc(); 00081 if (!contacts.empty()) 00082 horiz = new WContainerWidget(feedback); 00083 for (unsigned i = 0; i < contacts.size(); ++i) { 00084 new WText(L"Bcc: \"" + contacts[i].name + L"\" <" 00085 + contacts[i].email + L">", PlainText, horiz); 00086 new WBreak(horiz); 00087 } 00088 00089 horiz = new WContainerWidget(feedback); 00090 WText *t = new WText("Subject: \"" + composer_->subject() + "\"", 00091 PlainText, horiz); 00092 00093 std::vector<Attachment> attachments = composer_->attachments(); 00094 if (!attachments.empty()) 00095 horiz = new WContainerWidget(feedback); 00096 for (unsigned i = 0; i < attachments.size(); ++i) { 00097 new WText(L"Attachment: \"" 00098 + attachments[i].fileName 00099 + L"\" (" + attachments[i].contentDescription 00100 + L")", PlainText, horiz); 00101 00102 unlink(attachments[i].spoolFileName.c_str()); 00103 00104 new WText(", was in spool file: " 00105 + attachments[i].spoolFileName, horiz); 00106 new WBreak(horiz); 00107 } 00108 00109 std::wstring message = composer_->message(); 00110 00111 horiz = new WContainerWidget(feedback); 00112 t = new WText("Message body: ", horiz); 00113 new WBreak(horiz); 00114 00115 if (!message.empty()) { 00116 t = new WText(message, PlainText, horiz); 00117 } else 00118 t = new WText("<i>(empty)</i>", horiz); 00119 00120 delete composer_; 00121 delete details_; 00122 00123 wApp->quit(); 00124 } 00125 00126 void ComposeExample::discard() 00127 { 00128 WContainerWidget *feedback = new WContainerWidget(this); 00129 feedback->setStyleClass("feedback"); 00130 00131 WContainerWidget *horiz = new WContainerWidget(feedback); 00132 new WText("<p>Wise decision! Everyone's mailbox is already full anyway.</p>", 00133 horiz); 00134 00135 delete composer_; 00136 delete details_; 00137 00138 wApp->quit(); 00139 } 00140 00141 WApplication *createApplication(const WEnvironment& env) 00142 { 00143 WApplication *app = new WApplication(env); 00144 00145 // The following assumes composer.xml is in the webserver working directory 00146 // (but does not need to be deployed within docroot): 00147 app->messageResourceBundle().use(WApplication::appRoot() + "composer"); 00148 00149 // The following assumes composer.css is deployed in the seb server at the 00150 // same location as the application: 00151 app->useStyleSheet("composer.css"); 00152 00153 app->setTitle("Composer example"); 00154 00155 app->root()->addWidget(new ComposeExample()); 00156 00157 return app; 00158 } 00159 00160 int main(int argc, char **argv) 00161 { 00162 return WRun(argc, argv, &createApplication); 00163 } 00164