changeset 5877:f336fc0a7b8b

[gaim-migrate @ 6309] Added this cool little account drop-down widget, which is only used in pounces right now. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sun, 15 Jun 2003 03:17:41 +0000
parents 8d6e5f804325
children 9e54bb2ee3b5
files src/account.c src/account.h src/gtkpounce.c src/gtkutils.c src/gtkutils.h
diffstat 5 files changed, 180 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/account.c	Sun Jun 15 02:19:54 2003 +0000
+++ b/src/account.c	Sun Jun 15 03:17:41 2003 +0000
@@ -80,6 +80,7 @@
 } AccountParserData;
 
 static GList   *accounts = NULL;
+static GList   *active_accounts = NULL;
 static guint    accounts_save_timer = 0;
 static gboolean accounts_loaded = FALSE;
 
@@ -170,6 +171,9 @@
 
 	gaim_connection_connect(gc);
 
+	if (gaim_account_is_connected(account))
+		active_accounts = g_list_append(active_accounts, account);
+
 	return gc;
 }
 
@@ -181,6 +185,8 @@
 
 	gaim_connection_disconnect(account->gc);
 
+	active_accounts = g_list_remove(active_accounts, account);
+
 	account->gc = NULL;
 }
 
@@ -1265,6 +1271,12 @@
 	return accounts;
 }
 
+GList *
+gaim_accounts_get_active(void)
+{
+	return active_accounts;
+}
+
 GaimAccount *
 gaim_accounts_find(const char *name, GaimProtocol protocol)
 {
--- a/src/account.h	Sun Jun 15 02:19:54 2003 +0000
+++ b/src/account.h	Sun Jun 15 03:17:41 2003 +0000
@@ -492,6 +492,13 @@
 GList *gaim_accounts_get_all(void);
 
 /**
+ * Returns a list of all active accounts.
+ *
+ * @return A list of all accounts.
+ */
+GList *gaim_accounts_get_active(void);
+
+/**
  * Finds an account with the specified name and protocol.
  *
  * @param name     The account username.
--- a/src/gtkpounce.c	Sun Jun 15 02:19:54 2003 +0000
+++ b/src/gtkpounce.c	Sun Jun 15 03:17:41 2003 +0000
@@ -269,11 +269,13 @@
 }
 
 static void
-pounce_choose_cb(GtkWidget *item, GaimGtkPounceDialog *dialog)
+pounce_choose_cb(GtkWidget *item, GaimAccount *account,
+				 GaimGtkPounceDialog *dialog)
 {
-	dialog->account = g_object_get_data(G_OBJECT(item), "user_data");
+	dialog->account = account;
 }
 
+#if 0
 static GtkWidget *
 pounce_user_menu(GaimGtkPounceDialog *dialog)
 {
@@ -321,6 +323,7 @@
 
 	return opt_menu;
 }
+#endif
 
 static void
 buddy_changed_cb(GtkEntry *entry, GaimGtkPounceDialog *dialog)
@@ -405,7 +408,10 @@
 	gtk_widget_show(label);
 	gtk_size_group_add_widget(sg, label);
 
-	dialog->account_menu = pounce_user_menu(dialog);
+	dialog->account_menu =
+		gaim_gtk_account_option_menu_new(dialog->account, TRUE,
+										 G_CALLBACK(pounce_choose_cb), dialog);
+
 	gtk_box_pack_start(GTK_BOX(hbox), dialog->account_menu, FALSE, FALSE, 0);
 	gtk_widget_show(dialog->account_menu);
 
--- a/src/gtkutils.c	Sun Jun 15 02:19:54 2003 +0000
+++ b/src/gtkutils.c	Sun Jun 15 03:17:41 2003 +0000
@@ -641,3 +641,140 @@
 
 	return optmenu;
 }
+
+static void
+account_menu_cb(GtkWidget *optmenu, GCallback cb)
+{
+	GtkWidget *menu;
+	GtkWidget *item;
+	GaimAccount *account;
+	gpointer user_data;
+
+	menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu));
+	item = gtk_menu_get_active(GTK_MENU(menu));
+
+	account   = g_object_get_data(G_OBJECT(item),    "account");
+	user_data = g_object_get_data(G_OBJECT(optmenu), "user_data");
+
+	if (cb != NULL)
+		((void (*)(GtkWidget *, GaimAccount *, gpointer))cb)(item, account,
+															 user_data);
+}
+
+GtkWidget *
+gaim_gtk_account_option_menu_new(GaimAccount *default_account,
+								 gboolean show_all, GCallback cb,
+								 gpointer user_data)
+{
+	GaimAccount *account;
+	GList *list;
+	GtkWidget *hbox;
+	GtkWidget *label;
+	GtkWidget *optmenu;
+	GtkWidget *menu;
+	GtkWidget *item;
+	GtkWidget *image;
+	GdkPixbuf *pixbuf;
+	GdkPixbuf *scale;
+	GList *p;
+	GtkSizeGroup *sg;
+	char *filename;
+	const char *proto_name;
+	char buf[256];
+	int i, selected_index = -1;
+
+	optmenu = gtk_option_menu_new();
+	gtk_widget_show(optmenu);
+
+	g_object_set_data(G_OBJECT(optmenu), "user_data", user_data);
+
+	menu = gtk_menu_new();
+	gtk_widget_show(menu);
+
+	sg  = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+
+	if (show_all)
+		list = gaim_accounts_get_all();
+	else
+		list = gaim_accounts_get_active();
+
+	for (p = list, i = 0; p != NULL; p = p->next, i++) {
+		GaimPluginProtocolInfo *prpl_info = NULL;
+		GaimPlugin *plugin;
+
+		account = (GaimAccount *)p->data;
+
+		plugin = gaim_find_prpl(gaim_account_get_protocol(account));
+
+		if (plugin != NULL)
+			prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(plugin);
+
+		/* Create the item. */
+		item = gtk_menu_item_new();
+
+		/* Create the hbox. */
+		hbox = gtk_hbox_new(FALSE, 4);
+		gtk_container_add(GTK_CONTAINER(item), hbox);
+		gtk_widget_show(hbox);
+
+		/* Load the image. */
+		if (prpl_info != NULL) {
+			proto_name = prpl_info->list_icon(NULL, NULL);
+			g_snprintf(buf, sizeof(buf), "%s.png", proto_name);
+
+			filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status",
+										"default", buf, NULL);
+			pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
+			g_free(filename);
+
+			if (pixbuf != NULL) {
+				/* Scale and insert the image */
+				scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16,
+												GDK_INTERP_BILINEAR);
+				image = gtk_image_new_from_pixbuf(scale);
+
+				g_object_unref(G_OBJECT(pixbuf));
+				g_object_unref(G_OBJECT(scale));
+			}
+			else
+				image = gtk_image_new();
+		}
+		else
+			image = gtk_image_new();
+
+		gtk_size_group_add_widget(sg, image);
+
+		gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
+		gtk_widget_show(image);
+
+		g_snprintf(buf, sizeof(buf), "%s (%s)",
+				   gaim_account_get_username(account), plugin->info->name);
+
+		/* Create the label. */
+		label = gtk_label_new(buf);
+		gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
+		gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+		gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
+		gtk_widget_show(label);
+
+		g_object_set_data(G_OBJECT(item), "account", account);
+
+		gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+		gtk_widget_show(item);
+
+		if (account == default_account)
+			selected_index = i;
+	}
+
+	gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
+
+	if (selected_index != -1)
+		gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), selected_index);
+
+	g_signal_connect(G_OBJECT(optmenu), "changed",
+					 G_CALLBACK(account_menu_cb), cb);
+
+	g_object_unref(sg);
+
+	return optmenu;
+}
--- a/src/gtkutils.h	Sun Jun 15 02:19:54 2003 +0000
+++ b/src/gtkutils.h	Sun Jun 15 03:17:41 2003 +0000
@@ -176,4 +176,19 @@
 											 GCallback cb,
 											 gpointer user_data);
 
+/**
+ * Creates a drop-down option menu filled with accounts.
+ *
+ * @param default_account The account to select by default.
+ * @param show_all        Whether or not to show all accounts, or just active
+ *                        accounts.
+ * @param cb              The callback to call when an account is selected.
+ * @param user_data       Data to pass to the callback function.
+ *
+ * @return The drop-down option menu.
+ */
+GtkWidget *gaim_gtk_account_option_menu_new(GaimAccount *default_account,
+											gboolean show_all, GCallback cb,
+											gpointer user_data);
+
 #endif /* _GAIM_GTK_UTILS_H_ */