Wt examples 3.1.10
/build/buildd/witty-3.1.10/examples/composer/AddresseeEdit.C
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
00003  *
00004  * See the LICENSE file for terms of use.
00005  */
00006 
00007 #include <boost/tokenizer.hpp>
00008 #include <boost/algorithm/string.hpp>
00009 
00010 #include <Wt/WContainerWidget>
00011 
00012 #include "AddresseeEdit.h"
00013 #include "Label.h"
00014 
00015 AddresseeEdit::AddresseeEdit(const WString& label, WContainerWidget *parent,
00016                              WContainerWidget *labelParent)
00017   : WTextArea(parent)
00018 {
00019   label_ = new Label(label, labelParent);
00020 
00021   setRows(3); setColumns(55);
00022   resize(WLength(99, WLength::Percentage), WLength::Auto);
00023 
00024   setInline(false); // for IE to position the suggestions well
00025 }
00026 
00027 void AddresseeEdit::setAddressees(const std::vector<Contact>& contacts)
00028 {
00029   std::wstring text;
00030 
00031   for (unsigned i = 0; i < contacts.size(); ++i) {
00032     if (i != 0)
00033       text += L", ";
00034     text += contacts[i].formatted();
00035   }
00036 
00037   setText(text);
00038 }
00039 
00040 bool AddresseeEdit::parse(std::vector<Contact>& contacts) const
00041 {
00042   typedef boost::tokenizer<boost::escaped_list_separator<wchar_t>,
00043                            std::wstring::const_iterator, std::wstring>
00044     CsvTokenizer;
00045 
00046   std::wstring t = text();
00047   CsvTokenizer tok(t);
00048   
00049   for (CsvTokenizer::iterator i = tok.begin(); i != tok.end(); ++i) {
00050     std::wstring addressee = *i;
00051 
00052     boost::trim(addressee);
00053     std::wstring::size_type pos = addressee.find_last_of(' ');
00054     if (pos != std::string::npos) {
00055       std::wstring email = addressee.substr(pos + 1);
00056       std::wstring name = addressee.substr(0, pos);
00057 
00058       boost::trim(email);
00059       boost::trim(name);
00060       if (email[0] == '<')
00061         email = email.substr(1);
00062       if (email[email.length() - 1] == '>')
00063         email = email.substr(0, email.length() - 1);
00064 
00065       if (!email.empty())
00066         contacts.push_back(Contact(name, email));
00067     } else
00068       if (!addressee.empty())
00069         contacts.push_back(Contact(L"", addressee));
00070   }
00071   return true;
00072 }
00073 
00074 std::vector<Contact> AddresseeEdit::addressees() const
00075 {
00076   std::vector<Contact> result;
00077   parse(result);
00078 
00079   return result;
00080 }
00081 
00082 void AddresseeEdit::setHidden(bool hidden, const WAnimation& animation)
00083 {
00084   WTextArea::setHidden(hidden, animation);
00085   label_->setHidden(hidden, animation);
00086 }

Generated on Sat Dec 24 2011 for the C++ Web Toolkit (Wt) by doxygen 1.7.4