diff options
-rw-r--r-- | plugins/SmileyAdd/src/services.cpp | 124 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/smileys.cpp | 105 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/smileys.h | 4 |
3 files changed, 116 insertions, 117 deletions
diff --git a/plugins/SmileyAdd/src/services.cpp b/plugins/SmileyAdd/src/services.cpp index 4adb1cab94..adf533896b 100644 --- a/plugins/SmileyAdd/src/services.cpp +++ b/plugins/SmileyAdd/src/services.cpp @@ -22,7 +22,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. LIST<void> menuHandleArray(5);
-//implementation of service functions
+/////////////////////////////////////////////////////////////////////////////////////////
+// Service functions
SmileyPackType* FindSmileyPack(const char *proto, MCONTACT hContact, SmileyPackCType **smlc)
{
@@ -80,6 +81,8 @@ SmileyPackType* FindSmileyPack(const char *proto, MCONTACT hContact, SmileyPackC return g_SmileyCategories.GetSmileyPack(categoryName);
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
INT_PTR ReplaceSmileysCommand(WPARAM, LPARAM lParam)
{
SMADD_RICHEDIT3 *smre = (SMADD_RICHEDIT3*)lParam;
@@ -102,6 +105,8 @@ INT_PTR ReplaceSmileysCommand(WPARAM, LPARAM lParam) return TRUE;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
static int GetInfoCommandE(SMADD_INFO2 *smre, bool retDup)
{
if (smre == nullptr) return FALSE;
@@ -137,7 +142,7 @@ INT_PTR GetInfoCommand2(WPARAM, LPARAM lParam) return GetInfoCommandE((SMADD_INFO2*)lParam, true);
}
-
+/////////////////////////////////////////////////////////////////////////////////////////
INT_PTR ParseTextBatch(WPARAM, LPARAM lParam)
{
@@ -185,12 +190,16 @@ INT_PTR ParseTextBatch(WPARAM, LPARAM lParam) return (INT_PTR)res;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
INT_PTR FreeTextBatch(WPARAM, LPARAM lParam)
{
delete[](SMADD_BATCHPARSERES*)lParam;
return TRUE;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
INT_PTR RegisterPack(WPARAM, LPARAM lParam)
{
SMADD_REGCAT *smre = (SMADD_REGCAT*)lParam;
@@ -206,6 +215,8 @@ INT_PTR RegisterPack(WPARAM, LPARAM lParam) return TRUE;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
INT_PTR CustomCatMenu(WPARAM hContact, LPARAM lParam)
{
if (lParam != 0) {
@@ -227,6 +238,60 @@ INT_PTR CustomCatMenu(WPARAM hContact, LPARAM lParam) return TRUE;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
+INT_PTR ReloadPack(WPARAM, LPARAM lParam)
+{
+ if (lParam) {
+ SmileyCategoryType *smc = g_SmileyCategories.GetSmileyCategory(_A2T((char *)lParam));
+ if (smc != nullptr)
+ smc->Load();
+ }
+ else {
+ g_SmileyCategories.ClearAll();
+ g_SmileyCategories.AddAllProtocolsAsCategory();
+ g_SmileyCategories.ClearAndLoadAll();
+ }
+
+ NotifyEventHooks(g_hevOptionsChanged, 0, 0);
+ return 0;
+}
+
+INT_PTR LoadContactSmileys(WPARAM, LPARAM lParam)
+{
+ SMADD_CONT *cont = (SMADD_CONT *)lParam;
+
+ switch (cont->type) {
+ case 0:
+ g_SmileyPackCStore.AddSmileyPack(cont->pszModule, cont->path);
+ NotifyEventHooks(g_hevOptionsChanged, (WPARAM)cont->pszModule, 0);
+ break;
+
+ case 1:
+ g_SmileyPackCStore.AddSmiley(cont->pszModule, cont->path);
+ NotifyEventHooks(g_hevOptionsChanged, (WPARAM)cont->pszModule, 0);
+ break;
+
+ case 2:
+ WIN32_FIND_DATAW findData;
+ CMStringW wszPath(cont->path);
+ HANDLE hFind = FindFirstFileW(wszPath, &findData);
+ if (hFind != INVALID_HANDLE_VALUE) {
+ int idx = wszPath.ReverseFind('\\');
+ if (idx != -1)
+ wszPath.Truncate(idx + 1);
+
+ do {
+ if (!mir_wstrcmp(findData.cFileName, L".") || !mir_wstrcmp(findData.cFileName, L"."))
+ continue;
+
+ CMStringW wszFileName = wszPath + findData.cFileName;
+ g_SmileyPackCStore.AddSmiley(cont->pszModule, wszFileName);
+ } while (FindNextFileW(hFind, &findData));
+ }
+ }
+ return 0;
+}
int RebuildContactMenu(WPARAM wParam, LPARAM)
{
@@ -301,58 +366,8 @@ int RebuildContactMenu(WPARAM wParam, LPARAM) return 0;
}
-INT_PTR ReloadPack(WPARAM, LPARAM lParam)
-{
- if (lParam) {
- SmileyCategoryType *smc = g_SmileyCategories.GetSmileyCategory(_A2T((char *)lParam));
- if (smc != nullptr)
- smc->Load();
- }
- else {
- g_SmileyCategories.ClearAll();
- g_SmileyCategories.AddAllProtocolsAsCategory();
- g_SmileyCategories.ClearAndLoadAll();
- }
-
- NotifyEventHooks(g_hevOptionsChanged, 0, 0);
- return 0;
-}
-
-INT_PTR LoadContactSmileys(WPARAM, LPARAM lParam)
-{
- SMADD_CONT *cont = (SMADD_CONT*)lParam;
-
- switch (cont->type) {
- case 0:
- g_SmileyPackCStore.AddSmileyPack(cont->pszModule, cont->path);
- NotifyEventHooks(g_hevOptionsChanged, (WPARAM)cont->pszModule, 0);
- break;
-
- case 1:
- g_SmileyPackCStore.AddSmiley(cont->pszModule, cont->path);
- NotifyEventHooks(g_hevOptionsChanged, (WPARAM)cont->pszModule, 0);
- break;
-
- case 2:
- WIN32_FIND_DATAW findData;
- CMStringW wszPath(cont->path);
- HANDLE hFind = FindFirstFileW(wszPath, &findData);
- if (hFind != INVALID_HANDLE_VALUE) {
- int idx = wszPath.ReverseFind('\\');
- if (idx != -1)
- wszPath.Truncate(idx+1);
-
- do {
- if (!mir_wstrcmp(findData.cFileName, L".") || !mir_wstrcmp(findData.cFileName, L"."))
- continue;
-
- CMStringW wszFileName = wszPath + findData.cFileName;
- g_SmileyPackCStore.AddSmiley(cont->pszModule, wszFileName);
- } while (FindNextFileW(hFind, &findData));
- }
- }
- return 0;
-}
+/////////////////////////////////////////////////////////////////////////////////////////
+// Events
int AccountListChanged(WPARAM wParam, LPARAM lParam)
{
@@ -412,7 +427,6 @@ int DbSettingChanged(WPARAM hContact, LPARAM lParam) return 0;
}
-
int ReloadColour(WPARAM, LPARAM)
{
opt.SelWndBkgClr = db_get_dw(0, "SmileyAdd", "SelWndBkgClr", GetSysColor(COLOR_WINDOW));
diff --git a/plugins/SmileyAdd/src/smileys.cpp b/plugins/SmileyAdd/src/smileys.cpp index 0d6492a59b..cb4df861bc 100644 --- a/plugins/SmileyAdd/src/smileys.cpp +++ b/plugins/SmileyAdd/src/smileys.cpp @@ -741,7 +741,7 @@ void SmileyCategoryListType::SaveSettings(void) opt.WriteCustomCategories(catstr);
}
-void SmileyCategoryListType::AddAndLoad(const CMStringW &name, const CMStringW &displayName)
+void SmileyCategoryListType::AddAndLoad(const wchar_t *name, const wchar_t *displayName)
{
if (GetSmileyCategory(name) != nullptr)
return;
@@ -753,7 +753,7 @@ void SmileyCategoryListType::AddAndLoad(const CMStringW &name, const CMStringW & m_SmileyCategories[m_SmileyCategories.getCount() - 1].Load();
}
-void SmileyCategoryListType::AddCategory(const CMStringW &name, const CMStringW &displayName, SmcType typ, const CMStringW &defaultFilename)
+void SmileyCategoryListType::AddCategory(const wchar_t *name, const wchar_t *displayName, SmcType typ, const wchar_t *defaultFilename)
{
if (GetSmileyCategory(name) == nullptr)
m_SmileyCategories.insert(new SmileyCategoryType(m_pSmileyPackStore, name, displayName, defaultFilename, typ));
@@ -772,37 +772,39 @@ bool SmileyCategoryListType::DeleteCustomCategory(int index) void SmileyCategoryListType::AddAccountAsCategory(PROTOACCOUNT *acc, const CMStringW &defaultFile)
{
- if (acc->IsEnabled() && acc->szProtoName && IsSmileyProto(acc->szModuleName)) {
- CMStringW displayName(acc->tszAccountName ? acc->tszAccountName : _A2T(acc->szModuleName));
- CMStringW PhysProtoName, paths;
- DBVARIANT dbv;
+ if (!acc->IsEnabled() || !acc->szProtoName || !IsSmileyProto(acc->szModuleName))
+ return;
- if (db_get_ws(0, acc->szModuleName, "AM_BaseProto", &dbv) == 0) {
- PhysProtoName = L"AllProto";
- PhysProtoName += dbv.pwszVal;
- db_free(&dbv);
- }
+ CMStringW PhysProtoName, paths;
+ DBVARIANT dbv;
- if (!PhysProtoName.IsEmpty()) {
- auto *p = g_SmileyCategories.GetSmileyCategory(PhysProtoName);
- paths = (p) ? p->GetFilename() : L"";
- }
+ if (db_get_ws(0, acc->szModuleName, "AM_BaseProto", &dbv) == 0) {
+ PhysProtoName = L"AllProto";
+ PhysProtoName += dbv.pwszVal;
+ db_free(&dbv);
+ }
- // assemble default path
- if (paths.IsEmpty()) {
- const char *packnam = acc->szProtoName;
- if (mir_strcmp(packnam, "JABBER") == 0)
- packnam = "JGMail";
+ if (!PhysProtoName.IsEmpty()) {
+ auto *p = g_SmileyCategories.GetSmileyCategory(PhysProtoName);
+ paths = (p) ? p->GetFilename() : L"";
+ }
- wchar_t path[MAX_PATH];
- mir_snwprintf(path, L"%s\\Smileys\\nova\\%S.msl", g_plugin.wszDefaultPath, packnam);
- if (_waccess(path, 0) != 0)
- paths = defaultFile;
- }
+ // assemble default path
+ if (paths.IsEmpty()) {
+ const char *packnam = acc->szProtoName;
+ if (mir_strcmp(packnam, "JABBER") == 0)
+ packnam = "JGMail";
- CMStringW tname(_A2T(acc->szModuleName));
- AddCategory(tname, displayName, acc->bIsVirtual ? smcVirtualProto : smcProto, paths);
+ wchar_t path[MAX_PATH];
+ mir_snwprintf(path, L"%s\\Smileys\\nova\\%S.msl", g_plugin.wszDefaultPath, packnam);
+ if (_waccess(path, 0) != 0)
+ paths = defaultFile;
}
+
+ if (acc->tszAccountName)
+ AddCategory(_A2T(acc->szModuleName), acc->tszAccountName, acc->bIsVirtual ? smcVirtualProto : smcProto, paths);
+ else
+ AddCategory(_A2T(acc->szModuleName), _A2T(acc->szModuleName), acc->bIsVirtual ? smcVirtualProto : smcProto, paths);
}
void SmileyCategoryListType::AddProtoAsCategory(char *acc, const CMStringW &defaultFile)
@@ -821,10 +823,8 @@ void SmileyCategoryListType::AddProtoAsCategory(char *acc, const CMStringW &defa paths = defaultFile;
CMStringW dName(acc), displayName;
- displayName.AppendFormat(TranslateT("%s global smiley pack"), dName.GetBuffer());
- CMStringW tname("AllProto");
- tname += _A2T(acc);
- AddCategory(tname, displayName, smcPhysProto, paths);
+ displayName.AppendFormat(TranslateT("%s global smiley pack"), dName.c_str());
+ AddCategory(L"AllProto" + dName, displayName, smcPhysProto, paths);
}
void SmileyCategoryListType::DeleteAccountAsCategory(PROTOACCOUNT *acc)
@@ -859,43 +859,28 @@ void SmileyCategoryListType::AddContactTransportAsCategory(MCONTACT hContact, co if (proto == nullptr)
return;
- DBVARIANT dbv;
- if (!db_get_ws(hContact, proto, "Transport", &dbv)) {
- if (dbv.pwszVal[0] == '\0') {
- db_free(&dbv);
- return;
- }
- char *trsp = mir_strdup(_T2A(dbv.pwszVal));
- _strlwr(trsp);
-
- const char *packname = nullptr;
- if (strstr(trsp, "icq") != nullptr)
- packname = "icq";
+ CMStringW displayName(db_get_wsm(hContact, proto, "Transport"));
+ if (displayName.IsEmpty())
+ return;
- mir_free(trsp);
+ char *trsp = mir_u2a(displayName);
+ _strlwr(trsp);
- CMStringW paths, displayName(dbv.pwszVal);
- if (packname != nullptr) {
- paths.Format(L"%s\\Smileys\\nova\\%S.msl", g_plugin.wszDefaultPath, packname);
- paths = VARSW(paths);
- if (_waccess(paths.c_str(), 0) != 0)
- paths = defaultFile;
- }
- else paths = defaultFile;
+ const char *packname = nullptr;
+ if (strstr(trsp, "icq") != nullptr)
+ packname = "icq";
- AddCategory(displayName, displayName, smcTransportProto, defaultFile);
+ mir_free(trsp);
- db_free(&dbv);
- }
+ AddCategory(displayName, displayName, smcTransportProto, defaultFile);
}
void SmileyCategoryListType::AddAllProtocolsAsCategory(void)
{
- CMStringW displayName = TranslateT("Standard");
- CMStringW tname = L"Standard";
- AddCategory(tname, displayName, smcStd);
+ AddCategory(L"Standard", TranslateT("Standard"), smcStd);
+ AddCategory(L"Emoji", TranslateT("Emoji"), smcStd);
- const CMStringW &defaultFile = GetSmileyCategory(tname)->GetFilename();
+ auto &defaultFile = GetSmileyCategory(L"Standard")->GetFilename();
PROTOCOLDESCRIPTOR **proto;
int protoCount = 0;
@@ -913,7 +898,7 @@ void SmileyCategoryListType::AddAllProtocolsAsCategory(void) for (auto &hContact : Contacts())
AddContactTransportAsCategory(hContact, defaultFile);
- CMStringW cats;
+ CMStringW cats, displayName;
opt.ReadCustomCategories(cats);
int cppv = 0;
diff --git a/plugins/SmileyAdd/src/smileys.h b/plugins/SmileyAdd/src/smileys.h index 2a4df721dd..e4a45095b7 100644 --- a/plugins/SmileyAdd/src/smileys.h +++ b/plugins/SmileyAdd/src/smileys.h @@ -290,8 +290,8 @@ public: int NumberOfSmileyCategories(void) { return m_SmileyCategories.getCount(); }
- void AddCategory(const CMStringW &name, const CMStringW &displayName, SmcType typ, const CMStringW &defaultFilename = L"");
- void AddAndLoad(const CMStringW &name, const CMStringW &displayName);
+ void AddCategory(const wchar_t *name, const wchar_t *displayName, SmcType typ, const wchar_t *defaultFilename = L"");
+ void AddAndLoad(const wchar_t *name, const wchar_t *displayName);
void AddAllProtocolsAsCategory(void);
void AddAccountAsCategory(PROTOACCOUNT *acc, const CMStringW &defaultFile);
void AddProtoAsCategory(char *acc, const CMStringW &defaultFile);
|