Project

General

Profile

libaudgui.preset-browser.cc.patch

Jim Turner, December 10, 2015 08:23

View differences:

preset-browser.cc 2015-12-03 18:35:06.000000000 -0600
21 21
#include "libaudgui.h"
22 22
#include "preset-browser.h"
23 23

  
24
#include <string.h>
24 25
#include <gtk/gtk.h>
25 26

  
26 27
#include <libaudcore/audstrings.h>
......
28 29
#include <libaudcore/equalizer.h>
29 30
#include <libaudcore/i18n.h>
30 31
#include <libaudcore/vfs.h>
32
#include <libaudcore/playlist.h>
33
#include <libaudcore/runtime.h>
31 34

  
32 35
typedef void (* FilebrowserCallback) (const char * filename);
33 36

  
......
46 49
static void show_preset_browser (const char * title, gboolean save,
47 50
 const char * default_filename, FilebrowserCallback callback)
48 51
{
52
    GtkFileFilter * filter;
53

  
49 54
    GtkWidget * browser = gtk_file_chooser_dialog_new (title, nullptr, save ?
50 55
     GTK_FILE_CHOOSER_ACTION_SAVE : GTK_FILE_CHOOSER_ACTION_OPEN, _("Cancel"),
51 56
     GTK_RESPONSE_CANCEL, save ? _("Save") : _("Load"), GTK_RESPONSE_ACCEPT,
52 57
     nullptr);
53

  
58
    filter = gtk_file_filter_new ();
59
    gtk_file_filter_set_name (filter, _("Preset/Eq Files"));
60
    gtk_file_filter_add_pattern (filter, "*.preset");
61
    gtk_file_filter_add_pattern (filter, "*.eqf");
62
    gtk_file_filter_add_pattern (filter, "*.q1");
63
    gtk_file_chooser_add_filter ((GtkFileChooser *) browser, filter);
64
    gtk_file_chooser_set_current_folder_uri ((GtkFileChooser *) browser,
65
            str_printf("%s%s", "file://", aud_get_path (AudPath::UserDir)));
54 66
    if (default_filename)
55 67
        gtk_file_chooser_set_current_name ((GtkFileChooser *) browser, default_filename);
56 68

  
......
104 116

  
105 117
void eq_preset_save_file ()
106 118
{
119
    String filename;
120
	int current_playlist = aud_playlist_get_playing ();
121
    if (current_playlist >= 0)
122
    {
123
    	   int current_song = aud_playlist_get_position (current_playlist);
124
    	   if (current_song >= 0)
125
        {
126
        	   const char * slash;
127
        	   const char * base;
128
        	   int ln = -1;
129
            filename = aud_playlist_entry_get_filename (current_playlist, current_song);
130
            slash = filename ? strrchr (filename, '/') : nullptr;
131
            base = slash ? slash + 1 : nullptr;
132
            if (slash && (!base || base[0] == '\0')) // FILENAME ENDS IN A "/"!
133
            {
134
                do
135
                {
136
                   --slash;
137
                   ++ln;
138
                } while (slash && slash > filename && slash[0] != '/');
139
                base = slash ? slash + 1 : nullptr;
140
                if (ln > 0)
141
                {
142
                    show_preset_browser (_("Save Preset File"), true,
143
                            str_printf("%.*s%s", ln, base, ".preset"), do_save_file);
144
                    return;
145
                }
146
            }
147
            else if (base && base[0] != '\0' && strncmp (base, "-.", 2))
148
            {
149
            	   show_preset_browser (_("Save Preset File"), true,
150
                        str_printf("%s%s", base, ".preset"), do_save_file);
151
                return;
152
            }
153
        }
154
    }
107 155
    show_preset_browser (_("Save Preset File"), true, _("<name>.preset"), do_save_file);
108 156
}
109 157