]> git.mxchange.org Git - flightgear.git/commitdiff
Updates from Fred to add a progress bar and fix visual glitches.
authorcurt <curt>
Mon, 16 Feb 2004 14:08:20 +0000 (14:08 +0000)
committercurt <curt>
Mon, 16 Feb 2004 14:08:20 +0000 (14:08 +0000)
Tweaks by Curt to progress bar, plus sanity checks on included uninstall
box entries.

utils/fgadmin/src/fgadmin.cxx
utils/fgadmin/src/fgadmin.fl
utils/fgadmin/src/fgadmin.h
utils/fgadmin/src/fgadmin_funcs.cxx
utils/fgadmin/src/untarka.c
utils/fgadmin/src/untarka.h
utils/fgadmin/visualc/fgadmin/fgadmin.vcproj

index 2578284f0e5015daf7ab835aa3f9c2dd42283b0f..e9e55524b67369b67e3a93533607a1e41f4c048f 100644 (file)
@@ -47,7 +47,7 @@ FGAdminUI::FGAdminUI() {
   { Fl_Double_Window* o = main_window = new Fl_Double_Window(465, 435, "FlightGear Admin Wizard");
     w = o;
     o->user_data((void*)(this));
-    { Fl_Button* o = quit_b = new Fl_Button(190, 405, 85, 25, "Quit");
+    { Fl_Button* o = quit_b = new Fl_Button(360, 405, 85, 25, "Quit");
       o->callback((Fl_Callback*)cb_quit_b);
     }
     { Fl_Button* o = source_b = new Fl_Button(5, 5, 225, 25, "Select Scenery Source ...");
@@ -68,6 +68,10 @@ FGAdminUI::FGAdminUI() {
       o->labelfont(1);
       o->callback((Fl_Callback*)cb_remove_b);
     }
+    { Fl_Progress* o = progress = new Fl_Progress(20, 405, 195, 25);
+      o->color(FL_BACKGROUND_COLOR);
+      o->selection_color((Fl_Color)175);
+    }
     o->end();
   }
 }
index 536bd52008e6961c3c9ed35624894547b93e87a7..afb2b62fca8218458521960ab61918ea76b14950 100644 (file)
@@ -11,7 +11,7 @@ decl {\#include <FL/Fl_Preferences.H>} {public
 decl {using std::string;} {public
 } 
 
-class FGAdminUI {open selected
+class FGAdminUI {open
 } {
   decl {\#include <iostream>} {}
   decl {using std::cout;} {}
@@ -20,12 +20,12 @@ class FGAdminUI {open selected
   } {
     Fl_Window main_window {
       label {FlightGear Admin Wizard} open
-      xywh {187 544 465 435} type Double visible
+      xywh {294 195 465 435} type Double visible
     } {
       Fl_Button quit_b {
         label Quit
         callback {quit();}
-        xywh {190 405 85 25}
+        xywh {360 405 85 25}
       }
       Fl_Button source_b {
         label {Select Scenery Source ...}
@@ -63,6 +63,9 @@ refresh_lists();}
         callback {remove_selected();}
         xywh {250 360 195 35} labelfont 1
       }
+      Fl_Progress progress {selected
+        xywh {20 405 195 25} color 49 selection_color 175
+      }
     }
   }
   decl {~FGAdminUI();} {public
@@ -71,6 +74,8 @@ refresh_lists();}
   }
   decl {void show();} {public
   }
+  decl {static void step( void * );} {public
+  }
   decl {void refresh_lists();} {}
   decl {void quit();} {}
   decl {void select_install_source();} {}
index 821e2be5feb0839535ed3e79ac98a00633b85ee4..42926f263e08209104cdc6ee162ea27d5dd56c77 100644 (file)
@@ -10,6 +10,7 @@ using std::string;
 #include <FL/Fl_Button.H>
 #include <FL/Fl_Input.H>
 #include <FL/Fl_Check_Browser.H>
+#include <FL/Fl_Progress.H>
 
 class FGAdminUI {
 public:
@@ -44,9 +45,11 @@ private:
   inline void cb_remove_b_i(Fl_Button*, void*);
   static void cb_remove_b(Fl_Button*, void*);
 public:
+  Fl_Progress *progress;
   ~FGAdminUI();
   void init();
   void show();
+  static void step( void * );
 private:
   void refresh_lists();
   void quit();
index d17d7fd22c59d73ed904c4932a848e261bace128..735a86f324c059de166cbfa12b485683d67bcaf4 100644 (file)
@@ -42,6 +42,8 @@ using std::endl;
 using std::vector;
 using std::string;
 
+static const float min_progress = 0.0;
+static const float max_progress = 5000.0;
 
 // destructor
 FGAdminUI::~FGAdminUI() {
@@ -64,6 +66,9 @@ void FGAdminUI::init() {
     dest = buf;
 
     refresh_lists();
+
+    progress->minimum( min_progress );
+    progress->maximum( max_progress );
 }
 
 // show our UI
@@ -180,6 +185,8 @@ void FGAdminUI::update_install_box() {
         }
 
         delete [] sort_list;
+
+        install_box->redraw();
     }
 }
 
@@ -196,7 +203,13 @@ void FGAdminUI::update_remove_box() {
         ulDir *dir = ulOpenDir( dest.c_str() ) ;
         ulDirEnt *ent;
         while ( ent = ulReadDir( dir ) ) {
-            if ( strcmp(ent->d_name, ".") && strcmp(ent->d_name, "..") ) {
+            if ( strlen(ent->d_name) != 7 ) {
+                // simple heuristic to ingore non-scenery directories
+            } else if ( ent->d_name[0] != 'e' && ent->d_name[0] != 'w' ) {
+                // further sanity checks on name
+            } else if ( ent->d_name[4] != 'n' && ent->d_name[4] != 's' ) {
+                // further sanity checks on name
+            } else {
                 dir_list.push_back( ent->d_name );
             }
         }
@@ -216,6 +229,8 @@ void FGAdminUI::update_remove_box() {
         }
 
         delete [] sort_list;
+
+        remove_box->redraw();
     }
 }
 
@@ -224,6 +239,9 @@ void FGAdminUI::update_remove_box() {
 void FGAdminUI::install_selected() {
     char *f;
 
+    install_b->deactivate();
+    remove_b->deactivate();
+
     // traverse install box and install each item
     for ( int i = 0; i <= install_box->nitems(); ++i ) {
         if ( install_box->checked( i ) ) {
@@ -231,15 +249,21 @@ void FGAdminUI::install_selected() {
             SGPath file( source );
             file.append( f );
             cout << "installing " << file.str() << endl;
-            tarextract( (char *)file.c_str(), (char *)dest.c_str(), true, 0 );
+            progress->value( min_progress );
+            main_window->cursor( FL_CURSOR_WAIT );
+            tarextract( (char *)file.c_str(), (char *)dest.c_str(), true, &FGAdminUI::step, this );
+            progress->value( min_progress );
+            main_window->cursor( FL_CURSOR_DEFAULT );
         }
     }
+    install_b->activate();
+    remove_b->activate();
 
     refresh_lists();
 }
 
 
-static void remove_dir( const char *dir_name ) {
+static void remove_dir( const char *dir_name, void (*step)(void*), void *data ) {
     ulDir *dir = ulOpenDir( dir_name ) ;
     ulDirEnt *ent;
     while ( ent = ulReadDir( dir ) ) {
@@ -250,11 +274,12 @@ static void remove_dir( const char *dir_name ) {
         } else if ( ent->d_isdir ) {
             SGPath child( dir_name );
             child.append( ent->d_name );
-            remove_dir( child.c_str() );
+            remove_dir( child.c_str(), step, data );
         } else {
             SGPath child( dir_name );
             child.append( ent->d_name );
             unlink( child.c_str() );
+            if (step) step( data );
         }
     }
     ulCloseDir( dir );
@@ -266,17 +291,42 @@ static void remove_dir( const char *dir_name ) {
 void FGAdminUI::remove_selected() {
     char *f;
 
+    install_b->deactivate();
+    remove_b->deactivate();
     // traverse remove box and recursively remove each item
     for ( int i = 0; i <= remove_box->nitems(); ++i ) {
         if ( remove_box->checked( i ) ) {
             f = remove_box->text( i );
             SGPath dir( dest );
             dir.append( f );
+            progress->value( min_progress );
+            main_window->cursor( FL_CURSOR_WAIT );
             cout << "removing " << dir.str() << endl;
-            remove_dir( dir.c_str() );
+            remove_dir( dir.c_str(), &FGAdminUI::step, this );
+            progress->value( min_progress );
+            main_window->cursor( FL_CURSOR_DEFAULT );
         }
     }
+    install_b->activate();
+    remove_b->activate();
 
     refresh_lists();
    
 }
+
+
+void FGAdminUI::step(void *data)
+{
+   Fl_Progress *p = ((FGAdminUI*)data)->progress;
+
+   // we don't actually know the total work in advanced due to the
+   // nature of tar archives, and it would be inefficient to prescan
+   // the files, so just cycle the progress bar until we are done.
+   float tmp = p->value() + 1;
+   if ( tmp > max_progress ) {
+       tmp = 0.0;
+   }
+   p->value( tmp );
+
+   Fl::check();
+}
index a65d1c6525245c20b23f7a6f4e6ae62ad6a8d286..f7f35bd89249e0698c520c0a0b5ed9c8f6e6c693 100644 (file)
@@ -1166,7 +1166,7 @@ static int matchname (int arg,int argc,char **argv,char *fname)
 
 /* Tar file list or extract */
 
-static int tar (Readable* rin,int action,int arg,int argc,char **argv, char const* TGZfile, int verbose, void (*step)(void)) {
+static int tar (Readable* rin,int action,int arg,int argc,char **argv, char const* TGZfile, int verbose, void (*step)(void *), void *data) {
   union  tar_buffer buffer;
   int    is_tar_ok=0;
   int    len;
@@ -1341,7 +1341,7 @@ static int tar (Readable* rin,int action,int arg,int argc,char **argv, char cons
                  outfile = NULL;
                  utime(fname,&settime);
 #endif
-                  if (step) step();
+                  if (step) step(data);
                }
            }
        }
@@ -1440,7 +1440,7 @@ int main(int argc,char **argv) {
        case 3: fprintf(stderr, "%s: not a tar file: %s\n", prog, TGZfile); return 1;
        case 4: fprintf(stderr, "%s: cannot open tar file: %s\n", prog, TGZfile); return 1;
       }
-      return tar(&r, action, arg, argc, argv, TGZfile, 1, 0);
+      return tar(&r, action, arg, argc, argv, TGZfile, 1, 0, 0);
       default: error("Unknown option!");
     }
     return 0;
@@ -1448,7 +1448,7 @@ int main(int argc,char **argv) {
 #endif
 
 void
-tarextract(char *TGZfile,char *dest,int verbose, void (*step)(void))
+tarextract(char *TGZfile,char *dest,int verbose, void (*step)(void *), void *data)
 {
    Readable    r;
    if (xOpen4Read(&r,TGZfile) == 0)
@@ -1459,6 +1459,6 @@ tarextract(char *TGZfile,char *dest,int verbose, void (*step)(void))
       chdir( dest );
       argv[0] = "fgadmin";
       argv[1] = TGZfile;
-      tar(&r, TGZ_EXTRACT, arg, argc, argv, TGZfile, 0, step);
+      tar(&r, TGZ_EXTRACT, arg, argc, argv, TGZfile, 0, step, data);
       }
 }
index f1ee99b1b3f8e42628d91dedc3d2b6e824bc8646..32fd22bfe84ad58e5cd2466e1aa162a5a8ca8124 100644 (file)
@@ -7,4 +7,4 @@ using std::string;
 
 // extract the specified tar file into the specified destination
 // directory
-extern "C" void tarextract( char *tarfile, char *destdir, int verbose, void (*step)(void) );
+extern "C" void tarextract( char *tarfile, char *destdir, int verbose, void (*step)(void*), void *data );
index 8c6a3f3f841326e459afe3bc1784c4214a9550ec..a565f2c3aa937bf09928442368b2683db4ba18d0 100644 (file)
                                Optimization="2"\r
                                InlineFunctionExpansion="1"\r
                                OmitFramePointers="TRUE"\r
-                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"\r
+                               AdditionalIncludeDirectories="..\..\..\..\fltk-1.1.4"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;HAVE_ZLIB"\r
                                StringPooling="TRUE"\r
-                               RuntimeLibrary="4"\r
+                               RuntimeLibrary="2"\r
                                EnableFunctionLevelLinking="TRUE"\r
                                UsePrecompiledHeader="0"\r
                                WarningLevel="3"\r
                                Name="VCCustomBuildTool"/>\r
                        <Tool\r
                                Name="VCLinkerTool"\r
+                               AdditionalDependencies="fltk.lib Simgear.lib ul.lib comctl32.lib wsock32.lib zlib.lib"\r
                                OutputFile="$(OutDir)/fgadmin.exe"\r
                                LinkIncremental="1"\r
+                               AdditionalLibraryDirectories="&quot;..\..\..\..\fltk-1.1.4\lib&quot;"\r
                                GenerateDebugInformation="TRUE"\r
                                SubSystem="1"\r
                                OptimizeReferences="2"\r
                        Name="Source Files"\r
                        Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">\r
                        <File\r
-                               RelativePath="..\..\..\src\fgadmin.cxx">\r
+                               RelativePath="..\..\src\fgadmin.cxx">\r
                        </File>\r
                        <File\r
-                               RelativePath="..\..\..\src\fgadmin_funcs.cxx">\r
+                               RelativePath="..\..\src\fgadmin_funcs.cxx">\r
                        </File>\r
                        <File\r
-                               RelativePath="..\..\..\src\main.cxx">\r
+                               RelativePath="..\..\src\main.cxx">\r
                        </File>\r
                        <File\r
-                               RelativePath="..\..\..\src\untarka.c">\r
+                               RelativePath="..\..\src\untarka.c">\r
                        </File>\r
                </Filter>\r
                <Filter\r
                        Name="Header Files"\r
                        Filter="h;hpp;hxx;hm;inl;inc">\r
                        <File\r
-                               RelativePath="..\..\..\src\fgadmin.h">\r
+                               RelativePath="..\..\src\fgadmin.h">\r
                        </File>\r
                        <File\r
-                               RelativePath="..\..\..\src\tar_utils.hxx">\r
+                               RelativePath="..\..\src\untarka.h">\r
                        </File>\r
                </Filter>\r
-               <Filter\r
-                       Name="Resource Files"\r
-                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">\r
-               </Filter>\r
        </Files>\r
        <Globals>\r
        </Globals>\r