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)
5  2018, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
53 #ifndef STAGE_CTRL_NOTIFICATION_HUB_H
54 #define STAGE_CTRL_NOTIFICATION_HUB_H
55 
59 #include "stage/model/w-link.hpp"
60 
61 #include <functional>
62 
63 
64 namespace stage {
65 namespace ctrl {
66 
68  using model::WLink;
69 
70 
71 
72 
80  : public model::Controller
81  {
82 
83 
85  void
87  {
88  buffer.emplace(
90  );
91  UNIMPLEMENTED ("define and implement what need to be reflected from asset::ErrorLog");
92  }
93 
94 
95  /* ==== Tangible interface ==== */
96 
97  virtual bool
98  doReset() override
99  {
100  if (not widget_) return false;
101 
102  widget_->clearAll();
103  widget_->expand (false);
104  return true;
105  }
106 
107  virtual bool
108  doMsg (string text) override
109  {
110  getWidget().addInfo (text);
111  return false; // logging is no persistent state
112  }
113 
114  virtual bool
115  doClearMsg () override
116  {
117  if (widget_)
118  widget_->clearInfoMsg();
119  return false; // not persistent (sticky)
120  }
121 
122  virtual bool
123  doErr (string text) override
124  {
125  getWidget().addError (text);
126  return false;
127  }
128 
129  virtual bool
130  doClearErr () override
131  {
132  if (widget_)
133  widget_->turnError_into_InfoMsg();
134  return false; // not persistent (sticky)
135  }
136 
138  virtual void
139  doMark (GenNode const& stateMark) override
140  {
141  if (stateMark.idi.getSym() == MARK_Warning)
142  getWidget().addWarn (stateMark.data.get<string>());
143  else
144  // forward to default handler
145  Controller::doMark (stateMark);
146  }
147 
148  virtual void
149  doFlash() override
150  {
151  if (not widget_) return;
152  widget_->reveal();
153  widget_->triggerFlash();
154  }
155 
156 
157  public:
158  using WidgetAllocator = std::function<widget::ErrorLogDisplay&(void)>;
159 
160 
161  NotificationHub (ID identity, ctrl::BusTerm& nexus, WidgetAllocator wa)
162  : model::Controller{identity, nexus}
163  , allocateWidget_{wa}
164  , widget_{}
165  {
166  installExpander([&](){ return widget_ and widget_->expand; }
167  ,[&](bool yes)
168  {
169  if (widget_ or yes)
170  getWidget().expand (yes);
171  }
172  );
173  installRevealer([&](){ getWidget().reveal(); }); // implementation implies also expand
174  }
175 
177 
178 
179  private:
181  WidgetAllocator allocateWidget_;
182 
185 
186 
188  getWidget()
189  {
190  if (not widget_)
191  widget_.connect (allocateWidget_());
192  return *widget_;
193  }
194  };
195 
196 
197 
198 }}// namespace stage::ctrl
199 #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:96
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:288
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:104
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:37
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:273
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:222
WidgetAllocator allocateWidget_
external operation to find or allocate an log display widget
Customisable intermediary to abstract mutating operations on arbitrary, hierarchical object-like data...