diff options
author | Sebastien Bacher <seb128@ubuntu.com> | 2010-07-12 17:45:04 +0200 |
---|---|---|
committer | Sebastien Bacher <seb128@ubuntu.com> | 2010-07-12 17:45:04 +0200 |
commit | f6ffb190261dfdbbf55e90b63c1cd06f03037e35 (patch) | |
tree | f34ba1947d158c3c38de6556f4049c518dc58c43 /src/player-controller.c | |
parent | 964106d9c8c140d9c27a22aca8078dfdab57c5e9 (diff) | |
parent | d8253fc0cfe667316e2e5f033bcbfba4c3044297 (diff) | |
download | ayatana-indicator-sound-f6ffb190261dfdbbf55e90b63c1cd06f03037e35.tar.gz ayatana-indicator-sound-f6ffb190261dfdbbf55e90b63c1cd06f03037e35.tar.bz2 ayatana-indicator-sound-f6ffb190261dfdbbf55e90b63c1cd06f03037e35.zip |
Import upstream version 0.3.6
Diffstat (limited to 'src/player-controller.c')
-rw-r--r-- | src/player-controller.c | 98 |
1 files changed, 59 insertions, 39 deletions
diff --git a/src/player-controller.c b/src/player-controller.c index bbdbcbf..ca1485e 100644 --- a/src/player-controller.c +++ b/src/player-controller.c @@ -69,16 +69,6 @@ typedef struct _MprisControllerClass MprisControllerClass; #define _g_free0(var) (var = (g_free (var), NULL)) #define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL))) -#define TYPE_MPRIS_CONTROLLER_V2 (mpris_controller_v2_get_type ()) -#define MPRIS_CONTROLLER_V2(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MPRIS_CONTROLLER_V2, MprisControllerV2)) -#define MPRIS_CONTROLLER_V2_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MPRIS_CONTROLLER_V2, MprisControllerV2Class)) -#define IS_MPRIS_CONTROLLER_V2(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MPRIS_CONTROLLER_V2)) -#define IS_MPRIS_CONTROLLER_V2_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MPRIS_CONTROLLER_V2)) -#define MPRIS_CONTROLLER_V2_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MPRIS_CONTROLLER_V2, MprisControllerV2Class)) - -typedef struct _MprisControllerV2 MprisControllerV2; -typedef struct _MprisControllerV2Class MprisControllerV2Class; - #define TYPE_TITLE_MENUITEM (title_menuitem_get_type ()) #define TITLE_MENUITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TITLE_MENUITEM, TitleMenuitem)) #define TITLE_MENUITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TITLE_MENUITEM, TitleMenuitemClass)) @@ -125,6 +115,7 @@ struct _PlayerControllerPrivate { DbusmenuMenuitem* root_menu; char* _name; GAppInfo* _app_info; + gint _menu_offset; }; typedef enum { @@ -145,7 +136,8 @@ GType mpris_controller_get_type (void); enum { PLAYER_CONTROLLER_DUMMY_PROPERTY, PLAYER_CONTROLLER_NAME, - PLAYER_CONTROLLER_APP_INFO + PLAYER_CONTROLLER_APP_INFO, + PLAYER_CONTROLLER_MENU_OFFSET }; GType player_controller_state_get_type (void); #define PLAYER_CONTROLLER_METADATA 2 @@ -153,26 +145,24 @@ GType player_controller_state_get_type (void); static char* player_controller_format_client_name (const char* client_name); void player_controller_set_name (PlayerController* self, const char* value); void player_controller_update_state (PlayerController* self, PlayerControllerstate new_state); +void player_controller_set_menu_offset (PlayerController* self, gint value); static void player_controller_construct_widgets (PlayerController* self); static void player_controller_establish_mpris_connection (PlayerController* self); static void player_controller_update_layout (PlayerController* self); -PlayerController* player_controller_new (DbusmenuMenuitem* root, const char* client_name, PlayerControllerstate initial_state); -PlayerController* player_controller_construct (GType object_type, DbusmenuMenuitem* root, const char* client_name, PlayerControllerstate initial_state); +PlayerController* player_controller_new (DbusmenuMenuitem* root, const char* client_name, gint offset, PlayerControllerstate initial_state); +PlayerController* player_controller_construct (GType object_type, DbusmenuMenuitem* root, const char* client_name, gint offset, PlayerControllerstate initial_state); +const char* player_controller_get_name (PlayerController* self); void player_controller_activate (PlayerController* self); GAppInfo* player_controller_get_app_info (PlayerController* self); -const char* player_controller_get_name (PlayerController* self); void player_controller_instantiate (PlayerController* self); -MprisControllerV2* mpris_controller_v2_new (const char* name, PlayerController* controller); -MprisControllerV2* mpris_controller_v2_construct (GType object_type, const char* name, PlayerController* controller); -GType mpris_controller_v2_get_type (void); -MprisController* mpris_controller_new (const char* name, PlayerController* controller, const char* mpris_interface); -MprisController* mpris_controller_construct (GType object_type, const char* name, PlayerController* controller, const char* mpris_interface); +MprisController* mpris_controller_new (PlayerController* ctrl, const char* inter); +MprisController* mpris_controller_construct (GType object_type, PlayerController* ctrl, const char* inter); gboolean mpris_controller_connected (MprisController* self); void player_controller_vanish (PlayerController* self); PlayerItem* player_item_new (const char* type); PlayerItem* player_item_construct (GType object_type, const char* type); -TitleMenuitem* title_menuitem_new (PlayerController* parent, const char* name); -TitleMenuitem* title_menuitem_construct (GType object_type, PlayerController* parent, const char* name); +TitleMenuitem* title_menuitem_new (PlayerController* parent); +TitleMenuitem* title_menuitem_construct (GType object_type, PlayerController* parent); GType title_menuitem_get_type (void); MetadataMenuitem* metadata_menuitem_new (void); MetadataMenuitem* metadata_menuitem_construct (GType object_type); @@ -180,6 +170,7 @@ GType metadata_menuitem_get_type (void); TransportMenuitem* transport_menuitem_new (PlayerController* parent); TransportMenuitem* transport_menuitem_construct (GType object_type, PlayerController* parent); GType transport_menuitem_get_type (void); +gint player_controller_get_menu_offset (PlayerController* self); void player_controller_set_app_info (PlayerController* self, GAppInfo* value); static void player_controller_finalize (GObject* obj); static void player_controller_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec); @@ -216,7 +207,7 @@ static char* string_strip (const char* self) { } -PlayerController* player_controller_construct (GType object_type, DbusmenuMenuitem* root, const char* client_name, PlayerControllerstate initial_state) { +PlayerController* player_controller_construct (GType object_type, DbusmenuMenuitem* root, const char* client_name, gint offset, PlayerControllerstate initial_state) { PlayerController * self; DbusmenuMenuitem* _tmp0_; char* _tmp2_; @@ -231,6 +222,8 @@ PlayerController* player_controller_construct (GType object_type, DbusmenuMenuit _g_free0 (_tmp1_); self->custom_items = (_tmp3_ = gee_array_list_new (TYPE_PLAYER_ITEM, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL), _g_object_unref0 (self->custom_items), _tmp3_); player_controller_update_state (self, initial_state); + player_controller_set_menu_offset (self, offset); + g_debug ("player-controller.vala:54: offset = %i", offset); player_controller_construct_widgets (self); player_controller_establish_mpris_connection (self); player_controller_update_layout (self); @@ -238,14 +231,15 @@ PlayerController* player_controller_construct (GType object_type, DbusmenuMenuit } -PlayerController* player_controller_new (DbusmenuMenuitem* root, const char* client_name, PlayerControllerstate initial_state) { - return player_controller_construct (TYPE_PLAYER_CONTROLLER, root, client_name, initial_state); +PlayerController* player_controller_new (DbusmenuMenuitem* root, const char* client_name, gint offset, PlayerControllerstate initial_state) { + return player_controller_construct (TYPE_PLAYER_CONTROLLER, root, client_name, offset, initial_state); } void player_controller_update_state (PlayerController* self, PlayerControllerstate new_state) { g_return_if_fail (self != NULL); - g_debug ("player-controller.vala:59: update_state : new state %i", (gint) new_state); + g_debug ("player-controller.vala:62: update_state - player controller %s : new s" \ +"tate %i", self->priv->_name, (gint) new_state); self->current_state = (gint) new_state; } @@ -263,26 +257,27 @@ void player_controller_instantiate (PlayerController* self) { GError * _inner_error_; g_return_if_fail (self != NULL); _inner_error_ = NULL; + g_debug ("player-controller.vala:80: instantiate in player controller for %s", self->priv->_name); { g_app_info_launch (self->priv->_app_info, NULL, NULL, &_inner_error_); if (_inner_error_ != NULL) { - goto __catch1_g_error; + goto __catch0_g_error; } player_controller_update_state (self, PLAYER_CONTROLLER_STATE_INSTANTIATING); } - goto __finally1; - __catch1_g_error: + goto __finally0; + __catch0_g_error: { GError * _error_; _error_ = _inner_error_; _inner_error_ = NULL; { - g_warning ("player-controller.vala:82: Failed to launch app %s with error message:" \ + g_warning ("player-controller.vala:86: Failed to launch app %s with error message:" \ " %s", self->priv->_name, _error_->message); _g_error_free0 (_error_); } } - __finally1: + __finally0: if (_inner_error_ != NULL) { g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); @@ -294,18 +289,20 @@ void player_controller_instantiate (PlayerController* self) { static void player_controller_establish_mpris_connection (PlayerController* self) { g_return_if_fail (self != NULL); if (self->current_state != PLAYER_CONTROLLER_STATE_READY) { - g_debug ("player-controller.vala:89: establish_mpris_connection - Not ready to c" \ + g_debug ("player-controller.vala:93: establish_mpris_connection - Not ready to c" \ "onnect"); return; } if (_vala_strcmp0 (self->priv->_name, "Vlc") == 0) { MprisController* _tmp0_; - self->mpris_adaptor = (_tmp0_ = (MprisController*) mpris_controller_v2_new (self->priv->_name, self), _g_object_unref0 (self->mpris_adaptor), _tmp0_); + g_debug ("player-controller.vala:98: establishing a vlc mpris controller"); + self->mpris_adaptor = (_tmp0_ = mpris_controller_new (self, "org.mpris.MediaPlayer.Player"), _g_object_unref0 (self->mpris_adaptor), _tmp0_); } else { MprisController* _tmp1_; - self->mpris_adaptor = (_tmp1_ = mpris_controller_new (self->priv->_name, self, "org.freedesktop.MediaPlayer"), _g_object_unref0 (self->mpris_adaptor), _tmp1_); + self->mpris_adaptor = (_tmp1_ = mpris_controller_new (self, "org.freedesktop.MediaPlayer"), _g_object_unref0 (self->mpris_adaptor), _tmp1_); } if (mpris_controller_connected (self->mpris_adaptor) == TRUE) { + g_debug ("player-controller.vala:106: yup I'm connected"); player_controller_update_state (self, PLAYER_CONTROLLER_STATE_CONNECTED); } else { player_controller_update_state (self, PLAYER_CONTROLLER_STATE_DISCONNECTED); @@ -355,13 +352,16 @@ static void player_controller_update_layout (PlayerController* self) { if (self->current_state != PLAYER_CONTROLLER_STATE_CONNECTED) { visibility = FALSE; } - g_debug ("player-controller.vala:120: about the set the visibility on both the t" \ + g_debug ("player-controller.vala:128: about the set the visibility on both the t" \ "ransport and metadata widget to %s", _tmp0_ = bool_to_string (visibility)); _g_free0 (_tmp0_); dbusmenu_menuitem_property_set_bool ((DbusmenuMenuitem*) (_tmp1_ = (PlayerItem*) gee_abstract_list_get ((GeeAbstractList*) self->custom_items, PLAYER_CONTROLLER_TRANSPORT)), DBUSMENU_MENUITEM_PROP_VISIBLE, visibility); _g_object_unref0 (_tmp1_); dbusmenu_menuitem_property_set_bool ((DbusmenuMenuitem*) (_tmp2_ = (PlayerItem*) gee_abstract_list_get ((GeeAbstractList*) self->custom_items, PLAYER_CONTROLLER_METADATA)), DBUSMENU_MENUITEM_PROP_VISIBLE, visibility); _g_object_unref0 (_tmp2_); + if (self->mpris_adaptor == NULL) { + g_warning ("player-controller.vala:133: Why is the mpris object null"); + } } @@ -370,17 +370,15 @@ static void player_controller_construct_widgets (PlayerController* self) { TitleMenuitem* title_menu_item; MetadataMenuitem* metadata_item; TransportMenuitem* transport_item; - gint offset; g_return_if_fail (self != NULL); gee_abstract_collection_add ((GeeAbstractCollection*) self->custom_items, _tmp0_ = player_item_new (DBUSMENU_CLIENT_TYPES_SEPARATOR)); _g_object_unref0 (_tmp0_); - title_menu_item = title_menuitem_new (self, self->priv->_name); + title_menu_item = title_menuitem_new (self); gee_abstract_collection_add ((GeeAbstractCollection*) self->custom_items, (PlayerItem*) title_menu_item); metadata_item = metadata_menuitem_new (); gee_abstract_collection_add ((GeeAbstractCollection*) self->custom_items, (PlayerItem*) metadata_item); transport_item = transport_menuitem_new (self); gee_abstract_collection_add ((GeeAbstractCollection*) self->custom_items, (PlayerItem*) transport_item); - offset = 2; { GeeIterator* _item_it; _item_it = gee_abstract_collection_iterator ((GeeAbstractCollection*) self->custom_items); @@ -390,7 +388,7 @@ static void player_controller_construct_widgets (PlayerController* self) { break; } item = (PlayerItem*) gee_iterator_get (_item_it); - dbusmenu_menuitem_child_add_position (self->priv->root_menu, (DbusmenuMenuitem*) item, (guint) (offset + gee_abstract_list_index_of ((GeeAbstractList*) self->custom_items, item))); + dbusmenu_menuitem_child_add_position (self->priv->root_menu, (DbusmenuMenuitem*) item, (guint) (self->priv->_menu_offset + gee_abstract_list_index_of ((GeeAbstractList*) self->custom_items, item))); _g_object_unref0 (item); } _g_object_unref0 (_item_it); @@ -446,7 +444,7 @@ static char* player_controller_format_client_name (const char* client_name) { formatted = (_tmp2_ = g_strconcat (_tmp0_ = g_utf8_strup (client_name, (gssize) 1), _tmp1_ = string_slice (client_name, (glong) 1, g_utf8_strlen (client_name, -1)), NULL), _g_free0 (formatted), _tmp2_); _g_free0 (_tmp1_); _g_free0 (_tmp0_); - g_debug ("player-controller.vala:154: PlayerController->format_client_name - : %" \ + g_debug ("player-controller.vala:165: PlayerController->format_client_name - : %" \ "s", formatted); } result = formatted; @@ -486,6 +484,21 @@ void player_controller_set_app_info (PlayerController* self, GAppInfo* value) { } +gint player_controller_get_menu_offset (PlayerController* self) { + gint result; + g_return_val_if_fail (self != NULL, 0); + result = self->priv->_menu_offset; + return result; +} + + +void player_controller_set_menu_offset (PlayerController* self, gint value) { + g_return_if_fail (self != NULL); + self->priv->_menu_offset = value; + g_object_notify ((GObject *) self, "menu-offset"); +} + + static void player_controller_class_init (PlayerControllerClass * klass) { player_controller_parent_class = g_type_class_peek_parent (klass); g_type_class_add_private (klass, sizeof (PlayerControllerPrivate)); @@ -494,6 +507,7 @@ static void player_controller_class_init (PlayerControllerClass * klass) { G_OBJECT_CLASS (klass)->finalize = player_controller_finalize; g_object_class_install_property (G_OBJECT_CLASS (klass), PLAYER_CONTROLLER_NAME, g_param_spec_string ("name", "name", "name", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE)); g_object_class_install_property (G_OBJECT_CLASS (klass), PLAYER_CONTROLLER_APP_INFO, g_param_spec_object ("app-info", "app-info", "app-info", G_TYPE_APP_INFO, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), PLAYER_CONTROLLER_MENU_OFFSET, g_param_spec_int ("menu-offset", "menu-offset", "menu-offset", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE)); } @@ -537,6 +551,9 @@ static void player_controller_get_property (GObject * object, guint property_id, case PLAYER_CONTROLLER_APP_INFO: g_value_set_object (value, player_controller_get_app_info (self)); break; + case PLAYER_CONTROLLER_MENU_OFFSET: + g_value_set_int (value, player_controller_get_menu_offset (self)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -554,6 +571,9 @@ static void player_controller_set_property (GObject * object, guint property_id, case PLAYER_CONTROLLER_APP_INFO: player_controller_set_app_info (self, g_value_get_object (value)); break; + case PLAYER_CONTROLLER_MENU_OFFSET: + player_controller_set_menu_offset (self, g_value_get_int (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; |