/dev/tomkiewicz/e2ee: 0fbb73c987a4: E2EE: status icon implementa...

Tomasz Wasilczyk twasilczyk at pidgin.im
Sat Oct 5 11:29:18 EDT 2013


Changeset: 0fbb73c987a401932bf991ffd1e8662f9f896e2b
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2013-10-05 17:29 +0200
Branch:	 default
URL: https://hg.pidgin.im/dev/tomkiewicz/e2ee/rev/0fbb73c987a4

Description:

E2EE: status icon implementation for Pidgin

diffstat:

 libpurple/conversation.c                      |  11 +--
 libpurple/conversation.h                      |   2 +
 libpurple/e2ee.c                              |  22 +++++++-
 libpurple/e2ee.h                              |   6 ++
 pidgin/gtkconv.c                              |  81 ++++++++++++++++++++++++++-
 pidgin/gtkconvwin.h                           |   1 +
 pidgin/pixmaps/Makefile.am                    |   8 +-
 pidgin/pixmaps/e2ee-states/16/finished.png    |   0 
 pidgin/pixmaps/e2ee-states/16/not-private.png |   0 
 pidgin/pixmaps/e2ee-states/16/private.png     |   0 
 pidgin/pixmaps/e2ee-states/16/unverified.png  |   0 
 11 files changed, 118 insertions(+), 13 deletions(-)

diffs (297 lines):

diff --git a/libpurple/conversation.c b/libpurple/conversation.c
--- a/libpurple/conversation.c
+++ b/libpurple/conversation.c
@@ -953,8 +953,7 @@ purple_conversation_set_e2ee_state(Purpl
 	purple_e2ee_state_unref(conv->e2ee_state);
 	conv->e2ee_state = state;
 
-	purple_signal_emit(purple_conversations_get_handle(),
-		"conversation-e2ee-state-changed", conv);
+	purple_conversation_update(conv, PURPLE_CONV_UPDATE_E2EE);
 }
 
 PurpleE2eeState *
@@ -979,6 +978,9 @@ purple_conversation_get_e2ee_state(Purpl
 	} else
 		return NULL;
 
+	if (conv->e2ee_state == NULL)
+		return purple_e2ee_provider_get_default_state(provider);
+
 	if (purple_e2ee_state_get_provider(conv->e2ee_state) != provider) {
 		purple_debug_warning("conversation",
 			"e2ee state has invalid provider set");
@@ -2926,11 +2928,6 @@ purple_conversations_init(void)
 			     purple_value_new(PURPLE_TYPE_SUBTYPE,
 					    PURPLE_SUBTYPE_CONVERSATION),
 			     purple_value_new(PURPLE_TYPE_BOXED, "GList **"));
-
-	purple_signal_register(handle, "conversation-e2ee-state-changed",
-		purple_marshal_VOID__POINTER, NULL, 1,
-		purple_value_new(PURPLE_TYPE_SUBTYPE,
-			PURPLE_SUBTYPE_CONVERSATION));
 }
 
 void
diff --git a/libpurple/conversation.h b/libpurple/conversation.h
--- a/libpurple/conversation.h
+++ b/libpurple/conversation.h
@@ -73,6 +73,8 @@ typedef enum
 	PURPLE_CONV_UPDATE_LOGGING, /**< Logging for this conversation was
 	                               enabled or disabled. */
 	PURPLE_CONV_UPDATE_TOPIC,   /**< The topic for a chat was updated. */
+	PURPLE_CONV_UPDATE_E2EE,    /**< The End-to-end encryption state was
+	                               updated. */
 	/*
 	 * XXX These need to go when we implement a more generic core/UI event
 	 * system.
diff --git a/libpurple/e2ee.c b/libpurple/e2ee.c
--- a/libpurple/e2ee.c
+++ b/libpurple/e2ee.c
@@ -40,6 +40,7 @@ struct _PurpleE2eeState
 
 struct _PurpleE2eeProvider
 {
+	gchar *name;
 	PurpleE2eeFeatures features;
 	PurpleE2eeState *default_state;
 };
@@ -108,7 +109,7 @@ purple_e2ee_state_set_name(PurpleE2eeSta
 const gchar *
 purple_e2ee_state_get_name(PurpleE2eeState *state)
 {
-	g_return_val_if_fail(state, NULL);
+	g_return_val_if_fail(state != NULL, NULL);
 
 	return state->name;
 }
@@ -155,6 +156,7 @@ purple_e2ee_provider_free(PurpleE2eeProv
 		return;
 	}
 
+	g_free(provider->name);
 	g_free(provider);
 }
 
@@ -198,6 +200,24 @@ purple_e2ee_provider_get_features(Purple
 }
 
 void
+purple_e2ee_provider_set_name(PurpleE2eeProvider *provider, const gchar *name)
+{
+	g_return_if_fail(provider != NULL);
+	g_return_if_fail(name != NULL);
+
+	g_free(provider->name);
+	provider->name = g_strdup(name);
+}
+
+const gchar *
+purple_e2ee_provider_get_name(PurpleE2eeProvider *provider)
+{
+	g_return_val_if_fail(provider != NULL, NULL);
+
+	return provider->name;
+}
+
+void
 purple_e2ee_provider_set_default_state(PurpleE2eeProvider *provider,
 	PurpleE2eeState *state)
 {
diff --git a/libpurple/e2ee.h b/libpurple/e2ee.h
--- a/libpurple/e2ee.h
+++ b/libpurple/e2ee.h
@@ -98,6 +98,12 @@ PurpleE2eeFeatures
 purple_e2ee_provider_get_features(PurpleE2eeProvider *provider);
 
 void
+purple_e2ee_provider_set_name(PurpleE2eeProvider *provider, const gchar *name);
+
+const gchar *
+purple_e2ee_provider_get_name(PurpleE2eeProvider *provider);
+
+void
 purple_e2ee_provider_set_default_state(PurpleE2eeProvider *provider,
 	PurpleE2eeState *state);
 
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -119,7 +119,8 @@ typedef enum
 	PIDGIN_CONV_TAB_ICON			= 1 << 3,
 	PIDGIN_CONV_TOPIC			= 1 << 4,
 	PIDGIN_CONV_SMILEY_THEME		= 1 << 5,
-	PIDGIN_CONV_COLORIZE_TITLE		= 1 << 6
+	PIDGIN_CONV_COLORIZE_TITLE		= 1 << 6,
+	PIDGIN_CONV_E2EE			= 1 << 7
 }PidginConvFields;
 
 enum {
@@ -187,6 +188,7 @@ static GList *busy_list = NULL;
 static GList *xa_list = NULL;
 static GList *offline_list = NULL;
 static GHashTable *prpl_lists = NULL;
+static GHashTable *e2ee_stock = NULL;
 
 static PurpleTheme *default_conv_theme = NULL;
 
@@ -4124,6 +4126,71 @@ generate_send_to_items(PidginWindow *win
 	update_send_to_selection(win);
 }
 
+static GdkPixbuf *
+e2ee_stock_icon_get(const gchar *stock_name)
+{
+	gchar filename[100], *path;
+	GdkPixbuf *pixbuf;
+
+	if (g_hash_table_lookup_extended(e2ee_stock, stock_name, NULL, (gpointer*)&pixbuf))
+		return pixbuf;
+
+	g_snprintf(filename, sizeof(filename), "%s.png", stock_name);
+	path = g_build_filename(DATADIR, "pixmaps", "pidgin", "e2ee", "16",
+		filename, NULL);
+	pixbuf = pidgin_pixbuf_new_from_file(path);
+	g_free(path);
+
+	g_hash_table_insert(e2ee_stock, g_strdup(stock_name), pixbuf);
+	return pixbuf;
+}
+
+static void
+generate_e2ee_controls(PidginWindow *win)
+{
+	PidginConversation *gtkconv;
+	PurpleConversation *conv;
+	PurpleE2eeState *state;
+	PurpleE2eeProvider *provider;
+	GtkWidget *menu;
+
+	gtkconv = pidgin_conv_window_get_active_gtkconv(win);
+	g_return_if_fail(gtkconv != NULL);
+
+	conv = gtkconv->active_conv;
+	g_return_if_fail(conv != NULL);
+
+	if (win->menu.e2ee != NULL) {
+		gtk_widget_destroy(win->menu.e2ee);
+		win->menu.e2ee = NULL;
+	}
+
+	provider = purple_e2ee_provider_get_main();
+	state = purple_conversation_get_e2ee_state(conv);
+	if (state == NULL || provider == NULL)
+		return;
+	if (purple_e2ee_state_get_provider(state) != provider)
+		return;
+
+	win->menu.e2ee = gtk_image_menu_item_new_with_label(
+		purple_e2ee_provider_get_name(provider));
+
+	menu = gtk_menu_new();
+	gtk_menu_shell_insert(GTK_MENU_SHELL(win->menu.menubar),
+		win->menu.e2ee, 3);
+	gtk_menu_item_set_submenu(GTK_MENU_ITEM(win->menu.e2ee), menu);
+
+	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(win->menu.e2ee),
+		gtk_image_new_from_pixbuf(e2ee_stock_icon_get(
+			purple_e2ee_state_get_stock_icon(state))));
+
+	gtk_widget_set_tooltip_text(win->menu.e2ee,
+		purple_e2ee_state_get_name(state));
+
+	gtk_widget_show(win->menu.e2ee);
+	gtk_widget_show(menu);
+}
+
 static const char *
 get_chat_buddy_status_icon(PurpleConvChat *chat, const char *name, PurpleConvChatBuddyFlags flags)
 {
@@ -7402,6 +7469,9 @@ pidgin_conv_update_fields(PurpleConversa
 		regenerate_plugins_items(win);
 	}
 
+	if (fields & PIDGIN_CONV_E2EE)
+		generate_e2ee_controls(win);
+
 	if (fields & PIDGIN_CONV_TAB_ICON)
 	{
 		update_tab_icon(conv);
@@ -7599,6 +7669,10 @@ pidgin_conv_updated(PurpleConversation *
 	{
 		flags = PIDGIN_CONV_MENU;
 	}
+	else if (type == PURPLE_CONV_UPDATE_E2EE)
+	{
+		flags = PIDGIN_CONV_E2EE;
+	}
 
 	pidgin_conv_update_fields(conv, flags);
 }
@@ -8554,6 +8628,8 @@ pidgin_conversations_init(void)
 	void *blist_handle = purple_blist_get_handle();
 	char *theme_dir;
 
+	e2ee_stock = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref);
+
 	/* Conversations */
 	purple_prefs_add_none(PIDGIN_PREFS_ROOT "/conversations");
 	purple_prefs_add_none(PIDGIN_PREFS_ROOT "/conversations/themes");
@@ -8889,6 +8965,8 @@ pidgin_conversations_init(void)
 void
 pidgin_conversations_uninit(void)
 {
+	g_hash_table_destroy(e2ee_stock);
+	e2ee_stock = NULL;
 	purple_prefs_disconnect_by_handle(pidgin_conversations_get_handle());
 	purple_signals_disconnect_by_handle(pidgin_conversations_get_handle());
 	purple_signals_unregister_by_instance(pidgin_conversations_get_handle());
@@ -9890,6 +9968,7 @@ switch_conv_cb(GtkNotebook *notebook, Gt
 	                             purple_conversation_is_logging(conv));
 
 	generate_send_to_items(win);
+	generate_e2ee_controls(win);
 	regenerate_options_items(win);
 	regenerate_plugins_items(win);
 
diff --git a/pidgin/gtkconvwin.h b/pidgin/gtkconvwin.h
--- a/pidgin/gtkconvwin.h
+++ b/pidgin/gtkconvwin.h
@@ -77,6 +77,7 @@ struct _PidginWindow
 		GtkAction *show_formatting_toolbar;
 
 		GtkWidget *send_to;
+		GtkWidget *e2ee;
 
 		GtkWidget *tray;
 
diff --git a/pidgin/pixmaps/Makefile.am b/pidgin/pixmaps/Makefile.am
--- a/pidgin/pixmaps/Makefile.am
+++ b/pidgin/pixmaps/Makefile.am
@@ -89,10 +89,10 @@ DIALOGS_SCALABLE = \
 		dialogs/scalable/warning.svg
 
 E2EE_STATES_16 = \
-		e2ee-states/16/finished.png \
-		e2ee-states/16/not-private.png \
-		e2ee-states/16/private.png \
-		e2ee-states/16/unverified.png
+		e2ee/16/finished.png \
+		e2ee/16/not-private.png \
+		e2ee/16/private.png \
+		e2ee/16/unverified.png
 
 EMBLEMS_16 = \
 		emblems/16/aol-client.png \
diff --git a/pidgin/pixmaps/e2ee-states/16/finished.png b/pidgin/pixmaps/e2ee/16/finished.png
rename from pidgin/pixmaps/e2ee-states/16/finished.png
rename to pidgin/pixmaps/e2ee/16/finished.png
diff --git a/pidgin/pixmaps/e2ee-states/16/not-private.png b/pidgin/pixmaps/e2ee/16/not-private.png
rename from pidgin/pixmaps/e2ee-states/16/not-private.png
rename to pidgin/pixmaps/e2ee/16/not-private.png
diff --git a/pidgin/pixmaps/e2ee-states/16/private.png b/pidgin/pixmaps/e2ee/16/private.png
rename from pidgin/pixmaps/e2ee-states/16/private.png
rename to pidgin/pixmaps/e2ee/16/private.png
diff --git a/pidgin/pixmaps/e2ee-states/16/unverified.png b/pidgin/pixmaps/e2ee/16/unverified.png
rename from pidgin/pixmaps/e2ee-states/16/unverified.png
rename to pidgin/pixmaps/e2ee/16/unverified.png



More information about the Commits mailing list