Wtx ~ Wt Extension Library
WtxLib
AttachmentEditor.cpp
1 
2 #include <Wt/WText.h>
3 #include <Wt/WPushButton.h>
4 
5 #include "AttachmentEditor.h"
6 
7 Wtx::Eml::AttachmentEditor::AttachmentEditor( int count )
8 : Wt::WContainerWidget()
9 {
10  Wt::WText * text;
11 
12  if( count == 0 )
13  text = addNew< Wt::WText >( Wt::WString::tr("wtx.eml.composer.attachfile") );
14  else
15  text = addNew< Wt::WText >( Wt::WString::tr("wtx.eml.composer.attachanother") );
16 
17  text-> setAttributeValue( "style", "text-decoration: underline" );
18  text-> clicked().connect( this, &Wtx::Eml::AttachmentEditor::do_upload );
19 
20 }
21 
22 Wtx::Eml::AttachmentEditor::AttachmentEditor( const std::string & fileName )
23 {
24 }
25 
26 Wt::Signal<> & Wtx::Eml::AttachmentEditor::attached()
27 {
28  return m_attached;
29 }
30 
31 Wt::Signal<> & Wtx::Eml::AttachmentEditor::removed()
32 {
33  return m_removed;
34 }
35 
36 void Wtx::Eml::AttachmentEditor::do_upload()
37 {
38  clear();
39 
40  m_fileUpload = addNew< Wt::WFileUpload >();
41 
42  /*
43  * React to events.
44  */
45 
46  // Try to catch the fileupload change signal to trigger an upload.
47  // We could do like google and at a delay with a WTimer as well...
48  m_fileUpload-> changed().connect( m_fileUpload, &Wt::WFileUpload::upload );
49 
50  // React to a succesfull upload.
51  m_fileUpload-> uploaded().connect( this, &Wtx::Eml::AttachmentEditor::do_uploaded );
52 
53  // React to a fileupload problem.
54  m_fileUpload-> fileTooLarge().connect( this, &Wtx::Eml::AttachmentEditor::do_fileTooLarge );
55 
56  /*
57  * Connect the uploadDone signal to the Composer's attachmentDone,
58  * so that the Composer can keep track of attachment upload progress,
59  * if it wishes.
60  */
61 // uploadDone_.connect(composer, &Composer::attachmentDone);
62 
63 } // endvoid Wtx::Eml::AttachmentEditor::do_upload()
64 
65 void Wtx::Eml::AttachmentEditor::do_uploaded()
66 {
67 
68  std::vector< std::string > files;
69 
70  for( auto uploadedFile : m_fileUpload-> uploadedFiles() )
71  {
72  std::cout << __FILE__ << ":" << __LINE__
73  << " " << uploadedFile.spoolFileName()
74  << " " << uploadedFile.clientFileName()
75  << std::endl;
76 
77  files.push_back( uploadedFile.clientFileName() );
78 
79  }
80 
81  clear();
82 
83  for( auto file : files )
84  {
85  auto pbRemove = addNew< Wt::WPushButton >( "X" );
86  addNew< Wt::WText >( file );
87 
88  pbRemove-> setStyleClass( "btn-xs" );
89  pbRemove-> clicked().connect( this, &Wtx::Eml::AttachmentEditor::do_removed );
90 
91  }
92 
93  m_attached.emit();
94 
95 } // endvoid Wtx::Eml::AttachmentEditor::do_uploaded()
96 
97 void Wtx::Eml::AttachmentEditor::do_fileTooLarge()
98 {
99  std::cout << __FILE__ << ":" << __LINE__ << " " << std::endl;
100 
101 }
102 
103 void Wtx::Eml::AttachmentEditor::do_removed()
104 {
105  m_removed.emit();
106 }
107 
std::u32string fileName
The file name.
Definition: Attachment.h:24