00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 #include "showrecord.h"
00019 
00020 int const ShowRecord::continueShowHeaders( 0 );
00021 int const ShowRecord::cancelShowHeaders( 1 );
00022 
00023 ShowRecord::ShowRecord()
00024 {
00025   
00026   
00027   setAutoDelete( true );
00028 }
00029 
00030 ShowRecord::~ShowRecord()
00031 {
00032 }
00033 
00034 void ShowRecord::saveOptions( TQDomDocument& doc, TQDomElement& parent )
00035 {
00036   
00037   for( ShowRecordElem* pElem = first(); pElem; pElem = next() )
00038   {
00039     
00040     pElem->saveOptions( doc, parent );
00041   }
00042 }
00043 
00044 void ShowRecord::readStoredMails( TQDomElement& parent )
00045 {
00046   
00047   clear();
00048 
00049   
00050   TQDomNode n = parent.firstChild();
00051 
00052   
00053   while( !n.isNull() )
00054   {
00055     
00056     TQDomElement e = n.toElement();
00057 
00058     
00059     ShowRecordElem* pElem = new ShowRecordElem();
00060 
00061     
00062     pElem->readOptions( e );
00063 
00064     
00065     append( pElem );
00066 
00067     
00068     n = n.nextSibling();
00069   }
00070 }
00071 
00072 void ShowRecord::applyFilters ()
00073 {
00074   
00075   for( ShowRecordElem* pElem = first(); pElem; pElem = next() )
00076   {
00077     
00078     pElem->applyFilters ();
00079   }
00080 }
00081 
00082 bool ShowRecord::hasSelectedMails( )
00083 {
00084   bool selected = false;    
00085   ShowRecordElem* mail;     
00086 
00087   
00088   mail = first();
00089 
00090   
00091   while( mail != NULL && !selected )
00092   {
00093     
00094     selected = mail->isSelected();
00095 
00096     
00097     mail = next();
00098   }
00099 
00100   return selected;
00101 }
00102 
00103 MailNumberList_Type ShowRecord::getSelectedMails( )
00104 {
00105   MailNumberList_Type list;                     
00106   ShowRecordElem* mail;                         
00107   TQPtrListIterator<ShowRecordElem> it( *this ); 
00108 
00109   
00110   while( ( mail = it.current() ) != NULL )
00111   {
00112     
00113     ++it;
00114 
00115     
00116     if( mail->isSelected() )
00117       list.append( mail->number() );
00118   }
00119 
00120   return list;
00121 }
00122 
00123 void ShowRecord::removeMail( int number )
00124 {
00125   TQPtrListIterator<ShowRecordElem> it( *this );   
00126   ShowRecordElem* mail;                           
00127 
00128   
00129   while( ( mail = it.current() ) != NULL )
00130   {
00131     
00132     ++it;
00133 
00134     
00135     if( mail->number() == number )
00136       remove( mail );
00137   }
00138 }
00139 
00140 TQStringList ShowRecord::getSelectedSubjects( ) const
00141 {
00142   TQStringList subjects;                           
00143   TQPtrListIterator<ShowRecordElem> it( *this );   
00144   ShowRecordElem* mail;                           
00145 
00146   
00147   while( ( mail = it.current() ) != NULL )
00148   {
00149     
00150     ++it;
00151 
00152     
00153     if( mail->isSelected() )
00154       subjects.append( mail->subject() );
00155   }
00156 
00157   return subjects;
00158 }
00159 
00160 TQString ShowRecord::getSenderOf( int number ) const
00161 {
00162   TQPtrListIterator<ShowRecordElem> it( *this );   
00163   ShowRecordElem* mail;                           
00164   bool found = false;                             
00165   TQString sender;                                 
00166 
00167   
00168   while( ( mail = it.current() ) != NULL && !found )
00169   {
00170     
00171     ++it;
00172 
00173     
00174     if( mail->number() == number )
00175     {
00176       sender = mail->from();
00177       found = true;
00178     }
00179   }
00180   return sender;
00181 }
00182 
00183 TQString ShowRecord::getDateOf( int number ) const
00184 {
00185   TQPtrListIterator<ShowRecordElem> it( *this );   
00186   ShowRecordElem* mail;                           
00187   bool found = false;                             
00188   TQString date;                                   
00189 
00190   
00191   while( ( mail = it.current() ) != NULL && !found )
00192   {
00193     
00194     ++it;
00195 
00196     
00197     if( mail->number() == number )
00198     {
00199       date = mail->date();
00200       found = true;
00201     }
00202   }
00203   return date;
00204 
00205 }
00206 
00207 TQString ShowRecord::getSizeOf( int number ) const
00208 {
00209   TQPtrListIterator<ShowRecordElem> it( *this );   
00210   ShowRecordElem* mail;                           
00211   bool found = false;                             
00212   TQString size;                                   
00213 
00214   
00215   while( ( mail = it.current() ) != NULL && !found )
00216   {
00217     
00218     ++it;
00219 
00220     
00221     if( mail->number() == number )
00222     {
00223       size = mail->strSizePrefix();
00224       found = true;
00225     }
00226   }
00227   return size;
00228 
00229 }
00230 
00231 TQString ShowRecord::getSubjectOf( int number ) const
00232 {
00233   TQPtrListIterator<ShowRecordElem> it( *this );   
00234   ShowRecordElem* mail;                           
00235   bool found = false;                             
00236   TQString subject;                                
00237 
00238   
00239   while( ( mail = it.current() ) != NULL && !found )
00240   {
00241     
00242     ++it;
00243 
00244     
00245     if( mail->number() == number )
00246     {
00247       subject = mail->subject();
00248       found = true;
00249     }
00250   }
00251   return subject;
00252 
00253 }
00254 
00255 TQString ShowRecord::decodeMailBody( TQByteArray body, int number, bool preferHTML ) const
00256 {
00257   TQPtrListIterator<ShowRecordElem> it( *this );   
00258   ShowRecordElem* mail;                           
00259   bool found = false;                             
00260   TQString mailbody;                               
00261 
00262   
00263   while( ( mail = it.current() ) != NULL && !found )
00264   {
00265     
00266     ++it;
00267 
00268     
00269     if( mail->number() == number )
00270     {
00271       mailbody = mail->decodeMailBody( body, preferHTML );
00272       found = true;
00273     }
00274   }
00275   return mailbody;
00276 
00277 }
00278 
00279 bool ShowRecord::hasMail( TQString uid )
00280 {
00281   TQPtrListIterator<ShowRecordElem> it( *this );   
00282   ShowRecordElem* mail;                           
00283   bool found = false;                             
00284 
00285   while( ( mail = it.current() ) != NULL && !found )
00286   {
00287     
00288     ++it;
00289 
00290     
00291     if( mail->uidl() == uid )
00292     {
00293      found = true;
00294     }
00295   }
00296   return found;
00297 }
00298 
00299 void ShowRecord::appendNewMail( int number, TQString uid, bool isNew )
00300 {
00301   
00302   ShowRecordElem* newMail = new ShowRecordElem( number, uid, isNew );
00303 
00304   
00305   if( newMail != NULL )
00306     append( newMail );
00307 }
00308 
00309 void ShowRecord::printMailList( )
00310 {
00311   TQPtrListIterator<ShowRecordElem> it( *this );   
00312   ShowRecordElem* mail;                           
00313 
00314   while( ( mail = it.current() ) )
00315   {
00316     
00317     ++it;
00318 
00319     
00320     cout << mail->number() << " - UID: " << mail->uidl() << "; Size: " << mail->size() << "; Subject: " << mail->subject() << "; New: " << mail->isNew() << endl;
00321   }
00322 
00323 }
00324 
00325 void ShowRecord::setSize( int number, long size )
00326 {
00327   TQPtrListIterator<ShowRecordElem> it( *this );   
00328   ShowRecordElem* mail;                           
00329   bool found = false;                             
00330 
00331   
00332   while( ( mail = it.current() ) != NULL && !found )
00333   {
00334     
00335     ++it;
00336 
00337     
00338     if( mail->number() == number )
00339     {
00340       mail->setSize( size );
00341       found = true;
00342     }
00343   }
00344 }
00345 
00346 Types::MailNumberList_Type ShowRecord::getNewMails( )
00347 {
00348   MailNumberList_Type list;                     
00349   ShowRecordElem* mail;                         
00350   TQPtrListIterator<ShowRecordElem> it( *this ); 
00351 
00352   
00353   while( ( mail = it.current() ) != NULL )
00354   {
00355     
00356     ++it;
00357 
00358     
00359     if( mail->isNew() )
00360       list.append( mail->number() );
00361   }
00362 
00363   return list;
00364 }
00365 
00366 void ShowRecord::setHeader( int number, TQString header )
00367 {
00368   TQPtrListIterator<ShowRecordElem> it( *this );   
00369   ShowRecordElem* mail;                           
00370   bool found = false;                             
00371 
00372   
00373   while( ( mail = it.current() ) != NULL && !found )
00374   {
00375     
00376     ++it;
00377 
00378     
00379     if( mail->number() == number )
00380     {
00381       mail->setHeader( header );
00382       found = true;
00383     }
00384   }
00385 }
00386 
00387 TQStringList ShowRecord::getUIDsOfOldMails( )
00388 {
00389   TQStringList list;                             
00390   ShowRecordElem* mail;                         
00391   TQPtrListIterator<ShowRecordElem> it( *this ); 
00392 
00393   
00394   while( ( mail = it.current() ) != NULL )
00395   {
00396     
00397     ++it;
00398 
00399     
00400     if( !mail->isNew() )
00401       list.append( mail->uidl() );
00402   }
00403 
00404   return list;
00405 }
00406 
00407 TQString ShowRecord::getHeaderOf( TQString uid )
00408 {
00409   TQPtrListIterator<ShowRecordElem> it( *this );   
00410   ShowRecordElem* mail;                           
00411   bool found = false;                             
00412   TQString header;                                 
00413 
00414   
00415   while( ( mail = it.current() ) != NULL && !found )
00416   {
00417     
00418     ++it;
00419 
00420     
00421     if( mail->uidl() == uid )
00422     {
00423       header = mail->header();
00424       found = true;
00425     }
00426   }
00427   return header;
00428 }
00429 
00430 void ShowRecord::setHeader( TQString uid, TQString header )
00431 {
00432   TQPtrListIterator<ShowRecordElem> it( *this );   
00433   ShowRecordElem* mail;                           
00434   bool found = false;                             
00435 
00436   
00437   while( ( mail = it.current() ) != NULL && !found )
00438   {
00439     
00440     ++it;
00441 
00442     
00443     if( mail->uidl() == uid )
00444     {
00445       mail->setHeader( header );
00446       found = true;
00447     }
00448   }
00449 }
00450 
00451 int ShowRecord::getNumberNewMails( )
00452 {
00453   TQPtrListIterator<ShowRecordElem> it( *this );   
00454   ShowRecordElem* mail;                           
00455   int number = 0;                                 
00456 
00457   while( ( mail = it.current() ) )
00458   {
00459     
00460     ++it;
00461 
00462     
00463     if( mail->isNew() )
00464       number++;
00465   }
00466 
00467   return number;
00468 }
00469 
00470 int ShowRecord::getNumberMails( )
00471 {
00472   return count();
00473 }
00474 
00475 long ShowRecord::getTotalSize( )
00476 {
00477   TQPtrListIterator<ShowRecordElem> it( *this );   
00478   ShowRecordElem* mail;                           
00479   long size = 0;                                   
00480 
00481   while( ( mail = it.current() ) )
00482   {
00483     
00484     ++it;
00485 
00486     size += mail->size();
00487   }
00488 
00489   return size;
00490 }
00491 
00492 void ShowRecord::fillMailListView( KshowmailView * view, TQString & account )
00493 {
00494   TQPtrListIterator<ShowRecordElem> it( *this );   
00495   ShowRecordElem* mail;                           
00496 
00497   
00498   while( ( mail = it.current() ) )
00499   {
00500     
00501     ++it;
00502 
00503     
00504     TQString number = TQString( "%1" ).arg( mail->number() );
00505     TQString from = mail->from();
00506     TQString to = mail->to();
00507     TQString subject = mail->subject();
00508     TQString date = mail->date();
00509     TQString size = TQString( "%1" ).arg( mail->size() );
00510     TQString content = mail->content();
00511     TQString state = mail->state();
00512     TQString time = mail->strUnixTime();
00513     mail->setViewItem( view->insertMail( number, account, from, to, subject, date, size, content, state, time ) );
00514   }
00515 
00516 }
00517 
00518 int ShowRecord::showSelectedHeaders( TQString& account )
00519 {
00520   TQPtrListIterator<ShowRecordElem> it( *this );   
00521   ShowRecordElem* mail;                           
00522   int showNextHeader = ShowRecordElem::continueShowHeaders; 
00523 
00524   while( ( mail = it.current() ) && showNextHeader == ShowRecordElem::continueShowHeaders )
00525   {
00526     
00527     ++it;
00528 
00529     
00530     if( mail->isSelected() )
00531       showNextHeader = mail->showHeader( account );
00532   }
00533 
00534   return showNextHeader == ShowRecordElem::continueShowHeaders ? ShowRecord::continueShowHeaders : ShowRecord::cancelShowHeaders;
00535 }
00536 
00537 bool ShowRecord::isNew( TQString uid ) const
00538 {
00539   TQPtrListIterator<ShowRecordElem> it( *this );   
00540   ShowRecordElem* mail;                           
00541   bool found = false;                             
00542   bool newMail = false;                           
00543 
00544   while( ( mail = it.current() ) != NULL && !found )
00545   {
00546     
00547     ++it;
00548 
00549     
00550     if( mail->uidl() == uid )
00551     {
00552       found = true;
00553       newMail = mail->isNew();
00554     }
00555   }
00556 
00557   return newMail;
00558 }