Fixing sample file dialog initialization and other things - Alex
[terminatorX.git] / src / tX_global.c
index 5e33f2ef6fb40f9885aec3098fe8bfcf409488e3..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,22 +70,23 @@ void set_global_defaults() {
        globals.no_gui = 0;
        globals.alternate_rc = 0;
        
-#ifdef USE_ALSA        
-       strcpy(globals.audio_device, "plughw:0,0");     
-#else  
-       strcpy(globals.audio_device, "/dev/dsp");
-#endif 
-       
        strcpy(globals.xinput_device, "");
        globals.xinput_enable=0;
        
-       globals.update_idle=18;
+       globals.update_idle=14;
        globals.update_delay=1;
        
-       globals.buff_no=2;
-       globals.buff_size=9;
+       strcpy(globals.oss_device, "/dev/dsp");
+       globals.oss_buff_no=2;
+       globals.oss_buff_size=9;
+       globals.oss_samplerate=44100;
+
+       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;
        
@@ -120,27 +124,31 @@ void set_global_defaults() {
        globals.audiodevice_type=ALSA;
 #endif 
 #endif         
-       globals.audiodevice_buffersize=4096;
-       strcpy(globals.audiodevice_oss_devicename, "/dev/dsp");
-       globals.audiodevice_alsa_card=0;
-       globals.audiodevice_alsa_pcm=0;         
-
        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.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() {
        char rc_name[PATH_MAX]="";      
+       char device_type[16]="oss";
        xmlDocPtr doc;
        xmlNodePtr cur;
        int elementFound;
        double dvalue;
-
+       char tmp_xml_buffer[4096];
+       
        get_rc_name(rc_name);
        
        doc = xmlParseFile(rc_name);
@@ -163,23 +171,35 @@ int load_globals_xml() {
                xmlFreeDoc(doc);
                return 3;
        }
-       
+               
        for (cur=cur->xmlChildrenNode; cur != NULL; cur = cur->next) {
                if (cur->type == XML_ELEMENT_NODE) {                    
                        elementFound=0;
 
                        restore_int("store_globals", globals.store_globals);
-                       restore_string("audio_device", globals.audio_device);
+
+                       restore_string("audio_driver", device_type);
+                       
+                       restore_string("oss_device", globals.oss_device);
+                       restore_int("oss_buff_no", globals.oss_buff_no);
+                       restore_int("oss_buff_size", globals.oss_buff_size);
+                       restore_int("oss_samplerate", globals.oss_samplerate);
+
+                       restore_string("alsa_device", globals.alsa_device);
+                       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);
                        restore_int("update_delay", globals.update_delay);
-                       restore_int("buff_no", globals.buff_no);
-                       restore_int("buff_size", globals.buff_size);
                        restore_int("sense_cycles", globals.sense_cycles);
                        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);
@@ -189,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);
@@ -203,36 +228,68 @@ int load_globals_xml() {
 
        xmlFreeDoc(doc);
        
+       if (strcmp(device_type, "alsa")==0) globals.audiodevice_type=ALSA;
+       else if (strcmp(device_type, "jack")==0) globals.audiodevice_type=JACK;
+       else globals.audiodevice_type=OSS;
+       
        return 0;
 }
 
 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);
 
        rc=fopen(rc_name, "w");
        
+       switch (globals.audiodevice_type) {
+               case JACK:
+                       strcpy(device_type, "jack");
+                       break;
+               case ALSA:
+                       strcpy(device_type, "alsa");
+                       break;
+               case OSS:
+               default:
+                       strcpy(device_type, "oss");
+               
+       }
+       
        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);
 
                store_int("store_globals", globals.store_globals);
-               store_string("audio_device", globals.audio_device);
+
+               store_string("audio_driver", device_type);
+               
+               store_string("oss_device", globals.oss_device);
+               store_int("oss_buff_no", globals.oss_buff_no);
+               store_int("oss_buff_size", globals.oss_buff_size);
+               store_int("oss_samplerate", globals.oss_samplerate);
+
+               store_string("alsa_device", globals.alsa_device);
+               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);
                store_int("update_idle", globals.update_idle);
                store_int("update_delay", globals.update_delay);
-               store_int("buff_no", globals.buff_no);
-               store_int("buff_size", globals.buff_size);
                store_int("sense_cycles", globals.sense_cycles);
                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?
@@ -243,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");
        }
 }
@@ -270,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;
 }