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

List:       kde-commits
Subject:    kdepim/karm
From:       Mark Bucciarelli <mark () hubcapconsulting ! com>
Date:       2004-05-01 2:49:29
Message-ID: 20040501024929.AE6B99A75 () office ! kde ! org
[Download RAW message or body]

CVS commit by bucciare: 

Put back in calculation of maximum task depth
that my previous commit deleted.

Add progress dialog for csv export because with
many tasks (over 200) it takes a long time (over
one minute).

CCMAIL: 80462-done@bugs.kde.org


  M +39 -12    karmstorage.cpp   1.22


--- kdepim/karm/karmstorage.cpp  #1.21:1.22
@@ -29,4 +29,5 @@
 
 #include <qfile.h>
+#include <qsize.h>
 #include <qdict.h>
 #include <qdatetime.h>
@@ -39,4 +40,5 @@
 #include <klocale.h>            // i18n
 #include <kmessagebox.h>
+#include <kprogress.h>
 #include <resourcecalendar.h>
 #include <resourcelocal.h>
@@ -456,4 +458,5 @@ QString KarmStorage::exportcsvFile(TaskV
   QString err;
   Task* task;
+  int maxdepth=0; 
 
   kdDebug(5970)
@@ -467,25 +470,47 @@ QString KarmStorage::exportcsvFile(TaskV
   if (!err)
   {
+    QString title = i18n("Export Progress");
+    KProgressDialog dialog( taskview, 0, title );
+    dialog.setAutoClose( true );
+    dialog.setAllowCancel( true );
+    dialog.progressBar()->setTotalSteps( 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, true );
+    
+    if ( taskview->count() > 1 ) dialog.show();
+
     QTextStream stream(&f);
 
-    for (int tasknr=0; tasknr<=taskview->count()-1; ++tasknr)
+    // Find max task depth
+    int tasknr = 0;
+    while ( tasknr < taskview->count() && !dialog.wasCancelled() )
     {
-      task = taskview->item_at_index(tasknr);
+      dialog.progressBar()->advance( 1 );
+      if ( tasknr % 15 == 0 ) kapp->processEvents(); // repainting is slow 
+      if ( taskview->item_at_index(tasknr)->depth() > maxdepth ) 
+        maxdepth = taskview->item_at_index(tasknr)->depth(); 
+      tasknr++;
+    } 
 
-      kdDebug(5970) << "KarmStorage::exportcsvFile: " 
-        << task->name() << ": " << task->depth() << endl;
+    // Export to file
+    tasknr = 0;
+    while ( tasknr < taskview->count() && !dialog.wasCancelled() )
+    {
+      task = taskview->item_at_index( tasknr );
+
+      dialog.progressBar()->advance( 1 );
+      if ( tasknr % 15 == 0 ) kapp->processEvents();
 
       // indent the task in the csv-file:
-      for (int i=0; i < task->depth(); ++i)
-      {
-        stream << delim;
-      }
+      for ( int i=0; i < task->depth(); ++i ) stream << delim;
       stream << task->name().replace( delim, rdelim );
 
       // maybe other tasks are more indented, so to align the columns:
-      for (int i=0; i<task->depth(); ++i)
-      {
-        stream << delim;
-      }
+      for ( int i = 0; i < maxdepth - task->depth(); ++i ) stream << delim;
+
       stream << delim << task->sessionTime()
              << delim << task->time()
@@ -493,4 +518,5 @@ QString KarmStorage::exportcsvFile(TaskV
              << delim << task->totalTime()
              << endl;
+      tasknr++;
     }
     f.close();


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

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