summaryrefslogtreecommitdiff
path: root/plugins/MetaContacts/src/meta_utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/MetaContacts/src/meta_utils.cpp')
-rw-r--r--plugins/MetaContacts/src/meta_utils.cpp501
1 files changed, 182 insertions, 319 deletions
diff --git a/plugins/MetaContacts/src/meta_utils.cpp b/plugins/MetaContacts/src/meta_utils.cpp
index a11f28b90b..2217834d22 100644
--- a/plugins/MetaContacts/src/meta_utils.cpp
+++ b/plugins/MetaContacts/src/meta_utils.cpp
@@ -179,41 +179,41 @@ HANDLE Meta_GetHandle(const char *protocol, DBVARIANT *id)
* The login of the "MetaContacts" protocol will be copied from the login
* of the specified protocol.
*
-* @param proto : The name of the protocol used to get the login that will be
+* @param szProto : The name of the protocol used to get the login that will be
* affected to the "MetaContacts" protocol.
*
* @return O on success, 1 otherwise.
*/
-int Meta_SetNick(char *proto)
+int Meta_SetNick(char *szProto)
{
CONTACTINFO ci;
ci.cbSize = sizeof(CONTACTINFO);
ci.dwFlag = CNF_DISPLAY;
ci.hContact = NULL;
- ci.szProto = proto;
+ ci.szProto = szProto;
if (CallService(MS_CONTACT_GETCONTACTINFO,0,(LPARAM)&ci))
return 1;
switch(ci.type) {
case CNFT_BYTE:
- if ( db_set_b(NULL, META_PROTO, "Nick",ci.bVal))
+ if ( db_set_b(NULL, META_PROTO, "Nick", ci.bVal))
return 1;
break;
case CNFT_WORD:
- if ( db_set_w(NULL, META_PROTO, "Nick",ci.wVal))
+ if ( db_set_w(NULL, META_PROTO, "Nick", ci.wVal))
return 1;
break;
case CNFT_DWORD:
- if ( db_set_dw(NULL, META_PROTO, "Nick",ci.dVal))
+ if ( db_set_dw(NULL, META_PROTO, "Nick", ci.dVal))
return 1;
break;
case CNFT_ASCIIZ:
- if ( db_set_s(NULL, META_PROTO, "Nick",ci.pszVal))
+ if ( db_set_ts(NULL, META_PROTO, "Nick", ci.pszVal))
return 1;
mir_free(ci.pszVal);
break;
default:
- if ( db_set_s(NULL, META_PROTO, "Nick",(char *)Translate("Sender")))
+ if ( db_set_s(NULL, META_PROTO, "Nick",(char *)TranslateT("Sender")))
return 1;
break;
}
@@ -231,67 +231,66 @@ int Meta_SetNick(char *proto)
BOOL Meta_Assign(HANDLE src, HANDLE dest, BOOL set_as_default)
{
DBCONTACTWRITESETTING cws;
- DWORD metaID;
- char *proto,
- *field;
- DWORD num_contacts;
- char buffer[512], buffer2[512];
+ DWORD metaID, num_contacts;
+ char buffer[512], szId[40];
+ TCHAR buffer2[512];
WORD status;
HANDLE most_online;
if ((metaID=db_get_dw(dest, META_PROTO, META_ID,(DWORD)-1))==-1) {
- MessageBox(0, Translate("Could not get MetaContact id"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING);
+ MessageBox(0, TranslateT("Could not get MetaContact id"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING);
return FALSE;
}
if ((num_contacts=db_get_dw(dest, META_PROTO, "NumContacts",(DWORD)-1))==-1) {
- MessageBox(0, Translate("Could not retreive MetaContact contact count"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING);
+ MessageBox(0, TranslateT("Could not retreive MetaContact contact count"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING);
return FALSE;
}
- if ( !(proto = GetContactProto(src))) {
- MessageBox(0, Translate("Could not retreive contact protocol"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING);
+ char *szProto = GetContactProto(src);
+ if (szProto == NULL) {
+ MessageBox(0, TranslateT("Could not retreive contact protocol"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING);
return FALSE;
}
// Get the login of the subcontact
- field = (char *)CallProtoService(proto,PS_GETCAPS,PFLAG_UNIQUEIDSETTING,0);
- if ( db_get(src,proto,field,&cws.value)) {
- MessageBox(0, Translate("Could not get unique id of contact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING);
+ char *field = (char *)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
+ if ( db_get(src,szProto,field,&cws.value)) {
+ MessageBox(0, TranslateT("Could not get unique id of contact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING);
return FALSE;
}
// Check that is is 'on the list'
if ( db_get_b(src, "CList", "NotOnList", 0) == 1) {
- MessageBox(0, Translate("Contact is 'Not on List' - please add the contact to your contact list before assigning."), Translate("Assignment Error"), MB_OK | MB_ICONWARNING);
+ MessageBox(0, TranslateT("Contact is 'Not on List' - please add the contact to your contact list before assigning."), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING);
db_free(&cws.value);
return FALSE;
}
num_contacts++;
if (num_contacts >= MAX_CONTACTS) {
- MessageBox(0, Translate("MetaContact is full"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING);
+ MessageBox(0, TranslateT("MetaContact is full"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING);
db_free(&cws.value);
return FALSE;
}
// write the contact's protocol
strcpy(buffer, "Protocol");
- strcat(buffer, _itoa((int)(num_contacts -1), buffer2, 10));
+ strcat(buffer, _itoa((int)(num_contacts -1), szId, 10));
- if ( db_set_s(dest, META_PROTO, buffer, proto)) {
- MessageBox(0, Translate("Could not write contact protocol to MetaContact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING);
+ if ( db_set_s(dest, META_PROTO, buffer, szProto)) {
+ MessageBox(0, TranslateT("Could not write contact protocol to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING);
db_free(&cws.value);
return FALSE;
}
// write the login
strcpy(buffer, "Login");
- strcat(buffer, _itoa((int)(num_contacts - 1), buffer2, 10));
+ strcat(buffer, _itoa((int)(num_contacts - 1), szId, 10));
- cws.szModule=META_PROTO;
- cws.szSetting=buffer;
+ cws.szModule = META_PROTO;
+ cws.szSetting = buffer;
if ( CallService(MS_DB_CONTACT_WRITESETTING,(WPARAM)dest,(LPARAM)&cws)) {
- MessageBox(0, Translate("Could not write unique id of contact to MetaContact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING);
+ MessageBox(0, TranslateT("Could not write unique id of contact to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING);
db_free(&cws.value);
return FALSE;
}
@@ -299,16 +298,16 @@ BOOL Meta_Assign(HANDLE src, HANDLE dest, BOOL set_as_default)
db_free(&cws.value);
// If we can get the nickname of the subcontact...
- if ( !db_get(src,proto,"Nick",&cws.value)) {
+ if ( !db_get(src,szProto,"Nick",&cws.value)) {
// write the nickname
strcpy(buffer, "Nick");
- strcat(buffer, _itoa((int)(num_contacts - 1), buffer2, 10));
+ strcat(buffer, _itoa((int)(num_contacts - 1), szId, 10));
cws.szModule=META_PROTO;
cws.szSetting=buffer;
if (CallService(MS_DB_CONTACT_WRITESETTING,(WPARAM)dest,(LPARAM)&cws)) {
- MessageBox(0, Translate("Could not write nickname of contact to MetaContact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING);
+ MessageBox(0, TranslateT("Could not write nickname of contact to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING);
return FALSE;
}
@@ -322,7 +321,7 @@ BOOL Meta_Assign(HANDLE src, HANDLE dest, BOOL set_as_default)
// write the display name
strcpy(buffer, "CListName");
- strcat(buffer, _itoa((int)(num_contacts - 1), buffer2, 10));
+ strcat(buffer, _itoa((int)(num_contacts - 1), szId, 10));
if (wname && strncmp(name, (char *)wname, strlen(name)) != 0) {
DBWriteContactSettingWString(dest, META_PROTO, buffer, wname);
@@ -330,58 +329,58 @@ BOOL Meta_Assign(HANDLE src, HANDLE dest, BOOL set_as_default)
db_set_s(dest, META_PROTO, buffer, name);
// Get the status
- if ( !proto)
+ if ( !szProto)
status = ID_STATUS_OFFLINE;
else
- status = db_get_w(src, proto, "Status", ID_STATUS_OFFLINE);
+ status = db_get_w(src, szProto, "Status", ID_STATUS_OFFLINE);
}
// write the status
strcpy(buffer, "Status");
- strcat(buffer, _itoa((int)(num_contacts - 1), buffer2, 10));
+ strcat(buffer, _itoa((int)(num_contacts - 1), szId, 10));
if (db_set_w(dest, META_PROTO, buffer, status)) {
- MessageBox(0, Translate("Could not write contact status to MetaContact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING);
+ MessageBox(0, TranslateT("Could not write contact status to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING);
return FALSE;
}
// write the handle
strcpy(buffer, "Handle");
- strcat(buffer, _itoa((int)(num_contacts - 1), buffer2, 10));
+ strcat(buffer, _itoa((int)(num_contacts - 1), szId, 10));
if (db_set_dw(dest, META_PROTO, buffer, (DWORD)src)) {
- MessageBox(0, Translate("Could not write contact handle to MetaContact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING);
+ MessageBox(0, TranslateT("Could not write contact handle to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING);
return FALSE;
}
// write status string
strcpy(buffer, "StatusString");
- strcat(buffer, _itoa((int)(num_contacts - 1), buffer2, 10));
+ strcat(buffer, _itoa((int)(num_contacts - 1), szId, 10));
Meta_GetStatusString(status, buffer2, 512);
- if (db_set_s(dest, META_PROTO, buffer, buffer2)) {
- MessageBox(0, Translate("Could not write contact status string to MetaContact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING);
+ if (db_set_ts(dest, META_PROTO, buffer, buffer2)) {
+ MessageBox(0, TranslateT("Could not write contact status string to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING);
return FALSE;
}
// Write the link in the contact
if (db_set_dw(src, META_PROTO, META_LINK,metaID)) {
- MessageBox(0, Translate("Could not write MetaContact id to contact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING);
+ MessageBox(0, TranslateT("Could not write MetaContact id to contact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING);
return FALSE;
}
// Write the contact number in the contact
if (db_set_dw(src, META_PROTO, "ContactNumber",(DWORD)(num_contacts - 1))) {
- MessageBox(0, Translate("Could not write MetaContact contact number to contact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING);
+ MessageBox(0, TranslateT("Could not write MetaContact contact number to contact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING);
return FALSE;
}
// Write the handle in the contact
if (db_set_dw(src, META_PROTO, "Handle",(DWORD)dest)) {
- MessageBox(0, Translate("Could not write MetaContact contact number to contact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING);
+ MessageBox(0, TranslateT("Could not write MetaContact contact number to contact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING);
return FALSE;
}
// update count of contacts
if (db_set_dw(dest, META_PROTO, "NumContacts",num_contacts)) {
- MessageBox(0, Translate("Could not write contact count to MetaContact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING);
+ MessageBox(0, TranslateT("Could not write contact count to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING);
return FALSE;
}
@@ -409,7 +408,7 @@ BOOL Meta_Assign(HANDLE src, HANDLE dest, BOOL set_as_default)
_tcscpy(AI.filename, _T("X"));
if ((int)CallProtoService(META_PROTO, PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS)
- DBWriteContactSettingTString(dest, "ContactPhoto", "File",AI.filename);
+ db_set_ts(dest, "ContactPhoto", "File",AI.filename);
}
// Hide the contact
@@ -450,7 +449,7 @@ HANDLE Meta_GetMostOnlineSupporting(HANDLE hMeta, int pflagnum, unsigned long ca
HANDLE most_online_contact = NULL, hContact;
int i, status, default_contact_number, num_contacts;
unsigned long caps = 0;
- char *proto, *most_online_proto;
+ char *szProto, *most_online_proto;
// you can't get more online than having the default contact ONLINE - so check that first
if ((default_contact_number = db_get_dw(hMeta, META_PROTO, "Default",(DWORD)-1)) == (DWORD)-1)
@@ -465,28 +464,28 @@ HANDLE Meta_GetMostOnlineSupporting(HANDLE hMeta, int pflagnum, unsigned long ca
return NULL;
most_online_contact = Meta_GetContactHandle(hMeta, default_contact_number);
- proto = GetContactProto(most_online_contact);
- caps = proto ? CallProtoService(proto, PS_GETCAPS, (WPARAM)pflagnum, 0) : 0;
- if (proto && strcmp(proto, "IRC") == 0) caps |= PF1_IM;
+ szProto = GetContactProto(most_online_contact);
+ caps = szProto ? CallProtoService(szProto, PS_GETCAPS, (WPARAM)pflagnum, 0) : 0;
+ if (szProto && strcmp(szProto, "IRC") == 0) caps |= PF1_IM;
// we are forced to do use default for sending - '-1' capability indicates no specific capability, but respect 'Force Default'
- if (proto && db_get_b(hMeta, META_PROTO, "ForceDefault", 0) && capability != 0 && (capability == -1 || (caps & capability) == capability)) // capability is 0 when we're working out status
+ if (szProto && db_get_b(hMeta, META_PROTO, "ForceDefault", 0) && capability != 0 && (capability == -1 || (caps & capability) == capability)) // capability is 0 when we're working out status
return most_online_contact;
// a subcontact is being temporarily 'forced' to do sending
if ((most_online_contact = (HANDLE)db_get_dw(hMeta, META_PROTO, "ForceSend", 0))) {
- caps = proto ? CallProtoService(proto, PS_GETCAPS, (WPARAM)pflagnum, 0) : 0;
- if (proto && strcmp(proto, "IRC") == 0) caps |= PF1_IM;
- if (proto && (caps & capability) == capability && capability != 0) // capability is 0 when we're working out status
+ caps = szProto ? CallProtoService(szProto, PS_GETCAPS, (WPARAM)pflagnum, 0) : 0;
+ if (szProto && strcmp(szProto, "IRC") == 0) caps |= PF1_IM;
+ if (szProto && (caps & capability) == capability && capability != 0) // capability is 0 when we're working out status
return most_online_contact;
}
most_online_contact = Meta_GetContactHandle(hMeta, default_contact_number);
- proto = GetContactProto(most_online_contact);
- if (proto && CallProtoService(proto, PS_GETSTATUS, 0, 0) >= ID_STATUS_ONLINE) {
- caps = proto ? CallProtoService(proto, PS_GETCAPS, (WPARAM)pflagnum, 0) : 0;
- if (proto && strcmp(proto, "IRC") == 0) caps |= PF1_IM;
- if (proto && (capability == -1 || (caps & capability) == capability)) {
- most_online_status = db_get_w(most_online_contact, proto, "Status", ID_STATUS_OFFLINE);
+ szProto = GetContactProto(most_online_contact);
+ if (szProto && CallProtoService(szProto, PS_GETSTATUS, 0, 0) >= ID_STATUS_ONLINE) {
+ caps = szProto ? CallProtoService(szProto, PS_GETCAPS, (WPARAM)pflagnum, 0) : 0;
+ if (szProto && strcmp(szProto, "IRC") == 0) caps |= PF1_IM;
+ if (szProto && (capability == -1 || (caps & capability) == capability)) {
+ most_online_status = db_get_w(most_online_contact, szProto, "Status", ID_STATUS_OFFLINE);
// if our default is not offline, and option to use default is set - return default
// and also if our default is online, return it
@@ -498,35 +497,35 @@ HANDLE Meta_GetMostOnlineSupporting(HANDLE hMeta, int pflagnum, unsigned long ca
} else
most_online_status = ID_STATUS_OFFLINE;
- most_online_proto = proto;
+ most_online_proto = szProto;
// otherwise, check all the subcontacts for the one closest to the ONLINE state which supports the required capability
for (i = 0; i < num_contacts; i++) {
if (i == default_contact_number) // already checked that (i.e. initial value of most_online_contact and most_online_status are those of the default contact)
continue;
hContact = Meta_GetContactHandle(hMeta, i);
- proto = GetContactProto(hContact);
+ szProto = GetContactProto(hContact);
- if ( !proto || CallProtoService(proto, PS_GETSTATUS, 0, 0) < ID_STATUS_ONLINE) // proto offline or connecting
+ if ( !szProto || CallProtoService(szProto, PS_GETSTATUS, 0, 0) < ID_STATUS_ONLINE) // szProto offline or connecting
continue;
- caps = proto ? CallProtoService(proto, PS_GETCAPS, (WPARAM)pflagnum, 0) : 0;
- if (proto && strcmp(proto, "IRC") == 0) caps |= PF1_IM;
- if (proto && (capability == -1 || (caps & capability) == capability)) {
+ caps = szProto ? CallProtoService(szProto, PS_GETCAPS, (WPARAM)pflagnum, 0) : 0;
+ if (szProto && strcmp(szProto, "IRC") == 0) caps |= PF1_IM;
+ if (szProto && (capability == -1 || (caps & capability) == capability)) {
- status = db_get_w(hContact, proto, "Status", ID_STATUS_OFFLINE);
+ status = db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE);
if (status == ID_STATUS_ONLINE) {
most_online_contact = hContact;
- most_online_proto = proto;
+ most_online_proto = szProto;
return most_online_contact;
} else if (status <= ID_STATUS_OFFLINE) // status below ID_STATUS_OFFLINE is a connecting status
continue;
else {
- if (GetRealPriority(proto, status) < GetRealPriority(most_online_proto, most_online_status)) {
+ if (GetRealPriority(szProto, status) < GetRealPriority(most_online_proto, most_online_status)) {
most_online_status = status;
most_online_contact = hContact;
- most_online_proto = proto;
+ most_online_proto = szProto;
}
}
}
@@ -667,7 +666,7 @@ const char *MBirthdaySettings[3] =
// special handling for status message
// copy from first subcontact with any of these values that has the same status as the most online contact
-// proto:
+// szProto:
// clist: "StatusMsg"
void CopyStatusData(HANDLE hMeta)
@@ -687,24 +686,24 @@ void CopyStatusData(HANDLE hMeta)
else
hContact = Meta_GetContactHandle(hMeta, i);
- char *proto = GetContactProto(hContact);
+ char *szProto = GetContactProto(hContact);
- if (proto && db_get_w(hContact, proto, "Status", ID_STATUS_OFFLINE) == status) {
+ if (szProto && db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE) == status) {
if ( !bDoneStatus && !Mydb_get(hContact, "CList", "StatusMsg", &dbv)) {
MyDBWriteContactSetting(hMeta, "CList", "StatusMsg", &dbv);
db_free(&dbv);
bDoneStatus = TRUE;
}
- if ((!bDoneXStatus) && (!Mydb_get(hContact, proto, "XStatusId", &dbv)) && dbv.type != DBVT_DELETED) {
- db_set_s(hMeta, META_PROTO, "XStatusProto", proto);
+ if ((!bDoneXStatus) && (!Mydb_get(hContact, szProto, "XStatusId", &dbv)) && dbv.type != DBVT_DELETED) {
+ db_set_s(hMeta, META_PROTO, "XStatusProto", szProto);
MyDBWriteContactSetting(hMeta, META_PROTO, "XStatusId", &dbv);
db_free(&dbv);
- if ( !Mydb_get(hContact, proto, "XStatusMsg", &dbv)) {
+ if ( !Mydb_get(hContact, szProto, "XStatusMsg", &dbv)) {
MyDBWriteContactSetting(hMeta, META_PROTO, "XStatusMsg", &dbv);
db_free(&dbv);
}
- if ( !Mydb_get(hContact, proto, "XStatusName", &dbv)) {
+ if ( !Mydb_get(hContact, szProto, "XStatusName", &dbv)) {
MyDBWriteContactSetting(hMeta, META_PROTO, "XStatusName", &dbv);
db_free(&dbv);
}
@@ -750,11 +749,12 @@ HANDLE Meta_GetContactHandle(HANDLE hMeta, int contact_number)
return (HANDLE)db_get_dw(hMeta, META_PROTO, buffer, 0);
}
-int Meta_SetHandles(void) {
+int Meta_SetHandles(void)
+{
DWORD meta_id, num_contacts, contact_number;
HANDLE hContact2, hContact = db_find_first(), hNextContact;
- char buffer[512], buffer2[512];
- char nick_buffer[128];
+ char buffer[512];
+ TCHAR nick_buffer[128], buffer2[40];
BOOL found;
while ( hContact != NULL ) {
@@ -762,16 +762,16 @@ int Meta_SetHandles(void) {
// is a subcontact
// get nick for debug messages
- strcpy(nick_buffer, "meta_id: ");
- strcat(nick_buffer, _itoa(meta_id, buffer2, 10));
+ _tcscpy(nick_buffer, _T("meta_id: "));
+ _tcscat(nick_buffer, _itot(meta_id, buffer2, 10));
contact_number = db_get_dw(hContact, META_PROTO, "ContactNumber", (DWORD)-1);
- strcat(nick_buffer, ", contact num: ");
- strcat(nick_buffer, _itoa(contact_number, buffer2, 10));
+ _tcscat(nick_buffer, _T(", contact num: "));
+ _tcscat(nick_buffer, _itot(contact_number, buffer2, 10));
if (contact_number < 0) {
// problem!
- MessageBox(0, Translate("Subcontact contact number < 0 - deleting MetaContact"), nick_buffer, MB_OK | MB_ICONERROR);
+ MessageBox(0, TranslateT("Subcontact contact number < 0 - deleting MetaContact"), nick_buffer, MB_OK | MB_ICONERROR);
//CallService(MS_DB_CONTACT_DELETE, (WPARMA)hContact, 0);
hNextContact = db_find_next(hContact);
Meta_Delete((WPARAM)hContact, (LPARAM)1);
@@ -783,7 +783,6 @@ int Meta_SetHandles(void) {
// ensure the window open flag is not present
db_unset(hContact, META_PROTO, "WindowOpen");
-
// find metacontact
found = FALSE;
hContact2 = db_find_first();
@@ -791,7 +790,7 @@ int Meta_SetHandles(void) {
while ( hContact2 != NULL ) {
if (db_get_dw(hContact2, META_PROTO, META_ID,(DWORD)-1) == meta_id) {
found = TRUE;
-
+
// set handle
db_set_dw(hContact, META_PROTO, "Handle", (DWORD)hContact2);
@@ -802,20 +801,21 @@ int Meta_SetHandles(void) {
num_contacts = db_get_dw(hContact2, META_PROTO, "NumContacts", (DWORD)-1);
if (contact_number >= 0 && contact_number < num_contacts) {
// set metacontact's handle to us
+ char szId[40];
strcpy(buffer, "Handle");
- strcat(buffer, _itoa((int)contact_number, buffer2, 10));
+ strcat(buffer, _itoa((int)contact_number, szId, 10));
db_set_dw(hContact2, META_PROTO, buffer, (DWORD)hContact);
- } else {
- char buff[256];
+ }
+ else {
+ TCHAR buff[256];
// problem - contact number is greater than meta's number of contacts
- sprintf(buff, Translate("Subcontact contact number (%d) > meta num contacts (%d) - deleting MetaContact"), (int)contact_number, (int)num_contacts);
+ mir_sntprintf(buff, SIZEOF(buff), TranslateT("Subcontact contact number (%d) > meta num contacts (%d) - deleting MetaContact"), contact_number, num_contacts);
MessageBox(0, buff, nick_buffer, MB_OK | MB_ICONERROR);
- //CallService(MS_DB_CONTACT_DELETE, (WPARMA)hContact, 0);
+
hNextContact = db_find_next(hContact);
Meta_Delete((WPARAM)hContact, (LPARAM)1);
hContact = hNextContact;
continue;
- //return 1;
}
}
@@ -824,7 +824,7 @@ int Meta_SetHandles(void) {
if ( !found) {
// problem - subcontact's meta not found
- MessageBox(0, Translate("Subcontact's MetaContact not found - deleting MetaContact data"), nick_buffer, MB_OK | MB_ICONERROR);
+ MessageBox(0, TranslateT("Subcontact's MetaContact not found - deleting MetaContact data"), nick_buffer, MB_OK | MB_ICONERROR);
// delete meta data
db_unset(hContact, META_PROTO, "IsSubcontact");
@@ -833,25 +833,25 @@ int Meta_SetHandles(void) {
db_unset(hContact, META_PROTO, "ContactNumber");
Meta_RestoreGroup(hContact);
db_unset(hContact, META_PROTO, "OldCListGroup");
-
+
// stop ignoring, if we were
if (options.suppress_status)
CallService(MS_IGNORE_UNIGNORE, (WPARAM)hContact, (WPARAM)IGNOREEVENT_USERONLINE);
-
- } else {
+
+ }
+ else {
if ( !db_get_b(hContact, META_PROTO, "IsSubcontact", 0))
db_set_b(hContact, META_PROTO, "IsSubcontact", 1);
}
-
- } else
- db_unset(hContact, META_PROTO, "Handle");
+ }
+ else db_unset(hContact, META_PROTO, "Handle");
if ((meta_id = db_get_dw(hContact, META_PROTO, META_ID,(DWORD)-1))!=(DWORD)-1) {
// is a metacontact
// get nick for debug messages
- strcpy(nick_buffer, "meta_id: ");
- strcat(nick_buffer, _itoa(meta_id, buffer2, 10));
+ _tcscpy(nick_buffer, _T("meta_id: "));
+ _tcscat(nick_buffer, _itot(meta_id, buffer2, 10));
// ensure the window open flag is not present
db_unset(hContact, META_PROTO, "WindowOpen");
@@ -862,47 +862,40 @@ int Meta_SetHandles(void) {
if (num_contacts < 0) {
// problem
- MessageBox(0, Translate("MetaContact number of contacts < 0 - deleting MetaContact"), nick_buffer, MB_OK | MB_ICONERROR);
- //CallService(MS_DB_CONTACT_DELETE, (WPARMA)hContact, 0);
+ MessageBox(0, TranslateT("MetaContact number of contacts < 0 - deleting MetaContact"), nick_buffer, MB_OK | MB_ICONERROR);
hNextContact = db_find_next(hContact);
Meta_Delete((WPARAM)hContact, (LPARAM)1);
hContact = hNextContact;
continue;
- //return 1;
}
-
+
if (contact_number < 0 || contact_number >= num_contacts) {
// problem
- MessageBox(0, Translate("MetaContact default contact number out of range - deleting MetaContact"), nick_buffer, MB_OK | MB_ICONERROR);
+ MessageBox(0, TranslateT("MetaContact default contact number out of range - deleting MetaContact"), nick_buffer, MB_OK | MB_ICONERROR);
hNextContact = db_find_next(hContact);
Meta_Delete((WPARAM)hContact, (LPARAM)1);
hContact = hNextContact;
- //CallService(MS_DB_CONTACT_DELETE, (WPARMA)hContact, 0);
continue;
- //return 1;
}
}
hContact = db_find_next(hContact);
}
-
+
// loop through one more time - check contact counts match
hContact = db_find_first();
while ( hContact != NULL ) {
if ((meta_id = db_get_dw(hContact, META_PROTO, META_ID,(DWORD)-1))!=(DWORD)-1) {
// get nick for debug messages
- strcpy(nick_buffer, Translate("MetaId: "));
- strcat(nick_buffer, _itoa(meta_id, buffer2, 10));
num_contacts = db_get_b(hContact, META_PROTO, "ContactCountCheck", -2);
if (num_contacts != (DWORD)db_get_dw(hContact, META_PROTO, "NumContacts", (DWORD)-1)) {
- // mismatch
- //if (MessageBox(0, Translate("MetaContact corrupted - the number of subcontacts is incorrect.\nDelete MetaContact?"), nick_buffer, MB_YESNO | MB_ICONERROR) == IDYES) {
- // Meta_Delete((WPARAM)hContact, (LPARAM)1); // second param prevents confirm dialog
- //} else
- // return 1;
hNextContact = db_find_next(hContact);
- MessageBox(0, Translate("MetaContact corrupted - the number of subcontacts is incorrect.\nDeleting MetaContact."), nick_buffer, MB_OK | MB_ICONERROR);
+
+ _tcscpy(nick_buffer, TranslateT("MetaId: "));
+ _tcscat(nick_buffer, _itot(meta_id, buffer2, 10));
+ MessageBox(0, TranslateT("MetaContact corrupted - the number of subcontacts is incorrect.\nDeleting MetaContact."), nick_buffer, MB_OK | MB_ICONERROR);
+
Meta_Delete((WPARAM)hContact, (LPARAM)1);
hContact = hNextContact;
continue;
@@ -920,12 +913,21 @@ int Meta_SetHandles(void) {
*
* and ensure metafilter in place
*/
+
+#define szMsg "The 'MetaContacts Hidden Group' has been added to your contact list.\n\
+This is most likely due to server-side contact information. To fix this, so that\n\
+MetaContacts continues to function correctly, you should:\n\
+ - disable MetaContacts using the 'Toggle MetaContacts Off' main menu item\n\
+ - move all contacts out of this group\n\
+ - synchronize your contacts with the server\n\
+ - re-enable MetaContacts"
+
int Meta_HideLinkedContacts(void) {
DBVARIANT dbv, dbv2;
DWORD meta_id, num_contacts, contact_number;
WORD status;
char buffer[512], buffer2[512];
- char *proto, *group_name;
+ char *szProto, *group_name;
int hGroup = 1;
HANDLE hContact2, hContact = db_find_first();
@@ -937,26 +939,19 @@ int Meta_HideLinkedContacts(void) {
if (group_name && !strcmp(group_name, META_HIDDEN_GROUP)) {
// disabled because it shows a message box
//CallService(MS_CLIST_GROUPDELETE, (WPARAM)hGroup, 0);
- MessageBox(0, Translate("The 'MetaContacts Hidden Group' has been added to your contact list.\n"
- "This is most likely due to server-side contact information. To fix this, so that\n"
- "MetaContacts continues to function correctly, you should:\n"
- " - disable MetaContacts using the 'Toggle MetaContacts Off' main menu item\n"
- " - move all contacts out of this group\n"
- " - synchronize your contacts with the server\n"
- " - re-enable MetaContacts"), Translate("MetaContacts Warning"), MB_ICONWARNING | MB_OK);
+ MessageBox(0, TranslateT(szMsg), TranslateT("MetaContacts Warning"), MB_ICONWARNING | MB_OK);
break;
}
hGroup++;
} while(group_name);
-
while ( hContact != NULL ) {
if ((meta_id = db_get_dw(hContact, META_PROTO, META_LINK,(DWORD)-1))!=(DWORD)-1) {
// get contact number
contact_number = db_get_dw(hContact, META_PROTO, "ContactNumber", (DWORD)-1);
// prepare to update metacontact record of subcontat status
- proto = GetContactProto(hContact);
+ szProto = GetContactProto(hContact);
// save old group and move to invisible group (i.e. non-existent group)
Meta_SetGroup(hContact);
@@ -969,10 +964,10 @@ int Meta_HideLinkedContacts(void) {
num_contacts = db_get_dw(hContact2, META_PROTO, "NumContacts", (DWORD)-1);
if (contact_number >= 0 && contact_number < num_contacts) {
- if ( !proto)
+ if ( !szProto)
status = ID_STATUS_OFFLINE;
else
- status = db_get_w(hContact, proto, "Status", ID_STATUS_OFFLINE);
+ status = db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE);
// update metacontact's record of status for this contact
strcpy(buffer, "Status");
@@ -980,7 +975,7 @@ int Meta_HideLinkedContacts(void) {
db_set_w(hContact2, META_PROTO, buffer, status);
// update metacontact's record of nick for this contact
- if (proto && !db_get(hContact, proto, "Nick", &dbv)) {
+ if (szProto && !db_get(hContact, szProto, "Nick", &dbv)) {
strcpy(buffer, "Nick");
strcat(buffer, _itoa(contact_number, buffer2, 10));
MyDBWriteContactSetting(hContact2, META_PROTO, buffer, &dbv);
@@ -1159,18 +1154,18 @@ void Meta_RestoreGroup(HANDLE hContact) {
}
void Meta_SetGroup(HANDLE hContact) {
- char *proto, *uid;
+ char *szProto, *uid;
if (meta_group_hack_disabled) return; // clist has called api function to disable group hack - yay!
// the existence of this service means that clist_meta_mw is active and will do the hiding for us
if (ServiceExists(MS_CLUI_METASUPPORT)) return;
- proto = GetContactProto(hContact);
- if (proto)
- uid = (char *)CallProtoService(proto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
+ szProto = GetContactProto(hContact);
+ if (szProto)
+ uid = (char *)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
- if (proto && uid && (INT_PTR)uid != CALLSERVICE_NOTFOUND && !strcmp(JABBER_UNIQUE_ID_SETTING, uid)) {
+ if (szProto && uid && (INT_PTR)uid != CALLSERVICE_NOTFOUND && !strcmp(JABBER_UNIQUE_ID_SETTING, uid)) {
// if it's a jabber contact, hide it, and record the fact that it was us who did
db_set_b(hContact, META_PROTO, "Hidden", 1);
db_set_b(hContact, "CList", "Hidden", 1);
@@ -1193,44 +1188,45 @@ void Meta_SetGroup(HANDLE hContact) {
}
}
-void Meta_GetStatusString(int status, char *buf, size_t size) {
+void Meta_GetStatusString(int status, TCHAR *buf, size_t size)
+{
switch(status) {
- case ID_STATUS_OFFLINE:
- strncpy(buf, Translate("Offline"), size);
- break;
- case ID_STATUS_ONLINE:
- strncpy(buf, Translate("Online"), size);
- break;
- case ID_STATUS_AWAY:
- strncpy(buf, Translate("Away"), size);
- break;
- case ID_STATUS_DND:
- strncpy(buf, Translate("DND"), size);
- break;
- case ID_STATUS_NA:
- strncpy(buf, Translate("N/A"), size);
- break;
- case ID_STATUS_OCCUPIED:
- strncpy(buf, Translate("Occupied"), size);
- break;
- case ID_STATUS_FREECHAT:
- strncpy(buf, Translate("Free to Chat"), size);
- break;
- case ID_STATUS_INVISIBLE:
- strncpy(buf, Translate("Invisible"), size);
- break;
- case ID_STATUS_ONTHEPHONE:
- strncpy(buf, Translate("On the Phone"), size);
- break;
- case ID_STATUS_OUTTOLUNCH:
- strncpy(buf, Translate("Out to Lunch"), size);
- break;
- case ID_STATUS_IDLE:
- strncpy(buf, Translate("IDLE"), size);
- break;
- default:
- strncpy(buf, Translate("Unknown"), size);
- break;
+ case ID_STATUS_OFFLINE:
+ _tcsncpy(buf, TranslateT("Offline"), size);
+ break;
+ case ID_STATUS_ONLINE:
+ _tcsncpy(buf, TranslateT("Online"), size);
+ break;
+ case ID_STATUS_AWAY:
+ _tcsncpy(buf, TranslateT("Away"), size);
+ break;
+ case ID_STATUS_DND:
+ _tcsncpy(buf, TranslateT("DND"), size);
+ break;
+ case ID_STATUS_NA:
+ _tcsncpy(buf, TranslateT("N/A"), size);
+ break;
+ case ID_STATUS_OCCUPIED:
+ _tcsncpy(buf, TranslateT("Occupied"), size);
+ break;
+ case ID_STATUS_FREECHAT:
+ _tcsncpy(buf, TranslateT("Free to Chat"), size);
+ break;
+ case ID_STATUS_INVISIBLE:
+ _tcsncpy(buf, TranslateT("Invisible"), size);
+ break;
+ case ID_STATUS_ONTHEPHONE:
+ _tcsncpy(buf, TranslateT("On the Phone"), size);
+ break;
+ case ID_STATUS_OUTTOLUNCH:
+ _tcsncpy(buf, TranslateT("Out to Lunch"), size);
+ break;
+ case ID_STATUS_IDLE:
+ _tcsncpy(buf, TranslateT("IDLE"), size);
+ break;
+ default:
+ _tcsncpy(buf, TranslateT("Unknown"), size);
+ break;
}
}
@@ -1254,7 +1250,7 @@ int Meta_SuppressStatus(BOOL suppress) {
int Meta_CopyContactNick(HANDLE hMeta, HANDLE hContact) {
DBVARIANT dbv, dbv_proto;
- char *proto;
+ char *szProto;
if (options.lockHandle) {
hContact = Meta_GetContactHandle(hMeta, 0);
@@ -1262,13 +1258,13 @@ int Meta_CopyContactNick(HANDLE hMeta, HANDLE hContact) {
if ( !hContact) return 1;
- //proto = GetContactProto(hContact);
- // read proto direct from db, since we do this on load and other proto plugins may not be loaded yet
+ //szProto = GetContactProto(hContact);
+ // read szProto direct from db, since we do this on load and other szProto plugins may not be loaded yet
if ( !db_get(hContact, "Protocol", "p", &dbv_proto)) {
- proto = dbv_proto.pszVal;
- if (options.clist_contact_name == CNNT_NICK && proto) {
- if ( !Mydb_get(hContact, proto, "Nick", &dbv)) {
+ szProto = dbv_proto.pszVal;
+ if (options.clist_contact_name == CNNT_NICK && szProto) {
+ if ( !Mydb_get(hContact, szProto, "Nick", &dbv)) {
MyDBWriteContactSetting(hMeta, META_PROTO, "Nick", &dbv);
db_free(&dbv);
//CallService(MS_CLIST_INVALIDATEDISPLAYNAME, (WPARAM)hMeta, 0);
@@ -1277,20 +1273,9 @@ int Meta_CopyContactNick(HANDLE hMeta, HANDLE hContact) {
return 0;
}
} else if (options.clist_contact_name == CNNT_DISPLAYNAME) {
- char *name = (char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, 0);
- wchar_t *wname = (wchar_t *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_UNICODE);
-
- if (name && strcmp(name, Translate("(Unknown Contact)")) != 0) {
- if (wname && strncmp(name, (char *)wname, strlen(name)) != 0) {
- DBVARIANT dbv;
- dbv.pwszVal = wname;
- dbv.type = DBVT_WCHAR;
-
- MyDBWriteContactSetting(hMeta, META_PROTO, "Nick", &dbv);
- } else
- db_set_s(hMeta, META_PROTO, "Nick", name);
- //CallService(MS_CLIST_INVALIDATEDISPLAYNAME, (WPARAM)hMeta, 0);
- //CallService(MS_CLUI_CONTACTRENAMED, (WPARAM)hMeta, 0);
+ TCHAR *name = (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR);
+ if (name && _tcscmp(name, TranslateT("(Unknown Contact)")) != 0) {
+ db_set_ts(hMeta, META_PROTO, "Nick", name);
db_free(&dbv_proto);
return 0;
}
@@ -1535,143 +1520,21 @@ void copyHistory(HANDLE hContactFrom,HANDLE hContactTo)
}
dbei.szModule = META_PROTO;
- //oldBlobSize = dbei.cbBlob;
- //dbei.cbBlob = oldBlobSize + id_length;
dbei.flags &= ~DBEF_FIRST;
- //memcpy(dbei.pBlob + oldBlobSize, id, id_length);
CallService(MS_DB_EVENT_ADD, (WPARAM)hContactTo, (LPARAM)&dbei);
}
- //CallService(MS_DB_SETSAFETYMODE, (WPARAM)TRUE, 0);
DestroyWindow(progress_dialog);
if (buffer) mir_free(buffer);
//mir_free(id);
}
-/*
-void Meta_RemoveHistory(HANDLE hContactRemoveFrom, HANDLE hContactSource) {
- HANDLE hDbEvent;
- DBEVENTINFO dbei = { 0 };
- char *id;
- DWORD id_length;
- BYTE *buffer = 0;
- DWORD time_now = time(0), earliest_time = time_now;
- HWND progress_dialog, prog;
-
- if ( !hContactRemoveFrom || !hContactSource) return;
-
- id = Meta_GetUniqueIdentifier(hContactSource, &id_length);
- if ( !id) return;
-
- progress_dialog = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DELPROGRESS), 0, DlgProcNull);
- ShowWindow(progress_dialog, SW_SHOW);
-
- prog = GetDlgItem(progress_dialog, IDC_PROG);
-
- //CallService(MS_DB_SETSAFETYMODE, (WPARAM)FALSE, 0);
- hDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDFIRST,(WPARAM)hContactRemoveFrom, 0);
- while (hDbEvent)
- {
- // get the event
- ZeroMemory(&dbei, sizeof(dbei));
- dbei.cbSize = sizeof(dbei);
-
- if ((dbei.cbBlob = CallService(MS_DB_EVENT_GETBLOBSIZE, (WPARAM)hDbEvent, 0)) == -1) {
- break;
- }
-
- buffer = mir_realloc(buffer, dbei.cbBlob + id_length);
- dbei.pBlob = buffer;
-
- if (CallService(MS_DB_EVENT_GET,(WPARAM)hDbEvent,(LPARAM)&dbei)) break;
-
- if (dbei.timestamp < earliest_time)
- earliest_time = dbei.timestamp;
-
- if (dbei.eventType != EVENTTYPE_MESSAGE && dbei.eventType != EVENTTYPE_FILE && dbei.eventType != EVENTTYPE_URL) {
- hDbEvent=(HANDLE)CallService(MS_DB_EVENT_FINDNEXT,(WPARAM)hDbEvent,0);
- continue;
- }
-
- if (dbei.cbBlob >= id_length && strncmp((char *)(dbei.pBlob + dbei.cbBlob - id_length), id, id_length - 1) == 0) {
- // event is tagged with source contact id - remove
- HANDLE hDbEventNext;
-
- if (time_now > earliest_time) { // just in case
- SendMessage(prog, PBM_SETPOS, (WPARAM)(int)(100.0 * (dbei.timestamp - earliest_time) / (time_now - earliest_time)), 0);
- UpdateWindow(progress_dialog);
- }
-
- hDbEventNext = (HANDLE)CallService(MS_DB_EVENT_FINDNEXT,(WPARAM)hDbEvent,0);
- CallService(MS_DB_EVENT_DELETE, (WPARAM)hContactRemoveFrom, (LPARAM)hDbEvent);
- hDbEvent = hDbEventNext;
- continue;
- }
-
- hDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDNEXT,(WPARAM)hDbEvent,0);
- }
- //CallService(MS_DB_SETSAFETYMODE, (WPARAM)TRUE, 0);
-
- DestroyWindow(progress_dialog);
- if (buffer) mir_free(buffer);
- mir_free(id);
-}
-
-char *Meta_GetUniqueIdentifier(HANDLE hContact, DWORD *pused) {
- char *proto = GetContactProto(hContact);
- char *field;
- char *id;
- char buff[256];
- DWORD used;
- DBVARIANT dbv;
-
- id = (char *)mir_alloc(256);
-
- if ( !proto) return 0;
-
- strncpy(id, proto, 127);
- strcat(id, "*"); // seperate proto & proto id with asterisk to make one long comparable string
-
- used = strlen(id);
-
- field = (char *)CallProtoService(proto,PS_GETCAPS,PFLAG_UNIQUEIDSETTING,0);
- if ( !field) return 0;
-
- db_get(hContact,proto,field,&dbv);
- switch(dbv.type)
- {
- case DBVT_ASCIIZ:
- sprintf(buff,"%s",dbv.pszVal);
- break;
- case DBVT_BYTE:
- sprintf(buff,"%d",dbv.bVal);
- break;
- case DBVT_WORD:
- sprintf(buff,"%d",dbv.wVal);
- break;
- case DBVT_DWORD:
- sprintf(buff,"%d",dbv.dVal);
- break;
- default:
- sprintf(buff,"bugger this");
- }
- db_free(&dbv);
-
- strncpy(id + used, buff, 256 - used);
- if (used) {
- *pused = (DWORD)(used + strlen(buff) + 1);
- if (*pused > 256) *pused = 256;
- }
-
- return id;
-}
-*/
void Meta_FixStatus(HANDLE hMeta) {
HANDLE most_online = Meta_GetMostOnlineSupporting(hMeta, PFLAGNUM_1, 0);
if (most_online) {
- char *proto = GetContactProto(most_online);
- if (proto) {
- WORD status = (WORD)db_get_w(most_online, proto, "Status", (WORD)ID_STATUS_OFFLINE);
+ char *szProto = GetContactProto(most_online);
+ if (szProto) {
+ WORD status = (WORD)db_get_w(most_online, szProto, "Status", (WORD)ID_STATUS_OFFLINE);
db_set_w(hMeta, META_PROTO, "Status", status);
}
else db_set_w(hMeta, META_PROTO, "Status", (WORD)ID_STATUS_OFFLINE);