예제 #1
0
/** Invoked when we get NumberBatteriesChanged
 */
static void
gpm_phone_num_batteries_changed (DBusGProxy *proxy, guint number, GpmPhone *phone)
{
    g_return_if_fail (GPM_IS_PHONE (phone));

    egg_debug ("got NumberBatteriesChanged %i", number);
    if (number > 1) {
        egg_warning ("number not 0 or 1, not valid!");
        return;
    }

    /* are we removed? */
    if (number == 0) {
        phone->priv->present = FALSE;
        phone->priv->percentage = 0;
        phone->priv->onac = FALSE;
        egg_debug ("emitting device-removed : (%i)", 0);
        g_signal_emit (phone, signals [DEVICE_REMOVED], 0, 0);
        return;
    }

    if (phone->priv->present) {
        egg_warning ("duplicate NumberBatteriesChanged with no change");
        return;
    }

    /* reset to defaults until we get BatteryStateChanged */
    phone->priv->present = TRUE;
    phone->priv->percentage = 0;
    phone->priv->onac = FALSE;
    egg_debug ("emitting device-added : (%i)", 0);
    g_signal_emit (phone, signals [DEVICE_ADDED], 0, 0);
}
예제 #2
0
/**
 * gpk_log_get_old_transactions_cb
 **/
static void
gpk_log_get_old_transactions_cb (GObject *object, GAsyncResult *res, gpointer user_data)
{
//	PkClient *client = PK_CLIENT (object);
	GError *error = NULL;
	PkResults *results = NULL;
	PkError *error_code = NULL;

	/* get the results */
	results = pk_client_generic_finish (client, res, &error);
	if (results == NULL) {
		egg_warning ("failed to get old transactions: %s", error->message);
		g_error_free (error);
		goto out;
	}

	/* check error code */
	error_code = pk_results_get_error_code (results);
	if (error_code != NULL) {
		egg_warning ("failed to get old transactions: %s, %s", pk_error_enum_to_text (pk_error_get_code (error_code)), pk_error_get_details (error_code));
		goto out;
	}

	/* get the list */
	if (transactions != NULL)
		g_ptr_array_unref (transactions);
	transactions = pk_results_get_transaction_array (results);
	gpk_log_refilter ();
out:
	if (error_code != NULL)
		g_object_unref (error_code);
	if (results != NULL)
		g_object_unref (results);
}
예제 #3
0
/**
 * gpm_session_is_suspend_inhibited:
 **/
static gboolean
gpm_session_is_suspend_inhibited (GpmSession *session)
{
	gboolean ret;
	gboolean is_inhibited = FALSE;
	GError *error = NULL;

	/* no mate-session */
	if (session->priv->proxy == NULL) {
		egg_warning ("no mate-session");
		goto out;
	}

	/* find out if this change altered the inhibited state */
	ret = dbus_g_proxy_call (session->priv->proxy, "IsInhibited", &error,
				 G_TYPE_UINT, GPM_SESSION_INHIBIT_MASK_SUSPEND,
				 G_TYPE_INVALID,
				 G_TYPE_BOOLEAN, &is_inhibited,
				 G_TYPE_INVALID);
	if (!ret) {
		egg_warning ("failed to get inhibit status: %s", error->message);
		g_error_free (error);
		is_inhibited = FALSE;
	}
out:
	return is_inhibited;
}
예제 #4
0
파일: up-devd.c 프로젝트: Kalvados/upower
void
up_devd_init (UpBackend *backend)
{
	int event_fd;
	struct sockaddr_un addr;

	event_fd = socket(PF_UNIX, SOCK_STREAM, 0);
	if (event_fd < 0) {
		egg_warning("failed to create event socket: '%s'", g_strerror(errno));
		up_devd_inited = FALSE;
		return;
	}

	addr.sun_family = AF_UNIX;
	strncpy (addr.sun_path, UP_DEVD_SOCK_PATH, sizeof(addr.sun_path));
	if (connect (event_fd, (struct sockaddr *)&addr, sizeof(addr)) == 0) {
		GIOChannel *channel;

		channel = g_io_channel_unix_new (event_fd);
		g_io_add_watch (channel, G_IO_IN, up_devd_event_cb, backend);
		g_io_channel_unref (channel);
		up_devd_inited = TRUE;
	} else {
		egg_warning ("failed to connect to %s: '%s'", UP_DEVD_SOCK_PATH,
			     g_strerror(errno));
		close (event_fd);
		up_devd_inited = FALSE;
	}
}
예제 #5
0
/**
 * gpm_networkmanager_wake:
 *
 * Tell NetworkManager to wake up all the network devices
 *
 * Return value: TRUE if NetworkManager is now awake.
 **/
gboolean
gpm_networkmanager_wake (void)
{
	DBusGConnection *connection = NULL;
	DBusGProxy *nm_proxy = NULL;
	GError *error = NULL;

	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
	if (error) {
		egg_warning ("%s", error->message);
		g_error_free (error);
		return FALSE;
	}

	nm_proxy = dbus_g_proxy_new_for_name (connection,
			NM_LISTENER_SERVICE,
			NM_LISTENER_PATH,
			NM_LISTENER_INTERFACE);
	if (!nm_proxy) {
		egg_warning ("Failed to get name owner");
		return FALSE;
	}
	dbus_g_proxy_call_no_reply (nm_proxy, "wake", G_TYPE_INVALID);
	g_object_unref (G_OBJECT (nm_proxy));
	return TRUE;
}
예제 #6
0
/**
 * gpm_session_is_idle:
 **/
static gboolean
gpm_session_is_idle (GpmSession *session)
{
	gboolean ret;
	gboolean is_idle = FALSE;
	GError *error = NULL;
	GValue *value;

	/* no mate-session */
	if (session->priv->proxy_prop == NULL) {
		egg_warning ("no mate-session");
		goto out;
	}

	value = g_new0(GValue, 1);
	/* find out if this change altered the inhibited state */
	ret = dbus_g_proxy_call (session->priv->proxy_prop, "Get", &error,
				 G_TYPE_STRING, GPM_SESSION_MANAGER_PRESENCE_INTERFACE,
				 G_TYPE_STRING, "status",
				 G_TYPE_INVALID,
				 G_TYPE_VALUE, value,
				 G_TYPE_INVALID);
	if (!ret) {
		egg_warning ("failed to get idle status: %s", error->message);
		g_error_free (error);
		is_idle = FALSE;
		goto out;
	}
	is_idle = (g_value_get_uint (value) == GPM_SESSION_STATUS_ENUM_IDLE);
	g_free (value);
out:
	return is_idle;
}
/**
 * gpm_inhibit_applet_dbus_connect:
 **/
gboolean
gpm_inhibit_applet_dbus_connect (GpmInhibitApplet *applet)
{
	GError *error = NULL;

	if (applet->connection == NULL) {
		egg_debug ("get connection\n");
		g_clear_error (&error);
		applet->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
		if (error != NULL) {
			egg_warning ("Could not connect to DBUS daemon: %s", error->message);
			g_error_free (error);
			applet->connection = NULL;
			return FALSE;
		}
	}
	if (applet->proxy == NULL) {
		egg_debug ("get proxy\n");
		g_clear_error (&error);
		applet->proxy = dbus_g_proxy_new_for_name_owner (applet->connection,
							 GS_DBUS_SERVICE,
							 GS_DBUS_PATH,
							 GS_DBUS_INTERFACE,
							 &error);
		if (error != NULL) {
			egg_warning ("Cannot connect, maybe the daemon is not running: %s\n", error->message);
			g_error_free (error);
			applet->proxy = NULL;
			return FALSE;
		}
	}
	return TRUE;
}
/**
 * gpm_applet_set_brightness:
 * Return value: Success value, or zero for failure
 **/
static gboolean
gpm_applet_set_brightness (GpmBrightnessApplet *applet)
{
	GError  *error = NULL;
	gboolean ret;

	if (applet->proxy == NULL) {
		egg_warning ("not connected");
		return FALSE;
	}

	ret = dbus_g_proxy_call (applet->proxy, "SetBrightness", &error,
				 G_TYPE_UINT, applet->level,
				 G_TYPE_INVALID,
				 G_TYPE_INVALID);
	if (error) {
		egg_debug ("ERROR: %s", error->message);
		g_error_free (error);
	}
	if (!ret) {
		/* abort as the DBUS method failed */
		egg_warning ("SetBrightness failed!");
	}

	return ret;
}
/**
 * gpm_applet_get_brightness:
 * Return value: Success value, or zero for failure
 **/
static gboolean
gpm_applet_get_brightness (GpmBrightnessApplet *applet)
{
	GError  *error = NULL;
	gboolean ret;
	guint policy_brightness;

	if (applet->proxy == NULL) {
		egg_warning ("not connected\n");
		return FALSE;
	}

	ret = dbus_g_proxy_call (applet->proxy, "GetBrightness", &error,
				 G_TYPE_INVALID,
				 G_TYPE_UINT, &policy_brightness,
				 G_TYPE_INVALID);
	if (error) {
		egg_debug ("ERROR: %s\n", error->message);
		g_error_free (error);
	}
	if (ret) {
		applet->level = policy_brightness;
	} else {
		/* abort as the DBUS method failed */
		egg_warning ("GetBrightness failed!\n");
	}

	return ret;
}
예제 #10
0
/**
 * gpm_session_end_session_response:
 **/
gboolean
gpm_session_end_session_response (GpmSession *session, gboolean is_okay, const gchar *reason)
{
	gboolean ret = FALSE;
	GError *error = NULL;

	g_return_val_if_fail (GPM_IS_SESSION (session), FALSE);
	g_return_val_if_fail (session->priv->proxy_client_private != NULL, FALSE);

	/* no mate-session */
	if (session->priv->proxy_client_private == NULL) {
		egg_warning ("no mate-session proxy");
		goto out;
	}

	/* send response */
	ret = dbus_g_proxy_call (session->priv->proxy_client_private, "EndSessionResponse", &error,
				 G_TYPE_BOOLEAN, is_okay,
				 G_TYPE_STRING, reason,
				 G_TYPE_INVALID,
				 G_TYPE_INVALID);
	if (!ret) {
		egg_warning ("failed to send session response: %s", error->message);
		g_error_free (error);
		goto out;
	}
out:
	return ret;
}
예제 #11
0
/**
 * gpm_session_register_client:
 **/
gboolean
gpm_session_register_client (GpmSession *session, const gchar *app_id, const gchar *client_startup_id)
{
	gboolean ret = FALSE;
	gchar *client_id = NULL;
	GError *error = NULL;
	DBusGConnection *connection;

	g_return_val_if_fail (GPM_IS_SESSION (session), FALSE);

	/* no mate-session */
	if (session->priv->proxy == NULL) {
		egg_warning ("no mate-session");
		goto out;
	}

	/* find out if this change altered the inhibited state */
	ret = dbus_g_proxy_call (session->priv->proxy, "RegisterClient", &error,
				 G_TYPE_STRING, app_id,
				 G_TYPE_STRING, client_startup_id,
				 G_TYPE_INVALID,
				 DBUS_TYPE_G_OBJECT_PATH, &client_id,
				 G_TYPE_INVALID);
	if (!ret) {
		egg_warning ("failed to register client '%s': %s", client_startup_id, error->message);
		g_error_free (error);
		goto out;
	}

	/* get org.mate.Session.ClientPrivate interface */
	connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
	session->priv->proxy_client_private = dbus_g_proxy_new_for_name_owner (connection, GPM_SESSION_MANAGER_SERVICE,
									       client_id, GPM_SESSION_MANAGER_CLIENT_PRIVATE_INTERFACE, &error);
	if (session->priv->proxy_client_private == NULL) {
		egg_warning ("DBUS error: %s", error->message);
		g_error_free (error);
		goto out;
	}

	/* get Stop */
	dbus_g_proxy_add_signal (session->priv->proxy_client_private, "Stop", G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (session->priv->proxy_client_private, "Stop", G_CALLBACK (gpm_session_stop_cb), session, NULL);

	/* get QueryEndSession */
	dbus_g_proxy_add_signal (session->priv->proxy_client_private, "QueryEndSession", G_TYPE_UINT, G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (session->priv->proxy_client_private, "QueryEndSession", G_CALLBACK (gpm_session_query_end_session_cb), session, NULL);

	/* get EndSession */
	dbus_g_proxy_add_signal (session->priv->proxy_client_private, "EndSession", G_TYPE_UINT, G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (session->priv->proxy_client_private, "EndSession", G_CALLBACK (gpm_session_end_session_cb), session, NULL);

	egg_debug ("registered startup '%s' to client id '%s'", client_startup_id, client_id);
out:
	g_free (client_id);
	return ret;
}
예제 #12
0
/**
 * gpm_phone_service_appeared_cb:
 */
static void
gpm_phone_service_appeared_cb (GDBusConnection *connection,
                               const gchar *name, const gchar *name_owner,
                               GpmPhone *phone)
{
    GError *error = NULL;

    g_return_if_fail (GPM_IS_PHONE (phone));

    if (phone->priv->connection == NULL) {
        egg_debug ("get connection");
        g_clear_error (&error);
        phone->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
        if (error != NULL) {
            egg_warning ("Could not connect to DBUS daemon: %s", error->message);
            g_error_free (error);
            phone->priv->connection = NULL;
            return;
        }
    }
    if (phone->priv->proxy == NULL) {
        egg_debug ("get proxy");
        g_clear_error (&error);
        phone->priv->proxy = dbus_g_proxy_new_for_name_owner (phone->priv->connection,
                             MATE_PHONE_MANAGER_DBUS_SERVICE,
                             MATE_PHONE_MANAGER_DBUS_PATH,
                             MATE_PHONE_MANAGER_DBUS_INTERFACE,
                             &error);
        if (error != NULL) {
            egg_warning ("Cannot connect, maybe the daemon is not running: %s", error->message);
            g_error_free (error);
            phone->priv->proxy = NULL;
            return;
        }

        /* complicated type. ick */
        dbus_g_object_register_marshaller(gpm_marshal_VOID__UINT_UINT_BOOLEAN,
                                          G_TYPE_NONE, G_TYPE_UINT, G_TYPE_UINT,
                                          G_TYPE_BOOLEAN, G_TYPE_INVALID);

        /* get BatteryStateChanged */
        dbus_g_proxy_add_signal (phone->priv->proxy, "BatteryStateChanged",
                                 G_TYPE_UINT, G_TYPE_UINT, G_TYPE_BOOLEAN, G_TYPE_INVALID);
        dbus_g_proxy_connect_signal (phone->priv->proxy, "BatteryStateChanged",
                                     G_CALLBACK (gpm_phone_battery_state_changed),
                                     phone, NULL);

        /* get NumberBatteriesChanged */
        dbus_g_proxy_add_signal (phone->priv->proxy, "NumberBatteriesChanged",
                                 G_TYPE_UINT, G_TYPE_INVALID);
        dbus_g_proxy_connect_signal (phone->priv->proxy, "NumberBatteriesChanged",
                                     G_CALLBACK (gpm_phone_num_batteries_changed),
                                     phone, NULL);

    }
}
예제 #13
0
/**
 * mcm_utils_is_package_installed:
 **/
gboolean
mcm_utils_is_package_installed (const gchar *package_name)
{
	GDBusConnection *connection;
	GVariant *args = NULL;
	GVariant *response = NULL;
	GError *error = NULL;
	gboolean installed = TRUE;

	g_return_val_if_fail (package_name != NULL, FALSE);

#ifndef MCM_USE_PACKAGEKIT
	egg_warning ("cannot query %s: this package was not compiled with --enable-packagekit", package_name);
	return TRUE;
#endif

	/* get a session bus connection */
	connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
	if (connection == NULL) {
		/* TRANSLATORS: no DBus session bus */
		g_print ("%s %s\n", _("Failed to connect to session bus:"), error->message);
		g_error_free (error);
		goto out;
	}

	/* execute sync method */
	args = g_variant_new ("(ss)", package_name, "timeout=5");
	response = g_dbus_connection_call_sync (connection,
						PK_DBUS_SERVICE,
						PK_DBUS_PATH,
						PK_DBUS_INTERFACE_QUERY,
						"IsInstalled",
						args,
						G_VARIANT_TYPE ("(b)"),
						G_DBUS_CALL_FLAGS_NONE,
						G_MAXINT, NULL, &error);
	if (response == NULL) {
		/* TRANSLATORS: the DBus method failed */
		egg_warning ("%s %s\n", _("The request failed:"), error->message);
		g_error_free (error);
		goto out;
	}

	/* get value */
	g_variant_get (response, "(b)", &installed);
out:
	if (args != NULL)
		g_variant_unref (args);
	if (response != NULL)
		g_variant_unref (response);
	return installed;
}
예제 #14
0
/**
 * pk_filter_bitfield_from_text:
 * @filters: the enumerated constant value, e.g. "available;~gui"
 *
 * Converts text representation to its enumerated type bitfield, or 0 for invalid
 *
 * Return value: The enumerated type values
 **/
PkBitfield
pk_filter_bitfield_from_text (const gchar *filters)
{
	PkBitfield filters_enum = 0;
	gchar **split;
	guint length;
	guint i;
	PkFilterEnum filter;

	split = g_strsplit (filters, ";", 0);
	if (split == NULL) {
		egg_warning ("unable to split");
		goto out;
	}

	length = g_strv_length (split);
	for (i=0; i<length; i++) {
		filter = pk_filter_enum_from_text (split[i]);
		if (filter == PK_FILTER_ENUM_UNKNOWN) {
			filters_enum = 0;
			break;
		}
		filters_enum += pk_bitfield_value (filter);
	}
out:
	g_strfreev (split);
	return filters_enum;
}
예제 #15
0
/**
 * pk_filter_bitfield_to_text:
 * @filters: The enumerated type values
 *
 * Converts a enumerated type bitfield to its text representation
 *
 * Return value: the enumerated constant value, e.g. "available;~gui"
 **/
gchar *
pk_filter_bitfield_to_text (PkBitfield filters)
{
	GString *string;
	guint i;

	/* shortcut */
	if (filters == 0)
		return g_strdup (pk_filter_enum_to_text (PK_FILTER_ENUM_NONE));

	string = g_string_new ("");
	for (i=0; i<PK_FILTER_ENUM_LAST; i++) {
		if ((filters & pk_bitfield_value (i)) == 0)
			continue;
		g_string_append_printf (string, "%s;", pk_filter_enum_to_text (i));
	}
	/* do we have a 'none' filter? \n */
	if (string->len == 0) {
		egg_warning ("not valid!");
		g_string_append (string, pk_filter_enum_to_text (PK_FILTER_ENUM_NONE));
	} else {
		/* remove last \n */
		g_string_set_size (string, string->len - 1);
	}
	return g_string_free (string, FALSE);
}
예제 #16
0
/**
 * pk_role_bitfield_from_text:
 * @roles: the enumerated constant value, e.g. "available;~gui"
 *
 * Converts text representation to its enumerated type bitfield
 *
 * Return value: The enumerated type values, or 0 for invalid
 **/
PkBitfield
pk_role_bitfield_from_text (const gchar *roles)
{
	PkBitfield roles_enum = 0;
	gchar **split;
	guint length;
	guint i;
	PkRoleEnum role;

	split = g_strsplit (roles, ";", 0);
	if (split == NULL) {
		egg_warning ("unable to split");
		goto out;
	}

	length = g_strv_length (split);
	for (i=0; i<length; i++) {
		role = pk_role_enum_from_text (split[i]);
		if (role == PK_ROLE_ENUM_UNKNOWN) {
			roles_enum = 0;
			break;
		}
		roles_enum += pk_bitfield_value (role);
	}
out:
	g_strfreev (split);
	return roles_enum;
}
/**
 * mcm_calibrate_dialog_set_image_filename_private:
 **/
static void
mcm_calibrate_dialog_set_image_filename_private (McmCalibrateDialog *calibrate_dialog, const gchar *image_filename)
{
	GtkWidget *widget;
	gchar *filename = NULL;
	GdkPixbuf *pixbuf;
	GError *error = NULL;
	McmCalibrateDialogPrivate *priv = calibrate_dialog->priv;

	/* set the image */
	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "image_generic"));
	if (image_filename != NULL) {
		filename = g_build_filename (MCM_DATA, "icons", image_filename, NULL);
		pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 200, 400, &error);
		if (pixbuf == NULL) {
			egg_warning ("failed to load image: %s", error->message);
			g_error_free (error);
			gtk_widget_hide (widget);
		} else {
			gtk_image_set_from_pixbuf (GTK_IMAGE (widget), pixbuf);
			gtk_widget_show (widget);
		}
		g_free (filename);
	} else {
		gtk_widget_hide (widget);
	}
}
static gboolean
gpm_applet_uninhibit (GpmInhibitApplet *applet,
		      guint            cookie)
{
	GError *error = NULL;
	gboolean ret;

	if (applet->proxy == NULL) {
		egg_warning ("not connected");
		return FALSE;
	}

	ret = dbus_g_proxy_call (applet->proxy, "Uninhibit", &error,
				 G_TYPE_UINT, cookie,
				 G_TYPE_INVALID,
				 G_TYPE_INVALID);
	if (error) {
		g_debug ("ERROR: %s", error->message);
		g_error_free (error);
	}
	if (!ret) {
		/* abort as the DBUS method failed */
		g_warning ("Uninhibit failed!");
	}

	return ret;
}
예제 #19
0
/**
 * pk_group_bitfield_from_text:
 * @groups: the enumerated constant value, e.g. "available;~gui"
 *
 * Converts text representation to its enumerated type bitfield
 *
 * Return value: The enumerated type values, or 0 for invalid
 **/
PkBitfield
pk_group_bitfield_from_text (const gchar *groups)
{
	PkBitfield groups_enum = 0;
	gchar **split;
	guint length;
	guint i;
	PkGroupEnum group;

	split = g_strsplit (groups, ";", 0);
	if (split == NULL) {
		egg_warning ("unable to split");
		goto out;
	}

	length = g_strv_length (split);
	for (i=0; i<length; i++) {
		group = pk_group_enum_from_text (split[i]);
		if (group == PK_GROUP_ENUM_UNKNOWN) {
			groups_enum = 0;
			break;
		}
		groups_enum += pk_bitfield_value (group);
	}
out:
	g_strfreev (split);
	return groups_enum;
}
예제 #20
0
파일: up-device.c 프로젝트: Kalvados/upower
/**
 * up_device_coldplug:
 *
 * Return %TRUE on success, %FALSE if we failed to get data and should be removed
 **/
gboolean
up_device_coldplug (UpDevice *device, UpDaemon *daemon, GObject *native)
{
	gboolean ret;
	const gchar *native_path;
	UpDeviceClass *klass = UP_DEVICE_GET_CLASS (device);
	gchar *id = NULL;

	g_return_val_if_fail (UP_IS_DEVICE (device), FALSE);

	/* save */
	device->priv->native = g_object_ref (native);
	device->priv->daemon = g_object_ref (daemon);

	native_path = up_native_get_native_path (native);
	device->priv->native_path = g_strdup (native_path);

	/* stop signals and callbacks */
	g_object_freeze_notify (G_OBJECT(device));
	device->priv->during_coldplug = TRUE;

	/* coldplug source */
	if (klass->coldplug != NULL) {
		ret = klass->coldplug (device);
		if (!ret) {
			egg_debug ("failed to coldplug %s", device->priv->native_path);
			goto out;
		}
	}

	/* only put on the bus if we succeeded */
	ret = up_device_register_device (device);
	if (!ret) {
		egg_warning ("failed to register device %s", device->priv->native_path);
		goto out;
	}

	/* force a refresh, although failure isn't fatal */
	ret = up_device_refresh_internal (device);
	if (!ret) {
		egg_debug ("failed to refresh %s", device->priv->native_path);

		/* TODO: refresh should really have seporate
		 *       success _and_ changed parameters */
		ret = TRUE;
		goto out;
	}

	/* get the id so we can load the old history */
	id = up_device_get_id (device);
	if (id != NULL)
		up_history_set_id (device->priv->history, id);

out:
	/* start signals and callbacks */
	g_object_thaw_notify (G_OBJECT(device));
	device->priv->during_coldplug = FALSE;
	g_free (id);
	return ret;
}
예제 #21
0
/**
 * gpk_prefs_update_combo_changed:
 **/
static void
gpk_prefs_update_combo_changed (GtkWidget *widget, gpointer data)
{
	gchar *value;
	const gchar *action;
	GpkUpdateEnum update = GPK_UPDATE_ENUM_UNKNOWN;
	GConfClient *client;

	client = gconf_client_get_default ();
	value = gtk_combo_box_get_active_text (GTK_COMBO_BOX (widget));
	if (value == NULL) {
		egg_warning ("value NULL");
		return;
	}
	if (strcmp (value, PK_UPDATE_ALL_TEXT) == 0) {
		update = GPK_UPDATE_ENUM_ALL;
	} else if (strcmp (value, PK_UPDATE_SECURITY_TEXT) == 0) {
		update = GPK_UPDATE_ENUM_SECURITY;
	} else if (strcmp (value, PK_UPDATE_NONE_TEXT) == 0) {
		update = GPK_UPDATE_ENUM_NONE;
	} else {
		g_assert (FALSE);
	}

	action = gpk_update_enum_to_text (update);
	egg_debug ("Changing %s to %s", GPK_CONF_AUTO_UPDATE, action);
	gconf_client_set_string (client, GPK_CONF_AUTO_UPDATE, action, NULL);
	g_free (value);
	g_object_unref (client);
}
예제 #22
0
/**
 * pk_strcmp_sections:
 * @id1: the first item of text to test
 * @id2: the second item of text to test
 * @parts: the number of parts each id should have
 * @compare: the leading number of parts to compare
 *
 * We only want to compare some first sections, not all the data when
 * comparing package_id's and transaction_id's.
 *
 * Return value: %TRUE if the strings can be considered the same.
 *
 **/
static gboolean
pk_strcmp_sections (const gchar *id1, const gchar *id2, guint parts, guint compare)
{
	gchar **sections1;
	gchar **sections2;
	gboolean ret = FALSE;
	guint i;

	if (id1 == NULL || id2 == NULL) {
		egg_warning ("package id compare invalid '%s' and '%s'", id1, id2);
		return FALSE;
	}
	if (compare > parts) {
		egg_warning ("compare %i > parts %i", compare, parts);
		return FALSE;
	}
	if (compare == parts) {
		return (g_strcmp0 (id1, id2) == 0);
	}

	/* split, NULL will be returned if error */
	sections1 = pk_strsplit (id1, parts);
	sections2 = pk_strsplit (id2, parts);

	/* check we split okay */
	if (sections1 == NULL) {
		egg_warning ("string id compare sections1 invalid '%s'", id1);
		goto out;
	}
	if (sections2 == NULL) {
		egg_warning ("string id compare sections2 invalid '%s'", id2);
		goto out;
	}

	/* only compare preceeding sections */
	for (i=0; i<compare; i++) {
		if (g_strcmp0 (sections1[i], sections2[i]) != 0) {
			goto out;
		}
	}
	ret = TRUE;

out:
	g_strfreev (sections1);
	g_strfreev (sections2);
	return ret;
}
예제 #23
0
/**
 * gpm_backlight_button_pressed_cb:
 * @power: The power class instance
 * @type: The button type, e.g. "power"
 * @state: The state, where TRUE is depressed or closed
 * @brightness: This class instance
 **/
static void
gpm_backlight_button_pressed_cb (GpmButton *button, const gchar *type, GpmBacklight *backlight)
{
	gboolean ret;
	GError *error = NULL;
	guint percentage;
	gboolean hw_changed;
	egg_debug ("Button press event type=%s", type);

	if (strcmp (type, GPM_BUTTON_BRIGHT_UP) == 0) {
		/* go up one step */
		ret = gpm_brightness_up (backlight->priv->brightness, &hw_changed);

		/* show the new value */
		if (ret) {
			gpm_brightness_get (backlight->priv->brightness, &percentage);
			gpm_backlight_dialog_init (backlight);
			gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (backlight->priv->popup),
								percentage);
			gpm_backlight_dialog_show (backlight);
			/* save the new percentage */
			backlight->priv->master_percentage = percentage;
		}
		/* we emit a signal for the brightness applet */
		if (ret && hw_changed) {
			egg_debug ("emitting brightness-changed : %i", percentage);
			g_signal_emit (backlight, signals [BRIGHTNESS_CHANGED], 0, percentage);
		}
	} else if (strcmp (type, GPM_BUTTON_BRIGHT_DOWN) == 0) {
		/* go up down step */
		ret = gpm_brightness_down (backlight->priv->brightness, &hw_changed);

		/* show the new value */
		if (ret) {
			gpm_brightness_get (backlight->priv->brightness, &percentage);
			gpm_backlight_dialog_init (backlight);
			gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (backlight->priv->popup),
								percentage);
			gpm_backlight_dialog_show (backlight);
			/* save the new percentage */
			backlight->priv->master_percentage = percentage;
		}
		/* we emit a signal for the brightness applet */
		if (ret && hw_changed) {
			egg_debug ("emitting brightness-changed : %i", percentage);
			g_signal_emit (backlight, signals [BRIGHTNESS_CHANGED], 0, percentage);
		}
	} else if (strcmp (type, GPM_BUTTON_LID_OPEN) == 0) {
		/* make sure we undim when we lift the lid */
		gpm_backlight_brightness_evaluate_and_set (backlight, FALSE);

		/* ensure backlight is on */
		ret = gpm_dpms_set_mode (backlight->priv->dpms, GPM_DPMS_MODE_ON, &error);
		if (!ret) {
			egg_warning ("failed to turn on DPMS: %s", error->message);
			g_error_free (error);
		}
	}
}
예제 #24
0
/**
 * mcm_profile_store_add_profile:
 **/
static gboolean
mcm_profile_store_add_profile (McmProfileStore *profile_store, GFile *file)
{
	gboolean ret = FALSE;
	McmProfile *profile = NULL;
	McmProfile *profile_tmp = NULL;
	GError *error = NULL;
	gchar *filename = NULL;
	const gchar *checksum;
	McmProfileStorePrivate *priv = profile_store->priv;

	/* already added? */
	filename = g_file_get_path (file);
	profile = mcm_profile_store_get_by_filename (profile_store, filename);
	if (profile != NULL)
		goto out;

	/* parse the profile name */
	profile = mcm_profile_default_new ();
	ret = mcm_profile_parse (profile, file, &error);
	if (!ret) {
		egg_warning ("failed to add profile '%s': %s", filename, error->message);
		g_error_free (error);
		goto out;		
	}

	/* check the profile has not been added already */
	checksum = mcm_profile_get_checksum (profile);
	profile_tmp = mcm_profile_store_get_by_checksum (profile_store, checksum);
	if (profile_tmp != NULL) {

		/* we value a local file higher than the shared file */
		if (mcm_profile_get_can_delete (profile_tmp)) {
			egg_debug ("already added a deletable profile %s, cannot add %s",
				   mcm_profile_get_filename (profile_tmp), filename);
			goto out;
		}

		/* remove the old profile in favour of the new one */
		mcm_profile_store_remove_profile (profile_store, profile_tmp);
	}

	/* add to array */
	egg_debug ("parsed new profile '%s'", filename);
	g_ptr_array_add (priv->profile_array, g_object_ref (profile));
	g_signal_connect (profile, "notify::filename", G_CALLBACK(mcm_profile_store_notify_filename_cb), profile_store);

	/* emit a signal */
	egg_debug ("emit added (and changed): %s", filename);
	g_signal_emit (profile_store, signals[SIGNAL_ADDED], 0, profile);
	g_signal_emit (profile_store, signals[SIGNAL_CHANGED], 0);
out:
	g_free (filename);
	if (profile_tmp != NULL)
		g_object_unref (profile_tmp);
	if (profile != NULL)
		g_object_unref (profile);
	return ret;
}
예제 #25
0
파일: pk-main.c 프로젝트: zodman/PackageKit
/**
 * pk_object_register:
 * @connection: What we want to register to
 * @object: The GObject we want to register
 *
 * Register org.freedesktop.PackageKit on the system bus.
 * This function MUST be called before DBUS service will work.
 *
 * Return value: success
 **/
G_GNUC_WARN_UNUSED_RESULT static gboolean
pk_object_register (DBusGConnection *connection, GObject *object, GError **error)
{
	DBusGProxy *bus_proxy = NULL;
	guint request_name_result;
	gboolean ret;
	gchar *message;

	bus_proxy = dbus_g_proxy_new_for_name (connection,
					       DBUS_SERVICE_DBUS,
					       DBUS_PATH_DBUS,
					       DBUS_INTERFACE_DBUS);

	ret = dbus_g_proxy_call (bus_proxy, "RequestName", error,
				 G_TYPE_STRING, PK_DBUS_SERVICE,
				 G_TYPE_UINT, 0,
				 G_TYPE_INVALID,
				 G_TYPE_UINT, &request_name_result,
				 G_TYPE_INVALID);

	/* free the bus_proxy */
	g_object_unref (G_OBJECT (bus_proxy));

	/* abort as the DBUS method failed */
	if (!ret) {
		egg_warning ("RequestName failed!");
		g_clear_error (error);
		message = g_strdup_printf ("%s\n%s\n* %s\n* %s '%s'\n",
					   /* TRANSLATORS: failed due to DBus security */
					   _("Startup failed due to security policies on this machine."),
					   /* TRANSLATORS: only two ways this can fail... */
					   _("This can happen for two reasons:"),
					   /* TRANSLATORS: only allowed to be owned by root */
					   _("The correct user is not launching the executable (usually root)"),
					   /* TRANSLATORS: or we are installed in a prefix */
					   _("The org.freedesktop.PackageKit.conf file is not "
					     "installed in the system directory:"),
					     "/etc/dbus-1/system.d");
		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_DENIED, "%s", message);
		g_free (message);
		return FALSE;
	}

	/* already running */
 	if (request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_DENIED,
			     "Already running on this machine");
		return FALSE;
	}

	dbus_g_object_type_install_info (PK_TYPE_ENGINE, &dbus_glib_pk_engine_object_info);
	dbus_g_error_domain_register (PK_ENGINE_ERROR, NULL, PK_ENGINE_TYPE_ERROR);
	dbus_g_error_domain_register (PK_TRANSACTION_ERROR, NULL, PK_TRANSACTION_TYPE_ERROR);
	dbus_g_connection_register_g_object (connection, PK_DBUS_PATH, object);

	return TRUE;
}
예제 #26
0
/**
 * mcm_dump_profile_filename:
 **/
static gboolean
mcm_dump_profile_filename (const gchar *filename)
{
	gboolean ret;
	GError *error = NULL;
	McmProfile *profile;
	guint profile_kind;
	guint colorspace;
	guint size;
	gboolean has_vcgt;
	const gchar *description;
	const gchar *copyright;
	const gchar *manufacturer;
	const gchar *model;
	const gchar *datetime;
	GFile *file = NULL;

	/* parse profile */
	profile = mcm_profile_default_new ();
	file = g_file_new_for_path (filename);
	ret = mcm_profile_parse (profile, file, &error);
	if (!ret) {
		egg_warning ("failed to parse: %s", error->message);
		g_error_free (error);
		goto out;
	}

	/* print what we know */
	profile_kind = mcm_profile_get_kind (profile);
	g_print ("Kind:\t%s\n", mcm_profile_kind_to_string (profile_kind));
	colorspace = mcm_profile_get_colorspace (profile);
	g_print ("Colorspace:\t%s\n", mcm_colorspace_to_string (colorspace));
	size = mcm_profile_get_size (profile);
	g_print ("Size:\t%i bytes\n", size);
	has_vcgt = mcm_profile_get_has_vcgt (profile);
	g_print ("Has VCGT:\t%s\n", has_vcgt ? "Yes" : "No");
	description = mcm_profile_get_description (profile);
	if (description != NULL)
		g_print ("Description:\t%s\n", description);
	copyright = mcm_profile_get_copyright (profile);
	if (copyright != NULL)
		g_print ("Copyright:\t%s\n", copyright);
	manufacturer = mcm_profile_get_manufacturer (profile);
	if (manufacturer != NULL)
		g_print ("Manufacturer:\t%s\n", manufacturer);
	model = mcm_profile_get_model (profile);
	if (model != NULL)
		g_print ("Model:\t%s\n", model);
	datetime = mcm_profile_get_datetime (profile);
	if (datetime != NULL)
		g_print ("Created:\t%s\n", datetime);
out:
	if (file != NULL)
		g_object_unref (file);
	g_object_unref (profile);
	return ret;
}
예제 #27
0
/**
 * gpk_package_entry_completion_model_new:
 *
 * Creates a tree model containing completions from the system package list
 **/
static GtkTreeModel *
gpk_package_entry_completion_model_new (void)
{
	GPtrArray *list;
	guint i;
	PkPackage *item;
	GHashTable *hash;
	gpointer data;
	GtkListStore *store;
	GtkTreeIter iter;
	gchar **split;

	store = gtk_list_store_new (1, G_TYPE_STRING);
	hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
	list = gpk_package_entry_completion_get_names_from_file (PK_SYSTEM_PACKAGE_LIST_FILENAME);
	if (list == NULL) {
		egg_warning ("no package list, try refreshing");
		return NULL;
	}

	egg_debug ("loading %i autocomplete items", list->len);
	for (i=0; i<list->len; i++) {
		item = g_ptr_array_index (list, i);
		if (item == NULL || pk_package_get_id (item) == NULL) {
			egg_warning ("item invalid!");
			break;
		}

		split = pk_package_id_split (pk_package_get_id (item));
		data = g_hash_table_lookup (hash, (gpointer) split[PK_PACKAGE_ID_NAME]);
		if (data == NULL) {
			/* append just the name */
			g_hash_table_insert (hash, g_strdup (split[PK_PACKAGE_ID_NAME]), GINT_TO_POINTER (1));
			gtk_list_store_append (store, &iter);
			gtk_list_store_set (store, &iter, 0, split[PK_PACKAGE_ID_NAME], -1);
		}
		g_strfreev (split);
	}
	g_hash_table_unref (hash);
	g_ptr_array_unref (list);

	return GTK_TREE_MODEL (store);
}
예제 #28
0
/**
 * pk_task_list_get_item:
 **/
PkTaskListItem *
pk_task_list_get_item (PkTaskList *tlist, guint item)
{
	g_return_val_if_fail (PK_IS_TASK_LIST (tlist), NULL);
	if (item >= tlist->priv->task_list->len) {
		egg_warning ("item too large!");
		return NULL;
	}
	return g_ptr_array_index (tlist->priv->task_list, item);
}
예제 #29
0
/**
 * ai_generate_create_icon_directories:
 **/
static gboolean
ai_generate_create_icon_directories (const gchar *directory)
{
	gboolean ret;
	GError *error = NULL;
	GFile *file;
	gchar *path;
	guint i;

	/* create main directory */
	ret = g_file_test (directory, G_FILE_TEST_IS_DIR);
	if (!ret) {
		file = g_file_new_for_path (directory);
		ret = g_file_make_directory (file, NULL, &error);
		g_object_unref (file);
		if (!ret) {
			egg_warning ("cannot create %s: %s", directory, error->message);
			g_error_free (error);
			goto out;
		}
	}

	/* make sub directories */
	for (i=0; icon_sizes[i] != NULL; i++) {
		path = g_build_filename (directory, icon_sizes[i], NULL);
		ret = g_file_test (path, G_FILE_TEST_IS_DIR);
		if (!ret) {
			egg_debug ("creating %s", path);
			file = g_file_new_for_path (path);
			ret = g_file_make_directory (file, NULL, &error);
			if (!ret) {
				egg_warning ("cannot create %s: %s", path, error->message);
				g_clear_error (&error);
			}
			g_object_unref (file);
		}
		g_free (path);
	}
out:
	return ret;
}
예제 #30
0
/**
 * ai_generate_copy_icons:
 **/
static gboolean
ai_generate_copy_icons (const gchar *root, const gchar *directory, const gchar *icon_name)
{
	gboolean ret;
	GError *error = NULL;
	GFile *file;
	GFile *remote;
	gchar *dest;
	gchar *iconpath;
	gchar *icon_name_full;
	guint i;
	gboolean found_any_icons = FALSE;

	egg_debug ("looking for %s", icon_name);

	/* copy all icon sizes if they exist */
	for (i=0; icon_sizes[i] != NULL; i++) {

		/* get the icon name */
		if (g_strstr_len (icon_name, -1, ".") != NULL)
			icon_name_full = g_strdup (icon_name);
		else if (g_strcmp0 (icon_sizes[i], "scalable") == 0)
			icon_name_full = g_strdup_printf ("%s.svg", icon_name);
		else
			icon_name_full = g_strdup_printf ("%s.png", icon_name);

		/* build the icon path */
		iconpath = g_build_filename (root, ICONS_DIR, "hicolor", icon_sizes[i], "apps", icon_name_full, NULL);
		ret = g_file_test (iconpath, G_FILE_TEST_EXISTS);
		if (ret) {
			dest = g_build_filename (directory, icon_sizes[i], icon_name_full, NULL);
			egg_debug ("copying file %s to %s", iconpath, dest);
			file = g_file_new_for_path (iconpath);
			remote = g_file_new_for_path (dest);
			ret = g_file_copy (file, remote, G_FILE_COPY_TARGET_DEFAULT_PERMS | G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error);
			if (!ret) {
				egg_warning ("cannot copy %s: %s", dest, error->message);
				g_clear_error (&error);
			}
			/* success */
			found_any_icons = TRUE;
			g_object_unref (file);
			g_object_unref (remote);
			g_free (dest);
		} else {
			egg_debug ("does not exist: %s, so not copying", iconpath);
		}
		g_free (iconpath);
		g_free (icon_name_full);
	}

	return found_any_icons;
}