[gnome-color-manager] trivial: use the GcmDevice getters and setters in more places rather than g_object_get/set
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] trivial: use the GcmDevice getters and setters in more places rather than g_object_get/set
- Date: Wed, 24 Mar 2010 17:49:34 +0000 (UTC)
commit c78991515fee22aa4ab262ebe6408c39709db84f
Author: Richard Hughes <richard hughsie com>
Date: Wed Mar 24 15:51:07 2010 +0000
trivial: use the GcmDevice getters and setters in more places rather than g_object_get/set
src/gcm-apply.c | 4 ---
src/gcm-calibrate.c | 32 ++++++++--------------
src/gcm-client.c | 21 ++++----------
src/gcm-dbus.c | 28 ++++++-------------
src/gcm-device-sane.c | 18 +++++-------
src/gcm-device-xrandr.c | 38 ++++++++++++++------------
src/gcm-device-xrandr.h | 1 +
src/gcm-device.c | 19 +++----------
src/gcm-prefs.c | 67 ++++++++++++++---------------------------------
9 files changed, 80 insertions(+), 148 deletions(-)
---
diff --git a/src/gcm-apply.c b/src/gcm-apply.c
index e3e42e7..7649fff 100644
--- a/src/gcm-apply.c
+++ b/src/gcm-apply.c
@@ -46,7 +46,6 @@ main (int argc, char **argv)
guint i;
GcmClient *client = NULL;
GcmDevice *device;
- GcmDeviceTypeEnum type;
setlocale (LC_ALL, "");
@@ -75,9 +74,6 @@ main (int argc, char **argv)
array = gcm_client_get_devices (client);
for (i=0; i<array->len; i++) {
device = g_ptr_array_index (array, i);
- g_object_get (device,
- "type", &type,
- NULL);
/* set gamma for device */
egg_debug ("setting profiles on device: %s", gcm_device_get_id (device));
diff --git a/src/gcm-calibrate.c b/src/gcm-calibrate.c
index becf6ad..e1ec201 100644
--- a/src/gcm-calibrate.c
+++ b/src/gcm-calibrate.c
@@ -35,6 +35,7 @@
#include <gconf/gconf-client.h>
#include "gcm-calibrate.h"
+#include "gcm-device-xrandr.h"
#include "gcm-utils.h"
#include "gcm-brightness.h"
#include "gcm-colorimeter.h"
@@ -248,21 +249,19 @@ gboolean
gcm_calibrate_set_from_device (GcmCalibrate *calibrate, GcmDevice *device, GError **error)
{
gboolean ret = TRUE;
- gchar *native_device = NULL;
- gchar *manufacturer = NULL;
- gchar *model = NULL;
- gchar *description = NULL;
- gchar *serial = NULL;
+ const gchar *native_device = NULL;
+ const gchar *manufacturer = NULL;
+ const gchar *model = NULL;
+ const gchar *description = NULL;
+ const gchar *serial = NULL;
GcmDeviceTypeEnum type;
/* get the device */
- g_object_get (device,
- "type", &type,
- "serial", &serial,
- "model", &model,
- "title", &description,
- "manufacturer", &manufacturer,
- NULL);
+ type = gcm_device_get_kind (device);
+ serial = gcm_device_get_serial (device);
+ model = gcm_device_get_model (device);
+ description = gcm_device_get_title (device);
+ manufacturer = gcm_device_get_manufacturer (device);
/* set the proper values */
g_object_set (calibrate,
@@ -278,9 +277,7 @@ gcm_calibrate_set_from_device (GcmCalibrate *calibrate, GcmDevice *device, GErro
/* display specific properties */
if (type == GCM_DEVICE_TYPE_ENUM_DISPLAY) {
- g_object_get (device,
- "native-device", &native_device,
- NULL);
+ native_device = gcm_device_xrandr_get_native_device (GCM_DEVICE_XRANDR (device));
if (native_device == NULL) {
g_set_error (error,
GCM_CALIBRATE_ERROR,
@@ -295,11 +292,6 @@ gcm_calibrate_set_from_device (GcmCalibrate *calibrate, GcmDevice *device, GErro
}
out:
- g_free (native_device);
- g_free (manufacturer);
- g_free (model);
- g_free (description);
- g_free (serial);
return ret;
}
diff --git a/src/gcm-client.c b/src/gcm-client.c
index 2875869..4d62d87 100644
--- a/src/gcm-client.c
+++ b/src/gcm-client.c
@@ -937,9 +937,7 @@ gcm_client_add_saved (GcmClient *client, GError **error)
gcm_client_add_unconnected_device (client, keyfile, groups[i]);
} else {
egg_debug ("found already added %s", groups[i]);
- g_object_set (device,
- "saved", TRUE,
- NULL);
+ gcm_device_set_saved (device, TRUE);
}
}
out:
@@ -1012,7 +1010,7 @@ gboolean
gcm_client_add_device (GcmClient *client, GcmDevice *device, GError **error)
{
gboolean ret = FALSE;
- gchar *id = NULL;
+ const gchar *id;
gboolean virtual;
GcmDevice *device_tmp = NULL;
@@ -1020,16 +1018,14 @@ gcm_client_add_device (GcmClient *client, GcmDevice *device, GError **error)
g_return_val_if_fail (GCM_IS_DEVICE (device), FALSE);
/* check removable */
- g_object_get (device,
- "virtual", &virtual,
- "id", &id,
- NULL);
+ virtual = gcm_device_get_virtual (device);
if (!virtual) {
g_set_error_literal (error, 1, 0, "cannot add non-virtual devices");
goto out;
}
/* look to see if device already exists */
+ id = gcm_device_get_id (device);
device_tmp = gcm_client_get_device_by_id (client, id);
if (device_tmp != NULL) {
/* TRANSLATORS: error message */
@@ -1041,9 +1037,7 @@ gcm_client_add_device (GcmClient *client, GcmDevice *device, GError **error)
g_ptr_array_add (client->priv->array, g_object_ref (device));
/* update status */
- g_object_set (device,
- "saved", FALSE,
- NULL);
+ gcm_device_set_saved (device, FALSE);
/* emit a signal */
egg_debug ("emit added: %s", id);
@@ -1055,7 +1049,6 @@ gcm_client_add_device (GcmClient *client, GcmDevice *device, GError **error)
/* all okay */
ret = TRUE;
out:
- g_free (id);
if (device_tmp != NULL)
g_object_unref (device_tmp);
return ret;
@@ -1126,9 +1119,7 @@ gcm_client_delete_device (GcmClient *client, GcmDevice *device, GError **error)
goto out;
/* update status */
- g_object_set (device,
- "saved", FALSE,
- NULL);
+ gcm_device_set_saved (device, FALSE);
not_saved:
/* emit a signal */
diff --git a/src/gcm-dbus.c b/src/gcm-dbus.c
index f9506e9..947fc7d 100644
--- a/src/gcm-dbus.c
+++ b/src/gcm-dbus.c
@@ -29,6 +29,7 @@
#include "gcm-utils.h"
#include "gcm-dbus.h"
+#include "gcm-device-xrandr.h"
#include "gcm-client.h"
#include "gcm-profile.h"
#include "gcm-profile-store.h"
@@ -165,9 +166,9 @@ static GPtrArray *
gcm_dbus_get_profiles_for_device_internal (GcmDbus *dbus, const gchar *device_id_with_prefix)
{
gboolean ret;
- gchar *filename;
+ const gchar *filename;
const gchar *device_id;
- gchar *device_id_tmp;
+ const gchar *device_id_tmp;
guint i;
gboolean use_native_device = FALSE;
GcmDevice *device;
@@ -200,14 +201,10 @@ gcm_dbus_get_profiles_for_device_internal (GcmDbus *dbus, const gchar *device_id
device = g_ptr_array_index (array_devices, i);
/* get the id for this device */
- if (use_native_device) {
- g_object_get (device,
- "native-device", &device_id_tmp,
- NULL);
+ if (use_native_device && GCM_IS_DEVICE_XRANDR (device)) {
+ device_id_tmp = gcm_device_xrandr_get_native_device (GCM_DEVICE_XRANDR (device));
} else {
- g_object_get (device,
- "id", &device_id_tmp,
- NULL);
+ device_id_tmp = gcm_device_get_id (device);
}
/* wrong type of device */
@@ -217,11 +214,9 @@ gcm_dbus_get_profiles_for_device_internal (GcmDbus *dbus, const gchar *device_id
/* compare what we have against what we were given */
egg_debug ("comparing %s with %s", device_id_tmp, device_id);
if (g_strcmp0 (device_id_tmp, device_id) == 0) {
- g_object_get (device,
- "profile-filename", &filename,
- NULL);
/* we have a profile? */
+ filename = gcm_device_get_profile_filename (device);
if (filename == NULL) {
egg_warning ("%s does not have a profile set", device_id);
continue;
@@ -241,9 +236,7 @@ gcm_dbus_get_profiles_for_device_internal (GcmDbus *dbus, const gchar *device_id
/* unref */
g_object_unref (file);
g_object_unref (profile);
- g_free (filename);
}
- g_free (device_id_tmp);
}
/* unref list of devices */
@@ -432,7 +425,7 @@ gcm_dbus_get_profile_for_window (GcmDbus *dbus, guint xid, DBusGMethodInvocation
GError *error;
GcmDevice *device;
GdkWindow *window;
- gchar *filename = NULL;
+ const gchar *filename;
egg_debug ("getting profile for %i", xid);
@@ -455,9 +448,7 @@ gcm_dbus_get_profile_for_window (GcmDbus *dbus, guint xid, DBusGMethodInvocation
}
/* get the data */
- g_object_get (device,
- "profile-filename", &filename,
- NULL);
+ filename = gcm_device_get_profile_filename (device);
if (filename == NULL) {
error = g_error_new (1, 0, "no profiles found for xid %i", xid);
dbus_g_method_return_error (context, error);
@@ -473,7 +464,6 @@ out:
g_timer_reset (dbus->priv->timer);
if (window != NULL)
g_object_unref (window);
- g_free (filename);
}
/**
diff --git a/src/gcm-device-sane.c b/src/gcm-device-sane.c
index 07dfd3f..11a8d72 100644
--- a/src/gcm-device-sane.c
+++ b/src/gcm-device-sane.c
@@ -275,18 +275,17 @@ gcm_device_sane_apply_device (GcmDeviceSane *device_sane, GError **error)
gboolean ret = FALSE;
gchar *filename = NULL;
gchar *device_filename = NULL;
- gchar *profile_filename = NULL;
+ const gchar *profile_filename = NULL;
gchar *profile_filename_quoted = NULL;
GPtrArray *array;
- gchar *manufacturer = NULL;
- gchar *model = NULL;
+ const gchar *manufacturer = NULL;
+ const gchar *model = NULL;
+ GcmDevice *device = GCM_DEVICE (device_sane);
/* get properties from device */
- g_object_get (device_sane,
- "model", &model,
- "manufacturer", &manufacturer,
- "profile-filename", &profile_filename,
- NULL);
+ model = gcm_device_get_model (device);
+ manufacturer = gcm_device_get_manufacturer (device);
+ profile_filename = gcm_device_get_profile_filename (device);
profile_filename_quoted = g_strdup_printf ("\"%s\"", profile_filename);
device_filename = g_strdup_printf ("%s:%s.drc", manufacturer, model);
@@ -316,11 +315,8 @@ gcm_device_sane_apply_device (GcmDeviceSane *device_sane, GError **error)
out:
if (array != NULL)
g_ptr_array_unref (array);
- g_free (manufacturer);
- g_free (model);
g_free (filename);
g_free (device_filename);
- g_free (profile_filename);
return ret;
}
diff --git a/src/gcm-device-xrandr.c b/src/gcm-device-xrandr.c
index 8a465a8..846b65f 100644
--- a/src/gcm-device-xrandr.c
+++ b/src/gcm-device-xrandr.c
@@ -73,6 +73,15 @@ G_DEFINE_TYPE (GcmDeviceXrandr, gcm_device_xrandr, GCM_TYPE_DEVICE)
#define GCM_ICC_PROFILE_IN_X_VERSION_MINOR 3
/**
+ * gcm_device_xrandr_get_native_device:
+ **/
+const gchar *
+gcm_device_xrandr_get_native_device (GcmDeviceXrandr *device_xrandr)
+{
+ return device_xrandr->priv->native_device;
+}
+
+/**
* gcm_device_xrandr_get_output_name:
*
* Return value: the output name, free with g_free().
@@ -443,13 +452,13 @@ gcm_device_xrandr_apply (GcmDevice *device, GError **error)
GnomeRRCrtc *crtc;
GnomeRROutput *output;
gint x, y;
- gchar *filename = NULL;
+ const gchar *filename;
gchar *filename_systemwide = NULL;
gfloat gamma_adjust;
gfloat brightness;
gfloat contrast;
- gchar *output_name;
- gchar *id = NULL;
+ const gchar *output_name;
+ const gchar *id;
guint size;
gboolean saved;
gboolean use_global;
@@ -460,31 +469,24 @@ gcm_device_xrandr_apply (GcmDevice *device, GError **error)
GcmDeviceXrandr *device_xrandr = GCM_DEVICE_XRANDR (device);
GcmDeviceXrandrPrivate *priv = device_xrandr->priv;
- /* get details about the device */
- g_object_get (device_xrandr,
- "id", &id,
- "type", &type,
- "saved", &saved,
- "profile-filename", &filename,
- "gamma", &gamma_adjust,
- "brightness", &brightness,
- "contrast", &contrast,
- "native-device", &output_name,
- NULL);
-
/* do no set the gamma for non-display types */
+ id = gcm_device_get_id (device);
+ type = gcm_device_get_kind (device);
if (type != GCM_DEVICE_TYPE_ENUM_DISPLAY) {
g_set_error (error, 1, 0, "not a display: %s", id);
goto out;
}
/* should be set for display types */
+ output_name = gcm_device_xrandr_get_native_device (device_xrandr);
if (output_name == NULL || output_name[0] == '\0') {
g_set_error (error, 1, 0, "no output name for display: %s", id);
goto out;
}
/* if not saved, try to find default filename */
+ saved = gcm_device_get_saved (device);
+ filename = gcm_device_get_profile_filename (device);
if (!saved && filename == NULL) {
filename_systemwide = g_strdup_printf ("%s/%s.icc", GCM_SYSTEM_PROFILES_DIR, id);
ret = g_file_test (filename_systemwide, G_FILE_TEST_EXISTS);
@@ -536,6 +538,9 @@ gcm_device_xrandr_apply (GcmDevice *device, GError **error)
/* do fine adjustment */
if (use_global) {
+ gamma_adjust = gcm_device_get_gamma (device);
+ brightness = gcm_device_get_brightness (device);
+ contrast = gcm_device_get_contrast (device);
g_object_set (clut,
"gamma", gamma_adjust,
"brightness", brightness,
@@ -590,10 +595,7 @@ gcm_device_xrandr_apply (GcmDevice *device, GError **error)
}
}
out:
- g_free (id);
- g_free (filename);
g_free (filename_systemwide);
- g_free (output_name);
if (clut != NULL)
g_object_unref (clut);
if (profile != NULL)
diff --git a/src/gcm-device-xrandr.h b/src/gcm-device-xrandr.h
index 4ecb76a..b1f535a 100644
--- a/src/gcm-device-xrandr.h
+++ b/src/gcm-device-xrandr.h
@@ -53,6 +53,7 @@ GcmDevice *gcm_device_xrandr_new (void);
gboolean gcm_device_xrandr_set_from_output (GcmDevice *device,
GnomeRROutput *output,
GError **error);
+const gchar *gcm_device_xrandr_get_native_device (GcmDeviceXrandr *device_xrandr);
G_END_DECLS
diff --git a/src/gcm-device.c b/src/gcm-device.c
index 981fd0a..6558c45 100644
--- a/src/gcm-device.c
+++ b/src/gcm-device.c
@@ -1089,8 +1089,8 @@ gcm_device_test (EggTest *test)
GcmDevice *device;
gboolean ret;
GError *error = NULL;
- gchar *filename;
- gchar *profile;
+ const gchar *filename;
+ const gchar *profile;
gchar *data;
const gchar *type;
GcmDeviceTypeEnum type_enum;
@@ -1193,9 +1193,7 @@ gcm_device_test (EggTest *test)
egg_test_failed (test, "failed to load: %s", error->message);
/* get some properties */
- g_object_get (device,
- "profile-filename", &profile,
- NULL);
+ profile = gcm_device_get_profile_filename (device);
/************************************************************/
egg_test_title (test, "get profile filename");
@@ -1203,7 +1201,6 @@ gcm_device_test (EggTest *test)
egg_test_success (test, NULL);
else
egg_test_failed (test, "invalid profile: %s", profile);
- g_free (profile);
/* empty file that exists */
g_file_set_contents (filename, "", -1, NULL);
@@ -1228,9 +1225,7 @@ gcm_device_test (EggTest *test)
egg_test_failed (test, "failed to load: %s", error->message);
/* get some properties */
- g_object_get (device,
- "profile-filename", &profile,
- NULL);
+ profile = gcm_device_get_profile_filename (device);
/************************************************************/
egg_test_loop_wait (test, 100);
@@ -1249,12 +1244,9 @@ gcm_device_test (EggTest *test)
egg_test_success (test, NULL);
else
egg_test_failed (test, "invalid profile: %s", profile);
- g_free (profile);
/* set some properties */
- g_object_set (device,
- "profile-filename", "/srv/sysfs_canon_canoscan.icc",
- NULL);
+ gcm_device_set_profile_filename (device, "/srv/sysfs_canon_canoscan.icc");
/* ensure the file is nuked, again */
g_unlink (filename);
@@ -1284,7 +1276,6 @@ gcm_device_test (EggTest *test)
g_unlink (filename);
g_object_unref (device);
- g_free (filename);
egg_test_end (test);
}
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index 1a60dd9..fed6637 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -130,17 +130,13 @@ gcm_prefs_set_default (GcmDevice *device)
GError *error = NULL;
gboolean ret = FALSE;
gchar *cmdline = NULL;
- gchar *filename = NULL;
- gchar *id = NULL;
+ const gchar *filename;
+ const gchar *id;
gchar *install_cmd = NULL;
- /* get device properties */
- g_object_get (device,
- "profile-filename", &filename,
- "id", &id,
- NULL);
-
/* nothing set */
+ id = gcm_device_get_id (device);
+ filename = gcm_device_get_profile_filename (device);
if (filename == NULL) {
egg_debug ("no filename for %s", id);
goto out;
@@ -158,10 +154,8 @@ gcm_prefs_set_default (GcmDevice *device)
goto out;
}
out:
- g_free (id);
g_free (install_cmd);
g_free (cmdline);
- g_free (filename);
return ret;
}
@@ -225,11 +219,9 @@ gcm_prefs_default_cb (GtkWidget *widget, gpointer data)
array = gcm_client_get_devices (gcm_client);
for (i=0; i<array->len; i++) {
device = g_ptr_array_index (array, i);
- g_object_get (device,
- "type", &type,
- NULL);
/* not a xrandr panel */
+ type = gcm_device_get_kind (device);
if (type != GCM_DEVICE_TYPE_ENUM_DISPLAY)
continue;
@@ -1191,11 +1183,6 @@ gcm_prefs_is_profile_suitable_for_device (GcmProfile *profile, GcmDevice *device
gboolean ret = FALSE;
GcmDeviceTypeEnum device_type;
- g_object_get (device,
- "type", &device_type,
- "colorspace", &device_colorspace,
- NULL);
-
/* get properties */
g_object_get (profile,
"type", &profile_type_tmp,
@@ -1203,10 +1190,12 @@ gcm_prefs_is_profile_suitable_for_device (GcmProfile *profile, GcmDevice *device
NULL);
/* not the right colorspace */
+ device_colorspace = gcm_device_get_colorspace (device);
if (device_colorspace != profile_colorspace)
goto out;
/* not the correct type */
+ device_type = gcm_device_get_kind (device);
profile_type = gcm_utils_device_type_to_profile_type (device_type);
if (profile_type_tmp != profile_type)
goto out;
@@ -1762,10 +1751,10 @@ static void
gcm_prefs_add_device_xrandr (GcmDevice *device)
{
GtkTreeIter iter;
- gchar *title_tmp = NULL;
+ const gchar *title_tmp;
gchar *title = NULL;
gchar *sort = NULL;
- gchar *id = NULL;
+ const gchar *id;
gboolean ret;
gboolean connected;
GError *error = NULL;
@@ -1776,14 +1765,9 @@ gcm_prefs_add_device_xrandr (GcmDevice *device)
goto out;
}
- /* get details */
- g_object_get (device,
- "id", &id,
- "connected", &connected,
- "title", &title_tmp,
- NULL);
-
/* italic for non-connected devices */
+ connected = gcm_device_get_connected (device);
+ title_tmp = gcm_device_get_title (device);
if (connected) {
/* set the gamma on the device */
ret = gcm_device_apply (device, &error);
@@ -1810,6 +1794,7 @@ gcm_prefs_add_device_xrandr (GcmDevice *device)
title);
/* add to list */
+ id = gcm_device_get_id (device);
egg_debug ("add %s to device list", id);
gtk_list_store_append (list_store_devices, &iter);
gtk_list_store_set (list_store_devices, &iter,
@@ -1818,9 +1803,7 @@ gcm_prefs_add_device_xrandr (GcmDevice *device)
GCM_DEVICES_COLUMN_TITLE, title,
GCM_DEVICES_COLUMN_ICON, "video-display", -1);
out:
- g_free (id);
g_free (sort);
- g_free (title_tmp);
g_free (title);
}
@@ -2105,31 +2088,26 @@ static void
gcm_prefs_add_device_type (GcmDevice *device)
{
GtkTreeIter iter;
- gchar *title;
+ const gchar *title;
GString *string;
- gchar *id;
+ const gchar *id;
gchar *sort = NULL;
GcmDeviceTypeEnum type;
const gchar *icon_name;
gboolean connected;
gboolean virtual;
- /* get details */
- g_object_get (device,
- "id", &id,
- "connected", &connected,
- "virtual", &virtual,
- "title", &title,
- "type", &type,
- NULL);
-
/* get icon */
+ type = gcm_device_get_kind (device);
icon_name = gcm_prefs_device_type_to_icon_name (type);
/* create a title for the device */
+ title = gcm_device_get_title (device);
string = g_string_new (title);
/* italic for non-connected devices */
+ connected = gcm_device_get_connected (device);
+ virtual = gcm_device_get_virtual (device);
if (!connected && !virtual) {
/* TRANSLATORS: this is where the device has been setup but is not connected */
g_string_append_printf (string, "\n<i>[%s]</i>", _("disconnected"));
@@ -2141,14 +2119,13 @@ gcm_prefs_add_device_type (GcmDevice *device)
string->str);
/* add to list */
+ id = gcm_device_get_id (device);
gtk_list_store_append (list_store_devices, &iter);
gtk_list_store_set (list_store_devices, &iter,
GCM_DEVICES_COLUMN_ID, id,
GCM_DEVICES_COLUMN_SORT, sort,
GCM_DEVICES_COLUMN_TITLE, string->str,
GCM_DEVICES_COLUMN_ICON, icon_name, -1);
- g_free (id);
- g_free (title);
g_free (sort);
g_string_free (string, TRUE);
}
@@ -2205,12 +2182,8 @@ gcm_prefs_added_idle_cb (GcmDevice *device)
/* remove the saved device if it's already there */
gcm_prefs_remove_device (device);
- /* get the type of the device */
- g_object_get (device,
- "type", &type,
- NULL);
-
/* add the device */
+ type = gcm_device_get_kind (device);
if (type == GCM_DEVICE_TYPE_ENUM_DISPLAY)
gcm_prefs_add_device_xrandr (device);
else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]