[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdepim/kmail
From:       Jonathan Marten <jjm () keelhaul ! me ! uk>
Date:       2009-02-28 13:32:02
Message-ID: 1235827922.238789.18318.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 933232 by marten:

Fix problem of not being able to save attachments to a remote location.
QTemporaryFile::fileName() is only defined while the file is open, using it
after the close() passed a null source file to NetAccess::upload().

Also tidied up the error reporting.

BUG:165418


 M  +25 -10    kmcommands.cpp  


--- trunk/KDE/kdepim/kmail/kmcommands.cpp #933231:933232
@@ -2610,11 +2610,11 @@
     if ( !file.open( QIODevice::WriteOnly ) )
     {
       KMessageBox::error( parentWidget(),
-          i18nc( "%2 is detailed error description",
-            "Could not write the file %1:\n%2",
-            file.fileName(),
-            QString::fromLocal8Bit( strerror( errno ) ) ),
-          i18n( "KMail Error" ) );
+                          i18nc( "1 = file name, 2 = error string",
+                                 "<qt>Could not write to the file<br><b>%1</b><br><br>%2",
+                                 file.fileName(),
+                                 QString::fromLocal8Bit( strerror( errno ) ) ),
+                          i18n( "Error saving attachment" ) );
       return Failed;
     }
 
@@ -2630,16 +2630,31 @@
     ds.setDevice( &tf );
   }
 
-  ds.writeRawData( data.data(), data.size() );
+  if ( ds.writeRawData( data.data(), data.size() ) == -1)
+  {
+    QFile *f = static_cast<QFile *>( ds.device() );
+    KMessageBox::error( parentWidget(),
+                        i18nc( "1 = file name, 2 = error string",
+                               "<qt>Could not write to the file<br><b>%1</b><br><br>%2",
+                               f->fileName(),
+                               f->errorString() ),
+                        i18n( "Error saving attachment" ) );
+    return Failed;
+  }
+
   if ( !url.isLocalFile() )
   {
+    // QTemporaryFile::fileName() is only defined while the file is open
+    QString tfName = tf.fileName();
     tf.close();
-    if ( !KIO::NetAccess::upload( tf.fileName(), url, parentWidget() ) )
+    if ( !KIO::NetAccess::upload( tfName, url, parentWidget() ) )
     {
       KMessageBox::error( parentWidget(),
-          i18n( "Could not write the file %1.",
-            url.path() ),
-          i18n( "KMail Error" ) );
+                          i18nc( "1 = file name, 2 = error string",
+                                 "<qt>Could not write to the file<br><b>%1</b><br><br>%2",
+                                 url.prettyUrl(),
+                                 KIO::NetAccess::lastErrorString() ),
+                          i18n( "Error saving attachment" ) );
       return Failed;
     }
   } else
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic