This repository has been archived by the owner on Apr 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCfgController.h
175 lines (147 loc) · 4.96 KB
/
CfgController.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/**
* Configuration Controller
*
* Licensed under The GNU Lesser General Public License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright (c) 2005-2006 Sijawusz Pur Rahnama
* @link svn://konnekt.info/kaway2/ kAway2 plugin SVN Repo
* @version $Revision: 98 $
* @modifiedby $LastChangedBy: sija $
* @lastmodified $Date: 2006-12-08 18:27:59 +0100 (Pt, 08 gru 2006) $
* @license http://creativecommons.org/licenses/LGPL/2.1/
*/
#pragma once
#ifndef __CFGCTRL_H__
#define __CFGCTRL_H__
#include "IMController.h"
using namespace Konnekt::Tables;
using namespace Stamina;
using namespace boost;
namespace Konnekt {
class CfgController : public SharedObject<iSharedObject>, public signals::trackable {
public:
/* Class version */
STAMINA_OBJECT_CLASS_VERSION(CfgController, iSharedObject, Version(0,1,1,0));
public:
typedef std::vector<sIMessage_setColumn*> tCfgCols;
public:
inline CfgController(IMController* IMCtrl) {
this->attachObservers(IMCtrl);
}
inline CfgController() { }
inline virtual ~CfgController() {
for (tCfgCols::iterator it = _cols.begin(); it != _cols.end(); it++) {
delete *it;
}
}
public:
/* automagical registration of configuration columns (set via setColumn()) */
inline void attachObservers(IMController* IMCtrl) {
IMCtrl->registerObserver(IM_SETCOLS, bind(&CfgController::_setColumns, this, _1));
}
inline void setColumn(tTable table, tColId id, int type, const char* def, const char* name) {
_cols.push_back(new sIMessage_setColumn(table, id, type, def, name));
}
inline void setColumn(tTable table, tColId id, int type, int def, const char* name) {
_cols.push_back(new sIMessage_setColumn(table, id, type, def, name));
}
inline void resetColumns(tTable table = tableNotFound) {
if (!_cols.size()) return;
bool resetCnt = table == tableContacts;
bool resetCfg = table == tableConfig;
if (table == tableNotFound) {
resetCfg = resetCnt = true;
}
if (!resetCnt && !resetCfg) {
return;
}
tCfgCols dtCnt;
for (tCfgCols::iterator it = _cols.begin(); it != _cols.end(); it++) {
if ((*it)->_table == tableConfig && resetCfg) {
_resetColumn(*it);
}
if ((*it)->_table == tableContacts && resetCnt) {
dtCnt.push_back(*it);
}
}
if (dtCnt.size()) {
int count = Ctrl->IMessage(IMC_CNT_COUNT);
for (int i = 1; i < count; i++) {
for (tCfgCols::iterator it = dtCnt.begin(); it != dtCnt.end(); it++) {
_resetColumn(*it, i);
}
}
}
}
inline void resetColumn(int id, tCntId cnt = 0) {
if (!_cols.size()) return;
tTable table = !cnt ? tableConfig : tableContacts;
for (tCfgCols::iterator it = _cols.begin(); it != _cols.end(); it++) {
if ((*it)->_id == id && (*it)->_table == table) {
_resetColumn(*it, cnt); break;
}
}
}
/*
* @todo find some better way to handle it
*/
inline int getInheritedIValue(int col, tCntId cnt) {
return GETCNTI(cnt, col) >= 0 ? GETCNTI(cnt, col) : GETINT(col);
}
inline bool getInheritedBValue(int col, tCntId cnt) {
return (GETINT(col) && (GETCNTI(cnt, col) < 2)) || (!GETINT(col) && (GETCNTI(cnt, col) == 1));
}
inline const char* getInheritedCValue(int col, tCntId cnt) {
return strlen(GETCNTC(cnt, col)) ? GETCNTC(cnt, col) : GETSTRA(col);
}
protected:
inline void _resetColumn(sIMessage_setColumn* it, tCntId cnt = 0) {
bool isCnt = it->_table == tableContacts && cnt;
bool isConfig = it->_table == tableConfig;
if (!isCnt && !isConfig) {
return;
}
switch (it->_type) {
case ctypeInt: {
if (isConfig) {
SETINT(it->_id, it->_def);
}
if (isCnt) {
SETCNTI(cnt, it->_id, it->_def);
}
break;
}
case ctypeInt64: {
if (isConfig) {
// SETINT(it->_id, *it->_def_p64);
}
if (isCnt) {
SETCNTI64(cnt, it->_id, *it->_def_p64);
}
break;
}
case ctypeString: {
if (isConfig) {
SETSTR(it->_id, it->_def_ch);
}
if (isCnt) {
SETCNTC(cnt, it->_id, it->_def_ch);
}
break;
}
}
}
inline tIMCallback _setColumns(IMController* IMCtrl) {
for (tCfgCols::iterator it = _cols.begin(); it != _cols.end(); it++) {
Ctrl->IMessage(*it);
}
IMCtrl->setSuccess();
}
protected:
tCfgCols _cols;
};
typedef SharedPtr<CfgController> oCfgCtrl;
}
#endif // __CFGCTRL_H__