home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1997 #3 / amigaacscoverdisc / utilities / shareware / graphics / gallery / gallery.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-05  |  23.9 KB  |  783 lines

  1. #define __VERSION__     "39"
  2. #define __REVISION__     "4"
  3. #define __NAME__            "Gallery"
  4. #define __AUTHOR__        "Markus Hillenbrand"
  5.  
  6. char *V = "$VER: " __NAME__ " " __VERSION__ "." __REVISION__ " (" __DATE__ ")";
  7.  
  8. #include <string.h>
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11.  
  12. #include <GUIC_Classes/GUIC_System.hpp>
  13. #include <GUIC_Classes/GUIC_Date.hpp>
  14. #include <GUIC_Classes/GUIC_Error.hpp>
  15. #include <GUIC_Classes/GUIC_Frame.hpp>
  16. #include <GUIC_Classes/GUIC_Application.hpp>
  17. #include <GUIC_Classes/GUIC_Screen.hpp>
  18. #include <GUIC_Classes/GUIC_Window.hpp>
  19. #include <GUIC_Classes/GUIC_Error.hpp>
  20. #include <GUIC_Classes/GUIC_Exceptions.hpp>
  21. #include <GUIC_Classes/GUIC_DirectoryExamine.hpp>
  22. #include <GUIC_Classes/GUIC_FileExamine.hpp>
  23. #include <GUIC_Classes/GUIC_File.hpp>
  24. #include <GUIC_Classes/GUIC_Key.hpp>
  25. #include <GUIC_Classes/GUIC_List.hpp>
  26. #include <GUIC_Classes/GUIC_Node.hpp>
  27. #include <GUIC_Classes/GUIC_Exceptions.hpp>
  28. #include <GUIC_Classes/GUIC_Button.hpp>
  29. #include <GUIC_Classes/GUIC_Checkbox.hpp>
  30. #include <GUIC_Classes/GUIC_String.hpp>
  31. #include <GUIC_Classes/GUIC_Integer.hpp>
  32. #include <GUIC_Classes/GUIC_Slider.hpp>
  33. #include <GUIC_Classes/GUIC_Label.hpp>
  34. #include <GUIC_Classes/GUIC_SlidingInteger.hpp>
  35. #include <GUIC_Classes/GUIC_FileString.hpp>
  36. #include <GUIC_Classes/GUIC_PathString.hpp>
  37. #include <GUIC_Classes/GUIC_Message.hpp>
  38. #include <GUIC_Classes/GUIC_FileRequester.hpp>
  39. #include <GUIC_Classes/GUIC_ProgramArgs.hpp>
  40.  
  41. #define COPYRIGHT    "<SMALL> index file created with 'Gallery', (c) 1997 by <A HREF=\"http://www.student.uni-kl.de/~hillenbr\" TARGET=_top>Markus Hillenbrand</A> </SMALL>"
  42. #define FILEFILTER     "#?.(jpeg|jpg|gif|iff|ilbm|iff24|png|bmp|pcx|tiff)"
  43.  
  44. // Defines 
  45. #define MINLINES                            3
  46. #define MINCOLUMNS                    3    
  47. #define MAXLINES                            200
  48. #define MAXCOLUMNS                    200    
  49. #define DEFAULTLINES                    3
  50. #define DEFAULTCOLUMNS            5
  51. #define MENUFRAMEWIDTH            150
  52. #define MINTHUMBNAILWIDTH         50
  53. #define MINTHUMBNAILHEIGHT        50
  54. #define MAXTHUMBNAILWIDTH        200
  55. #define MAXTHUMBNAILHEIGHT    200
  56. #define DEFTHUMBNAILWIDTH         100
  57. #define DEFTHUMBNAILHEIGHT        100
  58. #define MINTABLEBORDERSIZE        0
  59. #define MAXTABLEBORDERSIZE    20
  60. #define DEFTABLEBORDERSIZE        4
  61.  
  62. #include "GUIC_Register.hpp"
  63.  
  64. GUIC_ListC errorList;
  65. int lastDay=0,lastMonth=0,lastYear=0;
  66.  
  67.  
  68. class GalleryEntryC : public GUIC_ObjectC
  69.     {
  70.     public:
  71.         GalleryEntryC        (STRPTR f, LONG s, int d, int m, int y)     { fileName=f; size=s; day=d; month=m; year=y; }
  72.         int         compare    (GUIC_ObjectC &o);
  73.         void    print        (void) { cout << fileName << endl; }
  74.         String fileName;
  75.         int day,month,year;
  76.         LONG size;
  77.     protected:
  78.         void cleanUp(void) {};
  79.     };
  80.     
  81. int GalleryEntryC::compare(GUIC_ObjectC &o)
  82.     // First we must convert the argument to what it really is:
  83.     GalleryEntryC *g = (GalleryEntryC *)&o; 
  84.     
  85.     return strcmp(this->fileName, g->fileName); // Just compare the two file names    
  86. }
  87.  
  88. String     makeThumbnail    (GUIC_FileExamineC &file, LONG thumbnailWidth, LONG thumbnailHeight)
  89. {
  90.     String fileName = file.getName();
  91.  
  92.     int i = fileName.length();
  93.     while (--i) if (fileName[i] == '.') break;
  94.  
  95.     String thumbName = fileName.left(i);
  96.     thumbName+="_.jpg";
  97.  
  98.     try
  99.         {
  100.         GUIC_FileExamineC f(thumbName);
  101.         if (f.newer(file)) return thumbName;
  102.         }
  103.     catch (GUIC_SystemX &e) { }
  104.  
  105.     char args[1024];
  106.     sprintf ( args, "<>NIL: \"%s\" TO \"%s\" FORMAT JPEG QUALITY 90 BOXFIT %ld %ld", (char *)fileName, (char *)thumbName, thumbnailWidth, thumbnailHeight);
  107.  
  108.     cout << " - creating thumbnail for file '" << fileName << "' ... " << flush;
  109.     BOOL result = GUIC_SystemC::runProgram("GfxCon_68020", 100000, args);
  110.     if (result) cout << "done." << endl; else cout << "error occured." << endl;
  111.  
  112.     return thumbName;
  113. }
  114. void         createGallery        (GUIC_ListC &fileList, STRPTR pattern, LONG linesInTable, LONG columnsInTable, BOOL picClick, BOOL showSize, BOOL showDate, LONG menuFrameWidth, LONG thumbnailWidth, LONG thumbnailHeight, LONG tableBorderSize, STRPTR baseName)
  115. {
  116.     GalleryEntryC *key = (GalleryEntryC *)fileList.objectAt(1);
  117.     GUIC_FileExamineC firstFile(key->fileName);
  118.     String currentDir = firstFile.getPathPart();
  119.     
  120.     ldiv_t d = ldiv ( fileList.length(), columnsInTable );
  121.     int lines = d.quot;
  122.     if (d.rem) lines++;
  123.     
  124.     d = ldiv (lines, linesInTable);
  125.     int galleries = d.quot;
  126.     if (d.rem) galleries++;
  127.  
  128.     cout << "Creating " << galleries << " galleries in directory '" << currentDir << "' " << endl;
  129.     
  130.     fileList.sort();
  131.     
  132.     GUIC_FileExamineC directoryName(currentDir);
  133.  
  134.     // Create the index file with the frames
  135.     STRPTR st = (STRPTR) malloc (strlen(baseName) + 6);
  136.     if (! st) throw GUIC_MemoryX("Can't allocate memory for a string.");
  137.     sprintf(st, "%s.html", baseName);
  138.     GUIC_FileC gallery(currentDir, st, GUIC_Write);
  139.     free (st);
  140.     
  141.     gallery.write("<TITLE>Gallery '");
  142.     gallery.write(directoryName.getFilePart());
  143.     gallery.writeLn("'</TITLE>");
  144.     gallery.write("<FRAMESET COLS=");
  145.     gallery.write(menuFrameWidth);
  146.     gallery.writeLn(",*>");
  147.     gallery.write("<FRAME NAME=F1 SRC=\"");
  148.     gallery.write(baseName);
  149.     gallery.writeLn("0.html\" MarginHeight=0 MarginWidth=0 Scrolling=\"auto\" FrameBorder=0>");
  150.     gallery.write("<FRAME NAME=F2 SRC=\"");
  151.     gallery.write(baseName);
  152.     gallery.writeLn("1.html\" MarginHeight=0 MarginWidth=0 Scrolling=\"auto\" FrameBorder=0>");
  153.     gallery.writeLn("</FRAMESET>");
  154.     
  155.     // now create the overview over the galleries
  156.     st = (STRPTR) malloc (strlen(baseName) + 7);
  157.     if (! st) throw GUIC_MemoryX("Can't allocate memory for a string.");
  158.     sprintf(st, "%s0.html", baseName);
  159.     GUIC_FileC overview (currentDir, st, GUIC_Write);
  160.     free(st);
  161.     
  162.     overview.writeLn("<HTML>");
  163.     overview.write("<H2 ALIGN=Center>"); 
  164.     overview.write(directoryName.getFilePart());
  165.     overview.writeLn("</H2><BR><UL>");
  166.     for (int i=1; i<=galleries; i++)
  167.         {
  168.         overview.write("<LI><A HREF=\"");
  169.         overview.write(baseName);
  170.         overview.write(i);
  171.         overview.write(".html\" TARGET=F2>Gallery ");
  172.         overview.write(i);
  173.         overview.writeLn("</A> <BR>");
  174.         }
  175.         
  176.     overview.write("</UL><BR> <BR> <IMG SRC=internal-gopher-menu> <A HREF=\"../");
  177.     overview.write(baseName);
  178.     overview.writeLn(".html\" TARGET=_top> up </A>");
  179.     overview.writeLn("</HTML>");
  180.  
  181.     // create each gallery
  182.     int count = 0;
  183.     for (i=1; i<=galleries; i++)
  184.         {
  185.         char filename[256];
  186.         sprintf(filename, "%s%ld.html", baseName, i);
  187.         GUIC_FileC indexFile(currentDir, filename, GUIC_Write);
  188.  
  189.         // write head and title    
  190.         indexFile.writeLn("<HTML>");
  191.         indexFile.writeLn("<HEAD>");
  192.     
  193.         indexFile.write("<TITLE> "); indexFile.write(directoryName.getFilePart());    indexFile.writeLn(" </TITLE>");
  194.         indexFile.writeLn("</HEAD>");
  195.         indexFile.write("<BODY");
  196.         if (pattern)
  197.             {
  198.             indexFile.write(" Background=\"");
  199.             indexFile.write(pattern);
  200.             indexFile.write("\"");
  201.             }
  202.         indexFile.writeLn(">");
  203.         
  204.         indexFile.write("<CENTER><H2>"); 
  205.         indexFile.write(directoryName.getFilePart()); 
  206.         indexFile.write("</H2> (Part ");
  207.         indexFile.write(i);
  208.         indexFile.write(" of ");
  209.         indexFile.write(galleries);
  210.         indexFile.writeLn(")<BR>");
  211.  
  212.         indexFile.writeLn("<HR>");
  213.         indexFile.write("<TABLE Border=");
  214.         indexFile.write(tableBorderSize);
  215.         indexFile.writeLn(" CellSpacing=4 CellPadding=4>");
  216.         
  217.         int boundary = count + columnsInTable*linesInTable;
  218.         if (boundary>fileList.length()) boundary = fileList.length();
  219.         
  220.         for (int j=count; j<boundary; j++)
  221.             {
  222.             key = (GalleryEntryC *)fileList.objectAt(j+1);
  223.             GUIC_FileExamineC file(key->fileName);
  224.             String thumbName = "";
  225.             
  226.             // Create the thumbnail now            
  227.             try
  228.                 {
  229.                 thumbName = makeThumbnail(file, thumbnailWidth, thumbnailHeight);
  230.                 GUIC_FileExamineC thumb (thumbName);
  231.                 thumbName = thumb.getFilePart();
  232.                 }
  233.             catch (GUIC_SystemX &e) { GalleryEntryC *s = new GalleryEntryC(key->fileName,0,0,0,0); errorList.addTail(*s); }
  234.  
  235.             // Check the date
  236.             GUIC_DateC oldDate(lastDay,lastMonth,lastYear),*fileDate = file.getDate();;
  237.             if (fileDate->greater(oldDate) )
  238.                 {
  239.                 lastDay   = fileDate->getDay();
  240.                 lastMonth = fileDate->getMonth();
  241.                 lastYear  = fileDate->getYear();
  242.                 }
  243.  
  244.             // Check if there are enough entries per line in the table
  245.             if (count++ % columnsInTable == 0) indexFile.write("<TR> ");
  246.  
  247.             // write the picture data
  248.             indexFile.write("<TD> <CENTER>");
  249.             
  250.             if (picClick)
  251.                 {
  252.                 indexFile.write("<A HREF=\"");
  253.                 indexFile.write(file.getFilePart());
  254.                 indexFile.write("\"> <IMG SRC=\"");
  255.                 indexFile.write(thumbName);
  256.                 indexFile.write("\" ALT=Thumbnail BORDER=0> <BR>");
  257.                 }
  258.             else
  259.                 {
  260.                 indexFile.write("<IMG SRC=\"");
  261.                 indexFile.write(thumbName);
  262.                 indexFile.write("\" ALT=Thumbnail> <BR>");
  263.                 indexFile.write("<A HREF=\"");
  264.                 indexFile.write(file.getFilePart());
  265.                 indexFile.write("\">");
  266.                 }
  267.                 
  268.             indexFile.write(file.getFilePart());
  269.             indexFile.write(" </A>");
  270.             if (showSize)
  271.                 {
  272.                 indexFile.write("<BR> Size: ");
  273.                 indexFile.write(key->size);
  274.                 }
  275.             if (showDate)
  276.                 {
  277.                 indexFile.write("<BR> Date: ");
  278.                 indexFile.write(key->day);
  279.                 indexFile.write(".");
  280.                 indexFile.write(key->month);
  281.                 indexFile.write(".");
  282.                 indexFile.write(key->year);
  283.                 }
  284.             indexFile.writeLn("</TD>");
  285.             }
  286.             
  287.         indexFile.writeLn("</TABLE>");
  288.  
  289.         indexFile.writeLn("<HR>");
  290.         indexFile.writeLn(COPYRIGHT);
  291.         indexFile.writeLn("</BODY>");
  292.         indexFile.writeLn("</HTML>");
  293.         }
  294. }
  295. void         createHTML        (GUIC_ListC &fileList, STRPTR pattern, BOOL showDate, LONG tableBorderSize, STRPTR baseName)
  296. {
  297.     GalleryEntryC *key = (GalleryEntryC *)fileList.objectAt(1);
  298.     GUIC_FileExamineC firstFile(key->fileName);
  299.  
  300.     STRPTR currentDir = firstFile.getPathPart();
  301.     STRPTR st = (STRPTR) malloc (strlen(baseName) + 6);
  302.     if (! st) throw GUIC_MemoryX("Can't allocate memory for a string.");
  303.     sprintf(st, "%s.html", baseName);
  304.     GUIC_FileC indexFile(currentDir, st, GUIC_Write);
  305.     free (st);
  306.     
  307.     GUIC_FileExamineC directoryName(currentDir);
  308.  
  309.     String titleString = directoryName.getFilePart();
  310.     if (titleString == String("") ) titleString = directoryName.getName();
  311.  
  312.     cout << "Creating file '" << indexFile.getName() << "'" << endl;
  313.  
  314.     indexFile.writeLn("<HTML>");
  315.     indexFile.writeLn("<HEAD>");
  316.     indexFile.write("<TITLE> "); indexFile.write(titleString); indexFile.writeLn(" </TITLE>");
  317.     indexFile.writeLn("</HEAD>");
  318.     indexFile.write("<BODY");
  319.     if (pattern)
  320.         {
  321.         indexFile.write(" Background=\"");
  322.         indexFile.write(pattern);
  323.         indexFile.write("\"");
  324.         }
  325.     indexFile.writeLn(">");
  326.     indexFile.write("<CENTER><H1>"); indexFile.write(titleString); indexFile.writeLn("</H1>");
  327.     indexFile.writeLn("<HR><BR><BR>");
  328.     
  329.     // Create the table of galleries
  330.     
  331.     indexFile.write("<TABLE Border=");
  332.     indexFile.write(tableBorderSize);
  333.     indexFile.writeLn(" CellSpacing=4 CellPadding=4>");
  334.     indexFile.write("<TR> <TH> <CENTER> <H3> Gallery Name </H3> </TH> <TH> <CENTER> <H3> Entries </H3> </TH>");
  335.     if (showDate) indexFile.write("<TH> <CENTER> <H3> Last Update </H3> </TH>");
  336.     indexFile.writeLn("");
  337.     
  338.     fileList.sort();
  339.     
  340.     for (int i=1; i<=fileList.length(); i++)
  341.         {
  342.         key = (GalleryEntryC *)fileList.objectAt(i);
  343.         GUIC_FileExamineC file (key->fileName);
  344.  
  345.         indexFile.write("<TR> <TD> <CENTER> <A HREF=\"");
  346.         indexFile.write(file.getFilePart());
  347.         indexFile.write("/");
  348.         indexFile.write(baseName);
  349.         indexFile.write(".html\"");
  350.         indexFile.write("> ");
  351.         indexFile.write(file.getFilePart());
  352.         indexFile.write(" </A> </TD> <TD> <CENTER> ");
  353.         indexFile.write(key->size);
  354.         
  355.         if (showDate)
  356.             {            
  357.             indexFile.write(" </TD> <TD> <CENTER> ");
  358.  
  359.             if (key->day)
  360.                 {
  361.                 indexFile.write(key->day);
  362.                 indexFile.write(".");
  363.                 indexFile.write(key->month);
  364.                 indexFile.write(".");
  365.                 indexFile.write(key->year);
  366.                 }
  367.             else indexFile.write("(Directory)");
  368.             }
  369.             
  370.         indexFile.writeLn(" </TD>");
  371.         }
  372.  
  373.     indexFile.writeLn("</TABLE>");
  374.  
  375.     indexFile.write("<BR> <IMG SRC=internal-gopher-menu> <A HREF=\"../");
  376.     indexFile.write(baseName);
  377.     indexFile.writeLn(".html\" TARGET=_top> up </A> <BR>");
  378.  
  379.     indexFile.writeLn("<HR>");
  380.     indexFile.writeLn(COPYRIGHT);
  381.     indexFile.writeLn("</BODY>");
  382.     indexFile.writeLn("</HTML>");
  383. }
  384. int             scanDir                (STRPTR startDir, STRPTR pattern, LONG linesInTable, LONG columnsInTable, BOOL picClick, BOOL showSize, BOOL showDate, LONG menuFrameWidth, LONG thumbnailWidth, LONG thumbnailHeight, LONG tableBorderSize, STRPTR baseName)
  385. {
  386.     GUIC_ListC fileList,dirList;
  387.     GalleryEntryC *key = 0;
  388.     GUIC_FileExamineC *filex = 0;
  389.     int entries = 0;
  390.  
  391.     GUIC_FileExamineC *examine = new GUIC_FileExamineC(startDir);
  392.     if (!examine->isDirectory()) throw GUIC_SystemX("Error in function ScanDir (directory name expected).");
  393.     String dirName = examine->getName();
  394.     delete examine; examine=0;
  395.  
  396.     GUIC_DirectoryExamineC *direx= new GUIC_DirectoryExamineC(dirName);
  397.     BOOL hasSubDirs = direx->hasSubdirectory();
  398.     if (!hasSubDirs) direx->setFilter(FILEFILTER);
  399.  
  400.     try
  401.         {
  402.         while ( (filex = direx->examineNext()) )
  403.             {
  404.             String fileName  = filex->getName();
  405.             GUIC_DateC *date = filex->getDate();
  406.  
  407.             if (filex->isDirectory())
  408.                 {
  409.                 String newPattern = String("../") + String(pattern);
  410.                 int entriesInDir  = scanDir(fileName, pattern ? (STRPTR) newPattern : 0, linesInTable, columnsInTable, picClick, showSize, showDate, menuFrameWidth, thumbnailWidth, thumbnailHeight, tableBorderSize, baseName);
  411.                 if (entriesInDir)
  412.                     {
  413.                     key = new GalleryEntryC(fileName, entriesInDir, lastDay, lastMonth, lastYear);
  414.                     if (!key) throw GUIC_MemoryX("Can't allocate memory for key.");
  415.                     dirList.addTail(*key);
  416.                     entries+=entriesInDir;
  417.                     }
  418.                 lastDay=0; lastMonth=0; lastYear=0;
  419.                 }
  420.             else if (! hasSubDirs && (fileName.right(5) != String("_.jpg") ) )
  421.                 {
  422.                 key = new GalleryEntryC(fileName, filex->getSize(), date->getDay(), date->getMonth(), date->getYear() );
  423.                 if (!key) throw GUIC_MemoryX("Can't allocate memory for key.");
  424.                 fileList.addTail(*key);
  425.                 entries++;
  426.                 }
  427.             }
  428.         }
  429.     catch (GUIC_SystemX &e) { cerr << "Exception caught while processing directory '" << direx->getName() << "': " << e.getMessage() << endl; }
  430.     delete direx;direx=0; /* Damit der lock auf das Verzeichnis freigegeben wird ! */
  431.  
  432.     if (dirList.length())     createHTML        (dirList,pattern, showDate, tableBorderSize, baseName);
  433.     if (fileList.length())    createGallery        (fileList,pattern, linesInTable, columnsInTable, picClick, showSize, showDate, menuFrameWidth, thumbnailWidth, thumbnailHeight, tableBorderSize, baseName);
  434.  
  435.     while (fileList.length()) delete (GalleryEntryC *)fileList.remove(1);
  436.     while ( dirList.length()) delete (GalleryEntryC *) dirList.remove(1);
  437.  
  438.     return entries;
  439. }
  440.  
  441.  
  442. class GalleryWindowC : public GUIC_WindowC
  443.     {
  444.     public:
  445.         GalleryWindowC        (GUIC_ApplicationC *app, GUIC_ScreenC *screen);
  446.         ~GalleryWindowC     (void);
  447.         BOOL action            (GUIC_EventC &);
  448.     private:
  449.         GUIC_ButtonC                *start, *quit;
  450.         GUIC_RegisterC            *reg;
  451.         GUIC_FileStringC            *pattern;
  452.         GUIC_PathStringC        *directory;
  453.         GUIC_SlidingIntegerC     *lines, *columns, *width, *height, *tableBorder;
  454.         GUIC_CheckboxC        *click, *size, *date;
  455.         GUIC_IntegerC                *frame;
  456.         GUIC_LabelC                *dirLabel, *pattLabel, *linesLabel, *columnsLabel, *clickLabel, *sizeLabel, *dateLabel, *frameLabel, *widthLabel, *heightLabel, *tableBorderLabel, *baseNameLabel;
  457.         GUIC_StringC                *baseName;
  458.     };
  459.     
  460. GalleryWindowC::GalleryWindowC    (GUIC_ApplicationC *app, GUIC_ScreenC *screen) : GUIC_WindowC (-1,-1,48,24)
  461. {
  462.     // Register erstellen
  463.     reg = new GUIC_RegisterC            (1,1,46,19,4);
  464.     
  465.     reg -> setName(1, "Global");
  466.     reg -> setName(2, "Tables");
  467.     reg -> setName(3, "HTML");
  468.     reg -> setName(4, "Thumbnail");
  469.  
  470.     reg -> setShortcut ('r');
  471.         
  472.     app -> addPrefs("Register", reg);
  473.  
  474.     add ( reg );
  475.  
  476.  
  477.     // Erstes Register
  478.     dirLabel                = new GUIC_LabelC            ( 0, 4,10,2,"_Directory:");
  479.     pattLabel            = new GUIC_LabelC            ( 0, 6,10,2,"_Pattern:");
  480.     baseNameLabel    = new GUIC_LabelC            ( 0, 9,30,2,"_Base name for HTML files:");
  481.     directory                = new GUIC_PathStringC    (11, 4,33,2,"");
  482.     pattern                = new GUIC_FileStringC        (11, 6,33,2,"");
  483.     baseName            = new GUIC_StringC            (31, 9,13,2,"index");
  484.  
  485.     directory        ->setHelp("Directory for the first index file.");
  486.     pattern        ->setHelp("Background pattern in HTML pages.");
  487.     baseName    ->setHelp("Enter base file name without a suffix."),
  488.  
  489.     directory        ->setShortcut('d');
  490.     pattern        ->setShortcut('p');
  491.     baseName    ->setShortcut('b');
  492.  
  493.     app->addPrefs("StartDirectory"        , directory);
  494.     app->addPrefs("BackgroundPattern" , pattern);
  495.     app->addPrefs("BaseName"                , baseName);
  496.     
  497.     reg->add(1, dirLabel);
  498.     reg->add(1, pattLabel);
  499.     reg->add(1, directory);
  500.     reg->add(1, pattern);
  501.     reg->add(1, baseNameLabel);
  502.     reg->add(1, baseName);
  503.  
  504.  
  505.     // Zweites Register
  506.     linesLabel                = new GUIC_LabelC                ( 0, 0,10,2,"_Lines:");
  507.     columnsLabel            = new GUIC_LabelC                ( 0, 2,10,2,"_Columns:");
  508.     sizeLabel                = new GUIC_LabelC                ( 0, 5,30,2,"Sh_ow size of picture:");
  509.     dateLabel                = new GUIC_LabelC                ( 0, 7,31,2,"Sho_w date of picture:");
  510.     clickLabel                = new GUIC_LabelC                ( 0,10,31,2,"_Use thumbnail picture as link:");
  511.     tableBorderLabel    = new GUIC_LabelC                ( 0,13,31,2,"Size of table's _border:");
  512.     lines                        = new GUIC_SlidingIntegerC    (11, 0,33,2,MINLINES,MAXLINES,DEFAULTLINES);
  513.     columns                    = new GUIC_SlidingIntegerC    (11, 2,33,2,MINCOLUMNS,MAXCOLUMNS,DEFAULTCOLUMNS);    
  514.     size                        = new GUIC_CheckboxC            (41, 5, 3,2,TRUE);
  515.     date                        = new GUIC_CheckboxC            (41, 7, 3,2,TRUE);
  516.     click                        = new GUIC_CheckboxC            (41,10, 3,2,FALSE);
  517.     tableBorder                = new GUIC_SlidingIntegerC    (30,13,14,2,MINTABLEBORDERSIZE, MAXTABLEBORDERSIZE, DEFTABLEBORDERSIZE);
  518.     
  519.     lines            ->setHelp("The number of lines per HTML table.");
  520.     columns        ->setHelp("The number of columns per HTML table.");
  521.     size            ->setHelp("Show picture's size in gallery?");
  522.     date            ->setHelp("Show picture's date in gallery?");
  523.     click            ->setHelp("Click on thumbnails to view picture?");
  524.     tableBorder    ->setHelp("Size of the border around the tables.");
  525.     
  526.     lines            ->setShortcut('l');
  527.     columns        ->setShortcut('c');
  528.     size            ->setShortcut('o');
  529.     date            ->setShortcut('w');
  530.     click            ->setShortcut('u');
  531.     tableBorder    ->setShortcut('b');
  532.  
  533.     reg->add (2, linesLabel );
  534.     reg->add (2, lines );
  535.     reg->add (2, columnsLabel );
  536.     reg->add (2, columns );
  537.     reg->add (2, sizeLabel );
  538.     reg->add (2, size );
  539.     reg->add (2, dateLabel );
  540.     reg->add (2, date );
  541.     reg->add (2, clickLabel );
  542.     reg->add (2, click );
  543.     reg->add (2, tableBorderLabel);
  544.     reg->add (2, tableBorder);
  545.     
  546.  
  547.     // Drittes Register
  548.     frameLabel        = new GUIC_LabelC    ( 0, 7,35,2,"Width of menu _frame (left frame):");
  549.     frame                = new GUIC_IntegerC    (36, 7,8,2,MENUFRAMEWIDTH);
  550.  
  551.     frame        ->setJustification(GUIC_Right);
  552.  
  553.     frame        ->setHelp("No. of pixels for the left hand frame.");
  554.  
  555.     frame        ->setShortcut('f');
  556.  
  557.     reg->add (3, frameLabel );
  558.     reg->add (3, frame );
  559.     
  560.  
  561.     // Viertes Register
  562.     widthLabel        = new GUIC_LabelC                ( 0, 5,26, 2,"Max. _width of thumbnails:");
  563.     heightLabel        = new GUIC_LabelC                ( 0, 7,26, 2,"Max. _height of thumbnails:");
  564.     width                = new GUIC_SlidingIntegerC    (27, 5,17, 2,MINTHUMBNAILWIDTH,MAXTHUMBNAILWIDTH,DEFTHUMBNAILWIDTH);
  565.     height                = new GUIC_SlidingIntegerC    (27, 7,17, 2,MINTHUMBNAILHEIGHT,MAXTHUMBNAILHEIGHT,DEFTHUMBNAILHEIGHT);
  566.  
  567.     width        ->setHelp("Maximum width for each thumbnail.");
  568.     height        ->setHelp("Maximum height for each thumbnail.");
  569.     
  570.     width        ->setShortcut('w');
  571.     height        ->setShortcut('h');
  572.     
  573.     reg->add (4, widthLabel );
  574.     reg->add (4, width );
  575.     reg->add (4, heightLabel );
  576.     reg->add (4, height );
  577.  
  578.  
  579.     // Start und Quit Buttons
  580.     start                = new GUIC_ButtonC                ( 1,21,15,2,"_Start");
  581.     quit                    = new GUIC_ButtonC                (32,21,15,2,"_Quit");
  582.     
  583.     start        ->setHelp("Start the creation of the gallery.");
  584.     quit            ->setHelp("Quit the program.");
  585.     
  586.     start        ->setShortcut('s');
  587.     quit            ->setShortcut('q');
  588.  
  589.     add ( start );
  590.     add ( quit );
  591.  
  592.  
  593.     // Prefs für das Fenster 
  594.     app->addPrefs("GalleryWindow"            , this);
  595.     app->addPrefs("NumberOfLines"            , lines);
  596.     app->addPrefs("NumberOfColumns"        , columns);
  597.     app->addPrefs("PictureAsLink"                , click);
  598.     app->addPrefs("TableFrameSize"            , tableBorder);
  599.     app->addPrefs("ShowSize"                    , size);
  600.     app->addPrefs("ShowDate"                    , date);
  601.     app->addPrefs("MenuFrameWidth"        , frame);
  602.     app->addPrefs("ThumbnailWidth"            , width);
  603.     app->addPrefs("ThumbnailHeight"            , height);
  604.         
  605.  
  606.     setTitle("Gallery - (c) by Markus Hillenbrand");
  607.     setHelp(TRUE);
  608.     
  609.     activate();
  610. }
  611. GalleryWindowC::~GalleryWindowC    (void)
  612. {
  613.     delete reg;
  614.     delete dirLabel;
  615.     delete directory;
  616.     delete pattLabel;
  617.     delete pattern;
  618.     delete linesLabel;
  619.     delete lines;
  620.     delete columnsLabel;
  621.     delete columns;
  622.     delete clickLabel;
  623.     delete click;
  624.     delete sizeLabel;
  625.     delete size;
  626.     delete dateLabel;
  627.     delete date;
  628.     delete frameLabel;
  629.     delete frame;
  630.     delete widthLabel;
  631.     delete width;
  632.     delete heightLabel;
  633.     delete height;
  634.     delete tableBorderLabel;
  635.     delete tableBorder;
  636.     delete start;
  637.     delete quit;
  638. }
  639.  
  640. BOOL GalleryWindowC::action(GUIC_EventC &e)
  641. {
  642.     switch (e.id)
  643.         {
  644.         case GUIC_GadgetEvent:
  645.             if (e.gadget == (GUIC_GadgetC *)start)
  646.                 {
  647.                 if (! strcmp(directory->get(), "") )
  648.                     {
  649.                     GUIC_ErrorC e("You must at least enter a directory name!");
  650.                     e.request(this);
  651.                     }
  652.                 else 
  653.                     {
  654.                     GUIC_SystemC::openConsole();
  655.                     sleep();
  656.                     activate();
  657.                     try 
  658.                         {
  659.                         scanDir (directory->get(), pattern->get(), lines->get(), columns->get(), click->get(), size->get(), date->get(), frame->get(), width->get(), height->get(), tableBorder->get() , baseName->get() );
  660.                         }
  661.                     catch (GUIC_Exception &x) { GUIC_ErrorC e("Exception caught:", x.getMessage() ); e.request(this); }
  662.                     waken();
  663.                     }
  664.                 }
  665.             else if (e.gadget == (GUIC_GadgetC *)quit) 
  666.                 {
  667.                 dispose();
  668.                 }
  669.             return TRUE;
  670.             break;
  671.         case GUIC_OpenWindow:
  672.             return TRUE;
  673.             break;
  674.         case GUIC_CloseWindow: 
  675.             return FALSE;
  676.             break;
  677.         default:
  678.             cerr << "Got an event: " << e.id << endl;
  679.         }
  680.     
  681.     return FALSE;
  682. }
  683.  
  684.  
  685.  
  686. void         shell                    (void)
  687. {
  688.     LONG result[] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
  689.     STRPTR templ = "STARTDIR/A,LINES/N,COLUMNS/N,BGPATTERN,PICCLICK/S,NOSIZE/S,NODATE/S,MENUFRAMEWIDTH/N,MAXTHUMBNAILWIDTH/N,MAXTHUMBNAILHEIGHT/N,TABLEBORDERSIZE/N,BASENAME";
  690.     GUIC_ProgramArgsC args;
  691.     if (! args.fit(templ, result))
  692.         {
  693.         cerr << "Usage: " << templ << endl;
  694.         GUIC_SystemC::exit(GUIC_ExitError);
  695.         }
  696.     
  697.     LONG lines = result[1] ? *(LONG *)result[1] : DEFAULTLINES;
  698.     if (lines < MINLINES)         lines=MINLINES;
  699.     if (lines > MAXLINES)    lines=MAXLINES;
  700.     
  701.     LONG columns = result[2] ? *(LONG *)result[2] : DEFAULTCOLUMNS;
  702.     if (columns < MINCOLUMNS)     columns=MINCOLUMNS;
  703.     if (columns > MAXCOLUMNS)    columns=MAXCOLUMNS;
  704.     
  705.     BOOL picclick        = result[4];
  706.     BOOL showSize    = ! result[5];
  707.     BOOL showDate    = ! result[6];
  708.     
  709.     LONG menuFrameWidth = result[7] ? *(LONG *)result[7] : MENUFRAMEWIDTH;
  710.     
  711.     LONG thumbnailWidth = result[8] ? *(LONG *)result[8] : DEFTHUMBNAILWIDTH;
  712.     if (thumbnailWidth < MINTHUMBNAILWIDTH)     thumbnailWidth=MINTHUMBNAILWIDTH;
  713.     if (thumbnailWidth > MAXTHUMBNAILWIDTH)    thumbnailWidth=MAXTHUMBNAILWIDTH;
  714.  
  715.     LONG thumbnailHeight = result[9] ? *(LONG *)result[9] : DEFTHUMBNAILHEIGHT;
  716.     if (thumbnailHeight < MINTHUMBNAILHEIGHT)     thumbnailHeight=MINTHUMBNAILHEIGHT;
  717.     if (thumbnailHeight > MAXTHUMBNAILHEIGHT)    thumbnailHeight=MAXTHUMBNAILHEIGHT;
  718.     
  719.     LONG tableBorderSize = result[10] ? *(LONG *)result[10] : DEFTABLEBORDERSIZE;
  720.     if (tableBorderSize < MINTABLEBORDERSIZE)     tableBorderSize=MINTABLEBORDERSIZE;
  721.     if (tableBorderSize > MAXTABLEBORDERSIZE)    tableBorderSize=MAXTABLEBORDERSIZE;
  722.     
  723.     STRPTR baseName = result[11] ? (STRPTR) result[11] : "index";
  724.     
  725.     scanDir((STRPTR)result[0], (STRPTR)result[3], lines, columns, picclick, showSize, showDate, menuFrameWidth, thumbnailWidth, thumbnailHeight, tableBorderSize, baseName); 
  726.  
  727.     if (errorList.length())
  728.         {
  729.         cerr << "The following files could not be converted to a thumbnail:" << endl;
  730.         while (errorList.length())
  731.             {
  732.             GalleryEntryC *s = (GalleryEntryC *)errorList.remove(1);
  733.             cerr << "- " << s->fileName << endl;
  734.             delete s;
  735.             }
  736.         cerr << "Please check them and run 'Gallery' again." << endl;
  737.         }
  738. }
  739. void        workbench            (void)
  740. {
  741.     GUIC_ApplicationC    app("Gallery");
  742.  
  743.     app.setAuthor        (__AUTHOR__);
  744.     app.setVersion    (__VERSION__);
  745.     app.setRevision    (__REVISION__);
  746.     app.setDate        (__DATE__);
  747.     app.setTime        (__TIME__);
  748.     app.setInitializer    (TRUE);
  749.  
  750.     GUIC_ScreenC            screen;
  751.     GalleryWindowC     window(&app, &screen);
  752.     
  753.     screen.add(window);
  754.     app.add(screen);
  755.  
  756.     app.start();
  757.  
  758.     BOOL running = TRUE;
  759.     GUIC_EventC *event = 0;
  760.  
  761.     int count = 0;
  762.     
  763.     while (running && (event = app.wait()) )
  764.         {
  765.         // As we have only one window, it is not neccessary to check for the window id
  766.         if (event->id == GUIC_CloseWindow) 
  767.             {
  768.             GUIC_MessageC    message    ("Do you really want to quit ?", "Yes|No");
  769.             if (1 == message.request(*event->window)) running = FALSE;
  770.             }
  771.         }
  772.  
  773.     app.stop();
  774. }
  775.  
  776. void         main                    (int argc, char **argv)
  777. {
  778.     GUIC_SystemC::checkStackSize(50000);
  779.     if (GUIC_SystemC::runFromShell() ) shell(); else workbench();
  780. }
  781.  
  782.