/usr/lib/Wt/examples/composer/AddresseeEdit.C is in witty-examples 3.3.0-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | /*
* Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string.hpp>
#include <Wt/WContainerWidget>
#include "AddresseeEdit.h"
#include "Label.h"
AddresseeEdit::AddresseeEdit(const WString& label, WContainerWidget *parent,
WContainerWidget *labelParent)
: WTextArea(parent)
{
label_ = new Label(label, labelParent);
setRows(3); setColumns(55);
resize(WLength(99, WLength::Percentage), WLength::Auto);
setInline(false); // for IE to position the suggestions well
}
void AddresseeEdit::setAddressees(const std::vector<Contact>& contacts)
{
std::wstring text;
for (unsigned i = 0; i < contacts.size(); ++i) {
if (i != 0)
text += L", ";
text += contacts[i].formatted();
}
setText(text);
}
bool AddresseeEdit::parse(std::vector<Contact>& contacts) const
{
typedef boost::tokenizer<boost::escaped_list_separator<wchar_t>,
std::wstring::const_iterator, std::wstring>
CsvTokenizer;
std::wstring t = text();
CsvTokenizer tok(t);
for (CsvTokenizer::iterator i = tok.begin(); i != tok.end(); ++i) {
std::wstring addressee = *i;
boost::trim(addressee);
std::wstring::size_type pos = addressee.find_last_of(' ');
if (pos != std::string::npos) {
std::wstring email = addressee.substr(pos + 1);
std::wstring name = addressee.substr(0, pos);
boost::trim(email);
boost::trim(name);
if (email[0] == '<')
email = email.substr(1);
if (email[email.length() - 1] == '>')
email = email.substr(0, email.length() - 1);
if (!email.empty())
contacts.push_back(Contact(name, email));
} else
if (!addressee.empty())
contacts.push_back(Contact(L"", addressee));
}
return true;
}
std::vector<Contact> AddresseeEdit::addressees() const
{
std::vector<Contact> result;
parse(result);
return result;
}
void AddresseeEdit::setHidden(bool hidden, const WAnimation& animation)
{
WTextArea::setHidden(hidden, animation);
label_->setHidden(hidden, animation);
}
|