From b2f4da66f2affc8a53f79eef2a74cf447c8b0db8 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 27 Sep 2024 20:41:06 +0300 Subject: SeenPlugin: old ugly schema of storing protocol settings replaced with more convenient one --- plugins/SeenPlugin/src/main.cpp | 6 ------ plugins/SeenPlugin/src/options.cpp | 15 ++------------- plugins/SeenPlugin/src/stdafx.h | 2 -- plugins/SeenPlugin/src/utils.cpp | 30 +++++++++++++++++------------- 4 files changed, 19 insertions(+), 34 deletions(-) (limited to 'plugins/SeenPlugin/src') diff --git a/plugins/SeenPlugin/src/main.cpp b/plugins/SeenPlugin/src/main.cpp index 1e2b114f73..80b5379fbc 100644 --- a/plugins/SeenPlugin/src/main.cpp +++ b/plugins/SeenPlugin/src/main.cpp @@ -55,12 +55,7 @@ DBVTranslation idleTr[TRANSNUMBER] = { { any_to_Idle, L"Any to /Idle or empty", 0 } }; -static int CompareProtos(const char *p1, const char *p2) -{ return mir_strcmp(p1, p2); -} - BOOL includeIdle; -LIST arWatchedProtos(10, CompareProtos); LIST arContacts(16, NumericKeySortT); mir_cs csContacts; @@ -144,7 +139,6 @@ int CMPlugin::Load() int CMPlugin::Unload() { UninitFileOutput(); - UnloadWatchedProtos(); WindowList_Destroy(g_pUserInfo); diff --git a/plugins/SeenPlugin/src/options.cpp b/plugins/SeenPlugin/src/options.cpp index 765fedb421..e3e2ef05b5 100644 --- a/plugins/SeenPlugin/src/options.cpp +++ b/plugins/SeenPlugin/src/options.cpp @@ -342,22 +342,11 @@ public: g_plugin.setByte("IdleSupport", IsDlgButtonChecked(m_hwnd, IDC_IDLESUPPORT)); // save protocol list - CMStringA watchedProtocols; - int nItems = protocols.GetItemCount(); - for (int i=0; i < nItems; i++) { - if (!protocols.GetCheckState(i)) - continue; - + for (int i = 0; i < nItems; i++) { char *szProto = (char *)protocols.GetItemData(i); - if (!watchedProtocols.IsEmpty()) - watchedProtocols.AppendChar('\n'); - watchedProtocols.Append(szProto); + db_set_b(0, szProto, MODULENAME "Enabled", protocols.GetCheckState(i)); } - g_plugin.setString("WatchedAccounts", watchedProtocols); - - UnloadWatchedProtos(); - LoadWatchedProtos(); return true; } diff --git a/plugins/SeenPlugin/src/stdafx.h b/plugins/SeenPlugin/src/stdafx.h index 61f6009db6..7246708e02 100644 --- a/plugins/SeenPlugin/src/stdafx.h +++ b/plugins/SeenPlugin/src/stdafx.h @@ -138,8 +138,6 @@ extern uint32_t dwmirver; extern bool g_bFileActive; void LoadWatchedProtos(); -void UnloadWatchedProtos(); -extern LIST arWatchedProtos; extern LIST arContacts; extern mir_cs csContacts; diff --git a/plugins/SeenPlugin/src/utils.cpp b/plugins/SeenPlugin/src/utils.cpp index 7897bec510..aacad823a3 100644 --- a/plugins/SeenPlugin/src/utils.cpp +++ b/plugins/SeenPlugin/src/utils.cpp @@ -38,18 +38,22 @@ void LoadWatchedProtos() } ptrA szProtos(g_plugin.getStringA("WatchedAccounts")); - if (szProtos == NULL) - return; - - for (char *p = strtok(szProtos, "\n"); p != nullptr; p = strtok(nullptr, "\n")) - arWatchedProtos.insert(mir_strdup(p)); -} - -void UnloadWatchedProtos() -{ - for (auto &it : arWatchedProtos) - mir_free(it); - arWatchedProtos.destroy(); + if (szProtos != NULL) { + OBJLIST oldProtos(1); + for (char *p = strtok(szProtos, "\n"); p != nullptr; p = strtok(nullptr, "\n")) + oldProtos.insert(newStr(rtrim(p))); + + for (auto *pa : Accounts()) { + db_set_b(0, pa->szModuleName, MODULENAME "Enabled", false); + for (auto &it: oldProtos) { + if (!mir_strcmp(pa->szModuleName, it)) { + db_set_b(0, pa->szModuleName, MODULENAME "Enabled", true); + break; + } + } + } + g_plugin.delSetting("WatchedAccounts"); + } } ///////////////////////////////////////////////////////////////////////////////////////// @@ -64,7 +68,7 @@ int IsWatchedProtocol(const char* szProto) if (pd == nullptr || CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_2, 0) == 0) return 0; - return arWatchedProtos.find((char*)szProto) != nullptr; + return db_get_b(0, szProto, MODULENAME "Enabled", true); } bool isJabber(const char *protoname) -- cgit v1.2.3