[KimDaBa] Patch to add symlink, hardlink, and no thumbnails options to HTML export

Robert L Krawitz rlk at alum.mit.edu
Thu Sep 23 20:52:57 CEST 2004


The following patch offers options to export by hard link and symlink
as a way to save disk space in situations where it is not really
necessary to copy files.  In addition, there's an option offered to
not generate thumbnails.  Finally, since it can't really be separated
out, the progress dialog is updated more accurately.

diff -ru kimdaba-2004-09-11-noi18n/kimdaba/export.cpp kimdaba-2004-09-11-noi18.new/kimdaba/export.cpp
--- kimdaba-2004-09-11-noi18n/kimdaba/export.cpp	2004-08-23 11:52:27.000000000 -0400
+++ kimdaba-2004-09-11-noi18.new/kimdaba/export.cpp	2004-09-11 08:48:26.000000000 -0400
@@ -54,7 +54,7 @@
 
     bool ok;
     Export* exp = new Export( list, zipFile, config._compress->isChecked(), maxSize, config.imageFileLocation(),
-                              QString::fromLatin1( "" ), ok );
+                              QString::fromLatin1( "" ), ok, config._generateThumbnails->isChecked());
     delete exp; // It will not return before done - we still need a class to connect slots etc.
 
     if ( ok )
@@ -75,12 +75,18 @@
     _include = new QRadioButton( i18n("Include in .kim file"), grp );
     _manually = new QRadioButton( i18n("Manual copy next to .kim file"), grp );
     _auto = new QRadioButton( i18n("Automatically copy next to .kim file"), grp );
+    _link = new QRadioButton( i18n("Hard link next to .kim file"), grp );
     _manually->setChecked( true );
 
     // Compress
     _compress = new QCheckBox( i18n("Compress Export File"), top );
     lay1->addWidget( _compress );
 
+    // Generate thumbnails
+    _generateThumbnails = new QCheckBox( i18n("Generate Thumbnails"), top );
+    _generateThumbnails->setChecked(true);
+    lay1->addWidget( _generateThumbnails );
+
     // Enforece max size
     QHBoxLayout* hlay = new QHBoxLayout( lay1, 6 );
     _enforeMaxSize = new QCheckBox( i18n( "Limit maximum image dimension to: " ), top, "_enforeMaxSize" );
@@ -99,6 +105,9 @@
                         "if your images are stored in tiff.</p></qt>" );
     QWhatsThis::add( _compress, txt );
 
+    txt = i18n( "<qt><p>Generate thumbnail images</p></qt>" );
+    QWhatsThis::add( _generateThumbnails, txt );
+
     txt = i18n( "<qt><p>With this option you may limit the maximum dimensions (width and height) of your images. "
                 "Doing so will make the resulting export file smaller, but will of course also make the quality "
                 "worse if someone wants to see the exported images with larger dimensions.</p></qt>" );
@@ -118,6 +127,7 @@
     QWhatsThis::add( grp, txt );
     QWhatsThis::add( _include, txt );
     QWhatsThis::add( _manually, txt );
+    QWhatsThis::add( _link, txt );
     QWhatsThis::add( _auto, txt );
     setHelp( QString::fromLatin1( "chp-exportDialog" ) );
 }
@@ -134,7 +144,7 @@
 
 
 Export::Export( const ImageInfoList& list, const QString& zipFile, bool compress, int maxSize, ImageFileLocation location,
-                const QString& baseUrl, bool& ok )
+                const QString& baseUrl, bool& ok, bool doGenerateThumbnails )
     : _ok( ok ), _maxSize( maxSize ), _location( location )
 {
     ok = true;
@@ -148,9 +158,11 @@
     }
 
     // Create progress dialog
-    int total = list.count(); // number of images *  create the thumbnails
-    if ( location != ManualCopy )
-        total *= 2;  // number of images *  copy images
+    int total = 1;
+    if (location != ManualCopy)
+      total += list.count();
+    if (doGenerateThumbnails)
+      total += list.count();
 
     _steps = 0;
     _progressDialog = new QProgressDialog( QString::null, i18n("Cancel"), total, 0, "progress dialog", true );
@@ -165,19 +177,22 @@
         copyImages( list );
     }
 
-    if ( _ok ) {
+    if ( _ok && doGenerateThumbnails ) {
         _copyingFiles = false;
         generateThumbnails( list );
     }
 
     if ( _ok ) {
         // Create the index.xml file
+        _progressDialog->setLabelText(i18n("Creating index file"));
         QCString indexml = createIndexXML( list, baseUrl );
         time_t t;
         time(&t);
         _zip->writeFile( QString::fromLatin1( "index.xml" ), QString::null, QString::null, indexml.size()-1,
                          0444, t, t, t, indexml.data() );
 
+	_steps++;
+	_progressDialog->setProgress( _steps );
         _zip->close();
     }
 }
@@ -245,6 +260,8 @@
                 _zip->addLocalFile( file, QString::fromLatin1( "Images/" ) + zippedName );
             else if ( _location == AutoCopy )
                 Util::copy( file, _destdir + QString::fromLatin1( "/" ) + zippedName );
+            else if ( _location == Link )
+                Util::make_link( file, _destdir + QString::fromLatin1( "/" ) + zippedName );
             _steps++;
             _progressDialog->setProgress( _steps );
         }
diff -ru kimdaba-2004-09-11-noi18n/kimdaba/export.h kimdaba-2004-09-11-noi18.new/kimdaba/export.h
--- kimdaba-2004-09-11-noi18n/kimdaba/export.h	2004-08-23 11:52:27.000000000 -0400
+++ kimdaba-2004-09-11-noi18.new/kimdaba/export.h	2004-09-11 09:09:40.000000000 -0400
@@ -29,7 +29,7 @@
 class KZip;
 class QProgressDialog;
 
-enum ImageFileLocation { Inline, ManualCopy, AutoCopy };
+enum ImageFileLocation { Inline, ManualCopy, AutoCopy, Link };
 
 class Export :public ImageClient {
 
@@ -37,7 +37,7 @@
     static void imageExport( const ImageInfoList& list);
     virtual void pixmapLoaded( const QString& fileName, const QSize& size, const QSize& fullSize, int angle, const QImage& );
     Export( const ImageInfoList& list, const QString& zipFile, bool compress, int maxSize,
-            ImageFileLocation, const QString& baseUrl, bool& ok );
+            ImageFileLocation, const QString& baseUrl, bool& ok, bool generateThumbnails );
     static void showUsageDialog();
 
 protected:
@@ -66,6 +66,7 @@
 public:
     ExportConfig();
     QCheckBox* _compress;
+    QCheckBox* _generateThumbnails;
     QCheckBox* _enforeMaxSize;
     QSpinBox* _maxSize;
 
@@ -74,6 +75,7 @@
 private:
     QRadioButton* _include;
     QRadioButton* _manually;
+    QRadioButton* _link;
     QRadioButton* _auto;
 };
 
diff -ru kimdaba-2004-09-11-noi18n/kimdaba/htmlexportdialog.cpp kimdaba-2004-09-11-noi18.new/kimdaba/htmlexportdialog.cpp
--- kimdaba-2004-09-11-noi18n/kimdaba/htmlexportdialog.cpp	2004-08-23 11:52:27.000000000 -0400
+++ kimdaba-2004-09-11-noi18.new/kimdaba/htmlexportdialog.cpp	2004-09-11 08:44:44.000000000 -0400
@@ -276,7 +276,7 @@
         if ( destURL.isEmpty() )
             destURL = _baseURL->text();
 
-        Export* exp = new Export( _list, kimFileName( false ), false, -1, ManualCopy, destURL, ok );
+        Export* exp = new Export( _list, kimFileName( false ), false, -1, ManualCopy, destURL, ok, true );
         delete exp; // It will not return before done - we still need a class to connect slots etc.
         if ( !ok )
             return false;
diff -ru kimdaba-2004-09-11-noi18n/kimdaba/util.cpp kimdaba-2004-09-11-noi18.new/kimdaba/util.cpp
--- kimdaba-2004-09-11-noi18n/kimdaba/util.cpp	2004-09-04 15:05:47.000000000 -0400
+++ kimdaba-2004-09-11-noi18.new/kimdaba/util.cpp	2004-09-11 08:46:40.000000000 -0400
@@ -319,6 +319,22 @@
     return true;
 }
 
+bool Util::make_link( const QString& from, const QString& to )
+{
+  if (link(from.ascii(), to.ascii()) != 0)
+    return false;
+  else
+    return true;
+}
+
+bool Util::make_symlink( const QString& from, const QString& to )
+{
+  if (symlink(from.ascii(), to.ascii()) != 0)
+    return false;
+  else
+    return true;
+}
+
 QString Util::readInstalledFile( const QString& fileName )
 {
     QString inFileName = locate( "data", QString::fromLatin1( "kimdaba/%1" ).arg( fileName ) );
diff -ru kimdaba-2004-09-11-noi18n/kimdaba/util.h kimdaba-2004-09-11-noi18.new/kimdaba/util.h
--- kimdaba-2004-09-11-noi18n/kimdaba/util.h	2004-09-04 15:05:47.000000000 -0400
+++ kimdaba-2004-09-11-noi18.new/kimdaba/util.h	2004-09-11 08:45:32.000000000 -0400
@@ -35,6 +35,8 @@
     static void checkForBackupFile( const QString& fileName );
     static bool ctrlKeyDown();
     static bool copy( const QString& from, const QString& to );
+    static bool make_link( const QString& from, const QString& to );
+    static bool make_symlink( const QString& from, const QString& to );
     static bool runningDemo();
     static void deleteDemo();
     static QString setupDemo();

-- 
Robert Krawitz                                     <rlk at alum.mit.edu>

Tall Clubs International  --  http://www.tall.org/ or 1-888-IM-TALL-2
Member of the League for Programming Freedom -- mail lpf at uunet.uu.net
Project lead for Gimp Print   --    http://gimp-print.sourceforge.net

"Linux doesn't dictate how I work, I dictate how Linux works."
--Eric Crampton



More information about the KimDaBa mailing list