kpilot Library API Documentation

pilotRecord.cc

00001 /* pilotRecord.cc KPilot 00002 ** 00003 ** Copyright (C) 1998-2001 by Dan Pilone 00004 ** 00005 ** This is a wrapper for pilot-link's general 00006 ** Pilot database structures. These records are 00007 *** just collections of bits. See PilotAppCategory 00008 ** for interpreting the bits in a meaningful way. 00009 ** 00010 ** As a crufty hack, the non-inline parts of 00011 ** PilotAppCategory live in this file as well. 00012 */ 00013 00014 /* 00015 ** This program is free software; you can redistribute it and/or modify 00016 ** it under the terms of the GNU Lesser General Public License as published by 00017 ** the Free Software Foundation; either version 2.1 of the License, or 00018 ** (at your option) any later version. 00019 ** 00020 ** This program is distributed in the hope that it will be useful, 00021 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 ** GNU Lesser General Public License for more details. 00024 ** 00025 ** You should have received a copy of the GNU Lesser General Public License 00026 ** along with this program in a file called COPYING; if not, write to 00027 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00028 ** MA 02111-1307, USA. 00029 */ 00030 00031 /* 00032 ** Bug reports and questions can be sent to kde-pim@kde.org 00033 */ 00034 #include "options.h" 00035 00036 #include <string.h> 00037 00038 #include <qtextcodec.h> 00039 #include <qregexp.h> 00040 00041 // PilotAppCategory includes pilotRecord and we 00042 // provide its implementation here as well. 00043 // 00044 #include "pilotAppCategory.h" 00045 00046 00047 00048 static const char *pilotRecord_id = 00049 "$Id: pilotRecord.cc,v 1.10 2003/05/29 07:01:20 kainhofe Exp $"; 00050 00051 /* static */ int PilotRecord::fAllocated = 0; 00052 /* static */ int PilotRecord::fDeleted = 0; 00053 00054 /* static */ void PilotRecord::allocationInfo() 00055 { 00056 #ifdef DEBUG 00057 FUNCTIONSETUP; 00058 DEBUGKPILOT << fname 00059 << ": Allocated " << fAllocated 00060 << " Deleted " << fDeleted; 00061 #endif 00062 } 00063 00064 PilotRecord::PilotRecord(void *data, int len, int attrib, int cat, 00065 pi_uid_t uid) : 00066 fData(0L), 00067 fLen(len), 00068 fAttrib(attrib), 00069 fCat(cat), 00070 fID(uid) 00071 { 00072 FUNCTIONSETUP; 00073 fData = new char[len]; 00074 00075 memcpy(fData, data, len); 00076 00077 fAllocated++; 00078 (void) pilotRecord_id; 00079 } 00080 00081 PilotRecord::PilotRecord(PilotRecord * orig) 00082 { 00083 FUNCTIONSETUP; 00084 fData = new char[orig->getLen()]; 00085 00086 memcpy(fData, orig->getData(), orig->getLen()); 00087 fLen = orig->getLen(); 00088 fAttrib = orig->getAttrib(); 00089 fCat = orig->getCat(); 00090 fID = orig->getID(); 00091 00092 fAllocated++; 00093 } 00094 00095 PilotRecord & PilotRecord::operator = (PilotRecord & orig) 00096 { 00097 FUNCTIONSETUP; 00098 if (fData) 00099 delete[]fData; 00100 fData = new char[orig.getLen()]; 00101 00102 memcpy(fData, orig.getData(), orig.getLen()); 00103 fLen = orig.getLen(); 00104 fAttrib = orig.getAttrib(); 00105 fCat = orig.getCat(); 00106 fID = orig.getID(); 00107 return *this; 00108 } 00109 00110 void PilotRecord::setData(const char *data, int len) 00111 { 00112 FUNCTIONSETUP; 00113 if (fData) 00114 delete[]fData; 00115 fData = new char[len]; 00116 00117 memcpy(fData, data, len); 00118 fLen = len; 00119 } 00120 00121 00122 /* static */ QTextCodec *PilotAppCategory::pilotCodec = 0L; 00123 00124 static const char *latin1 = "ISO8859-1" ; 00125 // Other names of encodings are in the config dialog source 00126 00127 /* static */ QTextCodec *PilotAppCategory::createCodec(const char *p) 00128 { 00129 FUNCTIONSETUP; 00130 00131 if (!p) p=latin1; 00132 #ifdef DEBUG 00133 DEBUGKPILOT << ": Creating codec for " << p << endl; 00134 #endif 00135 QTextCodec *q = QTextCodec::codecForName(p); 00136 if (!q) q = QTextCodec::codecForName(latin1); 00137 pilotCodec = q; 00138 return q; 00139 } 00140 00141 /* static */ QTextCodec *PilotAppCategory::setupPilotCodec(const QString &s) 00142 { 00143 FUNCTIONSETUP; 00144 QString cdc(s); 00145 00146 #ifdef DEBUG 00147 DEBUGKPILOT << fname 00148 << ": Creating codec " << cdc << endl; 00149 #endif 00150 // the codec can also be of the form "Description (codec)", so 00151 // if it matches the regexp ".*\\((.*)\\).*", use just the 00152 // value between the brackets. 00153 cdc.replace(QRegExp(".*\\((.*)\\).*"), "\\1"); 00154 00155 const char *p = 0L; 00156 // This latin1() is OK. The names of the encodings 00157 // as shown in the table in the QTextCodec docs 00158 // are all US-ASCII. 00159 if (!cdc.isEmpty()) p=cdc.latin1(); 00160 00161 (void) PilotAppCategory::createCodec(p); 00162 00163 #ifdef DEBUG 00164 DEBUGKPILOT << fname 00165 << ": Got codec " << codecName().latin1() << " for setting " 00166 << s.latin1() << endl; 00167 #endif 00168 return codec(); 00169 } 00170 00171 /* static */ QString PilotAppCategory::codecName() 00172 { 00173 return codec()->name(); 00174 }
KDE Logo
This file is part of the documentation for kpilot Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:57:49 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003