From 3892d0da37e70a6c0106e57dad835e9a67933b02 Mon Sep 17 00:00:00 2001 From: pescuma Date: Thu, 23 Apr 2009 04:31:27 +0000 Subject: extraicons: start of group code git-svn-id: http://pescuma.googlecode.com/svn/trunk/Miranda@168 c086bb3d-8645-0410-b8da-73a8550f86e7 --- Plugins/extraicons/ExtraIconGroup.cpp | 162 ++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 Plugins/extraicons/ExtraIconGroup.cpp (limited to 'Plugins/extraicons/ExtraIconGroup.cpp') diff --git a/Plugins/extraicons/ExtraIconGroup.cpp b/Plugins/extraicons/ExtraIconGroup.cpp new file mode 100644 index 0000000..48ff791 --- /dev/null +++ b/Plugins/extraicons/ExtraIconGroup.cpp @@ -0,0 +1,162 @@ +/* + Copyright (C) 2009void ExtraIconGroup::storeIcon(int id, HANDLE hContact, void *icon) + { + } + + 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" + +ExtraIconGroup::ExtraIconGroup(int id, const char *name) : + ExtraIcon(id, name), setValidExtraIcon(false) +{ + char setting[512]; + mir_snprintf(setting, MAX_REGS(setting), "%s/%s", MODULE_NAME, name); + CallService(MS_DB_SETSETTINGRESIDENT, TRUE, (WPARAM) setting); +} + +ExtraIconGroup::~ExtraIconGroup() +{ + items.clear(); +} + +void ExtraIconGroup::addExtraIcon(ExtraIcon *extra) +{ + items.push_back(extra); + + description = ""; + for (unsigned int i = 0; i < items.size(); ++i) + { + if (i > 0) + description += " / "; + description += items[i]->getDescription(); + } +} + +void ExtraIconGroup::rebuildIcons() +{ + for (unsigned int i = 0; i < items.size(); ++i) + items[i]->rebuildIcons(); +} + +void ExtraIconGroup::applyIcon(HANDLE hContact) +{ + if (hContact == NULL) + return; + + setValidExtraIcon = false; + + unsigned int i; + for (i = 0; !setValidExtraIcon && i < items.size(); ++i) + items[i]->applyIcon(hContact); + + DBWriteContactSettingDword(hContact, MODULE_NAME, name.c_str(), setValidExtraIcon ? items[i]->getID() : 0); +} + +ExtraIcon * ExtraIconGroup::getCurrentItem(HANDLE hContact) const +{ + int id = (int) DBGetContactSettingDword(hContact, MODULE_NAME, name.c_str(), 0); + if (id < 1) + return NULL; + + for (unsigned int i = 0; i < items.size(); ++i) + if (id == items[i]->getID()) + return items[i]; + + return NULL; +} + +void ExtraIconGroup::onClick(HANDLE hContact) +{ + ExtraIcon *extra = getCurrentItem(hContact); + if (extra != NULL) + extra->onClick(hContact); +} + +int ExtraIconGroup::setIcon(int id, HANDLE hContact, void *icon) +{ + ExtraIcon *current = getCurrentItem(hContact); + int currentPos = items.size(); + ExtraIcon *store = NULL; + int storePos = items.size(); + for (unsigned int i = 0; i < items.size(); ++i) + { + if (items[i]->getID() == id) + { + store = items[i]; + storePos = i; + } + + if (items[i] == current) + { + currentPos = i; + } + } + + if (store == NULL) + { + return -1; + } + else if (storePos < currentPos) + { + DBWriteContactSettingDword(hContact, MODULE_NAME, name.c_str(), id); + return store->setIcon(id, hContact, icon); + } + else if (storePos == currentPos) // store == current + { + return store->setIcon(id, hContact, icon); + } + else // if (storePos > currentPos) + { + store->storeIcon(hContact, icon); + return 0; + } +} + +void ExtraIconGroup::storeIcon(HANDLE hContact, void *icon) +{ +} + +const char *ExtraIconGroup::getDescription() const +{ + return description.c_str(); +} + +const char *ExtraIconGroup::getDescIcon() const +{ + for (unsigned int i = 0; i < items.size(); ++i) + if (!IsEmpty(items[i]->getDescIcon())) + return items[i]->getDescIcon(); + + return ""; +} + +int ExtraIconGroup::getType() const +{ + return EXTRAICON_TYPE_GROUP; +} + +int ExtraIconGroup::ClistSetExtraIcon(HANDLE hContact, int slot, HANDLE hImage) +{ + if (hImage != NULL && hImage != (HANDLE) -1) + setValidExtraIcon = true; + + return ExtraIcon::ClistSetExtraIcon(hContact, slot, hImage); +} + -- cgit v1.2.3