/pidgin/main: 76b701912a9d: Finch-OTR: implement e2ee conversati...
Tomasz Wasilczyk
twasilczyk at pidgin.im
Sat Apr 26 13:56:04 EDT 2014
Changeset: 76b701912a9d4c989ecc980b62644d84c69e99e0
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-04-26 19:55 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/76b701912a9d
Description:
Finch-OTR: implement e2ee conversation menu
diffstat:
finch/gntconv.c | 40 ++++++++++++++++++++++++++++++++++++++++
finch/gntconv.h | 14 +++++++++++---
finch/libgnt/gnt.h | 2 ++
finch/libgnt/gntmenu.c | 2 ++
finch/libgnt/gntmenuitem.c | 26 ++++++++++++++++++++++++++
finch/libgnt/gntmenuitem.h | 38 ++++++++++++++++++++++++++++++++++++++
libpurple/e2ee.c | 24 ++++++++++++++++++++++--
libpurple/e2ee.h | 14 ++++++++++++++
pidgin/gtkconv.c | 10 +++-------
9 files changed, 158 insertions(+), 12 deletions(-)
diffs (truncated from 318 to 300 lines):
diff --git a/finch/gntconv.c b/finch/gntconv.c
--- a/finch/gntconv.c
+++ b/finch/gntconv.c
@@ -63,6 +63,7 @@
static void finch_write_common(PurpleConversation *conv, const char *who,
const char *message, PurpleMessageFlags flags, time_t mtime);
static void generate_send_to_menu(FinchConv *ggc);
+static void generate_e2ee_menu(FinchConv *ggc);
static int color_message_receive;
static int color_message_send;
@@ -431,6 +432,8 @@ conv_updated(PurpleConversation *conv, P
gnt_screen_rename_widget(ggconv->window, title);
g_free(title);
+ generate_e2ee_menu(ggconv);
+
return;
}
}
@@ -619,6 +622,41 @@ generate_send_to_menu(FinchConv *ggc)
}
static void
+generate_e2ee_menu(FinchConv *ggc)
+{
+ GntMenu *sub;
+ GntWidget *menu = ggc->menu;
+ PurpleConversation *conv = ggc->active_conv;
+ GntMenuItem *item;
+ PurpleE2eeProvider *eprov;
+ GList *menu_actions, *it;
+
+ eprov = purple_e2ee_provider_get_main();
+
+ item = ggc->u.im->e2ee_menu;
+ if (item == NULL) {
+ item = gnt_menuitem_new(NULL);
+ gnt_menu_add_item(GNT_MENU(menu), item);
+ ggc->u.im->e2ee_menu = item;
+ }
+ sub = GNT_MENU(gnt_menu_new(GNT_MENU_POPUP));
+ gnt_menuitem_set_submenu(item, GNT_MENU(sub));
+
+ gnt_menuitem_set_visible(item, (eprov != NULL));
+ if (eprov == NULL)
+ return;
+ gnt_menuitem_set_text(item, purple_e2ee_provider_get_name(eprov));
+
+ menu_actions = purple_e2ee_provider_get_conv_menu_actions(eprov, conv);
+ for (it = menu_actions; it; it = g_list_next(it)) {
+ PurpleMenuAction *action = it->data;
+
+ finch_append_menu_action(sub, action, conv);
+ }
+ g_list_free(menu_actions);
+}
+
+static void
invite_cb(GntMenuItem *item, gpointer ggconv)
{
FinchConv *fc = ggconv;
@@ -688,6 +726,8 @@ gg_create_menu(FinchConv *ggc)
gnt_menuitem_set_callback(item, invite_cb, ggc);
}
+ generate_e2ee_menu(ggc);
+
item = gnt_menuitem_new(_("View Log..."));
gnt_menu_add_item(GNT_MENU(sub), item);
gnt_menuitem_set_callback(item, view_log_cb, ggc);
diff --git a/finch/gntconv.h b/finch/gntconv.h
--- a/finch/gntconv.h
+++ b/finch/gntconv.h
@@ -73,14 +73,22 @@ struct _FinchConv
struct _FinchConvChat
{
GntWidget *userlist; /* the userlist */
- void *pad1;
- void *pad2;
+
+ void *finch_reserved1;
+ void *finch_reserved2;
+ void *finch_reserved3;
+ void *finch_reserved4;
};
struct _FinchConvIm
{
GntMenuItem *sendto;
- void *something_for_later;
+ GntMenuItem *e2ee_menu;
+
+ void *finch_reserved1;
+ void *finch_reserved2;
+ void *finch_reserved3;
+ void *finch_reserved4;
};
/**
diff --git a/finch/libgnt/gnt.h b/finch/libgnt/gnt.h
--- a/finch/libgnt/gnt.h
+++ b/finch/libgnt/gnt.h
@@ -64,6 +64,8 @@ void gnt_init(void);
*
* You have to call this before #gnt_init. You might want to call this
* with %NULL, to free the resources, but not before a call to #gnt_quit.
+ *
+ * Since: 2.8.0
*/
void gnt_set_config_dir(const gchar *config_dir);
diff --git a/finch/libgnt/gntmenu.c b/finch/libgnt/gntmenu.c
--- a/finch/libgnt/gntmenu.c
+++ b/finch/libgnt/gntmenu.c
@@ -87,6 +87,8 @@ gnt_menu_draw(GntWidget *widget)
for (i = 0, iter = menu->list; iter; iter = iter->next, i++) {
GntMenuItem *item = GNT_MENU_ITEM(iter->data);
+ if (!gnt_menuitem_is_visible(item))
+ continue;
type = ' ' | gnt_color_pair(GNT_COLOR_HIGHLIGHT);
if (i == menu->selected)
type |= A_REVERSE;
diff --git a/finch/libgnt/gntmenuitem.c b/finch/libgnt/gntmenuitem.c
--- a/finch/libgnt/gntmenuitem.c
+++ b/finch/libgnt/gntmenuitem.c
@@ -65,6 +65,10 @@ gnt_menuitem_class_init(GntMenuItemClass
static void
gnt_menuitem_init(GTypeInstance *instance, gpointer klass)
{
+ GntMenuItem *item = GNT_MENU_ITEM(instance);
+ GntMenuItemPriv *priv = &item->priv;
+
+ priv->visible = TRUE;
}
/******************************************************************************
@@ -157,3 +161,25 @@ gboolean gnt_menuitem_activate(GntMenuIt
return FALSE;
}
+void
+gnt_menuitem_set_visible(GntMenuItem *item, gboolean visible)
+{
+ GntMenuItemPriv *priv = &item->priv;
+
+ priv->visible = visible;
+}
+
+gboolean
+gnt_menuitem_is_visible(GntMenuItem *item)
+{
+ g_return_val_if_fail(GNT_IS_MENU_ITEM(item), FALSE);
+
+ return item->priv.visible;
+}
+
+void
+gnt_menuitem_set_text(GntMenuItem *item, const gchar *text)
+{
+ g_free(item->text);
+ item->text = g_strdup(text);
+}
diff --git a/finch/libgnt/gntmenuitem.h b/finch/libgnt/gntmenuitem.h
--- a/finch/libgnt/gntmenuitem.h
+++ b/finch/libgnt/gntmenuitem.h
@@ -56,6 +56,7 @@ struct _GntMenuItemPriv
int y;
char trigger;
char *id;
+ gboolean visible;
};
typedef void (*GntMenuItemCallback)(GntMenuItem *item, gpointer data);
@@ -195,6 +196,43 @@ const char * gnt_menuitem_get_id(GntMenu
*/
gboolean gnt_menuitem_activate(GntMenuItem *item);
+/**
+ * gnt_menuitem_set_visible:
+ * @item: The menuitem.
+ * @visible: %TRUE to make @item visible, %FALSE to hide it.
+ *
+ * Sets @item visible or not.
+ *
+ * Since: 2.8.0
+ */
+void
+gnt_menuitem_set_visible(GntMenuItem *item, gboolean visible);
+
+/**
+ * gnt_menuitem_is_visible:
+ * @item: The menuitem.
+ *
+ * Checks, if the @item is visible.
+ *
+ * Returns: %TRUE, if the @item is visible.
+ *
+ * Since: 2.8.0
+ */
+gboolean
+gnt_menuitem_is_visible(GntMenuItem *item);
+
+/**
+ * gnt_menuitem_set_text:
+ * @item: The menuitem.
+ * @text: The new text.
+ *
+ * Changes the text for an @item.
+ *
+ * Since: 2.8.0
+ */
+void
+gnt_menuitem_set_text(GntMenuItem *item, const gchar *text);
+
G_END_DECLS
#endif /* GNT_MENUITEM_H */
diff --git a/libpurple/e2ee.c b/libpurple/e2ee.c
--- a/libpurple/e2ee.c
+++ b/libpurple/e2ee.c
@@ -168,7 +168,7 @@ purple_e2ee_provider_register(PurpleE2ee
void
purple_e2ee_provider_unregister(PurpleE2eeProvider *provider)
{
- GList *it;
+ GList *it, *clear_states = NULL;
g_return_if_fail(provider != NULL);
if (main_provider != provider) {
@@ -184,10 +184,14 @@ purple_e2ee_provider_unregister(PurpleE2
if (!state)
continue;
if (provider == purple_e2ee_state_get_provider(state))
- purple_conversation_set_e2ee_state(conv, NULL);
+ clear_states = g_list_prepend(clear_states, conv);
}
main_provider = NULL;
+
+ for (it = clear_states; it; it = g_list_next(it))
+ purple_conversation_set_e2ee_state(it->data, NULL);
+ g_list_free(clear_states);
}
PurpleE2eeProvider *
@@ -230,3 +234,19 @@ purple_e2ee_provider_get_conv_menu_cb(Pu
return provider->conv_menu_cb;
}
+
+GList *
+purple_e2ee_provider_get_conv_menu_actions(PurpleE2eeProvider *provider,
+ PurpleConversation *conv)
+{
+ PurpleE2eeConvMenuCallback cb;
+
+ g_return_val_if_fail(provider, NULL);
+ g_return_val_if_fail(conv, NULL);
+
+ cb = purple_e2ee_provider_get_conv_menu_cb(provider);
+ if (cb == NULL)
+ return NULL;
+
+ return cb(conv);
+}
diff --git a/libpurple/e2ee.h b/libpurple/e2ee.h
--- a/libpurple/e2ee.h
+++ b/libpurple/e2ee.h
@@ -240,6 +240,20 @@ purple_e2ee_provider_set_conv_menu_cb(Pu
PurpleE2eeConvMenuCallback
purple_e2ee_provider_get_conv_menu_cb(PurpleE2eeProvider *provider);
+/**
+ * purple_e2ee_provider_get_conv_menu_actions:
+ * @provider: The E2EE provider.
+ * @conv: The conversation.
+ *
+ * Returns the list of actions for an E2EE menu.
+ *
+ * Returns: (transfer container): the #GList of #PurpleMenuAction's. Should be
+ * #g_list_free'd when done using it.
+ */
+GList *
+purple_e2ee_provider_get_conv_menu_actions(PurpleE2eeProvider *provider,
+ PurpleConversation *conv);
+
G_END_DECLS
#endif /* _PURPLE_E2EE_H_ */
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -4167,8 +4167,7 @@ generate_e2ee_controls(PidginConvWindow
PurpleE2eeState *state;
PurpleE2eeProvider *provider;
GtkWidget *menu;
- PurpleE2eeConvMenuCallback menu_cb;
- GList *menu_actions = NULL, *it;
More information about the Commits
mailing list