Wtx ~ Wt Extension Library
WtxLib
ManagerWidget.cpp
1 
2 #include <Wt/WText.h>
3 #include <Wt/WTree.h>
4 #include <Wt/WTreeNode.h>
5 #include <Wt/WHBoxLayout.h>
6 #include <Wt/WVBoxLayout.h>
7 
8 #include <Wtx/Util/Util.h>
9 
10 #include "ManagerWidget.h"
11 
12 namespace {
13 
14 class FolderView
15 : public Wt::WContainerWidget
16 {
17  public:
18 
19  class Node
20  : public Wt::WTreeNode
21  {
22  public:
23 
24  Node( const std::string & label );
25 
26  protected:
27 
28  private:
29 
30  };
31 
32  FolderView( Wtx::Eml::Service::Account * account );
33 
34  Wtx::Eml::Service::Account * account();
35  Node * rootNode();
36 
37  Wtx::Eml::Service::Account * m_account;
38  Wt::WTree * m_tree;
39  Node * m_rootNode;
40 
41 };
42 
43 FolderView::Node::Node( const std::string & lbl )
44 : Wt::WTreeNode()
45 {
46  auto folderIcon =
47  std::make_unique<Wt::WIconPair>
48  (
49  "resources/icons/yellow-folder-closed.png",
50  "resources/icons/yellow-folder-open.png",
51  false
52  );
53 
54  setLabelIcon( std::move( folderIcon ) );
55  label()-> setTextFormat( Wt::TextFormat::Plain );
56  label()-> setWordWrap(false);
57  label()-> setText( lbl );
58  setStyleClass("linkstyle");
59  setLoadPolicy( Wt::ContentLoading::NextLevel );
60 
61 }
62 
63 FolderView::FolderView( Wtx::Eml::Service::Account * acct )
64 : m_account(acct)
65 {
66  auto u_hlw = std::make_unique< Wt::WHBoxLayout >();
67  auto hlw = u_hlw.get();
68  setLayout( std::move( u_hlw ) );
69  hlw-> setContentsMargins( 0,0,0,0 );
70 
71  auto u_tree = std::make_unique< Wt::WTree >();
72  m_tree = u_tree.get();
73  hlw-> addWidget( std::move( u_tree ), 1 );
74 
75  auto u_rootNode = std::make_unique< FolderView::Node >( account()-> name() );
76  m_rootNode = u_rootNode.get();
77  m_tree-> setTreeRoot( std::move(u_rootNode) );
78 
79  auto inbox = rootNode()-> addChildNode( std::make_unique< FolderView::Node >( "Inbox" ) );
80 
81  auto drafts = inbox-> addChildNode( std::make_unique< FolderView::Node > ( "Drafts" ) );
82  auto sent = inbox-> addChildNode( std::make_unique< FolderView::Node > ( "Sent" ) );
83  auto archives = inbox-> addChildNode( std::make_unique< FolderView::Node > ( "Archives" ) );
84  auto junk = inbox-> addChildNode( std::make_unique< FolderView::Node > ( "Junk" ) );
85  auto deleted = inbox-> addChildNode( std::make_unique< FolderView::Node > ( "Deleted" ) );
86  auto scam = inbox-> addChildNode( std::make_unique< FolderView::Node > ( "Scam" ) );
87 
88  for( int i=2005; i < 2020; i++ )
89  archives-> addChildNode( std::make_unique< FolderView::Node >( Wtx::itos(i) ) );
90 
91  rootNode()-> expand();
92 
93 }
94 
95 Wtx::Eml::Service::Account * FolderView::account()
96 {
97  return m_account;
98 }
99 
100 FolderView::Node * FolderView::rootNode()
101 {
102  return m_rootNode;
103 }
104 
105 
106 
107 
108 
109 class Widget
110 : public Wt::WContainerWidget
111 {
112  public:
113 
114  Widget( std::unique_ptr< Wtx::Eml::Service::Manager > sm );
115 
116  Wtx::Eml::Service::Manager * manager();
117 
118  std::unique_ptr< Wtx::Eml::Service::Manager > m_manager;
119 
120 };
121 
122 Widget::Widget( std::unique_ptr< Wtx::Eml::Service::Manager > sm )
123 : Wt::WContainerWidget(),
124  m_manager( std::move(sm) )
125 {
126  auto u_lw = std::make_unique< Wt::WVBoxLayout >();
127  auto lw = u_lw.get();
128  setLayout( std::move( u_lw ) );
129  lw-> setContentsMargins( 0,0,0,0 );
130 
131  for( auto emlAccount : manager()-> accounts() )
132  {
133  std::cout << __FILE__ << ":" << __LINE__
134  << " " << emlAccount-> name()
135  << std::endl
136  ;
137 
138  auto u_view = std::make_unique< FolderView >( emlAccount );
139  lw-> addWidget( std::move( u_view ) );
140 
141  }
142 
143 
144 #ifdef NEVER
145  auto u_productView = std::make_unique< Mrp::Product::ManagerWidget >();
146  auto productView = u_productView.get();
147  hlw-> addWidget( std::move(u_productView) );
148 
149  auto u_inventoryView = std::make_unique< Mrp::Inventory::ManagerWidget >();
150  auto inventoryView = u_inventoryView.get();
151  hlw-> addWidget( std::move(u_inventoryView) );
152 
153  auto u_cw = std::make_unique<Wt::WContainerWidget>();
154  auto cw = u_cw.get();
155  hlw-> addWidget( std::move(u_cw) );
156 
157  auto u_vlw = std::make_unique<Wt::WVBoxLayout>();
158  auto vlw = u_vlw.get();
159  cw-> setLayout( std::move(u_vlw) );
160 
161  auto u_inboundView = std::make_unique< Mrp::Inbound::ManagerWidget >();
162  auto inboundView = u_inboundView.get();
163  vlw-> addWidget( std::move(u_inboundView) );
164 
165  auto u_outboundView = std::make_unique< Mrp::Outbound::ManagerWidget >();
166  auto outboundView = u_outboundView.get();
167  vlw-> addWidget( std::move(u_outboundView) );
168 
169  productView-> itemClicked().connect( [=]( Wt::Dbo::ptr<Mrp::Product::Item> item )
170  {
171  inventoryView-> setFor( item );
172  });
173 
174  inventoryView-> itemClicked().connect( [=]( Wt::Dbo::ptr<Mrp::Inventory::Item> item )
175  {
176  inboundView-> setFor( item );
177  outboundView-> setFor( item );
178  });
179 #endif
180 
181 } // endWidget::Widget( std::unique_ptr< Wtx::Eml::Service::Manager > sm )
182 
183 
184 Wtx::Eml::Service::Manager * Widget::manager()
185 {
186  return m_manager.get();
187 }
188 
189 } // endnamespace {
190 
191 
192 
193 
194 
195 
196 
197 
198 
199 
200 Wtx::Eml::ManagerWidget::ManagerWidget( std::unique_ptr< Wtx::Eml::Service::Manager > sm )
201 : Wt::WContainerWidget()
202 {
203  auto layout = std::make_unique< Wt::WHBoxLayout >();
204  layout-> setContentsMargins( 0,0,0,0 );
205 
206  layout-> addWidget( std::make_unique<Widget>( std::move(sm) ) );
207 
208  setLayout( std::move( layout ) );
209 }
210 
std::string itos(int value)
Convert an Integer to a String.
Definition: Util.cpp:311