diff options
Diffstat (limited to 'plugins/CyrTranslit/src/MirandaContact.cpp')
-rw-r--r-- | plugins/CyrTranslit/src/MirandaContact.cpp | 163 |
1 files changed, 65 insertions, 98 deletions
diff --git a/plugins/CyrTranslit/src/MirandaContact.cpp b/plugins/CyrTranslit/src/MirandaContact.cpp index 0f5df412b2..931ed6e2c6 100644 --- a/plugins/CyrTranslit/src/MirandaContact.cpp +++ b/plugins/CyrTranslit/src/MirandaContact.cpp @@ -24,23 +24,22 @@ namespace CyrTranslit
{
-const std::string MirandaContact::SETTINGS_MODULE = "CyrTranslit";
+const char* MirandaContact::SETTINGS_MODULE = "CyrTranslit";
-const std::string MirandaContact::SETTING_SHOULD_TRANSLITERATE
- = "translit";
+const char* MirandaContact::SETTING_SHOULD_TRANSLITERATE = "translit";
char *MirandaContact::MENU_ITEM_TEXT = "&Transliterate (ÔÛÂÀ->FYVA)";
char *MirandaContact::MENU_COMMAND_CALLBACK_SERVICE
- = "CyrTranslit/ContactMenuCmd";
-
+ = "CyrTranslit/ContactMenuCmd";
+
HANDLE MirandaContact::hTransliterateCmdMenuItem = 0;
//------------------------------------------------------------------------------
MirandaContact::MirandaContact()
- : handle(0),
- transliterateOutgoingMessages(false)
+ : handle(0),
+ transliterateOutgoingMessages(false)
{
}
@@ -54,139 +53,107 @@ MirandaContact::~MirandaContact() void MirandaContact::initialize()
{
- CreateServiceFunction(MENU_COMMAND_CALLBACK_SERVICE,onMenuCommandTransliterate);
- generateMenuItemsForAllContacts();
-
- HookEvent(ME_CLIST_PREBUILDCONTACTMENU, onPreBuildContactMenu);
-
- TransliterationProtocol::initialize();
- activateTransliterationProtocolForSubscribedContacts();
+ 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;
-}
+ int b = db_get_b(hContact, SETTINGS_MODULE, SETTING_SHOULD_TRANSLITERATE, 0);
-//------------------------------------------------------------------------------
+ MirandaContact ret;
+ ret.handle = hContact;
+ ret.transliterateOutgoingMessages = (b != 0);
-void MirandaContact::save() const
-{
- DBWriteContactSettingByte(
- handle,
- SETTINGS_MODULE.c_str(),
- SETTING_SHOULD_TRANSLITERATE.c_str(),
- transliterateOutgoingMessages? 1 : 0);
+ return ret;
}
//------------------------------------------------------------------------------
-bool MirandaContact::shouldTransliterateOutgoingMessages() const
+void MirandaContact::save() const
{
- return transliterateOutgoingMessages;
+ db_set_b(handle, SETTINGS_MODULE, SETTING_SHOULD_TRANSLITERATE, transliterateOutgoingMessages);
}
//------------------------------------------------------------------------------
-void MirandaContact::fillInMenuItem(CLISTMENUITEM &mi)
+bool MirandaContact::shouldTransliterateOutgoingMessages() const
{
- 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;
+ return transliterateOutgoingMessages;
}
//------------------------------------------------------------------------------
void MirandaContact::generateMenuItemsForAllContacts()
{
- CLISTMENUITEM mi;
- fillInMenuItem(mi);
- hTransliterateCmdMenuItem = Menu_AddContactMenuItem(&mi);
+ 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;
+ hTransliterateCmdMenuItem = Menu_AddContactMenuItem(&mi);
}
//------------------------------------------------------------------------------
void MirandaContact::activateTransliterationProtocolForSubscribedContacts()
{
- HANDLE hContact = db_find_first();
- if(!hContact)
- return;
-
- do
- {
- MirandaContact mc = getContact(reinterpret_cast<HANDLE>(hContact));
-
- if(mc.shouldTransliterateOutgoingMessages())
- {
- TransliterationProtocol::activateForContact(mc.handle);
- }
- } while(hContact = db_find_next(hContact));
+ HANDLE hContact = db_find_first();
+ if (!hContact)
+ return;
+
+ do {
+ MirandaContact mc = getContact(reinterpret_cast<HANDLE>(hContact));
+ if (mc.shouldTransliterateOutgoingMessages())
+ mc.save();
+ }
+ while(hContact = db_find_next(hContact));
}
//------------------------------------------------------------------------------
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;
+ 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();
+ 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;
+ 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 = { sizeof(mi) };
+ mi.flags = CMIM_FLAGS;
+ if (mc.shouldTransliterateOutgoingMessages())
+ mi.flags |= CMIF_CHECKED;
+
+ CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hTransliterateCmdMenuItem, (LPARAM)&mi);
+ return 0;
}
}
\ No newline at end of file |