Exemplo n.º 1
0
gboolean
dnd_is_screensaver_active ()
{
	GError  *error = NULL;
	gboolean active = FALSE;;

	if (! get_screensaver_proxy ())
		return FALSE;

	dbus_g_proxy_call_with_timeout (
		gscrsvr, "GetActive", 2000, &error,
		G_TYPE_INVALID,
		G_TYPE_BOOLEAN, &active,
		G_TYPE_INVALID);

	if (error)
	{
		g_warning ("dnd_is_screensaver_active(): Got error \"%s\"\n",
		           error->message);
		g_error_free (error);
		error = NULL;
	}

	if (active)
		g_debug ("Gnome screensaver is active");

	return active;
}
Exemplo n.º 2
0
void
gsm_consolekit_attempt_stop (GsmConsolekit *manager)
{
        gboolean res;
        GError  *error;

        error = NULL;

        if (!gsm_consolekit_ensure_ck_connection (manager, &error)) {
                g_warning ("Could not connect to ConsoleKit: %s",
                           error->message);
                emit_stop_complete (manager, error);
                g_error_free (error);
                return;
        }

        res = dbus_g_proxy_call_with_timeout (manager->priv->ck_proxy,
                                              "Stop",
                                              INT_MAX,
                                              &error,
                                              G_TYPE_INVALID,
                                              G_TYPE_INVALID);

        if (!res) {
                g_warning ("Unable to stop system: %s", error->message);
                emit_stop_complete (manager, error);
                g_error_free (error);
        } else {
                emit_stop_complete (manager, NULL);
        }
}
Exemplo n.º 3
0
gboolean
gsm_consolekit_can_stop (GsmConsolekit *manager)
{
        gboolean res;
	gboolean can_stop;
        GError  *error;

        error = NULL;

        if (!gsm_consolekit_ensure_ck_connection (manager, &error)) {
                g_warning ("Could not connect to ConsoleKit: %s",
                           error->message);
                g_error_free (error);
                return FALSE;
        }

        res = dbus_g_proxy_call_with_timeout (manager->priv->ck_proxy,
                                              "CanStop",
                                              INT_MAX,
                                              &error,
                                              G_TYPE_INVALID,
                                              G_TYPE_BOOLEAN, &can_stop,
                                              G_TYPE_INVALID);

        if (res == FALSE) {
                g_warning ("Could not make DBUS call: %s",
                           error->message);
                g_error_free (error);
                return FALSE;
	}

	return can_stop;
}
Exemplo n.º 4
0
/* Calls AL Run method: runs an appl. with given appName */
static gint call_AL_run_app(gchar * appName){
	GError * error = NULL;
	gint al_reply_pid;
	gboolean method_call_status;
	int r = 0;
	
	assert(appName);

	method_call_status =dbus_g_proxy_call_with_timeout(get_AL_proxy(), "Run", REPLY_TIMEOUT, &error,
			G_TYPE_STRING, appName,
			G_TYPE_INT, 0,
			G_TYPE_BOOLEAN, TRUE,
			G_TYPE_INVALID,
			G_TYPE_INT, &al_reply_pid,
			G_TYPE_INVALID);
	if (!method_call_status || error){
		log_error_message("Could not call AL Run method!\n%s\n", (error ? error->message : ""));
		g_error_free(error);
		error = NULL;
		r = 1;
	}

	log_message("called AL Run with: %s, True ; reply-pid: %d\n", appName, al_reply_pid);

	return r;
}
Exemplo n.º 5
0
gboolean
dnd_is_idle_inhibited ()
{
	GError  *error = NULL;
	gboolean inhibited = FALSE;
	guint idle = 8; // 8: Inhibit the session being marked as idle

	if (! get_gnomesession_proxy ())
		return FALSE;

	dbus_g_proxy_call_with_timeout (
		gsmgr, "IsInhibited", 2000, &error,
		G_TYPE_UINT, idle,
		G_TYPE_INVALID,
		G_TYPE_BOOLEAN, &inhibited,
		G_TYPE_INVALID);

	if (error)
	{
		g_warning ("dnd_is_idle_inhibited(): "
		           "got error \"%s\"\n",
		           error->message);
		g_error_free (error);
		error = NULL;
	}

	if (inhibited)
		g_debug ("Session idleness has been inhibited");

	return inhibited;
}
Exemplo n.º 6
0
/* Gets pid for an appl. giving its dbus-path */
static guint get_pid_from_app_path(const gchar * inPath){
	DBusGProxy * lPropProxy = NULL;
	GValue lServicePidV = {0};
	guint lServicePid = 0;
	GError * lError = NULL;

	assert(inPath);
	if (!g_conn){
		g_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &lError);
		if (!g_conn || lError){
			log_error_message("Could not obtain dbus connection!\n%s\n", (lError ? lError->message : ""));
			g_error_free(lError);
			lError = NULL;
			goto res_free;
		}
	}

	/* Get a proxy to systemd Properties */
	lPropProxy = dbus_g_proxy_new_for_name(g_conn,
			SYSD_SERVICE_NAME,       //systemd service name
			inPath,                  //service path
			SYSD_INTERFACE_PROP);    //systemd properties interface
	if (NULL == lPropProxy){
		log_error_message("Failed to get Properties proxy!\n", 0);
		goto res_free;
	}

	/* Call Get method of dbus Properties interface
	   Find out Service ControlGroups list. */
	if (!dbus_g_proxy_call_with_timeout(lPropProxy,
				"Get",
				REPLY_TIMEOUT,
				&lError,
				G_TYPE_STRING,
				SYSD_INTERFACE_SERVICE,   //systemd Service interface
				G_TYPE_STRING,
				"ExecMainPID",                   //look for property
				G_TYPE_INVALID,
				G_TYPE_VALUE,
				&lServicePidV,                   //property value
				G_TYPE_INVALID)){
		log_error_message("Method call failed: %s\n", lError->message);
		g_error_free(lError);
		goto res_free;
	}

	log_debug_message("[%s] Got GValue, taking guint...\n", __func__);
	lServicePid = g_value_get_uint(&lServicePidV);
	log_debug_message("[%s] Got pid=%u\n", __func__, lServicePid);


res_free:
	if (lPropProxy){
		g_object_unref(lPropProxy);
		lPropProxy = NULL;
	}

	return lServicePid;
}
Exemplo n.º 7
0
int moonshot_get_identity (const char     *nai,
                           const char     *password,
                           const char     *service,
                           char          **nai_out,
                           char          **password_out,
                           char          **server_certificate_hash_out,
                           char          **ca_certificate_out,
                           char          **subject_name_constraint_out,
                           char          **subject_alt_name_constraint_out,
                           MoonshotError **error)
{
    GError     *g_error = NULL;
    DBusGProxy *dbus_proxy;
    int         success;

    dbus_proxy = get_dbus_proxy (error);

    if (*error != NULL)
        return FALSE;

    g_return_val_if_fail (DBUS_IS_G_PROXY (dbus_proxy), FALSE);

    dbus_g_proxy_call_with_timeout (dbus_proxy,
                       "GetIdentity",
				    INFINITE_TIMEOUT,
				    &g_error,
                       G_TYPE_STRING, nai,
                       G_TYPE_STRING, password,
                       G_TYPE_STRING, service,
                       G_TYPE_INVALID,
                       G_TYPE_STRING, nai_out,
                       G_TYPE_STRING, password_out,
                       G_TYPE_STRING, server_certificate_hash_out,
                       G_TYPE_STRING, ca_certificate_out,
                       G_TYPE_STRING, subject_name_constraint_out,
                       G_TYPE_STRING, subject_alt_name_constraint_out,
                       G_TYPE_BOOLEAN, &success,
                       G_TYPE_INVALID);

    g_object_unref (dbus_proxy);

    if (g_error != NULL) {
        *error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR,
                                     g_error->message);
        return FALSE;
    }

    if (success == FALSE) {
        *error = moonshot_error_new (MOONSHOT_ERROR_NO_IDENTITY_SELECTED,
                                     "No identity was returned by the Moonshot "
                                     "user interface.");
        return FALSE;
    }

    return TRUE;
}
Exemplo n.º 8
0
void
get_audacious_info(struct TrackInfo* ti)
{
	static DBusGProxy *proxy = 0;
	GError *error = 0;
	char *status = 0;
	int pos = 0;

        ti->status = PLAYER_STATUS_CLOSED;

	if (!dbus_g_running("org.atheme.audacious")) {
		return;
	}

        if (!proxy)
          {
            proxy = dbus_g_proxy_new_for_name (connection,
                                               "org.atheme.audacious",
                                               "/org/atheme/audacious",
                                               "org.atheme.audacious");
          }

	if (!dbus_g_proxy_call_with_timeout(proxy, "Status", DBUS_TIMEOUT, &error,
				G_TYPE_INVALID,
				G_TYPE_STRING, &status,
				G_TYPE_INVALID))
	{
		trace("Failed to make dbus call: %s", error->message);
		return;
	}

        ti->player = "Audacious";

	if (strcmp(status, "stopped") == 0) {
		ti->status = PLAYER_STATUS_STOPPED;
		return;
	} else if (strcmp(status, "playing") == 0) {
		ti->status = PLAYER_STATUS_PLAYING;
	} else {
		ti->status = PLAYER_STATUS_PAUSED;
	}

	// Find the position in the playlist
	pos = audacious_dbus_uint(proxy, "Position");

	ti->currentSecs = audacious_dbus_uint(proxy, "Time")/1000;
	ti->totalSecs = audacious_dbus_int(proxy, "SongLength", pos);

	audacious_dbus_string(proxy, "SongTuple", pos, "artist", ti->artist);
	audacious_dbus_string(proxy, "SongTuple", pos, "album", ti->album);
	audacious_dbus_string(proxy, "SongTuple", pos, "title", ti->track);
}
Exemplo n.º 9
0
static void
get_permissions_sync (BMClient *self)
{
	gboolean success;
	GHashTable *permissions = NULL;

	success = dbus_g_proxy_call_with_timeout (BM_CLIENT_GET_PRIVATE (self)->client_proxy,
	                                          "GetPermissions", 3000, NULL,
	                                          G_TYPE_INVALID,
	                                          DBUS_TYPE_G_MAP_OF_STRING, &permissions, G_TYPE_INVALID);
	update_permissions (self, success ? permissions : NULL);
	if (permissions)
		g_hash_table_destroy (permissions);
}
Exemplo n.º 10
0
unsigned int banshee_dbus_uint(DBusGProxy *proxy, const char *method)
{
	unsigned int ret;
	GError *error = 0;
	if (!dbus_g_proxy_call_with_timeout (proxy, method, DBUS_TIMEOUT, &error,
				G_TYPE_INVALID,
				G_TYPE_UINT, &ret,
				G_TYPE_INVALID))
	{
		trace("Failed to make dbus call %s: %s", method, error->message);
		return 0;
	}

	return ret;
}
Exemplo n.º 11
0
int audacious_dbus_int(DBusGProxy *proxy, const char *method, int pos)
{
	int ret;
	GError *error = 0;
	if (!dbus_g_proxy_call_with_timeout(proxy, method, DBUS_TIMEOUT, &error,
				G_TYPE_UINT,pos,
				G_TYPE_INVALID,
				G_TYPE_INT, &ret,
				G_TYPE_INVALID))
	{
		trace("Failed to make dbus call %s: %s", method, error->message);
		return 0;
	}

	return ret;
}
Exemplo n.º 12
0
static gboolean
mm_alive (DBusGProxy *proxy)
{
	char *owner = NULL;
	gboolean owned = FALSE;
	GError *error = NULL;

	if (dbus_g_proxy_call_with_timeout (proxy,
	                                    "GetNameOwner", 2000, &error,
	                                    G_TYPE_STRING, MM_DBUS_SERVICE,
	                                    G_TYPE_INVALID,
	                                    G_TYPE_STRING, &owner,
	                                    G_TYPE_INVALID)) {
		owned = !!owner;
		g_free (owner);
	}
	return owned;
}
Exemplo n.º 13
0
gboolean banshee_dbus_string(DBusGProxy *proxy, const char *method, char* dest)
{
	char *str = 0;
	GError *error = 0;
	if (!dbus_g_proxy_call_with_timeout (proxy, method, DBUS_TIMEOUT, &error,
				G_TYPE_INVALID,
				G_TYPE_STRING, &str,
				G_TYPE_INVALID))
	{
		trace("Failed to make dbus call %s: %s", method, error->message);
		return FALSE;
	}

	assert(str);
	strncpy(dest, str, STRLEN);
	dest[STRLEN-1] = 0;
	g_free(str);
	return TRUE;
}
Exemplo n.º 14
0
/* Calls AL Restart method: restarts appl. with given appName */
static gint call_AL_restart_app(gchar * appName){
	GError * error = NULL;
	gboolean al_reply_bool;
	guint al_reply_uint;
	gboolean method_call_status;
	int r = 0;

	method_call_status =dbus_g_proxy_call_with_timeout(get_AL_proxy(), "Restart", REPLY_TIMEOUT, &error,
			G_TYPE_STRING, appName,
			G_TYPE_INVALID,
			G_TYPE_INVALID);
	if (!method_call_status || error){
		log_error_message("Could not call AL Restart method!\n%s\n", (error ? error->message : ""));
		g_error_free(error);
		error = NULL;
		r = 1;
	}

        log_message("called AL Restart with: %s, reply: %s, %u\n", appName, (al_reply_bool ? "true" : "false"), al_reply_uint);

	return r;
}
Exemplo n.º 15
0
/* Calls AL Stop method: stops appl. with given pid */
static gint call_AL_stop_app(guint pid){
	GError * error = NULL;
	gboolean al_reply_bool;
	guint al_reply_uint;
	gboolean method_call_status;
	int r = 0;

	method_call_status =dbus_g_proxy_call_with_timeout(get_AL_proxy(), "Stop", REPLY_TIMEOUT, &error,
			G_TYPE_INT, pid,
			G_TYPE_INVALID,
			G_TYPE_INVALID);
	if (!method_call_status || error){
		log_error_message("Could not call AL Stop method!\n%s\n", (error ? error->message : ""));
		g_error_free(error);
		error = NULL;
		r = 1;
	}

        log_message("called AL Stop with %u, reply: %s, %u\n", pid, (al_reply_bool ? "true" : "false"), al_reply_uint);

	return r;
}
Exemplo n.º 16
0
char *
nm_dbus_manager_get_name_owner (NMDBusManager *self,
                                const char *name,
                                GError **error)
{
	char *owner = NULL;

	g_return_val_if_fail (NM_IS_DBUS_MANAGER (self), NULL);
	g_return_val_if_fail (name != NULL, NULL);
	if (error)
		g_return_val_if_fail (*error == NULL, NULL);

	if (!dbus_g_proxy_call_with_timeout (NM_DBUS_MANAGER_GET_PRIVATE (self)->proxy,
	                                     "GetNameOwner", 2000, error,
	                                     G_TYPE_STRING, name,
	                                     G_TYPE_INVALID,
	                                     G_TYPE_STRING, &owner,
	                                     G_TYPE_INVALID)) {
		return NULL;
	}

	return owner;
}
Exemplo n.º 17
0
gboolean audacious_dbus_string(DBusGProxy *proxy, const char *method, int pos, const char *arg, char* dest)
{
	GValue val;
	memset(&val, 0, sizeof(GValue));
	GError *error = 0;
	if (!dbus_g_proxy_call_with_timeout(proxy, method, DBUS_TIMEOUT, &error,
				G_TYPE_UINT, pos,
				G_TYPE_STRING, arg,
				G_TYPE_INVALID,
				G_TYPE_VALUE, &val,
				G_TYPE_INVALID))
	{
		trace("Failed to make dbus call %s: %s", method, error->message);
		return FALSE;
	}

	if (G_VALUE_TYPE(&val) == G_TYPE_STRING) {
		strncpy(dest, g_value_get_string(&val), STRLEN);
		dest[STRLEN-1] = 0;
	}
	g_value_unset(&val);
	return TRUE;
}
Exemplo n.º 18
0
/* Calls AL Run method to reboot system */
static gint call_AL_reboot_system(){
	GError * error = NULL;
	gint al_reply_pid;
	gboolean method_call_status;
	int r = 0;

	method_call_status =dbus_g_proxy_call_with_timeout(get_AL_proxy(), "Run", REPLY_TIMEOUT, &error,
			G_TYPE_STRING, "reboot 0s",
			G_TYPE_INT, 0,
			G_TYPE_BOOLEAN, TRUE,
			G_TYPE_INVALID,
			G_TYPE_INT, &al_reply_pid,
			G_TYPE_INVALID);
	if (!method_call_status || error){
		log_error_message("Could not call AL Run method to reboot in 0s!\n%s\n", (error ? error->message : ""));
		g_error_free(error);
		error = NULL;
		r = 1;
	}

	log_message("called AL Run with 'reboot 0s', True ; reply:%d\n", al_reply_pid);

	return r;
}
Exemplo n.º 19
0
gboolean
get_exaile_info(struct TrackInfo* ti)
{
	DBusGConnection *connection;
	DBusGProxy *proxy;
	GError *error = 0;
	char buf[STRLEN], status[STRLEN];

	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
	if (connection == NULL) {
		trace("Failed to open connection to dbus: %s\n", error->message);
		g_error_free (error);
		return FALSE;
	}

	if (!dbus_g_running(connection, "org.exaile.DBusInterface")) {
		ti->status = STATUS_OFF;
		return TRUE;
	}

	proxy = dbus_g_proxy_new_for_name (connection,
			"org.exaile.DBusInterface",
			"/DBusInterfaceObject",
			"org.exaile.DBusInterface");

	// We should be using "status" instead of "query" here, but its broken in
	// the current (0.2.6) Exaile version
	if (!exaile_dbus_query(proxy, "query", buf)) {
		trace("Failed to call Exaile dbus method. Assuming player is OFF");
		ti->status = STATUS_OFF;
		return TRUE;
	}

	if (sscanf(buf, "status: %s", status) == 1) {
		if (!strcmp(status, "playing"))
			ti->status = STATUS_NORMAL;
		else
			ti->status = STATUS_PAUSED;
	} else {
		ti->status = STATUS_OFF;
	}

	if (ti->status != STATUS_OFF) {
		int mins, secs;
		exaile_dbus_query(proxy, "get_artist", ti->artist);
		exaile_dbus_query(proxy, "get_album", ti->album);
		exaile_dbus_query(proxy, "get_title", ti->track);

		exaile_dbus_query(proxy, "get_length", buf);
		if (sscanf(buf, "%d:%d", &mins, &secs)) {
			ti->totalSecs = mins*60 + secs;	
		}

		error = 0;
		unsigned char percentage;
		if (!dbus_g_proxy_call_with_timeout(proxy, "current_position", DBUS_TIMEOUT, &error,
					G_TYPE_INVALID,
					G_TYPE_UCHAR, &percentage,
					G_TYPE_INVALID))
		{
			trace("Failed to make dbus call: %s", error->message);
		}
                trace("exaile_dbus_query: 'current_position' => %d", percentage);
		ti->currentSecs = percentage*ti->totalSecs/100;
	}
	return TRUE;
}
Exemplo n.º 20
0
static gboolean
get_modem_properties (DBusGConnection *connection,
					  const char *path,
					  char **device,
					  char **data_device,
					  char **driver,
					  guint32 *type,
					  guint32 *ip_method)
{
	DBusGProxy *proxy;
	GValue value = { 0 };
	GError *err = NULL;

	proxy = dbus_g_proxy_new_for_name (connection,
									   MM_DBUS_SERVICE,
									   path,
									   "org.freedesktop.DBus.Properties");

	if (dbus_g_proxy_call_with_timeout (proxy, "Get", 15000, &err,
	                                    G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM,
	                                    G_TYPE_STRING, "Type",
	                                    G_TYPE_INVALID,
	                                    G_TYPE_VALUE, &value,
	                                    G_TYPE_INVALID)) {
		*type = g_value_get_uint (&value);
		g_value_unset (&value);
	} else {
		nm_log_warn (LOGD_MB, "could not get device type: %s", err->message);
		goto out;
	}

	if (dbus_g_proxy_call_with_timeout (proxy, "Get", 15000, &err,
	                                    G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM,
	                                    G_TYPE_STRING, "MasterDevice",
	                                    G_TYPE_INVALID,
	                                    G_TYPE_VALUE, &value,
	                                    G_TYPE_INVALID)) {
		*device = g_value_dup_string (&value);
		g_value_unset (&value);
	} else {
		nm_log_warn (LOGD_MB, "could not get device: %s", err->message);
		goto out;
	}

	if (dbus_g_proxy_call_with_timeout (proxy, "Get", 15000, &err,
										G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM,
										G_TYPE_STRING, "IpMethod",
										G_TYPE_INVALID,
										G_TYPE_VALUE, &value,
										G_TYPE_INVALID)) {
		*ip_method = g_value_get_uint (&value);
		g_value_unset (&value);
	} else {
		nm_log_warn (LOGD_MB, "could not get IP method: %s", err->message);
		goto out;
	}

	if (dbus_g_proxy_call_with_timeout (proxy, "Get", 15000, &err,
										G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM,
										G_TYPE_STRING, "Device",
										G_TYPE_INVALID,
										G_TYPE_VALUE, &value,
										G_TYPE_INVALID)) {
		*data_device = g_value_dup_string (&value);
		g_value_unset (&value);
	} else {
		nm_log_warn (LOGD_MB, "could not get modem data device: %s", err->message);
		goto out;
	}

	if (dbus_g_proxy_call_with_timeout (proxy, "Get", 15000, &err,
										G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM,
										G_TYPE_STRING, "Driver",
										G_TYPE_INVALID,
										G_TYPE_VALUE, &value,
										G_TYPE_INVALID)) {
		*driver = g_value_dup_string (&value);
		g_value_unset (&value);
	} else {
		nm_log_warn (LOGD_MB, "could not get modem driver: %s", err->message);
		goto out;
	}

 out:
	if (err)
		g_error_free (err);

	g_object_unref (proxy);

	return *data_device && *driver;
}
Exemplo n.º 21
0
void
get_banshee_info(struct TrackInfo* ti)
{
	GError *error = 0;
	int status;
	char szStatus[STRLEN];

	if (dbus_g_running("org.gnome.Banshee")) {
                static DBusGProxy *proxy = 0;

                if (!proxy)
                  {
                    proxy = dbus_g_proxy_new_for_name (connection,
                                                       "org.gnome.Banshee",
                                                       "/org/gnome/Banshee/Player",
                                                       "org.gnome.Banshee.Core");
                  }

		if (!dbus_g_proxy_call_with_timeout (proxy, "GetPlayingStatus", DBUS_TIMEOUT, &error,
					G_TYPE_INVALID,
					G_TYPE_INT, &status,
					G_TYPE_INVALID))
		{
			trace("Failed to make dbus call: %s", error->message);
			return;
		}

		if (status == -1) {
			ti->status = PLAYER_STATUS_STOPPED;
			return;
		} else if (status == 1)
			ti->status = PLAYER_STATUS_PLAYING;
		else
			ti->status = PLAYER_STATUS_PAUSED;

		banshee_dbus_string(proxy, "GetPlayingArtist", ti->artist);
		banshee_dbus_string(proxy, "GetPlayingAlbum", ti->album);
		banshee_dbus_string(proxy, "GetPlayingTitle", ti->track);

		ti->totalSecs = banshee_dbus_int(proxy, "GetPlayingDuration");
		ti->currentSecs = banshee_dbus_int(proxy, "GetPlayingPosition");
		return;
	} else if (dbus_g_running("org.bansheeproject.Banshee")) { // provide for new interface in banshee 1.0
                static DBusGProxy *proxy = 0;
                if (!proxy)
                  {
                    proxy = dbus_g_proxy_new_for_name (connection,
                                                       "org.bansheeproject.Banshee",
                                                       "/org/bansheeproject/Banshee/PlayerEngine",
                                                       "org.bansheeproject.Banshee.PlayerEngine");
                  }

		banshee_dbus_string(proxy, "GetCurrentState", szStatus);
		if (strcmp(szStatus, "idle") == 0) {
			ti->status = PLAYER_STATUS_STOPPED;
			return;
		} else if (strcmp(szStatus, "playing") == 0)
			ti->status = PLAYER_STATUS_PLAYING;
		else
			ti->status = PLAYER_STATUS_PAUSED;

		GHashTable* table;
		if (!dbus_g_proxy_call_with_timeout (proxy, "GetCurrentTrack", DBUS_TIMEOUT, &error,
					G_TYPE_INVALID,
					dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &table,
					G_TYPE_INVALID))
		{
			trace("Failed to make dbus call: %s", error->message);
			return;
		}

		banshee_hash_str(table, "album", ti->album);
		banshee_hash_str(table, "artist", ti->artist);
		banshee_hash_str(table, "name", ti->track);

		g_hash_table_destroy(table);

		ti->totalSecs = banshee_dbus_uint(proxy, "GetLength") / 1000;
		ti->currentSecs = banshee_dbus_uint(proxy, "GetPosition") / 1000;
		return;
	}

        ti->status = PLAYER_STATUS_CLOSED;
}
Exemplo n.º 22
0
static gboolean
get_rhythmbox_info(gpointer data) {
  if (!enable) return FALSE;

  DBusGProxy *player = NULL;
  DBusGProxy *shell = NULL;
  GError *error = NULL;

  if (!conn) {
    conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
    if (error) g_error_free(error);
    if (!conn) return FALSE;
  }

  if (!proxy) {
    proxy = dbus_g_proxy_new_for_name(
        conn,
        "org.freedesktop.DBus",
        "/org/freedesktop/DBus",
        "org.freedesktop.DBus");
    if (error) g_error_free(error);
    if (!proxy) return FALSE;
  }

  gboolean exists = FALSE;
  if (dbus_g_proxy_call_with_timeout(
        proxy,
        "NameHasOwner",
        5000,
        &error,
        G_TYPE_STRING,
        "org.gnome.Rhythmbox",
        G_TYPE_INVALID,
        G_TYPE_BOOLEAN,
        &exists,
        G_TYPE_INVALID)) {
    if (error) g_error_free(error);
    if (!exists) return TRUE;
  }

  if (!shell) {
    shell = dbus_g_proxy_new_for_name(
        conn,
        "org.gnome.Rhythmbox",
        "/org/gnome/Rhythmbox/Shell",
        "org.gnome.Rhythmbox.Shell");
  }

  if (!player) {
    player = dbus_g_proxy_new_for_name(
        conn,
        "org.gnome.Rhythmbox",
        "/org/gnome/Rhythmbox/Player",
        "org.gnome.Rhythmbox.Player");
  }

  gboolean playing;
  if (!dbus_g_proxy_call_with_timeout(
        player,
        "getPlaying",
        5000,
        &error,
        G_TYPE_INVALID,
        G_TYPE_BOOLEAN,
        &playing,
        G_TYPE_INVALID)) {
    if (error) g_error_free(error);
    if (!playing) return TRUE;
  }

  char *uri;
  if (!dbus_g_proxy_call_with_timeout(
        player
        , "getPlayingUri",
        5000,
        &error,
        G_TYPE_INVALID,
        G_TYPE_STRING,
        &uri,
        G_TYPE_INVALID)) {
    if (error) g_error_free(error);
    return TRUE;
  }

  GHashTable *table;
  if (!dbus_g_proxy_call_with_timeout(
        shell,
        "getSongProperties",
        5000,
        &error,
        G_TYPE_STRING,
        uri,
        G_TYPE_INVALID,
        dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
        &table,
        G_TYPE_INVALID)) {
    if (error) g_error_free(error);
    return TRUE;
  }
  g_free(uri);

  GValue* value;
  gchar* title;
  gchar* artist;
  gchar* album;
  
  value = (GValue*) g_hash_table_lookup(table, "rb:stream-song-title");
  if (value != NULL && G_VALUE_HOLDS_STRING(value)) {
    title = g_strdup(g_value_get_string(value));
  } else {
    value = (GValue*) g_hash_table_lookup(table, "title");
    if (value != NULL && G_VALUE_HOLDS_STRING(value)) {
      title = g_strdup(g_value_get_string(value));
    }
  }
  value = (GValue*) g_hash_table_lookup(table, "artist");
  if (value != NULL && G_VALUE_HOLDS_STRING(value)) {
    artist = g_strdup(g_value_get_string(value));
  }
  value = (GValue*) g_hash_table_lookup(table, "album");
  if (value != NULL && G_VALUE_HOLDS_STRING(value)) {
    album = g_strdup(g_value_get_string(value));
  }

  g_hash_table_destroy(table);

  if (title && artist && album &&
          (!last_title  || strcmp(last_title, title)) &&
          (!last_artist || strcmp(last_artist, artist)) &&
          (!last_album  || strcmp(last_album, album))) {
    NOTIFICATION_INFO* ni = g_new0(NOTIFICATION_INFO, 1);
    ni->title = g_strdup(title);
    ni->text = g_strdup_printf("%s\n%s", album, artist);
    ni->icon = get_album_art(artist, album);
    g_timeout_add(10, delay_show, ni);

    if (last_title) g_free(last_title);
    if (last_artist) g_free(last_artist);
    if (last_album) g_free(last_album);
    last_title = title;
    last_artist = artist;
    last_album = album;
  } else {
    if (title) g_free(title);
    if (artist) g_free(artist);
    if (album) g_free(album);
  }

  return TRUE;
}