From e736ab21213b66669dde5d9a9003596706eee8bd Mon Sep 17 00:00:00 2001 From: Vadim Dashevskiy Date: Tue, 17 Jul 2012 08:44:50 +0000 Subject: CSList, CyrTranslit: changed folder structure git-svn-id: http://svn.miranda-ng.org/main/trunk@1002 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/CyrTranslit/src/MirandaContact.cpp | 191 +++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 plugins/CyrTranslit/src/MirandaContact.cpp (limited to 'plugins/CyrTranslit/src/MirandaContact.cpp') diff --git a/plugins/CyrTranslit/src/MirandaContact.cpp b/plugins/CyrTranslit/src/MirandaContact.cpp new file mode 100644 index 0000000000..1a0f149ef8 --- /dev/null +++ b/plugins/CyrTranslit/src/MirandaContact.cpp @@ -0,0 +1,191 @@ +/** + * CyrTranslit: the Cyrillic transliteration plug-in for Miranda IM. + * Copyright 2005 Ivan Krechetov. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "plugin.h" +#include "MirandaContact.h" +#include "TransliterationProtocol.h" + +namespace CyrTranslit +{ + +const std::string MirandaContact::SETTINGS_MODULE = "CyrTranslit"; + +const std::string MirandaContact::SETTING_SHOULD_TRANSLITERATE + = "translit"; + +char *MirandaContact::MENU_ITEM_TEXT = "&Transliterate (ÔÛÂÀ->FYVA)"; + +char *MirandaContact::MENU_COMMAND_CALLBACK_SERVICE + = "CyrTranslit/ContactMenuCmd"; + +HANDLE MirandaContact::hTransliterateCmdMenuItem = 0; + +//------------------------------------------------------------------------------ + +MirandaContact::MirandaContact() + : handle(0), + transliterateOutgoingMessages(false) +{ +} + +//------------------------------------------------------------------------------ + +MirandaContact::~MirandaContact() +{ +} + +//------------------------------------------------------------------------------ + +void MirandaContact::initialize() +{ + CreateServiceFunction(MENU_COMMAND_CALLBACK_SERVICE,onMenuCommandTransliterate); + generateMenuItemsForAllContacts(); + + HookEvent(ME_CLIST_PREBUILDCONTACTMENU, onPreBuildContactMenu); + + TransliterationProtocol::initialize(); + activateTransliterationProtocolForSubscribedContacts(); +} + +//------------------------------------------------------------------------------ + +MirandaContact MirandaContact::getContact(HANDLE hContact) +{ + int b = DBGetContactSettingByte( + hContact, + SETTINGS_MODULE.c_str(), + SETTING_SHOULD_TRANSLITERATE.c_str(), + 0); + + MirandaContact ret; + ret.handle = hContact; + ret.transliterateOutgoingMessages = (b != 0); + + return ret; +} + +//------------------------------------------------------------------------------ + +void MirandaContact::save() const +{ + DBWriteContactSettingByte( + handle, + SETTINGS_MODULE.c_str(), + SETTING_SHOULD_TRANSLITERATE.c_str(), + transliterateOutgoingMessages? 1 : 0); +} + +//------------------------------------------------------------------------------ + +bool MirandaContact::shouldTransliterateOutgoingMessages() const +{ + return transliterateOutgoingMessages; +} + +//------------------------------------------------------------------------------ + +void MirandaContact::fillInMenuItem(CLISTMENUITEM &mi) +{ + mi.cbSize = sizeof(CLISTMENUITEM); + mi.pszName = MENU_ITEM_TEXT; + mi.flags = 0; + mi.position = 65535; + mi.hIcon = NULL; + mi.pszService = MENU_COMMAND_CALLBACK_SERVICE; + mi.pszPopupName = NULL; + mi.popupPosition = 0; + mi.hotKey = 0; + mi.pszContactOwner = NULL; +} + +//------------------------------------------------------------------------------ + +void MirandaContact::generateMenuItemsForAllContacts() +{ + CLISTMENUITEM mi; + fillInMenuItem(mi); + hTransliterateCmdMenuItem = Menu_AddContactMenuItem(&mi); +} + +//------------------------------------------------------------------------------ + +void MirandaContact::activateTransliterationProtocolForSubscribedContacts() +{ + int hContact = CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); + if(!hContact) return; + + do + { + MirandaContact mc = getContact(reinterpret_cast(hContact)); + + if(mc.shouldTransliterateOutgoingMessages()) + { + TransliterationProtocol::activateForContact(mc.handle); + } + } while(hContact = CallService(MS_DB_CONTACT_FINDNEXT, hContact, 0)); +} + +//------------------------------------------------------------------------------ + +INT_PTR MirandaContact::onMenuCommandTransliterate(WPARAM wParam, LPARAM lParam) +{ + HANDLE hContact = reinterpret_cast(wParam); + if(!CallService(MS_DB_CONTACT_IS, wParam, 0)) return 0; + + MirandaContact mc = getContact(hContact); + mc.transliterateOutgoingMessages = !mc.transliterateOutgoingMessages; + mc.save(); + + if(mc.shouldTransliterateOutgoingMessages()) + { + TransliterationProtocol::activateForContact(mc.handle); + } + else + { + TransliterationProtocol::deactivateForContact(mc.handle); + } + + return 0; +} + +//------------------------------------------------------------------------------ + +int MirandaContact::onPreBuildContactMenu(WPARAM wParam, LPARAM lParam) +{ + if(!hTransliterateCmdMenuItem) return 0; + HANDLE hContact = reinterpret_cast(wParam); + if(!CallService(MS_DB_CONTACT_IS, wParam, 0)) return 0; + + MirandaContact mc = getContact(hContact); + + CLISTMENUITEM mi; + fillInMenuItem(mi); + + DWORD toSet = mc.shouldTransliterateOutgoingMessages()? CMIF_CHECKED : 0; + mi.flags = CMIM_FLAGS | toSet; + + CallService( + MS_CLIST_MODIFYMENUITEM, + reinterpret_cast(hTransliterateCmdMenuItem), + reinterpret_cast(&mi)); + + return 0; +} + +} \ No newline at end of file -- cgit v1.2.3