static void mex_search_plugin_model_changed_cb (GController *controller, GControllerAction action, GControllerReference *ref, MexModel *model) { gint i; gint n_indices = g_controller_reference_get_n_indices (ref); /* If the MIME type is unset, set one so that it's still playable in the * main UI. This plugin will only use white-listed Grilo plugins that we * know return playable media, so this is OK. */ switch (action) { case G_CONTROLLER_ADD: for (i = 0; i < n_indices; i++) { gchar *notify; MexContent *content; const gchar *property_name; gint content_index = g_controller_reference_get_index_uint (ref, i); content = mex_model_get_content (model, content_index); /* Make sure the mime-type remains useful */ property_name = mex_content_get_property_name (content, MEX_CONTENT_METADATA_MIMETYPE); if (property_name) { notify = g_strconcat ("notify::", property_name, NULL); g_signal_connect (content, notify, G_CALLBACK (mex_search_plugin_mimetype_set_cb), NULL); g_free (notify); } mex_search_plugin_mimetype_set_cb (content); } break; default: break; } }
/** * mex_column_controller_changed: * * Callback for when the current model controller's "changed" signal is emitted */ static void mex_column_controller_changed (GController *controller, GControllerAction action, GControllerReference *ref, MexColumn *column) { MexColumnPrivate *priv = column->priv; gint i, n_indices; MexContent *content; n_indices = g_controller_reference_get_n_indices (ref); switch (action) { case G_CONTROLLER_ADD: for (i = 0; i < n_indices; i++) { gint content_index = g_controller_reference_get_index_uint (ref, i); content = mex_model_get_content (priv->model, content_index); mex_column_add_content (column, content, content_index); } break; case G_CONTROLLER_REMOVE: for (i = 0; i < n_indices; i++) { GList *lnk; gint content_index = g_controller_reference_get_index_uint (ref, i); lnk = g_list_nth (priv->children, content_index); if (lnk->data == priv->current_focus) priv->current_focus = NULL; clutter_actor_destroy (lnk->data); priv->children = g_list_delete_link (priv->children, lnk); } break; case G_CONTROLLER_UPDATE: break; case G_CONTROLLER_CLEAR: mex_column_clear (column); break; case G_CONTROLLER_REPLACE: mex_column_clear (column); mex_column_populate (column); break; case G_CONTROLLER_INVALID_ACTION: g_warning (G_STRLOC ": Controller has issued an error"); break; default: g_warning (G_STRLOC ": Unhandled action"); break; } clutter_actor_queue_relayout (CLUTTER_ACTOR (column)); }
static void mex_aggregate_model_controller_changed_cb (GController *controller, GControllerAction action, GControllerReference *ref, MexAggregateModel *self) { gint i; gint n_indices = 0; MexAggregateModelPrivate *priv = self->priv; MexModel *model = g_hash_table_lookup (priv->controller_to_model, controller); if (!model) { g_warning (G_STRLOC ": Signal from unknown controller"); return; } if (ref) n_indices = g_controller_reference_get_n_indices (ref); switch (action) { case G_CONTROLLER_ADD: for (i = 0; i < n_indices; i++) { MexContent *content; gint content_index = g_controller_reference_get_index_uint (ref, i); content = mex_model_get_content (model, content_index); g_hash_table_insert (priv->content_to_model, content, model); mex_model_add_content (MEX_MODEL (self), content); } break; case G_CONTROLLER_REMOVE: for (i = 0; i < n_indices; i++) { MexContent *content; gint content_index = g_controller_reference_get_index_uint (ref, i); content = mex_model_get_content (model, content_index); g_hash_table_remove (priv->content_to_model, content); mex_model_remove_content (MEX_MODEL (self), content); } break; case G_CONTROLLER_UPDATE: break; case G_CONTROLLER_CLEAR: mex_aggregate_model_clear_model (self, model); break; case G_CONTROLLER_REPLACE: { MexContent *content; mex_aggregate_model_clear_model (self, model); i = 0; while ((content = mex_model_get_content (model, i++))) { g_hash_table_insert (priv->content_to_model, content, model); mex_model_add_content (MEX_MODEL (self), content); } } break; case G_CONTROLLER_INVALID_ACTION: g_warning (G_STRLOC ": Proxy controller has issued an error"); break; default: break; } }
static void mex_proxy_controller_changed_cb (GController *controller, GControllerAction action, GControllerReference *ref, MexProxy *proxy) { gint i, n_indices; MexContent *content; MexProxyPrivate *priv = proxy->priv; n_indices = g_controller_reference_get_n_indices (ref); switch (action) { case G_CONTROLLER_ADD: for (i = 0; i < n_indices; i++) { gint content_index = g_controller_reference_get_index_uint (ref, i); content = mex_model_get_content (priv->model, content_index); mex_proxy_add_content (proxy, content); } break; case G_CONTROLLER_REMOVE: { gint length, fillin = 0, start_fillin; GList *positions = NULL, *position; for (i = 0; i < n_indices; i++) { gint content_index = g_controller_reference_get_index_uint (ref, i); if (content_index >= priv->limit) positions = g_list_insert_sorted_with_data (positions, GINT_TO_POINTER (content_index), _insert_position, NULL); else fillin++; content = mex_model_get_content (priv->model, content_index); mex_proxy_remove_content (proxy, content); } position = positions; length = mex_model_get_length (priv->model); start_fillin = priv->limit; for (i = 0; i < MIN (fillin, (length - (gint) priv->limit)); i++) { if ((position != NULL) && (start_fillin == GPOINTER_TO_INT (position->data))) { while ((position != NULL) && (start_fillin == GPOINTER_TO_INT (position->data))) { start_fillin++; if (start_fillin > GPOINTER_TO_INT (position->data)) position = position->next; } } content = mex_model_get_content (priv->model, start_fillin); mex_proxy_add_content (proxy, content); start_fillin++; } g_list_free (positions); } break; case G_CONTROLLER_UPDATE: /* Should be no need for this, GBinding sorts it out for us :) */ break; case G_CONTROLLER_CLEAR: mex_proxy_clear (proxy); break; case G_CONTROLLER_REPLACE: mex_proxy_clear (proxy); i = 0; while ((content = mex_model_get_content (priv->model, i++))) mex_proxy_add_content (proxy, content); break; case G_CONTROLLER_INVALID_ACTION: g_warning (G_STRLOC ": Proxy controller has issued an error"); break; default: g_warning (G_STRLOC ": Unhandled action"); break; } }
static void mex_view_model_controller_changed_cb (GController *controller, GControllerAction action, GControllerReference *ref, MexViewModel *self) { gint n_indices, i; MexViewModelPrivate *priv = self->priv; n_indices = g_controller_reference_get_n_indices (ref); switch (action) { case G_CONTROLLER_ADD: { guint view_length; /* increase the internal items array by the number of new items */ view_length = mex_model_get_length (MEX_MODEL (self)); g_ptr_array_set_size (priv->internal_items, view_length + n_indices); /* set the new items */ while (n_indices-- > 0) { MexContent *content; guint idx; idx = g_controller_reference_get_index_uint (ref, n_indices); content = mex_model_get_content (priv->model, idx); g_signal_connect (content, "notify", G_CALLBACK (content_notify_cb), self); priv->internal_items->pdata[view_length + n_indices] = content; } } break; case G_CONTROLLER_REMOVE: { while (n_indices-- > 0) { MexContent *content; gint idx; idx = g_controller_reference_get_index_int (ref, n_indices); content = mex_model_get_content (priv->model, idx); g_signal_handlers_disconnect_by_func (content, G_CALLBACK (content_notify_cb), self); g_ptr_array_remove_fast (priv->internal_items, content); } } break; case G_CONTROLLER_UPDATE: /* Should be no need for this, GBinding sorts it out for us :) */ break; case G_CONTROLLER_CLEAR: for (i = 0; i < priv->external_items->len; i++) g_object_unref (g_ptr_array_index (priv->external_items, i)); g_ptr_array_set_size (priv->external_items, 0); for (i = 0; i < priv->external_items->len; i++) g_signal_handlers_disconnect_by_func (g_ptr_array_index (priv->external_items, i), G_CALLBACK (content_notify_cb), self); g_ptr_array_set_size (priv->internal_items, 0); break; case G_CONTROLLER_REPLACE: g_warning (G_STRLOC ": G_CONTROLLER_REPLACE not implemented by MexViewModel"); break; case G_CONTROLLER_INVALID_ACTION: g_warning (G_STRLOC ": View-model controller has issued an error"); break; default: g_warning (G_STRLOC ": Unhandled action"); break; } mex_view_model_refresh_external_items (self); }