+bool FormPreferences::ConvertersContainFormat( Format const & format ) const
+{
+ for( vector<Command>::const_iterator cit = commands_vec.begin();
+ cit != commands_vec.end(); ++cit ) {
+ if( format.name == (*cit).from->name ) return true;
+ if( format.name == (*cit).to->name ) return true;
+ }
+ return false;
+}
+
+
+bool FormPreferences::ConvertersDelete()
+{
+ Command command( 0, 0, "" );
+ if( !ConvertersSetCommand( command ) )
+ return false;
+
+ string from = command.from->prettyname;
+ string to = command.to->prettyname;
+ pair<string, string> FromTo = pair<string, string>(from, to);
+
+ vector<Command>::iterator it = // non-const because it's modified below
+ find_if(commands_vec.begin(), commands_vec.end(),
+ compare_memfun(&Command::getFromToPrettyname, FromTo));
+
+ fl_freeze_form(converters_->form);
+
+ if (it == commands_vec.end()) {
+ fl_deactivate_object(converters_->button_delete);
+ fl_set_object_lcol(converters_->button_delete, FL_INACTIVE);
+
+ fl_unfreeze_form(converters_->form);
+ return false;
+ }
+
+ commands_vec.erase(it);
+ ConvertersClear();
+
+ fl_unfreeze_form(converters_->form);
+ return true;
+}
+
+
+bool FormPreferences::ConvertersInput()
+{
+ string from = fl_get_choice_text( converters_->choice_from );
+ from = strip( frontStrip( from ) );
+
+ string to = fl_get_choice_text( converters_->choice_to );
+ to = strip( frontStrip( to ) );
+
+ string name;
+ if( !from.empty() && !to.empty() )
+ name = from + " -> " + to;
+
+ int sel = 0;
+ if( !name.empty() ) {
+ for( int i = 0;
+ i < fl_get_browser_maxline(converters_->browser_all);
+ ++i ) {
+ string str =
+ fl_get_browser_line( converters_->browser_all,
+ i+1 );
+ if( str == name ) {
+ sel = i+1;
+ break;
+ }
+ }
+ }
+
+ fl_freeze_form(converters_->form);
+
+ if( sel == 0 ) {
+ fl_set_object_label( converters_->button_add,
+ idex(_("Add|#A")) );
+ fl_set_button_shortcut( converters_->button_add,
+ scex(_("Add|#A")), 1);
+
+ if( name.empty() ) {
+ fl_deactivate_object(converters_->button_add);
+ fl_set_object_lcol(converters_->button_add, FL_INACTIVE);
+ } else {
+ fl_activate_object(converters_->button_add);
+ fl_set_object_lcol(converters_->button_add, FL_BLACK);
+ }
+
+ fl_deselect_browser(converters_->browser_all);
+
+ fl_deactivate_object(converters_->button_delete);
+ fl_set_object_lcol(converters_->button_delete, FL_INACTIVE);
+
+ } else {
+ fl_set_object_label( converters_->button_add,
+ idex(_("Modify|#M")) );
+ fl_set_button_shortcut( converters_->button_add,
+ scex(_("Modify|#M")), 1);
+
+ int top = sel-6;
+ if( top < 1 ) top = 0;
+ fl_set_browser_topline(converters_->browser_all, top);
+ fl_select_browser_line(converters_->browser_all, sel);
+
+ fl_activate_object(converters_->button_add);
+ fl_set_object_lcol(converters_->button_add, FL_BLACK);
+
+ fl_activate_object(converters_->button_delete);
+ fl_set_object_lcol(converters_->button_delete, FL_BLACK);
+ }
+
+ fl_unfreeze_form(converters_->form);
+ return true;
+}
+
+
+bool FormPreferences::ConvertersSetCommand( Command & command ) const
+{
+ string from = fl_get_choice_text( converters_->choice_from );
+ from = strip( frontStrip( from ) );
+ if( from.empty() )
+ return false;
+
+ vector<Format>::const_iterator fit =
+ find_if(formats_vec.begin(), formats_vec.end(),
+ compare_memfun(&Format::getprettyname, from));
+ if( fit == formats_vec.end() )
+ return false;
+
+ string to = fl_get_choice_text( converters_->choice_to );
+ to = strip( frontStrip( to ) );
+ if( to.empty() )
+ return false;
+
+ vector<Format>::const_iterator tit =
+ find_if(formats_vec.begin(), formats_vec.end(),
+ compare_memfun(&Format::getprettyname, to));
+ if( tit == formats_vec.end() )
+ return false;
+
+ string converter = fl_get_input( converters_->input_converter );
+ string flags = fl_get_input( converters_->input_flags );
+
+ command.from = fit;
+ command.to = tit;
+ command.command = converter;
+
+ return true;
+}
+
+
+void FormPreferences::ConvertersUpdateChoices()
+{
+ string choice;
+ for( vector<Format>::iterator cit = formats_vec.begin();
+ cit != formats_vec.end(); ++cit ) {
+ if( !choice.empty() )
+ choice += " | ";
+ else
+ choice += " ";
+ choice += (*cit).prettyname;
+ }
+ choice += " ";
+
+ fl_clear_choice( converters_->choice_from );
+ fl_addto_choice( converters_->choice_from, choice.c_str() );
+
+ fl_clear_choice( converters_->choice_to );
+ fl_addto_choice( converters_->choice_to, choice.c_str() );
+}
+
+