Bug 140477 - Wish: ability to rename images being sent via email
Summary: Wish: ability to rename images being sent via email
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Plugin-Generic-SendByMail (show other bugs)
Version: 5.6.0
Platform: Gentoo Packages Linux
: NOR wishlist
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-23 06:30 UTC by x3ri7yz02
Modified: 2018-03-23 12:09 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In: 0.1.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description x3ri7yz02 2007-01-23 06:30:27 UTC
Version:            (using KDE KDE 3.5.5)
Installed from:    Gentoo Packages
OS:                Linux

In Kipiplugins, it would be good if the "sendimages" plugin would optionally allow the user to rename the image files being sent.  This is because the names used when images are stored and the names used when images are emailed to people won't always be the same.  (This is likely to be true where many photos are stored.)  

For example, you may have images stored with numbered filenames (DSC1001.JPG; 20070120-0011.JPG).  When sending these images via email you may wish to make the names more descriptive for your recipients.  (Eg "Tommy's Birthday Cake";  "Me and Barb at the Zoo".)   As the plugin generates the re-sized versions of the images, it could optionally prompt for a new name if desired.

The name of the original file should not be changed.
Comment 1 Michael Höchstetter 2007-02-12 00:18:39 UTC
I am thinking about how to integrate this idea into the GUI.
From the backend there is no problem, but i want to do it in a intuitive way for the user.
Do you have any suggestions?

Another problems are spaces in filename " ". I think it would be no problem for you if i substitute these by "_".
Comment 2 x3ri7yz02 2007-02-12 08:21:36 UTC
Thank you for taking time to consider this idea.  Thinking about this made me realize that I don't know enough about how kipi-plugins is used in other KDE applications.  (I use kipi-plugins primarily [or only?] via digiKam.)  Would the GUI component have to be specific for each application?

Following are my thoughts on implementing this function in DigiKam:

In digiKam, the "Send Images" function shows the user a dialogue box with two tabs.  The first allows the user to select which images to send and the second controls parameters of the images to be mailed.  The renaming function proposed would more logically fit in the second of these two tabs, but the problem is that this tab does not display the image.  Also, the settings in this tab apply to all the images selected, not to individual images.  

If the renaming feature is implemented, users must be able to see the images when selecting new names.  Otherwise it would probably be annoying and hard to use accurately.

So, some possibilities (in increasing order of personal preference, best solution last): 

1)  Add the renaming function to the first of the two tabs.  Users can see the images here and (optionally) adding new names would be relatively easy.  But this goes against the logic of the two tabs outlined above.

2)  Only allow renaming images if a single image is being sent.  This would be easiest to implement currently (just add a "Name for Emailed File" field to the second tab) but would be annoying for users who wanted to send multiple images - they'd have to send multiple emails or rename manually. 

3)  Add a third tab to this dialogue.  Use the same thumbnail display as in the first tab, but maybe with a two column display (for old name / new name).  New name column would default to the old name, and users could adjust the names if they wished.  

4)  Provide a checkbox on the second tab in the "Change Properties of Image" section for users to flag that they wish to rename the images.  Could GUI then prompt for new names while displaying the thumbnails somehow?  This would change  the current interface a lot, but I can't think of anything better yet.

Perhaps I should post to the DigiKam mailing list for their thoughts?

PS.  Spaces in filenames would not be a problem for me.  Nor would other constraints required for security (eg length of new names etc)
Comment 3 Michael Höchstetter 2007-02-17 12:03:00 UTC
hm, what do you think about 1)
After a right-click i could add a menu entry "rename Image". In my opinion the logic doesn't break, and it is the most intuitive way.

Comment 4 x3ri7yz02 2007-02-19 07:40:54 UTC
I will be grateful no matter how this is implemented.  Your solution has the added advantage of not disturbing the interface - so people who aren't interested in the feature won't be bothered by it.

Your idea works for me - thanks!

PS.  Just to confirm - only the temporary copy of the image, created for the email, would be renamed?  (Ie, the original image name should not be changed.)
Comment 5 Michael Höchstetter 2007-02-19 17:08:23 UTC
i would never change the original filename
Comment 6 Chris Bayley 2007-03-07 21:45:09 UTC
I imagine that any renaming process should have an option to generate an automated filename - perhaps based on date, index, comment, tag etc. Perhaps its just me but I don't want to rename more than about 4 files by hand....
Comment 7 Michael Höchstetter 2007-06-06 02:56:35 UTC
SVN commit 672009 by hoechstetter:

If a description is available, it is used as name for the new generated foto. This is the most simple and cleanest solution;
BUG: 140477;

 M  +63 -12    sendimages.cpp  
 M  +3 -0      sendimages.h  


--- branches/extragear/kde3/libs/kipi-plugins/sendimages/sendimages.cpp #672008:672009
@@ -152,34 +152,74 @@
         QApplication::postEvent(m_parent, new QCustomEvent(QEvent::User, d));
 
         // Prepare resized target images to send.
+        QString imageFileName="";
+        
+        KIPI::ImageInfo info = m_interface->info( *it );
+        QString commentItem = info.description();
 
-        QString imageFileName = ItemName;
+            if ( commentItem.isEmpty() )
+            {
+                commentItem = ItemName.left(ItemName.findRev('.'));
+                qDebug("commentItem is empty");
+            }
+            else
+            {
+                qDebug("commentItem: %s",commentItem.ascii());
+            }
+        
+        
         //QString TempFileName             = (*it).directory().section('/', -1);
-        QString TempFileName=(*it).path().section('/', -2,-1);
+        QString TempFileName=(*it).path().section('/', -2,-2)+"/"+commentItem+
+                             +"."+(*it).path().section('.', -1,-1);
         qDebug("TempFileName: %s",TempFileName.ascii());
-        TempFileName.replace(QChar('/'), "-");
         
+        
         // Thunderbird does not like (). Replace them, BUG:131343
         TempFileName.replace(QChar('('), "_").replace(QChar(')'), "_");
         // and these characters are better eliminated, too ;-)
         TempFileName.replace(QChar(','), "_").replace(QChar(' '), "_");
         TempFileName.replace(QChar(';'), "_").replace(QChar('%'), "_");
+        TempFileName.replace(QChar('/'), "-");
 
+        //If TempFileName already exists, add a number oder increase number
+        if (entry_already_exists(m_filesSendList,m_tmp + TempFileName))
+        {
+                qDebug ("I entered");
+                QString secondpart=(m_tmp+TempFileName).section(".",-1,-1);
+                QString firstpart=
+                (m_tmp+TempFileName).left((m_tmp+TempFileName).length()-secondpart.length()-1);
+                qDebug("Firstpart: %s \n Secondpart: %s",firstpart.ascii(), secondpart.ascii());
+                //Add _integer value in the end and prove again
+                int int_index=2;
+                QString index=QString::number(int_index,10);
+                while (entry_already_exists(m_filesSendList,firstpart + "_"+index+"."+secondpart))
+                {
+                        int_index++;
+                        index=QString::number(int_index,10);
+                        qDebug("Index: %s",index.ascii());
+                }
+                QString temp=firstpart + "_"+index+"."+secondpart;
+                TempFileName=temp.right(temp.length()-m_tmp.length());
+       // .section("-",-2,-1);
+       //         m_tmp=(firstpart + "_"+index+"."+secondpart).section("-",-2);
+        }
+
+
         if ( m_changeProp == true )
         {
             // Prepare resizing images.
 
-            QString imageNameFormat = TempFileName.replace(QChar('.'), "_") +
-                                      extension(m_imageFormat);
+            //QString imageNameFormat = TempFileName.replace(QChar('.'), "_") +
+            //                          extension(m_imageFormat);
    
             qDebug( "Resizing %s-> '%s %s ' (%s ; %d )",imageName.ascii(),
-            m_tmp.ascii(),imageNameFormat.ascii(),m_imageFormat.ascii(),m_sizeFactor);
+            m_tmp.ascii(),TempFileName.ascii(),m_imageFormat.ascii(),m_sizeFactor);
  
             // 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,
+            if ( resizeImageProcess( imageName, m_tmp, m_imageFormat, TempFileName,
                                         m_sizeFactor, m_imageCompression, newsize) == false )
             {
                 // Resized images failed...
@@ -201,7 +241,7 @@
                 if (QString(QImageIO::imageFormat(imageName)).upper() == "JPEG" && 
                     m_imageFormat.upper() == "JPEG")
                 {
-                    QString targetFile = m_tmp + imageNameFormat;
+                    QString targetFile = m_tmp + TempFileName;
                     KExiv2Iface::KExiv2 exiv2Iface;
 
                     if (exiv2Iface.load(imageName))
@@ -215,7 +255,7 @@
                 {
                     qWarning( "createThumb::No Exif Data Found") ;
                 }
-        
+
                 d = new KIPISendimagesPlugin::EventData;
                 d->action    = KIPISendimagesPlugin::ResizeImages;
                 d->fileName  = (*it).fileName();
@@ -223,10 +263,10 @@
                 d->starting  = false;
                 d->success   = true;
                 QApplication::postEvent(m_parent, new QCustomEvent(QEvent::User, d));
-    
-                m_filesSendList.append(m_tmp + imageNameFormat);
+
+                m_filesSendList.append(m_tmp + TempFileName);
                 m_imagesPackage.append(*it);
-                m_imagesPackage.append(m_tmp + imageNameFormat);
+                m_imagesPackage.append(m_tmp + TempFileName);
             }
         }
         else     // No resize images operations...
@@ -255,6 +295,17 @@
     QApplication::postEvent(m_parent, new QCustomEvent(QEvent::User, d));
 }
 
+bool SendImages::entry_already_exists(KURL::List filenamelist,QString entry)
+{
+        KURL::List::Iterator it = filenamelist.begin();
+        while( it != filenamelist.end() )
+        {
+                if ((*it)==entry) return true;
+                it++;
+        }
+        return false;
+}
+
 /// Creates a text file with the images comments.
 void SendImages::makeCommentsFile(void)
 {
--- branches/extragear/kde3/libs/kipi-plugins/sendimages/sendimages.h #672008:672009
@@ -121,6 +121,9 @@
     bool copyImageProcess(const QString &oldFilePath, const QString &DestPath,
                                   const QString &ImageName);
     
+    ///Tests if an entry already exists in the filename list
+    bool entry_already_exists(KURL::List filenamelist,QString entry);
+
     ///Makes a deep copy of a KURL-list: Real and slow copying instead of only pointer arithmetics
     bool kurllistdeepcopy(KURL::List &Destination, KURL::List Source);
 private:
Comment 8 Geoff King 2007-06-07 13:50:36 UTC
Thank you for this feature, it seems very useful. However, Two issues:

1)  I think that the user should be able to turn this on or off. There are times where I might not want to send the comments and would rather just have original file names. Some of my comments are also rather long and I'd rather have simple filenames.  I think this should be accomplished with a checkbox in the dialog.

2)  It fails with an error when comments have certain characters.  For example, I get an an error box when a "?" is in the comment.
Comment 9 x3ri7yz02 2007-06-23 10:35:27 UTC
Michael - great job!  I think this is a really good change.

Many thanks.