[Kde-imaging] extragear/libs/kipi-plugins/sendimages

Gilles Caulier caulier.gilles at free.fr
Fri Nov 24 09:20:31 CET 2006


SVN commit 607337 by cgilles:

kipi-plugins from trunk : SendImages : patch from Michael Höchstetter :

- Support Exiv2Iface class instead JpegRestorer.
- Fix small bug concerning filenames and thunderbird, mozilla .... 
Now it is possible, that the path and filename contains  "spaces", however it 
still is not possible to contain signs like kommas. Still todo.

CCMAIL: kde-imaging at kde.org, michael.hoechstetter at gmx.de

 M  +8 -5      Makefile.am  
 D             exifrestorer.cpp  
 D             exifrestorer.h  
 D             jpegsection.h  
 M  +60 -93    sendimages.cpp  
 M  +1 -1      sendimages.h  


--- trunk/extragear/libs/kipi-plugins/sendimages/Makefile.am #607336:607337
@@ -1,20 +1,23 @@
-INCLUDES = $(KIPI_PLUGINS_COMMON_INCLUDE) $(LIBKIPI_CFLAGS) $(all_includes)
+INCLUDES = -I$(top_srcdir)/kipi-plugins/common/exiv2iface \
+           $(KIPI_PLUGINS_COMMON_INCLUDE) $(LIBKIPI_CFLAGS) $(all_includes)
 
 METASOURCES = AUTO
 
 # Install this plugin in the KDE modules directory
 kde_module_LTLIBRARIES = kipiplugin_sendimages.la
 kipiplugin_sendimages_la_DEPENDENCIES = $(LIBKIPI_LIBS_DEP)
+
 # Srcs for the plugin
 kipiplugin_sendimages_la_SOURCES = plugin_sendimages.cpp sendimagesdialog.cpp \
-                                   listimageserrordialog.cpp sendimages.cpp \
-                                   exifrestorer.cpp 
+                                   listimageserrordialog.cpp sendimages.cpp 
 
 # Libs needed by the plugin
-kipiplugin_sendimages_la_LIBADD = $(LIBKIPI_LIBS) $(LIB_KIO) $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT)
+kipiplugin_sendimages_la_LIBADD = $(top_builddir)/kipi-plugins/common/exiv2iface/libexiv2iface.la \
+                                  $(LIBKIPI_LIBS) $(LIB_KIO) $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT)
 
 # LD flags for the plugin
-kipiplugin_sendimages_la_LDFLAGS = $(KIPI_PLUGINS_COMMON_LDFLAGS) -module $(KDE_PLUGIN) $(all_libraries) -lkipiplugins
+kipiplugin_sendimages_la_LDFLAGS = $(KIPI_PLUGINS_COMMON_LDFLAGS) \
+                                   -module $(KDE_PLUGIN) $(all_libraries) -lkipiplugins
 
 # Install the desktop file needed to detect the plugin
 kde_services_DATA = kipiplugin_sendimages.desktop
--- trunk/extragear/libs/kipi-plugins/sendimages/sendimages.cpp #607336:607337
@@ -1,8 +1,7 @@
 /* ============================================================
- * Author: Gilles Caulier <caulier dot gilles at free.fr>
- *         from digiKam project.
- * Date  : 2004-02-25
- * Description : a kipi plugin for e-mailing images
+ * Authors: Gilles Caulier <caulier dot gilles at free.fr>
+ * Date   : 2004-02-25
+ * Description : a kipi plugin to e-mailing images
  * 
  * Copyright 2004-2005 by Gilles Caulier
  * Copyright 2006 by Tom Albers
@@ -22,7 +21,6 @@
 
 // Include files for Qt
 
-
 #include <qfileinfo.h>
 #include <qdir.h>
 #include <qimage.h>
@@ -30,6 +28,7 @@
 #include <qcombobox.h>
 #include <qcheckbox.h>
 #include <qtimer.h>
+#include <qurl.h>
 
 // Include files for KDE
 
@@ -53,11 +52,13 @@
 
 // Local include files
 
-#include "sendimages.h"
 #include "sendimagesdialog.h"
 #include "listimageserrordialog.h"
-#include "exifrestorer.h"
+#include "exiv2iface.h"
 #include "actions.h"
+#include "pluginsversion.h"
+#include "sendimages.h"
+#include "sendimages.moc"
 
 namespace KIPISendimagesPlugin
 {
@@ -77,18 +78,12 @@
             this, SLOT(slotMozillaTimeout()));
 }
 
-
-//////////////////////////////////// DESTRUCTOR /////////////////////////////////////////////
-
 SendImages::~SendImages()
 {
     delete m_sendImagesDialog;
     wait();
 }
 
-
-/////////////////////////////////////////////////////////////////////////////////////////////
-
 void SendImages::showDialog()
 {
     m_sendImagesDialog = new KIPISendimagesPlugin::SendImagesDialog(kapp->activeWindow(),
@@ -100,9 +95,7 @@
 }
 
 
-/////////////////////////////////////////////////////////////////////////////////////////////
-// Execute the no threadable operations before the real thread.
-
+/** Execute the no threadable operations before the real thread.*/
 void SendImages::prepare(void)
 {
     m_filesSendList.clear();
@@ -113,13 +106,13 @@
     m_imageFormat = m_sendImagesDialog->m_imagesFormat->currentText();
     m_sizeFactor = getSize( m_sendImagesDialog->m_imagesResize->currentItem() );
     m_imageCompression = m_sendImagesDialog->m_imageCompression->value();
-    m_attachmentlimit = m_sendImagesDialog->m_attachmentlimit->value()*770000-2000; ///Base64-encoding needs a lot of space
+    
+    // Base64-encoding needs a lot of space.
+    m_attachmentlimit = m_sendImagesDialog->m_attachmentlimit->value()*770000-2000; 
 }
 
 
-/////////////////////////////////////////////////////////////////////////////////////////////
-// List of threaded operations.
-
+/** List of threaded operations.*/
 void SendImages::run()
 {
     KIPISendimagesPlugin::EventData *d;
@@ -132,7 +125,7 @@
     QApplication::postEvent(m_parent, new QCustomEvent(QEvent::User, d));
 
     for( KURL::List::Iterator it = m_images.begin() ; it != m_images.end() ; ++it )
-        {
+    {
         QString imageName = (*it).path();
         QString ItemName = imageName.section( '/', -1 );
 
@@ -147,7 +140,7 @@
         // Prepare resized target images to send.
 
         if ( m_changeProp == true )
-           {
+        {
            // Prepare resizing images.
 
            QString imageFileName = ItemName;
@@ -162,10 +155,14 @@
 
            kdDebug (51000) << "Resizing ' " << imageName.ascii() << "-> '"
                            << m_tmp.ascii() << imageNameFormat.ascii()
-                           << "' (" << m_imageFormat.ascii() << ")" << endl;
+                           << "' (" << m_imageFormat.ascii() << "; "<<m_sizeFactor <<")" << endl;
+	   
+    	   // Return value for resizeImageProcess-function, in order to avoid reopening 
+           // the image for exiv-writing.
+	       QSize newsize;
 
            if ( resizeImageProcess( imageName, m_tmp, m_imageFormat, imageNameFormat,
-                                    m_sizeFactor, m_imageCompression) == false )
+                                    m_sizeFactor, m_imageCompression, newsize) == false )
                {
                // Resized images failed...
 
@@ -178,30 +175,28 @@
                QApplication::postEvent(m_parent, new QCustomEvent(QEvent::User, d));
 
                m_imagesResizedWithError.append(*it);
-               }
-           else          // Resized images OK...
-               {
+          } 
+	  else          // Resized images OK...
+          {
                // Only try to write Exif if both src and destination are JPEG files.
 
-               if (QString(QImageIO::imageFormat(imageName)).upper() == "JPEG" &&
-                   m_imageFormat.upper() == "JPEG")
-                  {
-                  ExifRestorer exifHolder;
-                  exifHolder.readFile(imageName, ExifRestorer::ExifOnly);
+               if (QString(QImageIO::imageFormat(imageName)).upper() == "JPEG" && m_imageFormat.upper() == "JPEG")
+               {
+                    QString targetFile = m_tmp + imageNameFormat;
+                            KIPIPlugins::Exiv2Iface exiv2Iface;
+                    if (exiv2Iface.load(imageName))
+                    {
+                        exiv2Iface.setImageProgramId(QString("Kipi SendImages"), QString(kipiplugins_version));
+                        exiv2Iface.setImageDimensions(newsize);
+                        exiv2Iface.save(targetFile);
+                    }
 
-                  QString targetFile = m_tmp + imageNameFormat;
-
-                  if (exifHolder.hasExif())
-                     {
-                     ExifRestorer restorer;
-                     restorer.readFile(targetFile, ExifRestorer::EntireImage);
-                     restorer.insertExifData(exifHolder.exifData());
-                     restorer.writeFile(targetFile);
-                     }
-                  else
-                     kdWarning( 51000 ) << ("createThumb::No Exif Data Found") << endl;
-                  }
-
+		       } 
+               else 
+               {
+                    kdWarning( 51000 ) << ("createThumb::No Exif Data Found") << endl;
+		       }
+	
                d = new KIPISendimagesPlugin::EventData;
                d->action   = KIPISendimagesPlugin::ResizeImages;
                d->fileName = (*it).fileName();
@@ -239,9 +234,7 @@
 }
 
 
-/////////////////////////////////////////////////////////////////////////////////////////////
-// Create a text file with the images comments.
-
+/** Create a text file with the images comments.*/
 void SendImages::makeCommentsFile(void)
 {
     if ( m_sendImagesDialog->m_addComments->isChecked() == true )
@@ -296,9 +289,6 @@
     }
 }
 
-
-/////////////////////////////////////////////////////////////////////////////////////////////
-
 bool SendImages::showErrors()
 {
     if ( m_imagesResizedWithError.isEmpty() == false )
@@ -339,10 +329,8 @@
 }
 
 
-/////////////////////////////////////////////////////////////////////////////////////////////
-// Returns a list of Filenames, whose sum filesize is smaller than the quota
-// by Michael Höchstetter
-//
+/** Returns a list of Filenames, whose sum filesize is smaller than the quota
+    by Michael Hoechstetter.*/
 KURL::List SendImages::divideEmails(void)
 {
 	 unsigned long mylistsize=0;
@@ -375,9 +363,7 @@
 	 return sendnow;
 }
 
-/////////////////////////////////////////////////////////////////////////////////////////////
-// Invoke mailer agent.
-
+/** Invoke mailer agent.*/
 bool SendImages::invokeMailAgent(void)
 {
   bool agentInvoked = false;
@@ -521,17 +507,22 @@
         *m_mailAgentProc << "netscape" << "-remote";
       }
 
-      QString Temp = "xfeDoCommand(composeMessage,attachment='";
+      QString Temp = "xfeDoCommand(composeMessage,attachment=";
 
       for ( KURL::List::Iterator it = filelist.begin() ; it != filelist.end() ; ++it )
       {
-        Temp.append( "file://" );
-        Temp.append( QFile::encodeName((*it).path()) );
-        Temp.append( "," );
+        Temp.append( "\"file://" );
+        //Temp.append( QFile::encodeName((*it).path()) );
+	///It is working with spaces inside the file and pathname, but what still is a problem are kommas
+	//FIXME
+	QString toencode=(*it).encodedPathAndQuery();
+	//QUrl::encode(toencode); 
+        Temp.append(toencode);
+	Temp.append( "\"," );
       }
-
-      Temp.append("')");
-
+      Temp.remove(Temp.length()-1,1);
+      Temp.append(")");
+      
       *m_mailAgentProc << Temp;
 
       connect(m_mailAgentProc, SIGNAL(processExited(KProcess *)),
@@ -563,9 +554,6 @@
        KMessageBox::error(kapp->activeWindow(), i18n("Cannot remove temporary folder %1.").arg(m_tmp));
 }
 
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////
-
 bool SendImages::DeleteDir(QString dirname)
 {
     if ( !dirname.isEmpty() )
@@ -589,9 +577,6 @@
     return true;
 }
 
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////
-
 bool SendImages::deldir(QString dirname)
 {
     QDir *dir = new QDir(dirname);
@@ -628,9 +613,6 @@
     return true;
 }
 
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////
-
 QString SendImages::extension(const QString& imageFileFormat)
 {
     if (imageFileFormat == "PNG")
@@ -643,9 +625,6 @@
     return "";
 }
 
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////
-
 int SendImages::getSize ( int choice )
 {
     switch (choice)
@@ -674,12 +653,9 @@
        }
 }
 
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////
-
-bool SendImages::resizeImageProcess( const QString &SourcePath, const QString &DestPath,
-                                     const QString &ImageFormat, const QString &ImageName,
-                                     int SizeFactor, int ImageCompression)
+bool SendImages::resizeImageProcess(const QString &SourcePath, const QString &DestPath,
+                                    const QString &ImageFormat, const QString &ImageName,
+                                    int SizeFactor, int ImageCompression, QSize &newsize)
 {
     QImage img;
 
@@ -718,6 +694,7 @@
                }
 
            img = scaleImg;
+	   newsize=img.size();
            }
 
         if ( !img.save(DestPath + ImageName, ImageFormat.latin1(), ImageCompression) )
@@ -732,9 +709,6 @@
     return false;
 }
 
-
-/////////////////////////////////////// SLOTS ///////////////////////////////////////////////////////
-
 void SendImages::slotMozillaExited(KProcess*)
 {
     if ( m_mozillaStdErr.find("No running window found") != -1 )   // No remote Mozilla | Netscape |
@@ -768,9 +742,6 @@
        }
 }
 
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////
-
 void SendImages::slotMozillaTimeout(void)
 {
     m_mailAgentProc3 = new KProcess;
@@ -802,9 +773,6 @@
                                   .arg(m_sendImagesDialog->m_mailAgentName->currentText()));
 }
 
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////
-
 void SendImages::slotMozillaReadStderr(KProcess*, char *buffer, int buflen)
 {
     m_mozillaStdErr = QString::fromLocal8Bit(buffer, buflen);
@@ -812,4 +780,3 @@
 
 }  // NameSpace KIPISendimagesPlugin
 
-#include "sendimages.moc"
--- trunk/extragear/libs/kipi-plugins/sendimages/sendimages.h #607336:607337
@@ -120,7 +120,7 @@
    
    bool resizeImageProcess( const QString &SourcePath, const QString &DestPath,
                             const QString &ImageFormat, const QString &ImageName,
-                            int SizeFactor, int ImageCompression);
+                            int SizeFactor, int ImageCompression, QSize &newsize);
 };
 
 }  // NameSpace KIPISendimagesPlugin


More information about the Kde-imaging mailing list