[gnome-packagekit] Change the firmware 'Do not show again' to a 'Ignore devices' button, and add vid_pid GConf mechanis
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-packagekit] Change the firmware 'Do not show again' to a 'Ignore devices' button, and add vid_pid GConf mechanis
- Date: Mon, 24 Aug 2009 09:30:52 +0000 (UTC)
commit c94ca1806ee277871d2fd49866bac7240f8d93ad
Author: Richard Hughes <richard hughsie com>
Date: Mon Aug 24 10:29:25 2009 +0100
Change the firmware 'Do not show again' to a 'Ignore devices' button, and add vid_pid GConf mechanism
data/gnome-packagekit.schemas.in | 12 ++++
src/gpk-common.h | 1 +
src/gpk-firmware.c | 127 +++++++++++++++++++++++++++++++++++---
3 files changed, 130 insertions(+), 10 deletions(-)
---
diff --git a/data/gnome-packagekit.schemas.in b/data/gnome-packagekit.schemas.in
index ced1a29..67180da 100644
--- a/data/gnome-packagekit.schemas.in
+++ b/data/gnome-packagekit.schemas.in
@@ -26,6 +26,18 @@
</schema>
<schema>
+ <key>/schemas/apps/gnome-packagekit/update-icon/ignored_devices</key>
+ <applyto>/apps/gnome-packagekit/update-icon/ignored_devices</applyto>
+ <owner>gnome-packagekit</owner>
+ <type>string</type>
+ <default></default>
+ <locale name="C">
+ <short>Devices that should be ignored</short>
+ <long>Devices that should be ignored, separated by commas. These can include '*' and '?' characters</long>
+ </locale>
+ </schema>
+
+ <schema>
<key>/schemas/apps/gnome-packagekit/update-icon/ignored_messages</key>
<applyto>/apps/gnome-packagekit/update-icon/ignored_messages</applyto>
<owner>gnome-packagekit</owner>
diff --git a/src/gpk-common.h b/src/gpk-common.h
index 21a9eae..e2e71f0 100644
--- a/src/gpk-common.h
+++ b/src/gpk-common.h
@@ -64,6 +64,7 @@ G_BEGIN_DECLS
#define GPK_CONF_AUTO_UPDATE "/apps/gnome-packagekit/update-icon/auto_update"
#define GPK_CONF_UPDATE_BATTERY "/apps/gnome-packagekit/update-icon/update_battery"
#define GPK_CONF_BANNED_FIRMWARE "/apps/gnome-packagekit/update-icon/banned_firmware"
+#define GPK_CONF_IGNORED_DEVICES "/apps/gnome-packagekit/update-icon/ignored_devices"
#define GPK_CONF_IGNORED_MESSAGES "/apps/gnome-packagekit/update-icon/ignored_messages"
#define GPK_CONF_WATCH_ACTIVE_TRANSACTIONS "/apps/gnome-packagekit/update-icon/watch_active_transactions"
#define GPK_CONF_APPLICATION_FILTER_BASENAME "/apps/gnome-packagekit/application/filter_basename"
diff --git a/src/gpk-firmware.c b/src/gpk-firmware.c
index 7233c7b..9c2bb87 100644
--- a/src/gpk-firmware.c
+++ b/src/gpk-firmware.c
@@ -82,6 +82,7 @@ typedef struct {
gchar *filename;
gchar *sysfs_path;
gchar *model;
+ gchar *id;
GpkFirmwareSubsystem subsystem;
} GpkFirmwareRequest;
@@ -110,6 +111,8 @@ gpk_firmware_request_new (const gchar *filename, const gchar *sysfs_path)
GUdevClient *client;
const gchar *subsystem;
const gchar *model;
+ const gchar *id_vendor;
+ const gchar *id_product;
#endif
req = g_new0 (GpkFirmwareRequest, 1);
@@ -141,6 +144,11 @@ gpk_firmware_request_new (const gchar *filename, const gchar *sysfs_path)
/* replace invalid chars */
g_strdelimit (req->model, "_", ' ');
}
+
+ /* create ID so we can ignore the specific device */
+ id_vendor = g_udev_device_get_property (device, "ID_VENDOR");
+ id_product = g_udev_device_get_property (device, "ID_MODEL_ID");
+ req->id = g_strdup_printf ("%s_%s", id_vendor, id_product);
out:
g_object_unref (device);
g_object_unref (client);
@@ -157,6 +165,7 @@ gpk_firmware_request_free (GpkFirmwareRequest *req)
g_free (req->filename);
g_free (req->model);
g_free (req->sysfs_path);
+ g_free (req->id);
g_free (req);
}
@@ -247,6 +256,56 @@ out:
}
/**
+ * gpk_firmware_ignore_devices:
+ **/
+static void
+gpk_firmware_ignore_devices (GpkFirmware *firmware)
+{
+ gboolean ret;
+ gchar *existing;
+ GError *error = NULL;
+ GpkFirmwareRequest *req;
+ GPtrArray *array;
+ GString *string;
+ guint i;
+
+ /* get from gconf */
+ existing = gconf_client_get_string (firmware->priv->gconf_client, GPK_CONF_IGNORED_DEVICES, &error);
+ if (error != NULL) {
+ egg_warning ("failed to get ignored devices: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* get existing string */
+ string = g_string_new (existing);
+ if (string->len > 0)
+ g_string_append (string, ",");
+
+ /* add all listed devices */
+ array = firmware->priv->array_requested;
+ for (i=0; i<array->len; i++) {
+ req = g_ptr_array_index (array, i);
+ g_string_append_printf (string, "%s,", req->id);
+ }
+
+ /* remove final ',' */
+ if (string->len > 2)
+ g_string_set_size (string, string->len - 1);
+
+ /* set new string to gconf */
+ ret = gconf_client_set_string (firmware->priv->gconf_client, GPK_CONF_IGNORED_DEVICES, string->str, &error);
+ if (!ret) {
+ egg_warning ("failed to set new string %s: %s", string->str, error->message);
+ g_error_free (error);
+ goto out;
+ }
+out:
+ g_free (existing);
+ g_string_free (string, TRUE);
+}
+
+/**
* gpk_firmware_libnotify_cb:
**/
static void
@@ -258,9 +317,8 @@ gpk_firmware_libnotify_cb (NotifyNotification *notification, gchar *action, gpoi
if (g_strcmp0 (action, "install-firmware") == 0) {
gpk_firmware_install_file (firmware);
- } else if (g_strcmp0 (action, "do-not-show-prompt-firmware") == 0) {
- egg_debug ("set %s to FALSE", GPK_CONF_ENABLE_CHECK_FIRMWARE);
- gconf_client_set_bool (firmware->priv->gconf_client, GPK_CONF_ENABLE_CHECK_FIRMWARE, FALSE, NULL);
+ } else if (g_strcmp0 (action, "ignore-devices") == 0) {
+ gpk_firmware_ignore_devices (firmware);
} else if (g_strcmp0 (action, "restart-now") == 0) {
ret = egg_console_kit_restart (firmware->priv->consolekit, &error);
if (!ret) {
@@ -328,7 +386,6 @@ out:
/**
* gpk_firmware_timeout_cb:
- * @data: This class instance
**/
static gboolean
gpk_firmware_timeout_cb (gpointer data)
@@ -398,8 +455,9 @@ gpk_firmware_timeout_cb (gpointer data)
notify_notification_add_action (notification, "install-firmware",
/* TRANSLATORS: button label */
_("Install firmware"), gpk_firmware_libnotify_cb, firmware, NULL);
- notify_notification_add_action (notification, "do-not-show-prompt-firmware",
- _("Do not show this again"), gpk_firmware_libnotify_cb, firmware, NULL);
+ notify_notification_add_action (notification, "ignore-devices",
+ /* TRANSLATORS: we should ignore this device and not ask anymore */
+ _("Ignore devices"), gpk_firmware_libnotify_cb, firmware, NULL);
ret = notify_notification_show (notification, &error);
if (!ret) {
egg_warning ("error: %s", error->message);
@@ -414,16 +472,15 @@ out:
/**
* gpk_firmware_remove_banned:
- * @data: This class instance
**/
static void
gpk_firmware_remove_banned (GpkFirmware *firmware, GPtrArray *array)
{
- gchar *banned_str;
- gchar **banned = NULL;
- guint i, j;
gboolean ret;
+ gchar **banned = NULL;
+ gchar *banned_str;
GpkFirmwareRequest *req;
+ guint i, j;
/* get from gconf */
banned_str = gconf_client_get_string (firmware->priv->gconf_client, GPK_CONF_BANNED_FIRMWARE, NULL);
@@ -450,6 +507,7 @@ gpk_firmware_remove_banned (GpkFirmware *firmware, GPtrArray *array)
egg_debug ("match %s for %s, removing", banned[j], req->filename);
gpk_firmware_request_free (req);
g_ptr_array_remove_index_fast (array, i);
+ break;
}
}
}
@@ -459,6 +517,52 @@ out:
}
/**
+ * gpk_firmware_remove_ignored:
+ **/
+static void
+gpk_firmware_remove_ignored (GpkFirmware *firmware, GPtrArray *array)
+{
+ gboolean ret;
+ gchar **ignored = NULL;
+ gchar *ignored_str;
+ GpkFirmwareRequest *req;
+ guint i, j;
+
+ /* get from gconf */
+ ignored_str = gconf_client_get_string (firmware->priv->gconf_client, GPK_CONF_IGNORED_DEVICES, NULL);
+ if (ignored_str == NULL) {
+ egg_warning ("could not read ignored list");
+ goto out;
+ }
+
+ /* nothing in list, common case */
+ if (egg_strzero (ignored_str)) {
+ egg_debug ("nothing in ignored list");
+ goto out;
+ }
+
+ /* split using "," */
+ ignored = g_strsplit (ignored_str, ",", 0);
+
+ /* remove any ignored pattern matches */
+ for (i=0; i<array->len; i++) {
+ req = g_ptr_array_index (array, i);
+ for (j=0; ignored[j] != NULL; j++) {
+ ret = g_pattern_match_simple (ignored[j], req->id);
+ if (ret) {
+ egg_debug ("match %s for %s, removing", ignored[j], req->id);
+ gpk_firmware_request_free (req);
+ g_ptr_array_remove_index_fast (array, i);
+ break;
+ }
+ }
+ }
+out:
+ g_free (ignored_str);
+ g_strfreev (ignored);
+}
+
+/**
* gpk_firmware_udev_text_decode:
**/
static gchar *
@@ -850,6 +954,9 @@ gpk_firmware_scan_directory (GpkFirmware *firmware)
/* remove banned files */
gpk_firmware_remove_banned (firmware, array);
+ /* remove ignored devices */
+ gpk_firmware_remove_ignored (firmware, array);
+
/* debugging */
array = firmware->priv->array_requested;
for (i=0; i<array->len; i++) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]