From 6194255e4ba17aaeb324a5e979245e7a52065c28 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Mon, 30 Aug 2010 20:57:21 +0200 Subject: added resume_last_session option --- main.c | 29 ++++++++++ playlist.c | 11 ++++ playlist.h | 3 ++ plugins/gtkui/callbacks.c | 1 + plugins/gtkui/callbacks.h | 4 ++ plugins/gtkui/deadbeef.glade | 126 +++++++++++++++++++++++++------------------ plugins/gtkui/interface.c | 61 ++++++++++++--------- plugins/gtkui/prefwin.c | 11 ++++ streamer.c | 7 ++- streamer.h | 7 +++ 10 files changed, 182 insertions(+), 78 deletions(-) diff --git a/main.c b/main.c index 3c06e3fa..e412e17e 100644 --- a/main.c +++ b/main.c @@ -67,6 +67,9 @@ #define USE_ABSTRACT_NAME 0 #endif +#define trace(...) { fprintf(stderr, __VA_ARGS__); } +//#define trace(fmt,...) + // some common global variables char confdir[1024]; // $HOME/.config char dbconfdir[1024]; // $HOME/.config/deadbeef @@ -673,9 +676,35 @@ main (int argc, char *argv[]) { streamer_init (); + if (conf_get_int ("resume_last_session", 0) && p_isstopped ()) { + int plt = conf_get_int ("resume.playlist", -1); + int track = conf_get_int ("resume.track", -1); + float pos = conf_get_float ("resume.position", -1); + trace ("resume: track %d pos %f playlist %d\n", track, pos, plt); + if (plt >= 0 && track >= 0 && pos >= 0) { + streamer_set_current_playlist (plt); + streamer_set_seek (pos); + streamer_set_nextsong (track, 3); + } + } + // this runs in main thread (blocks right here) player_mainloop (); + playItem_t *trk = streamer_get_playing_track (); + float playpos = -1; + int playtrack = -1; + int playlist = streamer_get_current_playlist (); + if (trk && playlist >= 0) { + playtrack = str_get_idx_of (trk); + playpos = streamer_get_playpos (); + pl_item_unref (trk); + } + + conf_set_float ("resume.position", playpos); + conf_set_int ("resume.track", playtrack); + conf_set_int ("resume.playlist", playlist); + // save config pl_save_all (); conf_save (); diff --git a/playlist.c b/playlist.c index f5ec9390..71a239cb 100644 --- a/playlist.c +++ b/playlist.c @@ -211,6 +211,17 @@ plt_get_curr_ptr (void) { return playlist; } +playlist_t * +plt_get (int idx) { + playlist_t *p = playlists_head; + for (int i = 0; p && i <= idx; i++, p = p->next) { + if (i == idx) { + return p; + } + } + return NULL; +} + int plt_get_count (void) { return playlists_count; diff --git a/playlist.h b/playlist.h index 00b6183a..d8fdb6c9 100644 --- a/playlist.h +++ b/playlist.h @@ -91,6 +91,9 @@ pl_global_unlock (void); playlist_t * plt_get_curr_ptr (void); +playlist_t * +plt_get (int idx); + int plt_get_count (void); diff --git a/plugins/gtkui/callbacks.c b/plugins/gtkui/callbacks.c index ee9422f7..a152aef5 100644 --- a/plugins/gtkui/callbacks.c +++ b/plugins/gtkui/callbacks.c @@ -1070,3 +1070,4 @@ create_seekbar (gchar *widget_name, gchar *string1, gchar *string2, { return GTK_WIDGET (ddb_seekbar_new ()); } + diff --git a/plugins/gtkui/callbacks.h b/plugins/gtkui/callbacks.h index 9777427d..62d79f38 100644 --- a/plugins/gtkui/callbacks.h +++ b/plugins/gtkui/callbacks.h @@ -971,3 +971,7 @@ gboolean on_statusbar_button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data); + +void +on_resume_last_session_toggled (GtkToggleButton *togglebutton, + gpointer user_data); diff --git a/plugins/gtkui/deadbeef.glade b/plugins/gtkui/deadbeef.glade index be214120..c2dd31f0 100644 --- a/plugins/gtkui/deadbeef.glade +++ b/plugins/gtkui/deadbeef.glade @@ -2684,6 +2684,79 @@ Album False + + + + True + False + 8 + + + + True + True + Add files from command line (or file manager) to this playlist: + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + 0 + False + False + + + + + + True + True + True + True + 0 + + True + + False + + + + 0 + True + True + + + + + 0 + False + False + + + + + + True + True + Resume previous session on startup + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + 0 + False + False + + False @@ -2694,7 +2767,7 @@ Album True - Sound (adv.) + Playback False False GTK_JUSTIFY_LEFT @@ -2938,56 +3011,7 @@ Album - - True - False - 8 - - - - True - True - Add files from command line (or file manager) to this playlist: - True - GTK_RELIEF_NORMAL - True - False - False - True - - - - 0 - False - False - - - - - - True - True - True - True - 0 - - True - - False - - - - 0 - True - True - - - - - 0 - False - False - + diff --git a/plugins/gtkui/interface.c b/plugins/gtkui/interface.c index 61521323..e6f59396 100644 --- a/plugins/gtkui/interface.c +++ b/plugins/gtkui/interface.c @@ -1554,6 +1554,10 @@ create_prefwin (void) GtkWidget *label8; GtkWidget *pref_replaygain_mode; GtkWidget *pref_replaygain_scale; + GtkWidget *hbox66; + GtkWidget *cli_add_to_playlist; + GtkWidget *cli_playlist_name; + GtkWidget *resume_last_session; GtkWidget *label39; GtkWidget *vbox9; GtkWidget *pref_close_send_to_tray; @@ -1567,9 +1571,6 @@ create_prefwin (void) GtkWidget *hbox65; GtkWidget *label102; GtkWidget *titlebar_format_stopped; - GtkWidget *hbox66; - GtkWidget *cli_add_to_playlist; - GtkWidget *cli_playlist_name; GtkWidget *label2; GtkWidget *notebook4; GtkWidget *vbox21; @@ -1796,7 +1797,24 @@ create_prefwin (void) gtk_widget_show (pref_replaygain_scale); gtk_box_pack_start (GTK_BOX (vbox8), pref_replaygain_scale, FALSE, FALSE, 0); - label39 = gtk_label_new (_("Sound (adv.)")); + hbox66 = gtk_hbox_new (FALSE, 8); + gtk_widget_show (hbox66); + gtk_box_pack_start (GTK_BOX (vbox8), hbox66, FALSE, FALSE, 0); + + cli_add_to_playlist = gtk_check_button_new_with_mnemonic (_("Add files from command line (or file manager) to this playlist:")); + gtk_widget_show (cli_add_to_playlist); + gtk_box_pack_start (GTK_BOX (hbox66), cli_add_to_playlist, FALSE, FALSE, 0); + + cli_playlist_name = gtk_entry_new (); + gtk_widget_show (cli_playlist_name); + gtk_box_pack_start (GTK_BOX (hbox66), cli_playlist_name, TRUE, TRUE, 0); + gtk_entry_set_invisible_char (GTK_ENTRY (cli_playlist_name), 9679); + + resume_last_session = gtk_check_button_new_with_mnemonic (_("Resume previous session on startup")); + gtk_widget_show (resume_last_session); + gtk_box_pack_start (GTK_BOX (vbox8), resume_last_session, FALSE, FALSE, 0); + + label39 = gtk_label_new (_("Playback")); gtk_widget_show (label39); gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 1), label39); @@ -1853,19 +1871,6 @@ create_prefwin (void) gtk_box_pack_start (GTK_BOX (hbox65), titlebar_format_stopped, TRUE, TRUE, 0); gtk_entry_set_invisible_char (GTK_ENTRY (titlebar_format_stopped), 8226); - hbox66 = gtk_hbox_new (FALSE, 8); - gtk_widget_show (hbox66); - gtk_box_pack_start (GTK_BOX (vbox9), hbox66, FALSE, FALSE, 0); - - cli_add_to_playlist = gtk_check_button_new_with_mnemonic (_("Add files from command line (or file manager) to this playlist:")); - gtk_widget_show (cli_add_to_playlist); - gtk_box_pack_start (GTK_BOX (hbox66), cli_add_to_playlist, FALSE, FALSE, 0); - - cli_playlist_name = gtk_entry_new (); - gtk_widget_show (cli_playlist_name); - gtk_box_pack_start (GTK_BOX (hbox66), cli_playlist_name, TRUE, TRUE, 0); - gtk_entry_set_invisible_char (GTK_ENTRY (cli_playlist_name), 9679); - label2 = gtk_label_new (_("GUI")); gtk_widget_show (label2); gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 2), label2); @@ -2505,6 +2510,15 @@ create_prefwin (void) g_signal_connect ((gpointer) pref_replaygain_scale, "clicked", G_CALLBACK (on_pref_replaygain_scale_clicked), NULL); + g_signal_connect ((gpointer) cli_add_to_playlist, "toggled", + G_CALLBACK (on_cli_add_to_playlist_toggled), + NULL); + g_signal_connect ((gpointer) cli_playlist_name, "changed", + G_CALLBACK (on_cli_playlist_name_changed), + NULL); + g_signal_connect ((gpointer) resume_last_session, "toggled", + G_CALLBACK (on_resume_last_session_toggled), + NULL); g_signal_connect ((gpointer) pref_close_send_to_tray, "clicked", G_CALLBACK (on_pref_close_send_to_tray_clicked), NULL); @@ -2526,12 +2540,6 @@ create_prefwin (void) g_signal_connect ((gpointer) titlebar_format_stopped, "changed", G_CALLBACK (on_titlebar_format_stopped_changed), NULL); - g_signal_connect ((gpointer) cli_add_to_playlist, "toggled", - G_CALLBACK (on_cli_add_to_playlist_toggled), - NULL); - g_signal_connect ((gpointer) cli_playlist_name, "changed", - G_CALLBACK (on_cli_playlist_name_changed), - NULL); g_signal_connect ((gpointer) override_bar_colors, "toggled", G_CALLBACK (on_override_bar_colors_toggled), NULL); @@ -2671,6 +2679,10 @@ create_prefwin (void) GLADE_HOOKUP_OBJECT (prefwin, label8, "label8"); GLADE_HOOKUP_OBJECT (prefwin, pref_replaygain_mode, "pref_replaygain_mode"); GLADE_HOOKUP_OBJECT (prefwin, pref_replaygain_scale, "pref_replaygain_scale"); + GLADE_HOOKUP_OBJECT (prefwin, hbox66, "hbox66"); + GLADE_HOOKUP_OBJECT (prefwin, cli_add_to_playlist, "cli_add_to_playlist"); + GLADE_HOOKUP_OBJECT (prefwin, cli_playlist_name, "cli_playlist_name"); + GLADE_HOOKUP_OBJECT (prefwin, resume_last_session, "resume_last_session"); GLADE_HOOKUP_OBJECT (prefwin, label39, "label39"); GLADE_HOOKUP_OBJECT (prefwin, vbox9, "vbox9"); GLADE_HOOKUP_OBJECT (prefwin, pref_close_send_to_tray, "pref_close_send_to_tray"); @@ -2684,9 +2696,6 @@ create_prefwin (void) GLADE_HOOKUP_OBJECT (prefwin, hbox65, "hbox65"); GLADE_HOOKUP_OBJECT (prefwin, label102, "label102"); GLADE_HOOKUP_OBJECT (prefwin, titlebar_format_stopped, "titlebar_format_stopped"); - GLADE_HOOKUP_OBJECT (prefwin, hbox66, "hbox66"); - GLADE_HOOKUP_OBJECT (prefwin, cli_add_to_playlist, "cli_add_to_playlist"); - GLADE_HOOKUP_OBJECT (prefwin, cli_playlist_name, "cli_playlist_name"); GLADE_HOOKUP_OBJECT (prefwin, label2, "label2"); GLADE_HOOKUP_OBJECT (prefwin, notebook4, "notebook4"); GLADE_HOOKUP_OBJECT (prefwin, vbox21, "vbox21"); diff --git a/plugins/gtkui/prefwin.c b/plugins/gtkui/prefwin.c index 633d0803..d206e362 100644 --- a/plugins/gtkui/prefwin.c +++ b/plugins/gtkui/prefwin.c @@ -522,6 +522,9 @@ on_preferences_activate (GtkMenuItem *menuitem, gtk_widget_set_sensitive (lookup_widget (prefwin, "cli_playlist_name"), active); gtk_entry_set_text (GTK_ENTRY (lookup_widget (prefwin, "cli_playlist_name")), deadbeef->conf_get_str ("cli_add_playlist_name", "Default")); + // resume last session + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (lookup_widget (w, "resume_last_session")), deadbeef->conf_get_int ("resume_last_session", 0)); + // override bar colors int override = deadbeef->conf_get_int ("gtkui.override_bar_colors", 0); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (lookup_widget (prefwin, "override_bar_colors")), override); @@ -1300,3 +1303,11 @@ on_cli_playlist_name_changed (GtkEditable *editable, deadbeef->conf_set_str ("cli_add_playlist_name", gtk_entry_get_text (GTK_ENTRY (editable))); } +void +on_resume_last_session_toggled (GtkToggleButton *togglebutton, + gpointer user_data) +{ + int active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (togglebutton)); + deadbeef->conf_set_int ("resume_last_session", active); +} + diff --git a/streamer.c b/streamer.c index c06391e5..96748312 100644 --- a/streamer.c +++ b/streamer.c @@ -714,7 +714,7 @@ streamer_set_nextsong (int song, int pstate) { // no sense to wait until end of previous song, reset buffer bytes_until_next_song = 0; playpos = 0; - seekpos = -1; +// seekpos = -1; } } @@ -1702,6 +1702,11 @@ streamer_get_current_fileinfo (void) { return fileinfo; } +void +streamer_set_current_playlist (int plt) { + streamer_playlist = plt_get (plt); +} + int streamer_get_current_playlist (void) { if (!streamer_playlist) { diff --git a/streamer.h b/streamer.h index e3a35127..3bcdbe49 100644 --- a/streamer.h +++ b/streamer.h @@ -98,9 +98,16 @@ streamer_move_to_randomsong (void); struct DB_fileinfo_s * streamer_get_current_fileinfo (void); +void +streamer_set_current_playlist (int plt); + int streamer_get_current_playlist (void); +// returns track index in current streamer playlist +int +str_get_idx_of (playItem_t *it); + void streamer_notify_playlist_deleted (playlist_t *plt); -- cgit v1.2.3