void ol_player_chooser_set_info_by_state (OlPlayerChooser *window, enum OlPlayerChooserState state) { ol_assert (OL_IS_PLAYER_CHOOSER (window)); OlPlayerChooserPrivate *priv = OL_PLAYER_CHOOSER_GET_PRIVATE (window); _set_sensitive (window, TRUE); switch (state) { case OL_PLAYER_CHOOSER_STATE_NO_PLAYER: ol_player_chooser_set_info (window, _("There is no supported player running"), _("Please choose a player below to launch")); ol_player_chooser_set_image_by_name (window, GTK_STOCK_DIALOG_INFO); break; case OL_PLAYER_CHOOSER_STATE_LAUNCH_FAIL: { gchar *title = g_strdup_printf (_("Failed to connect to %s"), g_app_info_get_name (priv->launch_app)); gchar *desc = g_strdup_printf (_("%s is not supported by OSD Lyrics, or not running. Please launch another player"), g_app_info_get_name (priv->launch_app)); ol_player_chooser_set_info (window, title, desc); ol_player_chooser_set_image_by_name (window, GTK_STOCK_DIALOG_ERROR); g_free (title); g_free (desc); _set_launch_app (window, NULL); break; } case OL_PLAYER_CHOOSER_STATE_CONNECTED: gtk_widget_hide (GTK_WIDGET (window)); break; default: ol_errorf ("Unknown player chooser state %d\n", (int) state); } }
void ol_player_chooser_set_image_by_gicon (OlPlayerChooser *window, GIcon *icon) { ol_assert (OL_IS_PLAYER_CHOOSER (window)); ol_assert (G_IS_ICON (icon)); OlPlayerChooserPrivate *priv = OL_PLAYER_CHOOSER_GET_PRIVATE (window); gtk_image_set_from_gicon (priv->info_icon, icon, GTK_ICON_SIZE_DIALOG); }
void ol_player_chooser_set_image_by_name (OlPlayerChooser *window, const char *icon_name) { ol_assert (OL_IS_PLAYER_CHOOSER (window)); ol_assert (icon_name != NULL); OlPlayerChooserPrivate *priv = OL_PLAYER_CHOOSER_GET_PRIVATE (window); gtk_image_set_from_icon_name (priv->info_icon, icon_name, GTK_ICON_SIZE_DIALOG); }
static void _remember_cmd_if_needed (OlPlayerChooser *window, const char *cmd) { ol_assert (OL_IS_PLAYER_CHOOSER (window)); OlPlayerChooserPrivate *priv = OL_PLAYER_CHOOSER_GET_PRIVATE (window); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->remember_button))) { OlConfigProxy *config = ol_config_proxy_get_instance (); ol_config_proxy_set_string (config, "General/startup-player", cmd); } }
void ol_player_chooser_set_info (OlPlayerChooser *window, const char *info, const char *description) { ol_assert (OL_IS_PLAYER_CHOOSER (window)); ol_assert (info != NULL); OlPlayerChooserPrivate *priv = OL_PLAYER_CHOOSER_GET_PRIVATE (window); gchar *text; if (description != NULL) text = g_strdup_printf ("%s\n\n%s", info, description); else text = g_strdup (info); gtk_label_set_text (priv->info_label, text); g_free (text); }
static void _launch_button_clicked_cb (GtkButton *button, OlPlayerChooser *window) { ol_assert (OL_IS_PLAYER_CHOOSER (window)); OlPlayerChooserPrivate *priv = OL_PLAYER_CHOOSER_GET_PRIVATE (window); const char *cmd = gtk_entry_get_text (priv->cmd_entry); if (ol_is_string_empty (cmd)) return; GAppInfo *app_info = G_APP_INFO (ol_app_info_new (cmd, NULL, NULL, OL_APP_INFO_PREFER_DESKTOP_FILE, NULL)); _launch_app (window, app_info); g_object_unref (app_info); }
static void _set_supported_players (OlPlayerChooser *window, GList *supported_players) { ol_assert (OL_IS_PLAYER_CHOOSER (window)); _set_apps_to_page (window, SUPPORT_CHOOSER_INDEX, supported_players); if (supported_players != NULL) { _show_page_by_index (window, SUPPORT_CHOOSER_INDEX); } else { _show_page_by_index (window, ALL_CHOOSER_INDEX); } }
static void _launch_app (OlPlayerChooser *window, GAppInfo *app_info) { GError *err = NULL; if (!g_app_info_launch (app_info, NULL, NULL, &err)) { ol_errorf ("Cannot launch %s: %s", g_app_info_get_commandline (app_info), err->message); gchar *title = g_strdup_printf (_("Failed to launch %s"), g_app_info_get_name (app_info)); ol_player_chooser_set_info (window, title, err->message); ol_player_chooser_set_image_by_name (window, GTK_STOCK_DIALOG_ERROR); g_free (title); g_error_free (err); } else { _set_launch_app (window, app_info); gchar *title = g_strdup_printf (_("Launching %s"), g_app_info_get_name (app_info)); gchar *desc = g_strdup_printf (_("OSD Lyrics is trying to launch and connect to %s. Please wait for a second."), g_app_info_get_name (app_info)); ol_player_chooser_set_info (window, title, desc); g_free (title); g_free (desc); ol_player_chooser_set_image_by_gicon (window, g_app_info_get_icon (app_info)); _set_sensitive (window, FALSE); if (OL_IS_PLAYER_CHOOSER (window)) { _remember_cmd_if_needed (window, g_app_info_get_commandline (app_info)); gtk_dialog_response (GTK_DIALOG (window), OL_PLAYER_CHOOSER_RESPONSE_LAUNCH); } } }