// generated by Fast Light User Interface Designer (fluid) version 1.0109

#include "flrecUIsettings.h"

void flrecUIsettings::cb_b_discard_i(Fl_Button*, void*) {
  loadsettings();
w_main->hide();
}
void flrecUIsettings::cb_b_discard(Fl_Button* o, void* v) {
  ((flrecUIsettings*)(o->parent()->user_data()))->cb_b_discard_i(o,v);
}

void flrecUIsettings::cb_b_save_settings_i(Fl_Button*, void*) {
  savesettings();
w_main->hide();
}
void flrecUIsettings::cb_b_save_settings(Fl_Button* o, void* v) {
  ((flrecUIsettings*)(o->parent()->user_data()))->cb_b_save_settings_i(o,v);
}

flrecUIsettings::flrecUIsettings() {
  { w_main = new Fl_Double_Window(275, 190, "flrec - settings");
    w_main->color(FL_LIGHT1);
    w_main->user_data((void*)(this));
    w_main->when(FL_WHEN_CHANGED);
    { set_sd = new Fl_Input(21, 30, 235, 24, "Starting Path:");
      set_sd->selection_color((Fl_Color)51);
      set_sd->labelfont(14);
      set_sd->align(FL_ALIGN_TOP_LEFT);
    } // Fl_Input* set_sd
    { set_mix = new Fl_Input(21, 77, 235, 24, "Mixer Command: ");
      set_mix->selection_color((Fl_Color)51);
      set_mix->labelfont(14);
      set_mix->align(FL_ALIGN_TOP_LEFT);
    } // Fl_Input* set_mix
    { b_discard = new Fl_Button(102, 150, 75, 25, "Discard");
      b_discard->box(FL_GTK_THIN_UP_BOX);
      b_discard->color(FL_LIGHT1);
      b_discard->callback((Fl_Callback*)cb_b_discard);
    } // Fl_Button* b_discard
    { b_save_settings = new Fl_Button(182, 150, 75, 25, "Save");
      b_save_settings->box(FL_GTK_THIN_UP_BOX);
      b_save_settings->color(FL_LIGHT1);
      b_save_settings->callback((Fl_Callback*)cb_b_save_settings);
    } // Fl_Button* b_save_settings
    { set_pam = new Fl_Check_Button(67, 112, 161, 25, "Autoname on Pause");
      set_pam->tooltip("pause during recording automatically rename file appending number");
      set_pam->down_box(FL_DOWN_BOX);
    } // Fl_Check_Button* set_pam
    w_main->end();
  } // Fl_Double_Window* w_main
  w_main->xclass("flrec");
}

bool flrecUIsettings::loadsettings() {
  FILE* fp;
char spath[1024];
char tmp[1024];
int itmp;

fl_filename_expand(spath,1024,"~/.flrec");
fp=fopen(spath,"r");

if (fp!=NULL){
	// read settings from file
	fscanf(fp,"starting_path=%s\n",tmp);
	set_sd->value(tmp);
	fgets(tmp,1024,fp);
	*(tmp+strlen(tmp)-1)=0;
	set_mix->value((strstr(tmp,"=")+1));
	fscanf(fp,"pam_mode=%i\n",&itmp);
	set_pam->value(itmp);
	fclose(fp);
	return true;
}else{
	
	printf("flrec: no .flrec found (cannot open?), using defaults\n");

	fl_filename_expand(spath,1024,"~");
	strncat(spath,"/.",1024);
	set_sd->value(spath);
	set_mix->value("xterm -e alsamixer");
}
return false;
}

void flrecUIsettings::savesettings() {
  FILE* fp;
char spath[1024];

fl_filename_expand(spath,1024,"~/.flrec");

fp=fopen(spath,"w");

if (fp){
	fprintf(fp,"starting_path=%s\n",set_sd->value());
	fprintf(fp,"mixer_cmd=%s\n",set_mix->value());
	fprintf(fp,"pam_mode=%i\n",set_pam->value());	
	fclose(fp);
}

//printf("flrec: settings saved in %s\n",spath);
}
