Re: GTK+ 3 vs GKrellM public API

Jindřich Makovička <[email protected]> Fri, 29 Oct 2010 09:05:10 +0200
Newsgroups gmane.comp.gnome.apps.gkrellm
Message-ID <[email protected]>
On Fri, Oct 29, 2010 at 01:01, Bill Wilson <[email protected]> wrote:
> On Fri, 29 Oct 2010 00:15:34 +0200
> Stefan Gehn <[email protected]> wrote:
>
>> On 28.10.10 21:48, Jindřich Makovička wrote:
>> > Hi,
>> >
>> > trying to build my plugin with -DGTK_DISABLE_DEPRECATED -DGSEAL_ENABLE
>> > , I just noticed that GKrellM public API still contains references to
>> > GtkItemFactory and GtkTooltips, which are scheduled for removal in
>> > GTK3. Considering that GTK3 release is planned at the end of the year,
>> > I'd like to ask if there are any plans on an API transition?
>>
>> I don't know about Bill's plans but I want to build GKrellM with
>> GTK_DISABLE_DEPRECATED set when redoing the gui parts that I intended to
>> redo about two releases ago ;)
>
> Sure, patches to replace deprecated code in GKrellM are welcome.

Actually, apart from the patch I sent above, there only change needed
is a conversion of GtkOptionMenu to GtkComboBox and couple of
one-liners.

With the attachments applied, GKrellM can be build with DISABLE_DEPRECATED.

-- 
Jindrich Makovicka
option-menu.diff (text/x-patch, 8.9 KB)
--- src.apiclean/mail.c	2010-09-14 18:25:51.000000000 +0200
+++ src/mail.c	2010-10-28 23:19:49.171198842 +0200
@@ -3138,7 +3138,7 @@
 						*imapfolder_entry,
 						*port_entry,
 #ifdef HAVE_SSL
-						*ssl_option_menu,
+						*ssl_combo_box,
 #endif
 						*port_button;
 
@@ -3146,7 +3146,7 @@
 						*remote_button,
 						*delete_button,
 						*new_apply_button,
-						*remote_option_menu;
+						*remote_combo_box;
 
 static GtkWidget		*mail_user_agent_entry;
 static GtkWidget		*enable_multimua_button;
@@ -3322,10 +3322,10 @@
 	gtk_entry_set_text(GTK_ENTRY(password_entry), "");
 	gtk_entry_set_text(GTK_ENTRY(imapfolder_entry), "");
 	gtk_widget_set_sensitive(imapfolder_entry, FALSE);
-	gtk_option_menu_set_history(GTK_OPTION_MENU(remote_option_menu), 0);
+	gtk_combo_box_set_active(GTK_COMBO_BOX(remote_combo_box), 0);
 	optmenu_auth_protocol = 0;
 #ifdef HAVE_SSL
-	gtk_option_menu_set_history(GTK_OPTION_MENU(ssl_option_menu), 0);
+	gtk_combo_box_set_active(GTK_COMBO_BOX(ssl_combo_box), 0);
 #endif
 	optmenu_use_ssl = SSL_NONE;
 
@@ -3365,11 +3365,9 @@
 
 #ifdef HAVE_SSL
 static void
-cb_ssl_selected(GtkMenuItem *menuitem)
+cb_ssl_selected(GtkComboBox *widget)
 	{
-	optmenu_use_ssl =
-			GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem),
-							  "user_data"));
+	optmenu_use_ssl = gtk_combo_box_get_active(widget);
 	default_port_entry();
 	}
 #endif
@@ -3381,10 +3379,9 @@
 	}
 
 static void
-cb_protocol_selected(GtkMenuItem *menuitem)
+cb_protocol_selected(GtkComboBox *widget)
 	{
-	optmenu_auth_protocol =
-			GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem),"user_data"));
+        optmenu_auth_protocol = gtk_combo_box_get_active(widget);
 	switch (menu_to_proto(optmenu_auth_protocol))
 		{
 		case PROTO_POP3:
@@ -3456,11 +3453,11 @@
 			}
 		default_port = atoi(default_port_of_proto(account->protocol,
 							  account->use_ssl));
-		gtk_option_menu_set_history(GTK_OPTION_MENU(remote_option_menu),
+		gtk_combo_box_set_active(GTK_COMBO_BOX(remote_combo_box),
 					optmenu_auth_protocol);
 #ifdef HAVE_SSL
-		gtk_option_menu_set_history(GTK_OPTION_MENU(ssl_option_menu),
-					    optmenu_use_ssl);
+		gtk_combo_box_set_active(GTK_COMBO_BOX(ssl_combo_box),
+                                         optmenu_use_ssl);
 #endif
 		if (account->port < 1)
 			account->port = default_port;
@@ -3806,33 +3803,6 @@
 		}
 	}
 
-static void
-add_menu_item(GtkWidget *menu, gchar *label, gint type)
-	{
-	GtkWidget	*menuitem;
-
-	menuitem = gtk_menu_item_new_with_label(label);
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
-	g_object_set_data(G_OBJECT(menuitem), "user_data", GINT_TO_POINTER(type));
-	g_signal_connect(G_OBJECT(menuitem), "activate",
-			G_CALLBACK(cb_protocol_selected), NULL);
-	}
-
-#ifdef HAVE_SSL
-static void
-add_ssl_menu_item(GtkWidget *menu, gchar *label, gint type)
-	{
-	GtkWidget	*menuitem;
-
-	menuitem = gtk_menu_item_new_with_label(label);
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
-	g_object_set_data(G_OBJECT(menuitem), "user_data",
-			  GINT_TO_POINTER(type));
-	g_signal_connect(G_OBJECT(menuitem), "activate",
-			 G_CALLBACK(cb_ssl_selected), NULL);
-	}
-#endif
-
 static gchar	*mail_info_text0[]	=
 {
 N_("<h>Mailboxes\n"),
@@ -3904,10 +3874,6 @@
 	{
 	GtkWidget		*tabs;
 	GtkWidget		*table;
-	GtkWidget		*menu;
-#ifdef HAVE_SSL
-	GtkWidget		*ssl_menu;
-#endif
 	GtkWidget		*vbox, *vbox1, *hbox, *hbox1;
 	GtkWidget		*label;
 	GtkWidget		*button;
@@ -4092,13 +4058,12 @@
 	gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
 	gtk_table_attach_defaults(GTK_TABLE(table), label, 2, 3, 0, 1);
 
-	remote_option_menu = gtk_option_menu_new();
-	gtk_table_attach_defaults(GTK_TABLE(table), remote_option_menu, 3, 4, 0,1);
-	menu = gtk_menu_new();
+	remote_combo_box = gtk_combo_box_new_text();
+	gtk_table_attach_defaults(GTK_TABLE(table), remote_combo_box, 3, 4, 0,1);
 	for (i = 0; auth_strings[i].string != NULL; ++i)
-		add_menu_item(menu, x_out(auth_strings[i].string), i);
-	gtk_widget_show(menu);
-	gtk_option_menu_set_menu(GTK_OPTION_MENU(remote_option_menu), menu);
+            gtk_combo_box_append_text(GTK_COMBO_BOX(remote_combo_box), auth_strings[i].string);
+	g_signal_connect(G_OBJECT(remote_combo_box), "changed",
+			G_CALLBACK(cb_protocol_selected), NULL);
 
 	i = 1;
 
@@ -4107,15 +4072,14 @@
 	gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
 	gtk_table_attach_defaults(GTK_TABLE(table), label, 2, 3, i, i+1);
 
-	ssl_option_menu = gtk_option_menu_new();
-	gtk_table_attach_defaults(GTK_TABLE(table), ssl_option_menu, 3, 4, i, i+1);
+	ssl_combo_box = gtk_combo_box_new_text();
+	gtk_table_attach_defaults(GTK_TABLE(table), ssl_combo_box, 3, 4, i, i+1);
 	++i;
-	ssl_menu = gtk_menu_new();
-	add_ssl_menu_item(ssl_menu, _("No"), SSL_NONE);
-	add_ssl_menu_item(ssl_menu, "SSL", SSL_TRANSPORT);
-	add_ssl_menu_item(ssl_menu, "STARTTLS", SSL_STARTTLS);
-	gtk_widget_show(ssl_menu);
-	gtk_option_menu_set_menu(GTK_OPTION_MENU(ssl_option_menu), ssl_menu);
+        gtk_combo_box_append_text(GTK_COMBO_BOX(ssl_combo_box), _("No"));
+        gtk_combo_box_append_text(GTK_COMBO_BOX(ssl_combo_box), "SSL");
+        gtk_combo_box_append_text(GTK_COMBO_BOX(ssl_combo_box), "STARTTLS");
+	g_signal_connect(G_OBJECT(ssl_combo_box), "changed",
+                         G_CALLBACK(cb_ssl_selected), NULL);
 #endif
 
 
--- src.apiclean/sensors.c	2010-09-14 18:25:51.000000000 +0200
+++ src/sensors.c	2010-10-28 23:19:47.879108541 +0200
@@ -1964,8 +1964,7 @@
 static GtkTreeSelection		*selection;
 
 
-static GtkWidget	*optionmenu,
-					*optionmenu_menu;
+static GtkWidget	*optionmenu;
 
 static GtkWidget	*display_mode_button[2];
 static GtkWidget	*factor_spin_button,
@@ -2267,19 +2266,19 @@
 		return;
 	sr = get_referenced_sensor();
 	if (sr == sensor)
-		gtk_option_menu_set_history(GTK_OPTION_MENU(optionmenu),
+		gtk_combo_box_set_active(GTK_COMBO_BOX(optionmenu),
 					SENSOR_PANEL_LOCATION);
 	}
 
 static void
-cb_location_menu(GtkOptionMenu *om, gpointer data)
+cb_location_menu(GtkComboBox *om, gpointer data)
 	{
 	GList		*list;
 	Sensor		*sr, *s;
 	gchar		*pname = NULL;
 	gint		location;
 
-	location = gtk_option_menu_get_history(om);
+	location = gtk_combo_box_get_active(om);
 	sr = get_referenced_sensor();
 	if (!sr || !sr->enabled || sr->location == location)
 		return;
@@ -2323,7 +2322,7 @@
 
 	if (sr->location != location)	/* location failed */
 		{
-		gtk_option_menu_set_history(GTK_OPTION_MENU(optionmenu),
+		gtk_combo_box_set_active(GTK_COMBO_BOX(optionmenu),
 					SENSOR_PANEL_LOCATION);
 		sensor_relocation_error(pname);
 		}
@@ -2333,8 +2332,6 @@
 static void
 create_location_menu(gint group)
 	{
-	GtkWidget	*menu;
-	GtkWidget	*menuitem;
 	gint		n, n_cpus;
 	static gint	sig_id;
 
@@ -2342,42 +2339,24 @@
 		return;
 	sensor_last_group = group;
 
-	if (optionmenu_menu)
-		{
-		g_signal_handler_disconnect(G_OBJECT(optionmenu), sig_id);
-		gtk_widget_destroy(optionmenu_menu);
-		}
-
-	menu = gtk_menu_new();
-
-	menuitem = gtk_menu_item_new_with_label("default");
-	gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
-	gtk_widget_show(menuitem);
+        gtk_combo_box_append_text(GTK_COMBO_BOX(optionmenu), "default");
 
 	if (group == SENSOR_GROUP_MAINBOARD)
 		{
-		menuitem = gtk_menu_item_new_with_label(
-					gkrellm_proc_get_sensor_panel_label());
-		gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
-		gtk_widget_show(menuitem);
+                    gtk_combo_box_append_text(GTK_COMBO_BOX(optionmenu),
+                                              gkrellm_proc_get_sensor_panel_label());
 
 		n_cpus = gkrellm_smp_cpus() + 1;
 		for (n = 0; n < n_cpus; ++n)
 			{
-			menuitem = gtk_menu_item_new_with_label(
-						gkrellm_cpu_get_sensor_panel_label(n));
-			gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
-			gtk_widget_show(menuitem);
+                    gtk_combo_box_append_text(GTK_COMBO_BOX(optionmenu),
+                                              gkrellm_cpu_get_sensor_panel_label(n));
 			}
 		}
 	else if (group == SENSOR_GROUP_DISK)
 		{
-		menuitem = gtk_menu_item_new_with_label(_("Disk"));
-		gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
-		gtk_widget_show(menuitem);
+                    gtk_combo_box_append_text(GTK_COMBO_BOX(optionmenu), _("Disk"));
 		}
-	gtk_option_menu_set_menu(GTK_OPTION_MENU(optionmenu), menu);
-	optionmenu_menu = menu;
 	sig_id = g_signal_connect(G_OBJECT(optionmenu), "changed",
 				G_CALLBACK(cb_location_menu), NULL);
 	}
@@ -2408,7 +2387,7 @@
 			}
 		}
 	create_location_menu(s ? s->group : 0);
-	gtk_option_menu_set_history(GTK_OPTION_MENU(optionmenu), location);
+	gtk_combo_box_set_active(GTK_COMBO_BOX(optionmenu), location);
 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(factor_spin_button), factor);
 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(offset_spin_button), offset);
 	gtk_widget_set_sensitive(optionmenu, p_sensitive);
@@ -2809,8 +2788,7 @@
 
 	box = gkrellm_gtk_framed_vbox(vbox1, _("Location"), 2, FALSE, 0, 2);
 
-	optionmenu = gtk_option_menu_new();
-	optionmenu_menu = NULL;
+	optionmenu = gtk_combo_box_new_text();
 
 	gtk_box_pack_start(GTK_BOX(box), optionmenu, FALSE, FALSE, 4);
gtk-timeout.diff (text/x-patch, 604 B)
--- src.apiclean/main.c	2010-10-28 20:48:43.000000000 +0200
+++ src/main.c	2010-10-28 21:59:14.858657898 +0200
@@ -401,17 +401,17 @@
 void
 gkrellm_start_timer(gint Hz)
 	{
-	static gint	timeout_id	= 0;
+	static guint	timeout_id	= 0;
 	gint		interval;
 
 	if (timeout_id)
-		gtk_timeout_remove(timeout_id);
+		g_source_remove(timeout_id);
 	timeout_id = 0;
 	if (Hz > 0)
 		{
 		interval = 1000 / Hz;
 		interval = interval * 60 / 63;	/* Compensate for overhead XXX */
-		timeout_id = gtk_timeout_add(interval,
+		timeout_id = g_timeout_add(interval,
 						(GtkFunction) update_monitors,NULL);
 		}
 	}
widget-ref.diff (text/x-patch, 712 B)
--- src.apiclean/plugins.c	2010-09-14 18:25:51.000000000 +0200
+++ src/plugins.c	2010-10-28 22:49:28.266509796 +0200
@@ -1337,7 +1337,7 @@
 		mon = (GkrellmMonitor *) list->data;
 		if (mon->privat->main_vbox && mon != gkrellm_mon_host())
 			{
-			gtk_widget_ref(mon->privat->main_vbox);
+                            g_object_ref(G_OBJECT(mon->privat->main_vbox));
 			gtk_container_remove(GTK_CONTAINER(gkrellm_monitor_vbox()),
 					mon->privat->main_vbox);
 			}
@@ -1359,7 +1359,7 @@
 			{
 			gtk_box_pack_start(GTK_BOX(gkrellm_monitor_vbox()),
 					mon->privat->main_vbox, FALSE, FALSE, 0);
-			gtk_widget_unref(mon->privat->main_vbox);
+			g_object_ref(G_OBJECT(mon->privat->main_vbox));
 			}
 		}
 	}
widget-state.diff (text/x-patch, 592 B)
--- src.apiclean/battery.c	2010-09-14 18:25:51.000000000 +0200
+++ src/battery.c	2010-10-28 22:13:18.837455609 +0200
@@ -534,8 +534,8 @@
 static gboolean
 cb_expose_event(GtkWidget *widget, GdkEventExpose *ev, GkrellmPanel *p)
 	{
-	gdk_draw_drawable(widget->window,
-			widget->style->fg_gc[GTK_WIDGET_STATE(widget)], p->pixmap,
+	gdk_draw_drawable(gtk_widget_get_window(widget),
+                          gtk_widget_get_style(widget)->fg_gc[gtk_widget_get_state(widget)], p->pixmap,
 			ev->area.x, ev->area.y, ev->area.x, ev->area.y,
 			ev->area.width, ev->area.height);
 	return FALSE;