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

List:       kde-commits
Subject:    KDE/kdepim/ktimetracker
From:       Thorsten Staerk <dev () staerk ! de>
Date:       2010-01-23 9:02:33
Message-ID: 1264237353.419967.6087.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1078934 by tstaerk:

Quotes in the task name must be duplicated, not escaped.

BUGS:223856


 M  +122 -121  timetrackerstorage.cpp  


--- trunk/KDE/kdepim/ktimetracker/timetrackerstorage.cpp #1078933:1078934
@@ -432,126 +432,6 @@
 }
 
 //----------------------------------------------------------------------------
-// Routines that handle Comma-Separated Values export file format.
-//
-QString timetrackerstorage::exportcsvFile( TaskView *taskview,
-                                    const ReportCriteria &rc )
-{
-    kDebug(5970) << "Entering function";
-    QString delim = rc.delimiter;
-    QString dquote = rc.quote;
-    QString double_dquote = dquote + dquote;
-    bool to_quote = true;
-    QString err;
-    Task* task;
-    int maxdepth=0;
-    QString title = i18n("Export Progress");
-    KProgressDialog dialog( taskview, 0, title );
-    dialog.setAutoClose( true );
-    dialog.setAllowCancel( true );
-    dialog.progressBar()->setMaximum( 2 * taskview->count() );
-
-    // The default dialog was not displaying all the text in the title bar.
-    int width = taskview->fontMetrics().width(title) * 3;
-    QSize dialogsize;
-    dialogsize.setWidth(width);
-    dialog.setInitialSize( dialogsize );
-
-    if ( taskview->count() > 1 ) dialog.show();
-    QString retval;
-
-    // Find max task depth
-    int tasknr = 0;
-    while ( tasknr < taskview->count() && !dialog.wasCancelled() )
-    {
-        dialog.progressBar()->setValue( dialog.progressBar()->value() + 1 );
-        if ( tasknr % 15 == 0 ) kapp->processEvents(); // repainting is slow
-        if ( taskview->itemAt(tasknr)->depth() > maxdepth )
-            maxdepth = taskview->itemAt(tasknr)->depth();
-        tasknr++;
-    }
-
-    // Export to file
-    tasknr = 0;
-    while ( tasknr < taskview->count() && !dialog.wasCancelled() )
-    {
-        task = taskview->itemAt( tasknr );
-        dialog.progressBar()->setValue( dialog.progressBar()->value() + 1 );
-        if ( tasknr % 15 == 0 ) kapp->processEvents();
-
-        // indent the task in the csv-file:
-        for ( int i=0; i < task->depth(); ++i ) retval += delim;
-
-        /*
-        // CSV compliance
-        // Surround the field with quotes if the field contains
-        // a comma (delim) or a double quote
-        if (task->name().contains(delim) || task->name().contains(dquote))
-        to_quote = true;
-        else
-        to_quote = false;
-        */
-        to_quote = true;
-
-        if (to_quote)
-            retval += dquote;
-
-        // Double quotes replaced by a pair of consecutive double quotes
-        retval += task->name().replace( dquote, double_dquote );
-
-        if (to_quote)
-            retval += dquote;
-
-        // maybe other tasks are more indented, so to align the columns:
-        for ( int i = 0; i < maxdepth - task->depth(); ++i ) retval += delim;
-
-        retval += delim + formatTime( task->sessionTime(),
-                                   rc.decimalMinutes )
-                + delim + formatTime( task->time(),
-                                   rc.decimalMinutes )
-                + delim + formatTime( task->totalSessionTime(),
-                                   rc.decimalMinutes )
-                + delim + formatTime( task->totalTime(),
-                                   rc.decimalMinutes )
-                + '\n';
-        tasknr++;
-    }
-
-    // save, either locally or remote
-    if ((rc.url.isLocalFile()) || (!rc.url.url().contains("/")))
-    {
-        QString filename=rc.url.toLocalFile();
-        if (filename.isEmpty()) filename=rc.url.url();
-        QFile f( filename );
-        if( !f.open( QIODevice::WriteOnly ) )
-        {
-            err = i18n( "Could not open \"%1\".", filename );
-        }
-        if (err.length()==0)
-        {
-            QTextStream stream(&f);
-            // Export to file
-            stream << retval;
-            f.close();
-        }
-    }
-    else // use remote file
-    {
-        KTemporaryFile tmpFile;
-        if ( !tmpFile.open() ) err = QString::fromLatin1( "Unable to get temporary \
                file" );
-        else
-        {
-            QTextStream stream ( &tmpFile );
-            stream << retval;
-            stream.flush();
-            if (!KIO::NetAccess::upload( tmpFile.fileName(), rc.url, 0 )) \
                err=QString::fromLatin1("Could not upload");
-        }
-    }
-
-    return err;
-}
-
-//----------------------------------------------------------------------------
 // Routines that handle logging ktimetracker history
 
 
@@ -707,6 +587,127 @@
     return err;
 }
 
+
+//----------------------------------------------------------------------------
+// Routines that handle Comma-Separated Values export file format.
+//
+QString timetrackerstorage::exportcsvFile( TaskView *taskview,
+                                    const ReportCriteria &rc )
+{
+    kDebug(5970) << "Entering function";
+    QString delim = rc.delimiter;
+    QString dquote = rc.quote;
+    QString double_dquote = dquote + dquote;
+    bool to_quote = true;
+    QString err;
+    Task* task;
+    int maxdepth=0;
+    QString title = i18n("Export Progress");
+    KProgressDialog dialog( taskview, 0, title );
+    dialog.setAutoClose( true );
+    dialog.setAllowCancel( true );
+    dialog.progressBar()->setMaximum( 2 * taskview->count() );
+
+    // The default dialog was not displaying all the text in the title bar.
+    int width = taskview->fontMetrics().width(title) * 3;
+    QSize dialogsize;
+    dialogsize.setWidth(width);
+    dialog.setInitialSize( dialogsize );
+
+    if ( taskview->count() > 1 ) dialog.show();
+    QString retval;
+
+    // Find max task depth
+    int tasknr = 0;
+    while ( tasknr < taskview->count() && !dialog.wasCancelled() )
+    {
+        dialog.progressBar()->setValue( dialog.progressBar()->value() + 1 );
+        if ( tasknr % 15 == 0 ) kapp->processEvents(); // repainting is slow
+        if ( taskview->itemAt(tasknr)->depth() > maxdepth )
+            maxdepth = taskview->itemAt(tasknr)->depth();
+        tasknr++;
+    }
+
+    // Export to file
+    tasknr = 0;
+    while ( tasknr < taskview->count() && !dialog.wasCancelled() )
+    {
+        task = taskview->itemAt( tasknr );
+        dialog.progressBar()->setValue( dialog.progressBar()->value() + 1 );
+        if ( tasknr % 15 == 0 ) kapp->processEvents();
+
+        // indent the task in the csv-file:
+        for ( int i=0; i < task->depth(); ++i ) retval += delim;
+
+        /*
+        // CSV compliance
+        // Surround the field with quotes if the field contains
+        // a comma (delim) or a double quote
+        if (task->name().contains(delim) || task->name().contains(dquote))
+        to_quote = true;
+        else
+        to_quote = false;
+        */
+        to_quote = true;
+
+        if (to_quote)
+            retval += dquote;
+
+        // Double quotes replaced by a pair of consecutive double quotes
+        retval += task->name().replace( dquote, double_dquote );
+
+        if (to_quote)
+            retval += dquote;
+
+        // maybe other tasks are more indented, so to align the columns:
+        for ( int i = 0; i < maxdepth - task->depth(); ++i ) retval += delim;
+
+        retval += delim + formatTime( task->sessionTime(),
+                                   rc.decimalMinutes )
+                + delim + formatTime( task->time(),
+                                   rc.decimalMinutes )
+                + delim + formatTime( task->totalSessionTime(),
+                                   rc.decimalMinutes )
+                + delim + formatTime( task->totalTime(),
+                                   rc.decimalMinutes )
+                + '\n';
+        tasknr++;
+    }
+
+    // save, either locally or remote
+    if ((rc.url.isLocalFile()) || (!rc.url.url().contains("/")))
+    {
+        QString filename=rc.url.toLocalFile();
+        if (filename.isEmpty()) filename=rc.url.url();
+        QFile f( filename );
+        if( !f.open( QIODevice::WriteOnly ) )
+        {
+            err = i18n( "Could not open \"%1\".", filename );
+        }
+        if (err.length()==0)
+        {
+            QTextStream stream(&f);
+            // Export to file
+            stream << retval;
+            f.close();
+        }
+    }
+    else // use remote file
+    {
+        KTemporaryFile tmpFile;
+        if ( !tmpFile.open() ) err = QString::fromLatin1( "Unable to get temporary \
file" ); +        else
+        {
+            QTextStream stream ( &tmpFile );
+            stream << retval;
+            stream.flush();
+            if (!KIO::NetAccess::upload( tmpFile.fileName(), rc.url, 0 )) \
err=QString::fromLatin1("Could not upload"); +        }
+    }
+
+    return err;
+}
+
 // export history report as csv, all tasks X all dates in one block
 QString timetrackerstorage::exportcsvHistory ( TaskView      *taskview,
                                             const QDate   &from,
@@ -779,7 +780,7 @@
         // use the internal table itab to create the return value retval
         for ( int y=0; y<=(taskview->count()); y++ )
         {
-            if (itab->item(y,0)) \
retval.append("\"").append(itab->item(y,0)->text().replace("\"","\\\"")).append("\""); \
// task names +            if (itab->item(y,0)) \
retval.append("\"").append(itab->item(y,0)->text().replace("\"","\"\"")).append("\""); \
// task names  for ( int x=1; x<=from.daysTo(to)+1; x++ )
             {
                 retval.append(rc.delimiter);


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

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