Commit d2d8f025 authored by Ali Abdallah's avatar Ali Abdallah

* Added option to remember the currently loaded media

	files in the playlist view.

(Old svn revision: 7888)
parent b63c5f7f
2009-08-04: 18:00 Ali aliov@xfce.org
* Added option to remember the currently loaded media
files in the playlist view.
2009-07-31: 11:30 Ali aliov@xfce.org
* Support for Recent played media files.
* Better configuration loading based GValues.
......
......@@ -46,8 +46,11 @@
#include "parole-filters.h"
#include "parole-pl-parser.h"
#include "parole-utils.h"
#include "parole-rc-utils.h"
#include "parole-dbus.h"
#define PAROLE_AUTO_SAVED_PLAYLIST "xfce4/parole/auto-saved-playlist.m3u"
typedef struct
{
GtkWidget *chooser;
......@@ -644,6 +647,16 @@ parole_media_list_clear_list (ParoleMediaList *list)
parole_media_list_set_widget_sensitive (list, FALSE);
}
static void
save_list_activated_cb (GtkWidget *mi)
{
gboolean active;
active = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (mi));
parole_rc_write_entry_bool ("SAVE_LIST_ON_EXIT", PAROLE_RC_GROUP_GENERAL, active);
}
static void
parole_media_list_show_menu (ParoleMediaList *list, guint button, guint activate_time)
{
......@@ -651,6 +664,24 @@ parole_media_list_show_menu (ParoleMediaList *list, guint button, guint activate
menu = gtk_menu_new ();
mi = gtk_check_menu_item_new_with_label (_("Remember playlist"));
gtk_widget_set_sensitive (mi, TRUE);
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi),
parole_rc_read_entry_bool ("SAVE_LIST_ON_EXIT",
PAROLE_RC_GROUP_GENERAL,
FALSE));
g_signal_connect (mi, "activate",
G_CALLBACK (save_list_activated_cb), NULL);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
gtk_widget_show (mi);
mi = gtk_separator_menu_item_new ();
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
/* Clear */
mi = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLEAR, NULL);
gtk_widget_set_sensitive (mi, TRUE);
......@@ -798,6 +829,8 @@ parole_media_list_init (ParoleMediaList *list)
{
GtkBuilder *builder;
GtkWidget *box;
gboolean load_saved_list;
GSList *fileslist = NULL;
list->priv = PAROLE_MEDIA_LIST_GET_PRIVATE (list);
......@@ -822,6 +855,33 @@ parole_media_list_init (ParoleMediaList *list)
gtk_widget_show_all (GTK_WIDGET (list));
parole_media_list_dbus_init (list);
load_saved_list = parole_rc_read_entry_bool ("SAVE_LIST_ON_EXIT", PAROLE_RC_GROUP_GENERAL, FALSE);
if ( load_saved_list )
{
gchar *playlist_file;
playlist_file = xfce_resource_save_location (XFCE_RESOURCE_DATA,
PAROLE_AUTO_SAVED_PLAYLIST,
FALSE);
if ( playlist_file )
{
fileslist = parole_pl_parser_load_file (playlist_file);
g_free (playlist_file);
if ( fileslist )
{
guint i, len;
len = g_slist_length (fileslist);
for ( i = 0; i < len; i++)
{
ParoleFile *file;
file = g_slist_nth_data (fileslist, i);
parole_media_list_add (list, file, FALSE);
}
g_slist_free (fileslist);
}
}
}
}
GtkWidget *
......@@ -978,6 +1038,35 @@ void parole_media_list_add_files (ParoleMediaList *list, gchar **filenames)
parole_media_list_add_by_path (list, filenames[i], i == 0 ? TRUE : FALSE);
}
void parole_media_list_save_list (ParoleMediaList *list)
{
gboolean save;
save = parole_rc_read_entry_bool ("SAVE_LIST_ON_EXIT", PAROLE_RC_GROUP_GENERAL, FALSE);
if ( save )
{
GSList *fileslist;
gchar *history;
history = xfce_resource_save_location (XFCE_RESOURCE_DATA, PAROLE_AUTO_SAVED_PLAYLIST , TRUE);
if ( !history )
{
g_warning ("Failed to save playlist");
return;
}
fileslist = parole_media_list_get_files (list);
if ( g_slist_length (fileslist) > 0 )
{
parole_pl_parser_save_file (fileslist, history, PAROLE_PL_FORMAT_M3U);
g_slist_foreach (fileslist, (GFunc) g_object_unref, NULL);
}
g_slist_free (fileslist);
}
}
static gboolean parole_media_list_dbus_add_files (ParoleMediaList *list,
gchar **in_files,
GError **error);
......
......@@ -90,6 +90,8 @@ void parole_media_list_open_location (ParoleMediaList *list);
void parole_media_list_add_files (ParoleMediaList *list,
gchar **filenames);
void parole_media_list_save_list (ParoleMediaList *list);
G_END_DECLS
#endif /* __PAROLE_MEDIA_LIST_H */
......@@ -533,6 +533,7 @@ parole_player_paused (ParolePlayer *player)
static void
parole_player_quit (ParolePlayer *player)
{
parole_media_list_save_list (player->priv->list);
gtk_widget_destroy (player->priv->window);
g_object_unref (player);
gtk_main_quit ();
......
......@@ -135,14 +135,14 @@ gchar **parole_rc_read_entry_list (const gchar *property, const gchar *group)
return ret_val;
}
gchar **parole_get_history (void)
gchar **parole_get_history_full (const gchar *relpath)
{
gchar **lines = NULL;
gchar *history = NULL;
gchar *contents = NULL;
gsize length = 0;
history = xfce_resource_lookup (XFCE_RESOURCE_CACHE, PAROLE_HISTORY_FILE);
history = xfce_resource_lookup (XFCE_RESOURCE_CACHE, relpath);
if (history && g_file_get_contents (history, &contents, &length, NULL))
{
......@@ -155,11 +155,21 @@ gchar **parole_get_history (void)
return lines;
}
gchar **parole_get_history (void)
{
return parole_get_history_full (PAROLE_HISTORY_FILE);
}
void parole_insert_line_history (const gchar *line)
{
parole_insert_line_history_full (PAROLE_HISTORY_FILE, line);
}
void parole_insert_line_history_full (const gchar *relpath, const gchar *line)
{
gchar *history = NULL;
history = xfce_resource_save_location (XFCE_RESOURCE_CACHE, PAROLE_HISTORY_FILE, TRUE);
history = xfce_resource_save_location (XFCE_RESOURCE_CACHE, relpath, TRUE);
if ( history )
{
......@@ -167,9 +177,28 @@ void parole_insert_line_history (const gchar *line)
f = fopen (history, "a");
fprintf (f, "%s\n", line);
fclose (f);
g_free (history);
}
else
g_warning ("Unable to open cache file");
g_free (history);
}
void parole_clear_history_file (void)
{
parole_clear_history_file_full (PAROLE_HISTORY_FILE);
}
void parole_clear_history_file_full (const gchar *relpath)
{
gchar *history = NULL;
history = xfce_resource_save_location (XFCE_RESOURCE_CACHE, relpath, FALSE);
if ( history )
{
FILE *f;
f = fopen (history, "w");
fclose (f);
g_free (history);
}
}
......@@ -65,6 +65,15 @@ gchar **parole_rc_read_entry_list (const gchar *property,
gchar **parole_get_history (void);
gchar **parole_get_history_full (const gchar *relpath);
void parole_insert_line_history (const gchar *line);
void parole_insert_line_history_full (const gchar *relpath,
const gchar *line);
void parole_clear_history_file (void);
void parole_clear_history_file_full (const gchar *relpath);
#endif /* __RC_UTILS_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment