changeset 4698:aa2ceea841b4

[gaim-migrate @ 5009] The docklet's back. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Tue, 11 Mar 2003 00:09:45 +0000
parents 4be12ff42986
children 2222cd30008a
files plugins/docklet/docklet.c src/buddy.c src/gtkft.c src/gtkft.h src/gtklist.h
diffstat 5 files changed, 113 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/docklet/docklet.c	Mon Mar 10 22:07:59 2003 +0000
+++ b/plugins/docklet/docklet.c	Tue Mar 11 00:09:45 2003 +0000
@@ -153,7 +153,7 @@
 	g_signal_connect(G_OBJECT(entry), "toggled", G_CALLBACK(docklet_toggle_mute), NULL);
 	gtk_menu_shell_append(GTK_MENU_SHELL(menu), entry);
 
-	gaim_new_item_from_stock(menu, _("File Transfers..."), GTK_STOCK_REVERT_TO_SAVED, G_CALLBACK(show_xfer_dialog), NULL, 0, 0, NULL);
+	gaim_new_item_from_stock(menu, _("File Transfers..."), GTK_STOCK_REVERT_TO_SAVED, G_CALLBACK(gaim_show_xfer_dialog), NULL, 0, 0, NULL);
 	gaim_new_item_from_pixbuf(menu, _("Accounts..."), "accounts-menu.png", G_CALLBACK(account_editor), NULL, 0, 0, NULL);
 	gaim_new_item_from_stock(menu, _("Preferences..."), GTK_STOCK_PREFERENCES, G_CALLBACK(show_prefs), NULL, 0, 0, NULL);
 
@@ -186,7 +186,7 @@
 				docklet_flush_queue();
 				docklet_update_status();
 			} else {
-				docklet_toggle();
+				gaim_gtk_blist_docklet_toggle();
 			}
 			break;
 		case 2:
@@ -296,8 +296,8 @@
 }
 
 static void docklet_embedded(GtkWidget *widget, void *data) {
-	debug_printf("Tray Icon: embedded\n");
-	docklet_add();
+	debug_printf("Tray Icon:embedded\n");
+	gaim_gtk_blist_docklet_add();
 }
 
 static void docklet_remove_callbacks() {
@@ -313,7 +313,7 @@
 static void docklet_destroyed(GtkWidget *widget, void *data) {
 	debug_printf("Tray Icon: destroyed\n");
 
-	docklet_remove();
+	gaim_gtk_blist_docklet_remove();
 
 	docklet_flush_queue();
 
@@ -448,7 +448,7 @@
 
 void gaim_plugin_remove() {
 	if (GTK_WIDGET_VISIBLE(docklet)) {
-		docklet_remove();
+		gaim_gtk_blist_docklet_remove();
 	}
 
 	docklet_flush_queue();
--- a/src/buddy.c	Mon Mar 10 22:07:59 2003 +0000
+++ b/src/buddy.c	Tue Mar 11 00:09:45 2003 +0000
@@ -56,12 +56,23 @@
 
 static struct gaim_gtk_buddy_list *gtkblist = NULL;
 
+/* Docklet nonsense */
+static gboolean gaim_gtk_blist_obscured = FALSE;
+
 static void gaim_gtk_blist_update(struct gaim_buddy_list *list, GaimBlistNode *node);
 
 /***************************************************
  *              Callbacks                          *
  ***************************************************/
 
+static void gaim_gtk_blist_destroy_cb()
+{
+	if (docklet_count)
+		gaim_blist_set_visible(FALSE);
+	else
+		do_quit();
+}
+
 static void gtk_blist_menu_im_cb(GtkWidget *w, struct buddy *b)
 {
        gaim_conversation_new(GAIM_CONV_IM, b->account, b->name);
@@ -302,7 +313,7 @@
 	{ N_("/Tools/A_ccounts"), "<CTL>A", account_editor, 0, NULL },
 	{ N_("/Tools/Preferences"), "<CTL>P", show_prefs, 0,
 	  "<StockItem>", GTK_STOCK_PREFERENCES },
-	{ N_("/Tools/_File Transfers"), NULL, NULL, 0,
+	{ N_("/Tools/_File Transfers"), NULL, gaim_show_xfer_dialog, 0,
 	  "<StockItem>", GTK_STOCK_REVERT_TO_SAVED },
 	{ N_("/Tools/sep2"), NULL, NULL, 0, "<Separator>" },
 	{ N_("/Tools/P_rotocol Actions"), NULL, NULL, 0, "<Branch>" },
@@ -561,6 +572,8 @@
 	gtkblist->vbox = gtk_vbox_new(FALSE, 6);
 	gtk_container_add(GTK_CONTAINER(gtkblist->window), gtkblist->vbox);
 
+	g_signal_connect(G_OBJECT(gtkblist->window), "delete_event", G_CALLBACK(gaim_gtk_blist_destroy_cb), NULL);
+
 	/******************************* Menu bar *************************************/
 	ift = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GaimMain>", NULL);
 	gtk_item_factory_create_items(ift, sizeof(blist_menu) / sizeof(*blist_menu),
@@ -828,10 +841,70 @@
 
 static void gaim_gtk_blist_set_visible(struct gaim_buddy_list *list, gboolean show)
 {
-	if (show)
-		gtk_widget_show(gtkblist->window);
-	else
-		gtk_widget_hide(gtkblist->window);
+	if (show) {
+		gtk_window_present(gtkblist->window);
+	} else {
+		if (!connections || docklet_count) {
+#ifdef _WIN32
+			wgaim_systray_minimize(blist);
+#endif
+			gtk_widget_hide(gtkblist->window);
+		} else {
+			gtk_window_iconify(GTK_WINDOW(gtkblist->window));
+		}
+	}
+}
+
+void gaim_gtk_blist_docklet_toggle() {
+	/* Useful for the docklet plugin and also for the win32 tray icon*/
+	/* This is called when one of those is clicked--it will show/hide the 
+	   buddy list/login window--depending on which is active */
+	if (connections && gtkblist) {
+		if (GTK_WIDGET_VISIBLE(gtkblist->window)) {
+			gaim_blist_set_visible(GAIM_WINDOW_ICONIFIED(gtkblist->window) || gaim_gtk_blist_obscured);
+		} else {
+#if _WIN32
+			wgaim_systray_maximize(blist);
+#endif
+			gaim_blist_set_visible(TRUE);
+		}
+	} else if (connections) {
+		/* we're logging in or something... do nothing */
+		debug_printf("docklet_toggle called with connections but no blist!\n");
+	} else {
+		if (GTK_WIDGET_VISIBLE(mainwindow)) {
+			if (GAIM_WINDOW_ICONIFIED(mainwindow)) {
+				gtk_window_present(GTK_WINDOW(mainwindow));
+			} else {
+#if _WIN32
+				wgaim_systray_minimize(mainwindow);
+#endif
+				gtk_widget_hide(mainwindow);
+			}
+		} else {
+#if _WIN32
+			wgaim_systray_maximize(mainwindow);
+#endif
+			gtk_window_present(GTK_WINDOW(mainwindow));
+		}
+	}
+}
+
+void gaim_gtk_blist_docklet_add()
+{
+	docklet_count++;
+}
+
+void gaim_gtk_blist_docklet_remove()
+{
+	docklet_count--;
+	if (!docklet_count) {
+		if (connections) {
+			gaim_blist_set_visible(TRUE);
+		} else {
+			gtk_window_present(GTK_WINDOW(gtkblist->window));
+		}
+	}
 }
 
 static struct gaim_blist_ui_ops blist_ui_ops =
--- a/src/gtkft.c	Mon Mar 10 22:07:59 2003 +0000
+++ b/src/gtkft.c	Tue Mar 11 00:09:45 2003 +0000
@@ -723,6 +723,22 @@
 }
 
 void
+gaim_show_xfer_dialog()
+{
+       struct gaim_gtkxfer_dialog *dialog;
+       
+       dialog = gaim_get_gtkxfer_dialog();
+       
+       if (dialog == NULL) {
+	       dialog = gaim_gtkxfer_dialog_new();
+
+	       gaim_set_gtkxfer_dialog(dialog);
+       }
+
+       gaim_gtkxfer_dialog_show(dialog);
+}
+
+void
 gaim_gtkxfer_dialog_add_xfer(struct gaim_gtkxfer_dialog *dialog,
 							 struct gaim_xfer *xfer)
 {
--- a/src/gtkft.h	Mon Mar 10 22:07:59 2003 +0000
+++ b/src/gtkft.h	Tue Mar 11 00:09:45 2003 +0000
@@ -67,6 +67,11 @@
 void gaim_gtkxfer_dialog_hide(struct gaim_gtkxfer_dialog *dialog);
 
 /**
+ * Shows the file transfer dialog, creating a new one if necessary
+ */
+void gaim_show_xfer_dialog();
+
+/**
  * Adds a file transfer to the dialog.
  *
  * @param dialog The file transfer dialog.
--- a/src/gtklist.h	Mon Mar 10 22:07:59 2003 +0000
+++ b/src/gtklist.h	Tue Mar 11 00:09:45 2003 +0000
@@ -96,4 +96,12 @@
  */
 void gaim_gtk_blist_update_toolbar();
 
+/**
+ * Useful for the docklet plugin and also for the win32 tray icon
+ * This is called when one of those is clicked--it will show/hide the 
+ * buddy list/login window--depending on which is active 
+ */
+void gaim_gtk_blist_docklet_toggle();
+void gaim_gtk_blist_docklet_add();
+void gaim_gtk_blist_docklet_remove();
 #endif /* _GAIM_GTK_LIST_H_ */