Patch for session filename
Emmanuel Saracco <[email protected]>
| Newsgroups | gmane.comp.audio.jamin.devel |
|---|---|
| Message-ID | <1179054180.3595.20.camel@localhost> |
Hi, Here is a little patch to have a session filename management more consistent IMHO. This patch is needed for the second patch I will send (if this one is accepted). My second patch will be intented to use gtk_file_chooser_* instead of gtk_file_selection_* when GTK+ >= 2.4. But to do that we must have a dynamically allocated global session filename (this current patch make it possible): * Renamed "filename" -> "session_filename". * Renamed "s_*_filename()" -> "s_*_session_filename()". * Added cleanup in "quit_clean()" for "session_filename". * Always use "s_get/set_session_filename()" to manipulate "session_filename" variable. Tell me if it is ok for you. If so, I will send the second patch. Thanks, Bye ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Jamin-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jamin-devel
jamin-0.96.01-session_filename.patch
(text/x-patch, 7 KB)
diff -u -x CVS jamin_orig/src/callbacks.c jamin/src/callbacks.c
--- jamin_orig/src/callbacks.c 2007-05-13 02:38:41.000000000 +0200
+++ jamin/src/callbacks.c 2007-05-13 12:47:29.000000000 +0200
@@ -1299,16 +1299,18 @@
gpointer user_data)
{
GtkFileSelection *file_selector;
- char *filename;
+ gchar *fname = NULL;
+ if (s_have_session_filename ()) {
+ fname = s_get_session_filename ();
+ }
file_selector =
(GtkFileSelection *) gtk_file_selection_new (_("Select a session file"));
- if (s_have_filename())
+ if (fname != NULL)
{
- filename = s_get_filename ();
- gtk_file_selection_set_filename (file_selector, filename);
+ gtk_file_selection_set_filename (file_selector, fname);
}
else
{
@@ -1336,8 +1338,8 @@
on_save1_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
- if (s_have_filename()) {
- s_save_session(NULL);
+ if (s_have_session_filename ()) {
+ s_save_session (NULL);
} else {
on_save_as1_activate (NULL, NULL);
}
diff -u -x CVS jamin_orig/src/hdeq.c jamin/src/hdeq.c
--- jamin_orig/src/hdeq.c 2005-04-24 15:17:00.000000000 +0200
+++ jamin/src/hdeq.c 2007-05-13 12:36:36.000000000 +0200
@@ -200,6 +200,9 @@
pref_write_jamin_defaults ();
+ /* free global session filename */
+
+ s_set_session_filename (NULL);
gtk_main_quit();
}
diff -u -x CVS jamin_orig/src/io.c jamin/src/io.c
--- jamin_orig/src/io.c 2005-04-16 02:46:47.000000000 +0200
+++ jamin/src/io.c 2007-05-13 12:47:47.000000000 +0200
@@ -786,7 +786,7 @@
case 'f':
if (check_file(optarg)) {
strncpy(session_file, optarg, sizeof(session_file));
- s_set_filename(session_file);
+ s_set_session_filename (session_file);
}
break;
case 'j': /* Set JACK server name */
diff -u -x CVS jamin_orig/src/state.c jamin/src/state.c
--- jamin_orig/src/state.c 2007-05-13 02:38:52.000000000 +0200
+++ jamin/src/state.c 2007-05-13 12:39:25.000000000 +0200
@@ -73,7 +73,7 @@
void s_save_global_float(xmlDocPtr doc, char *symbol, float value);
void s_save_global_gang(xmlDocPtr doc, char *p, int band, gboolean value);
-static const gchar *filename = NULL;
+gchar *session_filename = NULL;
/* global session parameters read from the XML file */
@@ -481,7 +481,7 @@
s_save_session(gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_selector)));
}
-void s_save_session (const char *fname)
+void s_save_session (const gchar *fname)
{
xmlDocPtr doc;
xmlNodePtr rootnode, node, sc_node;
@@ -494,11 +494,11 @@
* previous one */
if (fname) {
- filename = fname;
+ s_set_session_filename (fname);
s_update_title();
}
- if (!filename) {
- errstr = g_strdup_printf("No filename found at %s:%d, not saving\n",
+ if (!s_have_session_filename ()) {
+ errstr = g_strdup_printf("No session filename found at %s:%d, not saving\n",
__FILE__, __LINE__);
message (GTK_MESSAGE_WARNING, errstr);
free(errstr);
@@ -600,7 +600,7 @@
xmlAddChild(sc_node, node);
}
}
- xmlSaveFile(filename, doc);
+ xmlSaveFile((const char *) s_get_session_filename (), doc);
xmlFreeDoc(doc);
}
@@ -621,29 +621,32 @@
(file_selector)));
}
-void s_load_session (const char *fname)
+void s_load_session (const gchar *fname)
{
xmlSAXHandlerPtr handler;
int scene = -1;
int fd;
int i;
xml_global_params gp;
+ gchar *session_filename;
saved_scene = -1;
unset_scene_buttons ();
if (fname) {
- filename = fname;
+ s_set_session_filename (fname);
}
- if (filename == NULL) {
- filename = default_session;
+ if (!s_have_session_filename ()) {
+ s_set_session_filename (default_session);
}
+ session_filename = s_get_session_filename ();
+
/* Check to see if file is readable */
- if ((fd = open(filename, O_RDONLY)) >= 0) {
+ if ((fd = open((const char *) session_filename, O_RDONLY)) >= 0) {
close(fd);
} else {
- errstr = g_strdup_printf("Error opening '%s'", filename);
+ errstr = g_strdup_printf("Error opening '%s'", session_filename);
message (GTK_MESSAGE_WARNING, errstr);
perror(errstr);
free(errstr);
@@ -688,17 +691,17 @@
/* run the SAX parser */
scene_init();
- xmlSAXUserParseFile(handler, &gp, filename);
+ xmlSAXUserParseFile(handler, &gp, (const char *) session_filename);
if (gp.scene == LOAD_ERROR) {
- errstr = g_strdup_printf("Loading file '%s' failed", filename);
+ errstr = g_strdup_printf("Loading file '%s' failed", session_filename);
message (GTK_MESSAGE_WARNING, errstr);
perror(errstr);
free(errstr);
return;
}
- s_history_add(g_strdup_printf("Load %s", filename));
+ s_history_add(g_strdup_printf("Load %s", session_filename));
last_changed = S_LOAD;
free(handler);
@@ -749,7 +752,7 @@
}
if (!fname) {
- filename = NULL;
+ s_set_session_filename (NULL);
}
@@ -1015,36 +1018,43 @@
suppress_feedback--;
}
-int s_have_filename()
+int s_have_session_filename()
{
- return (filename != NULL);
+ return (session_filename != NULL);
}
-char *s_get_filename()
+gchar *s_get_session_filename()
{
- return ((char *) filename);
+ return ((gchar *) session_filename);
}
void s_update_title()
{
char *title;
char *base;
- char *tmp;
+ gchar *tmp;
/* name for title bar */
char *title_name = (client_name? client_name: PACKAGE);
- tmp = strdup(filename);
- base = basename(tmp);
- title = g_strdup_printf("%s - %s - " VERSION, title_name, base);
- free(tmp);
+ tmp = g_strdup (s_get_session_filename ());
+ base = basename (tmp);
+ title = g_strdup_printf ("%s - %s - " VERSION, title_name, base);
+ g_free (tmp);
gtk_window_set_title ((GtkWindow *) main_window, title);
- free(title);
+ g_free (title);
}
-void s_set_filename(const char *fname)
+void s_set_session_filename(const gchar *fname)
{
- filename = fname;
+ if (session_filename != NULL)
+ g_free (session_filename);
+
+ if (fname != NULL) {
+ session_filename = g_strdup (fname);
+ } else {
+ session_filename = NULL;
+ }
}
void s_set_crossfade_time(float ct)
diff -u -x CVS jamin_orig/src/state.h jamin/src/state.h
--- jamin_orig/src/state.h 2004-05-07 00:48:16.000000000 +0200
+++ jamin/src/state.h 2007-05-13 12:29:01.000000000 +0200
@@ -28,15 +28,15 @@
void s_save_session(const char *fname);
void s_load_session_from_ui(GtkWidget * w, gpointer user_data);
void s_load_session(const char *fname);
-void s_set_filename(const char *fname);
+void s_set_session_filename(const gchar *fname);
void s_crossfade(const int nframes);
void s_crossfade_ui();
void s_suppress_push();
void s_set_crossfade_time(float ct);
float s_get_crossfade_time();
void s_suppress_pop();
-int s_have_filename();
-char *s_get_filename();
+int s_have_session_filename();
+gchar *s_get_session_filename();
#define S_NONE -1