summaryrefslogtreecommitdiff
path: root/plugins/SmileyAdd
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/SmileyAdd')
-rw-r--r--plugins/SmileyAdd/src/customsmiley.cpp29
-rw-r--r--plugins/SmileyAdd/src/customsmiley.h21
-rw-r--r--plugins/SmileyAdd/src/dlgboxsubclass.cpp4
-rw-r--r--plugins/SmileyAdd/src/options.cpp2
-rw-r--r--plugins/SmileyAdd/src/richcall.cpp2
-rw-r--r--plugins/SmileyAdd/src/services.cpp100
-rw-r--r--plugins/SmileyAdd/src/services.h2
-rw-r--r--plugins/SmileyAdd/src/smileys.cpp35
-rw-r--r--plugins/SmileyAdd/src/smileys.h2
-rw-r--r--plugins/SmileyAdd/src/smltool.cpp35
-rw-r--r--plugins/SmileyAdd/src/smltool.h1
-rw-r--r--plugins/SmileyAdd/src/version.h4
12 files changed, 71 insertions, 166 deletions
diff --git a/plugins/SmileyAdd/src/customsmiley.cpp b/plugins/SmileyAdd/src/customsmiley.cpp
index b6e502e1f4..e3958760e5 100644
--- a/plugins/SmileyAdd/src/customsmiley.cpp
+++ b/plugins/SmileyAdd/src/customsmiley.cpp
@@ -20,39 +20,36 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
SmileyPackCListType g_SmileyPackCStore;
-bool SmileyPackCListType::AddSmileyPack(MCONTACT hContact, wchar_t *dir)
+bool SmileyPackCListType::AddSmileyPack(const char *pszModule, const wchar_t *dir)
{
bool res = true;
- if (GetSmileyPack(hContact) == nullptr) {
- SmileyPackCType *smileyPack = new SmileyPackCType;
+ if (GetSmileyPack(pszModule) == nullptr) {
+ SmileyPackCType *smileyPack = new SmileyPackCType(pszModule);
res = smileyPack->LoadSmileyDir(dir);
- if (res) {
- smileyPack->SetId(hContact);
+ if (res)
m_SmileyPacks.insert(smileyPack);
- }
- else delete smileyPack;
+ else
+ delete smileyPack;
}
return res;
}
-bool SmileyPackCListType::AddSmiley(MCONTACT hContact, wchar_t *path)
+bool SmileyPackCListType::AddSmiley(const char *pszModule, const wchar_t *path)
{
- SmileyPackCType *smpack = GetSmileyPack(hContact);
+ SmileyPackCType *smpack = GetSmileyPack(pszModule);
if (smpack == nullptr) {
- smpack = new SmileyPackCType;
-
- smpack->SetId(hContact);
+ smpack = new SmileyPackCType(pszModule);
m_SmileyPacks.insert(smpack);
}
return smpack->LoadSmiley(path);
}
-SmileyPackCType* SmileyPackCListType::GetSmileyPack(MCONTACT id)
+SmileyPackCType* SmileyPackCListType::GetSmileyPack(const char *pszModule)
{
for (auto &it : m_SmileyPacks)
- if (it->GetId() == id)
+ if (!mir_strcmp(it->GetId(), pszModule))
return it;
return nullptr;
@@ -83,7 +80,7 @@ bool SmileyCType::CreateTriggerText(char *text)
// SmileyPackCType
//
-bool SmileyPackCType::LoadSmileyDir(wchar_t *dir)
+bool SmileyPackCType::LoadSmileyDir(const wchar_t *dir)
{
CMStringW dirs = dir;
dirs += L"\\*.*";
@@ -113,7 +110,7 @@ bool SmileyPackCType::LoadSmileyDir(wchar_t *dir)
return false;
}
-bool SmileyPackCType::LoadSmiley(wchar_t *path)
+bool SmileyPackCType::LoadSmiley(const wchar_t *path)
{
CMStringW dirs = path;
int slash = dirs.ReverseFind('\\');
diff --git a/plugins/SmileyAdd/src/customsmiley.h b/plugins/SmileyAdd/src/customsmiley.h
index bd76875796..2deb75102c 100644
--- a/plugins/SmileyAdd/src/customsmiley.h
+++ b/plugins/SmileyAdd/src/customsmiley.h
@@ -37,11 +37,15 @@ private:
SmileyVectorType m_SmileyList;
SmileyLookupType m_SmileyLookup;
- MCONTACT m_id;
+ ptrA m_szModule;
void AddTriggersToSmileyLookup(void);
public:
+ SmileyPackCType(const char *pszModule) :
+ m_szModule(mir_strdup(pszModule))
+ {}
+
SmileyVectorType& GetSmileyList(void) { return m_SmileyList; }
SmileyLookupType& GetSmileyLookup(void) { return m_SmileyLookup; }
@@ -49,11 +53,10 @@ public:
SmileyCType* GetSmiley(unsigned index) { return &m_SmileyList[index]; }
- MCONTACT GetId(void) { return m_id; }
- void SetId(MCONTACT id) { m_id = id; }
+ const char* GetId(void) { return m_szModule; }
- bool LoadSmiley(wchar_t *path);
- bool LoadSmileyDir(wchar_t *dir);
+ bool LoadSmiley(const wchar_t *path);
+ bool LoadSmileyDir(const wchar_t *dir);
};
@@ -68,12 +71,12 @@ private:
public:
int NumberOfSmileyPacks(void) { return m_SmileyPacks.getCount(); }
- bool AddSmiley(MCONTACT hContact, wchar_t *path);
- bool AddSmileyPack(MCONTACT hContact, wchar_t *dir);
+ bool AddSmiley(const char *pszModule, const wchar_t *path);
+ bool AddSmileyPack(const char *pszModule, const wchar_t *dir);
- void ClearAndFreeAll(void) { m_SmileyPacks.destroy(); }
+ void ClearAndFreeAll(void) { m_SmileyPacks.destroy(); }
- SmileyPackCType* GetSmileyPack(MCONTACT id);
+ SmileyPackCType* GetSmileyPack(const char *pszModule);
};
extern SmileyPackCListType g_SmileyPackCStore;
diff --git a/plugins/SmileyAdd/src/dlgboxsubclass.cpp b/plugins/SmileyAdd/src/dlgboxsubclass.cpp
index 078d6e46be..1f11c44b48 100644
--- a/plugins/SmileyAdd/src/dlgboxsubclass.cpp
+++ b/plugins/SmileyAdd/src/dlgboxsubclass.cpp
@@ -33,7 +33,7 @@ struct MsgWndData : public MZeroedObject
void CreateSmileyButton(void)
{
- SmileyPackType *SmileyPack = GetSmileyPack(ProtocolName, hContact);
+ SmileyPackType *SmileyPack = GetSmileyPack(ProtocolName);
bool doSmileyButton = SmileyPack != nullptr && SmileyPack->VisibleSmileyCount() != 0;
doSmileyReplace = true;
@@ -135,7 +135,7 @@ int SmileyButtonPressed(WPARAM, LPARAM lParam)
return 0;
SmileyToolWindowParam *stwp = new SmileyToolWindowParam;
- stwp->pSmileyPack = GetSmileyPack(dat->ProtocolName, dat->hContact);
+ stwp->pSmileyPack = GetSmileyPack(dat->ProtocolName);
stwp->hWndParent = pcbc->hwndFrom;
stwp->hWndTarget = dat->hwndInput;
stwp->targetMessage = EM_REPLACESEL;
diff --git a/plugins/SmileyAdd/src/options.cpp b/plugins/SmileyAdd/src/options.cpp
index 20ec3f99be..9e592bc72c 100644
--- a/plugins/SmileyAdd/src/options.cpp
+++ b/plugins/SmileyAdd/src/options.cpp
@@ -455,8 +455,6 @@ public:
stwp->xPosition = rect.left;
stwp->yPosition = rect.bottom + 4;
stwp->direction = 1;
- stwp->hContact = 0;
-
mir_forkThread<SmileyToolWindowParam>(SmileyToolThread, stwp);
}
diff --git a/plugins/SmileyAdd/src/richcall.cpp b/plugins/SmileyAdd/src/richcall.cpp
index 3a7f0ae58a..1d9fc73d2f 100644
--- a/plugins/SmileyAdd/src/richcall.cpp
+++ b/plugins/SmileyAdd/src/richcall.cpp
@@ -132,7 +132,7 @@ static void ReplaceContactSmileys(RichEditData *rdt, const CHARRANGE &sel, bool
{
if ((rdt->inputarea && !opt.InputSmileys) || rdt->dontReplace) return;
SmileyPackCType *smcp = nullptr;
- SmileyPackType *SmileyPack = GetSmileyPack(nullptr, rdt->hContact, rdt->inputarea ? nullptr : &smcp);
+ SmileyPackType *SmileyPack = GetSmileyPack(Proto_GetBaseAccountName(rdt->hContact), rdt->inputarea ? nullptr : &smcp);
ReplaceSmileys(rdt->hwnd, SmileyPack, smcp, sel, false, ignoreLast, unFreeze);
}
diff --git a/plugins/SmileyAdd/src/services.cpp b/plugins/SmileyAdd/src/services.cpp
index bf3cbf472a..4dbfc85775 100644
--- a/plugins/SmileyAdd/src/services.cpp
+++ b/plugins/SmileyAdd/src/services.cpp
@@ -24,56 +24,23 @@ LIST<void> menuHandleArray(5);
//implementation of service functions
-SmileyPackType* GetSmileyPack(const char *proto, MCONTACT hContact, SmileyPackCType **smlc)
+SmileyPackType* GetSmileyPack(const char *proto, SmileyPackCType **smlc)
{
- hContact = DecodeMetaContact(hContact);
if (smlc)
- *smlc = g_SmileyPackCStore.GetSmileyPack(hContact);
+ *smlc = g_SmileyPackCStore.GetSmileyPack(proto);
if (proto != nullptr && IsBadStringPtrA(proto, 10))
return nullptr;
CMStringW categoryName;
- if (hContact != 0) {
- opt.ReadContactCategory(hContact, categoryName);
- if (categoryName == L"<None>") return nullptr;
- if (!categoryName.IsEmpty() && g_SmileyCategories.GetSmileyCategory(categoryName) == nullptr) {
- categoryName.Empty();
- opt.WriteContactCategory(hContact, categoryName);
- }
-
- if (categoryName.IsEmpty() && !opt.UseOneForAll) {
- char *protonam = Proto_GetBaseAccountName(hContact);
- if (protonam != nullptr) {
- DBVARIANT dbv;
- if (db_get_ws(hContact, protonam, "Transport", &dbv) == 0) {
- categoryName = dbv.pwszVal;
- db_free(&dbv);
- }
- else if (opt.UsePhysProto && db_get_ws(0, protonam, "AM_BaseProto", &dbv) == 0) {
- categoryName = L"AllProto";
- categoryName += dbv.pwszVal;
- db_free(&dbv);
- CMStringW categoryFileName = g_SmileyCategories.GetSmileyCategory(categoryName) ? g_SmileyCategories.GetSmileyCategory(categoryName)->GetFilename() : L"";
- if (categoryFileName.IsEmpty())
- categoryName = _A2T(protonam);
- }
- else
- categoryName = _A2T(protonam);
- }
- }
- }
-
- if (categoryName.IsEmpty()) {
- if (proto == nullptr || proto[0] == 0)
- categoryName = L"Standard";
- else {
- categoryName = _A2T(proto);
- if (opt.UseOneForAll) {
- SmileyCategoryType *smc = g_SmileyCategories.GetSmileyCategory(categoryName);
- if (smc == nullptr || smc->IsProto())
- categoryName = L"Standard";
- }
+ if (proto == nullptr || proto[0] == 0)
+ categoryName = L"Standard";
+ else {
+ categoryName = _A2T(proto);
+ if (opt.UseOneForAll) {
+ SmileyCategoryType *smc = g_SmileyCategories.GetSmileyCategory(categoryName);
+ if (smc == nullptr || smc->IsProto())
+ categoryName = L"Standard";
}
}
@@ -95,8 +62,7 @@ INT_PTR ReplaceSmileysCommand(WPARAM, LPARAM lParam)
else if (smrec.rangeToReplace->cpMax < 0) smrec.rangeToReplace->cpMax = LONG_MAX;
SmileyPackCType *smcp = nullptr;
- SmileyPackType *SmileyPack = GetSmileyPack(smrec.Protocolname, smrec.hContact,
- (smrec.flags & (SAFLRE_OUTGOING | SAFLRE_NOCUSTOM)) ? nullptr : &smcp);
+ SmileyPackType *SmileyPack = GetSmileyPack(smrec.Protocolname, (smrec.flags & SAFLRE_NOCUSTOM) ? nullptr : &smcp);
ReplaceSmileys(smre->hwndRichEditControl, SmileyPack, smcp, *smrec.rangeToReplace,
smrec.hContact == 0, false, false, (smre->flags & SAFLRE_FIREVIEW) ? true : false);
@@ -111,12 +77,9 @@ INT_PTR ShowSmileySelectionCommand(WPARAM, LPARAM lParam)
if (smaddInfo == nullptr) return FALSE;
HWND parent = smaddInfo->hwndParent;
- MCONTACT hContact = smaddInfo->hContact;
SmileyToolWindowParam *stwp = new SmileyToolWindowParam;
- stwp->pSmileyPack = GetSmileyPack(smaddInfo->Protocolname, hContact);
- stwp->hContact = hContact;
-
+ stwp->pSmileyPack = GetSmileyPack(smaddInfo->Protocolname);
stwp->hWndParent = parent;
stwp->hWndTarget = smaddInfo->hwndTarget;
stwp->targetMessage = smaddInfo->targetMessage;
@@ -124,7 +87,6 @@ INT_PTR ShowSmileySelectionCommand(WPARAM, LPARAM lParam)
stwp->xPosition = smaddInfo->xPosition;
stwp->yPosition = smaddInfo->yPosition;
stwp->direction = smaddInfo->Direction;
-
mir_forkThread<SmileyToolWindowParam>(SmileyToolThread, stwp);
return TRUE;
@@ -134,10 +96,8 @@ INT_PTR ShowSmileySelectionCommand(WPARAM, LPARAM lParam)
static int GetInfoCommandE(SMADD_INFO2 *smre, bool retDup)
{
if (smre == nullptr) return FALSE;
- MCONTACT hContact = smre->hContact;
-
- SmileyPackType *SmileyPack = GetSmileyPack(smre->Protocolname, hContact);
+ SmileyPackType *SmileyPack = GetSmileyPack(smre->Protocolname);
if (SmileyPack == nullptr || SmileyPack->SmileyCount() == 0) {
smre->ButtonIcon = nullptr;
smre->NumberOfSmileys = 0;
@@ -158,13 +118,11 @@ static int GetInfoCommandE(SMADD_INFO2 *smre, bool retDup)
return TRUE;
}
-
INT_PTR GetInfoCommand(WPARAM, LPARAM lParam)
{
return GetInfoCommandE((SMADD_INFO2*)lParam, false);
}
-
INT_PTR GetInfoCommand2(WPARAM, LPARAM lParam)
{
return GetInfoCommandE((SMADD_INFO2*)lParam, true);
@@ -175,15 +133,12 @@ INT_PTR GetInfoCommand2(WPARAM, LPARAM lParam)
INT_PTR ParseTextBatch(WPARAM, LPARAM lParam)
{
SMADD_BATCHPARSE2 *smre = (SMADD_BATCHPARSE2*)lParam;
-
- if (smre == nullptr) return FALSE;
- MCONTACT hContact = smre->hContact;
+ if (smre == nullptr)
+ return FALSE;
SmileyPackCType *smcp = nullptr;
- SmileyPackType *SmileyPack = GetSmileyPack(smre->Protocolname, hContact,
- (smre->flag & (SAFL_OUTGOING | SAFL_NOCUSTOM)) ? nullptr : &smcp);
-
SmileysQueueType smllist;
+ SmileyPackType *SmileyPack = GetSmileyPack(smre->Protocolname, (smre->flag & (SAFL_OUTGOING | SAFL_NOCUSTOM)) ? nullptr : &smcp);
if (smre->flag & SAFL_UNICODE)
LookupAllSmileys(SmileyPack, smcp, smre->wstr, smllist, false);
@@ -361,14 +316,29 @@ INT_PTR LoadContactSmileys(WPARAM, LPARAM lParam)
switch (cont->type) {
case 0:
- g_SmileyPackCStore.AddSmileyPack(cont->hContact, cont->path);
- NotifyEventHooks(hEvent1, (WPARAM)cont->hContact, 0);
+ g_SmileyPackCStore.AddSmileyPack(cont->pszModule, cont->path);
+ NotifyEventHooks(hEvent1, (WPARAM)cont->pszModule, 0);
break;
case 1:
- g_SmileyPackCStore.AddSmiley(cont->hContact, cont->path);
- NotifyEventHooks(hEvent1, (WPARAM)cont->hContact, 0);
+ g_SmileyPackCStore.AddSmiley(cont->pszModule, cont->path);
+ NotifyEventHooks(hEvent1, (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 {
+ CMStringW wszFileName = wszPath + findData.cFileName;
+ g_SmileyPackCStore.AddSmiley(cont->pszModule, wszFileName);
+ } while (FindNextFileW(hFind, &findData));
+ }
}
return 0;
}
diff --git a/plugins/SmileyAdd/src/services.h b/plugins/SmileyAdd/src/services.h
index eb88fdc5a7..70cad9b45f 100644
--- a/plugins/SmileyAdd/src/services.h
+++ b/plugins/SmileyAdd/src/services.h
@@ -39,7 +39,7 @@ int AccountListChanged(WPARAM wParam, LPARAM lParam);
int DbSettingChanged(WPARAM wParam, LPARAM lParam);
int ReloadColour(WPARAM, LPARAM);
-SmileyPackType* GetSmileyPack(const char* proto, MCONTACT hContact = 0, SmileyPackCType** smlc = nullptr);
+SmileyPackType* GetSmileyPack(const char* proto, SmileyPackCType** smlc = nullptr);
#endif // SMILEYADD_SERVICES_H_
diff --git a/plugins/SmileyAdd/src/smileys.cpp b/plugins/SmileyAdd/src/smileys.cpp
index d23e77b2e5..702b6e72a6 100644
--- a/plugins/SmileyAdd/src/smileys.cpp
+++ b/plugins/SmileyAdd/src/smileys.cpp
@@ -208,41 +208,6 @@ SmileyType* SmileyPackType::GetSmiley(unsigned index)
return (index < (unsigned)m_SmileyList.getCount()) ? &m_SmileyList[index] : nullptr;
}
-static DWORD_PTR ConvertServiceParam(MCONTACT hContact, const wchar_t *param)
-{
- if (param == nullptr)
- return 0;
- if (mir_wstrcmpi(L"hContact", param) == 0)
- return hContact;
- if (iswdigit(*param))
- return _wtoi(param);
-
- return (DWORD_PTR)param;
-}
-
-void SmileyType::CallSmileyService(MCONTACT hContact)
-{
- MRegexp16 srvsplit(L"(.*)\\|(.*)\\|(.*)");
- srvsplit.match(m_TriggerText);
-
- CMStringW name = srvsplit.getGroup(1);
- CMStringW par1 = srvsplit.getGroup(2);
- CMStringW par2 = srvsplit.getGroup(3);
-
- const char *proto = "";
- if (name[0] == '/') {
- proto = (const char*)Proto_GetBaseAccountName(hContact);
- if (proto == nullptr)
- return;
- }
-
- char str[MAXMODULELABELLENGTH];
- mir_snprintf(str, "%s%S", proto, name.c_str());
- CallService(str,
- ConvertServiceParam(hContact, par1.c_str()),
- ConvertServiceParam(hContact, par2.c_str()));
-}
-
SmileyPackType::~SmileyPackType()
{
if (m_hSmList != nullptr) ImageList_Destroy(m_hSmList);
diff --git a/plugins/SmileyAdd/src/smileys.h b/plugins/SmileyAdd/src/smileys.h
index 890e0538a6..bf7accdc8c 100644
--- a/plugins/SmileyAdd/src/smileys.h
+++ b/plugins/SmileyAdd/src/smileys.h
@@ -86,8 +86,6 @@ public:
void AddObject(ISmileyBase *pObject);
void RemoveObject(ISmileyBase *pObject);
- void CallSmileyService(MCONTACT hContact);
-
void SetHidden(bool hid) { SetFlagsBit(HiddenSmiley, hid); }
void SetRegEx(bool regex) { SetFlagsBit(RegExSmiley, regex); }
void SetService(bool service) { SetFlagsBit(ServiceSmiley, service); }
diff --git a/plugins/SmileyAdd/src/smltool.cpp b/plugins/SmileyAdd/src/smltool.cpp
index 1c50b5dc5b..648fa473f6 100644
--- a/plugins/SmileyAdd/src/smltool.cpp
+++ b/plugins/SmileyAdd/src/smltool.cpp
@@ -46,7 +46,6 @@ private:
int m_Direction;
UINT m_TargetMessage;
WPARAM m_TargetWParam;
- MCONTACT m_hContact;
int rowSel;
bool m_Choosing;
@@ -175,41 +174,18 @@ LRESULT SmileyToolWindowType::DialogProcedure(UINT msg, WPARAM wParam, LPARAM lP
return Result;
}
-struct smlsrvstruct
-{
- smlsrvstruct(SmileyType *tsml, MCONTACT thContact)
- : sml(tsml), hContact(thContact)
- {
- }
- SmileyType *sml;
- MCONTACT hContact;
-};
-
-void CALLBACK smileyServiceCallback(void *arg)
-{
- smlsrvstruct *p = (smlsrvstruct*)arg;
- p->sml->CallSmileyService(p->hContact);
- delete p;
-}
-
void SmileyToolWindowType::InsertSmiley(void)
{
if (m_CurrentHotTrack >= 0 && m_hWndTarget != nullptr) {
SmileyType *sml = m_pSmileyPack->GetSmiley(m_CurrentHotTrack);
- if (sml->IsService()) {
- smlsrvstruct *p = new smlsrvstruct(sml, m_hContact);
- CallFunctionAsync(smileyServiceCallback, p);
- }
- else {
- CMStringW insertText;
+ CMStringW insertText;
+ if (opt.SurroundSmileyWithSpaces) insertText = ' ';
+ insertText += sml->GetInsertText();
+ if (opt.SurroundSmileyWithSpaces) insertText += ' ';
- if (opt.SurroundSmileyWithSpaces) insertText = ' ';
- insertText += sml->GetInsertText();
- if (opt.SurroundSmileyWithSpaces) insertText += ' ';
+ SendMessage(m_hWndTarget, m_TargetMessage, m_TargetWParam, (LPARAM)insertText.c_str());
- SendMessage(m_hWndTarget, m_TargetMessage, m_TargetWParam, (LPARAM)insertText.c_str());
- }
m_Choosing = true;
DestroyWindow(m_hwndDialog);
}
@@ -469,7 +445,6 @@ void SmileyToolWindowType::InitDialog(LPARAM lParam)
m_TargetMessage = stwp->targetMessage;
m_TargetWParam = stwp->targetWParam;
m_Direction = stwp->direction;
- m_hContact = stwp->hContact;
m_CurrentHotTrack = -2;
m_CurrMouseTrack = -1;
diff --git a/plugins/SmileyAdd/src/smltool.h b/plugins/SmileyAdd/src/smltool.h
index 26221543dd..a2cdd74508 100644
--- a/plugins/SmileyAdd/src/smltool.h
+++ b/plugins/SmileyAdd/src/smltool.h
@@ -32,7 +32,6 @@ struct SmileyToolWindowParam
HWND hWndParent;
UINT targetMessage;
WPARAM targetWParam;
- MCONTACT hContact;
};
void __cdecl SmileyToolThread(SmileyToolWindowParam *stwp);
diff --git a/plugins/SmileyAdd/src/version.h b/plugins/SmileyAdd/src/version.h
index 1e0cc4ad64..fd79d40249 100644
--- a/plugins/SmileyAdd/src/version.h
+++ b/plugins/SmileyAdd/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 3
-#define __RELEASE_NUM 1
-#define __BUILD_NUM 2
+#define __RELEASE_NUM 2
+#define __BUILD_NUM 0
#include <stdver.h>