Commit 62bb6dac authored by cypherpunk's avatar cypherpunk
Browse files

	* otr-plugin.c:
	* gtk-dialog.c: Replace the OTR button in the button box if the
	user changes the button style (which causes gaim to remove all
	the buttons, and only replace its own).

	* gtk-dialog.c: Add a right-button context menu to the OTR
	button.  Currently, it only has one entry, which has the same
	effect as clicking the button; eventually, you'll be able to do
	other things here, like getting the info currently in the
	"Private Connection Established" dialog.  This also opens the
	door to making the button functionality available if the user
	hides his buttons completely (if we can find a place to make
	this context menu appear; say, on some F-key?).

	* otr-plugin.c (notify_cb): Initialize gaimlevel so that -Wall
	stops complaining, even though there's no situation in which it
	can actually get used while unset.
parent 80ad8452
2005-05-27
* otr-plugin.c:
* gtk-dialog.c: Replace the OTR button in the button box if the
user changes the button style (which causes gaim to remove all
the buttons, and only replace its own).
* gtk-dialog.c: Add a right-button context menu to the OTR
button. Currently, it only has one entry, which has the same
effect as clicking the button; eventually, you'll be able to do
other things here, like getting the info currently in the
"Private Connection Established" dialog. This also opens the
door to making the button functionality available if the user
hides his buttons completely (if we can find a place to make
this context menu appear; say, on some F-key?).
* otr-plugin.c (notify_cb): Initialize gaimlevel so that -Wall
stops complaining, even though there's no situation in which it
can actually get used while unset.
2005-05-19
* otr-plugin.h:
......
27 May 2005:
- The OTR button no longer disappears if you change your button style in
the gaim preferences.
- There is now a right-click context menu on the OTR button.
19 May 2005:
- OTR doesn't work over IRC (since IRC's maximum message size is too
small for a Key Exchange Message to fit), so don't even provide the
......
......@@ -324,18 +324,39 @@ static void otrg_gtk_dialog_unknown_fingerprint(OtrlUserState us,
gtk_widget_show_all(dialog);
}
static void otrg_gtk_dialog_clicked_connect(GtkWidget *widget, gpointer data);
static void dialog_update_label_conv(GaimConversation *conv, int is_private)
{
GtkWidget *label;
GtkWidget *button;
GtkWidget *menu;
GtkWidget *menuitem;
GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv);
label = gaim_conversation_get_data(conv, "otr-label");
button = gaim_conversation_get_data(conv, "otr-button");
menu = gaim_conversation_get_data(conv, "otr-menu");
menuitem = gaim_conversation_get_data(conv, "otr-menuitem");
gtk_label_set_text(GTK_LABEL(label),
is_private ? "OTR:\nPrivate" : "OTR:\nNot private");
gtk_tooltips_set_tip(gtkconv->tooltips, button,
is_private ? "Refresh the private conversation"
: "Start a private conversation", NULL);
/* Create the appropriate menu item, first destroying any old one
* that may still be around. */
if (menuitem != NULL) {
gtk_object_destroy(GTK_OBJECT(menuitem));
}
menuitem = gtk_menu_item_new_with_mnemonic(
is_private ? "Refresh _private conversation"
: "Start _private conversation");
gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
GTK_SIGNAL_FUNC(otrg_gtk_dialog_clicked_connect), conv);
gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), menuitem);
gtk_widget_show(menuitem);
gaim_conversation_set_data(conv, "otr-menuitem", menuitem);
/* Use any non-NULL value for "private", NULL for "not private" */
gaim_conversation_set_data(conv, "otr-private",
is_private ? conv : NULL);
......@@ -417,7 +438,8 @@ static void otrg_gtk_dialog_stillconnected(ConnContext *context)
dialog_update_label(context, 1);
}
/* This is called when the OTR button in the button box is clicked. */
/* This is called when the OTR button in the button box is clicked, or
* when the appropriate context menu item is selected. */
static void otrg_gtk_dialog_clicked_connect(GtkWidget *widget, gpointer data)
{
const char *format;
......@@ -438,6 +460,36 @@ static void otrg_gtk_dialog_clicked_connect(GtkWidget *widget, gpointer data)
static void dialog_resensitize(GaimConversation *conv);
/* If the OTR button is right-clicked, show the context menu. */
static gboolean button_pressed(GtkWidget *w, GdkEventButton *event,
gpointer data)
{
GaimConversation *conv = data;
if ((event->button == 3) && (event->type == GDK_BUTTON_PRESS)) {
GtkWidget *menu = gaim_conversation_get_data(conv, "otr-menu");
if (menu) {
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
3, event->time);
return TRUE;
}
}
return FALSE;
}
/* If the OTR button gets destroyed on us, clean up the data we stored
* pointing to it. */
static void button_destroyed(GtkWidget *w, GaimConversation *conv)
{
GtkWidget *menu = gaim_conversation_get_data(conv, "otr-menu");
if (menu) gtk_object_destroy(GTK_OBJECT(menu));
g_hash_table_remove(conv->data, "otr-label");
g_hash_table_remove(conv->data, "otr-button");
g_hash_table_remove(conv->data, "otr-private");
g_hash_table_remove(conv->data, "otr-menu");
g_hash_table_remove(conv->data, "otr-menuitem");
}
/* Set up the per-conversation information display */
static void otrg_gtk_dialog_new_conv(GaimConversation *conv)
{
......@@ -450,12 +502,27 @@ static void otrg_gtk_dialog_new_conv(GaimConversation *conv)
GtkWidget *bbox;
GtkWidget *button;
GtkWidget *label;
GtkWidget *menu;
GtkWidget *menuitem;
/* Do nothing if this isn't an IM conversation */
if (gaim_conversation_get_type(conv) != GAIM_CONV_IM) return;
/* Do nothing if we're already set up */
if (gaim_conversation_get_data(conv, "otr-button")) return;
bbox = gtkconv->bbox;
/* See if we're already set up */
button = gaim_conversation_get_data(conv, "otr-button");
if (button) {
/* Check if we've been removed from the bbox; gaim does this
* when the user changes her prefs for the style of buttons to
* display. */
GList *children = gtk_container_get_children(GTK_CONTAINER(bbox));
if (!g_list_find(children, button)) {
gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
}
g_list_free(children);
return;
}
account = gaim_conversation_get_account(conv);
accountname = gaim_account_get_username(account);
......@@ -468,16 +535,25 @@ static void otrg_gtk_dialog_new_conv(GaimConversation *conv)
state = context ? context->state : CONN_UNCONNECTED;
g_free(username);
bbox = gtkconv->bbox;
button = gtk_button_new();
label = gtk_label_new(NULL);
gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
gtk_container_add(GTK_CONTAINER(button), label);
gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
menu = gtk_menu_new();
menuitem = NULL;
gaim_conversation_set_data(conv, "otr-label", label);
gaim_conversation_set_data(conv, "otr-button", button);
gaim_conversation_set_data(conv, "otr-menu", menu);
gaim_conversation_set_data(conv, "otr-menuitem", menuitem);
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(otrg_gtk_dialog_clicked_connect), conv);
g_signal_connect(G_OBJECT(button), "destroy",
G_CALLBACK(button_destroyed), conv);
g_signal_connect(G_OBJECT(button), "button-press-event",
G_CALLBACK(button_pressed), conv);
dialog_update_label_conv(conv, state == CONN_CONNECTED);
dialog_resensitize(conv);
......@@ -494,9 +570,6 @@ static void otrg_gtk_dialog_remove_conv(GaimConversation *conv)
button = gaim_conversation_get_data(conv, "otr-button");
if (button) gtk_object_destroy(GTK_OBJECT(button));
g_hash_table_remove(conv->data, "otr-label");
g_hash_table_remove(conv->data, "otr-button");
g_hash_table_remove(conv->data, "otr-private");
}
/* Set the OTR button to "sensitive" or "insensitive" as appropriate. */
......
......@@ -178,7 +178,7 @@ static void notify_cb(void *opdata, OtrlNotifyLevel level,
const char *accountname, const char *protocol, const char *username,
const char *title, const char *primary, const char *secondary)
{
GaimNotifyMsgType gaimlevel;
GaimNotifyMsgType gaimlevel = GAIM_NOTIFY_MSG_ERROR;
switch (level) {
case OTRL_NOTIFY_ERROR:
......@@ -411,6 +411,16 @@ static void process_connection_change(GaimConnection *conn, void *data)
otrg_dialog_resensitize_all();
}
static void process_button_type_change(const char *name, GaimPrefType type,
gpointer value, gpointer data)
{
/* If the user changes the style of the buttons at the bottom of the
* conversation window, gaim annoyingly removes all the buttons from
* the bbox, and reinserts its own. So we need to reinsert our
* buttons as well. */
otrg_dialog_resensitize_all();
}
static void otr_options_cb(GaimBlistNode *node, gpointer user_data)
{
/* We've already checked GAIM_BLIST_NODE_IS_BUDDY(node) */
......@@ -448,6 +458,8 @@ void otrg_plugin_disconnect(ConnContext *context)
context->accountname, context->protocol, context->username);
}
static guint button_type_cbid;
static gboolean otr_plugin_load(GaimPlugin *handle)
{
gchar *privkeyfile = g_build_filename(gaim_user_dir(), PRIVKEYFNAME, NULL);
......@@ -487,6 +499,9 @@ static gboolean otr_plugin_load(GaimPlugin *handle)
GAIM_CALLBACK(process_connection_change), NULL);
gaim_signal_connect(blist_handle, "blist-node-extended-menu",
otrg_plugin_handle, GAIM_CALLBACK(supply_extended_menu), NULL);
button_type_cbid = gaim_prefs_connect_callback(
"/gaim/gtk/conversations/button_type",
process_button_type_change, NULL);
gaim_conversation_foreach(otrg_dialog_new_conv);
......@@ -515,6 +530,7 @@ static gboolean otr_plugin_unload(GaimPlugin *handle)
GAIM_CALLBACK(process_connection_change));
gaim_signal_disconnect(blist_handle, "blist-node-extended-menu",
otrg_plugin_handle, GAIM_CALLBACK(supply_extended_menu));
gaim_prefs_disconnect_callback(button_type_cbid);
gaim_conversation_foreach(otrg_dialog_remove_conv);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment