kaddressbook Library API Documentation

pab_pablib.cpp

00001 /*************************************************************************** 00002 pablib.cxx - description 00003 ------------------- 00004 begin : Tue Jul 4 2000 00005 copyright : (C) 2000 by Hans Dijkema 00006 email : kmailcvt@hum.org 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #include "pab_pablib.h" 00019 00020 #define REC_OK PAB_REC_OK 00021 00022 00023 pab::pab(const char *_pabfile) 00024 { 00025 pabfile=_pabfile; 00026 in.setName(pabfile); 00027 in.open(IO_ReadOnly); 00028 cap=i18n("Import MS Exchange Personal Addressbook (.PAB)"); 00029 } 00030 00031 00032 pab::~pab() 00033 { 00034 if (in.isOpen()) { in.close(); } 00035 } 00036 00038 // 00039 // Main conversion 00040 // 00042 00043 bool pab::convert(void) 00044 { 00045 adr_t A; 00046 bool ret; 00047 00048 if (!in.isOpen()) {QString msg; 00049 msg=i18n("Can't open %1 for reading").arg(pabfile); 00050 // info->alert(msg); 00051 return false; 00052 } 00053 if (!knownPAB()) { 00054 return false; 00055 } 00056 00057 /* 00058 if (!f->openAddressBook(info)) { 00059 return false; 00060 } 00061 */ 00062 00063 A=go(INDEX_OF_INDEX); 00064 ret=convert(A,0,0); 00065 00066 // f->closeAddressBook(); 00067 00068 return ret; 00069 } 00070 00071 bool pab::convert(adr_t A,content_t ,content_t ) 00072 { 00073 adr_t table; 00074 content_t start,stop,T; 00075 int N,n; 00076 00077 N=0; 00078 go(A); 00079 T=read(); 00080 00081 // Now we have to decide if this is a distribution list 00082 // or an addressbook container. If it is the last just 00083 // jump directly to dotable(). 00084 00085 //if (upper(T)==PAB_REC_OK) { 00086 // dotable(A,strt,stp); 00087 // return true; 00088 //} 00089 00090 // OK, it's not an addressbook container, 00091 // handle it like a distribution list 00092 00093 start=T; 00094 while(start!=0) { 00095 N+=1; 00096 stop=read(); 00097 table=read(); 00098 start=read(); 00099 } 00100 if (N==0) { N=1; } 00101 /* {char m[100]; 00102 sprintf(m,"%d",N); 00103 info->alert("",m); 00104 }*/ 00105 00106 //A=go(INDEX_OF_INDEX); 00107 //printf("IoI=%08lx\n",A); 00108 go(A); 00109 start=read(); 00110 n=0; 00111 while(start!=0) {adr_t cp; 00112 stop=read(); 00113 table=read(); 00114 cp=tell(); 00115 dotable(table,start,stop); 00116 //convert(table,start,stop); 00117 go(cp); 00118 start=read(); 00119 n+=1; 00120 // info->setOverall( 100 * n / N ); 00121 } 00122 00123 return true; 00124 } 00125 00126 00127 void pab::dotable(adr_t T,content_t start,content_t stop) 00128 { 00129 adr_t REC,pREC,cp; 00130 content_t cmp,skip; 00131 int N,n; 00132 00133 go(T); 00134 cp=tell(); 00135 00136 REC=0xffffffff; 00137 pREC=0; 00138 cmp=read(); 00139 if (cmp!=start) { 00140 // first try processing as if this was a record. I.e. at the stop thing 00141 processRec(stop); 00142 // Then exit 00143 // info->setCurrent(); 00144 // info->setCurrent(100); 00145 return; 00146 } // This is not a table. 00147 00148 // info->setCurrent(); 00149 N=0; 00150 while (cmp!=stop && REC!=pREC) { 00151 pREC=REC; 00152 REC=read(); 00153 if (REC!=pREC) { 00154 skip=read(); 00155 cmp=read(); 00156 } 00157 N+=1; 00158 } 00159 00160 go(cp); 00161 REC=0xffffffff; 00162 pREC=0; 00163 00164 cmp=read(); 00165 00166 n=0; 00167 while(cmp!=stop && REC!=pREC) {adr_t cp; 00168 pREC=REC; 00169 REC=read(); 00170 if (REC!=pREC) { 00171 skip=read(); 00172 cp=tell(); 00173 processRec(REC); 00174 go(cp); 00175 cmp=read(); 00176 } 00177 n+=1; 00178 // info->setCurrent(100 * n / N); 00179 } 00180 00181 // info->setCurrent(); 00182 // info->setCurrent(100); 00183 } 00184 00185 00186 void pab::processRec(adr_t REC) 00187 { 00188 content_t hdr; 00189 00190 hdr=go(REC); 00191 if (upper(hdr)==REC_OK) { // Now read a record and instantiate! 00192 pabrec rec(*this); 00193 pabfields_t fields(rec, NULL); 00194 00195 if (fields.isOK() && fields.isUsable()) { 00196 // f->addContact( fields.get() ); 00197 } 00198 } 00199 } 00200 00201 void pab::prt(unsigned char *,pabrec &,pabrec_entry ) 00202 { 00203 } 00204 00205 #define PABREC_N (sizeof(pabrec)/sizeof(word_t)) 00206 00207 void pab::rdPabRec(pabrec & ) 00208 { 00209 } 00210 00212 // 00213 // Here's where we recognize the record types 00214 // 00216 00217 bool pab::recUnknown(pabrec &) 00218 { 00219 return false; 00220 } 00221 00222 bool pab::recNoFunction(pabrec & ) 00223 { 00224 return false; 00225 } 00226 00227 const char *pab::get(unsigned char *,pabrec_entry ,pabrec & ) 00228 { 00229 return ""; 00230 } 00231 00232 void pab::getrange(pabrec & ,pabrec_entry ,word_t & ,word_t & ) 00233 { 00234 } 00235 00237 // 00238 // Here's where we recognize the PAB files 00239 // 00241 00242 bool pab::knownPAB(void) 00243 { 00244 content_t id; 00245 id=go(0); 00246 if (id!=PAB_FILE_ID) {QString msg; 00247 msg=i18n("%1 has no PAB id that I know of, can't convert this").arg(pabfile); 00248 // info->alert(msg); 00249 return false; 00250 } 00251 return true; 00252 } 00253 00254 00256 // 00257 // Functions to do file reading/positioning 00258 // 00260 00261 content_t pab::go(adr_t a) 00262 { 00263 content_t A; 00264 in.at(a); 00265 A=read(); 00266 in.at(a); 00267 return A; 00268 } 00269 00270 content_t pab::read(void) 00271 { 00272 unsigned char mem[4]; 00273 content_t A; 00274 in.readBlock((char *) &mem, sizeof(A)); // WinTel unsigned long opslag 00275 A=mem[3]; 00276 A<<=8;A|=mem[2]; 00277 A<<=8;A|=mem[1]; 00278 A<<=8;A|=mem[0]; 00279 return A; 00280 } 00281 00282 void pab::read(word_t & w) 00283 { 00284 unsigned char mem[2]; 00285 in.readBlock((char *) &mem, sizeof(w)); 00286 w=mem[1]; 00287 w<<=8;w|=mem[0]; 00288 } 00289 00290 content_t pab::relative(int words) 00291 { 00292 adr_t a; 00293 a=in.at(); 00294 return go(a+(words*sizeof(content_t))); 00295 } 00296 00297 content_t pab::add(adr_t & A,int words) 00298 { 00299 A+=(words*sizeof(content_t)); 00300 return go(A); 00301 } 00302 00303 pabsize_t pab::size(content_t A) 00304 { 00305 return A&0xFFFF; 00306 } 00307 00308 word_t pab::lower(content_t A) 00309 { 00310 return A&0xFFFF; 00311 } 00312 00313 word_t pab::upper(content_t A) 00314 { 00315 return A>>16; 00316 } 00317 00318 void pab::size(content_t A,pabsize_t & s1,pabsize_t & s2) 00319 { 00320 s1=A&0xFFFF; 00321 s2>>=16; 00322 } 00323 00324 byte_t pab::readbyte(void) 00325 { 00326 byte_t c; 00327 c=in.getch(); 00328 return c; 00329 } 00330 00331 void pab::read(unsigned char *mem,content_t size) 00332 { 00333 in.readBlock((char *) mem, size); 00334 }
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:08 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003