Summary: | possible memory leak in View Source | ||
---|---|---|---|
Product: | [Unmaintained] kmail | Reporter: | Ingo Klöcker <kloecker> |
Component: | GUI | Assignee: | kdepim bugs <kdepim-bugs> |
Status: | RESOLVED FIXED | ||
Severity: | major | ||
Priority: | NOR | ||
Version: | 1.6 | ||
Target Milestone: | --- | ||
Platform: | unspecified | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: |
Description
Ingo Klöcker
2004-01-28 17:36:36 UTC
Subject: kdepim/kmail CVS commit by tilladam: Fix memory usage problems with "view source" by: o not leaking the text highlighter o checking the mail size and going to Qt::LogText mode for mails > 500kb because the rich text mode is very inefficient and uses about 15 bytes per character. This loses the boldification of headers before the : for large mails, but I guess that's preferrable to using massive amounts of memory. Thanks to tronical for Qt consulting. :) CCMAIL: 73692-done@bugs.kde.org M +26 -19 mailsourceviewer.cpp 1.6 M +15 -0 mailsourceviewer.h 1.5 --- kdepim/kmail/mailsourceviewer.cpp #1.5:1.6 @@ -41,15 +41,8 @@ #include <qregexp.h> #include <qaccel.h> -#include <qsyntaxhighlighter.h> namespace KMail { -class MailSourceHighlighter : public QSyntaxHighlighter -{ -public: - MailSourceHighlighter( QTextEdit* edit ) - : QSyntaxHighlighter( edit ) - {} - int highlightParagraph( const QString& text, int ) { +int MailSourceHighlighter::highlightParagraph( const QString& text, int ) { QRegExp regexp( "^([\\w-]+:\\s)" ); if( regexp.search( text ) != -1 ) { @@ -59,18 +52,32 @@ public: } return 0; - } -}; +} MailSourceViewer::MailSourceViewer( QWidget *parent, const char *name ) - : KTextBrowser( parent, name ) + : KTextBrowser( parent, name ), mSourceHighLighter( 0 ) { setWFlags( WDestructiveClose ); QAccel *accel = new QAccel( this, "browser close-accel" ); accel->connectItem( accel->insertItem( Qt::Key_Escape ), this , SLOT( close() )); - setTextFormat( Qt::PlainText ); setWordWrap( KTextBrowser::NoWrap ); - new MailSourceHighlighter( this ); KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon()); } +MailSourceViewer::~MailSourceViewer() +{ + if ( mSourceHighLighter != 0 ) + delete mSourceHighLighter; +} + +void MailSourceViewer::setText( const QString& text ) +{ + if ( text.length() > 500000 ) { + setTextFormat( Qt::LogText ); + } else { + setTextFormat( Qt::PlainText ); + mSourceHighLighter = new MailSourceHighlighter( this ); + } + KTextBrowser::setText( text ); +} + } --- kdepim/kmail/mailsourceviewer.h #1.4:1.5 @@ -34,4 +34,5 @@ #include <ktextbrowser.h> +#include <qsyntaxhighlighter.h> @@ -46,8 +47,22 @@ namespace KMail { +class MailSourceHighlighter : public QSyntaxHighlighter +{ +public: + MailSourceHighlighter( QTextEdit* edit ) + : QSyntaxHighlighter( edit ) + {} + int highlightParagraph( const QString& text, int ); +}; + + class MailSourceViewer : public KTextBrowser { public: MailSourceViewer( QWidget *parent = 0, const char *name = 0 ); + ~MailSourceViewer(); + void setText( const QString& text ); +private: + MailSourceHighlighter *mSourceHighLighter; }; |