Skip to content

Commit

Permalink
added resume_last_session option
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksiy-Yakovenko committed Aug 30, 2010
1 parent 4084705 commit 6194255
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 78 deletions.
29 changes: 29 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ();
Expand Down
11 changes: 11 additions & 0 deletions playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions plugins/gtkui/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1070,3 +1070,4 @@ create_seekbar (gchar *widget_name, gchar *string1, gchar *string2,
{
return GTK_WIDGET (ddb_seekbar_new ());
}

4 changes: 4 additions & 0 deletions plugins/gtkui/callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
126 changes: 75 additions & 51 deletions plugins/gtkui/deadbeef.glade
Original file line number Diff line number Diff line change
Expand Up @@ -2684,6 +2684,79 @@ Album</property>
<property name="fill">False</property>
</packing>
</child>

<child>
<widget class="GtkHBox" id="hbox66">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">8</property>

<child>
<widget class="GtkCheckButton" id="cli_add_to_playlist">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Add files from command line (or file manager) to this playlist:</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_cli_add_to_playlist_toggled" last_modification_time="Thu, 12 Aug 2010 19:12:26 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>

<child>
<widget class="GtkEntry" id="cli_playlist_name">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">●</property>
<property name="activates_default">False</property>
<signal name="changed" handler="on_cli_playlist_name_changed" last_modification_time="Thu, 12 Aug 2010 19:12:30 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>

<child>
<widget class="GtkCheckButton" id="resume_last_session">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Resume previous session on startup</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_resume_last_session_toggled" last_modification_time="Mon, 30 Aug 2010 18:39:14 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
<packing>
<property name="tab_expand">False</property>
Expand All @@ -2694,7 +2767,7 @@ Album</property>
<child>
<widget class="GtkLabel" id="label39">
<property name="visible">True</property>
<property name="label" translatable="yes">Sound (adv.)</property>
<property name="label" translatable="yes">Playback</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
Expand Down Expand Up @@ -2938,56 +3011,7 @@ Album</property>
</child>

<child>
<widget class="GtkHBox" id="hbox66">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">8</property>

<child>
<widget class="GtkCheckButton" id="cli_add_to_playlist">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Add files from command line (or file manager) to this playlist:</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_cli_add_to_playlist_toggled" last_modification_time="Thu, 12 Aug 2010 19:12:26 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>

<child>
<widget class="GtkEntry" id="cli_playlist_name">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">●</property>
<property name="activates_default">False</property>
<signal name="changed" handler="on_cli_playlist_name_changed" last_modification_time="Thu, 12 Aug 2010 19:12:30 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
<placeholder/>
</child>
</widget>
<packing>
Expand Down
61 changes: 35 additions & 26 deletions plugins/gtkui/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down
11 changes: 11 additions & 0 deletions plugins/gtkui/prefwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

7 changes: 6 additions & 1 deletion streamer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 6194255

Please sign in to comment.