2 #include <Wt/WApplication.h> 3 #include <Wt/WPushButton.h> 4 #include <Wt/WContainerWidget.h> 7 #include <Wt/WLineEdit.h> 8 #include <Wt/WComboBox.h> 10 #include <Wt/WFileUpload.h> 11 #include <Wt/WTextArea.h> 12 #include <Wt/WTextEdit.h> 15 #include "AttachmentEditor.h" 18 :
public Wt::WContainerWidget
31 Wt::WLineEdit * m_fromEdit;
32 Wt::WLineEdit * m_subjectEdit;
36 Wt::WComboBox * recipientType;
37 Wt::WLineEdit * emailAddress;
42 std::vector< RecipientEditor > m_recipientEditors;
50 void addAttachmentEditor();
51 std::vector< AttachmentEditor > m_attachmentEditors;
57 Wt::WTextArea * m_body;
59 Wt::Signal<> m_discard;
63 DetailForm::DetailForm()
64 : Wt::WContainerWidget()
66 setStyleClass(
"darker" );
67 setOverflow( Wt::Overflow::Auto );
69 auto _controlButtons = [=]()
71 auto cw = addNew< Wt::WContainerWidget >();
74 auto pbSend = cw-> addNew< Wt::WPushButton >( Wt::WString::tr(
"wtx.eml.composer.send" ) );
75 pbSend-> setStyleClass(
"default btn-xs" );
76 pbSend-> clicked().connect( [=](){ m_send.emit(); } );
78 auto pbSave = cw-> addNew< Wt::WPushButton >( Wt::WString::tr(
"wtx.eml.composer.savenow" ) );
79 pbSave-> setStyleClass(
"btn-xs" );
80 pbSave-> clicked().connect(
this, &DetailForm::do_save );
82 auto pbDiscard = cw-> addNew< Wt::WPushButton >( Wt::WString::tr(
"wtx.eml.composer.discard" ) );
83 pbDiscard-> setStyleClass(
"btn-xs" );
84 pbDiscard-> clicked().connect( [=](){ m_discard.emit(); } );
91 m_table = addNew< Wt::WTable >();
93 m_body = addNew< Wt::WTextEdit >();
95 m_body-> setHeight(
"200px" );
103 void DetailForm::loadMessage()
106 m_recipientEditors.clear();
110 m_table-> setStyleClass(
"lighter" );
111 m_table-> resize( Wt::WLength( 100, Wt::LengthUnit::Percentage ), Wt::WLength::Auto );
112 m_table-> elementAt( row, 0 )-> resize( Wt::WLength( 1, Wt::LengthUnit::Percentage ), Wt::WLength::Auto );
114 m_table-> elementAt( row, 0 )-> addNew< Wt::WText >( Wt::WString::tr(
"wtx.eml.composer.from" ) );
115 m_fromEdit = m_table-> elementAt( row, 1 )-> addNew< Wt::WLineEdit >();
116 m_fromEdit-> setText( m_message.from().displayName() +
" <" + m_message.from().address() +
">" );
117 m_fromEdit-> setReadOnly(
true );
119 for(
auto recipient : m_message.recipients() )
121 auto recipientEditor = addRecipientEditor();
122 recipientEditor.emailAddress-> setValueText( recipient.mailbox.address() );
125 addRecipientEditor();
127 row = m_table-> rowCount();
128 m_table-> elementAt( row, 0 )-> addNew< Wt::WText >( Wt::WString::tr(
"wtx.eml.composer.subject" ) );
129 m_subjectEdit = m_table-> elementAt( row, 1 )-> addNew< Wt::WLineEdit >();
130 m_subjectEdit-> setValueText( m_message.subject() );
132 for(
auto attachment : m_message.attachments() )
134 int row = m_table-> rowCount();
135 m_table-> elementAt( row, 0 )-> addNew< Wt::WImage >(
"resources/icons/paperclip.png" );
136 m_table-> elementAt( row, 0 )-> setContentAlignment( Wt::AlignmentFlag::Right | Wt::AlignmentFlag::Top );
137 m_table-> elementAt( row, 0 )-> setPadding( 3 );
140 m_table-> elementAt( row, 1 )-> addNew< Wt::WText >( attachment.fileName );
143 addAttachmentEditor();
151 auto retVal = std::make_unique< Wt::WComboBox >();
153 retVal-> addItem( Wt::WString::tr(
"wtx.eml.composer.to" ) );
154 retVal-> addItem( Wt::WString::tr(
"wtx.eml.composer.cc" ) );
155 retVal-> addItem( Wt::WString::tr(
"wtx.eml.composer.bcc" ) );
161 for(
auto recipientEditor : m_recipientEditors )
162 if( row < recipientEditor.row )
163 row = recipientEditor.row;
166 m_table-> insertRow( row );
169 editor.recipientType = m_table-> elementAt( row, 0 )-> addWidget( _tcb() );
170 editor.emailAddress = m_table-> elementAt( row, 1 )-> addNew< Wt::WLineEdit >();
173 m_recipientEditors.push_back( editor );
175 return m_recipientEditors.at( m_recipientEditors.size()-1 );
179 void DetailForm::addAttachmentEditor()
181 int row = m_table-> rowCount();
182 m_table-> elementAt( row, 0 )-> addNew< Wt::WImage >(
"resources/icons/paperclip.png" );
183 m_table-> elementAt( row, 0 )-> setContentAlignment( Wt::AlignmentFlag::Right | Wt::AlignmentFlag::Top );
184 m_table-> elementAt( row, 0 )-> setPadding( 3 );
185 auto editor = m_table-> elementAt( row, 1 )-> addNew< Wtx::Eml::AttachmentEditor >( m_attachmentEditors.size() );
188 attachmentEditor.editor = editor;
189 attachmentEditor.row = row;
190 m_attachmentEditors.push_back( attachmentEditor );
192 editor-> attached().connect( [=]()
194 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << row << std::endl;
196 addAttachmentEditor();
199 editor-> removed().connect( [=]()
201 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << row << std::endl;
215 void DetailForm::do_save()
217 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << std::endl;
221 void DetailForm::do_attach()
223 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << std::endl;
232 Wtx::Eml::Composer::Composer()
234 m_impl = setImplementation( std::make_unique< DetailForm >() );
237 #ifdef DONT_USE_THIS_IT_DOESNT_WORK 238 Wtx::Eml::Composer::Composer(
const Wt::Mail::Message & message )
240 auto u_impl = std::make_unique< DetailForm >();
241 u_impl-> setMessage( message );
243 wApp-> processEvents();
245 m_impl = setImplementation( std::move( u_impl ) );
253 return dynamic_cast< DetailForm*
>( m_impl )-> m_message;
258 dynamic_cast< DetailForm*
>( m_impl )-> setMessage( message );
261 Wt::Signal<> & Wtx::Eml::Composer::send()
263 return dynamic_cast< DetailForm*
>( m_impl )-> m_send;
266 Wt::Signal<> & Wtx::Eml::Composer::discard()
268 return dynamic_cast< DetailForm*
>( m_impl )-> m_discard;