Lumiera  0.pre.03
»edit your freedom«
notification-hub.hpp
Go to the documentation of this file.
1 /*
2  NOTIFICATION-HUB.hpp - receive and reroute notification messages
3 
4  Copyright (C) Lumiera.org
5  2018, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
62 #ifndef STAGE_CTRL_NOTIFICATION_HUB_H
63 #define STAGE_CTRL_NOTIFICATION_HUB_H
64 
68 #include "stage/model/w-link.hpp"
69 
70 #include <functional>
71 
72 
73 namespace stage {
74 namespace ctrl {
75 
77  using model::WLink;
78 
79 
80 
81 
89  : public model::Controller
90  {
91 
92 
94  void
96  {
97  buffer.emplace(
99  );
100  UNIMPLEMENTED ("define and implement what need to be reflected from asset::ErrorLog");
101  }
102 
103 
104  /* ==== Tangible interface ==== */
105 
106  virtual bool
107  doReset() override
108  {
109  if (not widget_) return false;
110 
111  widget_->clearAll();
112  widget_->expand (false);
113  return true;
114  }
115 
116  virtual bool
117  doMsg (string text) override
118  {
119  getWidget().addInfo (text);
120  return false; // logging is no persistent state
121  }
122 
123  virtual bool
124  doClearMsg () override
125  {
126  if (widget_)
127  widget_->clearInfoMsg();
128  return false; // not persistent (sticky)
129  }
130 
131  virtual bool
132  doErr (string text) override
133  {
134  getWidget().addError (text);
135  return false;
136  }
137 
138  virtual bool
139  doClearErr () override
140  {
141  if (widget_)
142  widget_->turnError_into_InfoMsg();
143  return false; // not persistent (sticky)
144  }
145 
147  virtual void
148  doMark (GenNode const& stateMark) override
149  {
150  if (stateMark.idi.getSym() == MARK_Warning)
151  getWidget().addWarn (stateMark.data.get<string>());
152  else
153  // forward to default handler
154  Controller::doMark (stateMark);
155  }
156 
157  virtual void
158  doFlash() override
159  {
160  if (not widget_) return;
161  widget_->reveal();
162  widget_->triggerFlash();
163  }
164 
165 
166  public:
167  using WidgetAllocator = std::function<widget::ErrorLogDisplay&(void)>;
168 
169 
170  NotificationHub (ID identity, ctrl::BusTerm& nexus, WidgetAllocator wa)
171  : model::Controller{identity, nexus}
172  , allocateWidget_{wa}
173  , widget_{}
174  {
175  installExpander([&](){ return widget_ and widget_->expand; }
176  ,[&](bool yes)
177  {
178  if (widget_ or yes)
179  getWidget().expand (yes);
180  }
181  );
182  installRevealer([&](){ getWidget().reveal(); }); // implementation implies also expand
183  }
184 
186 
187 
188  private:
190  WidgetAllocator allocateWidget_;
191 
194 
195 
197  getWidget()
198  {
199  if (not widget_)
200  widget_.connect (allocateWidget_());
201  return *widget_;
202  }
203  };
204 
205 
206 
207 }}// namespace stage::ctrl
208 #endif /*STAGE_CTRL_NOTIFICATION_HUB_H*/
void addError(string text)
present an error notification prominently.
connection point at the UI-Bus.
Definition: bus-term.hpp:105
void addInfo(string text)
just add normal information message to buffer, without special markup and without expanding the widge...
void installRevealer(Revealer::RevealeItFun)
Configure the (optional) functionality to bring the UI-Element into sight.
Definition: tangible.hpp:297
void addWarn(string text)
add an information message, formatted more prominent as warning
virtual void doMark(GenNode const &stateMark) override
adds special treatment for a state mark tagged as "Warning"
void buildMutator(lib::diff::TreeMutator::Handle buffer) override
population and manipulation of persistent content via UI-Bus
static Builder< TreeMutator > build()
DSL: start building a custom adapted tree mutator, where the operations are tied by closures or wrapp...
SUB & emplace(SUB &&implementation)
move-construct an instance of a subclass into the opaque buffer
A handle to allow for safe »remote implantation« of an unknown subclass into a given opaque InPlaceBu...
Definition: record.hpp:113
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
Widget to display error messages to be accessible in non-modal way.
Service to receive and display error, warning and notification messages.
void installExpander(Expander::ProbeFun, Expander::ChangeFun)
Configure the (optional) functionality to expand or collapse the UI-Element.
Definition: tangible.hpp:282
Customisable intermediary to abstract generic tree mutation operations.
Widget to display log and error messages.
WLink< widget::ErrorLogDisplay > widget_
collaboration with a log display allocated elsewhere
Common Abstraction of all sub-controller, coordinated by the UI-Bus.
generic data element node within a tree
Definition: gen-node.hpp:231
WidgetAllocator allocateWidget_
external operation to find or allocate an log display widget
Customisable intermediary to abstract mutating operations on arbitrary, hierarchical object-like data...