On Mon, Nov 12, 2001, Robert O'Connor wrote: > I did an implementation of sections, but there is probably better ways of > doing it.
The changes you did cover most of the stuff I had done to support sections, so that is more or less OK also on Linux. I had to make some minor adjustments, though (see diff below). BTW, I would really recommend that you drop all these "anonymous" variable names and use proper names. Names like 'string', 'lng' and 'i' don't tell you anything about their use. Names like 'doc_name', 'bpp', and 'category' do ;-) > Just for curiosity, would it be possible to post a screenshot of what your > copy looks like on your computer, so it is easier to get an idea of what > things look like? When I was about to create a screenshot of the exclusion list it crashed. Some problem in listctrl_load_rows. I will take a look at it. I have put a few screenshots of other dialogs at http://www.sslug.dk/~micke/plucker/desktop/ /Mike -- --- channel_dialog.cpp 12 Nov 2001 18:22:20 -0000 1.1.2.3 +++ channel_dialog.cpp 13 Nov 2001 18:03:05 -0000 @@ -110,39 +110,52 @@ // the configuration file void channel_dialog::read_configuration() { - wxString string; - wxString buf; - int i = 0; - long lng = 0; - wxLogDebug( "Starting to read configuration file" ); + wxString key; + wxString doc_name; + + key = "doc_name"; + if ( ! the_configuration->Exists( key ) ) + key = "db_name"; + + if ( ! the_configuration->Exists( key ) ) + key = "doc_file"; + + if ( ! the_configuration->Exists( key ) ) + key = "db_file"; + + doc_name = the_configuration->Read( key, _T( "Unnamed Channel" ) ); + doc_name = basename( doc_name.c_str() ); + XMLCTRL( *the_channel_dialog, "channel_dialog_textctrl", wxTextCtrl ) - ->SetValue( the_configuration->Read( "doc_name", _T( "Unnamed Channel" ) ) ); + ->SetValue( doc_name ); wxLogDebug( "Initialized doc_name" ); //------Start Tab------------------------------------------------------------------- - string = the_configuration->Read( "home_url", _T( "" ) ); + wxString home_url; + + home_url = the_configuration->Read( "home_url", _T( "" ) ); // If no url specified: must be the default plucker home.html HTML page - if ( string == "" - || string == "plucker:/home.html" - || ( string.Contains( "plucker:" ) && string.Contains ( "channels" ) && string.Contains( "home.html" ) ) - ) { + if ( home_url == "" || home_url == "plucker:/home.html" || + ( home_url.Contains( "plucker:" ) && + home_url.Contains ( "channels" ) && + home_url.Contains( "home.html" ) ) ) { XMLCTRL( *the_channel_dialog, "channel_dialog_start_tab_links_radiobutton", wxRadioButton ) ->SetValue( TRUE ); // Else a file: protocol ( NULL argument tells not to store the remaining string anywhere ) - } else if ( string.StartsWith( "file:", NULL ) ) { + } else if ( home_url.StartsWith( "file:", NULL ) ) { XMLCTRL( *the_channel_dialog, "channel_dialog_start_tab_file_radiobutton", wxRadioButton ) ->SetValue( TRUE ); XMLCTRL( *the_channel_dialog, "channel_dialog_start_tab_file_textctrl", wxTextCtrl ) - ->SetValue( string ); + ->SetValue( home_url ); // Everything else into a website address } else { XMLCTRL( *the_channel_dialog, "channel_dialog_start_tab_url_radiobutton", wxRadioButton ) ->SetValue( TRUE ); XMLCTRL( *the_channel_dialog, "channel_dialog_start_tab_url_textctrl", wxTextCtrl ) - ->SetValue( string ); + ->SetValue( home_url ); } wxLogDebug( "Initialized home_url" ); @@ -156,10 +169,13 @@ ->SetValue( (bool) the_configuration->Read( "home_stayonhost", 0l ) ); wxLogDebug( "Initialized home_stayonhost" ); - string = the_configuration->Read( "home_staybelow", _T("") ); + + wxString staybelow; + + staybelow = the_configuration->Read( "home_staybelow", _T("") ); XMLCTRL( *the_channel_dialog, "channel_dialog_limits_tab_staybelow_textctrl", wxTextCtrl ) - ->SetValue( string ); - if ( string != _T("") ) { + ->SetValue( staybelow ); + if ( staybelow != _T("") ) { XMLCTRL( *the_channel_dialog, "channel_dialog_limits_tab_staybelow_checkbox", wxCheckBox ) ->SetValue ( TRUE ); } @@ -178,30 +194,44 @@ //------Images Tab------------------------------------------------------------------ - if ( the_configuration->Read( "bpp", 1l ) != 0 ) { + unsigned long bpp; + int choice; + + bpp = the_configuration->Read( "bpp", 1l ); + if ( 0 < bpp ) XMLCTRL( *the_channel_dialog, "channel_dialog_images_tab_include_images_checkbox", wxCheckBox ) ->SetValue( TRUE ); - } - i = 0; - switch ( the_configuration->Read( "bpp", 1l ) ) { - case 1: - i = 0; - break; - case 2: - i = 1; - break; - case 4: - i = 2; - break; - case 8: - i = 3; - break; - case 16: - i = 4; + + switch ( bpp ) { + case 1: + choice = 0; + break; + + case 2: + choice = 1; + break; + + case 4: + choice = 2; + break; + + case 8: + choice = 3; + break; + + case 16: + choice = 4; + break; + + default: + choice = 0; + break; } XMLCTRL( *the_channel_dialog, "channel_dialog_images_tab_depth_choice", wxChoice ) - ->SetSelection( i ); - wxLogDebug( "Initialized bpp" ); + ->SetSelection( choice ); + + wxLogDebug( "Initialized bpp" ); + XMLCTRL( *the_channel_dialog, "channel_dialog_images_tab_thumbnail_if_bigger_width_spinctrl", wxSpinCtrl ) ->SetValue( (int) the_configuration->Read( "maxwidth", 150l ) ); @@ -211,20 +241,28 @@ ->SetValue( (int) the_configuration->Read( "maxheight", 250l ) ); wxLogDebug( "Initialized maxheight" ); + // Some GUI tricks here. Always link by setting a very high number, Never link by setting // to zero. Else use the specified value. - lng = (long) the_configuration->Read( "alt_maxwidth", 1000000l ); - switch ( lng ) { - case 1000000: + const long ONLY_THUMBNAIL = 0; + const long ALWAYS_LINK = 1000000; + + long alt_maxwidth; + + alt_maxwidth = the_configuration->Read( "alt_maxwidth", ALWAYS_LINK ); + switch ( alt_maxwidth ) { + case ALWAYS_LINK: XMLCTRL( *the_channel_dialog, "channel_dialog_images_tab_always_link_radiobutton", wxRadioButton ) ->SetValue( TRUE ); wxLogDebug( "Initialized alt_maxwidth-height as 1000000" ); break; - case 0: + + case ONLY_THUMBNAIL: XMLCTRL( *the_channel_dialog, "channel_dialog_images_tab_only_thumbnail_radiobutton", wxRadioButton ) ->SetValue( TRUE ); wxLogDebug( "Initialized alt_maxwidth-height as 0" ); break; + default: XMLCTRL( *the_channel_dialog, "channel_dialog_images_tab_only_link_radiobutton", wxRadioButton ) ->SetValue( TRUE ); @@ -235,28 +273,40 @@ wxLogDebug( "Initialized alt_maxwidth/height as a specified value" ); break; } - wxLogDebug( "Initializion of alt_maxwidth complete" ); + wxLogDebug( "Initializion of alt_maxwidth complete" ); //------Output Tab------------------------------------------------------------------ - // DOC is choice index 0, ZLIB is choice index 1, so just cast from boolean. + int compression; + + key = "compression"; + if ( ! the_configuration->Exists( key ) ) + key = "zlib_compression"; + + // DOC is choice index 0, ZLIB is choice index 1 + compression = the_configuration->Read( key, 0l ); + XMLCTRL( *the_channel_dialog, "channel_dialog_output_tab_compression_choice", wxChoice ) - ->SetSelection( (int) the_configuration->Read( "zlib_compression", 1l ) ); - wxLogDebug( "Initialized zlib_compression" ); + ->SetSelection( compression ); + wxLogDebug( "Initialized compression" ); - i = the_configuration->Read( "no_image_compression_limit", 50l); + long compression_limit; + + compression_limit = the_configuration->Read( "image_compression_limit", 50l); XMLCTRL( *the_channel_dialog, "channel_dialog_output_tab_only_compress_spinctrl", wxSpinCtrl ) - ->SetValue( i ); - if ( i != 0 ) { + ->SetValue( compression_limit ); + if ( 0 < compression_limit ) { XMLCTRL( *the_channel_dialog, "channel_dialog_output_tab_only_compress_checkbox", wxCheckBox ) ->SetValue ( TRUE ); } - wxLogDebug( "Initialized no_image_compression" ); + wxLogDebug( "Initialized image_compression" ); - string = the_configuration->Read( "category", _T("") ); + wxString category; + + category = the_configuration->Read( "category", _T("") ); XMLCTRL( *the_channel_dialog, "channel_dialog_output_tab_category_textctrl", wxTextCtrl ) - ->SetValue( string ); - if ( string != _T("") ) { + ->SetValue( category ); + if ( category != _T("") ) { XMLCTRL( *the_channel_dialog, "channel_dialog_output_tab_category_checkbox", wxCheckBox ) ->SetValue ( TRUE ); } @@ -280,19 +330,23 @@ ->SetValue( (bool) the_configuration->Read( "launchable_bit", 0l ) ); wxLogDebug( "Initialized launchable_bit" ); - string = the_configuration->Read( "big_icon", _T("") ); + wxString big_icon; + + big_icon = the_configuration->Read( "big_icon", _T("") ); XMLCTRL( *the_channel_dialog, "channel_dialog_output_tab_custom_large_icon_textctrl", wxTextCtrl ) - ->SetValue( string ); - if ( string != _T("") ) { + ->SetValue( big_icon ); + if ( big_icon != _T("") ) { XMLCTRL( *the_channel_dialog, "channel_dialog_output_tab_custom_large_icon_checkbox", wxCheckBox ) ->SetValue ( TRUE ); } wxLogDebug( "Initialized big_icon" ); - string = the_configuration->Read( "small_icon", _T("") ); + wxString small_icon; + + small_icon = the_configuration->Read( "small_icon", _T("") ); XMLCTRL( *the_channel_dialog, "channel_dialog_output_tab_custom_small_icon_textctrl", wxTextCtrl ) - ->SetValue( string ); - if ( string != _T("") ) { + ->SetValue( small_icon ); + if ( small_icon != _T("") ) { XMLCTRL( *the_channel_dialog, "channel_dialog_output_tab_custom_small_icon_checkbox", wxCheckBox ) ->SetValue ( TRUE ); } @@ -300,35 +354,47 @@ //------Sync Tab-------------------------------------------------------------------- - string = the_configuration->Read( "doc_file", _T("") ); - // If doc_name is empty, or already is the section name, select the autogenerate button - buf = the_configuration->GetPath( ); - buf = buf.AfterFirst('/'); - if ( string == _T("") || string == buf ) { + wxString doc_file; + wxString path; + + key = "doc_file"; + if ( ! the_configuration->Exists( key ) ) + key = "db_file"; + + doc_file = the_configuration->Read( key, _T("") ); + + // If doc_file is empty, or already is the section name, select the autogenerate +button + path = the_configuration->GetPath(); + path = path.AfterFirst( '/' ); + if ( doc_file == _T("") || doc_file == path ) { XMLCTRL( *the_channel_dialog, "channel_dialog_sync_tab_autogenerate_filename_radiobutton", wxRadioButton ) ->SetValue( TRUE ); // Else fill in the custom filename textctrl and set the radiobutton } else { XMLCTRL( *the_channel_dialog, "channel_dialog_sync_tab_specify_filename_textctrl", wxTextCtrl ) - ->SetValue( string ); + ->SetValue( doc_file ); XMLCTRL( *the_channel_dialog, "channel_dialog_sync_tab_specify_filename_radiobutton", wxRadioButton ) ->SetValue( TRUE ); } wxLogDebug( "Initialized doc_file" ); - string = the_configuration->Read( "before_command", _T("") ); + wxString before_command; + + before_command = the_configuration->Read( "before_command", _T("") ); XMLCTRL( *the_channel_dialog, "channel_dialog_sync_tab_command_before_textctrl", wxTextCtrl ) - ->SetValue( string ); - if ( string != _T("") ) { + ->SetValue( before_command ); + if ( before_command != _T("") ) { XMLCTRL( *the_channel_dialog, "channel_dialog_sync_tab_command_before_checkbox", wxCheckBox ) ->SetValue ( TRUE ); } wxLogDebug( "Initialized before_command" ); - string = the_configuration->Read( "after_command", _T("") ); + wxString after_command; + + after_command = the_configuration->Read( "after_command", _T("") ); XMLCTRL( *the_channel_dialog, "channel_dialog_sync_tab_command_after_textctrl", wxTextCtrl ) - ->SetValue( string ); - if ( string != _T("") ) { + ->SetValue( after_command ); + if ( after_command != _T("") ) { XMLCTRL( *the_channel_dialog, "channel_dialog_sync_tab_command_after_checkbox", wxCheckBox ) ->SetValue ( TRUE ); } --- configuration.cpp 12 Nov 2001 18:22:20 -0000 1.1.2.4 +++ configuration.cpp 13 Nov 2001 18:03:06 -0000 @@ -49,11 +49,15 @@ wxString string; // TODO: set this to where it will be +#ifdef __WXGTK__ + string = "plucker" + get_configuration_extension(); + the_configuration = new wxFileConfig( string ); +#elif __WIN95__ string = wxGetCwd() << '/' << "plucker" << get_configuration_extension(); - wxLogDebug( "String for main configuration is %s", string.c_str() ); - the_configuration = new wxFileConfig( "Plucker Desktop", "The Plucker Team", string, wxEmptyString, wxCONFIG_USE_LOCAL_FILE ); +#endif + wxLogDebug( "String for main configuration is %s", string.c_str() ); // Sets the configuration to the currently active one. wxConfigBase::Set( the_configuration ); --- main_dialog.cpp 12 Nov 2001 18:22:20 -0000 1.1.2.4 +++ main_dialog.cpp 13 Nov 2001 18:03:08 -0000 @@ -194,10 +194,9 @@ void main_dialog::listctrl_load_rows() { wxString configuration_section; // Section of channel in configuration file - wxString string; // Temp string int row_number = 0; // List row to insert channel information long index = 0; // Index counter for looping through the sections - bool successful = FALSE; // To monitor success of getting first/next group + bool foundSection = FALSE; // To monitor success of getting first/next +group wxFile file; // To make a home.html if missing. wxLogDebug( "Starting to load channel sections into listctrl rows" ); @@ -211,52 +210,88 @@ // TODO: also make the default channel one, in case in is gone. - for ( successful = the_configuration->GetFirstGroup( configuration_section, index ); - successful ; - successful = the_configuration->GetNextGroup( configuration_section, index ) - ) { - // Load up the each channel section (group) from the plucker.ini/pluckerrc file - wxLogDebug( "Configuration section is %s", configuration_section.c_str() ); + foundSection = the_configuration->GetFirstGroup( configuration_section, + index ); + while ( foundSection ) { + // Load up the each channel section (group) from the + // plucker.ini/pluckerrc file + wxLogDebug( "Configuration section is %s", + configuration_section.c_str() ); if ( is_channel_configuration_section( configuration_section ) ) { - // TODO: check for illegal characters (spaces, etc) in the section name, and rename - // the section in the config file as necessary before loading it into listctrl. + // TODO: check for illegal characters (spaces, etc) in the + // section name, and rename the section in the config file + // as necessary before loading it into listctrl. - // Put the section_name as first zero-width column so know what section of - // configuration file to call when configure/update the channel. - MAIN_LISTCTRL->InsertItem( row_number, configuration_section ); + wxString doc_name; + + doc_name = configuration_section + "/doc_name"; + + if ( ! the_configuration->Exists( doc_name ) ) + doc_name = configuration_section + "/db_name"; + + if ( ! the_configuration->Exists( doc_name ) ) + doc_name = configuration_section + "/doc_file"; + + if ( ! the_configuration->Exists( doc_name ) ) + doc_name = configuration_section + "/db_file"; + + // only include channels with an assigned document name + if ( the_configuration->Exists( doc_name ) ) { + wxString channel_name; + wxString due_date; + wxString home_html; + + // Put the section_name as first zero-width column so + // know what section of configuration file to call when + // configure/update the channel. + MAIN_LISTCTRL->InsertItem( row_number, configuration_section ); - // Read the current channel name and stuff it into a row. TODO: The 0 in 3rd - // argument of InsertItem put as the image index for a little glyph later on. - string = the_configuration->Read( configuration_section + '/' + "doc_name", - _T( "Unnamed Channel") ); - MAIN_LISTCTRL->SetItem( row_number, NAME_COLUMN, string, 0 ); + // Read the current channel name and stuff it into a + // row. TODO: The 0 in 3rd argument of InsertItem put + // as the image index for a little glyph later on. + channel_name = the_configuration->Read( doc_name, + _T( "Unnamed Channel") ); + + channel_name = basename( channel_name.c_str() ); + MAIN_LISTCTRL->SetItem( row_number, NAME_COLUMN, + channel_name, 0 ); - // Read the due date and put it in its column. - // TODO: Put the actual item that will go in here (probably will be a converted date). - string = the_configuration->Read( configuration_section + '/' + "schedule_refresh_interval", - _T( "Never" ) ); - MAIN_LISTCTRL->SetItem( row_number, DUE_COLUMN, string ); + // Read the due date and put it in its column. + // TODO: Put the actual item that will go in here + // (probably will be a converted date). + due_date = the_configuration->Read( configuration_section + + "/schedule_refresh_interval", _T( "Never" ) ); + MAIN_LISTCTRL->SetItem( row_number, DUE_COLUMN, due_date ); - // Make a "channel" and a "channel/cache" directory for each entry - if (! wxDirExists( get_plkr_directory( CHANNELS ) + '/' + configuration_section ) ) { - wxMkdir( get_plkr_directory( CHANNELS ) + '/' + configuration_section, 0777 ); - wxLogDebug( "Finished testing/trying to make channel-specific directory" ); - wxMkdir( get_plkr_directory( CHANNELS ) + '/' + configuration_section + "/cache", 0777 ); - wxLogDebug( "Finished testing/trying to make channel's cache directory" ); - } - // If no home.html in the channel directory, make one of those too. - // TODO: Copy from the default home.html instead of making an empty one. - string = get_plkr_directory( CHANNELS ) + '/' + configuration_section + '/' + "home.html"; - if ( ! wxFileExists( string ) ) { - file.Create( string ); - file.Close(); - wxLogDebug( "Finished trying to make channel's home.html" ); - } + // Make a "channel" and a "channel/cache" directory for + // each entry + if (! wxDirExists( get_plkr_directory( CHANNELS ) + '/' + + configuration_section ) ) { + wxMkdir( get_plkr_directory( CHANNELS ) + '/' + + configuration_section, 0777 ); + wxLogDebug( "Finished testing/trying to make channel-specific +directory" ); + wxMkdir( get_plkr_directory( CHANNELS ) + '/' + + configuration_section + "/cache", 0777 ); + wxLogDebug( "Finished testing/trying to make channel's cache +directory" ); + } + // If no home.html in the channel directory, make one of + // those too. TODO: Copy from the default home.html instead + // of making an empty one. + home_html = get_plkr_directory( CHANNELS ) + '/' + + configuration_section + '/' + "home.html"; + if ( ! wxFileExists( home_html ) ) { + file.Create( home_html ); + file.Close(); + wxLogDebug( "Finished trying to make channel's home.html" ); + } - // Increase the row number where we will insert new one. - row_number++; + // Increase the row number where we will insert new one. + row_number++; + } } - } + foundSection = the_configuration->GetNextGroup( configuration_section, + index ); + } } // Get an array of sections names from channel rows currently selected in the listctrl