Mercurial > audlegacy
comparison src/audacious/main.c @ 3481:308e5fb348db trunk
Save extra playlists on exit
author | Kieran Clancy <clancy.kieran+audacious@gmail.com> |
---|---|
date | Mon, 10 Sep 2007 14:42:59 +0930 |
parents | 3f4ad59a5c02 |
children | 56e2a8704164 |
comparison
equal
deleted
inserted
replaced
3480:3f4ad59a5c02 | 3481:308e5fb348db |
---|---|
674 /* at least one of these should be true */ | 674 /* at least one of these should be true */ |
675 if ((!cfg.get_info_on_demand) && (!cfg.get_info_on_load)) | 675 if ((!cfg.get_info_on_demand) && (!cfg.get_info_on_load)) |
676 cfg.get_info_on_demand = TRUE; | 676 cfg.get_info_on_demand = TRUE; |
677 } | 677 } |
678 | 678 |
679 static gboolean | |
680 save_extra_playlist(const gchar * path, const gchar * basename, | |
681 gpointer savedlist) | |
682 { | |
683 GList *playlists, *iter; | |
684 GList **saved; | |
685 Playlist *playlist; | |
686 int found; | |
687 gchar *filename; | |
688 | |
689 playlists = playlist_get_playlists(); | |
690 saved = (GList **) savedlist; | |
691 | |
692 found = 0; | |
693 for (iter = playlists; iter; iter = iter->next) { | |
694 playlist = (Playlist *) iter->data; | |
695 if (g_list_find(*saved, playlist)) continue; | |
696 filename = playlist_filename_get(playlist); | |
697 if (!filename) continue; | |
698 if (strcmp(filename, path) == 0) { | |
699 /* Save playlist */ | |
700 playlist_save(playlist, path); | |
701 *saved = g_list_prepend(*saved, playlist); | |
702 found = 1; | |
703 g_free(filename); | |
704 break; | |
705 } | |
706 g_free(filename); | |
707 } | |
708 | |
709 if(!found) { | |
710 /* Remove playlist */ | |
711 unlink(path); | |
712 } | |
713 | |
714 return FALSE; /* process other playlists */ | |
715 } | |
716 | |
717 static void | |
718 save_other_playlists(GList *saved) | |
719 { | |
720 GList *playlists, *iter; | |
721 Playlist *playlist; | |
722 gchar *pos, *ext, *basename, *filename, *newbasename; | |
723 int i, num, isdigits; | |
724 | |
725 playlists = playlist_get_playlists(); | |
726 for(iter = playlists; iter; iter = iter->next) { | |
727 playlist = (Playlist *) iter->data; | |
728 if (g_list_find(saved, playlist)) continue; | |
729 filename = playlist_filename_get(playlist); | |
730 if (!filename || !filename[0] | |
731 || g_file_test(filename, G_FILE_TEST_IS_DIR)) { | |
732 /* default basename */ | |
733 #ifdef HAVE_XSPF_PLAYLIST | |
734 basename = g_strdup("playlist_01.xspf"); | |
735 #else | |
736 basename = g_strdup("playlist_01.m3u"); | |
737 #endif | |
738 } else { | |
739 basename = g_path_get_basename(filename); | |
740 } | |
741 g_free(filename); | |
742 if ((pos = strrchr(basename, '.'))) { | |
743 *pos = '\0'; | |
744 } | |
745 #ifdef HAVE_XSPF_PLAYLIST | |
746 ext = ".xspf"; | |
747 #else | |
748 ext = ".m3u"; | |
749 #endif | |
750 num = -1; | |
751 if ((pos = strrchr(basename, '_'))) { | |
752 isdigits = 0; | |
753 for (i=1; pos[i]; i++) { | |
754 if (!g_ascii_isdigit(pos[i])) { | |
755 isdigits = 0; | |
756 break; | |
757 } | |
758 isdigits = 1; | |
759 } | |
760 if (isdigits) { | |
761 num = atoi(pos+1) + 1; | |
762 *pos = '\0'; | |
763 } | |
764 } | |
765 /* attempt to generate unique filename */ | |
766 filename = NULL; | |
767 do { | |
768 g_free(filename); | |
769 if (num < 0) { | |
770 /* try saving without number first */ | |
771 newbasename = g_strdup_printf("%s%s", basename, ext); | |
772 num = 1; | |
773 } else { | |
774 newbasename = g_strdup_printf("%s_%02d%s", basename, num, ext); | |
775 num++; | |
776 if (num < 0) { | |
777 g_warning("Playlist number in filename overflowed." | |
778 " Not saving playlist.\n"); | |
779 goto cleanup; | |
780 } | |
781 } | |
782 filename = g_build_filename(bmp_paths[BMP_PATH_PLAYLISTS_DIR], | |
783 newbasename, NULL); | |
784 g_free(newbasename); | |
785 } while (g_file_test(filename, G_FILE_TEST_EXISTS)); | |
786 | |
787 playlist_save(playlist, filename); | |
788 cleanup: | |
789 g_free(filename); | |
790 g_free(basename); | |
791 } | |
792 } | |
679 | 793 |
680 void | 794 void |
681 bmp_config_save(void) | 795 bmp_config_save(void) |
682 { | 796 { |
683 GList *node; | 797 GList *node; |
684 gchar *str; | 798 gchar *str; |
685 gint i, cur_pb_time; | 799 gint i, cur_pb_time; |
686 ConfigDb *db; | 800 ConfigDb *db; |
801 GList *saved; | |
687 Playlist *playlist = playlist_get_active(); | 802 Playlist *playlist = playlist_get_active(); |
688 | 803 |
689 cfg.disabled_iplugins = input_stringify_disabled_list(); | 804 cfg.disabled_iplugins = input_stringify_disabled_list(); |
690 | 805 |
691 | 806 |
818 cfg.resume_playback_on_startup_time); | 933 cfg.resume_playback_on_startup_time); |
819 | 934 |
820 bmp_cfg_db_close(db); | 935 bmp_cfg_db_close(db); |
821 | 936 |
822 playlist_save(playlist, bmp_paths[BMP_PATH_PLAYLIST_FILE]); | 937 playlist_save(playlist, bmp_paths[BMP_PATH_PLAYLIST_FILE]); |
938 | |
939 /* Save extra playlists that were loaded from PLAYLISTS_DIR */ | |
940 saved = NULL; | |
941 if(!dir_foreach(bmp_paths[BMP_PATH_PLAYLISTS_DIR], save_extra_playlist, | |
942 &saved, NULL)) { | |
943 g_warning("Could not save extra playlists\n"); | |
944 } | |
945 | |
946 /* Save other playlists to PLAYLISTS_DIR */ | |
947 save_other_playlists(saved); | |
823 } | 948 } |
824 | 949 |
825 static void | 950 static void |
826 bmp_set_default_icon(void) | 951 bmp_set_default_icon(void) |
827 { | 952 { |