gnome-applets r11183 - in branches/gnome-2-24: . cpufreq cpufreq/src



Author: callum
Date: Tue Jan 13 08:36:09 2009
New Revision: 11183
URL: http://svn.gnome.org/viewvc/gnome-applets?rev=11183&view=rev

Log:
Backport of fixes to the CPU frequency applet from 2.25

Modified:
   branches/gnome-2-24/ChangeLog
   branches/gnome-2-24/NEWS
   branches/gnome-2-24/configure.in
   branches/gnome-2-24/cpufreq/ChangeLog
   branches/gnome-2-24/cpufreq/src/cpufreq-applet.c

Modified: branches/gnome-2-24/NEWS
==============================================================================
--- branches/gnome-2-24/NEWS	(original)
+++ branches/gnome-2-24/NEWS	Tue Jan 13 08:36:09 2009
@@ -1,3 +1,12 @@
+Changes in GNOME-Applets 2.24.3
+===============================
+
+CPU Frequency Applet: 
+ - Geometry and update fixes backported from 2.25.
+
+Translation Updates:
+bg, et, pt_BR
+
 Changes in GNOME-Applets 2.24.2
 ===============================
 

Modified: branches/gnome-2-24/configure.in
==============================================================================
--- branches/gnome-2-24/configure.in	(original)
+++ branches/gnome-2-24/configure.in	Tue Jan 13 08:36:09 2009
@@ -1,7 +1,7 @@
 dnl ***************************************************************************
 dnl *** configure.in for GNOME-APPLETS                                      ***
 dnl ***************************************************************************
-AC_INIT(gnome-applets, 2.24.2)
+AC_INIT(gnome-applets, 2.24.3)
 AC_PREREQ(2.59)
 
 AM_CONFIG_HEADER(config.h)

Modified: branches/gnome-2-24/cpufreq/src/cpufreq-applet.c
==============================================================================
--- branches/gnome-2-24/cpufreq/src/cpufreq-applet.c	(original)
+++ branches/gnome-2-24/cpufreq/src/cpufreq-applet.c	Tue Jan 13 08:36:09 2009
@@ -50,6 +50,8 @@
         PanelApplet       base;
 
         /* Visibility */
+	CPUFreqShowMode   show_mode;
+	CPUFreqShowTextMode show_text_mode;
         gboolean          show_freq;
         gboolean          show_perc;
         gboolean          show_unit;
@@ -64,6 +66,7 @@
         GtkWidget        *unit_label;
         GtkWidget        *icon;
         GtkWidget        *box;
+	GtkWidget        *labels_box;
         GtkWidget        *container;
         GdkPixbuf        *pixbufs[5];
 
@@ -113,10 +116,6 @@
 						  GtkRequisition     *requisition);
 static void     cpufreq_applet_change_orient     (PanelApplet        *pa,
                                                   PanelAppletOrient   orient);
-static void     cpufreq_applet_change_background (PanelApplet        *pa,
-                                                  PanelAppletBackgroundType type,
-                                                  GdkColor           *color,
-                                                  GdkPixmap          *pixmap);
 
 static gboolean cpufreq_applet_factory           (CPUFreqApplet      *applet,
                                                   const gchar        *iid,
@@ -196,7 +195,11 @@
 
 	applet->need_refresh = TRUE;
 
+	applet->show_mode = CPUFREQ_MODE_BOTH;
+	applet->show_text_mode = CPUFREQ_MODE_TEXT_FREQUENCY_UNIT;
+
         panel_applet_set_flags (PANEL_APPLET (applet), PANEL_APPLET_EXPAND_MINOR);
+	panel_applet_set_background_widget (PANEL_APPLET (applet), GTK_WIDGET (applet));
 
         applet->size = panel_applet_get_size (PANEL_APPLET (applet));
         applet->orient = panel_applet_get_orient (PANEL_APPLET (applet));
@@ -214,8 +217,6 @@
 
 	gtk_container_add (GTK_CONTAINER (applet), applet->container);
 	gtk_widget_show (applet->container);
-
-        gtk_widget_show (GTK_WIDGET (applet));
 }
 
 static void
@@ -233,7 +234,6 @@
         widget_class->key_press_event = cpufreq_applet_key_press;
            
         applet_class->change_orient = cpufreq_applet_change_orient;
-        applet_class->change_background = cpufreq_applet_change_background;
 }
 
 static void
@@ -277,6 +277,8 @@
 
         applet = CPUFREQ_APPLET (widget);
 
+	GTK_WIDGET_CLASS (cpufreq_applet_parent_class)->size_allocate (widget, allocation);
+
         switch (applet->orient) {
         case PANEL_APPLET_ORIENT_LEFT:
         case PANEL_APPLET_ORIENT_RIGHT:
@@ -292,8 +294,6 @@
                 applet->size = size;
                 cpufreq_applet_refresh (applet);
         }
-
-        GTK_WIDGET_CLASS (cpufreq_applet_parent_class)->size_allocate (widget, allocation);
 }
 
 static gint
@@ -382,7 +382,8 @@
 cpufreq_applet_size_request (GtkWidget *widget, GtkRequisition *requisition)
 {
 	CPUFreqApplet *applet;
-	gint           width = 0;
+	gint           labels_width = 0;
+	gint           width;
 
 	applet = CPUFREQ_APPLET (widget);
 	
@@ -393,23 +394,27 @@
 		return;
 	
 	if (applet->show_freq) {
-		width += cpufreq_applet_get_max_label_width (applet) + 2;
+		labels_width += cpufreq_applet_get_max_label_width (applet) + 2;
         }
 
         if (applet->show_perc) {
-		width += cpufreq_applet_get_max_perc_width (applet);
+		labels_width += cpufreq_applet_get_max_perc_width (applet);
         }
 
         if (applet->show_unit) {
-		width += cpufreq_applet_get_max_unit_width (applet);
+		labels_width += cpufreq_applet_get_max_unit_width (applet);
         }
 
         if (applet->show_icon) {
 		GtkRequisition req;
 		
 		gtk_widget_size_request (applet->icon, &req);
-		width += req.width + 2;
-        }
+		width = GTK_IS_HBOX (applet->box) ?
+			labels_width + req.width + 2 :
+			MAX (labels_width, req.width + 2);
+	} else {
+		width = labels_width;
+	}
 
 	requisition->width = width;
 }
@@ -558,45 +563,6 @@
 }
 
 static void
-cpufreq_applet_change_background (PanelApplet *pa,
-                                  PanelAppletBackgroundType type,
-                                  GdkColor *color, GdkPixmap *pixmap)
-{
-        CPUFreqApplet *applet;
-        /* Taken from TrashApplet */
-        GtkRcStyle    *rc_style;
-        GtkStyle      *style;
-
-        applet = CPUFREQ_APPLET (pa);
-
-        /* reset style */
-        gtk_widget_set_style (GTK_WIDGET (applet), NULL);
-        rc_style = gtk_rc_style_new ();
-        gtk_widget_modify_style (GTK_WIDGET (applet), rc_style);
-        gtk_rc_style_unref (rc_style);
-
-        switch (type) {
-        case PANEL_PIXMAP_BACKGROUND:
-                style = gtk_style_copy (GTK_WIDGET (applet)->style);
-                if (style->bg_pixmap[GTK_STATE_NORMAL])
-                        g_object_unref (
-                                style->bg_pixmap[GTK_STATE_NORMAL]);
-                style->bg_pixmap[GTK_STATE_NORMAL] = g_object_ref (
-                        pixmap);
-                gtk_widget_set_style (GTK_WIDGET (applet), style);
-                g_object_unref (style);
-                break;
-        case PANEL_COLOR_BACKGROUND:
-                gtk_widget_modify_bg (GTK_WIDGET (applet),
-                                      GTK_STATE_NORMAL, color);
-                break;
-        case PANEL_NO_BACKGROUND:
-        default:
-                break;
-        }
-}
-
-static void
 cpufreq_applet_preferences_cb (BonoboUIComponent *uic,
                                CPUFreqApplet     *applet,
                                const gchar       *cname)
@@ -684,6 +650,14 @@
         gtk_image_set_from_pixbuf (GTK_IMAGE (applet->icon), applet->pixbufs[image]);
 }
 
+static gboolean
+refresh_cb (CPUFreqApplet *applet)
+{
+	cpufreq_applet_refresh (applet);
+	
+	return FALSE;
+}
+
 static void
 cpufreq_applet_update_visibility (CPUFreqApplet *applet)
 {
@@ -718,9 +692,15 @@
                 show_icon = TRUE;
         }
 
-        if ((applet->show_perc && show_freq) ||
-            (applet->show_freq && show_perc))
-                need_update = TRUE;
+	if (applet->show_mode != show_mode) {
+		applet->show_mode = show_mode;
+		need_update = TRUE;
+	}
+	
+	if (applet->show_text_mode != show_text_mode) {
+		applet->show_text_mode = show_text_mode;
+		need_update = TRUE;
+	}
         
         if (show_freq != applet->show_freq) {
                 applet->show_freq = show_freq;
@@ -758,7 +738,7 @@
         }
 
         if (changed)
-                cpufreq_applet_refresh (applet);
+		g_idle_add ((GSourceFunc)refresh_cb, applet);
 
         if (need_update)
                 cpufreq_applet_update (applet, applet->monitor);
@@ -767,7 +747,7 @@
 static void
 cpufreq_applet_update (CPUFreqApplet *applet, CPUFreqMonitor *monitor)
 {
-        gchar          *text_tip, *text_mode;
+        gchar          *text_tip, *text_mode = NULL;
         gchar          *freq_label, *unit_label;
         gint            freq;
         gint            perc;
@@ -777,7 +757,7 @@
         cpu = cpufreq_monitor_get_cpu (monitor);
         freq = cpufreq_monitor_get_frequency (monitor);
         perc = cpufreq_monitor_get_percentage (monitor);
-        governor = g_strdup (cpufreq_monitor_get_governor (monitor));
+        governor = cpufreq_monitor_get_governor (monitor);
 
         freq_label = cpufreq_utils_get_frequency_label (freq);
         unit_label = cpufreq_utils_get_frequency_unit (freq);
@@ -802,24 +782,30 @@
                 cpufreq_applet_pixmap_set_image (applet, perc);
         }
 
-        governor[0] = g_ascii_toupper (governor[0]);
-        text_mode = g_strdup_printf ("%s\n%s %s (%d%%)",
-                                     governor, freq_label,
-                                     unit_label, perc);
+	if (governor) {
+		gchar *gov_text;
+
+		gov_text = g_strdup (governor);
+		gov_text[0] = g_ascii_toupper (gov_text[0]);
+		text_mode = g_strdup_printf ("%s\n%s %s (%d%%)",
+					     gov_text, freq_label,
+					     unit_label, perc);
+		g_free (gov_text);
+	}
 
         g_free (freq_label);
         g_free (unit_label);
-        g_free (governor);
 
-        if (cpufreq_utils_get_n_cpus () == 1)
-                text_tip = g_strdup_printf ("%s", text_mode);
-        else
-                text_tip = g_strdup_printf ("CPU %u - %s", cpu, text_mode);
-
-        g_free (text_mode);
-           
-        gtk_widget_set_tooltip_text (GTK_WIDGET (applet), text_tip);
-        g_free (text_tip);
+	if (text_mode) {
+		gchar *text_tip;
+		
+		text_tip = cpufreq_utils_get_n_cpus () == 1 ?
+			g_strdup_printf ("%s", text_mode) :
+			g_strdup_printf ("CPU %u - %s", cpu, text_mode);
+		g_free (text_mode);
+		gtk_widget_set_tooltip_text (GTK_WIDGET (applet), text_tip);
+		g_free (text_tip);
+	}
 
         /* Call refresh only the first time */
         if (applet->need_refresh) {
@@ -859,7 +845,6 @@
 static void
 cpufreq_applet_refresh (CPUFreqApplet *applet)
 {
-        GtkWidget *labels_box = NULL;
         gint       total_size = 0;
         gint       panel_size, label_size;
         gint       unit_label_size, pixmap_size;
@@ -889,27 +874,17 @@
         total_size += pixmap_size;
 
         if (applet->box) {
-                GtkWidget *child;
-                GList     *children;
-
-                do_unref = TRUE;
-                g_object_ref (applet->icon);
-                gtk_container_remove (GTK_CONTAINER (applet->box), applet->icon);
-                children = gtk_container_get_children (GTK_CONTAINER (applet->box));
-                if (children && children->data) {
-                        /* Should be labels_box */
-                        child = (GtkWidget *)children->data;
+	        if (applet->labels_box) {
                         g_object_ref (applet->label);
-                        gtk_container_remove (GTK_CONTAINER (child), applet->label);
+                        gtk_container_remove (GTK_CONTAINER (applet->labels_box), applet->label);
                         g_object_ref (applet->unit_label);
-                        gtk_container_remove (GTK_CONTAINER (child), applet->unit_label);
+                        gtk_container_remove (GTK_CONTAINER (applet->labels_box), applet->unit_label);
                 }
-                g_list_free (children);
                 gtk_widget_destroy (applet->box);
         }
 
 	if (horizontal) {
-		labels_box = gtk_hbox_new (FALSE, 2);
+		applet->labels_box = gtk_hbox_new (FALSE, 2);
 		if ((label_size + pixmap_size) <= panel_size)
 			applet->box = gtk_vbox_new (FALSE, 2);
 		else
@@ -917,22 +892,22 @@
 	} else {
                 if (total_size <= panel_size) {
                         applet->box = gtk_hbox_new (FALSE, 2);
-                        labels_box  = gtk_hbox_new (FALSE, 2);
+                        applet->labels_box  = gtk_hbox_new (FALSE, 2);
                 } else if ((label_size + unit_label_size) <= (panel_size - size_step)) {
                         applet->box = gtk_vbox_new (FALSE, 2);
-                        labels_box  = gtk_hbox_new (FALSE, 2);
+                        applet->labels_box  = gtk_hbox_new (FALSE, 2);
                 } else {
                         applet->box = gtk_vbox_new (FALSE, 2);
-                        labels_box  = gtk_vbox_new (FALSE, 2);
+                        applet->labels_box  = gtk_vbox_new (FALSE, 2);
                 }
 	}
 
-        gtk_box_pack_start (GTK_BOX (labels_box), applet->label, FALSE, FALSE, 0);
-        gtk_box_pack_start (GTK_BOX (labels_box), applet->unit_label, FALSE, FALSE, 0);
+        gtk_box_pack_start (GTK_BOX (applet->labels_box), applet->label, FALSE, FALSE, 0);
+        gtk_box_pack_start (GTK_BOX (applet->labels_box), applet->unit_label, FALSE, FALSE, 0);
         gtk_box_pack_start (GTK_BOX (applet->box), applet->icon, FALSE, FALSE, 0);
         
-        gtk_box_pack_start (GTK_BOX (applet->box), labels_box, FALSE, FALSE, 0);
-        gtk_widget_show (labels_box);
+        gtk_box_pack_start (GTK_BOX (applet->box), applet->labels_box, FALSE, FALSE, 0);
+        gtk_widget_show (applet->labels_box);
            
         gtk_container_add (GTK_CONTAINER (applet->container), applet->box);
         gtk_widget_show (applet->box);
@@ -997,8 +972,6 @@
                           G_CALLBACK (cpufreq_applet_prefs_show_mode_changed),
                           (gpointer) applet);
         
-        cpufreq_applet_update_visibility (applet);
-
         /* Monitor */
         applet->monitor = cpufreq_monitor_factory_create_monitor (
                 cpufreq_prefs_get_cpu (applet->prefs));
@@ -1030,6 +1003,10 @@
                 atk_object_set_name (atk_obj, _("CPU Frequency Scaling Monitor"));
                 atk_object_set_description (atk_obj, _("This utility shows the current CPU Frequency"));
         }
+
+	cpufreq_applet_update_visibility (applet);
+
+	gtk_widget_show (GTK_WIDGET (applet));
 }
 
 static gboolean



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]