static void
impl_deactivate	(TotemPlugin *plugin,
		 TotemObject *totem)
{
	TotemMediaPlayerKeysPlugin *pi = TOTEM_MEDIA_PLAYER_KEYS_PLUGIN (plugin);
	GtkWindow *window;

	if (pi->media_player_keys_proxy != NULL) {
		dbus_g_proxy_call (pi->media_player_keys_proxy,
				   "ReleaseMediaPlayerKeys", NULL,
				   G_TYPE_STRING, "Totem", G_TYPE_INVALID, G_TYPE_INVALID);
		g_object_unref (pi->media_player_keys_proxy);
		pi->media_player_keys_proxy = NULL;
	}

	if (pi->handler_id != 0) {
		window = totem_get_main_window (totem);
		if (window == NULL)
			return;

		g_signal_handler_disconnect (G_OBJECT (window), pi->handler_id);

		g_object_unref (window);
	}
}
Exemplo n.º 2
0
static gboolean
impl_activate (TotemPlugin *plugin, TotemObject *totem, GError **error)
{
	TotemYouTubePlugin *self = TOTEM_YOUTUBE_PLUGIN (plugin);
	GtkWindow *main_window;
	GtkBuilder *builder;
	guint i;

	self->totem = g_object_ref (totem);
	self->bvw = BACON_VIDEO_WIDGET (totem_get_video_widget (totem));

	/* Set up the interface */
	main_window = totem_get_main_window (totem);
	builder = totem_plugin_load_interface (plugin, "youtube.ui", TRUE, main_window, self);
	g_object_unref (main_window);

	self->search_entry = GTK_ENTRY (gtk_builder_get_object (builder, "yt_search_entry"));
	self->search_button = GTK_BUTTON (gtk_builder_get_object (builder, "yt_search_button"));
	self->notebook = GTK_NOTEBOOK (gtk_builder_get_object (builder, "yt_notebook"));

	/* Set up the tree view pages */
	for (i = 0; i < NUM_TREE_VIEWS; i++)
		set_up_tree_view (self, builder, i);
	self->current_tree_view = SEARCH_TREE_VIEW;

	self->vbox = GTK_WIDGET (gtk_builder_get_object (builder, "yt_vbox"));
	gtk_widget_show_all (self->vbox);

	/* Add the sidebar page */
	totem_add_sidebar_page (totem, "youtube", _("YouTube"), self->vbox);
	g_object_unref (builder);

	return TRUE;
}
Exemplo n.º 3
0
static void
query_finished_cb (GObject *source_object, GAsyncResult *result, QueryData *data)
{
	GtkWindow *window;
	GDataFeed *feed;
	GError *error = NULL;
	TotemYouTubePlugin *self = data->plugin;

	g_debug ("Search finished!");

	feed = gdata_service_query_finish (GDATA_SERVICE (self->service), result, &error);

	/* Stop the progress bar; a little hacky, but it works */
	self->progress_bar_increment[data->tree_view] = 1.0;
	increment_progress_bar_fraction (self, data->tree_view);

	if (feed != NULL) {
		/* Success! */
		g_object_unref (feed);
		query_data_free (data);

		return;
	}

	/* Bail out if the operation was cancelled */
	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) == TRUE) {
		/* Cancel the t-param and thumbnail threads, if applicable */
		if (data->t_param_cancellable != NULL)
			g_cancellable_cancel (data->t_param_cancellable);
		if (data->thumbnail_cancellable != NULL)
			g_cancellable_cancel (data->thumbnail_cancellable);

		goto finish;
	}

	/* Error! */
	window = totem_get_main_window (data->plugin->totem);
	if (g_error_matches (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR) == TRUE) {
		/* Hide the ugly technical message libgdata gives behind a nice one telling them it's out of date (which it likely is
		 * if we're receiving a protocol error). */
		totem_interface_error (_("Error Searching for Videos"),
				       _("The response from the server could not be understood. "
				         "Please check you are running the latest version of libgdata."), window);
	} else {
		/* Spew out the error message as provided */
		totem_interface_error (_("Error Searching for Videos"), error->message, window);
	}

	g_object_unref (window);

finish:
	g_error_free (error);
	query_data_free (data);

	return;
}
Exemplo n.º 4
0
static void
impl_deactivate (PeasActivatable *plugin)
{
	TotemGromitPlugin *pi = TOTEM_GROMIT_PLUGIN (plugin);
	GtkWindow *window;

	if (pi->priv->handler_id != 0) {
		window = totem_get_main_window (g_object_get_data (G_OBJECT (plugin), "object"));
		g_signal_handler_disconnect (G_OBJECT(window), pi->priv->handler_id);
		pi->priv->handler_id = 0;
		g_object_unref (window);
	}

	totem_gromit_clear (pi, TRUE);

	g_free (pi->priv->path);
	pi->priv->path = NULL;
}
Exemplo n.º 5
0
static void
impl_activate (PeasActivatable *plugin)
{
	TotemMediaPlayerKeysPlugin *pi = TOTEM_MEDIA_PLAYER_KEYS_PLUGIN (plugin);
	TotemObject *totem;
	GtkWindow *window;

	pi->priv->watch_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
					       "org.gnome.SettingsDaemon",
					       G_BUS_NAME_WATCHER_FLAGS_NONE,
					       (GBusNameAppearedCallback) name_appeared_cb,
					       (GBusNameVanishedCallback) name_vanished_cb,
					       g_object_ref (pi), (GDestroyNotify) g_object_unref);

	totem = g_object_get_data (G_OBJECT (plugin), "object");
	window = totem_get_main_window (totem);
	pi->priv->handler_id = g_signal_connect (G_OBJECT (window), "focus-in-event",
						 G_CALLBACK (on_window_focus_in_event), pi);

	g_object_unref (G_OBJECT (window));
}
Exemplo n.º 6
0
static void
impl_deactivate (PeasActivatable *plugin)
{
	TotemMediaPlayerKeysPlugin *pi = TOTEM_MEDIA_PLAYER_KEYS_PLUGIN (plugin);
	GtkWindow *window;

	if (pi->priv->cancellable_init) {
		g_cancellable_cancel (pi->priv->cancellable_init);
	}

	if (pi->priv->cancellable) {
		g_cancellable_cancel (pi->priv->cancellable);
	}

	if (pi->priv->proxy != NULL) {
		g_object_unref (pi->priv->proxy);
		pi->priv->proxy = NULL;
	}

	if (pi->priv->handler_id != 0) {
		TotemObject *totem;

		totem = g_object_get_data (G_OBJECT (plugin), "object");
		window = totem_get_main_window (totem);
		if (window == NULL)
			return;

		g_signal_handler_disconnect (G_OBJECT (window), pi->priv->handler_id);

		g_object_unref (window);
		pi->priv->handler_id = 0;
	}
	if (pi->priv->watch_id != 0) {
		g_bus_unwatch_name (pi->priv->watch_id);
		pi->priv->watch_id = 0;
	}
}
Exemplo n.º 7
0
static void
impl_activate (PeasActivatable *plugin)
{
	TotemGromitPlugin *pi = TOTEM_GROMIT_PLUGIN (plugin);
	GtkWindow *window;

	pi->priv->id = -1;
	pi->priv->pid = -1;

	if (!totem_gromit_available (pi)) {
		//FIXME
#if 0
		g_set_error_literal (error, TOTEM_PLUGIN_ERROR, TOTEM_PLUGIN_ERROR_ACTIVATION,
                                     _("The gromit binary was not found."));

		return FALSE;
#endif
	}

	window = totem_get_main_window (g_object_get_data (G_OBJECT (plugin), "object"));
	pi->priv->handler_id = g_signal_connect (G_OBJECT(window), "key-press-event", 
			G_CALLBACK (on_window_key_press_event), plugin);
	g_object_unref (window);
}
Exemplo n.º 8
0
void
open_in_web_browser_activate_cb (GtkAction *action, TotemYouTubePlugin *self)
{
	GtkTreeSelection *selection;
	GtkTreeModel *model;
	GList *paths, *path;

	selection = gtk_tree_view_get_selection (self->tree_view[self->current_tree_view]);
	paths = gtk_tree_selection_get_selected_rows (selection, &model);

	for (path = paths; path != NULL; path = path->next) {
		GtkTreeIter iter;
		GDataYouTubeVideo *video;
		GDataLink *link;
		GError *error = NULL;

		if (gtk_tree_model_get_iter (model, &iter, (GtkTreePath*) (path->data)) == FALSE)
			continue;

		/* Get the HTML page for the video; its <link rel="alternate" ... /> */
		gtk_tree_model_get (model, &iter, 3, &video, -1);
		link = gdata_entry_look_up_link (GDATA_ENTRY (video), GDATA_LINK_ALTERNATE);
		g_object_unref (video);

		/* Display the page */
		if (gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (self->bvw)), gdata_link_get_uri (link), GDK_CURRENT_TIME, &error) == FALSE) {
			GtkWindow *window = totem_get_main_window (self->totem);
			totem_interface_error (_("Error Opening Video in Web Browser"), error->message, window);
			g_object_unref (window);
			g_error_free (error);
		}
	}

	g_list_foreach (paths, (GFunc) gtk_tree_path_free, NULL);
	g_list_free (paths);
}
Exemplo n.º 9
0
static gboolean
impl_activate (TotemPlugin *plugin,
	       TotemObject *totem,
	       GError **error)
{
	TotemOntopPlugin *pi = TOTEM_ONTOP_PLUGIN (plugin);

	pi->priv->window = totem_get_main_window (totem);
	pi->priv->bvw = BACON_VIDEO_WIDGET (totem_get_video_widget (totem));
	pi->priv->totem = totem;

	pi->priv->handler_id = g_signal_connect (G_OBJECT (totem),
					   "notify::playing",
					   G_CALLBACK (property_notify_cb),
					   pi);
	pi->priv->handler_id_metadata = g_signal_connect (G_OBJECT (pi->priv->bvw),
						    "got-metadata",
						    G_CALLBACK (got_metadata_cb),
						    pi);

	update_from_state (pi->priv);

	return TRUE;
}
Exemplo n.º 10
0
static void
resolve_t_param_cb (SoupSession *session, SoupMessage *message, TParamData *data)
{
	gchar *video_uri = NULL;
	const gchar *video_id, *contents;
	gsize length;
	GMatchInfo *match_info;
	GtkTreeIter iter;
	TotemYouTubePlugin *self = data->plugin;

	/* Prevent cancellation */
	g_cancellable_disconnect (data->cancellable, data->cancelled_id);

	/* Finish loading the page */
	if (message->status_code != SOUP_STATUS_OK) {
		GtkWindow *window;

		/* Bail out if the operation was cancelled */
		if (message->status_code == SOUP_STATUS_CANCELLED)
			goto free_data;

		/* Couldn't load the page contents; error */
		window = totem_get_main_window (data->plugin->totem);
		totem_interface_error (_("Error Looking Up Video URI"), message->response_body->data, window);
		g_object_unref (window);
		goto free_data;
	}

	contents = message->response_body->data;
	length = message->response_body->length;

	video_id = gdata_youtube_video_get_video_id (GDATA_YOUTUBE_VIDEO (data->entry));

	/* Check for the fmt_url_map parameter */
	g_regex_match (self->regex, contents, 0, &match_info);
	if (g_match_info_matches (match_info) == TRUE) {
		gchar *fmt_url_map_escaped, *fmt_url_map;
		gchar **mappings, **i;
		GHashTable *fmt_table;
		gint connection_speed;

		/* We have a match */
		fmt_url_map_escaped = g_match_info_fetch (match_info, 1);
		fmt_url_map = g_uri_unescape_string (fmt_url_map_escaped, NULL);
		g_free (fmt_url_map_escaped);

		/* The fmt_url_map parameter is in the following format:
		 *   fmt1|uri1,fmt2|uri2,fmt3|uri3,...
		 * where fmtN is an identifier for the audio and video encoding and resolution as described here:
		 * (http://en.wikipedia.org/wiki/YouTube#Quality_and_codecs) and uriN is the playback URI for that format.
		 *
		 * We parse it into a hash table from format to URI, and use that against a ranked list of preferred formats (based on the user's
		 * connection speed) to determine the URI to use. */
		fmt_table = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
		mappings = g_strsplit (fmt_url_map, ",", 0);

		for (i = mappings; *i != NULL; i++) {
			/* For the moment we just take the first format we get */
			gchar **mapping;
			gint fmt;

			mapping = g_strsplit (*i, "|", 2);

			if (mapping[0] == NULL || mapping[1] == NULL) {
				g_warning ("Bad format-URI mapping: %s", *i);
				g_strfreev (mapping);
				continue;
			}

			fmt = atoi (mapping[0]);

			if (fmt < 1) {
				g_warning ("Badly-formed format: %s", mapping[0]);
				g_strfreev (mapping);
				continue;
			}

			g_hash_table_insert (fmt_table, GUINT_TO_POINTER ((guint) fmt), g_strdup (mapping[1]));
			g_strfreev (mapping);
		}

		g_strfreev (mappings);

		/* Starting with the highest connection speed we support, look for video URIs matching our connection speed. */
		connection_speed = MIN (bacon_video_widget_get_connection_speed (self->bvw), (gint) G_N_ELEMENTS (fmt_preferences) - 1);
		for (; connection_speed >= 0; connection_speed--) {
			guint idx = (guint) connection_speed;
			video_uri = g_strdup (g_hash_table_lookup (fmt_table, GUINT_TO_POINTER (fmt_preferences [idx])));

			/* Have we found a match yet? */
			if (video_uri != NULL) {
				g_debug ("Using video URI for format %u (connection speed %u)", fmt_preferences[idx], idx);
				break;
			}
		}

		g_hash_table_destroy (fmt_table);
	}

	/* Fallback */
	if (video_uri == NULL) {
		GDataMediaContent *content;

		/* We don't have a match, which is odd; fall back to the FLV URI as advertised by the YouTube API */
		content = GDATA_MEDIA_CONTENT (gdata_youtube_video_look_up_content (GDATA_YOUTUBE_VIDEO (data->entry),
										    "application/x-shockwave-flash"));
		if (content != NULL) {
			video_uri = g_strdup (gdata_media_content_get_uri (content));
			g_debug ("Couldn't find the t param of entry %s; falling back to its FLV URI (\"%s\")", video_id, video_uri);
		} else {
			/* Cop out */
			g_warning ("Couldn't find the t param of entry %s or its FLV URI.", video_uri);
			video_uri = NULL;
		}
	}

	g_match_info_free (match_info);

	/* Update the tree view with the new MRL */
	if (gtk_tree_model_get_iter (GTK_TREE_MODEL (self->list_store[data->tree_view]), &iter, data->path) == TRUE) {
		gtk_list_store_set (self->list_store[data->tree_view], &iter, 2, video_uri, -1);
		g_debug ("Updated list store with new video URI (\"%s\") for entry %s", video_uri, video_id);
	}

	g_free (video_uri);

free_data:
	/* Update the progress bar */
	increment_progress_bar_fraction (self, data->tree_view);

	g_object_unref (data->cancellable);
	g_object_unref (data->plugin);
	g_object_unref (data->entry);
	gtk_tree_path_free (data->path);
	g_slice_free (TParamData, data);
}
Exemplo n.º 11
0
static gboolean
impl_activate (TotemPlugin *plugin,
	       TotemObject *totem,
	       GError **error)
{
	TotemMediaPlayerKeysPlugin *pi = TOTEM_MEDIA_PLAYER_KEYS_PLUGIN (plugin);
	DBusGConnection *connection;
	GError *err = NULL;
	GtkWindow *window;

	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
	if (connection == NULL) {
		g_warning ("Error connecting to D-Bus: %s", err->message);
		return FALSE;
	}

	/* Try the mate-settings-daemon version,
	 * then the mate-control-center version of things */
	pi->media_player_keys_proxy = dbus_g_proxy_new_for_name_owner (connection,
								       "org.mate.SettingsDaemon",
								       "/org/mate/SettingsDaemon/MediaKeys",
								       "org.mate.SettingsDaemon.MediaKeys",
								       NULL);
	if (pi->media_player_keys_proxy == NULL) {
		pi->media_player_keys_proxy = dbus_g_proxy_new_for_name_owner (connection,
									       "org.mate.SettingsDaemon",
									       "/org/mate/SettingsDaemon",
									       "org.mate.SettingsDaemon",
									       &err);
	}

	dbus_g_connection_unref (connection);
	if (err != NULL) {
		gboolean daemon_not_running;
		g_warning ("Failed to create dbus proxy for org.mate.SettingsDaemon: %s",
			   err->message);
		daemon_not_running = (err->code == DBUS_GERROR_NAME_HAS_NO_OWNER);
		g_error_free (err);
		/* don't popup error if settings-daemon is not running,
 		 * ie when starting totem not under MATE desktop */
		return daemon_not_running;
	} else {
		g_signal_connect_object (pi->media_player_keys_proxy,
					 "destroy",
					 G_CALLBACK (proxy_destroy),
					 pi, 0);
	}

	dbus_g_proxy_call (pi->media_player_keys_proxy,
			   "GrabMediaPlayerKeys", NULL,
			   G_TYPE_STRING, "Totem", G_TYPE_UINT, 0, G_TYPE_INVALID,
			   G_TYPE_INVALID);

	dbus_g_object_register_marshaller (totem_marshal_VOID__STRING_STRING,
			G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
	dbus_g_proxy_add_signal (pi->media_player_keys_proxy, "MediaPlayerKeyPressed",
			G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (pi->media_player_keys_proxy, "MediaPlayerKeyPressed",
			G_CALLBACK (on_media_player_key_pressed), totem, NULL);

	window = totem_get_main_window (totem);
	pi->handler_id = g_signal_connect (G_OBJECT (window), "focus-in-event",
			G_CALLBACK (on_window_focus_in_event), pi);

	g_object_unref (G_OBJECT (window));

	return TRUE;
}