summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-05-07 17:50:35 +0200
committerGeorge Hazan <ghazan@miranda.im>2018-05-07 18:07:33 +0200
commit1732a6b13f52b573cc4af91c2d9120c596e6bf78 (patch)
tree57e853c70f4bf51bfedbd8a50874746e5a3bc971 /src
parentd1c9c916887e91a32d7794c83c37ff1c512660d9 (diff)
PROTOACCOUNT::bIsLocked: lock status to be stored in memory
PROTOACCOUNT became a normal class with constructor & destructor
Diffstat (limited to 'src')
-rw-r--r--src/mir_app/src/menu_clist.cpp6
-rw-r--r--src/mir_app/src/mir_app.def3
-rw-r--r--src/mir_app/src/mir_app64.def3
-rw-r--r--src/mir_app/src/proto_accs.cpp35
-rw-r--r--src/mir_app/src/proto_chains.cpp2
-rw-r--r--src/mir_app/src/proto_opts.cpp16
-rw-r--r--src/mir_app/src/protocols.cpp23
7 files changed, 44 insertions, 44 deletions
diff --git a/src/mir_app/src/menu_clist.cpp b/src/mir_app/src/menu_clist.cpp
index d8eba369c9..b7c1e66ea5 100644
--- a/src/mir_app/src/menu_clist.cpp
+++ b/src/mir_app/src/menu_clist.cpp
@@ -525,8 +525,8 @@ static INT_PTR StatusMenuExecService(WPARAM wParam, LPARAM)
char *prot = smep->szProto;
char szHumanName[64] = { 0 };
PROTOACCOUNT *acc = Proto_GetAccount(smep->szProto);
- bool bIsLocked = !acc->IsLocked();
- db_set_b(0, prot, "LockMainStatus", bIsLocked);
+ acc->bIsLocked = !acc->bIsLocked;
+ db_set_b(0, prot, "LockMainStatus", acc->bIsLocked);
CallProtoServiceInt(0, smep->szProto, PS_GETNAME, _countof(szHumanName), (LPARAM)szHumanName);
@@ -536,7 +536,7 @@ static INT_PTR StatusMenuExecService(WPARAM wParam, LPARAM)
TMO_IntMenuItem *root = (TMO_IntMenuItem*)pimi->mi.root;
wchar_t buf[256], *ptszName;
- if (bIsLocked) {
+ if (acc->bIsLocked) {
pimi->mi.flags |= CMIF_CHECKED;
mir_snwprintf(buf, TranslateT("%s (locked)"), acc->tszAccountName);
ptszName = buf;
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index 8361e8c9ae..6fa1d98644 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -523,7 +523,6 @@ Proto_GetAverageStatus @512
?RegisterProtocol@CMPluginBase@@IAEXHP6APAUPROTO_INTERFACE@@PBDPB_W@ZP6AHPAU2@@Z@Z @547 NONAME
Proto_GetUniqueId @548
Proto_SetUniqueId @549
-??4PROTOACCOUNT@@QAEAAU0@$$QAU0@@Z @550 NONAME
??4PROTOACCOUNT@@QAEAAU0@ABU0@@Z @551 NONAME
?IsEnabled@PROTOACCOUNT@@QBE_NXZ @552 NONAME
?IsLocked@PROTOACCOUNT@@QBE_NXZ @553 NONAME
@@ -594,3 +593,5 @@ Contact_GetStatus @609
?getMStringW@CMPluginBase@@QAE?AV?$CMStringT@_WV?$ChTraitsCRT@_W@@@@PBD@Z @618 NONAME
?getMStringW@PROTO_INTERFACE@@QAE?AV?$CMStringT@_WV?$ChTraitsCRT@_W@@@@IPBD@Z @619 NONAME
?getMStringW@PROTO_INTERFACE@@QAE?AV?$CMStringT@_WV?$ChTraitsCRT@_W@@@@PBD@Z @620 NONAME
+??0PROTOACCOUNT@@QAE@PBD@Z @621 NONAME
+??1PROTOACCOUNT@@QAE@XZ @622 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index e54f50ddcc..109b032808 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -523,7 +523,6 @@ Proto_GetAverageStatus @512
?RegisterProtocol@CMPluginBase@@IEAAXHP6APEAUPROTO_INTERFACE@@PEBDPEB_W@ZP6AHPEAU2@@Z@Z @547 NONAME
Proto_GetUniqueId @548
Proto_SetUniqueId @549
-??4PROTOACCOUNT@@QEAAAEAU0@$$QEAU0@@Z @550 NONAME
??4PROTOACCOUNT@@QEAAAEAU0@AEBU0@@Z @551 NONAME
?IsEnabled@PROTOACCOUNT@@QEBA_NXZ @552 NONAME
?IsLocked@PROTOACCOUNT@@QEBA_NXZ @553 NONAME
@@ -594,3 +593,5 @@ Contact_GetStatus @609
?getMStringW@CMPluginBase@@QEAA?AV?$CMStringT@_WV?$ChTraitsCRT@_W@@@@PEBD@Z @618 NONAME
?getMStringW@PROTO_INTERFACE@@QEAA?AV?$CMStringT@_WV?$ChTraitsCRT@_W@@@@IPEBD@Z @619 NONAME
?getMStringW@PROTO_INTERFACE@@QEAA?AV?$CMStringT@_WV?$ChTraitsCRT@_W@@@@PEBD@Z @620 NONAME
+??0PROTOACCOUNT@@QEAA@PEBD@Z @621 NONAME
+??1PROTOACCOUNT@@QEAA@XZ @622 NONAME
diff --git a/src/mir_app/src/proto_accs.cpp b/src/mir_app/src/proto_accs.cpp
index 68b61a17ae..39604d8da2 100644
--- a/src/mir_app/src/proto_accs.cpp
+++ b/src/mir_app/src/proto_accs.cpp
@@ -48,15 +48,12 @@ static int EnumDbModules(const char *szModuleName, void*)
ptrA szProtoName(db_get_sa(0, szModuleName, "AM_BaseProto"));
if (szProtoName) {
if (!Proto_GetAccount(szModuleName)) {
- PROTOACCOUNT *pa = (PROTOACCOUNT*)mir_calloc(sizeof(PROTOACCOUNT));
- pa->szModuleName = mir_strdup(szModuleName);
+ PROTOACCOUNT *pa = new PROTOACCOUNT(szModuleName);
pa->szProtoName = szProtoName.detach();
pa->tszAccountName = mir_a2u(szModuleName);
pa->bIsVisible = true;
pa->bIsEnabled = false;
pa->iOrder = accounts.getCount();
- pa->iIconBase = -1;
- pa->iRealStatus = ID_STATUS_OFFLINE;
accounts.insert(pa);
}
}
@@ -71,22 +68,15 @@ void LoadDbAccounts(void)
for (int i = 0; i < count; i++) {
char buf[10];
_itoa(i, buf, 10);
- char *szModuleName = db_get_sa(0, "Protocols", buf);
+ ptrA szModuleName(db_get_sa(0, "Protocols", buf));
if (szModuleName == nullptr)
continue;
PROTOACCOUNT *pa = Proto_GetAccount(szModuleName);
if (pa == nullptr) {
- pa = (PROTOACCOUNT*)mir_calloc(sizeof(PROTOACCOUNT));
- pa->szModuleName = szModuleName;
- pa->iIconBase = -1;
- pa->iRealStatus = ID_STATUS_OFFLINE;
+ pa = new PROTOACCOUNT(szModuleName);
accounts.insert(pa);
}
- else {
- mir_free(szModuleName);
- szModuleName = pa->szModuleName;
- }
_itoa(OFFSET_VISIBLE + i, buf, 10);
pa->bIsVisible = db_get_dw(0, "Protocols", buf, 1) != 0;
@@ -128,12 +118,11 @@ void LoadDbAccounts(void)
/////////////////////////////////////////////////////////////////////////////////////////
-typedef struct
+struct enumDB_ProtoProcParam
{
int arrlen;
char **pszSettingName;
-}
-enumDB_ProtoProcParam;
+};
static int enumDB_ProtoProc(const char* szSetting, void *lParam)
{
@@ -436,22 +425,20 @@ void UnloadAccount(PROTOACCOUNT *pa, int flags)
{
DeactivateAccount(pa, flags);
- replaceStrW(pa->tszAccountName, 0);
- replaceStr(pa->szProtoName, 0);
- replaceStr(pa->szUniqueId, 0);
-
// szModuleName should be freed only on a program's exit.
// otherwise many plugins dependand on static protocol names will crash!
// do NOT fix this 'leak', please
- if (!(flags & DAF_DYNAMIC)) {
- mir_free(pa->szModuleName);
- mir_free(pa);
+ if (!(flags & DAF_DYNAMIC))
+ delete pa;
+ else {
+ replaceStrW(pa->tszAccountName, 0); replaceStr(pa->szProtoName, 0); replaceStr(pa->szUniqueId, 0);
}
}
void UnloadAccountsModule()
{
- if (!bModuleInitialized) return;
+ if (!bModuleInitialized)
+ return;
auto T = accounts.rev_iter();
for (auto &it : T) {
diff --git a/src/mir_app/src/proto_chains.cpp b/src/mir_app/src/proto_chains.cpp
index f295886181..4e9912a07b 100644
--- a/src/mir_app/src/proto_chains.cpp
+++ b/src/mir_app/src/proto_chains.cpp
@@ -155,7 +155,7 @@ MIR_APP_DLL(char*) GetContactProto(MCONTACT hContact)
MIR_APP_DLL(char*) Proto_GetBaseAccountName(MCONTACT hContact)
{
PROTOACCOUNT *pa = Proto_GetAccount(hContact);
- return pa ? pa->szModuleName : nullptr;
+ return pa->IsEnabled() ? pa->szModuleName : nullptr;
}
MIR_APP_DLL(int) Proto_IsProtoOnContact(MCONTACT hContact, const char *szProto)
diff --git a/src/mir_app/src/proto_opts.cpp b/src/mir_app/src/proto_opts.cpp
index 208ccb107f..7b58a4abd0 100644
--- a/src/mir_app/src/proto_opts.cpp
+++ b/src/mir_app/src/proto_opts.cpp
@@ -55,14 +55,8 @@ MIR_APP_DLL(PROTOACCOUNT*) Proto_CreateAccount(const char *pszInternal, const ch
if (pszBaseProto == nullptr || tszAccountName == nullptr)
return nullptr;
- PROTOACCOUNT *pa = (PROTOACCOUNT*)mir_calloc(sizeof(PROTOACCOUNT));
- pa->bIsEnabled = pa->bIsVisible = true;
- pa->iOrder = accounts.getCount();
- pa->szProtoName = mir_strdup(pszBaseProto);
- pa->iRealStatus = ID_STATUS_OFFLINE;
- pa->iIconBase = -1;
-
// if the internal name is empty, generate new one
+ const char *szProto;
if (mir_strlen(pszInternal) == 0) {
char buf[100];
int count = 1;
@@ -71,10 +65,14 @@ MIR_APP_DLL(PROTOACCOUNT*) Proto_CreateAccount(const char *pszInternal, const ch
if (ptrA(db_get_sa(0, buf, "AM_BaseProto")) == nullptr)
break;
}
- pa->szModuleName = mir_strdup(buf);
+ szProto = buf;
}
- else pa->szModuleName = mir_strdup(pszInternal);
+ else szProto = pszInternal;
+ PROTOACCOUNT *pa = new PROTOACCOUNT(szProto);
+ pa->bIsEnabled = pa->bIsVisible = true;
+ pa->iOrder = accounts.getCount();
+ pa->szProtoName = mir_strdup(pszBaseProto);
pa->tszAccountName = mir_wstrdup(tszAccountName);
db_set_s(0, pa->szModuleName, "AM_BaseProto", pszBaseProto);
diff --git a/src/mir_app/src/protocols.cpp b/src/mir_app/src/protocols.cpp
index 14f679ea9b..6a28c9bfeb 100644
--- a/src/mir_app/src/protocols.cpp
+++ b/src/mir_app/src/protocols.cpp
@@ -121,14 +121,11 @@ MIR_APP_DLL(PROTOCOLDESCRIPTOR*) Proto_RegisterModule(int type, const char *szNa
ppi->m_iVersion = 1;
PROTOACCOUNT *pa = Proto_GetAccount(pd->szName);
if (pa == nullptr) {
- pa = (PROTOACCOUNT*)mir_calloc(sizeof(PROTOACCOUNT));
- pa->szModuleName = mir_strdup(szName);
+ pa = new PROTOACCOUNT(szName);
pa->szProtoName = mir_strdup(szName);
pa->tszAccountName = mir_a2u(szName);
pa->bIsVisible = pa->bIsEnabled = true;
pa->iOrder = accounts.getCount();
- pa->iIconBase = -1;
- pa->iRealStatus = ID_STATUS_OFFLINE;
accounts.insert(pa);
}
pa->bOldProto = true;
@@ -335,6 +332,22 @@ MIR_APP_DLL(LIST<PROTOACCOUNT>&) Accounts(void)
/////////////////////////////////////////////////////////////////////////////////////////
+PROTOACCOUNT::PROTOACCOUNT(const char *szProto) :
+ szModuleName(mir_strdup(szProto)),
+ iIconBase(-1),
+ iRealStatus(ID_STATUS_OFFLINE)
+{
+ bIsLocked = db_get_b(0, szProto, "LockMainStatus", 0) != 0;
+}
+
+PROTOACCOUNT::~PROTOACCOUNT()
+{
+ mir_free(szModuleName);
+ mir_free(szProtoName);
+ mir_free(szUniqueId);
+ mir_free(tszAccountName);
+}
+
bool PROTOACCOUNT::IsEnabled() const
{
return (this != nullptr) && ((bIsEnabled && !bDynDisabled) || bOldProto);
@@ -342,7 +355,7 @@ bool PROTOACCOUNT::IsEnabled() const
bool PROTOACCOUNT::IsLocked() const
{
- return (this != nullptr) && db_get_b(0, szModuleName, "LockMainStatus", 0) != 0;
+ return (this != nullptr) && bIsLocked;
}
bool PROTOACCOUNT::IsVisible() const