Debian Codegraph @

plugins/dm.gui/ReadablePopulator.h

raw
1 #pragma once
2
3 #include "gui/GuiManager.h"
4 #include "wxutil/dataview/VFSTreePopulator.h"
5 #include "wxutil/ModalProgressDialog.h"
6 #include "EventRateLimiter.h"
7 #include "i18n.h"
8
9 namespace ui
10 {
11
12 /**
13 * greebo: A helper class sorting GUIs into two given TreePopulators.
14 */
15 class ReadablePopulator :
16 public gui::GuiManager::Visitor
17 {
18 private:
19 wxutil::VFSTreePopulator& _popOne;
20 wxutil::VFSTreePopulator& _popTwo;
21
22 // Progress dialog and model count
23 wxutil::ModalProgressDialog _progress;
24 std::size_t _count;
25 std::size_t _numGuis;
26
27 // Event rate limiter for progress dialog
28 EventRateLimiter _evLimiter;
29
30 public:
31 ReadablePopulator(wxutil::VFSTreePopulator& popOne,
32 wxutil::VFSTreePopulator& popTwo) :
33 _popOne(popOne),
34 _popTwo(popTwo),
35 _progress(_("Analysing Guis")),
36 _count(0),
37 _numGuis(GlobalGuiManager().getNumGuis()),
38 _evLimiter(50)
39 {}
40
41 void visit(const std::string& guiPath, const gui::GuiType& guiType)
42 {
43 _count++;
44
45 if (_evLimiter.readyForEvent())
46 {
47 float fraction = static_cast<float>(_count) / _numGuis;
48 _progress.setTextAndFraction(guiPath.substr(guiPath.rfind('/') + 1), fraction);
49 }
50
51 gui::GuiType type;
52 if (guiType == gui::NOT_LOADED_YET || guiType == gui::UNDETERMINED)
53 {
54 type = GlobalGuiManager().getGuiType(guiPath);
55 }
56 else
57 {
58 type = guiType;
59 }
60
61 if (type == gui::ONE_SIDED_READABLE)
62 {
63 _popOne.addPath(guiPath.substr(guiPath.find('/') + 1)); // omit the guis-folder
64 }
65 else if (type == gui::TWO_SIDED_READABLE)
66 {
67 _popTwo.addPath(guiPath.substr(guiPath.find('/') + 1)); // omit the guis-folder
68 }
69 }
70 };
71
72 } // namespace