diff --git a/protocols/purple/PurpleApp.cpp b/protocols/purple/PurpleApp.cpp index b9c0556..51eb75c 100644 --- a/protocols/purple/PurpleApp.cpp +++ b/protocols/purple/PurpleApp.cpp @@ -173,10 +173,19 @@ PurpleApp::ImMessage(BMessage* msg) PurpleStatusPrimitive prim = cardie_status_to_purple(status); const char* primId = purple_primitive_get_id_from_type(prim); - std::cout << "setting status to " << primId << "…\n"; + std::cout << "purple setting status to " << primId << "…\n"; purple_account_set_status(account, primId, true); break; } + case IM_SET_OWN_NICKNAME: + { + PurpleAccount* account = _AccountFromMessage(msg); + const char* nick; + if (msg->FindString("user_name", &nick) == B_OK) + purple_account_set_public_alias(account, nick, + NULL, &callback_set_public_alias_failure); + break; + } case IM_SEND_MESSAGE: { BString body; @@ -1039,6 +1048,8 @@ init_signals() &handle, PURPLE_CALLBACK(signal_account_signed_on), NULL); purple_signal_connect(purple_accounts_get_handle(), "account-error-changed", &handle, PURPLE_CALLBACK(signal_account_error_changed), NULL); + purple_signal_connect(purple_accounts_get_handle(), "account-alias-changed", + &handle, PURPLE_CALLBACK(signal_account_alias_changed), NULL); purple_signal_connect(purple_accounts_get_handle(), "account-status-changed", &handle, PURPLE_CALLBACK(signal_account_status_changed), NULL); @@ -1116,6 +1127,15 @@ signal_account_error_changed(PurpleAccount* account, } +static void +signal_account_alias_changed(PurpleAccount* account, const char* old) +{ + BMessage own(IM_MESSAGE); + own.AddInt32("im_what", IM_OWN_NICKNAME_SET); + own.AddString("user_name", purple_account_get_alias(account)); + ((PurpleApp*)be_app)->SendMessage(account, own); +} + static void signal_account_status_changed(PurpleAccount* account, PurpleStatus* old, @@ -1484,7 +1504,7 @@ ui_op_notify_message(PurpleNotifyMsgType type, const char* title, BString text = _tr(primary); text << "\n" << _tr(secondary); - BAlert* alert = new BAlert(title, text.String(), "OK"); + BAlert* alert = new BAlert(title, text.String(), B_TRANSLATE("OK")); if (type == PURPLE_NOTIFY_MSG_WARNING) alert->SetType(B_WARNING_ALERT); @@ -1496,6 +1516,18 @@ ui_op_notify_message(PurpleNotifyMsgType type, const char* title, } +static void +callback_set_public_alias_failure(PurpleAccount* account, const char* error) +{ + BString text = B_TRANSLATE("Couldn't set your nick:\n%error%"); + text.ReplaceAll("%error%", error); + + BAlert* alert = new BAlert(B_TRANSLATE("Failed to set nickname"), text, + B_TRANSLATE("OK")); + alert->Go(NULL); +} + + bool is_own_user(PurpleAccount* account, const char* name) { diff --git a/protocols/purple/PurpleApp.h b/protocols/purple/PurpleApp.h index db774fa..9e03784 100644 --- a/protocols/purple/PurpleApp.h +++ b/protocols/purple/PurpleApp.h @@ -124,6 +124,8 @@ private: static void signal_account_error_changed(PurpleAccount* account, const PurpleConnectionErrorInfo* old_error, const PurpleConnectionErrorInfo* current_error); + static void signal_account_alias_changed(PurpleAccount* account, + const char* old); static void signal_account_status_changed(PurpleAccount* account, PurpleStatus* old, PurpleStatus* cur); @@ -214,11 +216,15 @@ private: void* user_data, size_t action_count, va_list actions); - // Notify ui ops +// Notify ui ops static void* ui_op_notify_message(PurpleNotifyMsgType type, const char* title, const char* primary, const char* secondary); +// Callbacks + static void callback_set_public_alias_failure(PurpleAccount* account, + const char* error); + // Util bool is_own_user(PurpleAccount* account, const char* name);