static void setup_dnd_targets(gmpv_handle *ctx) { PlaylistWidget *playlist; GtkTargetEntry target_entry[3]; playlist = PLAYLIST_WIDGET(ctx->gui->playlist); target_entry[0].target = "text/uri-list"; target_entry[0].flags = 0; target_entry[0].info = 0; target_entry[1].target = "text/plain"; target_entry[1].flags = 0; target_entry[1].info = 1; target_entry[2].target = "STRING"; target_entry[2].flags = 0; target_entry[2].info = 1; gtk_drag_dest_set( GTK_WIDGET(ctx->gui->vid_area), GTK_DEST_DEFAULT_ALL, target_entry, 3, GDK_ACTION_LINK ); gtk_drag_dest_set( GTK_WIDGET(playlist), GTK_DEST_DEFAULT_ALL, target_entry, 3, GDK_ACTION_COPY ); gtk_drag_dest_add_uri_targets(GTK_WIDGET(ctx->gui->vid_area)); gtk_drag_dest_add_uri_targets(GTK_WIDGET(playlist)); }
static void connect_signals(gmpv_handle *ctx) { PlaylistWidget *playlist = PLAYLIST_WIDGET(ctx->gui->playlist); playbackctl_connect_signals(ctx); if(main_window_get_use_opengl(ctx->gui)) { g_signal_connect( ctx->gui->vid_area, "render", G_CALLBACK(vid_area_render_handler), ctx ); } g_signal_connect( ctx->gui->vid_area, "drag-data-received", G_CALLBACK(drag_data_handler), ctx ); g_signal_connect( ctx->gui->playlist, "drag-data-received", G_CALLBACK(drag_data_handler), ctx ); g_signal_connect( ctx->gui, "draw", G_CALLBACK(draw_handler), ctx ); g_signal_connect( ctx->gui, "delete-event", G_CALLBACK(delete_handler), ctx ); g_signal_connect( ctx->gui, "key-press-event", G_CALLBACK(key_press_handler), ctx ); g_signal_connect( ctx->gui->vid_area, "button-press-event", G_CALLBACK(mouse_press_handler), ctx ); g_signal_connect( playlist->tree_view, "row-activated", G_CALLBACK(playlist_row_handler), ctx ); g_signal_connect( playlist->list_store, "row-inserted", G_CALLBACK(playlist_row_inserted_handler), ctx ); g_signal_connect( playlist->list_store, "row-deleted", G_CALLBACK(playlist_row_deleted_handler), ctx ); }
void remove_current_playlist_entry(gmpv_handle *ctx) { const gchar *cmd[] = {"playlist_remove", NULL, NULL}; PlaylistWidget *playlist; GtkTreePath *path; playlist = PLAYLIST_WIDGET(ctx->gui->playlist); gtk_tree_view_get_cursor ( GTK_TREE_VIEW(playlist->tree_view), &path, NULL ); if(path) { gint index; gchar *index_str; index = gtk_tree_path_get_indices(path)[0]; index_str = g_strdup_printf("%d", index); cmd[1] = index_str; g_signal_handlers_block_matched ( playlist->list_store, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, ctx ); playlist_widget_remove(playlist, index); if(ctx->loaded) { mpv_check_error(mpv_command(ctx->mpv_ctx, cmd)); } if(playlist_widget_empty(playlist)) { control_box_set_enabled (CONTROL_BOX(ctx->gui->control_box), FALSE); } g_signal_handlers_unblock_matched ( playlist->list_store, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, ctx ); g_free(index_str); } }
static gboolean load_files(gpointer data) { gmpv_handle *ctx = data; if(ctx->files) { gint i = 0; ctx->paused = FALSE; playlist_widget_clear(PLAYLIST_WIDGET(ctx->gui->playlist)); for(i = 0; ctx->files[i]; i++) { gchar *name = get_name_from_path(ctx->files[i]); if(ctx->init_load) { playlist_widget_append ( PLAYLIST_WIDGET (ctx->gui->playlist), name, ctx->files[i] ); } else { mpv_load( ctx, ctx->files[i], (i != 0), TRUE ); } g_free(name); } g_strfreev(ctx->files); } return FALSE; }
static void app_startup_handler(GApplication *app, gpointer data) { gmpv_handle *ctx = data; const gchar *vid_area_style = ".gmpv-vid-area{background-color: black}"; GSettingsBackend *config_backend; GtkCssProvider *style_provider; gboolean css_loaded; gboolean use_opengl; gboolean config_migrated; gboolean mpvinput_enable; gboolean csd_enable; gboolean dark_theme_enable; gchar *config_file; gchar *mpvinput; setlocale(LC_NUMERIC, "C"); g_set_application_name(_("GNOME MPV")); gtk_window_set_default_icon_name(ICON_NAME); bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); config_file = get_config_file_path(); config_backend = g_keyfile_settings_backend_new ( config_file, CONFIG_ROOT_PATH, CONFIG_ROOT_GROUP ); use_opengl = get_use_opengl(); ctx->mpv_ctx = mpv_create(); ctx->files = NULL; ctx->opengl_ctx = NULL; ctx->opengl_ready = FALSE; ctx->paused = TRUE; ctx->loaded = FALSE; ctx->new_file = TRUE; ctx->sub_visible = TRUE; ctx->init_load = TRUE; ctx->playlist_move_dest = -1; ctx->log_level_list = NULL; ctx->keybind_list = NULL; ctx->config = g_settings_new_with_backend(APP_ID, config_backend); ctx->app = GTK_APPLICATION(app); ctx->gui = MAIN_WINDOW(main_window_new(ctx->app, use_opengl)); ctx->fs_control = NULL; ctx->playlist_store = PLAYLIST_WIDGET(ctx->gui->playlist)->list_store; config_migrated = migrate_config(ctx); style_provider = gtk_css_provider_new(); css_loaded = gtk_css_provider_load_from_data (style_provider, vid_area_style, -1, NULL); if(!css_loaded) { g_warning ("Failed to apply background color css"); } gtk_style_context_add_provider_for_screen ( gtk_window_get_screen(GTK_WINDOW(ctx->gui)), GTK_STYLE_PROVIDER(style_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION ); g_object_unref(style_provider); csd_enable = g_settings_get_boolean (ctx->config, "csd-enable"); dark_theme_enable = g_settings_get_boolean (ctx->config, "dark-theme-enable"); mpvinput_enable = g_settings_get_boolean (ctx->config, "mpv-input-config-enable"); mpvinput = g_settings_get_string (ctx->config, "mpv-input-config-file"); if(csd_enable) { gtk_application_set_app_menu (ctx->app, G_MENU_MODEL(build_app_menu())); main_window_enable_csd(ctx->gui); } else { gtk_application_set_app_menu (ctx->app, NULL); gtk_application_set_menubar (ctx->app, G_MENU_MODEL(build_full_menu())); } gtk_widget_show_all(GTK_WIDGET(ctx->gui)); if(csd_enable) { control_box_set_fullscreen_btn_visible (CONTROL_BOX(ctx->gui->control_box), FALSE); } control_box_set_chapter_enabled (CONTROL_BOX(ctx->gui->control_box), FALSE); if(!main_window_get_use_opengl(ctx->gui)) { ctx->vid_area_wid = get_xid(ctx->gui->vid_area); } g_assert( main_window_get_use_opengl(ctx->gui) || ctx->vid_area_wid != -1 ); main_window_load_state(ctx->gui); setup_accelerators(ctx); setup_dnd_targets(ctx); actionctl_map_actions(ctx); connect_signals(ctx); load_keybind(ctx, mpvinput_enable?mpvinput:NULL, FALSE); mpris_init(ctx); media_keys_init(ctx); g_object_set( ctx->gui->settings, "gtk-application-prefer-dark-theme", dark_theme_enable, NULL ); g_timeout_add( SEEK_BAR_UPDATE_INTERVAL, (GSourceFunc)update_seek_bar, ctx ); if(config_migrated) { GtkWidget *dialog = gtk_message_dialog_new ( GTK_WINDOW(ctx->gui), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, _("Your configuration file has been " "moved to the new location at %s."), config_file ); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } g_free(config_file); g_free(mpvinput); }
void playlist_save_handler( GSimpleAction *action, GVariant *param, gpointer data ) { gmpv_handle *ctx = data; PlaylistWidget *playlist; GFile *dest_file; GOutputStream *dest_stream; GtkFileChooser *file_chooser; GtkWidget *save_dialog; GError *error; GtkTreeIter iter; gboolean rc; playlist = PLAYLIST_WIDGET(ctx->gui->playlist); dest_file = NULL; dest_stream = NULL; error = NULL; rc = FALSE; save_dialog = gtk_file_chooser_dialog_new( _("Save Playlist"), GTK_WINDOW(ctx->gui), GTK_FILE_CHOOSER_ACTION_SAVE, _("_Cancel"), GTK_RESPONSE_CANCEL, _("_Save"), GTK_RESPONSE_ACCEPT, NULL ); file_chooser = GTK_FILE_CHOOSER(save_dialog); gtk_file_chooser_set_do_overwrite_confirmation(file_chooser, TRUE); gtk_file_chooser_set_current_name(file_chooser, "playlist.m3u"); if(gtk_dialog_run(GTK_DIALOG(save_dialog)) == GTK_RESPONSE_ACCEPT) { /* There should be only one file selected. */ dest_file = gtk_file_chooser_get_file(file_chooser); } gtk_widget_destroy(save_dialog); if(dest_file) { GFileOutputStream *dest_file_stream; dest_file_stream = g_file_replace( dest_file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &error ); dest_stream = G_OUTPUT_STREAM(dest_file_stream); rc = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(playlist->list_store), &iter); rc &= !!dest_stream; } while(rc) { gchar *uri; gsize written; gtk_tree_model_get( GTK_TREE_MODEL(playlist->list_store), &iter, PLAYLIST_URI_COLUMN, &uri, -1 ); rc &= g_output_stream_printf( dest_stream, &written, NULL, &error, "%s\n", uri ); rc &= gtk_tree_model_iter_next (GTK_TREE_MODEL(playlist->list_store), &iter); } if(dest_stream) { g_output_stream_close(dest_stream, NULL, &error); } if(dest_file) { g_object_unref(dest_file); } if(error) { show_error_dialog(ctx, NULL, error->message); g_error_free(error); } }
void playlist_reset(gmpv_handle *ctx) { PlaylistWidget *playlist = PLAYLIST_WIDGET(ctx->gui->playlist); playlist_widget_set_indicator_pos(playlist, 0); }