Skip to content

Commit

Permalink
Use GApplication::shutdown to save playlist state and stop playback i…
Browse files Browse the repository at this point in the history
…n proper order.
  • Loading branch information
matiasdelellis committed Apr 10, 2014
1 parent 04eda64 commit b99cf42
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
7 changes: 3 additions & 4 deletions src/pragha-playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -3117,7 +3117,7 @@ pragha_playlist_get_selected_musicobject(PraghaPlaylist* cplaylist)

/* Save current playlist state on exit */

static void
void
pragha_playlist_save_playlist_state (PraghaPlaylist* cplaylist)
{
GtkTreePath *path = NULL;
Expand Down Expand Up @@ -3198,7 +3198,8 @@ static void init_playlist_current_playlist(PraghaPlaylist *cplaylist)
}
}

void init_current_playlist_view(PraghaPlaylist *cplaylist)
void
pragha_playlist_init_playlist_state (PraghaPlaylist *cplaylist)
{
gchar *ref = NULL;
GtkTreePath *path = NULL;
Expand Down Expand Up @@ -4428,8 +4429,6 @@ pragha_playlist_unrealize (GtkWidget *widget)
{
PraghaPlaylist *playlist = PRAGHA_PLAYLIST (widget);

if (pragha_preferences_get_restore_playlist (playlist->preferences))
pragha_playlist_save_playlist_state (playlist);
pragha_playlist_save_preferences (playlist);

(*GTK_WIDGET_CLASS (pragha_playlist_parent_class)->unrealize) (widget);
Expand Down
5 changes: 3 additions & 2 deletions src/pragha-playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ pragha_playlist_already_has_title_of_artist(PraghaPlaylist *cplaylist,
GList *pragha_playlist_get_mobj_list(PraghaPlaylist* cplaylist);
GList *pragha_playlist_get_selection_mobj_list(PraghaPlaylist* cplaylist);
GList *pragha_playlist_get_selection_ref_list(PraghaPlaylist *cplaylist);
PraghaMusicobject *pragha_playlist_get_selected_musicobject(PraghaPlaylist* cplaylist);
void init_current_playlist_view(PraghaPlaylist *cplaylist);

void pragha_playlist_save_playlist_state (PraghaPlaylist* cplaylist);
void pragha_playlist_init_playlist_state (PraghaPlaylist* cplaylist);
PraghaMusicobject *pragha_playlist_get_selected_musicobject(PraghaPlaylist* cplaylist);
gboolean pragha_playlist_propagate_event(PraghaPlaylist* cplaylist, GdkEventKey *event);

void pragha_playlist_activate_path (PraghaPlaylist* cplaylist, GtkTreePath *path);
Expand Down
2 changes: 1 addition & 1 deletion src/pragha-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
static void
pragha_session_quit (XfceSMClient *sm_client, PraghaApplication *pragha)
{
gtk_main_quit();
pragha_application_quit (pragha);
}

static void
Expand Down
2 changes: 1 addition & 1 deletion src/pragha-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ void pragha_init_gui_state (PraghaApplication *pragha)
preferences = pragha_application_get_preferences (pragha);
if (pragha_preferences_get_restore_playlist (preferences)) {
playlist = pragha_application_get_playlist (pragha);
init_current_playlist_view (playlist);
pragha_playlist_init_playlist_state (playlist);
}

if (info_bar_import_music_will_be_useful(pragha)) {
Expand Down
21 changes: 18 additions & 3 deletions src/pragha.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,6 @@ pragha_application_dispose (GObject *object)
pragha->setting_dialog = NULL;
}
if (pragha->backend) {
pragha_playback_stop (pragha);
g_object_unref (pragha->backend);
pragha->backend = NULL;
}
Expand Down Expand Up @@ -704,11 +703,28 @@ pragha_application_startup (GApplication *application)
pragha_init_gui_state (pragha);
}

static void
pragha_application_shutdown (GApplication *application)
{
PraghaApplication *pragha = PRAGHA_APPLICATION (application);

CDEBUG(DBG_INFO, "Pragha shutdown: Saving curret state.");

if (pragha_preferences_get_restore_playlist (pragha->preferences))
pragha_playlist_save_playlist_state (pragha->playlist);

pragha_playback_stop (pragha);

G_APPLICATION_CLASS (pragha_application_parent_class)->shutdown (application);
}

static void
pragha_application_activate (GApplication *application)
{
PraghaApplication *pragha = PRAGHA_APPLICATION (application);

CDEBUG(DBG_INFO, G_STRFUNC);

gtk_window_present (GTK_WINDOW (pragha->mainwindow));
}

Expand Down Expand Up @@ -769,8 +785,6 @@ pragha_application_local_command_line (GApplication *application, gchar ***argum
return FALSE;
}

//TODO consider use of GApplication::shutdown to save preferences and playlist

void
pragha_application_quit (PraghaApplication *pragha)
{
Expand All @@ -786,6 +800,7 @@ pragha_application_class_init (PraghaApplicationClass *class)
object_class->dispose = pragha_application_dispose;

application_class->startup = pragha_application_startup;
application_class->shutdown = pragha_application_shutdown;
application_class->activate = pragha_application_activate;
application_class->open = pragha_application_open;
application_class->command_line = pragha_application_command_line;
Expand Down

0 comments on commit b99cf42

Please sign in to comment.