[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kmail-devel
Subject:    Re: [Knode-devel] Re: KNode development status
From:       Marc Mutz <mutz () kde ! org>
Date:       2002-12-01 12:37:37
[Download RAW message or body]

On Saturday 30 November 2002 18:52, Ingo Klöcker wrote:
> Yeah, that's the problem. I currently don't know whether it makes
> sense to work on the common KReaderWidget without having common
> message classes since a lot of code in the KReaderWidget involves
> parsing of the message. Maybe someone else can comment on this.

That's a simple question: Refactor both classes until you've separated 
message-class-dependent code from message-class independent code into 
different methods, then extract a common subclass.

Simple aritficial example:

KNode:
  QStringList lines = m_essage->body()->lines();
  mHtmlBuffer = QString::null;
  for ( QStringListIterator it = lines.begin() ;
        it != lines.end() ; ++it ) {
    QString line = *it;
    // do text markup with HTML...
    mHtmlBuffer += line;
  }

KMail:
  QString bodytext = mMsg->bodyAsText();
  int lastPos = -1;
  for ( int pos = 0 ; ( pos = bodytext.find( '\n', pos ) ; ) {
    QString line = bodyText.mid( lastPort + 1, pos - lastPos -1 );
    // do quote markup and convert to HTML
    queueHTML( line + "<br/>" );
  }

would become:

libkdenetwork:
  doPrepareQueuedHTML();
  QStringList lines = lines();
  for ( QStringListIterator it = lines.begin() ;
        it != lines.end() ; ++it )
    queueHTML( doHTMLMarkUpOnLine( *it ) );
  doSendQueuedHTML();

KNode:
  void doPrepareQueuedHTML() {
    if ( mHtmlBuffer.isEmpty() ) return;

    doSendQueuedHTML();
    mHtmlBuffer = QString::null;
  }

  QStringList lines() const {
    return m_essage->body()->lines();
  }

  QString doHTMLMarkUpForLine( const QString & s ) {
     // ...
  }

  void queueHTML( const QString & s ) {
    mHtmlBuffer += s;
  }

  void doSendQueuedHTML() {
    mViewer->queueHTML( mHtmlBuffer );
  }

KMail:
  void doprepareQueuedHTML() {}

  QStringList lines() const {
    QString bodytext = mMsg->bodyAsText();
    return bodytext.split( '\n' );
  }

  QString doHTMLMarkUpForLine( const QString & s ) {
    // ...
  }

  void doSendQueuedHTML() { }

  void queueHTML( const QString & s ) {
    mHtmlPart->append( s );
  }

Then, break up doHTMLMarkupForLine() the same way and push common code 
into the superclass. And so on. Don't forget to have a folder with test 
mails handy.

Oh, forget about that. That's not the way it works here, is it? :-(((

Marc

-- 
memAlloc() Amnesia Error: Out of Memory

[Attachment #3 (application/pgp-signature)]
_______________________________________________
KMail Developers mailing list
kmail@mail.kde.org
http://mail.kde.org/mailman/listinfo/kmail

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic