[Digikam-devel] [Bug 141786] confirmation dialog during rename to existing file does not work

Marcel Wiesweg marcel.wiesweg at gmx.de
Sun Feb 25 21:21:56 GMT 2007


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
         
http://bugs.kde.org/show_bug.cgi?id=141786         




------- Additional Comments From marcel.wiesweg gmx de  2007-02-25 22:21 -------
SVN commit 637240 by mwiesweg:

Use KIO::rename to rename files
- The AlbumLister would ignore changes to the already listed items.
  Force it to recreate the ImageInfo object by
  a list of invalidated items.
- The thumbnail needs to be invalidated as well.
  This is done by listening to a signal from the KIO::CopyJob
- Remove low-level code from DIO::rename
- Remove actual renaming from ImageInfo::setName

CCBUG: 141786


 M  +25 -7     albumiconview.cpp  
 M  +1 -0      albumiconview.h  
 M  +21 -4     albumlister.cpp  
 M  +6 -0      albumlister.h  
 M  +11 -4     dio.cpp  
 M  +1 -1      dio.h  
 M  +4 -3      imageinfo.cpp  
 M  +2 -5      imageinfo.h  


--- trunk/extragear/graphics/digikam/digikam/albumiconview.cpp #637239:637240
 @ -804,16 +804,34  @
     if (!ok)
         return;
 
-    QString oldURL = item->imageInfo()->kurl().url();
+    KURL oldURL = item->imageInfo()->kurlForKIO();
+    KURL newURL = oldURL;
+    newURL.setFileName(newName + ext);
 
-    if (!item->imageInfo()->setName(newName + ext))
-        return;
+    KIO::CopyJob* job = DIO::rename(oldURL, newURL);
+    connect(job, SIGNAL(result(KIO::Job*)),
+            this, SLOT(slotDIOResult(KIO::Job*)));
+    connect(job, SIGNAL(copyingDone(KIO::Job *, const KURL &, const KURL &, bool, bool)),
+            this, SLOT(slotRenamed(KIO::Job*, const KURL &, const KURL&)));
 
-    d->itemDict.remove(oldURL);
-    d->itemDict.insert(item->imageInfo()->kurl().url(), item);
+    // The AlbumManager KDirWatch will trigger a DIO::scan.
+    // When this is completed, DIO will call AlbumLister::instance()->refresh().
+    // Usually the AlbumLister will ignore changes to already listed items.
+    // So the renamed item need explicitly be invalidated.
+    d->imageLister->invalidateItem(item->imageInfo());
+}
 
-    item->repaint();
-    signalItemsAdded();
+void AlbumIconView::slotRenamed(KIO::Job*, const KURL &, const KURL&newURL)
+{
+    // reconstruct file path from digikamalbums:// URL
+    KURL fileURL;
+    fileURL.setPath(newURL.user());
+    fileURL.addPath(newURL.path());
+
+    // refresh thumbnail
+    d->pixMan->remove(fileURL);
+    // clean LoadingCache as well - be pragmatic, do it here.
+    LoadingCacheInterface::cleanFromCache(fileURL.path());
 }
 
 void AlbumIconView::slotDeleteSelectedItems(bool deletePermanently)
--- trunk/extragear/graphics/digikam/digikam/albumiconview.h #637239:637240
 @ -181,6 +181,7  @
     void slotRemoveTag(int tagID);
 
     void slotDIOResult(KIO::Job* job);
+    void slotRenamed(KIO::Job*, const KURL &, const KURL&);
 
     void slotImageAttributesChanged(Q_LLONG imageId);
     void slotAlbumImagesChanged(int albumId);
--- trunk/extragear/graphics/digikam/digikam/albumlister.cpp #637239:637240
 @ -78,6 +78,7  @
     QString                         filter;
 
     QMap<Q_LLONG, ImageInfo*>       itemMap;
+    QMap<int,int>                   invalidatedItems;
     QMap<int,bool>                  dayFilter;
 
     QValueList<int>                 tagFilter;
 @ -292,6 +293,11  @
     d->filter = nameFilter;
 }
 
+void AlbumLister::invalidateItem(const ImageInfo *item)
+{
+    d->invalidatedItems.insert(item->id(), item->id());
+}
+
 void AlbumLister::slotClear()
 {
     emit signalClear();
 @ -351,6 +357,7  @
     {
         DWarning() << "Failed to list url: " << job->errorString() << endl;
         d->itemMap.clear();
+        d->invalidatedItems.clear();
         return;
     }
 
 @ -365,6 +372,7  @
     }
 
     d->itemMap.clear();
+    d->invalidatedItems.clear();
 
     emit signalCompleted();
 }
 @ -398,13 +406,22  @
         if (d->itemMap.contains(imageID))
         {
             ImageInfo* info = d->itemMap[imageID];
-            if (!matchesFilter(info))
+            d->itemMap.remove(imageID);
+
+            if (d->invalidatedItems.contains(imageID))
             {
+                emit signalDeleteItem(info);
                 emit signalDeleteFilteredItem(info);
+                d->itemList.remove(info);
             }
-            
-            d->itemMap.remove(imageID);
-            continue;
+            else
+            {
+                if (!matchesFilter(info))
+                {
+                    emit signalDeleteFilteredItem(info);
+                }
+                continue;
+            }
         }
 
         ImageInfo* info = new ImageInfo(imageID, albumID, name,
--- trunk/extragear/graphics/digikam/digikam/albumlister.h #637239:637240
 @ -89,6 +89,12  @
     void setDayFilter(const QValueList<int>& days);
     void setTagFilter(const QValueList<int>& tags, const MatchingCondition& matchingCond, 
                       bool showUnTagged=false);
+
+    /**
+      * Trigger a recreation of the given ImageInfo object
+      * for the next refresh.
+      */
+    void invalidateItem(const ImageInfo *item);
     
 signals:
 
--- trunk/extragear/graphics/digikam/digikam/dio.cpp #637239:637240
 @ -137,12 +137,18  @
     return job;
 }
 
-bool renameFile(const KURL& src, const KURL& dest)
+KIO::CopyJob *rename(const KURL& src, const KURL& dest)
 {
+    KIO::CopyJob * job = KIO::move(src, dest, false);
+    new Watch(job);
+
+    return job;
+
+    /*
     KURL srcdir;
     srcdir.setDirectory(src.directory());
     KURL dstdir;
-    dstdir.setDirectory(src.directory());
+    dstdir.setDirectory(dest.directory());
     Digikam::PAlbum* srcAlbum = Digikam::AlbumManager::instance()->findPAlbum(srcdir);
     Digikam::PAlbum* dstAlbum = Digikam::AlbumManager::instance()->findPAlbum(dstdir);
     if (!srcAlbum || !dstAlbum)
 @ -161,7 +167,7  @
     while (::stat(QFile::encodeName(dstPath), &stbuf) == 0)
     {
         KIO::RenameDlg_Result result =
-            KIO::open_RenameDlg(i18n("Rename File"), srcPath, KURL(dstPath).fileName(),
+            KIO::open_RenameDlg(i18n("Rename File"), srcPath, dstPath,
                                 KIO::RenameDlg_Mode(KIO::M_SINGLE |
                                                     KIO::M_OVERWRITE),
                                 newDstPath);
 @ -197,7 +203,8  @
 
     KMessageBox::error(0, i18n("Failed to rename file\n%1")
                        .arg(src.fileName()), i18n("Rename Failed"));
-    return false;    
+    return false;
+    */
 }
 
 KIO::Job* scan(const KURL& albumURL)
--- trunk/extragear/graphics/digikam/digikam/dio.h #637239:637240
 @ -38,7 +38,7  @
     
     KIO::Job* del(const KURL::List& srcList, bool useTrash = true);
     
-    bool      renameFile(const KURL& src, const KURL& dest);
+    KIO::CopyJob* rename(const KURL& src, const KURL& dest);
     
     KIO::Job* scan(const KURL& albumURL);
     
--- trunk/extragear/graphics/digikam/digikam/imageinfo.cpp #637239:637240
 @ -86,8 +86,9  @
     return m_name;
 }
 
-bool ImageInfo::setName(const QString& newName)
+void ImageInfo::setName(const QString& newName)
 {
+    /*
     KURL src = kurlForKIO();
     KURL dst = src.upURL();
     dst.addPath(newName);
 @ -101,9 +102,9  @
         DWarning() << "No album found for ID: " << m_albumID << endl;
         return false;
     }
-    
+    */
+
     m_name = newName;
-    return true;
 }
 
 size_t ImageInfo::fileSize() const
--- trunk/extragear/graphics/digikam/digikam/imageinfo.h #637239:637240
 @ -97,13 +97,10  @
     QString   name() const;
 
     /**
-     * Set a new name for the image. This will rename the file on the
-     * disk to the new name. Only use if you are sure of what you are
-     * doing
+     * Set a new name for the image.
      *  param  newName new name for the image
-     *  return true if successful, false otherwise
      */
-    bool      setName(const QString& newName);
+    void setName(const QString& newName);
     
     /**
      *  return the datetime of the image



More information about the Digikam-devel mailing list