diff options
Diffstat (limited to 'src/modules/extraicons')
-rw-r--r-- | src/modules/extraicons/DefaultExtraIcons.cpp | 42 | ||||
-rw-r--r-- | src/modules/extraicons/IcolibExtraIcon.cpp | 39 | ||||
-rw-r--r-- | src/modules/extraicons/usedIcons.cpp | 43 |
3 files changed, 38 insertions, 86 deletions
diff --git a/src/modules/extraicons/DefaultExtraIcons.cpp b/src/modules/extraicons/DefaultExtraIcons.cpp index 6599be7aa6..5f848af03f 100644 --- a/src/modules/extraicons/DefaultExtraIcons.cpp +++ b/src/modules/extraicons/DefaultExtraIcons.cpp @@ -21,6 +21,7 @@ #include "m_cluiframes.h"
+#include "ExtraIcon.h"
#include "extraicons.h"
/*
@@ -38,6 +39,7 @@ static void ProtocolInit();
static void DBExtraIconsInit();
+ExtraIcon* GetExtraIcon(HANDLE id);
void DefaultExtraIcons_Load()
{
@@ -57,7 +59,7 @@ HANDLE hExtraVisibility = NULL; HANDLE hExtraChat = NULL;
HANDLE hExtraGender = NULL;
-static void SetVisibility(HANDLE hContact, int apparentMode, BOOL clear)
+static void SetVisibility(HANDLE hContact, int apparentMode, bool clear)
{
if (hContact == NULL)
return;
@@ -70,28 +72,31 @@ static void SetVisibility(HANDLE hContact, int apparentMode, BOOL clear) apparentMode = db_get_w(hContact, proto, "ApparentMode", 0);
const char *ico = NULL;
+ HANDLE hExtraIcon;
- if (DBGetContactSettingByte(hContact, proto, "ChatRoom", 0)) {
+ if ( db_get_b(hContact, proto, "ChatRoom", 0)) {
// Is chat
+ hExtraIcon = hExtraChat;
if (apparentMode == ID_STATUS_OFFLINE)
ico = "ChatActivity";
-
- if (ico != NULL || clear)
- ExtraIcon_SetIcon(hExtraChat, hContact, ico);
}
else {
// Not chat
+ hExtraIcon = hExtraVisibility;
if (apparentMode == ID_STATUS_OFFLINE)
ico = "core_main_47";
else if (apparentMode == ID_STATUS_ONLINE)
ico = "core_main_46";
+ }
- if (ico != NULL || clear)
- ExtraIcon_SetIcon(hExtraVisibility, hContact, ico);
+ if (ico != NULL || clear) {
+ ExtraIcon *extra = GetExtraIcon(hExtraIcon);
+ if (extra)
+ extra->setIconByName((int)hExtraIcon, hContact, ico);
}
}
-static void SetGender(HANDLE hContact, int gender, BOOL clear)
+static void SetGender(HANDLE hContact, int gender, bool clear)
{
if (hContact == NULL)
return;
@@ -101,11 +106,11 @@ static void SetGender(HANDLE hContact, int gender, BOOL clear) return;
if (gender <= 0)
- gender = DBGetContactSettingByte(hContact, proto, "Gender", 0);
+ gender = db_get_b(hContact, proto, "Gender", 0);
if (gender <= 0)
- gender = DBGetContactSettingByte(hContact, "UserInfo", "Gender", 0);
+ gender = db_get_b(hContact, "UserInfo", "Gender", 0);
- const char *ico = NULL;
+ const char *ico;
if (gender == 'M')
ico = "gender_male";
else if (gender == 'F')
@@ -113,8 +118,11 @@ static void SetGender(HANDLE hContact, int gender, BOOL clear) else
ico = NULL;
- if (ico != NULL || clear)
- ExtraIcon_SetIcon(hExtraGender, hContact, ico);
+ if (ico != NULL || clear) {
+ ExtraIcon *extra = GetExtraIcon(hExtraGender);
+ if (extra)
+ extra->setIconByName((int)hExtraGender, hContact, ico);
+ }
}
static void EmailOnClick(Info *info, const char *text);
@@ -202,12 +210,12 @@ static int SettingChanged(WPARAM wParam, LPARAM lParam) bool isProto = (strcmp(cws->szModule, proto) == 0);
if (isProto && strcmp(cws->szSetting, "ApparentMode") == 0) {
- SetVisibility(hContact, cws->value.type == DBVT_DELETED ? 0 : cws->value.wVal, TRUE);
+ SetVisibility(hContact, cws->value.type == DBVT_DELETED ? 0 : cws->value.wVal, true);
return 0;
}
if (strcmp(cws->szSetting, "Gender") == 0 && (isProto || strcmp(cws->szModule, "UserInfo") == 0)) {
- SetGender(hContact, cws->value.type == DBVT_DELETED ? 0 : cws->value.bVal, TRUE);
+ SetGender(hContact, cws->value.type == DBVT_DELETED ? 0 : cws->value.bVal, true);
return 0;
}
@@ -284,8 +292,8 @@ static void DBExtraIconsInit() HANDLE hContact = db_find_first();
while (hContact != NULL) {
SetExtraIcons(hContact);
- SetVisibility(hContact, -1, FALSE);
- SetGender(hContact, -1, FALSE);
+ SetVisibility(hContact, -1, false);
+ SetGender(hContact, -1, false);
hContact = db_find_next(hContact);
}
diff --git a/src/modules/extraicons/IcolibExtraIcon.cpp b/src/modules/extraicons/IcolibExtraIcon.cpp index bf598c3e7e..e5727eac53 100644 --- a/src/modules/extraicons/IcolibExtraIcon.cpp +++ b/src/modules/extraicons/IcolibExtraIcon.cpp @@ -24,6 +24,8 @@ #include "extraicons.h"
#include "usedIcons.h"
+#include "..\icolib\IcoLib.h"
+
IcolibExtraIcon::IcolibExtraIcon(int _id, const char *_name, const TCHAR *_description, const char *_descIcon,
MIRANDAHOOKPARAM _OnClick, LPARAM _param) :
BaseExtraIcon(_id, _name, _description, _descIcon, _OnClick, _param)
@@ -74,7 +76,7 @@ int IcolibExtraIcon::setIcon(int id, HANDLE hContact, HANDLE hIcoLib) if (hIcoLib == INVALID_HANDLE_VALUE)
hIcoLib = NULL;
- if (isEnabled()) {
+ if ( isEnabled()) {
DBVARIANT dbv;
if ( !DBGetContactSettingString(hContact, MODULE_NAME, name.c_str(), &dbv)) {
if (!IsEmpty(dbv.pszVal))
@@ -84,19 +86,12 @@ int IcolibExtraIcon::setIcon(int id, HANDLE hContact, HANDLE hIcoLib) }
}
- char szId[30];
- wsprintfA(szId, "{%p}", hIcoLib);
- storeIcon(hContact, szId);
-
- if (isEnabled()) {
- HANDLE hImage;
- if (hIcoLib == NULL)
- hImage = INVALID_HANDLE_VALUE;
- else
- hImage = AddIcon(hIcoLib);
+ IconItem *p = (IconItem*)hIcoLib;
+ char *szName = (p) ? p->name : NULL;
+ storeIcon(hContact, szName);
- return ClistSetExtraIcon(hContact, hImage);
- }
+ if ( isEnabled())
+ return ClistSetExtraIcon(hContact, (hIcoLib == NULL) ? INVALID_HANDLE_VALUE : AddIcon(szName));
return 0;
}
@@ -109,7 +104,7 @@ int IcolibExtraIcon::setIconByName(int id, HANDLE hContact, const char *icon) if (icon == INVALID_HANDLE_VALUE)
icon = NULL;
- if (isEnabled()) {
+ if ( isEnabled()) {
DBVARIANT dbv;
if ( !DBGetContactSettingString(hContact, MODULE_NAME, name.c_str(), &dbv)) {
if (!IsEmpty(dbv.pszVal))
@@ -121,15 +116,8 @@ int IcolibExtraIcon::setIconByName(int id, HANDLE hContact, const char *icon) storeIcon(hContact, (char*)icon);
- if (isEnabled()) {
- HANDLE hImage;
- if ( IsEmpty(icon))
- hImage = INVALID_HANDLE_VALUE;
- else
- hImage = AddIcon(icon);
-
- return ClistSetExtraIcon(hContact, hImage);
- }
+ if ( isEnabled())
+ return ClistSetExtraIcon(hContact, ( IsEmpty(icon)) ? INVALID_HANDLE_VALUE : AddIcon(icon));
return 0;
}
@@ -141,7 +129,6 @@ void IcolibExtraIcon::storeIcon(HANDLE hContact, void *icon) const char *icolibName = (const char *) icon;
if ( IsEmpty(icolibName))
- db_unset(hContact, MODULE_NAME, name.c_str());
- else
- db_set_s(hContact, MODULE_NAME, name.c_str(), icolibName);
+ icolibName = "";
+ db_set_s(hContact, MODULE_NAME, name.c_str(), icolibName);
}
diff --git a/src/modules/extraicons/usedIcons.cpp b/src/modules/extraicons/usedIcons.cpp index 682573168b..3b2eb3f6a6 100644 --- a/src/modules/extraicons/usedIcons.cpp +++ b/src/modules/extraicons/usedIcons.cpp @@ -31,14 +31,6 @@ struct Icon name(icolibName), hIcoLib(0), refCount(0), hImage(INVALID_HANDLE_VALUE)
{
}
-
- Icon(HANDLE _hIcolib) :
- hIcoLib(_hIcolib), refCount(0), hImage(INVALID_HANDLE_VALUE)
- {
- char szId[30];
- wsprintfA(szId, "{%p}", _hIcolib);
- name = szId;
- }
};
static vector<Icon> usedIcons;
@@ -71,34 +63,6 @@ static Icon* FindIcon(const char *icolibName) return icon;
}
-static Icon* FindIcon(HANDLE hIcolib)
-{
- Icon *icon = NULL;
-
- for (unsigned int i = 0; i < usedIcons.size(); i++) {
- Icon *tmp = &usedIcons[i];
- if (tmp->hImage == hIcolib) {
- icon = tmp;
- break;
- }
- }
-
- if (icon == NULL) {
- usedIcons.push_back( Icon(hIcolib));
- icon = &usedIcons[usedIcons.size() - 1];
- }
-
- if (icon->hImage == INVALID_HANDLE_VALUE) {
- HICON hIcon = Skin_GetIconByHandle(icon->hIcoLib);
- if (hIcon != NULL) {
- icon->hImage = ExtraIcon_Add(hIcon);
- Skin_ReleaseIcon(hIcon);
- }
- }
-
- return icon;
-}
-
HANDLE GetIcon(const char *icolibName)
{
return FindIcon(icolibName)->hImage;
@@ -111,13 +75,6 @@ HANDLE AddIcon(const char *icolibName) return icon->hImage;
}
-HANDLE AddIcon(HANDLE hIcolib)
-{
- Icon *icon = FindIcon(hIcolib);
- icon->refCount++;
- return icon->hImage;
-}
-
void RemoveIcon(const char *icolibName)
{
for (unsigned int i = 0; i < usedIcons.size(); i++) {
|