From 91ab9d8fb7f0572605da89a54ccddbf74efc1598 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Mon, 12 Jul 2021 10:09:29 -0500 Subject: [PATCH] (purple) NotifyMessage dialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First of the NotifyUiOps― not sure if the others are used for anything useful in our use-case, I'll implement as I run into them. --- protocols/purple/Makefile | 1 + protocols/purple/PurpleApp.cpp | 39 +++++++++++++++++++++++++++++++ protocols/purple/PurpleApp.h | 5 ++++ protocols/purple/PurpleDialog.cpp | 4 ++-- protocols/purple/PurpleDialog.h | 1 - 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/protocols/purple/Makefile b/protocols/purple/Makefile index 6100cba..08b1485 100644 --- a/protocols/purple/Makefile +++ b/protocols/purple/Makefile @@ -33,6 +33,7 @@ APP_MIME_SIG = application/x-vnd.caya.purple # Also note that spaces in folder names do not work well with this Makefile. SRCS = \ protocols/purple/PurpleApp.cpp \ + protocols/purple/PurpleDialog.cpp \ protocols/purple/PurpleProtocol.cpp \ # Specify the resource definition files to use. Full or relative paths can be diff --git a/protocols/purple/PurpleApp.cpp b/protocols/purple/PurpleApp.cpp index fc5a9a3..3d177b5 100644 --- a/protocols/purple/PurpleApp.cpp +++ b/protocols/purple/PurpleApp.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -916,11 +917,30 @@ static PurpleRequestUiOps _ui_op_request = }; +static PurpleNotifyUiOps _ui_op_notify = +{ + ui_op_notify_message, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL +}; + + void init_ui_ops() { purple_eventloop_set_ui_ops(&_ui_op_eventloops); purple_request_set_ui_ops(&_ui_op_request); + purple_notify_set_ui_ops(&_ui_op_notify); } @@ -1275,6 +1295,25 @@ ui_op_request_action_with_icon(const char* title, const char* primary, } +static void* +ui_op_notify_message(PurpleNotifyMsgType type, const char* title, + const char* primary, const char* secondary) +{ + BString text = primary; + text << "\n" << secondary; + + BAlert* alert = new BAlert(title, text.String(), "OK"); + + if (type == PURPLE_NOTIFY_MSG_WARNING) + alert->SetType(B_WARNING_ALERT); + else if (type == PURPLE_NOTIFY_MSG_ERROR) + alert->SetType(B_STOP_ALERT); + + alert->Go(NULL); + return NULL; +} + + bool is_own_user(PurpleAccount* account, const char* name) { diff --git a/protocols/purple/PurpleApp.h b/protocols/purple/PurpleApp.h index a1a30e8..8b471b0 100644 --- a/protocols/purple/PurpleApp.h +++ b/protocols/purple/PurpleApp.h @@ -200,6 +200,11 @@ private: void* user_data, size_t action_count, va_list actions); + // Notify ui ops + static void* ui_op_notify_message(PurpleNotifyMsgType type, + const char* title, const char* primary, + const char* secondary); + // Util bool is_own_user(PurpleAccount* account, const char* name); diff --git a/protocols/purple/PurpleDialog.cpp b/protocols/purple/PurpleDialog.cpp index 66fff84..43a694f 100644 --- a/protocols/purple/PurpleDialog.cpp +++ b/protocols/purple/PurpleDialog.cpp @@ -38,8 +38,8 @@ PurpleDialog::MessageReceived(BMessage* msg) int32 id; if (msg->FindInt32("index", &id) != B_OK) break; - PurpleRequestActionCb cb = fActions.ItemAt(0)->callback.action; - cb(fUserData, fActions.ItemAt(0)->index); + PurpleRequestActionCb cb = fActions.ItemAt(id)->callback.action; + cb(fUserData, fActions.ItemAt(id)->index); Quit(); break; } diff --git a/protocols/purple/PurpleDialog.h b/protocols/purple/PurpleDialog.h index 352d946..c98dec5 100644 --- a/protocols/purple/PurpleDialog.h +++ b/protocols/purple/PurpleDialog.h @@ -13,7 +13,6 @@ const uint32 ACTION_BUTTON = 'PDab'; - struct RequestAction { BString name;