diff options
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/extraicons/BaseExtraIcon.cpp | 16 | ||||
-rw-r--r-- | src/modules/extraicons/CallbackExtraIcon.cpp | 15 | ||||
-rw-r--r-- | src/modules/extraicons/DefaultExtraIcons.cpp | 141 | ||||
-rw-r--r-- | src/modules/extraicons/ExtraIcon.h | 6 | ||||
-rw-r--r-- | src/modules/extraicons/ExtraIconGroup.cpp | 3 | ||||
-rw-r--r-- | src/modules/extraicons/IcolibExtraIcon.cpp | 44 | ||||
-rw-r--r-- | src/modules/extraicons/extraicons.cpp | 4 | ||||
-rw-r--r-- | src/modules/extraicons/options_ei.cpp | 5 | ||||
-rw-r--r-- | src/modules/extraicons/usedIcons.cpp | 5 |
9 files changed, 95 insertions, 144 deletions
diff --git a/src/modules/extraicons/BaseExtraIcon.cpp b/src/modules/extraicons/BaseExtraIcon.cpp index d8016f56be..5d9caf76ac 100644 --- a/src/modules/extraicons/BaseExtraIcon.cpp +++ b/src/modules/extraicons/BaseExtraIcon.cpp @@ -25,8 +25,8 @@ Boston, MA 02111-1307, USA. BaseExtraIcon::BaseExtraIcon(int id, const char *name, const TCHAR *description, const char *descIcon, MIRANDAHOOKPARAM OnClick, LPARAM param) :
ExtraIcon(name), id(id), OnClick(OnClick), onClickParam(param),
- tszDescription( mir_tstrdup(description)),
- szDescIcon( mir_strdup(descIcon))
+ tszDescription(mir_tstrdup(description)),
+ szDescIcon(mir_strdup(descIcon))
{
}
@@ -36,8 +36,8 @@ BaseExtraIcon::~BaseExtraIcon() void BaseExtraIcon::setOnClick(MIRANDAHOOKPARAM OnClick, LPARAM param)
{
- this->OnClick = OnClick;
- this->onClickParam = param;
+ OnClick = OnClick;
+ onClickParam = param;
}
int BaseExtraIcon::getID() const
@@ -55,7 +55,7 @@ void BaseExtraIcon::setDescription(const TCHAR *desc) tszDescription = mir_tstrdup(desc);
}
-const char *BaseExtraIcon::getDescIcon() const
+const char* BaseExtraIcon::getDescIcon() const
{
return szDescIcon;
}
@@ -67,10 +67,8 @@ void BaseExtraIcon::setDescIcon(const char *icon) void BaseExtraIcon::onClick(HANDLE hContact)
{
- if (OnClick == NULL)
- return;
-
- OnClick((WPARAM) hContact, (LPARAM) ConvertToClistSlot(slot), onClickParam);
+ if (OnClick != NULL)
+ OnClick((WPARAM)hContact, (LPARAM)ConvertToClistSlot(slot), onClickParam);
}
int BaseExtraIcon::ClistSetExtraIcon(HANDLE hContact, HANDLE hImage)
diff --git a/src/modules/extraicons/CallbackExtraIcon.cpp b/src/modules/extraicons/CallbackExtraIcon.cpp index 3e7229d5ca..b271aef8bb 100644 --- a/src/modules/extraicons/CallbackExtraIcon.cpp +++ b/src/modules/extraicons/CallbackExtraIcon.cpp @@ -23,10 +23,10 @@ Boston, MA 02111-1307, USA. #include "extraicons.h"
-CallbackExtraIcon::CallbackExtraIcon(int id, const char *name, const TCHAR *description, const char *descIcon,
- MIRANDAHOOK RebuildIcons, MIRANDAHOOK ApplyIcon, MIRANDAHOOKPARAM OnClick, LPARAM param) :
- BaseExtraIcon(id, name, description, descIcon, OnClick, param), RebuildIcons(RebuildIcons), ApplyIcon(ApplyIcon),
- needToRebuild(true)
+CallbackExtraIcon::CallbackExtraIcon(int _id, const char *_name, const TCHAR *_description, const char *_descIcon,
+ MIRANDAHOOK _RebuildIcons, MIRANDAHOOK _ApplyIcon, MIRANDAHOOKPARAM _OnClick, LPARAM _param) :
+ BaseExtraIcon(_id, _name, _description, _descIcon, _OnClick, _param),
+ RebuildIcons(_RebuildIcons), ApplyIcon(_ApplyIcon), needToRebuild(true)
{
}
@@ -41,13 +41,12 @@ int CallbackExtraIcon::getType() const void CallbackExtraIcon::rebuildIcons()
{
- if (!isEnabled())
- {
+ if (!isEnabled()) {
needToRebuild = true;
return;
}
- needToRebuild = false;
+ needToRebuild = false;
RebuildIcons(0, 0);
}
@@ -59,7 +58,7 @@ void CallbackExtraIcon::applyIcon(HANDLE hContact) if (needToRebuild)
rebuildIcons();
- ApplyIcon((WPARAM) hContact, 0);
+ ApplyIcon((WPARAM)hContact, 0);
}
int CallbackExtraIcon::setIcon(int id, HANDLE hContact, HANDLE icon)
diff --git a/src/modules/extraicons/DefaultExtraIcons.cpp b/src/modules/extraicons/DefaultExtraIcons.cpp index 79bb0677ff..5af212d444 100644 --- a/src/modules/extraicons/DefaultExtraIcons.cpp +++ b/src/modules/extraicons/DefaultExtraIcons.cpp @@ -28,13 +28,10 @@ Boston, MA 02111-1307, USA. ExtraIcon* GetExtraIcon(HANDLE id);
-// DB extra icons ///////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////
+// DB extra icons
-struct Info;
-
-HANDLE hExtraVisibility = NULL;
-HANDLE hExtraChat = NULL;
-HANDLE hExtraGender = NULL;
+HANDLE hExtraVisibility, hExtraChat, hExtraGender, hExtraProto;
static void SetVisibility(HANDLE hContact, int apparentMode, bool clear)
{
@@ -42,7 +39,7 @@ static void SetVisibility(HANDLE hContact, int apparentMode, bool clear) return;
char *proto = GetContactProto(hContact);
- if ( IsEmpty(proto))
+ if (IsEmpty(proto))
return;
if (apparentMode <= 0)
@@ -50,7 +47,7 @@ static void SetVisibility(HANDLE hContact, int apparentMode, bool clear) HANDLE hExtraIcon, hIcolib = NULL;
- if ( db_get_b(hContact, proto, "ChatRoom", 0)) {
+ if (db_get_b(hContact, proto, "ChatRoom", 0)) {
// Is chat
hExtraIcon = hExtraChat;
if (apparentMode == ID_STATUS_OFFLINE)
@@ -78,7 +75,7 @@ static void SetGender(HANDLE hContact, int gender, bool clear) return;
char *proto = GetContactProto(hContact);
- if ( IsEmpty(proto))
+ if (IsEmpty(proto))
return;
if (gender <= 0)
@@ -101,32 +98,15 @@ static void SetGender(HANDLE hContact, int gender, bool clear) }
}
-static void EmailOnClick(Info *info, const char *text);
-static void HomepageOnClick(Info *info, const char *text);
-static void DefaultSetIcon(HANDLE hContact, Info *info, const char *text);
-
struct Info
{
const char *name;
const char *desc;
int iSkinIcon;
const char *db[8];
- void (*SetIcon)(HANDLE hContact, Info *info, const char *text);
- void (*OnClick)(Info *info, const char *text);
+ void(*OnClick)(Info *info, const char *text);
HANDLE hIcolib, hExtraIcon;
-}
-static infos[] =
-{
- { "homepage", "Homepage", SKINICON_EVENT_URL,
- { NULL, "Homepage", "UserInfo", "Homepage" },
- DefaultSetIcon, &HomepageOnClick },
- { "sms", "Phone/SMS", SKINICON_OTHER_SMS,
- { NULL, "Cellular", "UserInfo", "Cellular", "UserInfo", "Phone", "UserInfo", "MyPhone0" },
- DefaultSetIcon, NULL },
- { "email", "E-mail", SKINICON_OTHER_SENDEMAIL,
- { NULL, "e-mail", "UserInfo", "e-mail", "UserInfo", "Mye-mail0" },
- DefaultSetIcon, &EmailOnClick },
};
static void EmailOnClick(Info *info, const char *text)
@@ -141,10 +121,18 @@ static void HomepageOnClick(Info *info, const char *text) ShellExecuteA(NULL, "open", text, NULL, NULL, SW_SHOW);
}
-static void DefaultSetIcon(HANDLE hContact, Info *info, const char *text)
+static Info infos[] =
{
- ExtraIcon_SetIcon(info->hExtraIcon, hContact, text ? info->hIcolib : NULL);
-}
+ { "homepage", "Homepage", SKINICON_EVENT_URL,
+ { NULL, "Homepage", "UserInfo", "Homepage" },
+ &HomepageOnClick },
+ { "sms", "Phone/SMS", SKINICON_OTHER_SMS,
+ { NULL, "Cellular", "UserInfo", "Cellular", "UserInfo", "Phone", "UserInfo", "MyPhone0" },
+ NULL },
+ { "email", "E-mail", SKINICON_OTHER_SENDEMAIL,
+ { NULL, "e-mail", "UserInfo", "e-mail", "UserInfo", "Mye-mail0" },
+ &EmailOnClick },
+};
static void SetExtraIcons(HANDLE hContact)
{
@@ -158,18 +146,14 @@ static void SetExtraIcons(HANDLE hContact) for (unsigned int i = 0; i < SIZEOF(infos); i++) {
Info &p = infos[i];
- bool show = false;
- for (unsigned int j = 0; !show && j < SIZEOF(p.db); j += 2) {
+ for (unsigned int j = 0; j < SIZEOF(p.db); j += 2) {
if (p.db[j + 1] == NULL)
break;
- DBVARIANT dbv;
- if (!db_get_s(hContact, p.db[j] == NULL ? proto : p.db[j], p.db[j+1], &dbv)) {
- if (!IsEmpty(dbv.pszVal)) {
- p.SetIcon(hContact, &p, dbv.pszVal);
- show = true;
- }
- db_free(&dbv);
+ ptrA szValue(db_get_sa(hContact, p.db[j] == NULL ? proto : p.db[j], p.db[j + 1]));
+ if (!IsEmpty(szValue)) {
+ ExtraIcon_SetIcon(p.hExtraIcon, hContact, szValue);
+ break;
}
}
}
@@ -178,15 +162,14 @@ static void SetExtraIcons(HANDLE hContact) static int SettingChanged(WPARAM wParam, LPARAM lParam)
{
HANDLE hContact = (HANDLE)wParam;
- DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*) lParam;
-
if (hContact == NULL)
return 0;
char *proto = GetContactProto(hContact);
- if ( IsEmpty(proto))
+ if (IsEmpty(proto))
return 0;
+ DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)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);
@@ -212,8 +195,7 @@ static int SettingChanged(WPARAM wParam, LPARAM lParam) continue;
bool show = (cws->value.type != DBVT_DELETED && !IsEmpty(cws->value.pszVal));
- p.SetIcon(hContact, &p, show ? cws->value.pszVal : NULL);
-
+ ExtraIcon_SetIcon(p.hExtraIcon, hContact, show ? cws->value.pszVal : NULL);
break;
}
}
@@ -232,7 +214,7 @@ static int DefaultOnClick(WPARAM wParam, LPARAM lParam, LPARAM param) return 0;
char *proto = GetContactProto(hContact);
- if ( IsEmpty(proto))
+ if (IsEmpty(proto))
return 0;
bool found = false;
@@ -240,45 +222,47 @@ static int DefaultOnClick(WPARAM wParam, LPARAM lParam, LPARAM param) if (p->db[j + 1] == NULL)
break;
- DBVARIANT dbv;
- if ( !db_get_s(hContact, p->db[j] == NULL ? proto : p->db[j], p->db[j+1], &dbv)) {
- if (!IsEmpty(dbv.pszVal)) {
- p->OnClick(p, dbv.pszVal);
- found = true;
- }
-
- db_free(&dbv);
+ ptrA szValue(db_get_sa(hContact, p->db[j] == NULL ? proto : p->db[j], p->db[j + 1]));
+ if (!IsEmpty(szValue)) {
+ p->OnClick(p, szValue);
+ found = true;
}
}
return 0;
}
-// Protocol /////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////
+// Protocol icon
struct ProtoInfo
{
- string proto;
+ ProtoInfo(LPCSTR _proto, HANDLE _image) :
+ proto(mir_strdup(_proto)),
+ hImage(_image)
+ {}
+
+ ptrA proto;
HANDLE hImage;
};
-vector<ProtoInfo> protos;
+static int CompareProtos(const ProtoInfo *p1, const ProtoInfo *p2)
+{ return strcmp(p1->proto, p2->proto);
+}
-static HANDLE hExtraProto;
+OBJLIST<ProtoInfo> arProtos(10, CompareProtos);
static int ProtocolRebuildIcons(WPARAM wParam, LPARAM lParam)
{
- protos.clear();
+ arProtos.destroy();
return 0;
}
-static ProtoInfo *FindProto(const char * proto)
+static ProtoInfo* FindProto(const char *proto)
{
- for (unsigned int i = 0; i < protos.size(); i++) {
- ProtoInfo *pi = &protos[i];
- if (strcmp(pi->proto.c_str(), proto) == 0)
- return pi;
- }
+ ProtoInfo *p = arProtos.find((ProtoInfo*)&proto);
+ if (p)
+ return p;
HICON hIcon = LoadSkinnedProtoIcon(proto, ID_STATUS_ONLINE);
if (hIcon == NULL)
@@ -288,43 +272,36 @@ static ProtoInfo *FindProto(const char * proto) if (hImage == INVALID_HANDLE_VALUE)
return NULL;
- ProtoInfo tmp;
- tmp.proto = proto;
- tmp.hImage = hImage;
- protos.push_back(tmp);
-
- return &protos[protos.size() - 1];
+ p = new ProtoInfo(proto, hImage);
+ arProtos.insert(p);
+ return p;
}
static int ProtocolApplyIcon(WPARAM wParam, LPARAM lParam)
{
HANDLE hContact = (HANDLE)wParam;
-
char *proto = GetContactProto(hContact);
- if ( IsEmpty(proto))
+ if (IsEmpty(proto))
return 0;
- ProtoInfo *pi = FindProto(proto);
-
HANDLE hImage = INVALID_HANDLE_VALUE;
+ ProtoInfo *pi = FindProto(proto);
if (pi != NULL)
hImage = pi->hImage;
ExtraIcon_SetIcon(hExtraProto, hContact, hImage);
-
return 0;
}
static int ProtocolOnClick(WPARAM wParam, LPARAM lParam, LPARAM param)
{
- HANDLE hContact = (HANDLE)wParam;
- if (hContact == NULL)
- return 0;
-
- CallService(MS_USERINFO_SHOWDIALOG, (WPARAM) hContact, 0);
+ if (wParam)
+ CallService(MS_USERINFO_SHOWDIALOG, wParam, 0);
return 0;
}
+////////////////////////////////////////////////////////////////////////////////////////
+
void DefaultExtraIcons_Load()
{
hExtraChat = ExtraIcon_Register("chat_activity", LPGEN("Chat activity"), "ChatActivity");
@@ -333,11 +310,11 @@ void DefaultExtraIcons_Load() hExtraProto = ExtraIcon_Register("protocol", "Account", LoadSkinnedIconName(SKINICON_OTHER_ACCMGR),
&ProtocolRebuildIcons, &ProtocolApplyIcon, &ProtocolOnClick);
- for (unsigned int i = 0; i < SIZEOF(infos); i++) {
+ for (int i = 0; i < SIZEOF(infos); i++) {
Info &p = infos[i];
p.hIcolib = LoadSkinnedIconHandle(p.iSkinIcon);
if (p.OnClick)
- p.hExtraIcon = ExtraIcon_Register(p.name, p.desc, LoadSkinnedIconName(p.iSkinIcon), DefaultOnClick, (LPARAM) &p);
+ p.hExtraIcon = ExtraIcon_Register(p.name, p.desc, LoadSkinnedIconName(p.iSkinIcon), DefaultOnClick, (LPARAM)&p);
else
p.hExtraIcon = ExtraIcon_Register(p.name, p.desc, LoadSkinnedIconName(p.iSkinIcon));
}
diff --git a/src/modules/extraicons/ExtraIcon.h b/src/modules/extraicons/ExtraIcon.h index dd76607cb9..29aa687c95 100644 --- a/src/modules/extraicons/ExtraIcon.h +++ b/src/modules/extraicons/ExtraIcon.h @@ -156,10 +156,10 @@ public: virtual void onClick(HANDLE hContact);
virtual int setIcon(int id, HANDLE hContact, HANDLE icon);
- virtual int setIconByName(int id, HANDLE hContact, const char* icon);
+ virtual int setIconByName(int id, HANDLE hContact, const char *icon);
- virtual const TCHAR *getDescription() const;
- virtual const char *getDescIcon() const;
+ virtual const TCHAR* getDescription() const;
+ virtual const char* getDescIcon() const;
virtual int getType() const;
virtual int getPosition() const;
diff --git a/src/modules/extraicons/ExtraIconGroup.cpp b/src/modules/extraicons/ExtraIconGroup.cpp index 0be86e5008..5d21599ba1 100644 --- a/src/modules/extraicons/ExtraIconGroup.cpp +++ b/src/modules/extraicons/ExtraIconGroup.cpp @@ -39,8 +39,7 @@ void ExtraIconGroup::addExtraIcon(BaseExtraIcon *extra) items.push_back(extra);
CMString description;
- for (unsigned int i = 0; i < items.size(); i++)
- {
+ for (unsigned int i = 0; i < items.size(); i++) {
if (i > 0)
description += _T(" / ");
description += items[i]->getDescription();
diff --git a/src/modules/extraicons/IcolibExtraIcon.cpp b/src/modules/extraicons/IcolibExtraIcon.cpp index 832d15f350..8b77e29cb5 100644 --- a/src/modules/extraicons/IcolibExtraIcon.cpp +++ b/src/modules/extraicons/IcolibExtraIcon.cpp @@ -53,13 +53,9 @@ void IcolibExtraIcon::applyIcon(HANDLE hContact) HANDLE hImage = INVALID_HANDLE_VALUE;
- DBVARIANT dbv;
- if ( !db_get_s(hContact, MODULE_NAME, name.c_str(), &dbv)) {
- if (!IsEmpty(dbv.pszVal))
- hImage = GetIcon(dbv.pszVal);
-
- db_free(&dbv);
- }
+ ptrA szIconName(db_get_sa(hContact, MODULE_NAME, name.c_str()));
+ if (!IsEmpty(szIconName))
+ hImage = GetIcon(szIconName);
ClistSetExtraIcon(hContact, hImage);
}
@@ -72,21 +68,17 @@ int IcolibExtraIcon::setIcon(int id, HANDLE hContact, HANDLE hIcoLib) if (hIcoLib == INVALID_HANDLE_VALUE)
hIcoLib = NULL;
- if ( isEnabled()) {
- DBVARIANT dbv;
- if ( !db_get_s(hContact, MODULE_NAME, name.c_str(), &dbv)) {
- if (!IsEmpty(dbv.pszVal))
- RemoveIcon(dbv.pszVal);
-
- db_free(&dbv);
- }
+ if (isEnabled()) {
+ ptrA szIconName(db_get_sa(hContact, MODULE_NAME, name.c_str()));
+ if (!IsEmpty(szIconName))
+ RemoveIcon(szIconName);
}
IcolibItem *p = (IcolibItem*)hIcoLib;
char *szName = (p) ? p->name : NULL;
storeIcon(hContact, szName);
- if ( isEnabled())
+ if (isEnabled())
return ClistSetExtraIcon(hContact, (hIcoLib == NULL) ? INVALID_HANDLE_VALUE : AddIcon(szName));
return 0;
@@ -100,20 +92,16 @@ int IcolibExtraIcon::setIconByName(int id, HANDLE hContact, const char *icon) if (icon == INVALID_HANDLE_VALUE)
icon = NULL;
- if ( isEnabled()) {
- DBVARIANT dbv;
- if ( !db_get_s(hContact, MODULE_NAME, name.c_str(), &dbv)) {
- if (!IsEmpty(dbv.pszVal))
- RemoveIcon(dbv.pszVal);
-
- db_free(&dbv);
- }
+ if (isEnabled()) {
+ ptrA szIconName(db_get_sa(hContact, MODULE_NAME, name.c_str()));
+ if (!IsEmpty(szIconName))
+ RemoveIcon(szIconName);
}
storeIcon(hContact, (char*)icon);
- if ( isEnabled())
- return ClistSetExtraIcon(hContact, ( IsEmpty(icon)) ? INVALID_HANDLE_VALUE : AddIcon(icon));
+ if (isEnabled())
+ return ClistSetExtraIcon(hContact, (IsEmpty(icon)) ? INVALID_HANDLE_VALUE : AddIcon(icon));
return 0;
}
@@ -123,8 +111,8 @@ void IcolibExtraIcon::storeIcon(HANDLE hContact, void *icon) if (hContact == NULL)
return;
- const char *icolibName = (const char *) icon;
- if ( IsEmpty(icolibName))
+ 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);
diff --git a/src/modules/extraicons/extraicons.cpp b/src/modules/extraicons/extraicons.cpp index 6de316c5a6..420be4b808 100644 --- a/src/modules/extraicons/extraicons.cpp +++ b/src/modules/extraicons/extraicons.cpp @@ -29,8 +29,6 @@ Boston, MA 02111-1307, USA. // Prototypes ///////////////////////////////////////////////////////////////////////////
-typedef vector<ExtraIcon*>::iterator IconIter;
-
int SortFunc(const ExtraIcon *p1, const ExtraIcon *p2)
{
int ret = p1->getPosition() - p2->getPosition();
@@ -170,7 +168,7 @@ static void LoadGroups(vector<ExtraIconGroup *> &groups) }
}
-static ExtraIconGroup * IsInGroup(vector<ExtraIconGroup *> &groups, BaseExtraIcon *extra)
+static ExtraIconGroup* IsInGroup(vector<ExtraIconGroup *> &groups, BaseExtraIcon *extra)
{
for (unsigned int i = 0; i < groups.size(); i++) {
ExtraIconGroup *group = groups[i];
diff --git a/src/modules/extraicons/options_ei.cpp b/src/modules/extraicons/options_ei.cpp index cf82b557fb..369efa6315 100644 --- a/src/modules/extraicons/options_ei.cpp +++ b/src/modules/extraicons/options_ei.cpp @@ -31,14 +31,11 @@ int SortFunc(const ExtraIcon *p1, const ExtraIcon *p2); BOOL ScreenToClient(HWND hWnd, LPRECT lpRect)
{
- BOOL ret;
POINT pt;
-
pt.x = lpRect->left;
pt.y = lpRect->top;
- ret = ScreenToClient(hWnd, &pt);
-
+ BOOL ret = ScreenToClient(hWnd, &pt);
if (!ret)
return ret;
diff --git a/src/modules/extraicons/usedIcons.cpp b/src/modules/extraicons/usedIcons.cpp index 882b8259fe..895ca78f8d 100644 --- a/src/modules/extraicons/usedIcons.cpp +++ b/src/modules/extraicons/usedIcons.cpp @@ -82,11 +82,6 @@ void RemoveIcon(const char *icolibName) icon->refCount--;
}
-static bool NotUsedIcon(const Icon &icon)
-{
- return icon.refCount <= 0;
-}
-
void ResetIcons()
{
for (int i = usedIcons.getCount()-1; i >= 0; i--) {
|