<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US"> <head> <title>karm: karmstorage.cpp Source File (karm)</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="pics-label" content='(pics-1.1 "http://www.icra.org/ratingsv02.html" comment "ICRAonline DE v2.0" l gen true for "http://www.kde.org" r (nz 1 vz 1 lz 1 oz 1 cb 1) "http://www.rsac.org/ratingsv01.html" l gen true for "http://www.kde.org" r (n 0 s 0 v 0 l 0))' /> <meta name="trademark" content="KDE e.V." /> <meta name="description" content="K Desktop Environment Homepage, KDE.org" /> <meta name="MSSmartTagsPreventParsing" content="true" /> <meta name="robots" content="all" /> <link rel="shortcut icon" href="../../favicon.ico" /> <link rel="stylesheet" media="screen" type="text/css" title="APIDOX" href="doxygen.css" /> <style type="text/css"> <!-- hr { display: none; } #content h2 { margin-left: 0px; } table.mdTable { background-color: #f8f8f8; border: .2em solid #d7d7d7; } td.mdRow { padding: 8px 20px; } td.md { font-weight: bold; } td.mdname1 { font-weight: bold; color: #602020; } td.mdname { font-weight: bold; color: #602020; } --> </style> </head> <body> <div id="nav_header_top" align="right"> <a href="#content" class="doNotDisplay" accesskey="2">Skip to main content ::</a> <a href="../.."><img id="nav_header_logo" alt="Home" align="left" src="../../kde_gear_64.png" border="0" /></a> <span class="doNotDisplay">::</span> <img id="nav_header_logo_right" alt="" align="right" src="../../pimlogo.png" border="0" /> <div id="nav_header_title" align="left">KDE PIM API Reference</div> </div> <div id="nav_header_bottom" align="right"> <span class="doNotDisplay">:: <a href="#navigation" accesskey="5">Skip to Link Menu</a><br/></span> <div id="nav_header_bottom_left" style="text-align: left;"> / <a href="../../">API Reference</a> / <a href=".">karm</a> </div> </div> <table id="main" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td valign="top" class="menuheader" height="0"></td> <td id="contentcolumn" valign="top" rowspan="2" > <div id="content" style="padding-top: 0px;"><div style="width:100%; margin: 0px; padding: 0px;"> <h2><a name="content"></a>karm</h2> <!-- Generated by Doxygen 1.5.5 --> <h1>karmstorage.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> * This file only:</span> <a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2003, 2004 Mark Bucciarelli <mark@hubcapconsulting.com></span> <a name="l00004"></a>00004 <span class="comment"> *</span> <a name="l00005"></a>00005 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span> <a name="l00006"></a>00006 <span class="comment"> * it under the terms of the GNU General Public License as published by</span> <a name="l00007"></a>00007 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span> <a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span> <a name="l00009"></a>00009 <span class="comment"> *</span> <a name="l00010"></a>00010 <span class="comment"> * This program is distributed in the hope that it will be useful,</span> <a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span> <a name="l00013"></a>00013 <span class="comment"> * GNU General Public License for more details.</span> <a name="l00014"></a>00014 <span class="comment"> *</span> <a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public License along</span> <a name="l00016"></a>00016 <span class="comment"> * with this program; if not, write to the</span> <a name="l00017"></a>00017 <span class="comment"> * Free Software Foundation, Inc.</span> <a name="l00018"></a>00018 <span class="comment"> * 51 Franklin Street, Fifth Floor</span> <a name="l00019"></a>00019 <span class="comment"> * Boston, MA 02110-1301 USA.</span> <a name="l00020"></a>00020 <span class="comment"> *</span> <a name="l00021"></a>00021 <span class="comment"> */</span> <a name="l00022"></a>00022 <a name="l00023"></a>00023 <span class="preprocessor">#include <sys/types.h></span> <a name="l00024"></a>00024 <span class="preprocessor">#include <sys/stat.h></span> <a name="l00025"></a>00025 <span class="preprocessor">#include <fcntl.h></span> <a name="l00026"></a>00026 <span class="preprocessor">#include <unistd.h></span> <a name="l00027"></a>00027 <a name="l00028"></a>00028 <span class="preprocessor">#include <cassert></span> <a name="l00029"></a>00029 <a name="l00030"></a>00030 <span class="preprocessor">#include <qfile.h></span> <a name="l00031"></a>00031 <span class="preprocessor">#include <qsize.h></span> <a name="l00032"></a>00032 <span class="preprocessor">#include <qdict.h></span> <a name="l00033"></a>00033 <span class="preprocessor">#include <qdatetime.h></span> <a name="l00034"></a>00034 <span class="preprocessor">#include <qstring.h></span> <a name="l00035"></a>00035 <span class="preprocessor">#include <qstringlist.h></span> <a name="l00036"></a>00036 <a name="l00037"></a>00037 <span class="preprocessor">#include "incidence.h"</span> <a name="l00038"></a>00038 <span class="preprocessor">#include "kapplication.h"</span> <span class="comment">// kapp</span> <a name="l00039"></a>00039 <span class="preprocessor">#include <kdebug.h></span> <a name="l00040"></a>00040 <span class="preprocessor">#include <kemailsettings.h></span> <a name="l00041"></a>00041 <span class="preprocessor">#include <klocale.h></span> <span class="comment">// i18n</span> <a name="l00042"></a>00042 <span class="preprocessor">#include <kmessagebox.h></span> <a name="l00043"></a>00043 <span class="preprocessor">#include <kprogress.h></span> <a name="l00044"></a>00044 <span class="preprocessor">#include <ktempfile.h></span> <a name="l00045"></a>00045 <span class="preprocessor">#include <resourcecalendar.h></span> <a name="l00046"></a>00046 <span class="preprocessor">#include <resourcelocal.h></span> <a name="l00047"></a>00047 <span class="preprocessor">#include <resourceremote.h></span> <a name="l00048"></a>00048 <span class="preprocessor">#include <kpimprefs.h></span> <a name="l00049"></a>00049 <span class="preprocessor">#include <taskview.h></span> <a name="l00050"></a>00050 <span class="preprocessor">#include <timekard.h></span> <a name="l00051"></a>00051 <span class="preprocessor">#include <karmutility.h></span> <a name="l00052"></a>00052 <span class="preprocessor">#include <kio/netaccess.h></span> <a name="l00053"></a>00053 <span class="preprocessor">#include <kurl.h></span> <a name="l00054"></a>00054 <span class="preprocessor">#include <vector></span> <a name="l00055"></a>00055 <a name="l00056"></a>00056 <span class="comment">//#include <calendarlocal.h></span> <a name="l00057"></a>00057 <span class="comment">//#include <journal.h></span> <a name="l00058"></a>00058 <span class="comment">//#include <event.h></span> <a name="l00059"></a>00059 <span class="comment">//#include <todo.h></span> <a name="l00060"></a>00060 <a name="l00061"></a>00061 <span class="preprocessor">#include "karmstorage.h"</span> <a name="l00062"></a>00062 <span class="preprocessor">#include "preferences.h"</span> <a name="l00063"></a>00063 <span class="preprocessor">#include "task.h"</span> <a name="l00064"></a>00064 <span class="preprocessor">#include "reportcriteria.h"</span> <a name="l00065"></a>00065 <a name="l00066"></a>00066 <span class="keyword">using namespace </span>std; <a name="l00067"></a>00067 <a name="l00068"></a>00068 <a class="code" href="classKarmStorage.html" title="Singleton to store/retrieve KArm data to/from persistent storage.">KarmStorage</a> *KarmStorage::_instance = 0; <a name="l00069"></a>00069 <span class="keyword">static</span> <span class="keywordtype">long</span> linenr; <span class="comment">// how many lines written by printTaskHistory so far</span> <a name="l00070"></a>00070 <a name="l00071"></a>00071 <a name="l00072"></a>00072 <a class="code" href="classKarmStorage.html" title="Singleton to store/retrieve KArm data to/from persistent storage.">KarmStorage</a> *KarmStorage::instance() <a name="l00073"></a>00073 { <a name="l00074"></a>00074 <span class="keywordflow">if</span> (_instance == 0) _instance = <span class="keyword">new</span> <a class="code" href="classKarmStorage.html" title="Singleton to store/retrieve KArm data to/from persistent storage.">KarmStorage</a>(); <a name="l00075"></a>00075 <span class="keywordflow">return</span> _instance; <a name="l00076"></a>00076 } <a name="l00077"></a>00077 <a name="l00078"></a>00078 KarmStorage::KarmStorage() <a name="l00079"></a>00079 { <a name="l00080"></a>00080 _calendar = 0; <a name="l00081"></a>00081 } <a name="l00082"></a>00082 <a name="l00083"></a>00083 QString KarmStorage::load (<a class="code" href="classTaskView.html" title="Container and interface for the tasks.">TaskView</a>* view, <span class="keyword">const</span> <a class="code" href="classPreferences.html" title="Provide an interface to the configuration options for the program.">Preferences</a>* preferences, QString fileName ) <a name="l00084"></a>00084 <span class="comment">// loads data from filename into view. If no filename is given, filename from preferences is used.</span> <a name="l00085"></a>00085 <span class="comment">// filename might be of use if this program is run as embedded konqueror plugin.</span> <a name="l00086"></a>00086 { <a name="l00087"></a>00087 <span class="comment">// When I tried raising an exception from this method, the compiler</span> <a name="l00088"></a>00088 <span class="comment">// complained that exceptions are not allowed. Not sure how apps</span> <a name="l00089"></a>00089 <span class="comment">// typically handle error conditions in KDE, but I'll return the error</span> <a name="l00090"></a>00090 <span class="comment">// as a string (empty is no error). -- Mark, Aug 8, 2003</span> <a name="l00091"></a>00091 <a name="l00092"></a>00092 <span class="comment">// Use KDE_CXXFLAGS=$(USE_EXCEPTIONS) in Makefile.am if you want to use</span> <a name="l00093"></a>00093 <span class="comment">// exceptions (David Faure)</span> <a name="l00094"></a>00094 <a name="l00095"></a>00095 QString err; <a name="l00096"></a>00096 KEMailSettings settings; <a name="l00097"></a>00097 <span class="keywordflow">if</span> ( fileName.isEmpty() ) fileName = preferences-><a class="code" href="classPreferences.html#c3effde4c28843fd40d2ca8622fb1517">iCalFile</a>(); <a name="l00098"></a>00098 <a name="l00099"></a>00099 <span class="comment">// If same file, don't reload</span> <a name="l00100"></a>00100 <span class="keywordflow">if</span> ( fileName == _icalfile ) <span class="keywordflow">return</span> err; <a name="l00101"></a>00101 <a name="l00102"></a>00102 <a name="l00103"></a>00103 <span class="comment">// If file doesn't exist, create a blank one to avoid ResourceLocal load</span> <a name="l00104"></a>00104 <span class="comment">// error. We make it user and group read/write, others read. This is</span> <a name="l00105"></a>00105 <span class="comment">// masked by the users umask. (See man creat)</span> <a name="l00106"></a>00106 <span class="keywordflow">if</span> ( ! remoteResource( _icalfile ) ) <a name="l00107"></a>00107 { <a name="l00108"></a>00108 <span class="keywordtype">int</span> handle; <a name="l00109"></a>00109 handle = open ( <a name="l00110"></a>00110 QFile::encodeName( fileName ), <a name="l00111"></a>00111 O_CREAT|O_EXCL|O_WRONLY, <a name="l00112"></a>00112 S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH <a name="l00113"></a>00113 ); <a name="l00114"></a>00114 <span class="keywordflow">if</span> (handle != -1) close(handle); <a name="l00115"></a>00115 } <a name="l00116"></a>00116 <a name="l00117"></a>00117 <span class="keywordflow">if</span> ( _calendar) <a name="l00118"></a>00118 closeStorage(view); <a name="l00119"></a>00119 <a name="l00120"></a>00120 <span class="comment">// Create local file resource and add to resources</span> <a name="l00121"></a>00121 _icalfile = fileName; <a name="l00122"></a>00122 <a name="l00123"></a>00123 KCal::ResourceCached *resource; <a name="l00124"></a>00124 <span class="keywordflow">if</span> ( remoteResource( _icalfile ) ) <a name="l00125"></a>00125 { <a name="l00126"></a>00126 KURL url( _icalfile ); <a name="l00127"></a>00127 resource = <span class="keyword">new</span> KCal::ResourceRemote( url, url ); <span class="comment">// same url for upload and download</span> <a name="l00128"></a>00128 } <a name="l00129"></a>00129 <span class="keywordflow">else</span> <a name="l00130"></a>00130 { <a name="l00131"></a>00131 resource = <span class="keyword">new</span> KCal::ResourceLocal( _icalfile ); <a name="l00132"></a>00132 } <a name="l00133"></a>00133 _calendar = resource; <a name="l00134"></a>00134 <a name="l00135"></a>00135 QObject::connect (_calendar, SIGNAL(resourceChanged(ResourceCalendar *)), <a name="l00136"></a>00136 view, SLOT(iCalFileModified(ResourceCalendar *))); <a name="l00137"></a>00137 _calendar->setTimeZoneId( KPimPrefs::timezone() ); <a name="l00138"></a>00138 _calendar->setResourceName( QString::fromLatin1(<span class="stringliteral">"KArm"</span>) ); <a name="l00139"></a>00139 _calendar->open(); <a name="l00140"></a>00140 _calendar->load(); <a name="l00141"></a>00141 <a name="l00142"></a>00142 <span class="comment">// Claim ownership of iCalendar file if no one else has.</span> <a name="l00143"></a>00143 KCal::Person owner = resource->getOwner(); <a name="l00144"></a>00144 <span class="keywordflow">if</span> ( owner.isEmpty() ) <a name="l00145"></a>00145 { <a name="l00146"></a>00146 resource->setOwner( KCal::Person( <a name="l00147"></a>00147 settings.getSetting( KEMailSettings::RealName ), <a name="l00148"></a>00148 settings.getSetting( KEMailSettings::EmailAddress ) ) ); <a name="l00149"></a>00149 } <a name="l00150"></a>00150 <a name="l00151"></a>00151 <span class="comment">// Build task view from iCal data</span> <a name="l00152"></a>00152 <span class="keywordflow">if</span> (!err) <a name="l00153"></a>00153 { <a name="l00154"></a>00154 KCal::Todo::List todoList; <a name="l00155"></a>00155 KCal::Todo::List::ConstIterator todo; <a name="l00156"></a>00156 QDict< Task > map; <a name="l00157"></a>00157 <a name="l00158"></a>00158 <span class="comment">// Build dictionary to look up Task object from Todo uid. Each task is a</span> <a name="l00159"></a>00159 <span class="comment">// QListViewItem, and is initially added with the view as the parent.</span> <a name="l00160"></a>00160 todoList = _calendar->rawTodos(); <a name="l00161"></a>00161 kdDebug(5970) << <span class="stringliteral">"KarmStorage::load "</span> <a name="l00162"></a>00162 << <span class="stringliteral">"rawTodo count (includes completed todos) ="</span> <a name="l00163"></a>00163 << todoList.count() << endl; <a name="l00164"></a>00164 <span class="keywordflow">for</span>( todo = todoList.begin(); todo != todoList.end(); ++todo ) <a name="l00165"></a>00165 { <a name="l00166"></a>00166 <span class="comment">// Initially, if a task was complete, it was removed from the view.</span> <a name="l00167"></a>00167 <span class="comment">// However, this increased the complexity of reporting on task history.</span> <a name="l00168"></a>00168 <span class="comment">//</span> <a name="l00169"></a>00169 <span class="comment">// For example, if a task is complete yet has time logged to it during</span> <a name="l00170"></a>00170 <span class="comment">// the date range specified on the history report, we have to figure out</span> <a name="l00171"></a>00171 <span class="comment">// how that task fits into the task hierarchy. Currently, this</span> <a name="l00172"></a>00172 <span class="comment">// structure is held in memory by the structure in the list view.</span> <a name="l00173"></a>00173 <span class="comment">//</span> <a name="l00174"></a>00174 <span class="comment">// I considered creating a second tree that held the full structure of</span> <a name="l00175"></a>00175 <span class="comment">// all complete and incomplete tasks. But this seemed to much of a</span> <a name="l00176"></a>00176 <span class="comment">// change with an impending beta release and a full todo list.</span> <a name="l00177"></a>00177 <span class="comment">//</span> <a name="l00178"></a>00178 <span class="comment">// Hence this "solution". Include completed tasks, but mark them as</span> <a name="l00179"></a>00179 <span class="comment">// inactive in the view.</span> <a name="l00180"></a>00180 <span class="comment">//</span> <a name="l00181"></a>00181 <span class="comment">//if ((*todo)->isCompleted()) continue;</span> <a name="l00182"></a>00182 <a name="l00183"></a>00183 <a class="code" href="classTask.html" title="A class representing a task.">Task</a>* task = <span class="keyword">new</span> <a class="code" href="classTask.html" title="A class representing a task.">Task</a>(*todo, view); <a name="l00184"></a>00184 map.insert( (*todo)->uid(), task ); <a name="l00185"></a>00185 view->setRootIsDecorated(<span class="keyword">true</span>); <a name="l00186"></a>00186 task-><a class="code" href="classTask.html#8440f07186682b23c1c1212a461a33ee" title="Sets an appropriate icon for this task based on its level of completion.">setPixmapProgress</a>(); <a name="l00187"></a>00187 } <a name="l00188"></a>00188 <a name="l00189"></a>00189 <span class="comment">// Load each task under it's parent task.</span> <a name="l00190"></a>00190 <span class="keywordflow">for</span>( todo = todoList.begin(); todo != todoList.end(); ++todo ) <a name="l00191"></a>00191 { <a name="l00192"></a>00192 <a class="code" href="classTask.html" title="A class representing a task.">Task</a>* task = map.find( (*todo)->uid() ); <a name="l00193"></a>00193 <a name="l00194"></a>00194 <span class="comment">// No relatedTo incident just means this is a top-level task.</span> <a name="l00195"></a>00195 <span class="keywordflow">if</span> ( (*todo)->relatedTo() ) <a name="l00196"></a>00196 { <a name="l00197"></a>00197 <a class="code" href="classTask.html" title="A class representing a task.">Task</a>* newParent = map.find( (*todo)->relatedToUid() ); <a name="l00198"></a>00198 <a name="l00199"></a>00199 <span class="comment">// Complete the loading but return a message</span> <a name="l00200"></a>00200 <span class="keywordflow">if</span> ( !newParent ) <a name="l00201"></a>00201 err = i18n(<span class="stringliteral">"Error loading \"%1\": could not find parent (uid=%2)"</span>) <a name="l00202"></a>00202 .arg(task-><a class="code" href="classTask.html#e18d2ce750c810aa14033d6c1df99e0d" title="returns the name of this task.">name</a>()) <a name="l00203"></a>00203 .arg((*todo)->relatedToUid()); <a name="l00204"></a>00204 <a name="l00205"></a>00205 <span class="keywordflow">if</span> (!err) task-><a class="code" href="classTask.html#c5b97ac4b67457341ee4c9e8b00e74f1" title="cut Task out of parent Task or the TaskView and into the destination Task">move</a>( newParent); <a name="l00206"></a>00206 } <a name="l00207"></a>00207 } <a name="l00208"></a>00208 <a name="l00209"></a>00209 kdDebug(5970) << <span class="stringliteral">"KarmStorage::load - loaded "</span> << view-><a class="code" href="classTaskView.html#1baadc861bc75b2aa06ce7351a03cefd" title="Return the total number if items in the view.">count</a>() <a name="l00210"></a>00210 << <span class="stringliteral">" tasks from "</span> << _icalfile << endl; <a name="l00211"></a>00211 } <a name="l00212"></a>00212 <a name="l00213"></a>00213 <span class="keywordflow">return</span> err; <a name="l00214"></a>00214 } <a name="l00215"></a>00215 <a name="l00216"></a>00216 QString KarmStorage::icalfile() <a name="l00217"></a>00217 { <a name="l00218"></a>00218 kdDebug(5970) << <span class="stringliteral">"Entering KarmStorage::icalfile"</span> << endl; <a name="l00219"></a>00219 <span class="keywordflow">return</span> _icalfile; <a name="l00220"></a>00220 } <a name="l00221"></a>00221 <a name="l00222"></a>00222 QString KarmStorage::buildTaskView(KCal::ResourceCalendar *rc, <a class="code" href="classTaskView.html" title="Container and interface for the tasks.">TaskView</a> *view) <a name="l00223"></a>00223 <span class="comment">// makes *view contain the tasks out of *rc.</span> <a name="l00224"></a>00224 { <a name="l00225"></a>00225 QString err; <a name="l00226"></a>00226 KCal::Todo::List todoList; <a name="l00227"></a>00227 KCal::Todo::List::ConstIterator todo; <a name="l00228"></a>00228 QDict< Task > map; <a name="l00229"></a>00229 vector<QString> runningTasks; <a name="l00230"></a>00230 vector<QDateTime> startTimes; <a name="l00231"></a>00231 <a name="l00232"></a>00232 <span class="comment">// remember tasks that are running and their start times</span> <a name="l00233"></a>00233 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0; i<view-><a class="code" href="classTaskView.html#1baadc861bc75b2aa06ce7351a03cefd" title="Return the total number if items in the view.">count</a>(); i++) <a name="l00234"></a>00234 { <a name="l00235"></a>00235 <span class="keywordflow">if</span> ( view-><a class="code" href="classTaskView.html#9050454887e14a5c62725e23f242639d" title="Return the i&#39;th item (zero-based), cast to a Task pointer.">item_at_index</a>(i)-><a class="code" href="classTask.html#810ac835cff9a3fab9f7c8983a950431" title="return the state of a task - if it&#39;s running or not">isRunning</a>() ) <a name="l00236"></a>00236 { <a name="l00237"></a>00237 runningTasks.push_back( view-><a class="code" href="classTaskView.html#9050454887e14a5c62725e23f242639d" title="Return the i&#39;th item (zero-based), cast to a Task pointer.">item_at_index</a>(i)-><a class="code" href="classTask.html#9a822ba9744f31d2e2bc92c74b757ac2" title="Return unique iCalendar Todo ID for this task.">uid</a>() ); <a name="l00238"></a>00238 startTimes.push_back( view-><a class="code" href="classTaskView.html#9050454887e14a5c62725e23f242639d" title="Return the i&#39;th item (zero-based), cast to a Task pointer.">item_at_index</a>(i)-><a class="code" href="classTask.html#90ce9e63c953acda7036d71a6a30a667" title="delivers when the task was started last">lastStart</a>() ); <a name="l00239"></a>00239 } <a name="l00240"></a>00240 } <a name="l00241"></a>00241 <a name="l00242"></a>00242 <span class="comment">//view->stopAllTimers();</span> <a name="l00243"></a>00243 <span class="comment">// delete old tasks</span> <a name="l00244"></a>00244 <span class="keywordflow">while</span> (view-><a class="code" href="classTaskView.html#9050454887e14a5c62725e23f242639d" title="Return the i&#39;th item (zero-based), cast to a Task pointer.">item_at_index</a>(0)) view-><a class="code" href="classTaskView.html#9050454887e14a5c62725e23f242639d" title="Return the i&#39;th item (zero-based), cast to a Task pointer.">item_at_index</a>(0)-><a class="code" href="classTask.html#d999ac7a55fc18de3dae5804da154616" title="cut Task out of parent Task or the TaskView">cut</a>(); <a name="l00245"></a>00245 <a name="l00246"></a>00246 <span class="comment">// 1. insert tasks form rc into taskview</span> <a name="l00247"></a>00247 <span class="comment">// 1.1. Build dictionary to look up Task object from Todo uid. Each task is a</span> <a name="l00248"></a>00248 <span class="comment">// QListViewItem, and is initially added with the view as the parent.</span> <a name="l00249"></a>00249 todoList = rc->rawTodos(); <a name="l00250"></a>00250 <span class="keywordflow">for</span>( todo = todoList.begin(); todo != todoList.end(); ++todo ) <a name="l00251"></a>00251 { <a name="l00252"></a>00252 <a class="code" href="classTask.html" title="A class representing a task.">Task</a>* task = <span class="keyword">new</span> <a class="code" href="classTask.html" title="A class representing a task.">Task</a>(*todo, view); <a name="l00253"></a>00253 map.insert( (*todo)->uid(), task ); <a name="l00254"></a>00254 view->setRootIsDecorated(<span class="keyword">true</span>); <a name="l00255"></a>00255 task-><a class="code" href="classTask.html#8440f07186682b23c1c1212a461a33ee" title="Sets an appropriate icon for this task based on its level of completion.">setPixmapProgress</a>(); <a name="l00256"></a>00256 } <a name="l00257"></a>00257 <a name="l00258"></a>00258 <span class="comment">// 1.1. Load each task under it's parent task.</span> <a name="l00259"></a>00259 <span class="keywordflow">for</span>( todo = todoList.begin(); todo != todoList.end(); ++todo ) <a name="l00260"></a>00260 { <a name="l00261"></a>00261 <a class="code" href="classTask.html" title="A class representing a task.">Task</a>* task = map.find( (*todo)->uid() ); <a name="l00262"></a>00262 <a name="l00263"></a>00263 <span class="comment">// No relatedTo incident just means this is a top-level task.</span> <a name="l00264"></a>00264 <span class="keywordflow">if</span> ( (*todo)->relatedTo() ) <a name="l00265"></a>00265 { <a name="l00266"></a>00266 <a class="code" href="classTask.html" title="A class representing a task.">Task</a>* newParent = map.find( (*todo)->relatedToUid() ); <a name="l00267"></a>00267 <a name="l00268"></a>00268 <span class="comment">// Complete the loading but return a message</span> <a name="l00269"></a>00269 <span class="keywordflow">if</span> ( !newParent ) <a name="l00270"></a>00270 err = i18n(<span class="stringliteral">"Error loading \"%1\": could not find parent (uid=%2)"</span>) <a name="l00271"></a>00271 .arg(task-><a class="code" href="classTask.html#e18d2ce750c810aa14033d6c1df99e0d" title="returns the name of this task.">name</a>()) <a name="l00272"></a>00272 .arg((*todo)->relatedToUid()); <a name="l00273"></a>00273 <a name="l00274"></a>00274 <span class="keywordflow">if</span> (!err) task-><a class="code" href="classTask.html#c5b97ac4b67457341ee4c9e8b00e74f1" title="cut Task out of parent Task or the TaskView and into the destination Task">move</a>( newParent); <a name="l00275"></a>00275 } <a name="l00276"></a>00276 } <a name="l00277"></a>00277 <a name="l00278"></a>00278 view-><a class="code" href="classTaskView.html#918b4d6f5147a80b9d60d57fc2ae0a8c" title="clears all active tasks.">clearActiveTasks</a>(); <a name="l00279"></a>00279 <span class="comment">// restart tasks that have been running with their start times</span> <a name="l00280"></a>00280 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0; i<view-><a class="code" href="classTaskView.html#1baadc861bc75b2aa06ce7351a03cefd" title="Return the total number if items in the view.">count</a>(); i++) <a name="l00281"></a>00281 { <a name="l00282"></a>00282 <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n=0; n<runningTasks.size(); n++) <a name="l00283"></a>00283 { <a name="l00284"></a>00284 <span class="keywordflow">if</span> ( runningTasks[n] == view-><a class="code" href="classTaskView.html#9050454887e14a5c62725e23f242639d" title="Return the i&#39;th item (zero-based), cast to a Task pointer.">item_at_index</a>(i)-><a class="code" href="classTask.html#9a822ba9744f31d2e2bc92c74b757ac2" title="Return unique iCalendar Todo ID for this task.">uid</a>() ) <a name="l00285"></a>00285 { <a name="l00286"></a>00286 view-><a class="code" href="classTaskView.html#1f0a2039eca771ee28f457f6a8d098d5" title="starts timer for task.">startTimerFor</a>( view-><a class="code" href="classTaskView.html#9050454887e14a5c62725e23f242639d" title="Return the i&#39;th item (zero-based), cast to a Task pointer.">item_at_index</a>(i), startTimes[n] ); <a name="l00287"></a>00287 } <a name="l00288"></a>00288 } <a name="l00289"></a>00289 } <a name="l00290"></a>00290 <a name="l00291"></a>00291 view-><a class="code" href="classTaskView.html#62a6de5702b8772e6200ec447cf9b664" title="Used to refresh (e.g.">refresh</a>(); <a name="l00292"></a>00292 <a name="l00293"></a>00293 <span class="keywordflow">return</span> err; <a name="l00294"></a>00294 } <a name="l00295"></a>00295 <a name="l00296"></a>00296 <span class="keywordtype">void</span> KarmStorage::closeStorage(<a class="code" href="classTaskView.html" title="Container and interface for the tasks.">TaskView</a>* view) <a name="l00297"></a>00297 { <a name="l00298"></a>00298 <span class="keywordflow">if</span> ( _calendar ) <a name="l00299"></a>00299 { <a name="l00300"></a>00300 _calendar->close(); <a name="l00301"></a>00301 <span class="keyword">delete</span> _calendar; <a name="l00302"></a>00302 _calendar = 0; <a name="l00303"></a>00303 <a name="l00304"></a>00304 view->clear(); <a name="l00305"></a>00305 } <a name="l00306"></a>00306 } <a name="l00307"></a>00307 <a name="l00308"></a>00308 QString KarmStorage::save(<a class="code" href="classTaskView.html" title="Container and interface for the tasks.">TaskView</a>* taskview) <a name="l00309"></a>00309 { <a name="l00310"></a>00310 kdDebug(5970) << <span class="stringliteral">"entering KarmStorage::save"</span> << endl; <a name="l00311"></a>00311 QString err=QString(); <a name="l00312"></a>00312 <a name="l00313"></a>00313 QPtrStack< KCal::Todo > parents; <a name="l00314"></a>00314 <a name="l00315"></a>00315 <span class="keywordflow">for</span> (<a class="code" href="classTask.html" title="A class representing a task.">Task</a>* task=taskview-><a class="code" href="classTaskView.html#19f03096ab651f975fec50e4be6aef49" title="Return the first item in the view, cast to a Task pointer.">first_child</a>(); task; task = task-><a class="code" href="classTask.html#a7c59fd2c4318c9eac3bf10fb0201422">nextSibling</a>()) <a name="l00316"></a>00316 { <a name="l00317"></a>00317 err=writeTaskAsTodo(task, 1, parents ); <a name="l00318"></a>00318 } <a name="l00319"></a>00319 <a name="l00320"></a>00320 <span class="keywordflow">if</span> ( !saveCalendar() ) <a name="l00321"></a>00321 { <a name="l00322"></a>00322 err=<span class="stringliteral">"Could not save"</span>; <a name="l00323"></a>00323 } <a name="l00324"></a>00324 <a name="l00325"></a>00325 <span class="keywordflow">if</span> ( err.isEmpty() ) <a name="l00326"></a>00326 { <a name="l00327"></a>00327 kdDebug(5970) <a name="l00328"></a>00328 << <span class="stringliteral">"KarmStorage::save : wrote "</span> <a name="l00329"></a>00329 << taskview-><a class="code" href="classTaskView.html#1baadc861bc75b2aa06ce7351a03cefd" title="Return the total number if items in the view.">count</a>() << <span class="stringliteral">" tasks to "</span> << _icalfile << endl; <a name="l00330"></a>00330 } <a name="l00331"></a>00331 <span class="keywordflow">else</span> <a name="l00332"></a>00332 { <a name="l00333"></a>00333 kdWarning(5970) << <span class="stringliteral">"KarmStorage::save : "</span> << err << endl; <a name="l00334"></a>00334 } <a name="l00335"></a>00335 <a name="l00336"></a>00336 <span class="keywordflow">return</span> err; <a name="l00337"></a>00337 } <a name="l00338"></a>00338 <a name="l00339"></a>00339 QString KarmStorage::writeTaskAsTodo(<a class="code" href="classTask.html" title="A class representing a task.">Task</a>* task, <span class="keyword">const</span> <span class="keywordtype">int</span> level, <a name="l00340"></a>00340 QPtrStack< KCal::Todo >& parents ) <a name="l00341"></a>00341 { <a name="l00342"></a>00342 QString err; <a name="l00343"></a>00343 KCal::Todo* todo; <a name="l00344"></a>00344 <a name="l00345"></a>00345 todo = _calendar->todo(task-><a class="code" href="classTask.html#9a822ba9744f31d2e2bc92c74b757ac2" title="Return unique iCalendar Todo ID for this task.">uid</a>()); <a name="l00346"></a>00346 <span class="keywordflow">if</span> ( !todo ) <a name="l00347"></a>00347 { <a name="l00348"></a>00348 kdDebug(5970) << <span class="stringliteral">"Could not get todo from calendar"</span> << endl; <a name="l00349"></a>00349 <span class="keywordflow">return</span> <span class="stringliteral">"Could not get todo from calendar"</span>; <a name="l00350"></a>00350 } <a name="l00351"></a>00351 task-><a class="code" href="classTask.html#fe2427b39575f149d4064d4537b61a87" title="Load the todo passed in with this tasks info.">asTodo</a>(todo); <a name="l00352"></a>00352 <span class="keywordflow">if</span> ( !parents.isEmpty() ) todo->setRelatedTo( parents.top() ); <a name="l00353"></a>00353 parents.push( todo ); <a name="l00354"></a>00354 <a name="l00355"></a>00355 <span class="keywordflow">for</span> ( <a class="code" href="classTask.html" title="A class representing a task.">Task</a>* nextTask = task-><a class="code" href="classTask.html#aaedcc7fa646b15e0451a638ed3fdf63" title="return parent Task or null in case of TaskView.">firstChild</a>(); nextTask; <a name="l00356"></a>00356 nextTask = nextTask-><a class="code" href="classTask.html#a7c59fd2c4318c9eac3bf10fb0201422">nextSibling</a>() ) <a name="l00357"></a>00357 { <a name="l00358"></a>00358 err = writeTaskAsTodo(nextTask, level+1, parents ); <a name="l00359"></a>00359 } <a name="l00360"></a>00360 <a name="l00361"></a>00361 parents.pop(); <a name="l00362"></a>00362 <span class="keywordflow">return</span> err; <a name="l00363"></a>00363 } <a name="l00364"></a>00364 <a name="l00365"></a><a class="code" href="classKarmStorage.html#506bee62614f3e59f7eae9466876f2bc">00365</a> <span class="keywordtype">bool</span> <a class="code" href="classKarmStorage.html#506bee62614f3e59f7eae9466876f2bc" title="Check if the iCalendar file currently loaded has any Todos in it.">KarmStorage::isEmpty</a>() <a name="l00366"></a>00366 { <a name="l00367"></a>00367 KCal::Todo::List todoList; <a name="l00368"></a>00368 <a name="l00369"></a>00369 todoList = _calendar->rawTodos(); <a name="l00370"></a>00370 <span class="keywordflow">return</span> todoList.empty(); <a name="l00371"></a>00371 } <a name="l00372"></a>00372 <a name="l00373"></a><a class="code" href="classKarmStorage.html#6661913d2f9ff26a7d400890b291b73b">00373</a> <span class="keywordtype">bool</span> <a class="code" href="classKarmStorage.html#6661913d2f9ff26a7d400890b291b73b" title="Check if iCalendar file name in the preferences has changed since the last call to...">KarmStorage::isNewStorage</a>(<span class="keyword">const</span> <a class="code" href="classPreferences.html" title="Provide an interface to the configuration options for the program.">Preferences</a>* preferences)<span class="keyword"> const</span> <a name="l00374"></a>00374 <span class="keyword"></span>{ <a name="l00375"></a>00375 <span class="keywordflow">if</span> ( !_icalfile.isNull() ) <span class="keywordflow">return</span> preferences-><a class="code" href="classPreferences.html#c3effde4c28843fd40d2ca8622fb1517">iCalFile</a>() != _icalfile; <a name="l00376"></a>00376 <span class="keywordflow">else</span> <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00377"></a>00377 } <a name="l00378"></a>00378 <a name="l00379"></a>00379 <span class="comment">//----------------------------------------------------------------------------</span> <a name="l00380"></a>00380 <span class="comment">// Routines that handle legacy flat file format.</span> <a name="l00381"></a>00381 <span class="comment">// These only stored total and session times.</span> <a name="l00382"></a>00382 <span class="comment">//</span> <a name="l00383"></a>00383 <a name="l00384"></a><a class="code" href="classKarmStorage.html#31314be2d906119dfba7111b18b7b17b">00384</a> QString <a class="code" href="classKarmStorage.html#31314be2d906119dfba7111b18b7b17b" title="Read tasks and their total times from a text file (legacy storage).">KarmStorage::loadFromFlatFile</a>(<a class="code" href="classTaskView.html" title="Container and interface for the tasks.">TaskView</a>* taskview, <a name="l00385"></a>00385 <span class="keyword">const</span> QString& filename) <a name="l00386"></a>00386 { <a name="l00387"></a>00387 QString err; <a name="l00388"></a>00388 <a name="l00389"></a>00389 kdDebug(5970) <a name="l00390"></a>00390 << <span class="stringliteral">"KarmStorage::loadFromFlatFile: "</span> << filename << endl; <a name="l00391"></a>00391 <a name="l00392"></a>00392 QFile f(filename); <a name="l00393"></a>00393 <span class="keywordflow">if</span>( !f.exists() ) <a name="l00394"></a>00394 err = i18n(<span class="stringliteral">"File \"%1\" not found."</span>).arg(filename); <a name="l00395"></a>00395 <a name="l00396"></a>00396 <span class="keywordflow">if</span> (!err) <a name="l00397"></a>00397 { <a name="l00398"></a>00398 <span class="keywordflow">if</span>( !f.open( IO_ReadOnly ) ) <a name="l00399"></a>00399 err = i18n(<span class="stringliteral">"Could not open \"%1\"."</span>).arg(filename); <a name="l00400"></a>00400 } <a name="l00401"></a>00401 <a name="l00402"></a>00402 <span class="keywordflow">if</span> (!err) <a name="l00403"></a>00403 { <a name="l00404"></a>00404 <a name="l00405"></a>00405 QString line; <a name="l00406"></a>00406 <a name="l00407"></a>00407 QPtrStack<Task> stack; <a name="l00408"></a>00408 <a class="code" href="classTask.html" title="A class representing a task.">Task</a> *task; <a name="l00409"></a>00409 <a name="l00410"></a>00410 QTextStream stream(&f); <a name="l00411"></a>00411 <a name="l00412"></a>00412 <span class="keywordflow">while</span>( !stream.atEnd() ) { <a name="l00413"></a>00413 <span class="comment">// lukas: this breaks for non-latin1 chars!!!</span> <a name="l00414"></a>00414 <span class="comment">// if ( file.readLine( line, T_LINESIZE ) == 0 )</span> <a name="l00415"></a>00415 <span class="comment">// break;</span> <a name="l00416"></a>00416 <a name="l00417"></a>00417 line = stream.readLine(); <a name="l00418"></a>00418 kdDebug(5970) << <span class="stringliteral">"DEBUG: line: "</span> << line << <span class="stringliteral">"\n"</span>; <a name="l00419"></a>00419 <a name="l00420"></a>00420 <span class="keywordflow">if</span> (line.isNull()) <a name="l00421"></a>00421 <span class="keywordflow">break</span>; <a name="l00422"></a>00422 <a name="l00423"></a>00423 <span class="keywordtype">long</span> minutes; <a name="l00424"></a>00424 <span class="keywordtype">int</span> level; <a name="l00425"></a>00425 QString name; <a name="l00426"></a>00426 DesktopList desktopList; <a name="l00427"></a>00427 <span class="keywordflow">if</span> (!parseLine(line, &minutes, &name, &level, &desktopList)) <a name="l00428"></a>00428 <span class="keywordflow">continue</span>; <a name="l00429"></a>00429 <a name="l00430"></a>00430 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> stackLevel = stack.count(); <a name="l00431"></a>00431 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = level; i<=stackLevel ; i++) { <a name="l00432"></a>00432 stack.pop(); <a name="l00433"></a>00433 } <a name="l00434"></a>00434 <a name="l00435"></a>00435 <span class="keywordflow">if</span> (level == 1) { <a name="l00436"></a>00436 kdDebug(5970) << <span class="stringliteral">"KarmStorage::loadFromFlatFile - toplevel task: "</span> <a name="l00437"></a>00437 << name << <span class="stringliteral">" min: "</span> << minutes << <span class="stringliteral">"\n"</span>; <a name="l00438"></a>00438 task = <span class="keyword">new</span> <a class="code" href="classTask.html" title="A class representing a task.">Task</a>(name, minutes, 0, desktopList, taskview); <a name="l00439"></a>00439 task-><a class="code" href="classTask.html#f52bbd875ab08da52edee8769ff3fb40" title="Set unique id for the task.">setUid</a>(<a class="code" href="classKarmStorage.html#aea5b0757f27a32779ca56ba7abdb75a" title="Add this task from iCalendar file.">addTask</a>(task, 0)); <a name="l00440"></a>00440 } <a name="l00441"></a>00441 <span class="keywordflow">else</span> { <a name="l00442"></a>00442 <a class="code" href="classTask.html" title="A class representing a task.">Task</a> *parent = stack.top(); <a name="l00443"></a>00443 kdDebug(5970) << <span class="stringliteral">"KarmStorage::loadFromFlatFile - task: "</span> << name <a name="l00444"></a>00444 << <span class="stringliteral">" min: "</span> << minutes << <span class="stringliteral">" parent"</span> << parent-><a class="code" href="classTask.html#e18d2ce750c810aa14033d6c1df99e0d" title="returns the name of this task.">name</a>() << <span class="stringliteral">"\n"</span>; <a name="l00445"></a>00445 task = <span class="keyword">new</span> <a class="code" href="classTask.html" title="A class representing a task.">Task</a>(name, minutes, 0, desktopList, parent); <a name="l00446"></a>00446 <a name="l00447"></a>00447 task-><a class="code" href="classTask.html#f52bbd875ab08da52edee8769ff3fb40" title="Set unique id for the task.">setUid</a>(<a class="code" href="classKarmStorage.html#aea5b0757f27a32779ca56ba7abdb75a" title="Add this task from iCalendar file.">addTask</a>(task, parent)); <a name="l00448"></a>00448 <a name="l00449"></a>00449 <span class="comment">// Legacy File Format (!):</span> <a name="l00450"></a>00450 parent-><a class="code" href="classTask.html#1be2a2bf84f843d70b33be28c10a4025" title="Add minutes to time and session time, and write to storage.">changeTimes</a>(0, -minutes); <a name="l00451"></a>00451 taskview->setRootIsDecorated(<span class="keyword">true</span>); <a name="l00452"></a>00452 parent->setOpen(<span class="keyword">true</span>); <a name="l00453"></a>00453 } <a name="l00454"></a>00454 <span class="keywordflow">if</span> (!task-><a class="code" href="classTask.html#9a822ba9744f31d2e2bc92c74b757ac2" title="Return unique iCalendar Todo ID for this task.">uid</a>().isNull()) <a name="l00455"></a>00455 stack.push(task); <a name="l00456"></a>00456 <span class="keywordflow">else</span> <a name="l00457"></a>00457 <span class="keyword">delete</span> task; <a name="l00458"></a>00458 } <a name="l00459"></a>00459 <a name="l00460"></a>00460 f.close(); <a name="l00461"></a>00461 <a name="l00462"></a>00462 } <a name="l00463"></a>00463 <a name="l00464"></a>00464 <span class="keywordflow">return</span> err; <a name="l00465"></a>00465 } <a name="l00466"></a>00466 <a name="l00467"></a><a class="code" href="classKarmStorage.html#46b934dd0e1694f0f39e3e62a479638c">00467</a> QString <a class="code" href="classKarmStorage.html#46b934dd0e1694f0f39e3e62a479638c" title="Reads tasks and their total times from text file (legacy).">KarmStorage::loadFromFlatFileCumulative</a>(<a class="code" href="classTaskView.html" title="Container and interface for the tasks.">TaskView</a>* taskview, <a name="l00468"></a>00468 <span class="keyword">const</span> QString& filename) <a name="l00469"></a>00469 { <a name="l00470"></a>00470 QString err = <a class="code" href="classKarmStorage.html#31314be2d906119dfba7111b18b7b17b" title="Read tasks and their total times from a text file (legacy storage).">loadFromFlatFile</a>(taskview, filename); <a name="l00471"></a>00471 <span class="keywordflow">if</span> (!err) <a name="l00472"></a>00472 { <a name="l00473"></a>00473 <span class="keywordflow">for</span> (<a class="code" href="classTask.html" title="A class representing a task.">Task</a>* task = taskview-><a class="code" href="classTaskView.html#19f03096ab651f975fec50e4be6aef49" title="Return the first item in the view, cast to a Task pointer.">first_child</a>(); task; <a name="l00474"></a>00474 task = task-><a class="code" href="classTask.html#a7c59fd2c4318c9eac3bf10fb0201422">nextSibling</a>()) <a name="l00475"></a>00475 { <a name="l00476"></a>00476 adjustFromLegacyFileFormat(task); <a name="l00477"></a>00477 } <a name="l00478"></a>00478 } <a name="l00479"></a>00479 <span class="keywordflow">return</span> err; <a name="l00480"></a>00480 } <a name="l00481"></a>00481 <a name="l00482"></a>00482 <span class="keywordtype">bool</span> KarmStorage::parseLine(QString line, <span class="keywordtype">long</span> *time, QString *name, <a name="l00483"></a>00483 <span class="keywordtype">int</span> *level, DesktopList* desktopList) <a name="l00484"></a>00484 { <a name="l00485"></a>00485 <span class="keywordflow">if</span> (line.find(<span class="charliteral">'#'</span>) == 0) { <a name="l00486"></a>00486 <span class="comment">// A comment line</span> <a name="l00487"></a>00487 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00488"></a>00488 } <a name="l00489"></a>00489 <a name="l00490"></a>00490 <span class="keywordtype">int</span> index = line.find(<span class="charliteral">'\t'</span>); <a name="l00491"></a>00491 <span class="keywordflow">if</span> (index == -1) { <a name="l00492"></a>00492 <span class="comment">// This doesn't seem like a valid record</span> <a name="l00493"></a>00493 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00494"></a>00494 } <a name="l00495"></a>00495 <a name="l00496"></a>00496 QString levelStr = line.left(index); <a name="l00497"></a>00497 QString rest = line.remove(0,index+1); <a name="l00498"></a>00498 <a name="l00499"></a>00499 index = rest.find(<span class="charliteral">'\t'</span>); <a name="l00500"></a>00500 <span class="keywordflow">if</span> (index == -1) { <a name="l00501"></a>00501 <span class="comment">// This doesn't seem like a valid record</span> <a name="l00502"></a>00502 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00503"></a>00503 } <a name="l00504"></a>00504 <a name="l00505"></a>00505 QString timeStr = rest.left(index); <a name="l00506"></a>00506 rest = rest.remove(0,index+1); <a name="l00507"></a>00507 <a name="l00508"></a>00508 <span class="keywordtype">bool</span> ok; <a name="l00509"></a>00509 <a name="l00510"></a>00510 index = rest.find(<span class="charliteral">'\t'</span>); <span class="comment">// check for optional desktops string</span> <a name="l00511"></a>00511 <span class="keywordflow">if</span> (index >= 0) { <a name="l00512"></a>00512 *name = rest.left(index); <a name="l00513"></a>00513 QString deskLine = rest.remove(0,index+1); <a name="l00514"></a>00514 <a name="l00515"></a>00515 <span class="comment">// now transform the ds string (e.g. "3", or "1,4,5") into</span> <a name="l00516"></a>00516 <span class="comment">// an DesktopList</span> <a name="l00517"></a>00517 QString ds; <a name="l00518"></a>00518 <span class="keywordtype">int</span> d; <a name="l00519"></a>00519 <span class="keywordtype">int</span> commaIdx = deskLine.find(<span class="charliteral">','</span>); <a name="l00520"></a>00520 <span class="keywordflow">while</span> (commaIdx >= 0) { <a name="l00521"></a>00521 ds = deskLine.left(commaIdx); <a name="l00522"></a>00522 d = ds.toInt(&ok); <a name="l00523"></a>00523 <span class="keywordflow">if</span> (!ok) <a name="l00524"></a>00524 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00525"></a>00525 <a name="l00526"></a>00526 desktopList->push_back(d); <a name="l00527"></a>00527 deskLine.remove(0,commaIdx+1); <a name="l00528"></a>00528 commaIdx = deskLine.find(<span class="charliteral">','</span>); <a name="l00529"></a>00529 } <a name="l00530"></a>00530 <a name="l00531"></a>00531 d = deskLine.toInt(&ok); <a name="l00532"></a>00532 <a name="l00533"></a>00533 <span class="keywordflow">if</span> (!ok) <a name="l00534"></a>00534 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00535"></a>00535 <a name="l00536"></a>00536 desktopList->push_back(d); <a name="l00537"></a>00537 } <a name="l00538"></a>00538 <span class="keywordflow">else</span> { <a name="l00539"></a>00539 *name = rest.remove(0,index+1); <a name="l00540"></a>00540 } <a name="l00541"></a>00541 <a name="l00542"></a>00542 *time = timeStr.toLong(&ok); <a name="l00543"></a>00543 <a name="l00544"></a>00544 <span class="keywordflow">if</span> (!ok) { <a name="l00545"></a>00545 <span class="comment">// the time field was not a number</span> <a name="l00546"></a>00546 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00547"></a>00547 } <a name="l00548"></a>00548 *level = levelStr.toInt(&ok); <a name="l00549"></a>00549 <span class="keywordflow">if</span> (!ok) { <a name="l00550"></a>00550 <span class="comment">// the time field was not a number</span> <a name="l00551"></a>00551 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00552"></a>00552 } <a name="l00553"></a>00553 <a name="l00554"></a>00554 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00555"></a>00555 } <a name="l00556"></a>00556 <a name="l00557"></a>00557 <span class="keywordtype">void</span> KarmStorage::adjustFromLegacyFileFormat(<a class="code" href="classTask.html" title="A class representing a task.">Task</a>* task) <a name="l00558"></a>00558 { <a name="l00559"></a>00559 <span class="comment">// unless the parent is the listView</span> <a name="l00560"></a>00560 <span class="keywordflow">if</span> ( task-><a class="code" href="classTask.html#f7b39711f7479ea91734f690134bbc1c">parent</a>() ) <a name="l00561"></a>00561 task-><a class="code" href="classTask.html#f7b39711f7479ea91734f690134bbc1c">parent</a>()-><a class="code" href="classTask.html#1be2a2bf84f843d70b33be28c10a4025" title="Add minutes to time and session time, and write to storage.">changeTimes</a>(-task-><a class="code" href="classTask.html#8234e6992334d4e80388e4918e9948d1">sessionTime</a>(), -task-><a class="code" href="classTask.html#623e46356eb7d8e93ac827130c0d08a5">time</a>()); <a name="l00562"></a>00562 <a name="l00563"></a>00563 <span class="comment">// traverse depth first -</span> <a name="l00564"></a>00564 <span class="comment">// as soon as we're in a leaf, we'll substract it's time from the parent</span> <a name="l00565"></a>00565 <span class="comment">// then, while descending back we'll do the same for each node untill</span> <a name="l00566"></a>00566 <span class="comment">// we reach the root</span> <a name="l00567"></a>00567 <span class="keywordflow">for</span> ( <a class="code" href="classTask.html" title="A class representing a task.">Task</a>* subtask = task-><a class="code" href="classTask.html#aaedcc7fa646b15e0451a638ed3fdf63" title="return parent Task or null in case of TaskView.">firstChild</a>(); subtask; <a name="l00568"></a>00568 subtask = subtask-><a class="code" href="classTask.html#a7c59fd2c4318c9eac3bf10fb0201422">nextSibling</a>() ) <a name="l00569"></a>00569 adjustFromLegacyFileFormat(subtask); <a name="l00570"></a>00570 } <a name="l00571"></a>00571 <a name="l00572"></a>00572 <span class="comment">//----------------------------------------------------------------------------</span> <a name="l00573"></a>00573 <span class="comment">// Routines that handle Comma-Separated Values export file format.</span> <a name="l00574"></a>00574 <span class="comment">//</span> <a name="l00575"></a>00575 QString KarmStorage::exportcsvFile( <a class="code" href="classTaskView.html" title="Container and interface for the tasks.">TaskView</a> *taskview, <a name="l00576"></a>00576 <span class="keyword">const</span> <a class="code" href="classReportCriteria.html" title="Stores entries from export dialog.">ReportCriteria</a> &rc ) <a name="l00577"></a>00577 { <a name="l00578"></a>00578 QString delim = rc.<a class="code" href="classReportCriteria.html#a31ef3532d513d3585afdafc2ab1ebcc" title="The delimiter to use when outputting comma-seperated value reports.">delimiter</a>; <a name="l00579"></a>00579 QString dquote = rc.<a class="code" href="classReportCriteria.html#c3f9f255c22564d464f4e745a9f76a56" title="The quote to use for text fields when outputting comma-seperated reports.">quote</a>; <a name="l00580"></a>00580 QString double_dquote = dquote + dquote; <a name="l00581"></a>00581 <span class="keywordtype">bool</span> to_quote = <span class="keyword">true</span>; <a name="l00582"></a>00582 <a name="l00583"></a>00583 QString err; <a name="l00584"></a>00584 <a class="code" href="classTask.html" title="A class representing a task.">Task</a>* task; <a name="l00585"></a>00585 <span class="keywordtype">int</span> maxdepth=0; <a name="l00586"></a>00586 <a name="l00587"></a>00587 kdDebug(5970) <a name="l00588"></a>00588 << <span class="stringliteral">"KarmStorage::exportcsvFile: "</span> << rc.<a class="code" href="classReportCriteria.html#7ed11ea6932032297409c5f831a4dd10" title="For reports that write to a file, the filename to write to.">url</a> << endl; <a name="l00589"></a>00589 <a name="l00590"></a>00590 QString title = i18n(<span class="stringliteral">"Export Progress"</span>); <a name="l00591"></a>00591 KProgressDialog dialog( taskview, 0, title ); <a name="l00592"></a>00592 dialog.setAutoClose( <span class="keyword">true</span> ); <a name="l00593"></a>00593 dialog.setAllowCancel( <span class="keyword">true</span> ); <a name="l00594"></a>00594 dialog.progressBar()->setTotalSteps( 2 * taskview-><a class="code" href="classTaskView.html#1baadc861bc75b2aa06ce7351a03cefd" title="Return the total number if items in the view.">count</a>() ); <a name="l00595"></a>00595 <a name="l00596"></a>00596 <span class="comment">// The default dialog was not displaying all the text in the title bar.</span> <a name="l00597"></a>00597 <span class="keywordtype">int</span> width = taskview->fontMetrics().width(title) * 3; <a name="l00598"></a>00598 QSize dialogsize; <a name="l00599"></a>00599 dialogsize.setWidth(width); <a name="l00600"></a>00600 dialog.setInitialSize( dialogsize, <span class="keyword">true</span> ); <a name="l00601"></a>00601 <a name="l00602"></a>00602 <span class="keywordflow">if</span> ( taskview-><a class="code" href="classTaskView.html#1baadc861bc75b2aa06ce7351a03cefd" title="Return the total number if items in the view.">count</a>() > 1 ) dialog.show(); <a name="l00603"></a>00603 <a name="l00604"></a>00604 QString retval; <a name="l00605"></a>00605 <a name="l00606"></a>00606 <span class="comment">// Find max task depth</span> <a name="l00607"></a>00607 <span class="keywordtype">int</span> tasknr = 0; <a name="l00608"></a>00608 <span class="keywordflow">while</span> ( tasknr < taskview->count() && !dialog.wasCancelled() ) <a name="l00609"></a>00609 { <a name="l00610"></a>00610 dialog.progressBar()->advance( 1 ); <a name="l00611"></a>00611 <span class="keywordflow">if</span> ( tasknr % 15 == 0 ) kapp->processEvents(); <span class="comment">// repainting is slow</span> <a name="l00612"></a>00612 <span class="keywordflow">if</span> ( taskview-><a class="code" href="classTaskView.html#9050454887e14a5c62725e23f242639d" title="Return the i&#39;th item (zero-based), cast to a Task pointer.">item_at_index</a>(tasknr)->depth() > maxdepth ) <a name="l00613"></a>00613 maxdepth = taskview-><a class="code" href="classTaskView.html#9050454887e14a5c62725e23f242639d" title="Return the i&#39;th item (zero-based), cast to a Task pointer.">item_at_index</a>(tasknr)->depth(); <a name="l00614"></a>00614 tasknr++; <a name="l00615"></a>00615 } <a name="l00616"></a>00616 <a name="l00617"></a>00617 <span class="comment">// Export to file</span> <a name="l00618"></a>00618 tasknr = 0; <a name="l00619"></a>00619 <span class="keywordflow">while</span> ( tasknr < taskview->count() && !dialog.wasCancelled() ) <a name="l00620"></a>00620 { <a name="l00621"></a>00621 task = taskview-><a class="code" href="classTaskView.html#9050454887e14a5c62725e23f242639d" title="Return the i&#39;th item (zero-based), cast to a Task pointer.">item_at_index</a>( tasknr ); <a name="l00622"></a>00622 dialog.progressBar()->advance( 1 ); <a name="l00623"></a>00623 <span class="keywordflow">if</span> ( tasknr % 15 == 0 ) kapp->processEvents(); <a name="l00624"></a>00624 <a name="l00625"></a>00625 <span class="comment">// indent the task in the csv-file:</span> <a name="l00626"></a>00626 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0; i < task->depth(); ++i ) retval += delim; <a name="l00627"></a>00627 <a name="l00628"></a>00628 <span class="comment">/*</span> <a name="l00629"></a>00629 <span class="comment"> // CSV compliance</span> <a name="l00630"></a>00630 <span class="comment"> // Surround the field with quotes if the field contains</span> <a name="l00631"></a>00631 <span class="comment"> // a comma (delim) or a double quote</span> <a name="l00632"></a>00632 <span class="comment"> if (task->name().contains(delim) || task->name().contains(dquote))</span> <a name="l00633"></a>00633 <span class="comment"> to_quote = true;</span> <a name="l00634"></a>00634 <span class="comment"> else</span> <a name="l00635"></a>00635 <span class="comment"> to_quote = false;</span> <a name="l00636"></a>00636 <span class="comment"> */</span> <a name="l00637"></a>00637 to_quote = <span class="keyword">true</span>; <a name="l00638"></a>00638 <a name="l00639"></a>00639 <span class="keywordflow">if</span> (to_quote) <a name="l00640"></a>00640 retval += dquote; <a name="l00641"></a>00641 <a name="l00642"></a>00642 <span class="comment">// Double quotes replaced by a pair of consecutive double quotes</span> <a name="l00643"></a>00643 retval += task-><a class="code" href="classTask.html#e18d2ce750c810aa14033d6c1df99e0d" title="returns the name of this task.">name</a>().replace( dquote, double_dquote ); <a name="l00644"></a>00644 <a name="l00645"></a>00645 <span class="keywordflow">if</span> (to_quote) <a name="l00646"></a>00646 retval += dquote; <a name="l00647"></a>00647 <a name="l00648"></a>00648 <span class="comment">// maybe other tasks are more indented, so to align the columns:</span> <a name="l00649"></a>00649 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < maxdepth - task->depth(); ++i ) retval += delim; <a name="l00650"></a>00650 <a name="l00651"></a>00651 retval += delim + formatTime( task-><a class="code" href="classTask.html#8234e6992334d4e80388e4918e9948d1">sessionTime</a>(), <a name="l00652"></a>00652 rc.<a class="code" href="classReportCriteria.html#0a40fd5022cc4bfde6c2f2b3f38d2178" title="True if the durations should be output in decimal hours.">decimalMinutes</a> ) <a name="l00653"></a>00653 + delim + formatTime( task-><a class="code" href="classTask.html#623e46356eb7d8e93ac827130c0d08a5">time</a>(), <a name="l00654"></a>00654 rc.<a class="code" href="classReportCriteria.html#0a40fd5022cc4bfde6c2f2b3f38d2178" title="True if the durations should be output in decimal hours.">decimalMinutes</a> ) <a name="l00655"></a>00655 + delim + formatTime( task-><a class="code" href="classTask.html#48b06f2ba66c3cfb369427c810688610">totalSessionTime</a>(), <a name="l00656"></a>00656 rc.<a class="code" href="classReportCriteria.html#0a40fd5022cc4bfde6c2f2b3f38d2178" title="True if the durations should be output in decimal hours.">decimalMinutes</a> ) <a name="l00657"></a>00657 + delim + formatTime( task-><a class="code" href="classTask.html#e36175fb3aebe274f2938b680757f23a">totalTime</a>(), <a name="l00658"></a>00658 rc.<a class="code" href="classReportCriteria.html#0a40fd5022cc4bfde6c2f2b3f38d2178" title="True if the durations should be output in decimal hours.">decimalMinutes</a> ) <a name="l00659"></a>00659 + <span class="stringliteral">"\n"</span>; <a name="l00660"></a>00660 tasknr++; <a name="l00661"></a>00661 } <a name="l00662"></a>00662 <a name="l00663"></a>00663 <span class="comment">// save, either locally or remote</span> <a name="l00664"></a>00664 <span class="keywordflow">if</span> ((rc.<a class="code" href="classReportCriteria.html#7ed11ea6932032297409c5f831a4dd10" title="For reports that write to a file, the filename to write to.">url</a>.isLocalFile()) || (!rc.<a class="code" href="classReportCriteria.html#7ed11ea6932032297409c5f831a4dd10" title="For reports that write to a file, the filename to write to.">url</a>.url().contains(<span class="stringliteral">"/"</span>))) <a name="l00665"></a>00665 { <a name="l00666"></a>00666 QString filename=rc.<a class="code" href="classReportCriteria.html#7ed11ea6932032297409c5f831a4dd10" title="For reports that write to a file, the filename to write to.">url</a>.path(); <a name="l00667"></a>00667 <span class="keywordflow">if</span> (filename.isEmpty()) filename=rc.<a class="code" href="classReportCriteria.html#7ed11ea6932032297409c5f831a4dd10" title="For reports that write to a file, the filename to write to.">url</a>.url(); <a name="l00668"></a>00668 QFile f( filename ); <a name="l00669"></a>00669 <span class="keywordflow">if</span>( !f.open( IO_WriteOnly ) ) { <a name="l00670"></a>00670 err = i18n( <span class="stringliteral">"Could not open \"%1\"."</span> ).arg( filename ); <a name="l00671"></a>00671 } <a name="l00672"></a>00672 <span class="keywordflow">if</span> (!err) <a name="l00673"></a>00673 { <a name="l00674"></a>00674 QTextStream stream(&f); <a name="l00675"></a>00675 <span class="comment">// Export to file</span> <a name="l00676"></a>00676 stream << retval; <a name="l00677"></a>00677 f.close(); <a name="l00678"></a>00678 } <a name="l00679"></a>00679 } <a name="l00680"></a>00680 <span class="keywordflow">else</span> <span class="comment">// use remote file</span> <a name="l00681"></a>00681 { <a name="l00682"></a>00682 KTempFile tmpFile; <a name="l00683"></a>00683 <span class="keywordflow">if</span> ( tmpFile.status() != 0 ) err = QString::fromLatin1( <span class="stringliteral">"Unable to get temporary file"</span> ); <a name="l00684"></a>00684 <span class="keywordflow">else</span> <a name="l00685"></a>00685 { <a name="l00686"></a>00686 QTextStream *stream=tmpFile.textStream(); <a name="l00687"></a>00687 *stream << retval; <a name="l00688"></a>00688 tmpFile.close(); <a name="l00689"></a>00689 <span class="keywordflow">if</span> (!KIO::NetAccess::upload( tmpFile.name(), rc.<a class="code" href="classReportCriteria.html#7ed11ea6932032297409c5f831a4dd10" title="For reports that write to a file, the filename to write to.">url</a>, 0 )) err=QString::fromLatin1(<span class="stringliteral">"Could not upload"</span>); <a name="l00690"></a>00690 } <a name="l00691"></a>00691 } <a name="l00692"></a>00692 <a name="l00693"></a>00693 <span class="keywordflow">return</span> err; <a name="l00694"></a>00694 } <a name="l00695"></a>00695 <a name="l00696"></a>00696 <span class="comment">//----------------------------------------------------------------------------</span> <a name="l00697"></a>00697 <span class="comment">// Routines that handle logging KArm history</span> <a name="l00698"></a>00698 <span class="comment">//</span> <a name="l00699"></a>00699 <a name="l00700"></a>00700 <span class="comment">//</span> <a name="l00701"></a>00701 <span class="comment">// public routines:</span> <a name="l00702"></a>00702 <span class="comment">//</span> <a name="l00703"></a>00703 <a name="l00704"></a><a class="code" href="classKarmStorage.html#aea5b0757f27a32779ca56ba7abdb75a">00704</a> QString <a class="code" href="classKarmStorage.html#aea5b0757f27a32779ca56ba7abdb75a" title="Add this task from iCalendar file.">KarmStorage::addTask</a>(<span class="keyword">const</span> <a class="code" href="classTask.html" title="A class representing a task.">Task</a>* task, <span class="keyword">const</span> <a class="code" href="classTask.html" title="A class representing a task.">Task</a>* parent) <a name="l00705"></a>00705 { <a name="l00706"></a>00706 KCal::Todo* todo; <a name="l00707"></a>00707 QString uid; <a name="l00708"></a>00708 <a name="l00709"></a>00709 todo = <span class="keyword">new</span> KCal::Todo(); <a name="l00710"></a>00710 <span class="keywordflow">if</span> ( _calendar->addTodo( todo ) ) <a name="l00711"></a>00711 { <a name="l00712"></a>00712 task-><a class="code" href="classTask.html#fe2427b39575f149d4064d4537b61a87" title="Load the todo passed in with this tasks info.">asTodo</a>( todo ); <a name="l00713"></a>00713 <span class="keywordflow">if</span> (parent) <a name="l00714"></a>00714 todo->setRelatedTo(_calendar->todo(parent-><a class="code" href="classTask.html#9a822ba9744f31d2e2bc92c74b757ac2" title="Return unique iCalendar Todo ID for this task.">uid</a>())); <a name="l00715"></a>00715 uid = todo->uid(); <a name="l00716"></a>00716 } <a name="l00717"></a>00717 <span class="keywordflow">else</span> <a name="l00718"></a>00718 { <a name="l00719"></a>00719 <span class="comment">// Most likely a lock could not be pulled, although there are other</span> <a name="l00720"></a>00720 <span class="comment">// possiblities (like a really confused resource manager).</span> <a name="l00721"></a>00721 uid = <span class="stringliteral">""</span>; <a name="l00722"></a>00722 } <a name="l00723"></a>00723 <a name="l00724"></a>00724 <span class="keywordflow">return</span> uid; <a name="l00725"></a>00725 } <a name="l00726"></a>00726 <a name="l00727"></a><a class="code" href="classKarmStorage.html#602128e1797fa4b69cf86ae2b5b57705">00727</a> <span class="keywordtype">bool</span> <a class="code" href="classKarmStorage.html#602128e1797fa4b69cf86ae2b5b57705" title="Remove this task from iCalendar file.">KarmStorage::removeTask</a>(<a class="code" href="classTask.html" title="A class representing a task.">Task</a>* task) <a name="l00728"></a>00728 { <a name="l00729"></a>00729 <a name="l00730"></a>00730 <span class="comment">// delete history</span> <a name="l00731"></a>00731 KCal::Event::List eventList = _calendar->rawEvents(); <a name="l00732"></a>00732 <span class="keywordflow">for</span>(KCal::Event::List::iterator i = eventList.begin(); <a name="l00733"></a>00733 i != eventList.end(); <a name="l00734"></a>00734 ++i) <a name="l00735"></a>00735 { <a name="l00736"></a>00736 <span class="comment">//kdDebug(5970) << "KarmStorage::removeTask: "</span> <a name="l00737"></a>00737 <span class="comment">// << (*i)->uid() << " - relatedToUid() "</span> <a name="l00738"></a>00738 <span class="comment">// << (*i)->relatedToUid()</span> <a name="l00739"></a>00739 <span class="comment">// << ", relatedTo() = " << (*i)->relatedTo() <<endl;</span> <a name="l00740"></a>00740 <span class="keywordflow">if</span> ( (*i)->relatedToUid() == task-><a class="code" href="classTask.html#9a822ba9744f31d2e2bc92c74b757ac2" title="Return unique iCalendar Todo ID for this task.">uid</a>() <a name="l00741"></a>00741 || ( (*i)->relatedTo() <a name="l00742"></a>00742 && (*i)->relatedTo()->uid() == task-><a class="code" href="classTask.html#9a822ba9744f31d2e2bc92c74b757ac2" title="Return unique iCalendar Todo ID for this task.">uid</a>())) <a name="l00743"></a>00743 { <a name="l00744"></a>00744 _calendar->deleteEvent(*i); <a name="l00745"></a>00745 } <a name="l00746"></a>00746 } <a name="l00747"></a>00747 <a name="l00748"></a>00748 <span class="comment">// delete todo</span> <a name="l00749"></a>00749 KCal::Todo *todo = _calendar->todo(task-><a class="code" href="classTask.html#9a822ba9744f31d2e2bc92c74b757ac2" title="Return unique iCalendar Todo ID for this task.">uid</a>()); <a name="l00750"></a>00750 _calendar->deleteTodo(todo); <a name="l00751"></a>00751 <a name="l00752"></a>00752 <span class="comment">// Save entire file</span> <a name="l00753"></a>00753 saveCalendar(); <a name="l00754"></a>00754 <a name="l00755"></a>00755 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00756"></a>00756 } <a name="l00757"></a>00757 <a name="l00758"></a><a class="code" href="classKarmStorage.html#851699a706f7f2f98333023547908539">00758</a> <span class="keywordtype">void</span> <a class="code" href="classKarmStorage.html#851699a706f7f2f98333023547908539" title="Log a new comment for this task.">KarmStorage::addComment</a>(<span class="keyword">const</span> <a class="code" href="classTask.html" title="A class representing a task.">Task</a>* task, <span class="keyword">const</span> QString& comment) <a name="l00759"></a>00759 { <a name="l00760"></a>00760 <a name="l00761"></a>00761 KCal::Todo* todo; <a name="l00762"></a>00762 <a name="l00763"></a>00763 todo = _calendar->todo(task-><a class="code" href="classTask.html#9a822ba9744f31d2e2bc92c74b757ac2" title="Return unique iCalendar Todo ID for this task.">uid</a>()); <a name="l00764"></a>00764 <a name="l00765"></a>00765 <span class="comment">// Do this to avoid compiler warnings about comment not being used. once we</span> <a name="l00766"></a>00766 <span class="comment">// transition to using the addComment method, we need this second param.</span> <a name="l00767"></a>00767 QString s = comment; <a name="l00768"></a>00768 <a name="l00769"></a>00769 <span class="comment">// TODO: Use libkcal comments</span> <a name="l00770"></a>00770 <span class="comment">// todo->addComment(comment);</span> <a name="l00771"></a>00771 <span class="comment">// temporary</span> <a name="l00772"></a>00772 todo->setDescription(task-><a class="code" href="classTask.html#2a946793a28513235c856bf8766d7dee" title="Retrieve the entire comment for the task.">comment</a>()); <a name="l00773"></a>00773 <a name="l00774"></a>00774 saveCalendar(); <a name="l00775"></a>00775 } <a name="l00776"></a>00776 <a name="l00777"></a>00777 <span class="keywordtype">long</span> KarmStorage::printTaskHistory ( <a name="l00778"></a>00778 <span class="keyword">const</span> <a class="code" href="classTask.html" title="A class representing a task.">Task</a> *task, <a name="l00779"></a>00779 <span class="keyword">const</span> QMap<QString,long> &taskdaytotals, <a name="l00780"></a>00780 QMap<QString,long> &daytotals, <a name="l00781"></a>00781 <span class="keyword">const</span> QDate &from, <a name="l00782"></a>00782 <span class="keyword">const</span> QDate &to, <a name="l00783"></a>00783 <span class="keyword">const</span> <span class="keywordtype">int</span> level, <a name="l00784"></a>00784 vector <QString> &matrix, <a name="l00785"></a>00785 <span class="keyword">const</span> <a class="code" href="classReportCriteria.html" title="Stores entries from export dialog.">ReportCriteria</a> &rc) <a name="l00786"></a>00786 <span class="comment">// to>=from is precondition</span> <a name="l00787"></a>00787 { <a name="l00788"></a>00788 <span class="keywordtype">long</span> ownline=linenr++; <span class="comment">// the how many-th instance of this function is this</span> <a name="l00789"></a>00789 <span class="keywordtype">long</span> colrectot=0; <span class="comment">// colum where to write the task's total recursive time</span> <a name="l00790"></a>00790 vector <QString> cell; <span class="comment">// each line of the matrix is stored in an array of cells, one containing the recursive total</span> <a name="l00791"></a>00791 <span class="keywordtype">long</span> <span class="keyword">add</span>; <span class="comment">// total recursive time of all subtasks</span> <a name="l00792"></a>00792 QString delim = rc.<a class="code" href="classReportCriteria.html#a31ef3532d513d3585afdafc2ab1ebcc" title="The delimiter to use when outputting comma-seperated value reports.">delimiter</a>; <a name="l00793"></a>00793 QString dquote = rc.<a class="code" href="classReportCriteria.html#c3f9f255c22564d464f4e745a9f76a56" title="The quote to use for text fields when outputting comma-seperated reports.">quote</a>; <a name="l00794"></a>00794 QString double_dquote = dquote + dquote; <a name="l00795"></a>00795 <span class="keywordtype">bool</span> to_quote = <span class="keyword">true</span>; <a name="l00796"></a>00796 <a name="l00797"></a>00797 <span class="keyword">const</span> QString cr = QString::fromLatin1(<span class="stringliteral">"\n"</span>); <a name="l00798"></a>00798 QString buf; <a name="l00799"></a>00799 QString daytaskkey, daykey; <a name="l00800"></a>00800 QDate day; <a name="l00801"></a>00801 <span class="keywordtype">long</span> sum; <a name="l00802"></a>00802 <a name="l00803"></a>00803 <span class="keywordflow">if</span> ( !task ) <span class="keywordflow">return</span> 0; <a name="l00804"></a>00804 <a name="l00805"></a>00805 day = from; <a name="l00806"></a>00806 sum = 0; <a name="l00807"></a>00807 <span class="keywordflow">while</span> (day <= to) <a name="l00808"></a>00808 { <a name="l00809"></a>00809 <span class="comment">// write the time in seconds for the given task for the given day to s</span> <a name="l00810"></a>00810 daykey = day.toString(QString::fromLatin1(<span class="stringliteral">"yyyyMMdd"</span>)); <a name="l00811"></a>00811 daytaskkey = QString::fromLatin1(<span class="stringliteral">"%1_%2"</span>) <a name="l00812"></a>00812 .arg(daykey) <a name="l00813"></a>00813 .arg(task-><a class="code" href="classTask.html#9a822ba9744f31d2e2bc92c74b757ac2" title="Return unique iCalendar Todo ID for this task.">uid</a>()); <a name="l00814"></a>00814 <a name="l00815"></a>00815 <span class="keywordflow">if</span> (taskdaytotals.contains(daytaskkey)) <a name="l00816"></a>00816 { <a name="l00817"></a>00817 cell.push_back(QString::fromLatin1(<span class="stringliteral">"%1"</span>) <a name="l00818"></a>00818 .arg(formatTime(taskdaytotals[daytaskkey]/60, rc.<a class="code" href="classReportCriteria.html#0a40fd5022cc4bfde6c2f2b3f38d2178" title="True if the durations should be output in decimal hours.">decimalMinutes</a>))); <a name="l00819"></a>00819 sum += taskdaytotals[daytaskkey]; <span class="comment">// in seconds</span> <a name="l00820"></a>00820 <a name="l00821"></a>00821 <span class="keywordflow">if</span> (daytotals.contains(daykey)) <a name="l00822"></a>00822 daytotals.replace(daykey, daytotals[daykey]+taskdaytotals[daytaskkey]); <a name="l00823"></a>00823 <span class="keywordflow">else</span> <a name="l00824"></a>00824 daytotals.insert(daykey, taskdaytotals[daytaskkey]); <a name="l00825"></a>00825 } <a name="l00826"></a>00826 cell.push_back(delim); <a name="l00827"></a>00827 <a name="l00828"></a>00828 day = day.addDays(1); <a name="l00829"></a>00829 } <a name="l00830"></a>00830 <a name="l00831"></a>00831 <span class="comment">// Total for task</span> <a name="l00832"></a>00832 cell.push_back(QString::fromLatin1(<span class="stringliteral">"%1"</span>).arg(formatTime(sum/60, rc.<a class="code" href="classReportCriteria.html#0a40fd5022cc4bfde6c2f2b3f38d2178" title="True if the durations should be output in decimal hours.">decimalMinutes</a>))); <a name="l00833"></a>00833 <a name="l00834"></a>00834 <span class="comment">// room for the recursive total time (that cannot be calculated now)</span> <a name="l00835"></a>00835 cell.push_back(delim); <a name="l00836"></a>00836 colrectot = cell.size(); <a name="l00837"></a>00837 cell.push_back(<span class="stringliteral">"???"</span>); <a name="l00838"></a>00838 cell.push_back(delim); <a name="l00839"></a>00839 <a name="l00840"></a>00840 <span class="comment">// Task name</span> <a name="l00841"></a>00841 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = level + 1; i > 0; i-- ) cell.push_back(delim); <a name="l00842"></a>00842 <a name="l00843"></a>00843 <span class="comment">/*</span> <a name="l00844"></a>00844 <span class="comment"> // CSV compliance</span> <a name="l00845"></a>00845 <span class="comment"> // Surround the field with quotes if the field contains</span> <a name="l00846"></a>00846 <span class="comment"> // a comma (delim) or a double quote</span> <a name="l00847"></a>00847 <span class="comment"> to_quote = task->name().contains(delim) || task->name().contains(dquote);</span> <a name="l00848"></a>00848 <span class="comment"> */</span> <a name="l00849"></a>00849 to_quote = <span class="keyword">true</span>; <a name="l00850"></a>00850 <span class="keywordflow">if</span> ( to_quote) cell.push_back(dquote); <a name="l00851"></a>00851 <a name="l00852"></a>00852 <a name="l00853"></a>00853 <span class="comment">// Double quotes replaced by a pair of consecutive double quotes</span> <a name="l00854"></a>00854 cell.push_back(task-><a class="code" href="classTask.html#e18d2ce750c810aa14033d6c1df99e0d" title="returns the name of this task.">name</a>().replace( dquote, double_dquote )); <a name="l00855"></a>00855 <a name="l00856"></a>00856 <span class="keywordflow">if</span> ( to_quote) cell.push_back(dquote); <a name="l00857"></a>00857 <a name="l00858"></a>00858 cell.push_back(cr); <a name="l00859"></a>00859 <a name="l00860"></a>00860 <span class="keyword">add</span>=0; <a name="l00861"></a>00861 <span class="keywordflow">for</span> (<a class="code" href="classTask.html" title="A class representing a task.">Task</a>* subTask = task-><a class="code" href="classTask.html#aaedcc7fa646b15e0451a638ed3fdf63" title="return parent Task or null in case of TaskView.">firstChild</a>(); <a name="l00862"></a>00862 subTask; <a name="l00863"></a>00863 subTask = subTask-><a class="code" href="classTask.html#a7c59fd2c4318c9eac3bf10fb0201422">nextSibling</a>()) <a name="l00864"></a>00864 { <a name="l00865"></a>00865 <span class="keyword">add</span> += printTaskHistory( subTask, taskdaytotals, daytotals, from, to , level+1, matrix, <a name="l00866"></a>00866 rc ); <a name="l00867"></a>00867 } <a name="l00868"></a>00868 cell[colrectot]=(QString::fromLatin1(<span class="stringliteral">"%1"</span>).arg(formatTime((<span class="keyword">add</span>+sum)/60, rc.<a class="code" href="classReportCriteria.html#0a40fd5022cc4bfde6c2f2b3f38d2178" title="True if the durations should be output in decimal hours.">decimalMinutes</a> ))); <a name="l00869"></a>00869 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i < cell.size(); i++) matrix[ownline]+=cell[i]; <a name="l00870"></a>00870 <span class="keywordflow">return</span> <span class="keyword">add</span>+sum; <a name="l00871"></a>00871 } <a name="l00872"></a>00872 <a name="l00873"></a><a class="code" href="classKarmStorage.html#4d36c935a652dabc297ea571b5f7cfbd">00873</a> QString <a class="code" href="classKarmStorage.html#4d36c935a652dabc297ea571b5f7cfbd" title="Output a report based on contents of ReportCriteria.">KarmStorage::report</a>( <a class="code" href="classTaskView.html" title="Container and interface for the tasks.">TaskView</a> *taskview, <span class="keyword">const</span> <a class="code" href="classReportCriteria.html" title="Stores entries from export dialog.">ReportCriteria</a> &rc ) <a name="l00874"></a>00874 { <a name="l00875"></a>00875 QString err; <a name="l00876"></a>00876 <span class="keywordflow">if</span> ( rc.<a class="code" href="classReportCriteria.html#9d58d3994764df4bd8e435448544a905" title="The type of report we are running.">reportType</a> == ReportCriteria::CSVHistoryExport ) <a name="l00877"></a>00877 err = exportcsvHistory( taskview, rc.<a class="code" href="classReportCriteria.html#5671cee62da1587e9fc2f99ac4cd61b2" title="For history reports, the lower bound of the date range to report on.">from</a>, rc.<a class="code" href="classReportCriteria.html#4953a7eecad4bf77a40ea84b23277611" title="For history reports, the upper bound of the date range to report on.">to</a>, rc ); <a name="l00878"></a>00878 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( rc.<a class="code" href="classReportCriteria.html#9d58d3994764df4bd8e435448544a905" title="The type of report we are running.">reportType</a> == ReportCriteria::CSVTotalsExport ) <a name="l00879"></a>00879 err = exportcsvFile( taskview, rc ); <a name="l00880"></a>00880 <span class="keywordflow">else</span> { <a name="l00881"></a>00881 <span class="comment">// hmmmm ... assert(0)?</span> <a name="l00882"></a>00882 } <a name="l00883"></a>00883 <span class="keywordflow">return</span> err; <a name="l00884"></a>00884 } <a name="l00885"></a>00885 <a name="l00886"></a>00886 <span class="comment">// export history report as csv, all tasks X all dates in one block</span> <a name="l00887"></a>00887 QString KarmStorage::exportcsvHistory ( <a class="code" href="classTaskView.html" title="Container and interface for the tasks.">TaskView</a> *taskview, <a name="l00888"></a>00888 <span class="keyword">const</span> QDate &from, <a name="l00889"></a>00889 <span class="keyword">const</span> QDate &to, <a name="l00890"></a>00890 <span class="keyword">const</span> <a class="code" href="classReportCriteria.html" title="Stores entries from export dialog.">ReportCriteria</a> &rc) <a name="l00891"></a>00891 { <a name="l00892"></a>00892 QString delim = rc.<a class="code" href="classReportCriteria.html#a31ef3532d513d3585afdafc2ab1ebcc" title="The delimiter to use when outputting comma-seperated value reports.">delimiter</a>; <a name="l00893"></a>00893 <span class="keyword">const</span> QString cr = QString::fromLatin1(<span class="stringliteral">"\n"</span>); <a name="l00894"></a>00894 QString err; <a name="l00895"></a>00895 <a name="l00896"></a>00896 <span class="comment">// below taken from timekard.cpp</span> <a name="l00897"></a>00897 QString retval; <a name="l00898"></a>00898 QString taskhdr, totalhdr; <a name="l00899"></a>00899 QString line, buf; <a name="l00900"></a>00900 <span class="keywordtype">long</span> sum; <a name="l00901"></a>00901 <a name="l00902"></a>00902 QValueList<HistoryEvent> events; <a name="l00903"></a>00903 QValueList<HistoryEvent>::iterator event; <a name="l00904"></a>00904 QMap<QString, long> taskdaytotals; <a name="l00905"></a>00905 QMap<QString, long> daytotals; <a name="l00906"></a>00906 QString daytaskkey, daykey; <a name="l00907"></a>00907 QDate day; <a name="l00908"></a>00908 QDate dayheading; <a name="l00909"></a>00909 <a name="l00910"></a>00910 <span class="comment">// parameter-plausi</span> <a name="l00911"></a>00911 <span class="keywordflow">if</span> ( from > to ) <a name="l00912"></a>00912 { <a name="l00913"></a>00913 err = QString::fromLatin1 ( <a name="l00914"></a>00914 <span class="stringliteral">"'to' has to be a date later than or equal to 'from'."</span>); <a name="l00915"></a>00915 } <a name="l00916"></a>00916 <a name="l00917"></a>00917 <span class="comment">// header</span> <a name="l00918"></a>00918 retval += i18n(<span class="stringliteral">"Task History\n"</span>); <a name="l00919"></a>00919 retval += i18n(<span class="stringliteral">"From %1 to %2"</span>) <a name="l00920"></a>00920 .arg(KGlobal::locale()->formatDate(from)) <a name="l00921"></a>00921 .arg(KGlobal::locale()->formatDate(to)); <a name="l00922"></a>00922 retval += cr; <a name="l00923"></a>00923 retval += i18n(<span class="stringliteral">"Printed on: %1"</span>) <a name="l00924"></a>00924 .arg(KGlobal::locale()->formatDateTime(QDateTime::currentDateTime())); <a name="l00925"></a>00925 retval += cr; <a name="l00926"></a>00926 <a name="l00927"></a>00927 day=from; <a name="l00928"></a>00928 events = taskview-><a class="code" href="classTaskView.html#01feebb113c1885b3bda674167c7a88b" title="Return list of start/stop events for given date range.">getHistory</a>(from, to); <a name="l00929"></a>00929 taskdaytotals.clear(); <a name="l00930"></a>00930 daytotals.clear(); <a name="l00931"></a>00931 <a name="l00932"></a>00932 <span class="comment">// Build lookup dictionary used to output data in table cells. keys are</span> <a name="l00933"></a>00933 <span class="comment">// in this format: YYYYMMDD_NNNNNN, where Y = year, M = month, d = day and</span> <a name="l00934"></a>00934 <span class="comment">// NNNNN = the VTODO uid. The value is the total seconds logged against</span> <a name="l00935"></a>00935 <span class="comment">// that task on that day. Note the UID is the todo id, not the event id,</span> <a name="l00936"></a>00936 <span class="comment">// so times are accumulated for each task.</span> <a name="l00937"></a>00937 <span class="keywordflow">for</span> (event = events.begin(); <span class="keyword">event</span> != events.end(); ++event) <a name="l00938"></a>00938 { <a name="l00939"></a>00939 daykey = (*event).start().date().toString(QString::fromLatin1(<span class="stringliteral">"yyyyMMdd"</span>)); <a name="l00940"></a>00940 daytaskkey = QString(QString::fromLatin1(<span class="stringliteral">"%1_%2"</span>)) <a name="l00941"></a>00941 .arg(daykey) <a name="l00942"></a>00942 .arg((*event).todoUid()); <a name="l00943"></a>00943 <a name="l00944"></a>00944 <span class="keywordflow">if</span> (taskdaytotals.contains(daytaskkey)) <a name="l00945"></a>00945 taskdaytotals.replace(daytaskkey, <a name="l00946"></a>00946 taskdaytotals[daytaskkey] + (*event).duration()); <a name="l00947"></a>00947 <span class="keywordflow">else</span> <a name="l00948"></a>00948 taskdaytotals.insert(daytaskkey, (*event).duration()); <a name="l00949"></a>00949 } <a name="l00950"></a>00950 <a name="l00951"></a>00951 <span class="comment">// day headings</span> <a name="l00952"></a>00952 dayheading = from; <a name="l00953"></a>00953 <span class="keywordflow">while</span> ( dayheading <= to ) <a name="l00954"></a>00954 { <a name="l00955"></a>00955 <span class="comment">// Use ISO 8601 format for date.</span> <a name="l00956"></a>00956 retval += dayheading.toString(QString::fromLatin1(<span class="stringliteral">"yyyy-MM-dd"</span>)); <a name="l00957"></a>00957 retval += delim; <a name="l00958"></a>00958 dayheading=dayheading.addDays(1); <a name="l00959"></a>00959 } <a name="l00960"></a>00960 retval += i18n(<span class="stringliteral">"Sum"</span>) + delim + i18n(<span class="stringliteral">"Total Sum"</span>) + delim + i18n(<span class="stringliteral">"Task Hierarchy"</span>); <a name="l00961"></a>00961 retval += cr; <a name="l00962"></a>00962 retval += line; <a name="l00963"></a>00963 <a name="l00964"></a>00964 <span class="comment">// the tasks</span> <a name="l00965"></a>00965 vector <QString> matrix; <a name="l00966"></a>00966 linenr=0; <a name="l00967"></a>00967 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i<=taskview-><a class="code" href="classTaskView.html#1baadc861bc75b2aa06ce7351a03cefd" title="Return the total number if items in the view.">count</a>()+1; i++) matrix.push_back(<span class="stringliteral">""</span>); <a name="l00968"></a>00968 <span class="keywordflow">if</span> (events.empty()) <a name="l00969"></a>00969 { <a name="l00970"></a>00970 retval += i18n(<span class="stringliteral">" No hours logged."</span>); <a name="l00971"></a>00971 } <a name="l00972"></a>00972 <span class="keywordflow">else</span> <a name="l00973"></a>00973 { <a name="l00974"></a>00974 <span class="keywordflow">if</span> ( rc.<a class="code" href="classReportCriteria.html#728d2340758d663c9e34ed6dc5579639" title="True if the report should contain all tasks in Karm.">allTasks</a> ) <a name="l00975"></a>00975 { <a name="l00976"></a>00976 <span class="keywordflow">for</span> ( <a class="code" href="classTask.html" title="A class representing a task.">Task</a>* task= taskview-><a class="code" href="classTaskView.html#9050454887e14a5c62725e23f242639d" title="Return the i&#39;th item (zero-based), cast to a Task pointer.">item_at_index</a>(0); <a name="l00977"></a>00977 task; task= task-><a class="code" href="classTask.html#a7c59fd2c4318c9eac3bf10fb0201422">nextSibling</a>() ) <a name="l00978"></a>00978 { <a name="l00979"></a>00979 printTaskHistory( task, taskdaytotals, daytotals, from, to, 0, <a name="l00980"></a>00980 matrix, rc ); <a name="l00981"></a>00981 } <a name="l00982"></a>00982 } <a name="l00983"></a>00983 <span class="keywordflow">else</span> <a name="l00984"></a>00984 { <a name="l00985"></a>00985 printTaskHistory( taskview-><a class="code" href="classTaskView.html#39ddafca93de0b8753014151e47734f3" title="Return the current item in the view, cast to a Task pointer.">current_item</a>(), taskdaytotals, daytotals, <a name="l00986"></a>00986 from, to, 0, matrix, rc ); <a name="l00987"></a>00987 } <a name="l00988"></a>00988 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i<matrix.size(); i++) retval+=matrix[i]; <a name="l00989"></a>00989 retval += line; <a name="l00990"></a>00990 <a name="l00991"></a>00991 <span class="comment">// totals</span> <a name="l00992"></a>00992 sum = 0; <a name="l00993"></a>00993 day = from; <a name="l00994"></a>00994 <span class="keywordflow">while</span> (day<=to) <a name="l00995"></a>00995 { <a name="l00996"></a>00996 daykey = day.toString(QString::fromLatin1(<span class="stringliteral">"yyyyMMdd"</span>)); <a name="l00997"></a>00997 <a name="l00998"></a>00998 <span class="keywordflow">if</span> (daytotals.contains(daykey)) <a name="l00999"></a>00999 { <a name="l01000"></a>01000 retval += QString::fromLatin1(<span class="stringliteral">"%1"</span>) <a name="l01001"></a>01001 .arg(formatTime(daytotals[daykey]/60, rc.<a class="code" href="classReportCriteria.html#0a40fd5022cc4bfde6c2f2b3f38d2178" title="True if the durations should be output in decimal hours.">decimalMinutes</a>)); <a name="l01002"></a>01002 sum += daytotals[daykey]; <span class="comment">// in seconds</span> <a name="l01003"></a>01003 } <a name="l01004"></a>01004 retval += delim; <a name="l01005"></a>01005 day = day.addDays(1); <a name="l01006"></a>01006 } <a name="l01007"></a>01007 <a name="l01008"></a>01008 retval += QString::fromLatin1(<span class="stringliteral">"%1%2%3%4"</span>) <a name="l01009"></a>01009 .arg( formatTime( sum/60, rc.<a class="code" href="classReportCriteria.html#0a40fd5022cc4bfde6c2f2b3f38d2178" title="True if the durations should be output in decimal hours.">decimalMinutes</a> ) ) <a name="l01010"></a>01010 .arg( delim ).arg( delim ) <a name="l01011"></a>01011 .arg( i18n( <span class="stringliteral">"Total"</span> ) ); <a name="l01012"></a>01012 } <a name="l01013"></a>01013 <a name="l01014"></a>01014 <span class="comment">// above taken from timekard.cpp</span> <a name="l01015"></a>01015 <a name="l01016"></a>01016 <span class="comment">// save, either locally or remote</span> <a name="l01017"></a>01017 <a name="l01018"></a>01018 <span class="keywordflow">if</span> ((rc.<a class="code" href="classReportCriteria.html#7ed11ea6932032297409c5f831a4dd10" title="For reports that write to a file, the filename to write to.">url</a>.isLocalFile()) || (!rc.<a class="code" href="classReportCriteria.html#7ed11ea6932032297409c5f831a4dd10" title="For reports that write to a file, the filename to write to.">url</a>.url().contains(<span class="stringliteral">"/"</span>))) <a name="l01019"></a>01019 { <a name="l01020"></a>01020 QString filename=rc.<a class="code" href="classReportCriteria.html#7ed11ea6932032297409c5f831a4dd10" title="For reports that write to a file, the filename to write to.">url</a>.path(); <a name="l01021"></a>01021 <span class="keywordflow">if</span> (filename.isEmpty()) filename=rc.<a class="code" href="classReportCriteria.html#7ed11ea6932032297409c5f831a4dd10" title="For reports that write to a file, the filename to write to.">url</a>.url(); <a name="l01022"></a>01022 QFile f( filename ); <a name="l01023"></a>01023 <span class="keywordflow">if</span>( !f.open( IO_WriteOnly ) ) { <a name="l01024"></a>01024 err = i18n( <span class="stringliteral">"Could not open \"%1\"."</span> ).arg( filename ); <a name="l01025"></a>01025 } <a name="l01026"></a>01026 <span class="keywordflow">if</span> (!err) <a name="l01027"></a>01027 { <a name="l01028"></a>01028 QTextStream stream(&f); <a name="l01029"></a>01029 <span class="comment">// Export to file</span> <a name="l01030"></a>01030 stream << retval; <a name="l01031"></a>01031 f.close(); <a name="l01032"></a>01032 } <a name="l01033"></a>01033 } <a name="l01034"></a>01034 <span class="keywordflow">else</span> <span class="comment">// use remote file</span> <a name="l01035"></a>01035 { <a name="l01036"></a>01036 KTempFile tmpFile; <a name="l01037"></a>01037 <span class="keywordflow">if</span> ( tmpFile.status() != 0 ) <a name="l01038"></a>01038 { <a name="l01039"></a>01039 err = QString::fromLatin1( <span class="stringliteral">"Unable to get temporary file"</span> ); <a name="l01040"></a>01040 } <a name="l01041"></a>01041 <span class="keywordflow">else</span> <a name="l01042"></a>01042 { <a name="l01043"></a>01043 QTextStream *stream=tmpFile.textStream(); <a name="l01044"></a>01044 *stream << retval; <a name="l01045"></a>01045 tmpFile.close(); <a name="l01046"></a>01046 <span class="keywordflow">if</span> (!KIO::NetAccess::upload( tmpFile.name(), rc.<a class="code" href="classReportCriteria.html#7ed11ea6932032297409c5f831a4dd10" title="For reports that write to a file, the filename to write to.">url</a>, 0 )) err=QString::fromLatin1(<span class="stringliteral">"Could not upload"</span>); <a name="l01047"></a>01047 } <a name="l01048"></a>01048 } <a name="l01049"></a>01049 <span class="keywordflow">return</span> err; <a name="l01050"></a>01050 } <a name="l01051"></a>01051 <a name="l01052"></a><a class="code" href="classKarmStorage.html#9deb86884cc80783e4488b39f0fac128">01052</a> <span class="keywordtype">void</span> <a class="code" href="classKarmStorage.html#9deb86884cc80783e4488b39f0fac128" title="Log the event that the timer has stopped for this task.">KarmStorage::stopTimer</a>(<span class="keyword">const</span> <a class="code" href="classTask.html" title="A class representing a task.">Task</a>* task, QDateTime when) <a name="l01053"></a>01053 { <a name="l01054"></a>01054 kdDebug(5970) << <span class="stringliteral">"Entering KarmStorage::stopTimer"</span> << endl; <a name="l01055"></a>01055 <span class="keywordtype">long</span> delta = task-><a class="code" href="classTask.html#c0149b61633034c25eddbe2aa0ffe065" title="Return time the task was started.">startTime</a>().secsTo(when); <a name="l01056"></a>01056 <a class="code" href="classKarmStorage.html#bd6111b30d7c4930d8c6d7b9d4daf294" title="Log the change in a task&#39;s time.">changeTime</a>(task, delta); <a name="l01057"></a>01057 } <a name="l01058"></a>01058 <a name="l01059"></a><a class="code" href="classKarmStorage.html#082d5930150c3db256c4dd23dbefb70c">01059</a> <span class="keywordtype">bool</span> <a class="code" href="classKarmStorage.html#082d5930150c3db256c4dd23dbefb70c" title="Book time to a task.">KarmStorage::bookTime</a>(<span class="keyword">const</span> <a class="code" href="classTask.html" title="A class representing a task.">Task</a>* task, <a name="l01060"></a>01060 <span class="keyword">const</span> QDateTime& startDateTime, <a name="l01061"></a>01061 <span class="keyword">const</span> <span class="keywordtype">long</span> durationInSeconds) <a name="l01062"></a>01062 { <a name="l01063"></a>01063 <span class="comment">// Ignores preferences setting re: logging history.</span> <a name="l01064"></a>01064 KCal::Event* e; <a name="l01065"></a>01065 QDateTime end; <a name="l01066"></a>01066 <a name="l01067"></a>01067 e = baseEvent( task ); <a name="l01068"></a>01068 e->setDtStart( startDateTime ); <a name="l01069"></a>01069 e->setDtEnd( startDateTime.addSecs( durationInSeconds ) ); <a name="l01070"></a>01070 <a name="l01071"></a>01071 <span class="comment">// Use a custom property to keep a record of negative durations</span> <a name="l01072"></a>01072 e->setCustomProperty( kapp->instanceName(), <a name="l01073"></a>01073 QCString(<span class="stringliteral">"duration"</span>), <a name="l01074"></a>01074 QString::number(durationInSeconds)); <a name="l01075"></a>01075 <a name="l01076"></a>01076 <span class="keywordflow">return</span> _calendar->addEvent(e); <a name="l01077"></a>01077 } <a name="l01078"></a>01078 <a name="l01079"></a><a class="code" href="classKarmStorage.html#bd6111b30d7c4930d8c6d7b9d4daf294">01079</a> <span class="keywordtype">void</span> <a class="code" href="classKarmStorage.html#bd6111b30d7c4930d8c6d7b9d4daf294" title="Log the change in a task&#39;s time.">KarmStorage::changeTime</a>(<span class="keyword">const</span> <a class="code" href="classTask.html" title="A class representing a task.">Task</a>* task, <span class="keyword">const</span> <span class="keywordtype">long</span> deltaSeconds) <a name="l01080"></a>01080 { <a name="l01081"></a>01081 kdDebug(5970) << <span class="stringliteral">"Entering KarmStorage::changeTime ( "</span> << task-><a class="code" href="classTask.html#e18d2ce750c810aa14033d6c1df99e0d" title="returns the name of this task.">name</a>() << <span class="stringliteral">","</span> << deltaSeconds << <span class="stringliteral">" )"</span> << endl; <a name="l01082"></a>01082 KCal::Event* e; <a name="l01083"></a>01083 QDateTime end; <a name="l01084"></a>01084 <a name="l01085"></a>01085 <span class="comment">// Don't write events (with timer start/stop duration) if user has turned</span> <a name="l01086"></a>01086 <span class="comment">// this off in the settings dialog.</span> <a name="l01087"></a>01087 <span class="keywordflow">if</span> ( ! task-><a class="code" href="classTask.html#d76165e22581f54e9fda8a639cdffe7a" title="Return task view for this task.">taskView</a>()-><a class="code" href="classTaskView.html#03abf669a3d3a5a669cd2f8e0dcbcee0" title="Return preferences user selected on settings dialog.">preferences</a>()-><a class="code" href="classPreferences.html#4ecd291eb7bff05df039326ae0a61b8e">logging</a>() ) <span class="keywordflow">return</span>; <a name="l01088"></a>01088 <a name="l01089"></a>01089 e = baseEvent(task); <a name="l01090"></a>01090 <a name="l01091"></a>01091 <span class="comment">// Don't use duration, as ICalFormatImpl::writeIncidence never writes a</span> <a name="l01092"></a>01092 <span class="comment">// duration, even though it looks like it's used in event.cpp.</span> <a name="l01093"></a>01093 end = task-><a class="code" href="classTask.html#c0149b61633034c25eddbe2aa0ffe065" title="Return time the task was started.">startTime</a>(); <a name="l01094"></a>01094 <span class="keywordflow">if</span> ( deltaSeconds > 0 ) end = task-><a class="code" href="classTask.html#c0149b61633034c25eddbe2aa0ffe065" title="Return time the task was started.">startTime</a>().addSecs(deltaSeconds); <a name="l01095"></a>01095 e->setDtEnd(end); <a name="l01096"></a>01096 <a name="l01097"></a>01097 <span class="comment">// Use a custom property to keep a record of negative durations</span> <a name="l01098"></a>01098 e->setCustomProperty( kapp->instanceName(), <a name="l01099"></a>01099 QCString(<span class="stringliteral">"duration"</span>), <a name="l01100"></a>01100 QString::number(deltaSeconds)); <a name="l01101"></a>01101 <a name="l01102"></a>01102 _calendar->addEvent(e); <a name="l01103"></a>01103 <a name="l01104"></a>01104 <span class="comment">// This saves the entire iCal file each time, which isn't efficient but</span> <a name="l01105"></a>01105 <span class="comment">// ensures no data loss. A faster implementation would be to append events</span> <a name="l01106"></a>01106 <span class="comment">// to a file, and then when KArm closes, append the data in this file to the</span> <a name="l01107"></a>01107 <span class="comment">// iCal file.</span> <a name="l01108"></a>01108 <span class="comment">//</span> <a name="l01109"></a>01109 <span class="comment">// Meanwhile, we simply use a timer to delay the full-saving until the GUI</span> <a name="l01110"></a>01110 <span class="comment">// has updated, for better user feedback. Feel free to get rid of this</span> <a name="l01111"></a>01111 <span class="comment">// if/when implementing the faster saving (DF).</span> <a name="l01112"></a>01112 task-><a class="code" href="classTask.html#d76165e22581f54e9fda8a639cdffe7a" title="Return task view for this task.">taskView</a>()-><a class="code" href="classTaskView.html#cdacd37c9f4309ee0b2ff52e052792e1" title="Schedule that we should save very soon.">scheduleSave</a>(); <a name="l01113"></a>01113 } <a name="l01114"></a>01114 <a name="l01115"></a>01115 <a name="l01116"></a>01116 KCal::Event* KarmStorage::baseEvent(<span class="keyword">const</span> <a class="code" href="classTask.html" title="A class representing a task.">Task</a> * task) <a name="l01117"></a>01117 { <a name="l01118"></a>01118 KCal::Event* e; <a name="l01119"></a>01119 QStringList categories; <a name="l01120"></a>01120 <a name="l01121"></a>01121 e = <span class="keyword">new</span> KCal::Event; <a name="l01122"></a>01122 e->setSummary(task-><a class="code" href="classTask.html#e18d2ce750c810aa14033d6c1df99e0d" title="returns the name of this task.">name</a>()); <a name="l01123"></a>01123 <a name="l01124"></a>01124 <span class="comment">// Can't use setRelatedToUid()--no error, but no RelatedTo written to disk</span> <a name="l01125"></a>01125 e->setRelatedTo(_calendar->todo(task-><a class="code" href="classTask.html#9a822ba9744f31d2e2bc92c74b757ac2" title="Return unique iCalendar Todo ID for this task.">uid</a>())); <a name="l01126"></a>01126 <a name="l01127"></a>01127 <span class="comment">// Debugging: some events where not getting a related-to field written.</span> <a name="l01128"></a>01128 assert(e->relatedTo()->uid() == task-><a class="code" href="classTask.html#9a822ba9744f31d2e2bc92c74b757ac2" title="Return unique iCalendar Todo ID for this task.">uid</a>()); <a name="l01129"></a>01129 <a name="l01130"></a>01130 <span class="comment">// Have to turn this off to get datetimes in date fields.</span> <a name="l01131"></a>01131 e->setFloats(<span class="keyword">false</span>); <a name="l01132"></a>01132 e->setDtStart(task-><a class="code" href="classTask.html#c0149b61633034c25eddbe2aa0ffe065" title="Return time the task was started.">startTime</a>()); <a name="l01133"></a>01133 <a name="l01134"></a>01134 <span class="comment">// So someone can filter this mess out of their calendar display</span> <a name="l01135"></a>01135 categories.append(i18n(<span class="stringliteral">"KArm"</span>)); <a name="l01136"></a>01136 e->setCategories(categories); <a name="l01137"></a>01137 <a name="l01138"></a>01138 <span class="keywordflow">return</span> e; <a name="l01139"></a>01139 } <a name="l01140"></a>01140 <a name="l01141"></a>01141 <a class="code" href="classHistoryEvent.html#88d02a28b767f7ca78503390df2bf43e" title="Needed to be used in a value list.">HistoryEvent::HistoryEvent</a>(QString uid, QString name, <span class="keywordtype">long</span> duration, <a name="l01142"></a>01142 QDateTime start, QDateTime stop, QString todoUid) <a name="l01143"></a>01143 { <a name="l01144"></a>01144 _uid = uid; <a name="l01145"></a>01145 _name = name; <a name="l01146"></a>01146 _duration = duration; <a name="l01147"></a>01147 _start = start; <a name="l01148"></a>01148 _stop = stop; <a name="l01149"></a>01149 _todoUid = todoUid; <a name="l01150"></a>01150 } <a name="l01151"></a>01151 <a name="l01152"></a>01152 <a name="l01153"></a><a class="code" href="classKarmStorage.html#5cef00b43033590f9b509559540c8d22">01153</a> QValueList<HistoryEvent> <a class="code" href="classKarmStorage.html#5cef00b43033590f9b509559540c8d22" title="Return a list of start/stop events for the given date range.">KarmStorage::getHistory</a>(<span class="keyword">const</span> QDate& from, <a name="l01154"></a>01154 <span class="keyword">const</span> QDate& to) <a name="l01155"></a>01155 { <a name="l01156"></a>01156 QValueList<HistoryEvent> retval; <a name="l01157"></a>01157 QStringList processed; <a name="l01158"></a>01158 KCal::Event::List events; <a name="l01159"></a>01159 KCal::Event::List::iterator event; <a name="l01160"></a>01160 QString duration; <a name="l01161"></a>01161 <a name="l01162"></a>01162 <span class="keywordflow">for</span>(QDate d = from; d <= to; d = d.addDays(1)) <a name="l01163"></a>01163 { <a name="l01164"></a>01164 events = _calendar->rawEventsForDate( d ); <a name="l01165"></a>01165 <span class="keywordflow">for</span> (event = events.begin(); <span class="keyword">event</span> != events.end(); ++event) <a name="l01166"></a>01166 { <a name="l01167"></a>01167 <a name="l01168"></a>01168 <span class="comment">// KArm events have the custom property X-KDE-Karm-duration</span> <a name="l01169"></a>01169 <span class="keywordflow">if</span> (! processed.contains( (*event)->uid())) <a name="l01170"></a>01170 { <a name="l01171"></a>01171 <span class="comment">// If an event spans multiple days, CalendarLocal::rawEventsForDate</span> <a name="l01172"></a>01172 <span class="comment">// will return the same event on both days. To avoid double-counting</span> <a name="l01173"></a>01173 <span class="comment">// such events, we (arbitrarily) attribute the hours from both days on</span> <a name="l01174"></a>01174 <span class="comment">// the first day. This mis-reports the actual time spent, but it is</span> <a name="l01175"></a>01175 <span class="comment">// an easy fix for a (hopefully) rare situation.</span> <a name="l01176"></a>01176 processed.append( (*event)->uid()); <a name="l01177"></a>01177 <a name="l01178"></a>01178 duration = (*event)->customProperty(kapp->instanceName(), <a name="l01179"></a>01179 QCString(<span class="stringliteral">"duration"</span>)); <a name="l01180"></a>01180 <span class="keywordflow">if</span> ( ! duration.isNull() ) <a name="l01181"></a>01181 { <a name="l01182"></a>01182 <span class="keywordflow">if</span> ( (*event)->relatedTo() <a name="l01183"></a>01183 && ! (*event)->relatedTo()->uid().isEmpty() ) <a name="l01184"></a>01184 { <a name="l01185"></a>01185 retval.append(<a class="code" href="classHistoryEvent.html" title="One start/stop event that has been logged.">HistoryEvent</a>( <a name="l01186"></a>01186 (*event)->uid(), <a name="l01187"></a>01187 (*event)->summary(), <a name="l01188"></a>01188 duration.toLong(), <a name="l01189"></a>01189 (*event)->dtStart(), <a name="l01190"></a>01190 (*event)->dtEnd(), <a name="l01191"></a>01191 (*event)->relatedTo()->uid() <a name="l01192"></a>01192 )); <a name="l01193"></a>01193 } <a name="l01194"></a>01194 <span class="keywordflow">else</span> <a name="l01195"></a>01195 <span class="comment">// Something is screwy with the ics file, as this KArm history event</span> <a name="l01196"></a>01196 <span class="comment">// does not have a todo related to it. Could have been deleted</span> <a name="l01197"></a>01197 <span class="comment">// manually? We'll continue with report on with report ...</span> <a name="l01198"></a>01198 kdDebug(5970) << <span class="stringliteral">"KarmStorage::getHistory(): "</span> <a name="l01199"></a>01199 << <span class="stringliteral">"The event "</span> << (*event)->uid() <a name="l01200"></a>01200 << <span class="stringliteral">" is not related to a todo. Dropped."</span> << endl; <a name="l01201"></a>01201 } <a name="l01202"></a>01202 } <a name="l01203"></a>01203 } <a name="l01204"></a>01204 } <a name="l01205"></a>01205 <a name="l01206"></a>01206 <span class="keywordflow">return</span> retval; <a name="l01207"></a>01207 } <a name="l01208"></a>01208 <a name="l01209"></a>01209 <span class="keywordtype">bool</span> KarmStorage::remoteResource( <span class="keyword">const</span> QString& file )<span class="keyword"> const</span> <a name="l01210"></a>01210 <span class="keyword"></span>{ <a name="l01211"></a>01211 QString f = file.lower(); <a name="l01212"></a>01212 <span class="keywordtype">bool</span> rval = f.startsWith( <span class="stringliteral">"http://"</span> ) || f.startsWith( <span class="stringliteral">"ftp://"</span> ); <a name="l01213"></a>01213 <a name="l01214"></a>01214 kdDebug(5970) << <span class="stringliteral">"KarmStorage::remoteResource( "</span> << file << <span class="stringliteral">" ) returns "</span> << rval << endl; <a name="l01215"></a>01215 <span class="keywordflow">return</span> rval; <a name="l01216"></a>01216 } <a name="l01217"></a>01217 <a name="l01218"></a>01218 <span class="keywordtype">bool</span> KarmStorage::saveCalendar() <a name="l01219"></a>01219 { <a name="l01220"></a>01220 kdDebug(5970) << <span class="stringliteral">"KarmStorage::saveCalendar"</span> << endl; <a name="l01221"></a>01221 <a name="l01222"></a>01222 <span class="preprocessor">#if 0</span> <a name="l01223"></a>01223 <span class="preprocessor"></span> Event::List evl=_calendar->rawEvents(); <a name="l01224"></a>01224 kdDebug(5970) << <span class="stringliteral">"summary - dtStart - dtEnd"</span> << endl; <a name="l01225"></a>01225 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i<evl.count(); i++) <a name="l01226"></a>01226 { <a name="l01227"></a>01227 kdDebug() << evl[i]->summary() << evl[i]->dtStart() << evl[i]->dtEnd() << endl; <a name="l01228"></a>01228 } <a name="l01229"></a>01229 <span class="preprocessor">#endif</span> <a name="l01230"></a>01230 <span class="preprocessor"></span> KABC::Lock *lock = _calendar->lock(); <a name="l01231"></a>01231 <span class="keywordflow">if</span> ( !lock || !lock->lock() ) <a name="l01232"></a>01232 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l01233"></a>01233 <a name="l01234"></a>01234 <span class="keywordflow">if</span> ( _calendar && _calendar->save() ) { <a name="l01235"></a>01235 lock->unlock(); <a name="l01236"></a>01236 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l01237"></a>01237 } <a name="l01238"></a>01238 <a name="l01239"></a>01239 lock->unlock(); <a name="l01240"></a>01240 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l01241"></a>01241 } </pre></div></div> </div></div> </td> </tr> <tr> <td valign="top" id="leftmenu" width="25%"> <a name="navigation"></a> <div class="menu_box"><h2>karm</h2> <div class="nav_list"> <ul><li><a href="index.html">Main Page</a></li><li><a href="hierarchy.html">Class Hierarchy</a></li><li><a href="classes.html">Alphabetical List</a></li><li><a href="annotated.html">Class List</a></li><li><a href="files.html">File List</a></li><li><a href="functions.html">Class Members</a></li><li><a href="pages.html">Related Pages</a></li></ul> <!-- <h2>Class Picker</h2> <div style="text-align: center;"> <form name="guideform"> <select name="guidelinks" style="width:100%;" onChange="window.location=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value"> <option value="annotated.html">-- Choose --</option> <option value="classDesktopTracker.html">desktoptracker</option>, <option value="classEditTaskDialog.html">edittaskdialog</option>, <option value="classHistoryEvent.html">historyevent</option>, <option value="classIdleTimeDetector.html">idletimedetector</option>, <option value="classKAccelMenuWatch.html">kaccelmenuwatch</option>, <option value="classKarmDCOPIface.html">karmdcopiface</option>, <option value="classKarmStorage.html">karmstorage</option>, <option value="classKArmTimeWidget.html">karmtimewidget</option>, <option value="classMainWindow.html">mainwindow</option>, <option value="classMyPrinter.html">myprinter</option>, <option value="classPlannerParser.html">plannerparser</option>, <option value="classPreferences.html">preferences</option>, <option value="classReportCriteria.html">reportcriteria</option>, <option value="classTask.html">task</option>, <option value="classTaskView.html">taskview</option>, <option value="classTaskViewWhatsThis.html">taskviewwhatsthis</option>, <option value="classTimeKard.html">timekard</option>, <option value="classWeek.html">week</option>, </select> </form> </div> --> </div></div> <div class="menu_box"><h2>API Dox</h2> <div class="nav_list"> <ul> <li><a href="../../akregator/html/index.html">akregator</a></li><li> <a href="../../akregator/src/html/index.html">src</a></li><li> <a href="../../akregator/src/librss/html/index.html">librss</a></li><li><a href="../../certmanager/html/index.html">certmanager</a></li><li> <a href="../../certmanager/lib/html/index.html">lib</a></li><li><a href="../../kaddressbook/html/index.html">kaddressbook</a></li><li><a href="../../kalarm/html/index.html">kalarm</a></li><li> <a href="../../kalarm/lib/html/index.html">lib</a></li><li><a href="../../kandy/html/index.html">kandy</a></li><li><a href="../../karm/html/index.html">karm</a></li><li><a href="../../kdgantt/html/index.html">kdgantt</a></li><li><a href="../../kgantt/html/index.html">kgantt</a></li><li><a href="../../kioslaves/html/index.html">kioslaves</a></li><li> <a href="../../kioslaves/imap4/html/index.html">imap4</a></li><li> <a href="../../kioslaves/mbox/html/index.html">mbox</a></li><li><a href="../../kitchensync/html/index.html">kitchensync</a></li><li><a href="../../kmail/html/index.html">kmail</a></li><li><a href="../../knotes/html/index.html">knotes</a></li><li><a href="../../konsolekalendar/html/index.html">konsolekalendar</a></li><li><a href="../../kontact/html/index.html">kontact</a></li><li><a href="../../korganizer/html/index.html">korganizer</a></li><li><a href="../../kpilot/html/index.html">kpilot</a></li><li> <a href="../../kpilot/kpilot/html/index.html">kpilot</a></li><li> <a href="../../kpilot/lib/html/index.html">lib</a></li><li><a href="../../libemailfunctions/html/index.html">libemailfunctions</a></li><li><a href="../../libkcal/html/index.html">libkcal</a></li><li><a href="../../libkdepim/html/index.html">libkdepim</a></li><li><a href="../../libkholidays/html/index.html">libkholidays</a></li><li><a href="../../libkmime/html/index.html">libkmime</a></li><li><a href="../../libkpgp/html/index.html">libkpgp</a></li><li><a href="../../libkpimidentities/html/index.html">libkpimidentities</a></li> </ul></div></div> </td> </tr> </table> <span class="doNotDisplay"> <a href="http://www.kde.org/" accesskey="8">KDE Home</a> | <a href="http://accessibility.kde.org/" accesskey="9">KDE Accessibility Home</a> | <a href="http://www.kde.org/media/accesskeys.php" accesskey="0">Description of Access Keys</a> </span> <div style="height: 8px"></div> <div id="footer"> <div id="footer_left"> Maintained by <a href="mailto:groot@kde.org">Adriaan de Groot</a> and <a href="mailto:winter@kde.org">Allen Winter</a>. <br/> KDE and K Desktop Environment are trademarks of <a href="http://www.kde.org/areas/kde-ev/" title="Homepage of the KDE non-profit Organization">KDE e.V.</a> | <a href="http://www.kde.org/contact/impressum.php">Legal</a> </div> <div id="footer_right"><img src="/media/images/footer_right.png" style="margin: 0px" alt="" /></div> </div> <!-- WARNING: DO NOT SEND MAIL TO THE FOLLOWING EMAIL ADDRESS! YOU WILL BE BLOCKED INSTANTLY AND PERMANENTLY! <a href="mailto:aaaatrap-425acc3b5374943f@kde.org">Block me</a> WARNING END --> </body> </html>