From b88e43ee05321968fa6ab3ae00155d5412cb9006 Mon Sep 17 00:00:00 2001 From: pescuma Date: Tue, 7 Apr 2009 03:47:48 +0000 Subject: extraicons: initial import git-svn-id: http://pescuma.googlecode.com/svn/trunk/Miranda@155 c086bb3d-8645-0410-b8da-73a8550f86e7 --- Plugins/extraicons/IcolibExtraIcon.cpp | 102 +++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 Plugins/extraicons/IcolibExtraIcon.cpp (limited to 'Plugins/extraicons/IcolibExtraIcon.cpp') diff --git a/Plugins/extraicons/IcolibExtraIcon.cpp b/Plugins/extraicons/IcolibExtraIcon.cpp new file mode 100644 index 0000000..406b43b --- /dev/null +++ b/Plugins/extraicons/IcolibExtraIcon.cpp @@ -0,0 +1,102 @@ +/* + Copyright (C) 2009 Ricardo Pescuma Domenecci + + This is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this file; see the file license.txt. If + not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +#include "commons.h" + +IcolibExtraIcon::IcolibExtraIcon(const char *name, const char *description, const char *descIcon) : + ExtraIcon(name, description, descIcon) +{ + char setting[512]; + mir_snprintf(setting, MAX_REGS(setting), "%s/%s", MODULE_NAME, name); + CallService(MS_DB_SETSETTINGRESIDENT, TRUE, (WPARAM) setting); +} + +IcolibExtraIcon::~IcolibExtraIcon() +{ +} + +int IcolibExtraIcon::getType() const +{ + return EXTRAICON_TYPE_ICOLIB; +} + +bool IcolibExtraIcon::needToRebuildIcons() +{ + return false; +} + +void IcolibExtraIcon::rebuildIcons() +{ +} + +void IcolibExtraIcon::applyIcon(HANDLE hContact) +{ + if (!isEnabled() || hContact == NULL) + return; + + HANDLE hImage = NULL; + + DBVARIANT dbv = { 0 }; + if (!DBGetContactSettingString(hContact, MODULE_NAME, name.c_str(), &dbv)) + { + if (!IsEmpty(dbv.pszVal)) + hImage = GetIcon(dbv.pszVal); + + DBFreeVariant(&dbv); + } + + Clist_SetExtraIcon(hContact, slot, hImage); +} + +int IcolibExtraIcon::setIcon(HANDLE hContact, void *icon) +{ + if (hContact == NULL) + return -1; + + const char *icolibName = (const char *) icon; + + if (isEnabled()) + { + DBVARIANT dbv = { 0 }; + if (!DBGetContactSettingString(hContact, MODULE_NAME, name.c_str(), &dbv)) + { + if (!IsEmpty(dbv.pszVal)) + RemoveIcon(dbv.pszVal); + + DBFreeVariant(&dbv); + } + } + + if (IsEmpty(icolibName)) + DBDeleteContactSetting(hContact, MODULE_NAME, name.c_str()); + else + DBWriteContactSettingString(hContact, MODULE_NAME, name.c_str(), icolibName); + + if (isEnabled()) + { + HANDLE hImage = NULL; + if (!IsEmpty(icolibName)) + hImage = AddIcon(icolibName); + + return Clist_SetExtraIcon(hContact, slot, hImage); + } + + return 0; +} + -- cgit v1.2.3