Bug 122374 - image viewer ignores read-only permission
Summary: image viewer ignores read-only permission
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: ImageEditor-Save (show other bugs)
Version: 0.8.1
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-20 22:07 UTC by Gerhard
Modified: 2022-02-03 03:49 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 0.9.0


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gerhard 2006-02-20 22:07:47 UTC
Version:           0.8.1 (using KDE KDE 3.5.0)
Installed from:    SuSE RPMs
OS:                Linux

I set the permissions of my photos to r--r--r-- in order to not accidentally overwrite them. If I modify such a photo in the image viewer, i.e. convert it to B&W, and click to the next photo, I'm asked if I want to save this change (OK so far). If I select "Yes", digikam actually saves the change to the read-only(!!) image which I think is a bug
Comment 1 caulier.gilles 2006-04-15 09:54:09 UTC
Gerhard,

Have you tried to reproduce this bug using current implementation:

--> stable : 0.8.2-svn
--> trunk : 0.9.0-svn

I think that 0.8.2-svn still bugous.
Image editor IO files interface have been completly re-written into 0.9.0-svn. No sure that this bug exist in this branch...

Thanks in advance
Gilles
Comment 2 Marcel Wiesweg 2006-04-24 22:48:11 UTC
SVN commit 533453 by mwiesweg:

Check for write permissions before saving a file in IE.
Ask again (KMessageBox) if permissions are not available.

TODO: We might want to check that the permissions can actually
      be changed (file can be written) if the user wants to.

BUG: 122374


 M  +1 -0      NEWS  
 M  +0 -1      TODO  
 M  +36 -0     utilities/imageeditor/editor/editorwindow.cpp  
 M  +3 -2      utilities/imageeditor/editor/editorwindow.h  


--- trunk/extragear/graphics/digikam/NEWS #533452:533453
@@ -122,5 +122,6 @@
 ==> 115423 (thumbnails view jumps to top when new photos are added)
 ==> 125732 (ICC settings get reset when disabled and re-enabled)
 ==> 119741 (Image Editor: restore image editor if already open)
+==> 122374 (Image Editor: ignores read-only permission during saving)
 
 ----------------------------------------------------------------------------------------------------
--- trunk/extragear/graphics/digikam/TODO #533452:533453
@@ -56,7 +56,6 @@
 ==> 118501  (Image Editor:   Exif lost when modifying the images)
 ==> 116148  (Image Editor:   auto-scrolling when selecting large area)
 ==> 111446  (Image Editor:   bad behaviour when out of disk space)
-==> 122374  (Image Editor:   ignores read-only permission during saving)
 ==> 121242  (Showfoto:       mimelnk/x-image-raw.desktop conflicts with kdegraphics-3.5.x)
 
 LATER 0.9.0 TODO LIST
--- trunk/extragear/graphics/digikam/utilities/imageeditor/editor/editorwindow.cpp #533452:533453
@@ -1283,6 +1283,9 @@
     if (m_savingContext->savingState != SavingContextContainer::SavingStateNone)
         return;
 
+    if (!checkPermissions(url))
+        return;
+
     m_savingContext->srcURL         = url;
     m_savingContext->destinationURL = m_savingContext->srcURL;
     m_savingContext->savingState    = SavingContextContainer::SavingStateSave;
@@ -1403,6 +1406,11 @@
 
         if (result != KMessageBox::Yes)
             return false;
+
+        // There will be two message boxes if the file is not writable.
+        // This may be controversial, and it may be changed, but it was a deliberate decision.
+        if (!checkPermissions(newURL))
+            return false;
     }
 
     // Now do the actual saving -----------------------------------------------------
@@ -1418,6 +1426,34 @@
     return true;
 }
 
+bool EditorWindow::checkPermissions(const KURL& url)
+{
+    //TODO: Check that the permissions can actually be changed
+    //      if write permissions are not available.
+
+    QFileInfo fi(url.path());
+
+    if (fi.exists() && !fi.isWritable())
+    {
+       int result =
+
+            KMessageBox::warningYesNo( this, i18n("You do not have write permissions "
+                                                  "for the file named \"%1\". "
+                                                  "Are you sure you want "
+                                                  "to overwrite it?")
+                                       .arg(url.filename()),
+                                       i18n("Overwrite File?"),
+                                       i18n("Overwrite"),
+                                       KStdGuiItem::cancel() );
+
+        if (result != KMessageBox::Yes)
+            return false;
+    }
+
+    return true;
+}
+
+
 }  // namespace Digikam
 
 #include "editorwindow.moc"
--- trunk/extragear/graphics/digikam/utilities/imageeditor/editor/editorwindow.h #533452:533453
@@ -127,9 +127,10 @@
     bool promptUserSave(const KURL& url);
     void startingSave(const KURL& url);
     bool startingSaveAs(const KURL& url);
-    
-    virtual void finishSaving(bool success);    
+    bool checkPermissions(const KURL& url);
 
+    virtual void finishSaving(bool success);
+
     virtual void readSettings()               { readStandardSettings(); };
     virtual void saveSettings()               { saveStandardSettings(); };
     virtual void toggleActions(bool val)      { toggleStandardActions(val); };