kpilot

pilotDOCEntry.cc

Go to the documentation of this file.
00001 /* KPilot
00002 **
00003 ** Copyright (C) 2002 by Reinhold Kainhofer
00004 **
00005 ** This is a C++ class dealing with PalmDOC text records
00006 */
00007 
00008 /*
00009 ** This program is free software; you can redistribute it and/or modify
00010 ** it under the terms of the GNU General Public License as published by
00011 ** the Free Software Foundation; either version 2 of the License, or
00012 ** (at your option) any later version.
00013 **
00014 ** This program is distributed in the hope that it will be useful,
00015 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017 ** GNU General Public License for more details.
00018 **
00019 ** You should have received a copy of the GNU General Public License
00020 ** along with this program in a file called COPYING; if not, write to
00021 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00022 ** MA 02110-1301, USA.
00023 */
00024 
00025 /*
00026 ** Bug reports and questions can be sent to kde-pim@kde.org
00027 */
00028 
00029 #include "options.h"
00030 #include "pilotDOCEntry.h"
00031 
00032 
00033 
00034 const int PilotDOCEntry::TEXT_SIZE = 4096;
00035 
00036 
00037 PilotDOCEntry::PilotDOCEntry():PilotRecordBase()
00038 {
00039     FUNCTIONSETUP;
00040     compress = false;
00041 }
00042 
00043 
00044 
00045 /* initialize the entry from another one. If rec==NULL, this constructor does the same as PilotDOCEntry()
00046 */
00047 PilotDOCEntry::PilotDOCEntry(PilotRecord * rec, bool compressed):PilotRecordBase(rec)
00048 {
00049     if (rec) fText.setText((unsigned char *) rec->data(), rec->size(), compressed);
00050     compress = compressed;
00051 }
00052 
00053 
00054 
00055 PilotDOCEntry::PilotDOCEntry(const PilotDOCEntry & e):PilotRecordBase(e)
00056 {
00057     FUNCTIONSETUP;
00058     // See PilotDateEntry::operator = for details
00059     fText.setText(e.fText.text(), e.fText.Len(), e.fText.compressed());
00060     compress = e.compress;
00061 }
00062 
00063 
00064 
00065 PilotDOCEntry & PilotDOCEntry::operator =(const PilotDOCEntry & e)
00066 {
00067     if (this != &e)
00068     {
00069         fText.setText(e.fText.text(), e.fText.Len(), e.fText.compressed());
00070         compress = e.compress;
00071     }
00072     return *this;
00073 }
00074 
00075 
00076 
00077 
00078 PilotRecord *PilotDOCEntry::pack()
00079 {
00080     int len = compress ? fText.Compress() : fText.Decompress();
00081 
00082     if (len<0)
00083     {
00084         return 0L;
00085     }
00086 
00087     pi_buffer_t *b = pi_buffer_new( len + 4 ); // +4 for safety
00088     memcpy( b->data, (const char *) fText.text(), len );
00089     b->used = len;
00090     PilotRecord* rec =  new PilotRecord(b, this);
00091     return rec;
00092 }