kaddressbook

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 Address Book (.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("Cannot 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 = 0;
00076 
00077    go(A);
00078    T=read();
00079 
00080    // Now we have to decide if this is a distribution list
00081    // or an addressbook container. If it is the last just
00082    // jump directly to dotable().
00083 
00084    //if (upper(T)==PAB_REC_OK) {
00085    //  dotable(A,strt,stp);
00086    //  return true;
00087    //}
00088 
00089    // OK, it's not an addressbook container,
00090    // handle it like a distribution list
00091 
00092    start=T;
00093    while(start!=0) {
00094      N+=1;
00095      stop=read();
00096      table=read();
00097      start=read();
00098    }
00099    if (N==0) { N=1; }
00100 /*   {char m[100];
00101      sprintf(m,"%d",N);
00102      info->alert("",m);
00103    }*/
00104 
00105    //A=go(INDEX_OF_INDEX);
00106    //printf("IoI=%08lx\n",A);
00107    go(A);
00108    start=read();
00109    n=0;
00110    while(start!=0) {adr_t cp;
00111      stop=read();
00112      table=read();
00113      cp=tell();
00114      dotable(table,start,stop);
00115      //convert(table,start,stop);
00116      go(cp);
00117      start=read();
00118      n+=1;
00119      // info->setOverall( 100 * n / N );
00120    }
00121 
00122 return true;
00123 }
00124 
00125 
00126 void pab::dotable(adr_t T,content_t start,content_t stop)
00127 {
00128 adr_t REC,pREC,cp;
00129 content_t cmp,skip;
00130 int   N,n;
00131 
00132   go(T);
00133   cp=tell();
00134 
00135   REC=0xffffffff;
00136   pREC=0;
00137   cmp=read();
00138   if (cmp!=start) {
00139     // first try processing as if this was a record. I.e. at the stop thing
00140     processRec(stop);
00141     // Then exit
00142     // info->setCurrent();
00143     // info->setCurrent(100);
00144     return;
00145   }   // This is not a table.
00146 
00147   // info->setCurrent();
00148   N=0;
00149   while (cmp!=stop && REC!=pREC) {
00150     pREC=REC;
00151     REC=read();
00152     if (REC!=pREC) {
00153       skip=read();
00154       cmp=read();
00155     }
00156     N+=1;
00157   }
00158 
00159   go(cp);
00160   REC=0xffffffff;
00161   pREC=0;
00162 
00163   cmp=read();
00164 
00165   n=0;
00166   while(cmp!=stop && REC!=pREC) {adr_t cp;
00167     pREC=REC;
00168     REC=read();
00169     if (REC!=pREC) {
00170       skip=read();
00171       cp=tell();
00172       processRec(REC);
00173       go(cp);
00174       cmp=read();
00175     }
00176     n+=1;
00177     // info->setCurrent(100 * n / N);
00178   }
00179 
00180   // info->setCurrent();
00181   // info->setCurrent(100);
00182 }
00183 
00184 
00185 void pab::processRec(adr_t REC)
00186 {
00187 content_t hdr;
00188 
00189    hdr=go(REC);
00190    if (upper(hdr)==REC_OK) {    // Now read a record and instantiate!
00191      pabrec       rec(*this);
00192      pabfields_t  fields(rec, NULL);
00193 
00194      if (fields.isOK() && fields.isUsable()) {
00195        // f->addContact( fields.get() );
00196       }
00197    }
00198 }
00199 
00200 void pab::prt(unsigned char *,pabrec &,pabrec_entry )
00201 {
00202 }
00203 
00204 #define PABREC_N (sizeof(pabrec)/sizeof(word_t))
00205 
00206 void pab::rdPabRec(pabrec & )
00207 {
00208 }
00209 
00211 //
00212 // Here's where we recognize the record types
00213 //
00215 
00216 bool  pab::recUnknown(pabrec &)
00217 {
00218 return false;
00219 }
00220 
00221 bool  pab::recNoFunction(pabrec & )
00222 {
00223 return false;
00224 }
00225 
00226 const char *pab::get(unsigned char *,pabrec_entry ,pabrec & )
00227 {
00228 return "";
00229 }
00230 
00231 void pab::getrange(pabrec & ,pabrec_entry ,word_t & ,word_t & )
00232 {
00233 }
00234 
00236 //
00237 // Here's where we recognize the PAB files
00238 //
00240 
00241 bool pab::knownPAB(void)
00242 {
00243 content_t id;
00244    id=go(0);
00245    if (id!=PAB_FILE_ID) {QString msg;
00246      msg=i18n("%1 has no PAB id that I know of, cannot convert this").arg(pabfile);
00247      // info->alert(msg);
00248      return false;
00249    }
00250 return true;
00251 }
00252 
00253 
00255 //
00256 // Functions to do file reading/positioning
00257 //
00259 
00260 content_t pab::go(adr_t a)
00261 {
00262 content_t A;
00263   in.at(a);
00264   A=read();
00265   in.at(a);
00266 return A;
00267 }
00268 
00269 content_t pab::read(void)
00270 {
00271 unsigned char mem[4];
00272 content_t A;
00273   in.readBlock((char *) &mem, sizeof(A));   // WinTel unsigned long opslag
00274   A=mem[3];
00275   A<<=8;A|=mem[2];
00276   A<<=8;A|=mem[1];
00277   A<<=8;A|=mem[0];
00278 return A;
00279 }
00280 
00281 void pab::read(word_t & w)
00282 {
00283 unsigned char mem[2];
00284   in.readBlock((char *) &mem, sizeof(w));
00285   w=mem[1];
00286   w<<=8;w|=mem[0];
00287 }
00288 
00289 content_t pab::relative(int words)
00290 {
00291 adr_t     a;
00292   a=in.at();
00293 return go(a+(words*sizeof(content_t)));
00294 }
00295 
00296 content_t pab::add(adr_t & A,int words)
00297 {
00298   A+=(words*sizeof(content_t));
00299 return go(A);
00300 }
00301 
00302 pabsize_t pab::size(content_t A)
00303 {
00304 return A&0xFFFF;
00305 }
00306 
00307 word_t pab::lower(content_t A)
00308 {
00309 return A&0xFFFF;
00310 }
00311 
00312 word_t pab::upper(content_t A)
00313 {
00314 return A>>16;
00315 }
00316 
00317 void pab::size(content_t A,pabsize_t & s1,pabsize_t & s2)
00318 {
00319   s1=A&0xFFFF;
00320   s2>>=16;
00321 }
00322 
00323 byte_t pab::readbyte(void)
00324 {
00325 byte_t c;
00326     c=in.getch();
00327 return c;
00328 }
00329 
00330 void pab::read(unsigned char *mem,content_t size)
00331 {
00332   in.readBlock((char *) mem, size);
00333 }
KDE Home | KDE Accessibility Home | Description of Access Keys