kpilot Library API Documentation

pilotListMakerEntry.cc

00001 /* pilotListMakerEntry.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 ListMaker-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 groot@kde.org
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 "pilotListMakerEntry.h"
00047 
00048 static const char *pilotListMakerEntry_id =
00049         "$Id: pilotListMakerEntry.cc,v 1.1.4.1 2003/03/12 23:31:09 adridg Exp $";
00050 
00051 
00052 /***********************************************************************
00053  * Function:    unpack_ListMaker
00054  * Summary:     Unpack the ListMaker structure into records we can chew on
00055  * Parmeters:   None
00056  * Returns:     Nothing
00057  ***********************************************************************/
00058 void PilotListMakerEntry::unpack(const void *buffer, int len) {
00059         unsigned long d;
00060         char *start = (char*)buffer;
00061 
00062         /* Each record had the following byte structure:
00063            XXXX | FF DD | TTTTT...  0 NNNN... 0 CC... 0 XX
00064         
00065            The X denote an unknown byte, | does not have a meaning.
00066            FF is a bit flag with the bits (highest bit first) having the following meaning:
00067               1.. the item is checked (1)
00068               2.. if the 3rd bit is set (meaning it is a subgroup) the group is open (1) / closed (0)
00069               3.. the item has subitems (1)
00070               4 .. the item is visible (i.e. not a subitem of a closed group)
00071               5.. unknown (set if item or subitem is checked)
00072               6 .. " normal item", i.e. not a common item
00073               7.. unknown
00074               8.. the item is a common item (1)
00075               9-13.. unknown
00076               14-16 .. level of the item
00077            DD is the due date of the item (or 0xff, if no date is set)
00078            TTTTT is the text of the item
00079            NNNN is the text of the note
00080            CCC is the custom field
00081         */
00082         
00083         if (len < 11)  return;// 0;
00084         char f = (char) get_byte((char*)buffer+4);
00085         setFlag(IS_CHECKED, (f>>7) & 1);
00086         setFlag(IS_EXPANDED, (f>>6) & 1);
00087         setFlag(HAS_CHILDREN, (f>>5) & 1);
00088         setFlag(IS_VISIBLE, (f>>4) & 1);
00089         setFlag(FLAG_CUSTOM1, f & 1);
00090         f=(char) get_byte((char*)buffer+5);
00091         setLevel(f & 7);
00092         
00093         d = (unsigned short int) get_short((char*)buffer+6);
00094         setDate(DATE_DUE, d);
00095 
00096         setPriority(0);
00097 
00098         (char*)buffer += 8;
00099         len -= 8;
00100 
00101         if (len < 1) return;
00102         setDescription(strdup((char *) buffer));
00103 
00104         (char*)buffer += strlen(getDescription()) + 1;
00105         len -= strlen(getDescription()) + 1;
00106 
00107         if (len < 1) {
00108 //              free(fData.description);
00109 //              fData.description = 0;
00110                 return;
00111         }
00112         setNote( strdup((char *) buffer) );
00113 
00114         (char*)buffer += strlen(getNote()) + 1;
00115         len -= strlen(getNote()) + 1;
00116 
00117 //      return (buffer - start);        /* FIXME: return real length */
00118 }
00119 
00120 /***********************************************************************
00121  * Function:    pack_ListMaker
00122  * Summary:     Pack the ListMaker records into a structure
00123  * Parmeters:   None
00124  * Returns:     Nothing
00125  ***********************************************************************/
00126 void *PilotListMakerEntry::pack(void *buf, int *len) {
00127         int pos;
00128         int destlen = 13;
00129 
00130         if (getDescription()) destlen += strlen(getDescription());
00131         if (getNote()) destlen += strlen(getNote());
00132 
00133         if (!buf) return NULL;// destlen;
00134         if (*len < destlen) return NULL;// 0;
00135 
00136         ((char*)buf)[0]=0;
00137         ((char*)buf)[1]=0;
00138         ((char*)buf)[2]=0;
00139         ((char*)buf)[3]=0;
00140         ((char*)buf)[4]=0;
00141         if (getFlag(IS_CHECKED)) ((char*)buf)[4]|=0x80;
00142         if (getFlag(IS_EXPANDED)) ((char*)buf)[4]|=0x40;
00143         if (getFlag(HAS_CHILDREN)) ((char*)buf)[4]|=0x20;
00144         if (getFlag(IS_VISIBLE)) ((char*)buf)[4]|=0x10;
00145 //      if(lm->normal) buf[4]|=0x04;
00146         if (getFlag(FLAG_CUSTOM1)) ((char*)buf)[4]|=0x01; else ((char*)buf)[4]|=0x04;
00147         ((char*)buf)[5]=getLevel();
00148         
00149         if (hasDate(DATE_DUE)) {
00150                 QDate due=getDate(DATE_DUE).date();
00151                 set_short((char*)buf+6, ((due.year() - 4) << 9) | ((due.month() + 1) << 5) | due.day());
00152         } else {
00153                 ((char*)buf)[6] = 0xff;
00154                 ((char*)buf)[7] = 0xff;
00155         }
00156         pos = 8;
00157         if (getDescription()) {
00158                 strcpy((char *) buf + pos, getDescription());
00159                 pos += strlen(getDescription()) + 1;
00160         } else {
00161                 ((char*)buf)[pos++] = 0;
00162         }
00163 
00164         if (getNote()) {
00165                 strcpy((char *) buf + pos, getNote());
00166                 pos += strlen(getNote()) + 1;
00167         } else {
00168                 ((char*)buf)[pos++] = 0;
00169         }
00170         ((char*)buf)[pos++]=0;
00171         // don't know what the last two bytes are, so just set them 0
00172         ((char*)buf)[pos++]=0;
00173         ((char*)buf)[pos++]=0;
00174         *len=pos;
00175         return &pos;
00176 }
00177 
00178 
00179 PilotListMakerEntry::PilotListMakerEntry(PilotRecord * rec):PilotOrganizerEntry(rec) {
00180         unpack((unsigned char *) rec->getData(), rec->getLen());
00181         (void) pilotListMakerEntry_id;
00182 }
00183 
00184 
00185 // $Log: pilotListMakerEntry.cc,v $
00186 // Revision 1.1.4.1  2003/03/12 23:31:09  adridg
00187 // CVS_SILENT: FSF address change
00188 //
00189 // Revision 1.1  2002/04/07 12:09:42  kainhofe
00190 // Initial checkin of the conduit. The gui works mostly, but syncing crashes KPilot...
00191 //
00192 // Revision 1.5  2002/04/05 23:35:29  reinhold
00193 // Restructuring the dir structure
00194 //
00195 // Revision 1.4  2002/04/05 21:17:01  reinhold
00196 // *** empty log message ***
00197 //
00198 // Revision 1.3  2002/03/10 23:58:32  reinhold
00199 // Made the conduit compile...
00200 //
00201 // Revision 1.2  2002/03/10 16:06:43  reinhold
00202 // Cleaned up the class hierarchy, implemented some more features (should be quite finished now...)
00203 //
00204 // Revision 1.1  2002/03/09 15:48:32  reinhold
00205 // Added the classes for the different palm database formats
00206 //
00207 //
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:14 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001