clang-format the project

This commit is contained in:
Tony Crisci
2018-09-26 10:36:54 -04:00
parent a3694bfa79
commit 2e3b24f36e
6 changed files with 972 additions and 973 deletions

11
.clang-format Normal file
View File

@@ -0,0 +1,11 @@
BasedOnStyle: google
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortBlocksOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: false
IndentWidth: 4
PointerBindsToType: false
ColumnLimit: 100
SpaceBeforeParens: ControlStatements
IndentCaseLabels: false

View File

@@ -1,5 +1,4 @@
/* vim:ts=2:sw=2:expandtab
*
/*
* This file is part of playerctl.
*
* playerctl is free software: you can redistribute it and/or modify it under
@@ -18,12 +17,12 @@
* Copyright © 2014 - 2016, Tony Crisci and contributors.
*/
#include "playerctl.h"
#include <stdlib.h>
#include <stdio.h>
#include <gio/gio.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "playerctl.h"
#define LENGTH(array) (sizeof array / sizeof array[0])
@@ -40,32 +39,20 @@ static gboolean print_version_and_exit;
/* The commands passed on the command line, filled in via G_OPTION_REMAINING. */
static gchar **command = NULL;
static GString *list_player_names_on_bus(GError **err, GBusType busType)
{
static GString *list_player_names_on_bus(GError **err, GBusType busType) {
GError *tmp_error = NULL;
GDBusProxy *proxy = g_dbus_proxy_new_for_bus_sync(
busType,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
NULL,
&tmp_error);
busType, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.DBus",
"/org/freedesktop/DBus", "org.freedesktop.DBus", NULL, &tmp_error);
if (tmp_error != NULL) {
g_propagate_error(err, tmp_error);
return NULL;
}
GVariant *reply = g_dbus_proxy_call_sync(proxy,
"ListNames",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&tmp_error);
GVariant *reply = g_dbus_proxy_call_sync(
proxy, "ListNames", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &tmp_error);
if (tmp_error != NULL) {
g_propagate_error(err, tmp_error);
@@ -110,7 +97,6 @@ static gchar *list_player_names(GError **err) {
return g_string_free(sessionPlayers, FALSE);
}
#define PLAYER_COMMAND_FUNC(COMMAND) \
GError *tmp_error = NULL; \
\
@@ -121,45 +107,47 @@ static gchar *list_player_names(GError **err) {
} \
return TRUE;
static gboolean play (PlayerctlPlayer *player, gchar **arguments, GError **error)
{
static gboolean play(PlayerctlPlayer *player, gchar **arguments,
GError **error) {
PLAYER_COMMAND_FUNC(play);
}
/* Pause is defined in unistd.h */
static gboolean paus (PlayerctlPlayer *player, gchar **arguments, GError **error)
{
static gboolean paus(PlayerctlPlayer *player, gchar **arguments,
GError **error) {
PLAYER_COMMAND_FUNC(pause);
}
static gboolean play_pause (PlayerctlPlayer *player, gchar **arguments, GError **error)
{
static gboolean play_pause(PlayerctlPlayer *player, gchar **arguments,
GError **error) {
PLAYER_COMMAND_FUNC(play_pause);
}
static gboolean stop (PlayerctlPlayer *player, gchar **arguments, GError **error)
{
static gboolean stop(PlayerctlPlayer *player, gchar **arguments,
GError **error) {
PLAYER_COMMAND_FUNC(stop);
}
static gboolean next (PlayerctlPlayer *player, gchar **arguments, GError **error)
{
static gboolean next(PlayerctlPlayer *player, gchar **arguments,
GError **error) {
PLAYER_COMMAND_FUNC(next);
}
static gboolean previous (PlayerctlPlayer *player, gchar **arguments, GError **error)
{
static gboolean previous(PlayerctlPlayer *player, gchar **arguments,
GError **error) {
PLAYER_COMMAND_FUNC(previous);
}
#undef PLAYER_COMMAND_FUNC
static gboolean open (PlayerctlPlayer *player, gchar **arguments, GError **error)
{
static gboolean open(PlayerctlPlayer *player, gchar **arguments,
GError **error) {
const gchar *uri = *arguments;
GError *tmp_error = NULL;
if (uri) {
playerctl_player_open(player, g_file_get_uri(g_file_new_for_commandline_arg(uri)), &tmp_error);
playerctl_player_open(player,
g_file_get_uri(g_file_new_for_commandline_arg(uri)),
&tmp_error);
if (tmp_error != NULL) {
g_propagate_error(error, tmp_error);
return FALSE;
@@ -168,8 +156,8 @@ static gboolean open (PlayerctlPlayer *player, gchar **arguments, GError **error
return TRUE;
}
static gboolean position (PlayerctlPlayer *player, gchar **arguments, GError **error)
{
static gboolean position(PlayerctlPlayer *player, gchar **arguments,
GError **error) {
const gchar *position = *arguments;
gint64 offset;
GError *tmp_error = NULL;
@@ -179,7 +167,8 @@ static gboolean position (PlayerctlPlayer *player, gchar **arguments, GError **e
offset = 1000000.0 * strtod(position, &endptr);
if (position == endptr) {
g_set_error(error, playerctl_cli_error_quark (), 1, "Could not parse position as a number: %s\n", position);
g_set_error(error, playerctl_cli_error_quark(), 1,
"Could not parse position as a number: %s\n", position);
return FALSE;
}
@@ -209,8 +198,8 @@ static gboolean position (PlayerctlPlayer *player, gchar **arguments, GError **e
return TRUE;
}
static gboolean set_or_get_volume (PlayerctlPlayer *player, gchar **arguments, GError **error)
{
static gboolean set_or_get_volume(PlayerctlPlayer *player, gchar **arguments,
GError **error) {
const gchar *volume = *arguments;
gdouble level;
@@ -222,7 +211,8 @@ static gboolean set_or_get_volume (PlayerctlPlayer *player, gchar **arguments, G
gdouble adjustment = strtod(volume, &endptr);
if (volume == endptr) {
g_set_error(error, playerctl_cli_error_quark (), 1, "Could not parse volume as a number: %s\n", volume);
g_set_error(error, playerctl_cli_error_quark(), 1,
"Could not parse volume as a number: %s\n", volume);
return FALSE;
}
@@ -235,10 +225,10 @@ static gboolean set_or_get_volume (PlayerctlPlayer *player, gchar **arguments, G
} else {
level = strtod(volume, &endptr);
if (volume == endptr) {
g_set_error(error, playerctl_cli_error_quark (), 1, "Could not parse volume as a number: %s\n", volume);
g_set_error(error, playerctl_cli_error_quark(), 1,
"Could not parse volume as a number: %s\n", volume);
return FALSE;
}
}
g_object_set(player, "volume", level, NULL);
} else {
@@ -249,8 +239,8 @@ static gboolean set_or_get_volume (PlayerctlPlayer *player, gchar **arguments, G
return TRUE;
}
static gboolean status (PlayerctlPlayer *player, gchar **arguments, GError **error)
{
static gboolean status(PlayerctlPlayer *player, gchar **arguments,
GError **error) {
gchar *state = NULL;
g_object_get(player, "status", &state, NULL);
@@ -260,8 +250,8 @@ static gboolean status (PlayerctlPlayer *player, gchar **arguments, GError **err
return TRUE;
}
static gboolean get_metadata (PlayerctlPlayer *player, gchar **arguments, GError **error)
{
static gboolean get_metadata(PlayerctlPlayer *player, gchar **arguments,
GError **error) {
const gchar *type = *arguments;
GError *tmp_error = NULL;
gchar *data;
@@ -303,48 +293,61 @@ struct PlayerCommand {
{"metadata", &get_metadata},
};
static gboolean handle_player_command (PlayerctlPlayer *player, gchar **command, GError **error)
{
static gboolean handle_player_command(PlayerctlPlayer *player, gchar **command,
GError **error) {
for (int i = 0; i < LENGTH(commands); i++) {
if (g_strcmp0(commands[i].name, command[0]) == 0) {
// Do not pass the command's name to the function that processes it.
return commands[i].func(player, command + 1, error);
}
}
g_set_error(error, playerctl_cli_error_quark (), 1, "Command not recognized: %s", command[0]);
g_set_error(error, playerctl_cli_error_quark(), 1,
"Command not recognized: %s", command[0]);
return FALSE;
}
static const GOptionEntry entries[] = {
{"player", 'p', G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &player_name_list,
"A comma separated list of names of players to control (default: the first available player)", "NAME" },
{ "all-players", 'a', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &select_all_players,
"Select all available players to be controlled", NULL },
{ "list-all", 'l', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &list_all_players_and_exit,
"A comma separated list of names of players to control (default: the "
"first available player)",
"NAME"},
{"all-players", 'a', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE,
&select_all_players, "Select all available players to be controlled",
NULL},
{"list-all", 'l', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE,
&list_all_players_and_exit,
"List the names of running players that can be controlled and exit", NULL},
{ "version", 'v', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &print_version_and_exit,
"Print version information and exit", NULL },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &command, NULL, "COMMAND" },
{ NULL }
};
{"version", 'v', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE,
&print_version_and_exit, "Print version information and exit", NULL},
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &command, NULL,
"COMMAND"},
{NULL}};
static gboolean parse_setup_options (int argc, char *argv[], GError **error)
{
static const gchar *description = "Available Commands:"
static gboolean parse_setup_options(int argc, char *argv[], GError **error) {
static const gchar *description =
"Available Commands:"
"\n open [URI] Command for the player to open given URI."
"\n URI can be either file path or remote URL with mandatory scheme, like http://..."
"\n URI can be either file path or remote URL "
"with mandatory scheme, like http://..."
"\n play Command the player to play"
"\n pause Command the player to pause"
"\n play-pause Command the player to toggle between play/pause"
"\n play-pause Command the player to toggle between "
"play/pause"
"\n stop Command the player to stop"
"\n next Command the player to skip to the next track"
"\n previous Command the player to skip to the previous track"
"\n position [OFFSET][+/-] Command the player to go to the position or seek forward/backward OFFSET in seconds"
"\n volume [LEVEL][+/-] Print or set the volume to LEVEL from 0.0 to 1.0"
"\n previous Command the player to skip to the previous "
"track"
"\n position [OFFSET][+/-] Command the player to go to the position or "
"seek forward/backward OFFSET in seconds"
"\n volume [LEVEL][+/-] Print or set the volume to LEVEL from 0.0 "
"to 1.0"
"\n status Get the play status of the player"
"\n metadata [KEY] Print metadata information for the current track. If KEY is passed,"
"\n print only that value. KEY may be one of artist, title or album";
static const gchar *summary = " Only for players supporting the MPRIS D-Bus specification";
"\n metadata [KEY] Print metadata information for the current "
"track. If KEY is passed,"
"\n print only that value. KEY may be one of "
"artist, title or album";
static const gchar *summary =
" Only for players supporting the MPRIS D-Bus specification";
GOptionContext *context = NULL;
gboolean success;
@@ -360,9 +363,11 @@ static gboolean parse_setup_options (int argc, char *argv[], GError **error)
return FALSE;
}
if (command == NULL && !print_version_and_exit && !list_all_players_and_exit) {
if (command == NULL && !print_version_and_exit &&
!list_all_players_and_exit) {
gchar *help = g_option_context_get_help(context, TRUE, NULL);
g_set_error (error, playerctl_cli_error_quark(), 1, "No command entered\n\n%s", help);
g_set_error(error, playerctl_cli_error_quark(), 1,
"No command entered\n\n%s", help);
g_option_context_free(context);
g_free(help);
return FALSE;
@@ -372,8 +377,7 @@ static gboolean parse_setup_options (int argc, char *argv[], GError **error)
return TRUE;
}
int main (int argc, char *argv[])
{
int main(int argc, char *argv[]) {
PlayerctlPlayer *player;
GError *error = NULL;
int exit_status = 0;
@@ -461,4 +465,3 @@ end:
return exit_status;
}

View File

@@ -1,5 +1,4 @@
/* vim:ts=2:sw=2:expandtab
*
/*
* This file is part of playerctl.
*
* playerctl is free software: you can redistribute it and/or modify it under
@@ -18,12 +17,12 @@
* Copyright © 2014 - 2016, Tony Crisci and contributors.
*/
#include <string.h>
#include <gio/gio.h>
#include <glib-object.h>
#include <string.h>
#include "playerctl-player.h"
#include "playerctl-generated.h"
#include "playerctl-player.h"
#include <stdint.h>
@@ -49,12 +48,13 @@ enum {
LAST_SIGNAL
};
static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
static GParamSpec *obj_properties[N_PROPERTIES] = {
NULL,
};
static guint connection_signals[LAST_SIGNAL] = {0};
struct _PlayerctlPlayerPrivate
{
struct _PlayerctlPlayerPrivate {
OrgMprisMediaPlayer2Player *proxy;
gchar *player_name;
gchar *bus_name;
@@ -63,12 +63,15 @@ struct _PlayerctlPlayerPrivate
GVariant *metadata;
};
static void playerctl_player_properties_changed_callback (GDBusProxy *_proxy, GVariant *changed_properties, const gchar *const *invalidated_properties, gpointer user_data)
{
static void playerctl_player_properties_changed_callback(
GDBusProxy *_proxy, GVariant *changed_properties,
const gchar *const *invalidated_properties, gpointer user_data) {
PlayerctlPlayer *self = user_data;
GVariant *metadata = g_variant_lookup_value(changed_properties, "Metadata", NULL);
GVariant *playback_status = g_variant_lookup_value(changed_properties, "PlaybackStatus", NULL);
GVariant *metadata =
g_variant_lookup_value(changed_properties, "Metadata", NULL);
GVariant *playback_status =
g_variant_lookup_value(changed_properties, "PlaybackStatus", NULL);
if (metadata) {
g_signal_emit(self, connection_signals[METADATA], 0, metadata);
@@ -96,12 +99,14 @@ static void playerctl_player_properties_changed_callback (GDBusProxy *_proxy, GV
static void playerctl_player_initable_iface_init(GInitableIface *iface);
G_DEFINE_TYPE_WITH_CODE(PlayerctlPlayer, playerctl_player, G_TYPE_OBJECT,
G_ADD_PRIVATE(PlayerctlPlayer) G_IMPLEMENT_INTERFACE(G_TYPE_INITABLE, playerctl_player_initable_iface_init));
G_ADD_PRIVATE(PlayerctlPlayer) G_IMPLEMENT_INTERFACE(
G_TYPE_INITABLE,
playerctl_player_initable_iface_init));
G_DEFINE_QUARK(playerctl-player-error-quark, playerctl_player_error);
static GVariant *playerctl_player_get_metadata(PlayerctlPlayer *self, GError **err)
{
static GVariant *playerctl_player_get_metadata(PlayerctlPlayer *self,
GError **err) {
GVariant *metadata;
GError *tmp_error = NULL;
@@ -111,15 +116,10 @@ static GVariant *playerctl_player_get_metadata(PlayerctlPlayer *self, GError **e
if (!metadata) {
// XXX: Ugly spotify workaround. Spotify does not seem to use the property
// cache. We have to get the properties directly.
GVariant *call_reply = g_dbus_proxy_call_sync (G_DBUS_PROXY(self->priv->proxy),
"org.freedesktop.DBus.Properties.Get",
g_variant_new ("(ss)",
"org.mpris.MediaPlayer2.Player",
"Metadata"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&tmp_error);
GVariant *call_reply = g_dbus_proxy_call_sync(
G_DBUS_PROXY(self->priv->proxy), "org.freedesktop.DBus.Properties.Get",
g_variant_new("(ss)", "org.mpris.MediaPlayer2.Player", "Metadata"),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &tmp_error);
if (tmp_error != NULL) {
g_propagate_error(err, tmp_error);
@@ -137,18 +137,20 @@ static GVariant *playerctl_player_get_metadata(PlayerctlPlayer *self, GError **e
return metadata;
}
static void playerctl_player_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) {
static void playerctl_player_set_property(GObject *object, guint property_id,
const GValue *value,
GParamSpec *pspec) {
PlayerctlPlayer *self = PLAYERCTL_PLAYER(object);
switch (property_id)
{
switch (property_id) {
case PROP_PLAYER_NAME:
g_free(self->priv->player_name);
self->priv->player_name = g_strdup(g_value_get_string(value));
break;
case PROP_VOLUME:
org_mpris_media_player2_player_set_volume(self->priv->proxy, g_value_get_double(value));
org_mpris_media_player2_player_set_volume(self->priv->proxy,
g_value_get_double(value));
break;
default:
@@ -157,11 +159,11 @@ static void playerctl_player_set_property(GObject *object, guint property_id, co
}
}
static void playerctl_player_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) {
static void playerctl_player_get_property(GObject *object, guint property_id,
GValue *value, GParamSpec *pspec) {
PlayerctlPlayer *self = PLAYERCTL_PLAYER(object);
switch (property_id)
{
switch (property_id) {
case PROP_PLAYER_NAME:
g_value_set_string(value, self->priv->player_name);
break;
@@ -169,14 +171,15 @@ static void playerctl_player_get_property(GObject *object, guint property_id, GV
case PROP_STATUS:
if (self->priv->proxy) {
g_main_context_iteration(NULL, FALSE);
g_value_set_string(value, org_mpris_media_player2_player_get_playback_status(self->priv->proxy));
g_value_set_string(value,
org_mpris_media_player2_player_get_playback_status(
self->priv->proxy));
} else {
g_value_set_string(value, "");
}
break;
case PROP_METADATA:
{
case PROP_METADATA: {
GVariant *metadata = NULL;
if (self->priv->proxy)
@@ -193,7 +196,8 @@ static void playerctl_player_get_property(GObject *object, guint property_id, GV
case PROP_VOLUME:
if (self->priv->proxy) {
g_main_context_iteration(NULL, FALSE);
g_value_set_double(value, org_mpris_media_player2_player_get_volume(self->priv->proxy));
g_value_set_double(value, org_mpris_media_player2_player_get_volume(
self->priv->proxy));
} else {
g_value_set_double(value, 0);
}
@@ -205,25 +209,25 @@ static void playerctl_player_get_property(GObject *object, guint property_id, GV
// connection is made so we have to call the method directly here or it
// won't work.
GError *tmp_error = NULL;
GVariant *call_reply = g_dbus_proxy_call_sync (G_DBUS_PROXY(self->priv->proxy),
GVariant *call_reply = g_dbus_proxy_call_sync(
G_DBUS_PROXY(self->priv->proxy),
"org.freedesktop.DBus.Properties.Get",
g_variant_new ("(ss)",
"org.mpris.MediaPlayer2.Player",
"Position"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&tmp_error);
g_variant_new("(ss)", "org.mpris.MediaPlayer2.Player", "Position"),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &tmp_error);
if (tmp_error) {
g_warning("Get position property failed. Using cache. (%s)", tmp_error->message);
gint64 cached_position = org_mpris_media_player2_player_get_position(self->priv->proxy);
g_warning("Get position property failed. Using cache. (%s)",
tmp_error->message);
gint64 cached_position =
org_mpris_media_player2_player_get_position(self->priv->proxy);
g_value_set_int64(value, cached_position);
break;
}
GVariant *call_reply_properties = g_variant_get_child_value(call_reply, 0);
GVariant *call_reply_unboxed = g_variant_get_variant(call_reply_properties);
GVariant *call_reply_properties =
g_variant_get_child_value(call_reply, 0);
GVariant *call_reply_unboxed =
g_variant_get_variant(call_reply_properties);
gint64 position = g_variant_get_int64(call_reply_unboxed);
g_value_set_int64(value, position);
@@ -242,8 +246,7 @@ static void playerctl_player_get_property(GObject *object, guint property_id, GV
}
}
static void playerctl_player_constructed(GObject *gobject)
{
static void playerctl_player_constructed(GObject *gobject) {
PlayerctlPlayer *self = PLAYERCTL_PLAYER(gobject);
self->priv->init_error = NULL;
@@ -253,8 +256,7 @@ static void playerctl_player_constructed(GObject *gobject)
G_OBJECT_CLASS(playerctl_player_parent_class)->constructed(gobject);
}
static void playerctl_player_dispose(GObject *gobject)
{
static void playerctl_player_dispose(GObject *gobject) {
PlayerctlPlayer *self = PLAYERCTL_PLAYER(gobject);
g_clear_error(&self->priv->init_error);
@@ -263,8 +265,7 @@ static void playerctl_player_dispose(GObject *gobject)
G_OBJECT_CLASS(playerctl_player_parent_class)->dispose(gobject);
}
static void playerctl_player_finalize(GObject *gobject)
{
static void playerctl_player_finalize(GObject *gobject) {
PlayerctlPlayer *self = PLAYERCTL_PLAYER(gobject);
g_free(self->priv->player_name);
@@ -282,47 +283,32 @@ static void playerctl_player_class_init (PlayerctlPlayerClass *klass) {
gobject_class->dispose = playerctl_player_dispose;
gobject_class->finalize = playerctl_player_finalize;
obj_properties[PROP_PLAYER_NAME] =
g_param_spec_string("player-name",
"Player name",
"The name of the player mpris player",
obj_properties[PROP_PLAYER_NAME] = g_param_spec_string(
"player-name", "Player name", "The name of the player mpris player",
NULL, /* default */
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
obj_properties[PROP_STATUS] =
g_param_spec_string("status",
"Player status",
"The play status of the player",
NULL, /* default */
g_param_spec_string("status", "Player status",
"The play status of the player", NULL, /* default */
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_properties[PROP_VOLUME] =
g_param_spec_double("volume",
"Player volume",
"The volume level of the player",
0,
100,
0,
obj_properties[PROP_VOLUME] = g_param_spec_double(
"volume", "Player volume", "The volume level of the player", 0, 100, 0,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
obj_properties[PROP_POSITION] =
g_param_spec_int64("position",
"Player position",
"The position in the current track of the player",
0,
INT64_MAX,
0,
obj_properties[PROP_POSITION] = g_param_spec_int64(
"position", "Player position",
"The position in the current track of the player", 0, INT64_MAX, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_properties[PROP_METADATA] =
g_param_spec_variant("metadata",
"Player metadata",
"The metadata of the currently playing track",
G_VARIANT_TYPE_VARIANT,
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_properties[PROP_METADATA] = g_param_spec_variant(
"metadata", "Player metadata",
"The metadata of the currently playing track", G_VARIANT_TYPE_VARIANT,
NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties(gobject_class, N_PROPERTIES, obj_properties);
g_object_class_install_properties(gobject_class, N_PROPERTIES,
obj_properties);
#if 0
/* not implemented yet */
@@ -339,8 +325,8 @@ static void playerctl_player_class_init (PlayerctlPlayerClass *klass) {
G_TYPE_VARIANT);
#endif
connection_signals[PLAY] = g_signal_new(
"play", /* signal_name */
connection_signals[PLAY] =
g_signal_new("play", /* signal_name */
PLAYERCTL_TYPE_PLAYER, /* itype */
G_SIGNAL_RUN_FIRST, /* signal_flags */
0, /* class_offset */
@@ -350,8 +336,8 @@ static void playerctl_player_class_init (PlayerctlPlayerClass *klass) {
G_TYPE_NONE, /* return_type */
0); /* n_params */
connection_signals[PAUSE] = g_signal_new(
"pause", /* signal_name */
connection_signals[PAUSE] =
g_signal_new("pause", /* signal_name */
PLAYERCTL_TYPE_PLAYER, /* itype */
G_SIGNAL_RUN_FIRST, /* signal_flags */
0, /* class_offset */
@@ -361,8 +347,8 @@ static void playerctl_player_class_init (PlayerctlPlayerClass *klass) {
G_TYPE_NONE, /* return_type */
0); /* n_params */
connection_signals[STOP] = g_signal_new(
"stop", /* signal_name */
connection_signals[STOP] =
g_signal_new("stop", /* signal_name */
PLAYERCTL_TYPE_PLAYER, /* itype */
G_SIGNAL_RUN_FIRST, /* signal_flags */
0, /* class_offset */
@@ -372,8 +358,8 @@ static void playerctl_player_class_init (PlayerctlPlayerClass *klass) {
G_TYPE_NONE, /* return_type */
0); /* n_params */
connection_signals[METADATA] = g_signal_new(
"metadata", /* signal_name */
connection_signals[METADATA] =
g_signal_new("metadata", /* signal_name */
PLAYERCTL_TYPE_PLAYER, /* itype */
G_SIGNAL_RUN_FIRST, /* signal_flags */
0, /* class_offset */
@@ -384,8 +370,8 @@ static void playerctl_player_class_init (PlayerctlPlayerClass *klass) {
1, /* n_params */
G_TYPE_VARIANT);
connection_signals[EXIT] = g_signal_new(
"exit", /* signal_name */
connection_signals[EXIT] =
g_signal_new("exit", /* signal_name */
PLAYERCTL_TYPE_PLAYER, /* itype */
G_SIGNAL_RUN_FIRST, /* signal_flags */
0, /* class_offset */
@@ -396,13 +382,12 @@ static void playerctl_player_class_init (PlayerctlPlayerClass *klass) {
0); /* n_params */
}
static void playerctl_player_init (PlayerctlPlayer *self)
{
static void playerctl_player_init(PlayerctlPlayer *self) {
self->priv = playerctl_player_get_instance_private(self);
}
static gchar *playerctl_player_get_bus_name(PlayerctlPlayer *self, GError **err, GBusType busType)
{
static gchar *playerctl_player_get_bus_name(PlayerctlPlayer *self, GError **err,
GBusType busType) {
gchar *bus_name = NULL;
GError *tmp_error = NULL;
@@ -413,31 +398,21 @@ static gchar *playerctl_player_get_bus_name(PlayerctlPlayer *self, GError **err,
}
if (self->priv->player_name != NULL) {
return g_strjoin(".", "org.mpris.MediaPlayer2", self->priv->player_name, NULL);
return g_strjoin(".", "org.mpris.MediaPlayer2", self->priv->player_name,
NULL);
}
GDBusProxy *proxy = g_dbus_proxy_new_for_bus_sync(
busType,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
NULL,
&tmp_error);
busType, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.DBus",
"/org/freedesktop/DBus", "org.freedesktop.DBus", NULL, &tmp_error);
if (tmp_error != NULL) {
g_propagate_error(err, tmp_error);
return NULL;
}
GVariant *reply = g_dbus_proxy_call_sync(proxy,
"ListNames",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&tmp_error);
GVariant *reply = g_dbus_proxy_call_sync(
proxy, "ListNames", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &tmp_error);
if (tmp_error != NULL) {
g_propagate_error(err, tmp_error);
@@ -462,7 +437,8 @@ static gchar *playerctl_player_get_bus_name(PlayerctlPlayer *self, GError **err,
g_free(names);
if (bus_name == NULL) {
tmp_error = g_error_new(playerctl_player_error_quark(), 1, "No players found");
tmp_error =
g_error_new(playerctl_player_error_quark(), 1, "No players found");
g_propagate_error(err, tmp_error);
return NULL;
}
@@ -470,8 +446,9 @@ static gchar *playerctl_player_get_bus_name(PlayerctlPlayer *self, GError **err,
return bus_name;
}
static gboolean playerctl_player_initable_init(GInitable *initable, GCancellable *cancellable, GError **err)
{
static gboolean playerctl_player_initable_init(GInitable *initable,
GCancellable *cancellable,
GError **err) {
GError *tmp_error = NULL;
PlayerctlPlayer *player = PLAYERCTL_PLAYER(initable);
GBusType busType = G_BUS_TYPE_SESSION;
@@ -481,11 +458,13 @@ static gboolean playerctl_player_initable_init(GInitable *initable, GCancellable
g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
player->priv->bus_name = playerctl_player_get_bus_name(player, &tmp_error, busType);
player->priv->bus_name =
playerctl_player_get_bus_name(player, &tmp_error, busType);
if (tmp_error) {
g_clear_error(&tmp_error);
busType = G_BUS_TYPE_SYSTEM;
player->priv->bus_name = playerctl_player_get_bus_name(player, &tmp_error, busType);
player->priv->bus_name =
playerctl_player_get_bus_name(player, &tmp_error, busType);
}
if (tmp_error != NULL) {
@@ -500,26 +479,23 @@ static gboolean playerctl_player_initable_init(GInitable *initable, GCancellable
}
player->priv->proxy = org_mpris_media_player2_player_proxy_new_for_bus_sync(
busType,
G_DBUS_PROXY_FLAGS_NONE,
player->priv->bus_name,
"/org/mpris/MediaPlayer2",
NULL,
&tmp_error);
busType, G_DBUS_PROXY_FLAGS_NONE, player->priv->bus_name,
"/org/mpris/MediaPlayer2", NULL, &tmp_error);
if (tmp_error != NULL) {
g_propagate_error(err, tmp_error);
return FALSE;
}
g_signal_connect(player->priv->proxy, "g-properties-changed", G_CALLBACK(playerctl_player_properties_changed_callback), player);
g_signal_connect(player->priv->proxy, "g-properties-changed",
G_CALLBACK(playerctl_player_properties_changed_callback),
player);
player->priv->initted = TRUE;
return TRUE;
}
static void playerctl_player_initable_iface_init(GInitableIface *iface)
{
static void playerctl_player_initable_iface_init(GInitableIface *iface) {
iface->init = playerctl_player_initable_init;
}
@@ -534,12 +510,12 @@ static void playerctl_player_initable_iface_init(GInitableIface *iface)
* Returns:(transfer full): A new #PlayerctlPlayer connected to the bus name or
* NULL if an error occurred
*/
PlayerctlPlayer *playerctl_player_new(const gchar *name, GError **err)
{
PlayerctlPlayer *playerctl_player_new(const gchar *name, GError **err) {
GError *tmp_error = NULL;
PlayerctlPlayer *player;
player = g_initable_new(PLAYERCTL_TYPE_PLAYER, NULL, &tmp_error, "player-name", name, NULL);
player = g_initable_new(PLAYERCTL_TYPE_PLAYER, NULL, &tmp_error,
"player-name", name, NULL);
if (tmp_error != NULL) {
g_propagate_error(err, tmp_error);
@@ -558,8 +534,8 @@ PlayerctlPlayer *playerctl_player_new(const gchar *name, GError **err)
*
* Returns: (transfer none): the #PlayerctlPlayer for chaining
*/
PlayerctlPlayer *playerctl_player_on(PlayerctlPlayer *self, const gchar *event, GClosure *callback, GError **err)
{
PlayerctlPlayer *playerctl_player_on(PlayerctlPlayer *self, const gchar *event,
GClosure *callback, GError **err) {
g_return_val_if_fail(self != NULL, NULL);
g_return_val_if_fail(event != NULL, NULL);
g_return_val_if_fail(callback != NULL, NULL);
@@ -589,7 +565,8 @@ PlayerctlPlayer *playerctl_player_on(PlayerctlPlayer *self, const gchar *event,
return self; \
} \
\
org_mpris_media_player2_player_call_##COMMAND##_sync(self->priv->proxy, NULL, &tmp_error); \
org_mpris_media_player2_player_call_##COMMAND##_sync(self->priv->proxy, \
NULL, &tmp_error); \
\
if (tmp_error != NULL) { \
g_propagate_error(err, tmp_error); \
@@ -606,8 +583,8 @@ PlayerctlPlayer *playerctl_player_on(PlayerctlPlayer *self, const gchar *event,
*
* Returns: (transfer none): the #PlayerctlPlayer for chaining
*/
PlayerctlPlayer *playerctl_player_play_pause(PlayerctlPlayer *self, GError **err)
{
PlayerctlPlayer *playerctl_player_play_pause(PlayerctlPlayer *self,
GError **err) {
PLAYER_COMMAND_FUNC(play_pause);
}
@@ -620,8 +597,8 @@ PlayerctlPlayer *playerctl_player_play_pause(PlayerctlPlayer *self, GError **err
*
* Returns: (transfer none): the #PlayerctlPlayer for chaining
*/
PlayerctlPlayer *playerctl_player_open(PlayerctlPlayer *self, gchar *uri, GError **err)
{
PlayerctlPlayer *playerctl_player_open(PlayerctlPlayer *self, gchar *uri,
GError **err) {
GError *tmp_error = NULL;
g_return_val_if_fail(self != NULL, NULL);
@@ -631,7 +608,8 @@ PlayerctlPlayer *playerctl_player_open(PlayerctlPlayer *self, gchar *uri, GError
g_propagate_error(err, g_error_copy(self->priv->init_error));
return self;
}
org_mpris_media_player2_player_call_open_uri_sync(self->priv->proxy, uri, NULL, &tmp_error);
org_mpris_media_player2_player_call_open_uri_sync(self->priv->proxy, uri,
NULL, &tmp_error);
if (tmp_error != NULL) {
g_propagate_error(err, tmp_error);
@@ -650,8 +628,7 @@ PlayerctlPlayer *playerctl_player_open(PlayerctlPlayer *self, gchar *uri, GError
*
* Returns: (transfer none): the #PlayerctlPlayer for chaining
*/
PlayerctlPlayer *playerctl_player_play(PlayerctlPlayer *self, GError **err)
{
PlayerctlPlayer *playerctl_player_play(PlayerctlPlayer *self, GError **err) {
PLAYER_COMMAND_FUNC(play);
}
@@ -664,8 +641,7 @@ PlayerctlPlayer *playerctl_player_play(PlayerctlPlayer *self, GError **err)
*
* Returns: (transfer none): the #PlayerctlPlayer for chaining
*/
PlayerctlPlayer *playerctl_player_pause(PlayerctlPlayer *self, GError **err)
{
PlayerctlPlayer *playerctl_player_pause(PlayerctlPlayer *self, GError **err) {
PLAYER_COMMAND_FUNC(pause);
}
@@ -678,8 +654,7 @@ PlayerctlPlayer *playerctl_player_pause(PlayerctlPlayer *self, GError **err)
*
* Returns: (transfer none): the #PlayerctlPlayer for chaining
*/
PlayerctlPlayer *playerctl_player_stop(PlayerctlPlayer *self, GError **err)
{
PlayerctlPlayer *playerctl_player_stop(PlayerctlPlayer *self, GError **err) {
PLAYER_COMMAND_FUNC(stop);
}
@@ -692,8 +667,8 @@ PlayerctlPlayer *playerctl_player_stop(PlayerctlPlayer *self, GError **err)
*
* Returns: (transfer none): the #PlayerctlPlayer for chaining
*/
PlayerctlPlayer *playerctl_player_seek(PlayerctlPlayer *self, gint64 offset, GError **err)
{
PlayerctlPlayer *playerctl_player_seek(PlayerctlPlayer *self, gint64 offset,
GError **err) {
GError *tmp_error = NULL;
g_return_val_if_fail(self != NULL, NULL);
@@ -704,7 +679,8 @@ PlayerctlPlayer *playerctl_player_seek(PlayerctlPlayer *self, gint64 offset, GEr
return self;
}
org_mpris_media_player2_player_call_seek_sync(self->priv->proxy, offset, NULL, &tmp_error);
org_mpris_media_player2_player_call_seek_sync(self->priv->proxy, offset, NULL,
&tmp_error);
if (tmp_error != NULL) {
g_propagate_error(err, tmp_error);
@@ -723,8 +699,7 @@ PlayerctlPlayer *playerctl_player_seek(PlayerctlPlayer *self, gint64 offset, GEr
*
* Returns: (transfer none): the #PlayerctlPlayer for chaining
*/
PlayerctlPlayer *playerctl_player_next(PlayerctlPlayer *self, GError **err)
{
PlayerctlPlayer *playerctl_player_next(PlayerctlPlayer *self, GError **err) {
PLAYER_COMMAND_FUNC(next);
}
@@ -737,8 +712,8 @@ PlayerctlPlayer *playerctl_player_next(PlayerctlPlayer *self, GError **err)
*
* Returns: (transfer none): the #PlayerctlPlayer for chaining
*/
PlayerctlPlayer *playerctl_player_previous(PlayerctlPlayer *self, GError **err)
{
PlayerctlPlayer *playerctl_player_previous(PlayerctlPlayer *self,
GError **err) {
PLAYER_COMMAND_FUNC(previous);
}
@@ -753,8 +728,9 @@ PlayerctlPlayer *playerctl_player_previous(PlayerctlPlayer *self, GError **err)
*
* Returns: (transfer full): The artist from the metadata of the current track
*/
gchar *playerctl_player_print_metadata_prop(PlayerctlPlayer *self, const gchar *property, GError **err)
{
gchar *playerctl_player_print_metadata_prop(PlayerctlPlayer *self,
const gchar *property,
GError **err) {
GError *tmp_error = NULL;
g_return_val_if_fail(self != NULL, NULL);
@@ -818,13 +794,12 @@ gchar *playerctl_player_print_metadata_prop(PlayerctlPlayer *self, const gchar *
* @self: a #PlayerctlPlayer
* @err: (allow-none): the location of a GError or NULL
*
* Gets the artist from the metadata of the current track, or the empty string if
* no track is playing.
* Gets the artist from the metadata of the current track, or the empty string
* if no track is playing.
*
* Returns: (transfer full): The artist from the metadata of the current track
*/
gchar *playerctl_player_get_artist(PlayerctlPlayer *self, GError **err)
{
gchar *playerctl_player_get_artist(PlayerctlPlayer *self, GError **err) {
g_return_val_if_fail(self != NULL, NULL);
g_return_val_if_fail(err == NULL || *err == NULL, NULL);
@@ -846,8 +821,7 @@ gchar *playerctl_player_get_artist(PlayerctlPlayer *self, GError **err)
*
* Returns: (transfer full): The title from the metadata of the current track
*/
gchar *playerctl_player_get_title(PlayerctlPlayer *self, GError **err)
{
gchar *playerctl_player_get_title(PlayerctlPlayer *self, GError **err) {
g_return_val_if_fail(self != NULL, NULL);
g_return_val_if_fail(err == NULL || *err == NULL, NULL);
@@ -869,8 +843,7 @@ gchar *playerctl_player_get_title(PlayerctlPlayer *self, GError **err)
*
* Returns: (transfer full): The album from the metadata of the current track
*/
gchar *playerctl_player_get_album(PlayerctlPlayer *self, GError **err)
{
gchar *playerctl_player_get_album(PlayerctlPlayer *self, GError **err) {
g_return_val_if_fail(self != NULL, NULL);
g_return_val_if_fail(err == NULL || *err == NULL, NULL);
@@ -889,8 +862,8 @@ gchar *playerctl_player_get_album(PlayerctlPlayer *self, GError **err)
*
* Sets the position of the current track to the given position in microseconds.
*/
void playerctl_player_set_position(PlayerctlPlayer *self, gint64 position, GError **err)
{
void playerctl_player_set_position(PlayerctlPlayer *self, gint64 position,
GError **err) {
GError *tmp_error = NULL;
g_return_if_fail(self != NULL);
@@ -907,28 +880,31 @@ void playerctl_player_set_position(PlayerctlPlayer *self, gint64 position, GErro
return;
}
GVariant *track_id_variant = g_variant_lookup_value(metadata, "mpris:trackid", G_VARIANT_TYPE_OBJECT_PATH);
GVariant *track_id_variant = g_variant_lookup_value(
metadata, "mpris:trackid", G_VARIANT_TYPE_OBJECT_PATH);
if (track_id_variant == NULL) {
// XXX some players set this as a string, which is against the protocol,
// but a lot of them do it and I don't feel like fixing it on all the
// players in the world.
track_id_variant = g_variant_lookup_value(metadata, "mpris:trackid", G_VARIANT_TYPE_STRING);
track_id_variant = g_variant_lookup_value(metadata, "mpris:trackid",
G_VARIANT_TYPE_STRING);
}
g_variant_unref(metadata);
if (track_id_variant == NULL) {
tmp_error = g_error_new(playerctl_player_error_quark(), 1, "Could not get track id to set position");
tmp_error = g_error_new(playerctl_player_error_quark(), 1,
"Could not get track id to set position");
g_propagate_error(err, tmp_error);
return;
}
const gchar *track_id = g_variant_get_string(track_id_variant, NULL);
org_mpris_media_player2_player_call_set_position_sync(self->priv->proxy, track_id, position, NULL, &tmp_error);
org_mpris_media_player2_player_call_set_position_sync(
self->priv->proxy, track_id, position, NULL, &tmp_error);
g_variant_unref(track_id_variant);
if (tmp_error != NULL) {
g_propagate_error(err, tmp_error);
}
}

View File

@@ -1,5 +1,4 @@
/* vim:ts=2:sw=2:expandtab
*
/*
* This file is part of playerctl.
*
* playerctl is free software: you can redistribute it and/or modify it under
@@ -32,18 +31,24 @@
* @short_description: A class to control an MPRIS player
*/
#define PLAYERCTL_TYPE_PLAYER (playerctl_player_get_type())
#define PLAYERCTL_PLAYER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PLAYERCTL_TYPE_PLAYER, PlayerctlPlayer))
#define PLAYERCTL_IS_PLAYER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PLAYERCTL_TYPE_PLAYER))
#define PLAYERCTL_PLAYER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PLAYERCTL_TYPE_PLAYER, PlayerctlPlayerClass))
#define PLAYERCTL_IS_PLAYER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PLAYERCTL_TYPE_PLAYER))
#define PLAYERCTL_PLAYER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PLAYERCTL_TYPE_PLAYER, PlayerctlPlayerClass))
#define PLAYERCTL_PLAYER(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), PLAYERCTL_TYPE_PLAYER, PlayerctlPlayer))
#define PLAYERCTL_IS_PLAYER(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), PLAYERCTL_TYPE_PLAYER))
#define PLAYERCTL_PLAYER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), PLAYERCTL_TYPE_PLAYER, \
PlayerctlPlayerClass))
#define PLAYERCTL_IS_PLAYER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), PLAYERCTL_TYPE_PLAYER))
#define PLAYERCTL_PLAYER_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), PLAYERCTL_TYPE_PLAYER, \
PlayerctlPlayerClass))
typedef struct _PlayerctlPlayer PlayerctlPlayer;
typedef struct _PlayerctlPlayerClass PlayerctlPlayerClass;
typedef struct _PlayerctlPlayerPrivate PlayerctlPlayerPrivate;
struct _PlayerctlPlayer
{
struct _PlayerctlPlayer {
/* Parent instance structure */
GObject parent_instance;
@@ -51,8 +56,7 @@ struct _PlayerctlPlayer
PlayerctlPlayerPrivate *priv;
};
struct _PlayerctlPlayerClass
{
struct _PlayerctlPlayerClass {
/* Parent class structure */
GObjectClass parent_class;
};
@@ -65,17 +69,21 @@ PlayerctlPlayer *playerctl_player_new (const gchar *name, GError **err);
* Method definitions.
*/
PlayerctlPlayer *playerctl_player_on(PlayerctlPlayer *self, const gchar *event, GClosure *callback, GError **err);
PlayerctlPlayer *playerctl_player_on(PlayerctlPlayer *self, const gchar *event,
GClosure *callback, GError **err);
PlayerctlPlayer *playerctl_player_open(PlayerctlPlayer *self, gchar *uri, GError **err);
PlayerctlPlayer *playerctl_player_open(PlayerctlPlayer *self, gchar *uri,
GError **err);
PlayerctlPlayer *playerctl_player_play_pause(PlayerctlPlayer *self, GError **err);
PlayerctlPlayer *playerctl_player_play_pause(PlayerctlPlayer *self,
GError **err);
PlayerctlPlayer *playerctl_player_play(PlayerctlPlayer *self, GError **err);
PlayerctlPlayer *playerctl_player_stop(PlayerctlPlayer *self, GError **err);
PlayerctlPlayer *playerctl_player_seek(PlayerctlPlayer *self, gint64 offset, GError **err);
PlayerctlPlayer *playerctl_player_seek(PlayerctlPlayer *self, gint64 offset,
GError **err);
PlayerctlPlayer *playerctl_player_pause(PlayerctlPlayer *self, GError **err);
@@ -83,7 +91,9 @@ PlayerctlPlayer *playerctl_player_next(PlayerctlPlayer *self, GError **err);
PlayerctlPlayer *playerctl_player_previous(PlayerctlPlayer *self, GError **err);
gchar *playerctl_player_print_metadata_prop(PlayerctlPlayer *self, const gchar *property, GError **err);
gchar *playerctl_player_print_metadata_prop(PlayerctlPlayer *self,
const gchar *property,
GError **err);
gchar *playerctl_player_get_artist(PlayerctlPlayer *self, GError **err);
@@ -91,6 +101,7 @@ gchar *playerctl_player_get_title(PlayerctlPlayer *self, GError **err);
gchar *playerctl_player_get_album(PlayerctlPlayer *self, GError **err);
void playerctl_player_set_position(PlayerctlPlayer *self, gint64 position, GError **err);
void playerctl_player_set_position(PlayerctlPlayer *self, gint64 position,
GError **err);
#endif /* __PLAYERCTL_PLAYER_H__ */

View File

@@ -1,5 +1,4 @@
/* vim:ts=2:sw=2:expandtab
*
/*
* This file is part of playerctl.
*
* playerctl is free software: you can redistribute it and/or modify it under

View File

@@ -1,5 +1,4 @@
/* vim:ts=2:sw=2:expandtab
*
/*
* This file is part of playerctl.
*
* playerctl is free software: you can redistribute it and/or modify it under
@@ -23,8 +22,8 @@
#define __PLAYERCTL_INSIDE__
#include <playerctl/playerctl-version.h>
#include <playerctl/playerctl-player.h>
#include <playerctl/playerctl-version.h>
#undef __PLAYERCTL_INSIDE__