kpilot Library API Documentation

pilotProgectEntry.cc

00001 /* pilotProgectEntry.cc                 KPilot
00002 **
00003 ** Copyright (C) 1998-2001 by Dan Pilone
00004 ** Copyright (c) 1996, Kenneth Albanowski
00005 ** Copyright (c) 2002, Reinhold Kainhofer
00006 **
00007 ** This is a C++ wrapper for the Progect-list entry structures.
00008 ** it is based on the pilotToDoEntry.cc by Dan Pilone,
00009 ** the pack/unpack functions are based on pilot-link.
00010 */
00011 
00012 /*
00013 ** This program is free software; you can redistribute it and/or modify
00014 ** it under the terms of the GNU General Public License as published by
00015 ** the Free Software Foundation; either version 2 of the License, or
00016 ** (at your option) any later version.
00017 **
00018 ** This program is distributed in the hope that it will be useful,
00019 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00021 ** GNU General Public License for more details.
00022 **
00023 ** You should have received a copy of the GNU General Public License
00024 ** along with this program in a file called COPYING; if not, write to
00025 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00026 ** MA 02111-1307, USA.
00027 */
00028 
00029 /*
00030 ** Bug reports and questions can be sent to reinhold@kainhofer.com
00031 */
00032 #include <stdlib.h>
00033 
00034 //#include <pi-source.h>
00035 //#include <pi-dlp.h>
00036 //#include <pi-todo.h>
00037 
00038 #ifndef _KDEBUG_H_
00039 #include <kdebug.h>
00040 #endif
00041 
00042 #ifndef _KPILOT_OPTIONS_H
00043 #include "options.h"
00044 #endif
00045 
00046 #include "pilotProgectEntry.h"
00047 
00048 static const char *pilotProgectEntry_id =
00049         "$Id: pilotProgectEntry.cc,v 1.1.4.1 2003/03/12 23:31:09 adridg Exp $";
00050 
00051 
00052 /***********************************************************************
00053  * Function:    unpack_Progect
00054  * Summary:     Unpack the Progect structure into records we can chew on
00055  * Parmeters:   None
00056  * Returns:     Nothing
00057  ***********************************************************************/
00058 void PilotProgectEntry::unpack(const void *buffer, int len) {
00059         unsigned long d;
00060         char *start = (char*)buffer;
00061 
00062         if (len < 11)  return 0;
00063         setLevel((byte)get_byte((char*)buffer));
00064         
00065         byte f=(byte)get_byte((char*)buffer+1);
00066         setFlag(HAS_NEXT, (f>>7) & 1);
00067         setFlag(HAS_CHILDREN, (f>>6) & 1);
00068         setFlag(HAS_EXPANDED, (f>>5) & 1);
00069         setFlag(HAS_PREVIOUS, (f>>4) & 1);
00070         
00071         f=(byte)get_byte(buffer+2);
00072         setFlag(HAS_NEXT, (f>>7) & 1);
00073         setFlag(HAS_NEXT, (f>>6) & 1);
00074         setFlag(HAS_NEXT, (f>>5) & 1);
00075         
00076         f=(byte)get_byte(buffer+2);
00077 //      pg->hasDueDate=(f>>7)&1;
00078 //      pg->hasToDo=(f>>6)&1;
00079 //      pg->hasNote=(f>>5)&1;
00080         
00081         setPriority((int)get_byte((char*)buffer+4));
00082 
00083         byte c=(byte)get_byte((char*)buffer+5);
00084         if (c<=10) { // PERCENTAGE
00085                 setProgress(10*c);
00086                 setFlag(IS_CHECKED,(pg==10)?1:0);
00087                 setType(PERCENTAGE);
00088         } else if (c==12) { // TODO completed
00089                 setFlat(IS_CHECKED, true);
00090                 setType(TODO);
00091         } else if (c>=20) { // NUMERICAL, value is 20+percent, extra info contains num. vals.
00092                 setProgress(c-20);
00093                 setFlat(IS_CHECKED, (c==120)?1:0);
00094                 setType(NUMERIC);
00095         } else if (c==16) { // INFORMATIVE
00096                 setFlag(IS_CHECKED, false);
00097                 setType(INFORMATIVE);
00098         } else { // assume everything else is a TODO NOT completed
00099                 setFlag(IS_CHECKED, false);
00100                 setType(TODO);
00101         }
00102 
00103         // TODO: really get_short???
00104         unsigned int dt = (unsigned int) get_short((char*)buffer+6);
00105         if (dt != 0xffff) {
00106                 tm due
00107                 due.tm_year = (dt >> 9) + 4;
00108                 due.tm_mon = ((dt >> 5) & 15) - 1;
00109                 due.tm_mday = dt & 31;
00110                 due.tm_hour = 0;
00111                 due.tm_min = 0;
00112                 due.tm_sec = 0;
00113                 due.tm_isdst = -1;
00114                 mktime(&due);
00115                 setDate(DATE_DUE, due);
00116         }
00117 
00118         buffer += 8;
00119         len -= 8;
00120 
00121         if (len < 1) return;
00122         setDescription(strdup((char *) buffer));
00123 
00124         (char*)buffer += strlen(getDescription()) + 1;
00125         len -= strlen(getDescription()) + 1;
00126 
00127         if (len < 1) {
00128 //              free(fData.description);
00129 //              fData.description = 0;
00130                 return;
00131         }
00132         setNote(strdup((char *) buffer));
00133 
00134         (char*)buffer += strlen(getNote()) + 1;
00135         len -= strlen(getNote()) + 1;
00136         if (getType()==NUMERIC) {
00137                 maxVal=(byte)get_byte((char*)buffer+5)*(1<<8) + (byte)get_byte((char*)buffer+6);
00138                 numVal=(byte)get_byte((char*)buffer+7)*(1<<8) + (byte)get_byte((char*)buffer+8);
00139                 (char*)buffer+=8;
00140         }
00141 
00142         return (buffer - start);        /* FIXME: return real length */
00143 }
00144 
00145 /***********************************************************************
00146  * Function:    pack_Progect
00147  * Summary:     Pack the Progect records into a structure
00148  * Parmeters:   None
00149  * Returns:     Nothing
00150  ***********************************************************************/
00151 int pack_Progect(struct Progect *pg, struct ToDo *a, unsigned char *buf, int len) {
00152         int pos;
00153         int destlen = 10;
00154 
00155         if (getDescription()) destlen += strlen(getDescription());
00156         if (getNote()) destlen += strlen(getNote());
00157         if (getType()==NUMERIC) destlen+=8;
00158 
00159         if (!buf) return destlen;
00160         if (len < destlen) return 0;
00161 
00162         ((char*)buf)[0]=getLevel();
00163         ((char*)buf)[1]=0;
00164         if (getFlag(HAS_NEXT)) ((char*)buf)[1]|=0x80;
00165         if (getFlag(HAS_CHILDREN)) ((char*)buf)[1]|=0x40;
00166         if (getFlag(IS_EXPANDED)) ((char*)buf)[1]|=0x20;
00167         if (getFlag(HAS_PREVIOUS)) ((char*)buf)[1]|=0x10;
00168         ((char*)buf)[2]=0;
00169         if (hasDate(DATE_DUE)) ((char*)buf)[2]|=0x10;
00170         if (getTodoLink()) ((char*)buf)[2]|=0x08;
00171         if (getNote()) ((char*)buf)[2]|=0x04;
00172         ((char*)buf)buf[3]=0;
00173         
00174         ((char*)buf)[4]=getPriority();
00175         if (((char*)buf)[4]==0) ((char*)buf)[4]=6;
00176         
00177         ((char*)buf)buf[5]=0;
00178         switch (getType()) {
00179                 case PERCENTAGE: ((char*)buf)[5]=(byte)(getProgress()/10); break;
00180                 case INFORMATIVE: ((char*)buf)[5]=16; break;
00181                 case NUMERICAL: ((char*)buf)[5]=20+(100*numVal/maxVal); break;
00182                 case TODO:
00183                 default:
00184                         ((char*)buf)[5]=11;
00185                         if (getFlag(IS_CHECKED)) ((char*)buf)[5]=12;
00186                         break;
00187         }
00188 
00189         if (hasDate(DATE_DUE) {
00190                 ((char*)buf)[6] = 0xff;
00191                 ((char*)buf)[7] = 0xff;
00192         } else {
00193                 tm due=getDate(DATE_DUE);
00194                 set_short(((char*)buf)+6, ((due.tm_year - 4) << 9) | ((due.tm_mon + 1) << 5) | due.tm_mday);
00195         }
00196 
00197         pos = 8;
00198         if (getDescription()) {
00199                 strcpy((char *)buf + pos, getDescription());
00200                 pos += strlen(getDescription()) + 1;
00201         } else {
00202                 ((char*)buf)[pos++] = 0;
00203         }
00204 
00205         if (getNote()) {
00206                 strcpy((char *)buf + pos, getNote());
00207                 pos += strlen(getNote()) + 1;
00208         } else {
00209                 ((char*)buf)[pos++] = 0;
00210         }
00211         
00212         if (getType()==NUMERICAL) {
00213                 ((char*)buf)[pos++]=0;
00214                 ((char*)buf)[pos++]=0;
00215                 ((char*)buf)[pos++]=0;
00216                 ((char*)buf)[pos++]=0;
00217                 ((char*)buf)[pos++]=(maxVal>>8);
00218                 ((char*)buf)[pos++]=(maxVal & 0xff);
00219                 ((char*)buf)[pos++]=(numVal>>8);
00220                 ((char*)buf)[pos++]=(numVal & 0xff);
00221         }
00222 
00223         return pos;
00224 }
00225 
00227 
00228 
00229 PilotProgectEntry::PilotProgectEntry(PilotRecord * rec):PilotOrganizerEntry(rec) {
00230         unpack((unsigned char *) rec->getData(), rec->getLen());
00231         (void) pilotProgectEntry_id;
00232 }
00233 
00234 PilotProgectEntry & PilotProgectEntry::operator = (const PilotProgectEntry & e) {
00235         PilotTodoEntry::operator =(e);
00236         if (e) {
00237                 maxVal=e->maxVal;
00238                 numVal=e->numVal;
00239         }
00240         return *this;
00241 }                               // end of assignment operator
00242 
00243 
00244 // $Log: pilotProgectEntry.cc,v $
00245 // Revision 1.1.4.1  2003/03/12 23:31:09  adridg
00246 // CVS_SILENT: FSF address change
00247 //
00248 // Revision 1.1  2002/04/07 12:09:42  kainhofe
00249 // Initial checkin of the conduit. The gui works mostly, but syncing crashes KPilot...
00250 //
00251 // Revision 1.2  2002/03/23 18:21:14  reinhold
00252 // Cleaned up the structure. Works with QTimer instead of loops.
00253 //
00254 // Revision 1.3  2002/03/10 23:58:32  reinhold
00255 // Made the conduit compile...
00256 //
00257 // Revision 1.2  2002/03/10 16:06:43  reinhold
00258 // Cleaned up the class hierarchy, implemented some more features (should be quite finished now...)
00259 //
00260 // Revision 1.1  2002/03/09 15:48:32  reinhold
00261 // Added the classes for the different palm database formats
00262 //
00263 //
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:44 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001