Ok, I have all the framework for the "open to last selection" to be user
defined in the preference menu. I just dont know how to query that
preference from in the file selection and GTK file selection source. 
This patch also adds directory add ability to the "add file" button on
freeamp's main window.  

Here is a patch against the latest freeamp cvs.  Seems that the fix for
vorbis was reversed?  Anyways.   The preferences selection works, it
saves to the config file and all that.  Everything seems to be
functioning as planned. 

this patch should be applied via   cat <patch> | patch -p1    from
within freeamp's top level dir. 


diff -urN -x corba -x CVS -x config.status -x configure -x config.h -x config.log -x Makefile* -x aclocal* -x config.cache ./freeamp/base/include/preferences.h ./freeamp-patched/base/include/preferences.h
--- ./freeamp/base/include/preferences.h	Tue Oct 16 01:23:08 2001
+++ ./freeamp-patched/base/include/preferences.h	Sun Mar 31 17:23:11 2002
@@ -81,6 +81,7 @@
 extern const char* kViewMusicBrowserPref;
 extern const char* kWelcomePref;
 extern const char* kPlayImmediatelyPref;
+extern const char* kSetLastResumePref;
 extern const char* kNumberOfURLsToRememberPref;
 extern const char* kCDDevicePathPref;
 extern const char* kCheckCDAutomaticallyPref;
diff -urN -x corba -x CVS -x config.status -x configure -x config.h -x config.log -x Makefile* -x aclocal* -x config.cache ./freeamp/base/src/preferences.cpp ./freeamp-patched/base/src/preferences.cpp
--- ./freeamp/base/src/preferences.cpp	Tue Oct 16 01:23:08 2001
+++ ./freeamp-patched/base/src/preferences.cpp	Sun Mar 31 17:32:10 2002
@@ -79,6 +79,7 @@
 const char* kWindowModePref = "WindowMode";
 const char* kWelcomePref = "Welcome";
 const char* kPlayImmediatelyPref = "PlayImmediately";
+const char* kSetLastResumePref = "SetLastResume";
 const char* kNumberOfURLsToRememberPref = "NumberOfURLsToRemember";
 const char* kCDDevicePathPref = "CDDevice";
 const char* kCheckCDAutomaticallyPref = "AutoUpdateCD";
@@ -156,6 +157,7 @@
 const bool kDefaultViewMusicBrowser = true;
 const bool kDefaultWelcome = true;
 const bool kDefaultPlayImmediately = true;
+const bool kDefaultSetLastResume = true;
 const int32 kDefaultNumberOfURLsToRemember = 10;
 const char* kDefaultMBServer = "http://www.musicbrainz.org:80";;
 const bool kDefaultConvertUnderscoresToSpaces = true;
@@ -346,6 +348,9 @@
 
     if (GetPrefBoolean(kPlayImmediatelyPref, &dummyBool) == kError_NoPrefValue)
         SetPrefBoolean(kPlayImmediatelyPref, kDefaultPlayImmediately);
+	
+    if (GetPrefBoolean(kSetLastResumePref, &dummyBool) == kError_NoPrefValue)
+	SetPrefBoolean(kSetLastResumePref, kDefaultSetLastResume);
 
     if (GetPrefInt32(kNumberOfURLsToRememberPref, &dummyInt) == kError_NoPrefValue)
         SetPrefInt32(kNumberOfURLsToRememberPref, kDefaultNumberOfURLsToRemember);
diff -urN -x corba -x CVS -x config.status -x configure -x config.h -x config.log -x Makefile* -x aclocal* -x config.cache ./freeamp/lmc/vorbis/src/vorbislmc.cpp ./freeamp-patched/lmc/vorbis/src/vorbislmc.cpp
--- ./freeamp/lmc/vorbis/src/vorbislmc.cpp	Wed Feb 13 03:11:49 2002
+++ ./freeamp-patched/lmc/vorbis/src/vorbislmc.cpp	Sun Mar 31 19:19:00 2002
@@ -172,7 +172,7 @@
    m_section = -1;
 
    m_pContext->prefs->GetPrefInt32(kOutputBufferSizePref, &iNewSize);
-   iNewSize = max(iNewSize, iInitialOutputBufferSize);
+   iNewSize = max(iNewSize, iMinimumOutputBufferSize);
    iNewSize *= 1024;
 
    result = m_pOutputBuffer->Resize(iNewSize, iNewSize / 6);
diff -urN -x corba -x CVS -x config.status -x configure -x config.h -x config.log -x Makefile* -x aclocal* -x config.cache ./freeamp/ui/freeamp/unix/include/GTKPreferenceWindow.h ./freeamp-patched/ui/freeamp/unix/include/GTKPreferenceWindow.h
--- ./freeamp/ui/freeamp/unix/include/GTKPreferenceWindow.h	Tue Oct 16 01:03:41 2001
+++ ./freeamp-patched/ui/freeamp/unix/include/GTKPreferenceWindow.h	Sun Mar 31 18:32:34 2002
@@ -77,6 +77,7 @@
     bool useImages; 
     bool savePlaylistOnExit;
     bool playImmediately;
+    bool setLastResume;
     bool allowMultipleInstances;
  
     string saveMusicDirectory;
@@ -107,6 +108,7 @@
             convertUnderscores == pref.convertUnderscores &&
             allowMultipleInstances == pref.allowMultipleInstances &&
             playImmediately == pref.playImmediately &&
+	    setLastResume == pref.setLastResume &&
             useTextLabels == pref.useTextLabels &&
             useImages == pref.useImages &&
             savePlaylistOnExit == pref.savePlaylistOnExit &&
@@ -316,6 +318,7 @@
       void SetToolbar(bool text, bool pics);
       void SaveOnExitToggle(int active);
       void PlayImmediatelyToggle(int active);
+      void SetLastResumeToggle(int active);
       void AllowMultipleToggle(int active);
       void ConvertUnderscoresToggle(int active);
       void ReclaimTypesToggle(int active);
diff -urN -x corba -x CVS -x config.status -x configure -x config.h -x config.log -x Makefile* -x aclocal* -x config.cache ./freeamp/ui/freeamp/unix/src/GTKFileSelector.cpp ./freeamp-patched/ui/freeamp/unix/src/GTKFileSelector.cpp
--- ./freeamp/ui/freeamp/unix/src/GTKFileSelector.cpp	Wed May 24 13:08:34 2000
+++ ./freeamp-patched/ui/freeamp/unix/src/GTKFileSelector.cpp	Sun Mar 31 19:23:54 2002
@@ -23,6 +23,9 @@
 
 #include "GTKFileSelector.h"
 #include <unistd.h>
+#include <dirent.h>
+
+extern char old_path[PATH_MAX];
 
 GTKFileSelector::GTKFileSelector(const char *windowtitle)
 {
@@ -51,6 +54,34 @@
     p->CancelEvent();
 }
 
+string GTKrecursive_path(char subdirs[PATH_MAX], string returnpath,int *sub_rnum)
+{  
+    DIR *dir=NULL;
+    struct dirent *current=NULL;
+    if ((dir = opendir(subdirs))!=NULL){
+        current = readdir(dir);
+        current = readdir(dir); 
+        while((current=readdir(dir))!=NULL){ 
+            if(current->d_type==DT_DIR){  
+                char temp_subdir[PATH_MAX];
+                strncpy(temp_subdir, subdirs,PATH_MAX);
+                strcat(temp_subdir,"/");
+                strncat(temp_subdir,current->d_name,FILENAME_MAX);
+                returnpath = GTKrecursive_path(temp_subdir,returnpath,sub_rnum);
+            }
+            else {
+                returnpath += "\n";
+                returnpath += subdirs;
+		returnpath += "/";
+                returnpath += current->d_name;
+                sub_rnum++;
+            }
+        }
+    }
+    closedir(dir);
+    return (returnpath);
+}                    
+
 void GTKFileSelector::CancelEvent()
 {
     gtk_widget_destroy(filesel);
@@ -64,6 +95,7 @@
     char *raw_path = NULL;
     GList *row = GTK_CLIST(gfile->file_list)->row_list;
     gint rownum = 0;
+    gint sub_rnum = 0;
     char *temp, *path_temp;
 
     returnpath = gtk_file_selection_get_filename(gfile);
@@ -78,23 +110,33 @@
         tempdir[0] = '\0';
 
     raw_path = gtk_entry_get_text(GTK_ENTRY(gfile->selection_entry));
-    while (row) {
-        if (GTK_CLIST_ROW(row)->state == GTK_STATE_SELECTED) {
-            if (gtk_clist_get_cell_type(GTK_CLIST(gfile->file_list), rownum, 0)
-                == GTK_CELL_TEXT) {
-                gtk_clist_get_text(GTK_CLIST(gfile->file_list), rownum, 0, &temp);
-                if (!strcmp(temp, raw_path))
-                    goto next_iter;
-                returnpath += "\n";
-                returnpath += path_temp;
-                returnpath += "/";
-                returnpath += temp;
-            }
-        }
-    next_iter:
-        rownum++;
-        row = g_list_next(row);
+    strncpy(old_path,path_temp,PATH_MAX);
+    if(row){
+	while (row) {
+    	    if (GTK_CLIST_ROW(row)->state == GTK_STATE_SELECTED) {
+        	if (gtk_clist_get_cell_type(GTK_CLIST(gfile->file_list), rownum, 0)
+            	    == GTK_CELL_TEXT) {
+            	    gtk_clist_get_text(GTK_CLIST(gfile->file_list), rownum, 0, &temp);
+            	    if (!strcmp(temp, raw_path))
+                	goto next_iter;
+            	    returnpath += "\n";
+            	    returnpath += path_temp;
+            	    returnpath += "/";
+            	    returnpath += temp;
+        	}
+    	    }
+	    next_iter:
+    	    rownum++;
+    	    row = g_list_next(row);
+	}
+    }
+    else {
+	char subdirs[PATH_MAX];
+	strncpy(subdirs,old_path,PATH_MAX);
+	returnpath="";
+	returnpath = GTKrecursive_path(subdirs,returnpath,&sub_rnum);
     }
+    rownum += sub_rnum;
     gtk_widget_destroy(GTK_WIDGET(gfile));
     free(path_temp);
 
@@ -108,7 +150,8 @@
         gdk_threads_enter();
 
     filesel = gtk_file_selection_new(title.c_str());
-
+//    if(SetLastResume)
+	gtk_file_selection_set_filename (GTK_FILE_SELECTION (filesel), old_path);
     gtk_window_set_modal(GTK_WINDOW(filesel), TRUE);
     gtk_signal_connect(GTK_OBJECT(filesel), "destroy",
                        GTK_SIGNAL_FUNC(filesel_destroy), (gpointer)runMain);
diff -urN -x corba -x CVS -x config.status -x configure -x config.h -x config.log -x Makefile* -x aclocal* -x config.cache ./freeamp/ui/freeamp/unix/src/GTKPreferenceWindow.cpp ./freeamp-patched/ui/freeamp/unix/src/GTKPreferenceWindow.cpp
--- ./freeamp/ui/freeamp/unix/src/GTKPreferenceWindow.cpp	Tue Oct 16 01:03:41 2001
+++ ./freeamp-patched/ui/freeamp/unix/src/GTKPreferenceWindow.cpp	Sun Mar 31 18:35:44 2002
@@ -447,6 +447,9 @@
     prefs->GetPrefBoolean(kShowToolbarImagesPref, &values->useImages);
     prefs->GetPrefBoolean(kSaveCurrentPlaylistOnExitPref, &values->savePlaylistOnExit);
     prefs->GetPrefBoolean(kPlayImmediatelyPref, &values->playImmediately);
+    
+    prefs->GetPrefBoolean(kSetLastResumePref, &values->setLastResume);
+    
     prefs->GetPrefBoolean(kAllowMultipleInstancesPref, &values->allowMultipleInstances);
 
     if(kError_BufferTooSmall == prefs->GetPrefString(kSaveMusicDirPref, buffer, &size))
@@ -540,6 +543,9 @@
     prefs->SetPrefBoolean(kShowToolbarImagesPref, values->useImages);
     prefs->SetPrefBoolean(kSaveCurrentPlaylistOnExitPref, values->savePlaylistOnExit);
     prefs->SetPrefBoolean(kPlayImmediatelyPref, values->playImmediately);
+    
+    prefs->SetPrefBoolean(kSetLastResumePref, values->setLastResume);
+    
     prefs->SetPrefBoolean(kAllowMultipleInstancesPref, values->allowMultipleInstances);
     prefs->SetPrefBoolean(kAskToReclaimFiletypesPref, values->askReclaimFiletypes);
     prefs->SetPrefBoolean(kReclaimFiletypesPref, values->reclaimFiletypes);
@@ -657,6 +663,19 @@
     p->PlayImmediatelyToggle(i);
 }
 
+void GTKPreferenceWindow::SetLastResumeToggle(int active)
+{
+    proposedValues.setLastResume = active;
+    if(!firsttime)
+	gtk_widget_set_sensitive(applyButton,TRUE);
+}
+
+static void set_last_toggle(GtkWidget *w, GTKPreferenceWindow *p)
+{
+    int i = GTK_TOGGLE_BUTTON(w)->active;
+    p->SetLastResumeToggle(i);
+}
+
 void GTKPreferenceWindow::AllowMultipleToggle(int active)
 {
     proposedValues.allowMultipleInstances = active;
@@ -789,6 +808,14 @@
                        GTK_SIGNAL_FUNC(play_now_toggle), this);
     if (!originalValues.playImmediately) 
         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), TRUE);
+    gtk_widget_show(check);
+
+    check = gtk_check_button_new_with_label("Open File to Last Selected");
+    gtk_box_pack_start(GTK_BOX(vbox), check, FALSE,FALSE,0);
+    gtk_signal_connect(GTK_OBJECT(check), "toggled",
+		       GTK_SIGNAL_FUNC(set_last_toggle), this);
+    if(originalValues.setLastResume)
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), TRUE);
     gtk_widget_show(check);
 
     frame = gtk_frame_new("Miscellaneous");
diff -urN -x corba -x CVS -x config.status -x configure -x config.h -x config.log -x Makefile* -x aclocal* -x config.cache ./freeamp/ui/musicbrowser/unix/src/fileselector.cpp ./freeamp-patched/ui/musicbrowser/unix/src/fileselector.cpp
--- ./freeamp/ui/musicbrowser/unix/src/fileselector.cpp	Thu Sep 28 04:08:03 2000
+++ ./freeamp-patched/ui/musicbrowser/unix/src/fileselector.cpp	Sun Mar 31 18:24:01 2002
@@ -24,6 +24,7 @@
 #include "config.h"
 
 #include <unistd.h>
+#include <dirent.h>
 
 #ifdef __QNX__
 #include <strings.h>
@@ -32,6 +33,8 @@
 #include "fileselector.h"
 #include "utility.h"
 
+char old_path[PATH_MAX]="/\0";
+
 FileSelector::FileSelector(const char *windowtitle)
 {
     title = windowtitle;
@@ -59,6 +62,34 @@
     p->CancelEvent();
 }
 
+string recursive_path(char subdirs[PATH_MAX], string returnpath,int *sub_rnum)
+{
+    DIR *dir=NULL;
+    struct dirent *current=NULL;
+    if ((dir = opendir(subdirs))!=NULL){
+        current = readdir(dir);
+        current = readdir(dir);
+        while((current=readdir(dir))!=NULL){
+            if(current->d_type==DT_DIR){
+		char temp_subdir[PATH_MAX];
+		strncpy(temp_subdir, subdirs,PATH_MAX);
+		strcat(temp_subdir,"/");
+		strncat(temp_subdir,current->d_name,FILENAME_MAX);
+		returnpath = recursive_path(temp_subdir,returnpath,sub_rnum);
+	    }
+	    else {
+    	    returnpath += "\n";
+	    returnpath += subdirs;
+	    returnpath += "/";
+	    returnpath += current->d_name;
+	    sub_rnum++;
+	    }
+	}
+    }
+    closedir(dir);
+    return (returnpath);
+}
+
 void FileSelector::CancelEvent()
 {
     gtk_widget_destroy(filesel);
@@ -72,6 +103,7 @@
     char *raw_path = NULL;
     GList *row = GTK_CLIST(gfile->file_list)->row_list;
     gint rownum = 0;
+    gint sub_rnum = 0;
     char *temp, *path_temp;
 
     char *rawtext = gtk_entry_get_text(GTK_ENTRY(gfile->selection_entry));
@@ -79,7 +111,6 @@
         !strncasecmp("rtp://", rawtext, 6)) {
         returnpath = strdup_new(rawtext);
         gtk_widget_destroy(GTK_WIDGET(gfile));
-
         ok = true;
         done = true;
 
@@ -88,33 +119,41 @@
 
     returnpath = gtk_file_selection_get_filename(gfile);
     path_temp = strdup(returnpath.c_str());
-
+    raw_path = 	gtk_entry_get_text(GTK_ENTRY(gfile->selection_entry));
     char *tempdir = strrchr(path_temp, '/');
+    strncpy(old_path,path_temp,PATH_MAX);
     if (!tempdir) {
         strcpy(path_temp, "./");
         path_temp = (char *)realloc(path_temp, strlen(path_temp) + 1);
     }
     else
         tempdir[0] = '\0';
-
-    raw_path = gtk_entry_get_text(GTK_ENTRY(gfile->selection_entry));
-    while (row) {
-        if (GTK_CLIST_ROW(row)->state == GTK_STATE_SELECTED) {
-            if (gtk_clist_get_cell_type(GTK_CLIST(gfile->file_list), rownum, 0)
-                == GTK_CELL_TEXT) {
-                gtk_clist_get_text(GTK_CLIST(gfile->file_list), rownum, 0, &temp);
-                if (!strcmp(temp, raw_path))
-                    goto next_iter;
-                returnpath += "\n";
-                returnpath += path_temp;
-                returnpath += "/";
-                returnpath += temp;
-            }
-        }
-    next_iter:
-        rownum++;
-        row = g_list_next(row);
+    if(row){
+	while (row) {
+    	    if (GTK_CLIST_ROW(row)->state == GTK_STATE_SELECTED) {
+        	if (gtk_clist_get_cell_type(GTK_CLIST(gfile->file_list), rownum, 0)
+            	    == GTK_CELL_TEXT) {
+            	    gtk_clist_get_text(GTK_CLIST(gfile->file_list), rownum, 0, &temp);
+		    if (!strcmp(temp, raw_path))
+                	goto next_iter;
+		    returnpath += "\n";
+            	    returnpath += path_temp;
+            	    returnpath += "/";
+            	    returnpath += temp;
+        	}
+    	    }
+	    next_iter:
+    	    rownum++;
+    	    row = g_list_next(row);
+	}
+    } 
+    else {
+	char subdirs[PATH_MAX];
+	strncpy(subdirs,old_path,PATH_MAX);
+	returnpath="";
+	returnpath = recursive_path(subdirs, returnpath,&sub_rnum);
     }
+    rownum += sub_rnum;
     gtk_widget_destroy(GTK_WIDGET(gfile));
     free(path_temp);
 
@@ -124,11 +163,13 @@
 
 bool FileSelector::Run(bool runMain)
 {
+    bool dummyBool;
     if (!runMain)
         gdk_threads_enter();
 
     filesel = gtk_file_selection_new(title.c_str());
-
+//    if(GetPrefBoolean(kSetLastResumePref, &dummyBool))
+	gtk_file_selection_set_filename (GTK_FILE_SELECTION (filesel), old_path);
     gtk_window_set_modal(GTK_WINDOW(filesel), TRUE);
     gtk_signal_connect(GTK_OBJECT(filesel), "destroy",
                        GTK_SIGNAL_FUNC(filesel_destroy), (gpointer)runMain);

Reply via email to