1 /*
2  status_bar_presenter.cpp     MindForger thinking notebook
3 
4  Copyright (C) 2016-2020 Martin Dvorak <martin.dvorak@mindforger.com>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  as published by the Free Software Foundation; either version 2
9  of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "status_bar_presenter.h"
20 
21 using namespace std;
22 
23 namespace m8r {
24 
StatusBarPresenter(const StatusBarView * view,Mind * mind)25 StatusBarPresenter::StatusBarPresenter(const StatusBarView* view, Mind* mind)
26     : view(view), mind(mind)
27 {
28 }
29 
showInfo(const QString & message)30 void StatusBarPresenter::showInfo(const QString& message)
31 {
32     view->showInfo(message);
33 }
34 
showWarning(const QString & message)35 void StatusBarPresenter::showWarning(const QString& message)
36 {
37     view->showWarning(message);
38 }
39 
showError(const QString & message)40 void StatusBarPresenter::showError(const QString& message)
41 {
42     view->showError(message);
43 }
44 
showMindStatistics()45 void StatusBarPresenter::showMindStatistics()
46 {
47     // IMPROVE string builder
48     // IMPROVE const delimiter "    "
49 
50     status.clear();
51 
52     status += " ";
53     switch(Configuration::getInstance().getMindState()) {
54     case Configuration::MindState::THINKING:
55         status += "Thinking";
56         break;
57     case Configuration::MindState::DREAMING:
58         status += "Dreaming";
59         break;
60     case Configuration::MindState::SLEEPING:
61         status += "Sleeping";
62         break;
63     }
64     status += "   ";
65 
66     switch(Configuration::getInstance().getActiveRepository()->getType()) {
67     case Repository::RepositoryType::MINDFORGER:
68         status += "MF";
69         break;
70     case Repository::RepositoryType::MARKDOWN:
71         status += "MD";
72         break;
73     }
74     switch(Configuration::getInstance().getActiveRepository()->getMode()) {
75     case Repository::RepositoryMode::REPOSITORY:
76         status += " repository   ";
77         break;
78     case Repository::RepositoryMode::FILE:
79         status += " file   ";
80         break;
81     }
82 
83     // IMPROVE helper method @ QString gear
84     status += stringFormatIntAsUs(mind->remind().getOutlinesCount());
85     status += " notebooks   ";
86     status += stringFormatIntAsUs(mind->remind().getNotesCount());
87     status += " notes   ";
88 #ifdef MF_WIP
89     status += stringFormatIntAsUs(mind->getTriplesCount());
90     status += " triples   ";
91 #endif
92     status += stringFormatIntAsUs(mind->remind().getOutlineMarkdownsSize());
93     status += " bytes   ";
94     if(mind->getScopeAspect().isEnabled()) {
95         status += "scope:";
96         if(mind->getTimeScopeAspect().isEnabled()) {
97             status += mind->getTimeScopeAsString().c_str();
98             if(mind->getTagsScopeAspect().isEnabled()) {
99                 status += "+tags";
100             }
101         } else {
102             if(mind->getTagsScopeAspect().isEnabled()) {
103                 status += "tags";
104             }
105         }
106         status += "   ";
107     }
108 
109     if(Configuration::getInstance().isAutolinking()) {
110         status += "autolinking   ";
111     }
112 
113 
114 #ifdef DO_MF_DEBUG
115     status += "watermark:";
116     status += stringFormatIntAsUs(mind->getDeleteWatermark());
117 #endif
118 
119     view->showInfo(status);
120 }
121 
122 } // namespace
123