All pastes #967939 Raw Edit

icon thingy2

public diff v1 · immutable
·published 2008-04-02 19:09 UTC
rendered paste body
diff --git a/hal/Makefile.am b/hal/Makefile.amindex 663fc1d..cf4a88e 100644--- a/hal/Makefile.am+++ b/hal/Makefile.am@@ -16,6 +16,7 @@ hal-marshal.c: hal-marshal.list   libgiohal_volume_monitor_la_SOURCES =                          \+       hal-utils.c             hal-utils.h \        hal-module.c                                    \        hal-marshal.c           hal-marshal.h           \        hal-device.c            hal-device.h            \diff --git a/hal/ghalmount.c b/hal/ghalmount.cindex 35d964e..ba5d834 100644--- a/hal/ghalmount.c+++ b/hal/ghalmount.c@@ -36,6 +36,8 @@ #include "ghalmount.h" #include "ghalvolume.h" +#include "hal-utils.h"+ /* Protects all fields of GHalDrive that can change */ G_LOCK_DEFINE_STATIC(hal_mount); @@ -157,63 +159,6 @@ changed_in_idle (gpointer data)   return FALSE; } -static const struct {-  const char *disc_type;-  const char *icon_name;-  char *ui_name;-  char *ui_name_blank;-} disc_data[] = {-  {"cd_rom",        "media-optical-cd-rom", N_("CD-ROM Disc"), N_("Blank CD-ROM Disc")},-  {"cd_r",          "media-optical-cd-r", N_("CD-R Disc"), N_("Blank CD-R Disc")},-  {"cd_rw",         "media-optical-cd-rw", N_("CD-RW Disc"), N_("Blank CD-RW Disc")},-  {"dvd_rom",       "media-optical-dvd-rom", N_("DVD-ROM Disc"), N_("Blank DVD-ROM Disc")},-  {"dvd_ram",       "media-optical-dvd-ram", N_("DVD-RAM Disc"), N_("Blank DVD-RAM Disc")},-  {"dvd_r",         "media-optical-dvd-r", N_("DVD-ROM Disc"), N_("Blank DVD-ROM Disc")},-  {"dvd_rw",        "media-optical-dvd-rw", N_("DVD-RW Disc"), N_("Blank DVD-RW Disc")},-  {"dvd_plus_r",    "media-optical-dvd-r-plus", N_("DVD+R Disc"), N_("Blank DVD+R Disc")},-  {"dvd_plus_rw",   "media-optical-dvd-rw-plus",  N_("DVD+RW Disc"), N_("Blank DVD+RW Disc")},-  {"dvd_plus_r_dl", "media-optical-dvd-dl-r-plus", N_("DVD+R DL Disc"), N_("Blank DVD+R DL Disc")},-  {"bd_rom",        "media-optical-bd-rom", N_("Blu-Ray Disc"), N_("Blank Blu-Ray Disc")},-  {"bd_r",          "media-optical-bd-r", N_("Blu-Ray R Disc"), N_("Blank Blu-Ray R Disc")},-  {"bd_re",         "media-optical-bd-re", N_("Blu-Ray RW Disc"), N_("Blank Blu-Ray RW Disc")},-  {"hddvd_rom",     "media-optical-hddvd-rom", N_("HD DVD Disc"), N_("Blank HD DVD Disc")},-  {"hddvd_r",       "media-optical-hddvd-r", N_("HD DVD-R Disc"), N_("Blank HD DVD-R Disc")},-  {"hddvd_rw",      "media-optical-hddvd-rw", N_("HD DVD-RW Disc"), N_("Blank HD DVD-RW Disc")},-  {"mo",            "media-optical-mo", N_("MO Disc"), N_("Blank MO Disc")},-  {NULL,            "media-optical", N_("Disc"), N_("Blank Disc")}-};--static const char *-get_disc_icon (const char *disc_type)-{-  int n;-  -  for (n = 0; disc_data[n].disc_type != NULL; n++)-    {-      if (strcmp (disc_data[n].disc_type, disc_type) == 0)-        break;-    }-  -  return disc_data[n].icon_name;-}--static const char *-get_disc_name (const char *disc_type, gboolean is_blank)-{-  int n;-  -  for (n = 0; disc_data[n].disc_type != NULL; n++)-    {-      if (strcmp (disc_data[n].disc_type, disc_type) == 0)-        break;-    }-  -  if (is_blank)-    return dgettext (GETTEXT_PACKAGE, disc_data[n].ui_name_blank);-  else-    return dgettext (GETTEXT_PACKAGE, disc_data[n].ui_name);-}- typedef struct _MountIconSearchData {   GHalMount *mount;@@ -388,6 +333,7 @@ do_update_from_hal (GHalMount *m)   HalDevice *drive;   char *name;   const char *icon_name;+  const char *icon_name_fallback;   const char *drive_type;   const char *drive_bus;   gboolean drive_uses_removable_media;@@ -437,19 +383,14 @@ do_update_from_hal (GHalMount *m)   /*g_warning ("drive_bus='%s'", drive_bus); */   /*g_warning ("drive_uses_removable_media=%d", drive_uses_removable_media); */ +  icon_name_fallback = NULL;+   if (strlen (volume_icon_from_hal) > 0)     icon_name = volume_icon_from_hal;   else if (strlen (icon_from_hal) > 0)     icon_name = icon_from_hal;   else if (is_audio_player)     icon_name = "multimedia-player";-#if 0-  /* This icon hasn't been finalized yet, and causes issues with-   * the icon theme, so it has been disabled for gnome 2.22.-   */-  else if (is_crypto || is_crypto_cleartext)-    icon_name = "media-encrypted";-#endif   else if (strcmp (drive_type, "disk") == 0)     {       if (strcmp (drive_bus, "ide") == 0)@@ -464,7 +405,7 @@ do_update_from_hal (GHalMount *m)         icon_name = "drive-harddisk";     }   else if (strcmp (drive_type, "cdrom") == 0)-    icon_name = g_strdup (get_disc_icon (volume_disc_type));+    icon_name = get_disc_icon (volume_disc_type);   else if (strcmp (drive_type, "floppy") == 0)     icon_name = "media-floppy";   else if (strcmp (drive_type, "tape") == 0)@@ -480,7 +421,16 @@ do_update_from_hal (GHalMount *m)   else     icon_name = "drive-harddisk"; -  +  /* Create default fallbacks for the icon_name by default+   * with get_themed_icon_with_fallbacks () */+  icon_name_fallback = icon_name;++  /* Note: we are not chaning the default fallbacks+   * so we get all the fallbacks if the media-encrytped+   * icon is not there */+  if (is_crypto || is_crypto_cleartext)+    icon_name = "media-encrypted";+   if (strlen (volume_name_from_hal) > 0)     name = g_strdup (volume_name_from_hal);   else if (strlen (name_from_hal) > 0)@@ -520,8 +470,9 @@ do_update_from_hal (GHalMount *m)   if (m->override_icon != NULL)     m->icon = g_object_ref (m->override_icon);   else-    m->icon = g_themed_icon_new_with_default_fallbacks (icon_name);-    +    m->icon = get_themed_icon_with_fallbacks (icon_name,+                                              icon_name_fallback);+   /* If this is a CD-ROM, begin searching for an icon specified in    * autorun.inf.   **/diff --git a/hal/ghalvolume.c b/hal/ghalvolume.cindex 076147a..145f6b3 100644--- a/hal/ghalvolume.c+++ b/hal/ghalvolume.c@@ -36,6 +36,8 @@ #include "ghalvolume.h" #include "ghalmount.h" +#include "hal-utils.h"+ /* Protects all fields of GHalDrive that can change */ G_LOCK_DEFINE_STATIC(hal_volume); @@ -63,6 +65,7 @@ struct _GHalVolume {    char *name;   char *icon;+  char *icon_fallback; };  static void g_hal_volume_volume_iface_init (GVolumeIface *iface);@@ -110,6 +113,7 @@ g_hal_volume_finalize (GObject *object)    g_free (volume->name);   g_free (volume->icon);+  g_free (volume->icon_fallback);    if (G_OBJECT_CLASS (g_hal_volume_parent_class)->finalize)     (*G_OBJECT_CLASS (g_hal_volume_parent_class)->finalize) (object);@@ -146,50 +150,6 @@ changed_in_idle (gpointer data)   return FALSE; } -static const struct {-  const char *disc_type;-  const char *icon_name;-  char *ui_name;-  char *ui_name_blank;-} disc_data[] = {-  {"cd_rom",        "media-optical-cd-rom", N_("CD-ROM Disc"), N_("Blank CD-ROM Disc")},-  {"cd_r",          "media-optical-cd-r", N_("CD-R Disc"), N_("Blank CD-R Disc")},-  {"cd_rw",         "media-optical-cd-rw", N_("CD-RW Disc"), N_("Blank CD-RW Disc")},-  {"dvd_rom",       "media-optical-dvd-rom", N_("DVD-ROM Disc"), N_("Blank DVD-ROM Disc")},-  {"dvd_ram",       "media-optical-dvd-ram", N_("DVD-RAM Disc"), N_("Blank DVD-RAM Disc")},-  {"dvd_r",         "media-optical-dvd-r", N_("DVD-ROM Disc"), N_("Blank DVD-ROM Disc")},-  {"dvd_rw",        "media-optical-dvd-rw", N_("DVD-RW Disc"), N_("Blank DVD-RW Disc")},-  {"dvd_plus_r",    "media-optical-dvd-r-plus", N_("DVD+R Disc"), N_("Blank DVD+R Disc")},-  {"dvd_plus_rw",   "media-optical-dvd-rw-plus",  N_("DVD+RW Disc"), N_("Blank DVD+RW Disc")},-  {"dvd_plus_r_dl", "media-optical-dvd-dl-r-plus", N_("DVD+R DL Disc"), N_("Blank DVD+R DL Disc")},-  {"bd_rom",        "media-optical-bd-rom", N_("Blu-Ray Disc"), N_("Blank Blu-Ray Disc")},-  {"bd_r",          "media-optical-bd-r", N_("Blu-Ray R Disc"), N_("Blank Blu-Ray R Disc")},-  {"bd_re",         "media-optical-bd-re", N_("Blu-Ray RW Disc"), N_("Blank Blu-Ray RW Disc")},-  {"hddvd_rom",     "media-optical-hddvd-rom", N_("HD DVD Disc"), N_("Blank HD DVD Disc")},-  {"hddvd_r",       "media-optical-hddvd-r", N_("HD DVD-R Disc"), N_("Blank HD DVD-R Disc")},-  {"hddvd_rw",      "media-optical-hddvd-rw", N_("HD DVD-RW Disc"), N_("Blank HD DVD-RW Disc")},-  {"mo",            "media-optical-mo", N_("MO Disc"), N_("Blank MO Disc")},-  {NULL,            "media-optical", N_("Disc"), N_("Blank Disc")}-};--static const char *-get_disc_name (const char *disc_type, gboolean is_blank)-{-  int n;-  -  for (n = 0; disc_data[n].disc_type != NULL; n++)-    {-      if (strcmp (disc_data[n].disc_type, disc_type) == 0)-        break;-    }-  -  if (is_blank)-    return dgettext (GETTEXT_PACKAGE, disc_data[n].ui_name_blank);-  else-    return dgettext (GETTEXT_PACKAGE, disc_data[n].ui_name);-}-- #define KILOBYTE_FACTOR 1000.0 #define MEGABYTE_FACTOR (1000.0 * 1000.0) #define GIGABYTE_FACTOR (1000.0 * 1000.0 * 1000.0)@@ -332,11 +292,13 @@ do_update_from_hal (GHalVolume *mv)     }    mv->name = name;+  mv->icon = _drive_get_icon (drive); /* use the drive icon since we're unmounted */    if (is_crypto || is_crypto_cleartext)-    mv->icon = g_strdup ("drive-encrypted");-  else-    mv->icon = _drive_get_icon (drive); /* use the drive icon since we're unmounted */+    {+      mv->icon_fallback = mv->icon;+      mv->icon = g_strdup ("drive-encrypted");+    }    if (hal_device_get_property_bool (volume, "volume.is_mounted"))     mv->mount_path = g_strdup (hal_device_get_property_string (volume, "volume.mount_point"));@@ -690,11 +652,19 @@ g_hal_volume_get_icon (GVolume *volume) {   GHalVolume *hal_volume = G_HAL_VOLUME (volume);   GIcon *icon;+  const char *name;+  const char *fallback;    G_LOCK (hal_volume);-  icon = g_themed_icon_new_with_default_fallbacks (hal_volume->icon);+  name = hal_volume->icon;++  if (hal_volume->icon_fallback)+    fallback = hal_volume->icon_fallback;+  else /* if no custom fallbacks are set, use the icon to create them */+    fallback = name;++  icon = get_themed_icon_with_fallbacks (name, fallback);   G_UNLOCK (hal_volume);-     return icon; } diff --git a/hal/hal-utils.c b/hal/hal-utils.cnew file mode 100644index 0000000..bbf760f--- /dev/null+++ b/hal/hal-utils.c@@ -0,0 +1,144 @@+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */++/* GIO - GLib Input, Output and Streaming Library+ *+ * Copyright (C) 2006-2007 Red Hat, Inc.+ *+ * This library is free software; you can redistribute it and/or+ * modify it under the terms of the GNU Lesser General Public+ * License as published by the Free Software Foundation; either+ * version 2 of the License, or (at your option) any later version.+ *+ * This library is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU+ * Lesser General Public License for more details.+ *+ * You should have received a copy of the GNU Lesser General+ * Public License along with this library; if not, write to the+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,+ * Boston, MA 02111-1307, USA.+ *+ * Author: David Zeuthen <davidz@redhat.com>+ *         Christian Kellner <gicmo@gnome.org>+ */++#include <config.h>++#include <glib.h>+#include <glib/gi18n-lib.h>+#include <gio/gio.h>++#include "string.h"++#include "hal-utils.h"++static const struct {+  const char *disc_type;+  const char *icon_name;+  char *ui_name;+  char *ui_name_blank;+} disc_data[] = {+  {"cd_rom",        "media-optical-cd-rom", N_("CD-ROM Disc"), N_("Blank CD-ROM Disc")},+  {"cd_r",          "media-optical-cd-r", N_("CD-R Disc"), N_("Blank CD-R Disc")},+  {"cd_rw",         "media-optical-cd-rw", N_("CD-RW Disc"), N_("Blank CD-RW Disc")},+  {"dvd_rom",       "media-optical-dvd-rom", N_("DVD-ROM Disc"), N_("Blank DVD-ROM Disc")},+  {"dvd_ram",       "media-optical-dvd-ram", N_("DVD-RAM Disc"), N_("Blank DVD-RAM Disc")},+  {"dvd_r",         "media-optical-dvd-r", N_("DVD-ROM Disc"), N_("Blank DVD-ROM Disc")},+  {"dvd_rw",        "media-optical-dvd-rw", N_("DVD-RW Disc"), N_("Blank DVD-RW Disc")},+  {"dvd_plus_r",    "media-optical-dvd-r-plus", N_("DVD+R Disc"), N_("Blank DVD+R Disc")},+  {"dvd_plus_rw",   "media-optical-dvd-rw-plus",  N_("DVD+RW Disc"), N_("Blank DVD+RW Disc")},+  {"dvd_plus_r_dl", "media-optical-dvd-dl-r-plus", N_("DVD+R DL Disc"), N_("Blank DVD+R DL Disc")},+  {"bd_rom",        "media-optical-bd-rom", N_("Blu-Ray Disc"), N_("Blank Blu-Ray Disc")},+  {"bd_r",          "media-optical-bd-r", N_("Blu-Ray R Disc"), N_("Blank Blu-Ray R Disc")},+  {"bd_re",         "media-optical-bd-re", N_("Blu-Ray RW Disc"), N_("Blank Blu-Ray RW Disc")},+  {"hddvd_rom",     "media-optical-hddvd-rom", N_("HD DVD Disc"), N_("Blank HD DVD Disc")},+  {"hddvd_r",       "media-optical-hddvd-r", N_("HD DVD-R Disc"), N_("Blank HD DVD-R Disc")},+  {"hddvd_rw",      "media-optical-hddvd-rw", N_("HD DVD-RW Disc"), N_("Blank HD DVD-RW Disc")},+  {"mo",            "media-optical-mo", N_("MO Disc"), N_("Blank MO Disc")},+  {NULL,            "media-optical", N_("Disc"), N_("Blank Disc")}+};++const char *+get_disc_icon (const char *disc_type)+{+  int n;+ +  for (n = 0; disc_data[n].disc_type != NULL; n++)+    {+      if (strcmp (disc_data[n].disc_type, disc_type) == 0)+        break;+    }+ +  return disc_data[n].icon_name;+}++const char *+get_disc_name (const char *disc_type, gboolean is_blank)+{+  int n;+ +  for (n = 0; disc_data[n].disc_type != NULL; n++)+    {+      if (strcmp (disc_data[n].disc_type, disc_type) == 0)+        break;+    }+ +  if (is_blank)+    return dgettext (GETTEXT_PACKAGE, disc_data[n].ui_name_blank);+  else+    return dgettext (GETTEXT_PACKAGE, disc_data[n].ui_name);+}++/*+ * Creates a GThemedIcon from icon_name and creates default+ * fallbacks from fallbacks. Is smart in the case that icon_name+ * and fallbacks are identically.+ * Note: See the GThemedIcon documentation for more information+ * on default fallbacks+ */+GIcon *+get_themed_icon_with_fallbacks (const char *icon_name,+                                const char *fallbacks)+{+  int i = 0, dashes = 0;+  const char *p;+  char *dashp;+  char *last;+  char **names;+  GIcon *icon;++  if (G_UNLIKELY (icon_name == NULL))+    return NULL;++  if (fallbacks == NULL)+    return g_themed_icon_new (icon_name);++  p = fallbacks;+  while (*p)+    {+      if (*p == '-')+        dashes++;+      p++;+    }++  if (strcmp (icon_name, fallbacks))+    {+      names = g_new (char *, dashes + 3);+      names[i++] = g_strdup (icon_name);+    }+  else+    names = g_new (char *, dashes + 2); ++  names[i++] = last = g_strdup (fallbacks);++  while ((dashp = strrchr (last, '-')) != NULL)+    names[i++] = last = g_strndup (last, dashp - last);++  names[i++] = NULL;+  icon =  g_themed_icon_new_from_names (names, -1);+  g_strfreev (names);++  return icon;+}+diff --git a/hal/hal-utils.h b/hal/hal-utils.hnew file mode 100644index 0000000..375df7c--- /dev/null+++ b/hal/hal-utils.h@@ -0,0 +1,40 @@+/* GIO - GLib Input, Output and Streaming Library+ * + * Copyright (C) 2006-2007 Red Hat, Inc.+ *+ * This library is free software; you can redistribute it and/or+ * modify it under the terms of the GNU Lesser General Public+ * License as published by the Free Software Foundation; either+ * version 2 of the License, or (at your option) any later version.+ *+ * This library is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU+ * Lesser General Public License for more details.+ *+ * You should have received a copy of the GNU Lesser General+ * Public License along with this library; if not, write to the+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,+ * Boston, MA 02111-1307, USA.+ *+ * Author: David Zeuthen <davidz@redhat.com>+ *         Chrsitian Kellner <gicmo@gnome.org>+ */++#ifndef __HAL_UTILS_H__+#define __HAL_UTILS_H__++#include <glib-object.h>+#include <gio/gio.h>++G_BEGIN_DECLS++const char * get_disc_icon (const char *disc_type);+const char * get_disc_name (const char *disc_type, gboolean is_blank);++GIcon *      get_themed_icon_with_fallbacks (const char *icon_name,+                                             const char *fallbacks);++G_END_DECLS++#endif /* __HAL_UTILS_H__ */