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

List:       kde-commits
Subject:    branches/KDE/3.5/kdesdk/kbabel/catalogmanager
From:       Nicolas Goutte <nicolasg () snafu ! de>
Date:       2005-12-09 20:55:06
Message-ID: 1134161706.179415.14082.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 487229 by goutte:

Improve the code saving the markers by using KTempFile


 M  +56 -28    catalogmanagerview.cpp  


--- branches/KDE/3.5/kdesdk/kbabel/catalogmanager/catalogmanagerview.cpp \
#487228:487229 @@ -69,8 +69,8 @@
 #include <kio/netaccess.h>
 #include <kprogress.h>
 #include <kwin.h>
-#include <ktar.h>
 #include <kdeversion.h>
+#include <ktempfile.h>
 
 #include <qfileinfo.h>
 #include <qdir.h>
@@ -523,40 +523,68 @@
 	}
     }
 
-    QString filename;
-    if( url.isLocalFile() ) filename=url.path(0);
-    else filename=kapp->tempSaveName( url.path(0) );
-
-    bool error=false;
-
-    QFile f(filename);
-    if( f.open(IO_WriteOnly) )
+#if KDE_IS_VERSION( 3, 5, 0 )
+    // Support for partially remote KIO slave like media:
+    KURL url2( url );
+    url = KIO::NetAccess::MostLocalURL( url2, this );
+#endif
+    
+    QFile* file = 0;
+    KTempFile* tempFile = 0;
+    QTextStream* stream = 0;
+    bool error = false;
+    
+    if ( url.isLocalFile() )
     {
-	QTextStream s( &f );
-	s << "[Markers]" << endl;
-	for( QStringList::const_iterator it = _markerList.constBegin(); \
                it!=_markerList.constEnd() ; ++it )
-	    s << (*it) << endl;
-	f.close();
+        // We have a local file
+        file = new QFile( url.path() );
+        if ( file->open (IO_WriteOnly) )
+        {
+            stream = new QTextStream();
+        }
+        else
+        {
+            error = true;
+        }
     }
     else
     {
-	error=true;
-        KMessageBox::error(this,
-	    i18n("An error occurred while trying to write to \
file:\n%1\n").arg(url.prettyURL())); +        tempFile = new KTempFile();
+        tempFile->setAutoDelete(true);
+        stream = tempFile->textStream();
+        error = !stream;
     }
-
-    if( !error && !url.isLocalFile())
+    if ( !error )
     {
-	if( !KIO::NetAccess::upload( filename, url ) )
-	{
-    	    KMessageBox::error(this,
-		i18n("An error occurred while trying to upload the \
                file:\n%1\n").arg(url.prettyURL()));
-	}
+        // ### TODO: try to get a better file format for KDE4 (XML?), one working \
with real relative paths (no / at start) and working with UTF-8 +        *stream << \
"[Markers]" << endl; +        for( QStringList::const_iterator it = \
_markerList.constBegin(); it!=_markerList.constEnd() ; ++it ) +            *stream << \
(*it) << endl;  }
-
-    if( !url.isLocalFile() ) QFile::remove(filename);
-
-   checkSelected();
+    if ( error )
+    {
+        // ### KDE4 FIXME: strip the final \n of the message
+        KMessageBox::error( this,
+            i18n( "An error occurred while trying to write to file:\n%1\n" ).arg( \
url.prettyURL()) ); +    }
+    else if ( !url.isLocalFile() )
+    {
+#if KDE_IS_VERSION( 3, 2, 90 )
+        if( !KIO::NetAccess::upload( tempFile->name(), url, this ) )
+#else
+        if( !KIO::NetAccess::upload( tempFile->name(), url ) )
+#endif
+        {
+            // ### KDE4 FIXME: strip the final \n of the message
+            KMessageBox::error(this,
+                i18n("An error occurred while trying to upload the \
file:\n%1\n").arg(url.prettyURL())); +        }
+    }
+    delete stream;
+    delete file;
+    delete tempFile;
+   
+    checkSelected();
 }
 
 void CatalogManagerView::slotMarkPattern( )


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

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