File: playlist_management.c

package info (click to toggle)
gnomp3 0.1.7-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 488 kB
  • ctags: 342
  • sloc: ansic: 3,285; makefile: 74; awk: 33
file content (123 lines) | stat: -rw-r--r-- 3,267 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
 ** playlist.c - playlist loading/saving and UI functions
 **
 ** Copyright (C) 2000 Matthew Pratt <mattpratt@yahoo.com>
 **
 ** This software is licensed under the terms of the GNU General 
 ** Public License (GPL). Please see the file LICENSE for details.
 **/ 

#include "gnomp3.h"
#include "utility.h"
#include "mp3info.h"
#include "playlist.h"
#include "rule_list.h"
#include "mp3list.h"
#include "dynamic_list.h"

#include <sys/types.h>
#include <dirent.h>


/* 
 *scnas the playlist directory for playlist files. Any found are added to the
 * dropdown menu of the playlist combo 
 */
void playlist_scan()
{
    DIR *dir;
    struct dirent *dir_ent;
    GList *glist=NULL;
    
    if( gnomp3.playlist_dir[strlen(gnomp3.playlist_dir)-1] == '/' )
	gnomp3.playlist_dir[strlen(gnomp3.playlist_dir)-1] = 0;

    dir = opendir(gnomp3.playlist_dir);
    if( !dir ){
	gnome_ok_dialog("Could not open playlist directory");
	return;
    }
    
    glist = g_list_append(glist, "");
    glist = dynamic_list_add_names(glist);

    while( (dir_ent = readdir(dir)) != NULL ){
	if( dir_ent->d_name[0] != '.' ){
	    glist = g_list_append(glist, g_strdup(dir_ent->d_name) );
	}
    }
    closedir(dir);
    
    gtk_combo_set_popdown_strings( GTK_COMBO(gnomp3.playlist_combo), glist );
}

void playlist_combo_activated(GtkWidget *w, gpointer data)
{
    static char filename[MAX_PATH];
    strncpy( filename, gtk_entry_get_text( GTK_ENTRY(GTK_COMBO(gnomp3.playlist_combo)->entry)), sizeof(filename));

    playlist_load(gnomp3.playlist_dir, filename);
}

/* callback for the 'new playlist' toolbar button. */
void playlist_new_cb(GtkWidget *w, gpointer data)
{
    GList *list;

    playlist_clear_rules();
    gtk_clist_clear(  GTK_CLIST(gnomp3.play_clist) );
    list = g_list_copy(playlist);
    g_list_foreach( list, (GFunc)playlist_remove_row, NULL );
    g_list_free(list);
    gnomp3.playlist_loaded[0] = 0;
    gtk_entry_set_text( GTK_ENTRY(GTK_COMBO(gnomp3.playlist_combo)->entry), "");
}

/* callbcak for the 'save as' dialog */
void playlist_save_dialog_done(GtkWidget *w, gpointer data)
{
    playlist_save(gnomp3.playlist_dir, gtk_entry_get_text( GTK_ENTRY(w)));
}

/* 
 * callback for the 'save playlist' toolbar button. If the playlist has not
 * yet been given and name, a dialog is loaded and displayed 
 */
void playlist_save_cb(GtkWidget *w, gpointer data)
{
    printf("playlit: %s\n", gnomp3.playlist_loaded);
    if( gnomp3.playlist_loaded[0] != 0 &&
	!dynamic_list_find(gnomp3.playlist_loaded) ){

	playlist_save( gnomp3.playlist_dir, gnomp3.playlist_loaded);
    }else{
	GladeXML *xml;
	
	xml = glade_xml_new( gnomp3.glade_file, "save_dialog");
	if(!xml) {
	    g_warning("We could not load the main_window interface!");
	    return;
	}
	glade_xml_signal_autoconnect(xml);
	gtk_object_unref(GTK_OBJECT(xml)); 
    }
}

/* 
 * callback for the 'save as playlist' toolbar button or menu item. Dialog 
 * is loaded and displayed 
 */
void playlist_save_as_cb(GtkWidget *w, gpointer data)
{
    GladeXML *xml;
    
    xml = glade_xml_new( gnomp3.glade_file, "save_dialog");
    if(!xml) {
	g_warning("We could not load the main_window interface!");
	return;
    }
    
    glade_xml_signal_autoconnect(xml);
    gtk_object_unref(GTK_OBJECT(xml));
}