diff options
author | Alexey Yakovenko <wakeroid@gmail.com> | 2010-04-06 19:27:21 +0200 |
---|---|---|
committer | Alexey Yakovenko <wakeroid@gmail.com> | 2010-04-06 19:27:21 +0200 |
commit | 80f7aa0cfe21fc2715af029cc5bea6e8b4e18a5f (patch) | |
tree | 9df38c9c686e3f803fdb74492f89677b2ea8704a | |
parent | 40522448588f63d6d72ef775e0340b7fae548a05 (diff) |
added auto-saving config/playlist files
-rw-r--r-- | deadbeef.h | 3 | ||||
-rw-r--r-- | main.c | 4 | ||||
-rw-r--r-- | playlist.c | 40 | ||||
-rw-r--r-- | playlist.h | 3 | ||||
-rw-r--r-- | plugins.c | 9 | ||||
-rw-r--r-- | plugins/gtkui/ddbtabstrip.c | 8 | ||||
-rw-r--r-- | plugins/gtkui/fileman.c | 3 |
7 files changed, 66 insertions, 4 deletions
@@ -357,6 +357,8 @@ typedef struct { void (*pl_clear) (void); int (*pl_load) (const char *name); int (*pl_save) (const char *name); + int (*pl_save_current) (void); + int (*pl_save_all) (void); void (*pl_select_all) (void); void (*pl_crop_selected) (void); int (*pl_getselcount) (void); @@ -475,6 +477,7 @@ typedef struct { void (*conf_set_float) (const char *key, float val); DB_conf_item_t * (*conf_find) (const char *group, DB_conf_item_t *prev); void (*conf_remove_items) (const char *key); + int (*conf_save) (void); // plugin communication struct DB_decoder_s **(*plug_get_decoder_list) (void); struct DB_output_s **(*plug_get_output_list) (void); @@ -344,6 +344,7 @@ player_mainloop (void) { switch (msg) { case M_REINIT_SOUND: plug_reinit_sound (); + conf_save (); break; case M_TERMINATE: return; @@ -387,10 +388,11 @@ player_mainloop (void) { streamer_move_to_randomsong (); break; case M_PLAYLISTREFRESH: + pl_save_current (); plug_trigger_event_playlistchanged (); break; case M_CONFIGCHANGED: - //plug_get_output ()->configchanged (); + conf_save (); streamer_configchanged (); plug_trigger_event (DB_EV_CONFIGCHANGED, 0); break; @@ -269,6 +269,14 @@ plt_add (int before, const char *title) { if (!playlist) { playlist = plt; + if (!plt_loading) { + // need to delete old playlist file if exists + char path[PATH_MAX]; + if (snprintf (path, sizeof (path), "%s/playlists/%d.dbpl", dbconfdir, playlists_count-1) <= sizeof (path)) { + unlink (path); + } + pl_save_current (); + } } PLT_UNLOCK; @@ -351,6 +359,8 @@ plt_set_curr (int plt) { playlist = p; if (!plt_loading) { plug_trigger_event (DB_EV_PLAYLISTSWITCH, 0); + conf_set_int ("playlist.current", plt_get_curr ()); + conf_save (); } } PLT_UNLOCK; @@ -1714,8 +1724,34 @@ save_fail: } int +pl_save_current (void) { + char path[PATH_MAX]; + if (snprintf (path, sizeof (path), "%s/playlists", dbconfdir) > sizeof (path)) { + fprintf (stderr, "error: failed to make path string for playlists folder\n"); + return -1; + } + // make folder + mkdir (path, 0755); + + PLT_LOCK; + int curr = plt_get_curr (); + int err = 0; + + plt_loading = 1; + if (snprintf (path, sizeof (path), "%s/playlists/%d.dbpl", dbconfdir, curr) > sizeof (path)) { + fprintf (stderr, "error: failed to make path string for playlist file\n"); + PLT_UNLOCK; + return -1; + } + err = pl_save (path); + plt_loading = 0; + PLT_UNLOCK; + return err; +} + +int pl_save_all (void) { - char path[1024]; + char path[PATH_MAX]; if (snprintf (path, sizeof (path), "%s/playlists", dbconfdir) > sizeof (path)) { fprintf (stderr, "error: failed to make path string for playlists folder\n"); return -1; @@ -1734,7 +1770,7 @@ pl_save_all (void) { for (i = 0; i < cnt; i++, p = p->next) { plt_set_curr (i); if (snprintf (path, sizeof (path), "%s/playlists/%d.dbpl", dbconfdir, i) > sizeof (path)) { - fprintf (stderr, "error: failed to make path string for playlists folder\n"); + fprintf (stderr, "error: failed to make path string for playlist file\n"); err = -1; break; } @@ -209,6 +209,9 @@ int pl_save (const char *fname); int +pl_save_current (void); + +int pl_save_all (void); int @@ -147,6 +147,8 @@ static DB_functions_t deadbeef_api = { .pl_clear = pl_clear, .pl_load = pl_load, .pl_save = pl_save, + .pl_save_current = pl_save_current, + .pl_save_all = pl_save_all, .pl_select_all = pl_select_all, .pl_crop_selected = pl_crop_selected, .pl_getselcount = pl_getselcount, @@ -230,6 +232,7 @@ static DB_functions_t deadbeef_api = { .conf_set_float = conf_set_float, .conf_find = conf_find, .conf_remove_items = conf_remove_items, + .conf_save = conf_save, // plugin communication .plug_get_decoder_list = plug_get_decoder_list, .plug_get_output_list = plug_get_output_list, @@ -422,11 +425,17 @@ plug_event_call (DB_event_t *ev) { ev->time = time (NULL); // printf ("plug_event_call enter %d\n", ev->event); mutex_lock (mutex); + for (int i = 0; i < MAX_HANDLERS; i++) { if (handlers[ev->event][i].plugin && !handlers[ev->event][i].plugin->inactive) { handlers[ev->event][i].callback (ev, handlers[ev->event][i].data); } } +// if (ev->event == DB_EV_PLAYLISTSWITCH) { +// printf ("DB_EV_PLAYLISTSWITCH %d %d\n", plt_get_curr (), conf_get_int ("playlist.current", 0)); +// pl_save_current (); +// } + mutex_unlock (mutex); // printf ("plug_event_call leave %d\n", ev->event); } diff --git a/plugins/gtkui/ddbtabstrip.c b/plugins/gtkui/ddbtabstrip.c index 8d9b6675..98ec3f1a 100644 --- a/plugins/gtkui/ddbtabstrip.c +++ b/plugins/gtkui/ddbtabstrip.c @@ -201,6 +201,8 @@ static int tab_overlap_size = 0; // widget_height/2 static int tabs_left_margin = 4; static int min_tab_size = 80; +static int tab_moved = 0; + void ddb_tabstrip_draw_tab (GtkWidget *widget, GdkDrawable *drawable, int selected, int x, int y, int w, int h) { GdkPoint points_filled[] = { @@ -452,6 +454,7 @@ on_tabstrip_button_press_event (GtkWidget *widget, ts->prepare = 1; ts->dragging = tab_clicked; ts->prev_x = event->x; + tab_moved = 0; } else if (event->button == 3) { GtkWidget *menu = create_plmenu (); @@ -481,6 +484,10 @@ on_tabstrip_button_release_event (GtkWidget *widget, ts->prepare = 0; tabstrip_render (ts); tabstrip_expose (ts, 0, 0, widget->allocation.width, widget->allocation.height); + if (tab_moved) { + deadbeef->pl_save_all (); + deadbeef->conf_save (); + } } } return FALSE; @@ -558,6 +565,7 @@ on_tabstrip_motion_notify_event (GtkWidget *widget, snprintf (str2, sizeof (str2), "playlist.scroll.%d", inspos); pos2 = deadbeef->conf_get_int (str2, 0); deadbeef->plt_move (ts->dragging, inspos); + tab_moved = 1; deadbeef->conf_set_int (str1, pos2); deadbeef->conf_set_int (str2, pos1); ts->dragging = inspos; diff --git a/plugins/gtkui/fileman.c b/plugins/gtkui/fileman.c index 1ae8b4aa..8ef81238 100644 --- a/plugins/gtkui/fileman.c +++ b/plugins/gtkui/fileman.c @@ -32,7 +32,8 @@ gtkpl_add_file_info_cb (DB_playItem_t *it, void *data) { static gboolean progress_hide_idle (gpointer data) { progress_hide (); - playlist_refresh (); + deadbeef->sendmessage (M_PLAYLISTREFRESH, 0, 0, 0); + //playlist_refresh (); return FALSE; } |