Fixing sample file dialog initialization and other things - Alex
[terminatorX.git] / src / tX_global.c
index 49b2272445a08d55f6fb6a07df108aa5d3ab3284..1434f2784e24d964d511e1a0fef8e80a6a7021b8 100644 (file)
 #include "string.h"
 #include <libxml/xmlmemory.h>
 #include <libxml/parser.h>
+#include <libxml/encoding.h>
+
 
 #define TX_XML_RC_VERSION "1.0"
 
 tx_global globals;
+int _store_compress_xml=0;
 
 void get_rc_name(char *buffer)
 {
@@ -67,11 +70,10 @@ void set_global_defaults() {
        globals.no_gui = 0;
        globals.alternate_rc = 0;
        
-       
        strcpy(globals.xinput_device, "");
        globals.xinput_enable=0;
        
-       globals.update_idle=18;
+       globals.update_idle=14;
        globals.update_delay=1;
        
        strcpy(globals.oss_device, "/dev/dsp");
@@ -79,12 +81,12 @@ void set_global_defaults() {
        globals.oss_buff_size=9;
        globals.oss_samplerate=44100;
 
-       strcpy(globals.alsa_device, "hw:0,0");  
-       globals.alsa_buff_no=2;
-       globals.alsa_buff_size=1024;
+       strcpy(globals.alsa_device, "00-00: Default");  
+       globals.alsa_buffer_time=80000;
+       globals.alsa_period_time=20000;
        globals.alsa_samplerate=44100;
        
-       globals.sense_cycles=12;
+       globals.sense_cycles=80;
        
        globals.mouse_speed=0.8;
        
@@ -123,12 +125,19 @@ void set_global_defaults() {
 #endif 
 #endif         
        globals.use_stdout_cmdline=0;
-       globals.current_path = NULL;
+       strcpy(globals.current_path, "");
        globals.pitch=1.0;
        globals.volume=1.0;
-       globals.fullscreen_enabled=1;
        
-       if (!globals.true_block_size) globals.true_block_size=1<globals.oss_buff_size;
+       strcpy(globals.lrdf_path, "/usr/share/ladspa/rdf:/usr/local/share/ladspa/rdf");
+       globals.fullscreen_enabled=0;
+       globals.confirm_events=0;
+       globals.compress_set_files=0;
+       
+       globals.vtt_inertia=10.0;
+       
+       globals.alsa_free_hwstats=1;
+       globals.filename_length=20;
 }
 
 int load_globals_xml() {
@@ -138,7 +147,8 @@ int load_globals_xml() {
        xmlNodePtr cur;
        int elementFound;
        double dvalue;
-
+       char tmp_xml_buffer[4096];
+       
        get_rc_name(rc_name);
        
        doc = xmlParseFile(rc_name);
@@ -176,10 +186,11 @@ int load_globals_xml() {
                        restore_int("oss_samplerate", globals.oss_samplerate);
 
                        restore_string("alsa_device", globals.alsa_device);
-                       restore_int("alsa_buff_no", globals.alsa_buff_no);
-                       restore_int("alsa_buff_size", globals.alsa_buff_size);
+                       restore_int("alsa_buffer_time", globals.alsa_buffer_time);
+                       restore_int("alsa_period_time", globals.alsa_period_time);
                        restore_int("alsa_samplerate", globals.alsa_samplerate);
-
+                       restore_int("alsa_free_hwstats", globals.alsa_free_hwstats);
+                       
                        restore_string("xinput_device", globals.xinput_device);
                        restore_int("xinput_enable", globals.xinput_enable);
                        restore_int("update_idle", globals.update_idle);
@@ -188,6 +199,7 @@ int load_globals_xml() {
                        restore_float("mouse_speed", globals.mouse_speed);
                        restore_int("width", globals.width);
                        restore_int("height", globals.height);
+                       restore_int("filename_length", globals.filename_length);
                        restore_int("tooltips", globals.tooltips);
                        restore_int("use_stdout", globals.use_stdout);
                        restore_int("show_nag", globals.show_nag);
@@ -197,11 +209,16 @@ int load_globals_xml() {
                        restore_float("volume", globals.volume);
                        restore_float("flash_response", globals.flash_response);
                        restore_int("button_type", globals.button_type);
-                       restore_int("true_block_size", globals.true_block_size);
                        restore_string("tables_filename", globals.tables_filename);
                        restore_string("record_filename", globals.record_filename);
                        restore_string("file_editor", globals.file_editor);
+                       restore_string("lrdf_path", globals.lrdf_path);
+                       restore_string("last_path", globals.current_path);
+                       
+                       restore_int("compress_set_files", globals.compress_set_files);
                        restore_int("fullscreen_enabled", globals.fullscreen_enabled);
+                       restore_int("confirm_events", globals.confirm_events);
+                       restore_float("vtt_inertia", globals.vtt_inertia);
 
                        if (!elementFound) {
                                fprintf(stderr, "tX: Unhandled XML element: \"%s\"\n", cur->name);
@@ -222,8 +239,10 @@ void store_globals() {
        char rc_name[PATH_MAX]="";
        char device_type[16];
        char indent[]="\t";
-       FILE *rc;
+       FILE *rc=NULL;
+       gzFile rz=NULL;
        char tmp_xml_buffer[4096];
+       _store_compress_xml=0;
        
        get_rc_name(rc_name);
 
@@ -243,7 +262,7 @@ void store_globals() {
        }
        
        if (rc) {               
-               fprintf(rc, "<?xml version=\"1.0\" encoding=\"US-ASCII\"?>\n\n");
+               fprintf(rc, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n");
                fprintf(rc, "<!-- Warning: this file will be rewritten by terminatorX on exit!\n     Don\'t waste your time adding comments - they will be erased -->\n\n" );
                fprintf(rc, "<terminatorXrc version=\"%s\">\n", TX_XML_RC_VERSION);
 
@@ -257,9 +276,10 @@ void store_globals() {
                store_int("oss_samplerate", globals.oss_samplerate);
 
                store_string("alsa_device", globals.alsa_device);
-               store_int("alsa_buff_no", globals.alsa_buff_no);
-               store_int("alsa_buff_size", globals.alsa_buff_size);
+               store_int("alsa_buffer_time", globals.alsa_buffer_time);
+               store_int("alsa_period_time", globals.alsa_period_time);
                store_int("alsa_samplerate", globals.alsa_samplerate);          
+               store_int("alsa_free_hwstats", globals.alsa_free_hwstats);
                
                store_string("xinput_device", globals.xinput_device);
                store_int("xinput_enable", globals.xinput_enable);
@@ -269,6 +289,7 @@ void store_globals() {
                store_float("mouse_speed", globals.mouse_speed);
                store_int("width", globals.width);
                store_int("height", globals.height);
+               store_int("filename_length", globals.filename_length);
                store_int("tooltips", globals.tooltips);
                store_int("use_stdout", globals.use_stdout);
                // globals.use_stdout_from_conf_file=0; What the heck is this?
@@ -279,12 +300,17 @@ void store_globals() {
                store_float("volume", globals.volume);
                store_float("flash_response", globals.flash_response);
                store_int("button_type", globals.button_type);
-               store_int("true_block_size", globals.true_block_size);
                store_string("tables_filename", globals.tables_filename);
                store_string("record_filename", globals.record_filename);
                store_string("file_editor", globals.file_editor);
+               store_string("lrdf_path", globals.lrdf_path);
+               store_int("compress_set_files", globals.compress_set_files);
                store_int("fullscreen_enabled", globals.fullscreen_enabled);
-               
+               store_int("confirm_events", globals.confirm_events);
+               store_float("vtt_inertia", globals.vtt_inertia);
+
+               store_string("last_path", globals.current_path);
+
                fprintf(rc,"</terminatorXrc>\n");
        }
 }
@@ -306,23 +332,47 @@ void load_globals() {
 
 char *encode_xml(char *dest, const char *src) {
        int i, t, max;
+       char tmp[4096];
+       int outlen=4096;
+       int inlen;
+       int res;
        
-       dest[0]=0;
+       tmp[0]=0;
        t=0;
        max=strlen(src);
        
        for (i=0; i<max; i++) {
                switch (src[i]) {
-                       case '<': dest[t]=0; strcat(dest, "&lt;"); t+=4; break;
-                       case '>': dest[t]=0; strcat(dest, "&gt;"); t+=4; break;
-                       case '&': dest[t]=0; strcat(dest, "&amp;"); t+=5; break;
-                       case '"': dest[t]=0; strcat(dest, "&quot;"); t+=6; break;
-                       case '\'': strcat(dest, "&apos;"); t+=7; break;
-                       default: dest[t]=src[i]; t++;
+                       case '<': tmp[t]=0; strcat(tmp, "&lt;"); t+=4; break;
+                       case '>': tmp[t]=0; strcat(tmp, "&gt;"); t+=4; break;
+                       case '&': tmp[t]=0; strcat(tmp, "&amp;"); t+=5; break;
+                       case '"': tmp[t]=0; strcat(tmp, "&quot;"); t+=6; break;
+                       case '\'': strcat(tmp, "&apos;"); t+=7; break;
+                       default: tmp[t]=src[i]; t++;
                }
        }
-       dest[t]=0;
+       tmp[t]=0;
+
+       inlen=t;
+       res=isolat1ToUTF8((unsigned char *) dest, &outlen, (unsigned char *) tmp, &inlen);
+       dest[outlen]=0;
+       if (res<0) {
+               tX_error("failed to encode string (%s) to UTF-8.", src);
+       }
+       
+       return dest;
+}
+
+char *decode_xml(char *dest, const char *src) {
+       int inlen=strlen(src);
+       int outlen=4096;
+       
+       int res=UTF8Toisolat1(dest, &outlen, src, &inlen);
+       dest[outlen]=0;
+       
+       if (res<0) {
+               tX_error("failed to decode UTF-8 string (%s).", src);
+       }
        
-       //tX_debug("encode_xml: from \"%s\" to \"%s\".", src, dest); 
        return dest;
 }