diff options
author | Vadim Dashevskiy <watcherhd@gmail.com> | 2012-07-17 08:44:50 +0000 |
---|---|---|
committer | Vadim Dashevskiy <watcherhd@gmail.com> | 2012-07-17 08:44:50 +0000 |
commit | e736ab21213b66669dde5d9a9003596706eee8bd (patch) | |
tree | b891b19763dd047c3b34c9df8c3b32b941ce4983 /plugins/CyrTranslit/src | |
parent | ee2e419778605a5445474a33a29f2cfbb7eed245 (diff) |
CSList, CyrTranslit: changed folder structure
git-svn-id: http://svn.miranda-ng.org/main/trunk@1002 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/CyrTranslit/src')
-rw-r--r-- | plugins/CyrTranslit/src/MirandaContact.cpp | 191 | ||||
-rw-r--r-- | plugins/CyrTranslit/src/MirandaContact.h | 123 | ||||
-rw-r--r-- | plugins/CyrTranslit/src/TransliterationMap.cpp | 247 | ||||
-rw-r--r-- | plugins/CyrTranslit/src/TransliterationMap.h | 73 | ||||
-rw-r--r-- | plugins/CyrTranslit/src/TransliterationProtocol.cpp | 166 | ||||
-rw-r--r-- | plugins/CyrTranslit/src/TransliterationProtocol.h | 64 | ||||
-rw-r--r-- | plugins/CyrTranslit/src/main.cpp | 72 | ||||
-rw-r--r-- | plugins/CyrTranslit/src/plugin.h | 62 | ||||
-rw-r--r-- | plugins/CyrTranslit/src/resource.h | 15 |
9 files changed, 1013 insertions, 0 deletions
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<HANDLE>(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<HANDLE>(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<HANDLE>(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<WPARAM>(hTransliterateCmdMenuItem),
+ reinterpret_cast<LPARAM>(&mi));
+
+ return 0;
+}
+
+}
\ No newline at end of file diff --git a/plugins/CyrTranslit/src/MirandaContact.h b/plugins/CyrTranslit/src/MirandaContact.h new file mode 100644 index 0000000000..0e29f3d74e --- /dev/null +++ b/plugins/CyrTranslit/src/MirandaContact.h @@ -0,0 +1,123 @@ +/**
+ * 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.
+ */
+
+#pragma once
+
+#include "plugin.h"
+
+namespace CyrTranslit
+{
+
+/**
+ * The Miranda IM contact abstraction in respect to the transliteration process.
+ */
+class MirandaContact
+{
+public:
+ /**
+ * This message must be sent on Miranda startup.
+ */
+ static void initialize();
+
+ /**
+ * A factory method which instantiates new MirandaContact objects, loading
+ * its data from the Miranda database.
+ *
+ * @param hContact The handle of the contact object to be instantiated.
+ * @return The Miranda IM contact having the passed handle.
+ */
+ static MirandaContact getContact(HANDLE hContact);
+
+ /**
+ * Saves this object's data to the persistent storage -- the Miranda
+ * database. This information may be retreived later on by means of
+ * getContact() factory method invocation.
+ */
+ void save() const;
+
+ /**
+ * @return True only if the Cyrillic transliteration is on for this contact.
+ */
+ bool shouldTransliterateOutgoingMessages() const;
+
+ ~MirandaContact();
+
+private:
+ static const std::string SETTINGS_MODULE;
+ static const std::string SETTING_SHOULD_TRANSLITERATE;
+
+ static char *MENU_ITEM_TEXT;
+
+ MirandaContact();
+
+ /**
+ * Must be called on Miranda start-up to generate the transliteration
+ * command menu items for all the contacts (a contact-specific menu).
+ */
+ static void generateMenuItemsForAllContacts();
+
+ static void activateTransliterationProtocolForSubscribedContacts();
+
+ /**
+ * This is a callback function for the transliteration command menu item.
+ * This menu item is contact-specific.
+ *
+ * @param wParam The HANDLE of the contact that owns the activated menu
+ * item.
+ * @param lParam hwndContactList
+ * @return Always returns 0.
+ */
+ static INT_PTR onMenuCommandTransliterate(WPARAM wParam, LPARAM lParam);
+
+ /**
+ * This is a service name to bind the onMenuCommandTransliterate() method to
+ * within the Miranda IM framework.
+ */
+ static char *MENU_COMMAND_CALLBACK_SERVICE;
+
+ /**
+ * Stores the handle to a single user menu item shared by all the contacts.
+ * This menu item has a contact-specific state -- checked or unchecked, as
+ * far as for some contacts transliteration may be on, and for others it may
+ * be off.
+ *
+ * MirandaContact class makes the necessary update just before a menu is
+ * shown for a contact: it checks or unchecks the transliteration menu item.
+ *
+ * When the transliteration menu item is activated by a user, the
+ * transliteration setting (on or off) is inverted for the contact owing the
+ * menu.
+ */
+ static HANDLE hTransliterateCmdMenuItem;
+
+ /**
+ * @param wParam The HANDLE of the contact that owns the menu item being
+ * built.
+ * @param lParam = 0.
+ * @return Always returns 0.
+ */
+ static int onPreBuildContactMenu(WPARAM wParam, LPARAM lParam);
+
+ static void fillInMenuItem(CLISTMENUITEM &mi);
+
+ HANDLE handle;
+ bool transliterateOutgoingMessages;
+};
+
+}
\ No newline at end of file diff --git a/plugins/CyrTranslit/src/TransliterationMap.cpp b/plugins/CyrTranslit/src/TransliterationMap.cpp new file mode 100644 index 0000000000..f678c0a16e --- /dev/null +++ b/plugins/CyrTranslit/src/TransliterationMap.cpp @@ -0,0 +1,247 @@ +/**
+ * 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 "TransliterationMap.h"
+
+namespace CyrTranslit
+{
+
+TransliterationMap::Guard TransliterationMap::guard;
+const TransliterationMap *TransliterationMap::pInstance = 0;
+
+//------------------------------------------------------------------------------
+
+TransliterationMap::Guard::~Guard()
+{
+ delete TransliterationMap::pInstance;
+}
+
+//------------------------------------------------------------------------------
+
+const TransliterationMap& TransliterationMap::getInstance()
+{
+ if(!pInstance)
+ {
+ pInstance = new TransliterationMap();
+ }
+ return *pInstance;
+}
+
+//------------------------------------------------------------------------------
+
+TransliterationMap::TransliterationMap()
+{
+ theMap['à'] = "a";
+ theMap['á'] = "b";
+ theMap['â'] = "v";
+ theMap['ã'] = "g";
+ theMap['ä'] = "d";
+ theMap['å'] = "e";
+ theMap['¸'] = "e";
+ theMap['æ'] = "zh";
+ theMap['ç'] = "z";
+ theMap['è'] = "i";
+ theMap['é'] = "i";
+ theMap['ê'] = "k";
+ theMap['ë'] = "l";
+ theMap['ì'] = "m";
+ theMap['í'] = "n";
+ theMap['î'] = "o";
+ theMap['ï'] = "p";
+ theMap['ð'] = "r";
+ theMap['ñ'] = "s";
+ theMap['ò'] = "t";
+ theMap['ó'] = "u";
+ theMap['ô'] = "f";
+ theMap['õ'] = "kh";
+ theMap['ö'] = "ts";
+ theMap['÷'] = "ch";
+ theMap['ø'] = "sh";
+ theMap['ù'] = "sch";
+ theMap['ú'] = "`";
+ theMap['û'] = "y";
+ theMap['ü'] = "'";
+ theMap['ý'] = "e";
+ theMap['þ'] = "yu";
+ theMap['ÿ'] = "ya";
+
+ theMap['À'] = "A";
+ theMap['Á'] = "B";
+ theMap['Â'] = "V";
+ theMap['Ã'] = "G";
+ theMap['Ä'] = "D";
+ theMap['Å'] = "E";
+ theMap['¨'] = "E";
+ theMap['Æ'] = "ZH";
+ theMap['Ç'] = "Z";
+ theMap['È'] = "I";
+ theMap['É'] = "I";
+ theMap['Ê'] = "K";
+ theMap['Ë'] = "L";
+ theMap['Ì'] = "M";
+ theMap['Í'] = "N";
+ theMap['Î'] = "O";
+ theMap['Ï'] = "P";
+ theMap['Ð'] = "R";
+ theMap['Ñ'] = "S";
+ theMap['Ò'] = "T";
+ theMap['Ó'] = "U";
+ theMap['Ô'] = "F";
+ theMap['Õ'] = "KH";
+ theMap['Ö'] = "TS";
+ theMap['×'] = "CH";
+ theMap['Ø'] = "SH";
+ theMap['Ù'] = "SCH";
+ theMap['Ú'] = "`";
+ theMap['Û'] = "Y";
+ theMap['Ü'] = "'";
+ theMap['Ý'] = "E";
+ theMap['Þ'] = "YU";
+ theMap['ß'] = "YA";
+
+
+
+
+ theMapW[L'à'] = L"a";
+ theMapW[L'á'] = L"b";
+ theMapW[L'â'] = L"v";
+ theMapW[L'ã'] = L"g";
+ theMapW[L'ä'] = L"d";
+ theMapW[L'å'] = L"e";
+ theMapW[L'¸'] = L"e";
+ theMapW[L'æ'] = L"zh";
+ theMapW[L'ç'] = L"z";
+ theMapW[L'è'] = L"i";
+ theMapW[L'é'] = L"i";
+ theMapW[L'ê'] = L"k";
+ theMapW[L'ë'] = L"l";
+ theMapW[L'ì'] = L"m";
+ theMapW[L'í'] = L"n";
+ theMapW[L'î'] = L"o";
+ theMapW[L'ï'] = L"p";
+ theMapW[L'ð'] = L"r";
+ theMapW[L'ñ'] = L"s";
+ theMapW[L'ò'] = L"t";
+ theMapW[L'ó'] = L"u";
+ theMapW[L'ô'] = L"f";
+ theMapW[L'õ'] = L"kh";
+ theMapW[L'ö'] = L"ts";
+ theMapW[L'÷'] = L"ch";
+ theMapW[L'ø'] = L"sh";
+ theMapW[L'ù'] = L"sch";
+ theMapW[L'ú'] = L"`";
+ theMapW[L'û'] = L"y";
+ theMapW[L'ü'] = L"'";
+ theMapW[L'ý'] = L"e";
+ theMapW[L'þ'] = L"yu";
+ theMapW[L'ÿ'] = L"ya";
+
+ theMapW[L'À'] = L"A";
+ theMapW[L'Á'] = L"B";
+ theMapW[L'Â'] = L"V";
+ theMapW[L'Ã'] = L"G";
+ theMapW[L'Ä'] = L"D";
+ theMapW[L'Å'] = L"E";
+ theMapW[L'¨'] = L"E";
+ theMapW[L'Æ'] = L"ZH";
+ theMapW[L'Ç'] = L"Z";
+ theMapW[L'È'] = L"I";
+ theMapW[L'É'] = L"I";
+ theMapW[L'Ê'] = L"K";
+ theMapW[L'Ë'] = L"L";
+ theMapW[L'Ì'] = L"M";
+ theMapW[L'Í'] = L"N";
+ theMapW[L'Î'] = L"O";
+ theMapW[L'Ï'] = L"P";
+ theMapW[L'Ð'] = L"R";
+ theMapW[L'Ñ'] = L"S";
+ theMapW[L'Ò'] = L"T";
+ theMapW[L'Ó'] = L"U";
+ theMapW[L'Ô'] = L"F";
+ theMapW[L'Õ'] = L"KH";
+ theMapW[L'Ö'] = L"TS";
+ theMapW[L'×'] = L"CH";
+ theMapW[L'Ø'] = L"SH";
+ theMapW[L'Ù'] = L"SCH";
+ theMapW[L'Ú'] = L"`";
+ theMapW[L'Û'] = L"Y";
+ theMapW[L'Ü'] = L"'";
+ theMapW[L'Ý'] = L"E";
+ theMapW[L'Þ'] = L"YU";
+ theMapW[L'ß'] = L"YA";
+}
+
+//------------------------------------------------------------------------------
+
+std::string TransliterationMap::cyrillicToLatin(char c) const
+{
+ std::string ret(1, c);
+
+ CharMap::const_iterator it = theMap.find(c);
+ if(it != theMap.end())
+ {
+ ret = (*it).second;
+ }
+
+ return ret;
+}
+//------------------------------------------------------------------------------
+
+std::wstring TransliterationMap::cyrillicToLatin(wchar_t c) const
+{
+ std::wstring ret(1, c);
+
+ WCharMap::const_iterator it = theMapW.find(c);
+ if(it != theMapW.end())
+ {
+ ret = (*it).second;
+ }
+
+ return ret;
+}
+
+//------------------------------------------------------------------------------
+
+std::string TransliterationMap::cyrillicToLatin(const std::string &src) const
+{
+ std::string ret;
+
+ for(std::string::const_iterator i = src.begin(); i != src.end(); ++i)
+ {
+ ret += cyrillicToLatin(*i);
+ }
+
+ return ret;
+}
+//------------------------------------------------------------------------------
+
+std::wstring TransliterationMap::cyrillicToLatin(const std::wstring &src) const
+{
+ std::wstring ret;
+
+ for(std::wstring::const_iterator i = src.begin(); i != src.end(); ++i)
+ {
+ ret += cyrillicToLatin(*i);
+ }
+
+ return ret;
+}
+
+}
\ No newline at end of file diff --git a/plugins/CyrTranslit/src/TransliterationMap.h b/plugins/CyrTranslit/src/TransliterationMap.h new file mode 100644 index 0000000000..596e9d3e8f --- /dev/null +++ b/plugins/CyrTranslit/src/TransliterationMap.h @@ -0,0 +1,73 @@ +/**
+ * 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.
+ */
+
+#pragma once
+
+#include "plugin.h"
+
+namespace CyrTranslit
+{
+
+/**
+ * Maps the Cyrillic letters to the phonetically equivalent latin character
+ * sequences. That's what transliteration is.
+ */
+class TransliterationMap
+{
+public:
+ /**
+ * Gives an access to the singleton object of this class.
+ *
+ * @return One and only instance of TransliterationMap class.
+ */
+ static const TransliterationMap& getInstance();
+
+ /**
+ * Performs the transliteration from Cyrillic to Latin.
+ *
+ * @param src The source string that may contain Cyrillic characters.
+ *
+ * @return The transliterated source string in which all the occurences of
+ * Cyrillic letters are replaced by the phonetically equivalent Latin
+ * sequences (1-3 letters for a single Cyrillic leter).
+ */
+ std::string cyrillicToLatin(const std::string &src) const;
+ std::wstring cyrillicToLatin(const std::wstring &src) const;
+
+private:
+ class Guard
+ {
+ public:
+ ~Guard();
+ };
+
+ TransliterationMap();
+ std::string cyrillicToLatin(char c) const;
+ std::wstring cyrillicToLatin(wchar_t c) const;
+
+ static const TransliterationMap *pInstance;
+ static Guard guard;
+
+ typedef std::map<char, std::string> CharMap;
+ typedef std::map<wchar_t, std::wstring> WCharMap;
+ CharMap theMap;
+ WCharMap theMapW;
+};
+
+}
\ No newline at end of file diff --git a/plugins/CyrTranslit/src/TransliterationProtocol.cpp b/plugins/CyrTranslit/src/TransliterationProtocol.cpp new file mode 100644 index 0000000000..1738aa818d --- /dev/null +++ b/plugins/CyrTranslit/src/TransliterationProtocol.cpp @@ -0,0 +1,166 @@ +/**
+ * 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 "TransliterationProtocol.h"
+#include "TransliterationMap.h"
+
+namespace CyrTranslit
+{
+
+char *TransliterationProtocol::MODULE_NAME = "ProtoCyrTranslitByIKR";
+
+//------------------------------------------------------------------------------
+
+void TransliterationProtocol::initialize()
+{
+ PROTOCOLDESCRIPTOR desc;
+ desc.cbSize = sizeof(desc);
+ desc.szName = MODULE_NAME;
+ desc.type = PROTOTYPE_TRANSLATION;
+
+ CallService(
+ MS_PROTO_REGISTERMODULE,
+ 0,
+ reinterpret_cast<LPARAM>(&desc));
+
+ CreateProtoServiceFunction(MODULE_NAME, PSS_MESSAGE, sendMessageA);
+ CreateProtoServiceFunction(MODULE_NAME, PSS_MESSAGE"W", sendMessageW);
+}
+
+//------------------------------------------------------------------------------
+void TransliterationProtocol::TranslateMessageUTF(WPARAM wParam, LPARAM lParam)
+{
+ CCSDATA *ccs = reinterpret_cast<CCSDATA*>(lParam);
+
+ wchar_t* txtWdecoded = mir_utf8decodeW(reinterpret_cast<const char*>(ccs->lParam));
+ std::wstring txtW = txtWdecoded;
+ mir_free(txtWdecoded);
+
+ txtW = TransliterationMap::getInstance().cyrillicToLatin(txtW);
+
+ char* txtUTFencoded = mir_utf8encodeW(txtW.c_str());
+ std::string txtUTF = txtUTFencoded;
+ mir_free(txtUTFencoded);
+
+ ccs->lParam = reinterpret_cast<LPARAM>(mir_alloc(txtUTF.length()));
+ strcpy(reinterpret_cast<char*>(ccs->lParam), txtUTF.c_str());
+}
+
+void TransliterationProtocol::TranslateMessageW(WPARAM wParam, LPARAM lParam)
+{
+ CCSDATA *ccs = reinterpret_cast<CCSDATA*>(lParam);
+
+ std::string txtA = reinterpret_cast<const char*>(ccs->lParam);
+ int txtAlen = (int)(sizeof(txtA[0]) * (txtA.length() + 1));
+ txtA = TransliterationMap::getInstance().cyrillicToLatin(txtA);
+
+ std::wstring txtW = reinterpret_cast<const wchar_t*>(ccs->lParam + txtAlen);
+ txtW = TransliterationMap::getInstance().cyrillicToLatin(txtW);
+
+ txtAlen = (int)(sizeof(txtA[0]) * (txtA.length() + 1));
+ const DWORD newSize = static_cast<DWORD>(txtAlen + (sizeof(txtW[0]) * (txtW.length() + 1)));
+
+ ccs->lParam = reinterpret_cast<LPARAM>(mir_alloc(newSize));
+
+ strcpy(reinterpret_cast<char*>(ccs->lParam), txtA.c_str());
+ wcscpy(reinterpret_cast<wchar_t*>(ccs->lParam + txtAlen), txtW.c_str());
+}
+
+void TransliterationProtocol::TranslateMessageA(WPARAM wParam, LPARAM lParam)
+{
+ CCSDATA *ccs = reinterpret_cast<CCSDATA*>(lParam);
+
+ std::string txt = reinterpret_cast<const char*>(ccs->lParam);
+ txt = TransliterationMap::getInstance().cyrillicToLatin(txt);
+
+ const DWORD newSize = static_cast<DWORD>(txt.length() + 1);
+
+ ccs->lParam = reinterpret_cast<LPARAM>(mir_alloc(newSize));
+
+ strcpy(reinterpret_cast<char*>(ccs->lParam), txt.c_str());
+}
+
+INT_PTR TransliterationProtocol::sendMessageW(WPARAM wParam, LPARAM lParam)
+{
+ CCSDATA *ccs = reinterpret_cast<CCSDATA*>(lParam);
+ LPARAM oldlParam = ccs->lParam;
+
+ TranslateMessageW(wParam, lParam);
+
+ int ret = CallService(MS_PROTO_CHAINSEND /* "W" */, wParam, lParam);
+
+ mir_free(reinterpret_cast<void*>(ccs->lParam));
+ ccs->lParam = oldlParam;
+
+ return ret;
+}
+//------------------------------------------------------------------------------
+
+INT_PTR TransliterationProtocol::sendMessageA(WPARAM wParam, LPARAM lParam)
+{
+ CCSDATA *ccs = reinterpret_cast<CCSDATA*>(lParam);
+ LPARAM oldlParam = ccs->lParam;
+ bool msgProcessed = true;
+
+ if(ccs->wParam & PREF_UTF)
+ {
+ TranslateMessageUTF(wParam, lParam);
+ }
+ else if(ccs->wParam & PREF_UNICODE)
+ {
+ TranslateMessageW(wParam, lParam);
+ }
+ else
+ {
+ TranslateMessageA(wParam, lParam);
+ }
+
+ int ret = CallService(MS_PROTO_CHAINSEND, wParam, lParam);
+
+ if(msgProcessed)
+ {
+ mir_free(reinterpret_cast<void*>(ccs->lParam));
+ ccs->lParam = oldlParam;
+ }
+
+ return ret;
+}
+
+//------------------------------------------------------------------------------
+
+void TransliterationProtocol::activateForContact(HANDLE hContact)
+{
+ CallService(
+ MS_PROTO_ADDTOCONTACT,
+ reinterpret_cast<WPARAM>(hContact),
+ reinterpret_cast<LPARAM>(MODULE_NAME));
+}
+
+//------------------------------------------------------------------------------
+
+void TransliterationProtocol::deactivateForContact(HANDLE hContact)
+{
+ CallService(
+ MS_PROTO_REMOVEFROMCONTACT,
+ reinterpret_cast<WPARAM>(hContact),
+ reinterpret_cast<LPARAM>(MODULE_NAME));
+}
+
+}
diff --git a/plugins/CyrTranslit/src/TransliterationProtocol.h b/plugins/CyrTranslit/src/TransliterationProtocol.h new file mode 100644 index 0000000000..52d9fc0e74 --- /dev/null +++ b/plugins/CyrTranslit/src/TransliterationProtocol.h @@ -0,0 +1,64 @@ +/**
+ * 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.
+ */
+
+#pragma once
+
+#include "plugin.h"
+
+namespace CyrTranslit
+{
+
+/**
+ * A simnple TRANSLATION-type Miranda protocol which performs the
+ * transliteration of Cyrillic text for selected contacts.
+ */
+class TransliterationProtocol
+{
+public:
+ /**
+ * Initializes this protocol on Miranda start-up.
+ */
+ static void initialize();
+
+ /**
+ * A call-back function called when a new outgoing message must be
+ * transferred by this protocol.
+ *
+ * @param wParam flags
+ * @param lParam (LPARAM)(const char*)szMessage
+ * @return a hProcess corresponding to the one in the ack event.
+ */
+ static INT_PTR sendMessageA(WPARAM wParam, LPARAM lParam);
+ static INT_PTR sendMessageW(WPARAM wParam, LPARAM lParam);
+
+ static void TranslateMessageA(WPARAM wParam, LPARAM lParam);
+ static void TranslateMessageW(WPARAM wParam, LPARAM lParam);
+ static void TranslateMessageUTF(WPARAM wParam, LPARAM lParam);
+
+ static void activateForContact(HANDLE hContact);
+ static void deactivateForContact(HANDLE hContact);
+
+private:
+ static char *MODULE_NAME;
+
+ TransliterationProtocol();
+ ~TransliterationProtocol();
+};
+
+}
\ No newline at end of file diff --git a/plugins/CyrTranslit/src/main.cpp b/plugins/CyrTranslit/src/main.cpp new file mode 100644 index 0000000000..49761dc305 --- /dev/null +++ b/plugins/CyrTranslit/src/main.cpp @@ -0,0 +1,72 @@ +/**
+ * 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"
+
+HINSTANCE hInst;
+int hLangpack = 0;
+
+PLUGININFOEX pluginInfoEx={
+ sizeof(PLUGININFOEX),
+ PLG_SHORTNAME,
+ PLG_VERSION,
+ PLG_DESCRIPTION,
+ PLG_AUTHOR,
+ PLG_AUTHOREMAIL,
+ PLG_COPYRIGHT,
+ PLG_HOMEPAGE,
+ PLG_FLAGS,
+ MIID_V_CYRTRANSLIT
+};
+
+//------------------------------------------------------------------------------
+
+BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
+{
+ hInst = hinstDLL;
+ return TRUE;
+}
+
+//------------------------------------------------------------------------------
+
+extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
+{
+ return &pluginInfoEx;
+}
+
+
+//------------------------------------------------------------------------------
+
+extern "C" __declspec(dllexport) int Load(void)
+{
+ mir_getLP(&pluginInfoEx);
+
+ //plugin inits: PLACE IT ONLY AFTER THIS LINE
+
+ CyrTranslit::MirandaContact::initialize();
+ return 0;
+}
+
+//------------------------------------------------------------------------------
+
+extern "C" __declspec(dllexport) int Unload(void)
+{
+ return 0;
+}
\ No newline at end of file diff --git a/plugins/CyrTranslit/src/plugin.h b/plugins/CyrTranslit/src/plugin.h new file mode 100644 index 0000000000..866ec60bb8 --- /dev/null +++ b/plugins/CyrTranslit/src/plugin.h @@ -0,0 +1,62 @@ +/**
+ * Plugin.H: Main common header of MirandaIM plugin
+ * Copyright 2009 Valeriy V. Vyshnyak.
+ *
+ * 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.
+ */
+#pragma once
+
+
+/****** SYSTEM OPTIONS *******************************************************/
+
+// set compatibility lever for Miranda 0.4.x
+#define MIRANDA_VER 0x0400
+
+// for windows:
+#define _CRT_SECURE_NO_WARNINGS
+#pragma warning (disable : 4312) /*C4312: 'type cast' : conversion from 'int' to 'char *' of greater size */
+
+
+
+/****** INCLUDES *************************************************************/
+
+#include <windows.h>
+#include <map>
+#include <string>
+#include "newpluginapi.h"
+#include "m_database.h"
+#include "m_protomod.h"
+#include "m_protosvc.h"
+#include "m_system.h"
+#include "m_clist.h"
+#include "m_langpack.h"
+
+
+/****** PLUGIN DEFINES *******************************************************/
+
+// pluginInfo:
+#define PLG_SHORTNAME "CyrTranslit"
+#define PLG_VERSION PLUGIN_MAKE_VERSION(1, 0, 3, 0)
+#define PLG_DESCRIPTION "Replaces (for the selected contacts only) the Cyrillic letters in the "\
+ "outgoing messages with the phonetically equivalent Latin letter "\
+ "combinations."
+#define PLG_AUTHOR "ValeraVi, Ivan Krechetov"
+#define PLG_AUTHOREMAIL "valeravi@vi-soft.com.ua"
+#define PLG_COPYRIGHT "© 2005-2009 ValeraVi, Ivan Krechetov"
+#define PLG_HOMEPAGE "http://www.vi-soft.com.ua"
+#define PLG_FLAGS 0 /*UNICODE_AWARE, will be set dynamically*/
+#define MIID_V_CYRTRANSLIT {0xbcec0bd7, 0xca59, 0x44b2, {0x9a, 0x14, 0x3a, 0x14, 0x98, 0x0f, 0x52, 0x4a}}
+
+
diff --git a/plugins/CyrTranslit/src/resource.h b/plugins/CyrTranslit/src/resource.h new file mode 100644 index 0000000000..e17dce6b19 --- /dev/null +++ b/plugins/CyrTranslit/src/resource.h @@ -0,0 +1,15 @@ +//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by CyrTranslit.rc
+//
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 101
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1001
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif
|