diff --git a/ChangeLog b/ChangeLog index 6efa1467f..38bab76d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 1999-01-29 Stefan Taferner (KMail-1.0.15) + * Fix: improved performance when displaying messages (Bug #148). + * Bugfix: fixed crash when dropping message on directory entry in folder list. diff --git a/kfileio.cpp b/kfileio.cpp index 793e5153e..8a0eb9d2b 100644 --- a/kfileio.cpp +++ b/kfileio.cpp @@ -119,7 +119,7 @@ bool kStringToFile(const QString aBuffer, const char* aFileName, { if (aAskIfExists) { - QString str(256); + QString str; str.sprintf(i18n( "File %s exists.\nDo you want to replace it ?"), aFileName); @@ -166,7 +166,7 @@ bool kStringToFile(const QString aBuffer, const char* aFileName, } len = aBuffer.size() - 1; - debug("kStringToFile: writing %d bytes", len); + debug("kStringToFile: writing %d bytes", len, aBuffer.length()); writeLen = file.writeBlock(aBuffer.data(), len); if (writeLen < 0) @@ -176,7 +176,7 @@ bool kStringToFile(const QString aBuffer, const char* aFileName, } else if (writeLen < len) { - QString msg(256); + QString msg; msg.sprintf(i18n("Could only write %d bytes of %d."), writeLen, len); msgDialog(msg); diff --git a/kmmessage.cpp b/kmmessage.cpp index 13ef57c33..26c06e4a2 100644 --- a/kmmessage.cpp +++ b/kmmessage.cpp @@ -228,19 +228,24 @@ const QString KMMessage::headerAsString(void) void KMMessage::fromString(const QString aStr, bool aSetStatus) { int i, j, len; + const char* strPos; + char* resultPos; + char ch; if (mMsg) delete mMsg; mMsg = new DwMessage; // copy string and throw out obsolete control characters len = aStr.length(); - result.resize(len +1); - for (i=0,j=0; i=' ' || aStr[i]=='\t' || aStr[i]=='\n' || aStr[i]<='\0') - result[j++] = aStr[i]; + if (ch>=' ' || ch=='\t' || ch=='\n' || ch<='\0') + *resultPos++ = ch; } - result[j++] = '\0'; // terminate zero for casting + *resultPos = '\0'; // terminate zero for casting mMsg->FromString((const char*)result); mMsg->Parse(); diff --git a/kmmsgpart.cpp b/kmmsgpart.cpp index aa56d0829..78285db37 100644 --- a/kmmsgpart.cpp +++ b/kmmsgpart.cpp @@ -136,7 +136,10 @@ const QString KMMessagePart::bodyDecoded(void) const case DwMime::kCte7bit: case DwMime::kCte8bit: case DwMime::kCteBinary: - result = mBody; + len = mBody.length(); + result.resize(len+1); + memcpy((void*)result.data(), (void*)mBody.data(), len); + result[len] = '\0'; break; } diff --git a/kmreaderwin.cpp b/kmreaderwin.cpp index 473b3e840..a4f478a09 100644 --- a/kmreaderwin.cpp +++ b/kmreaderwin.cpp @@ -455,6 +455,8 @@ void KMReaderWin::writeBodyStr(const QString aStr) mViewer->write(htmlStr); } + +//----------------------------------------------------------------------------- QString KMReaderWin::quotedHTML(char * pos) { QString htmlStr, line; @@ -511,7 +513,7 @@ QString KMReaderWin::quotedHTML(char * pos) //----------------------------------------------------------------------------- void KMReaderWin::writePartIcon(KMMessagePart* aMsgPart, int aPartNum) { - QString iconName, href(255), label, comment; + QString iconName, href(255), label, comment, tmpStr; if(aMsgPart == NULL) { debug("writePartIcon: aMsgPart == NULL\n"); @@ -557,7 +559,8 @@ void KMReaderWin::writePartIcon(KMMessagePart* aMsgPart, int aPartNum) fname.remove(c, 1); } - if (!kStringToFile(aMsgPart->bodyDecoded(), fname, false, false, false)) + tmpStr = aMsgPart->bodyDecoded(); + if (!kStringToFile(tmpStr, fname, false, false, false)) ok = false; } if (ok) @@ -585,43 +588,56 @@ void KMReaderWin::writePartIcon(KMMessagePart* aMsgPart, int aPartNum) const QString KMReaderWin::strToHtml(const QString aStr, bool aDecodeQP, bool aPreserveBlanks) const { - QString htmlStr, qpstr, iStr; + QString qpstr, iStr, result; char ch, *pos, str[256]; int i, i1, x, len; + int maxLen = 30000; + char htmlStr[maxLen+256]; + char* htmlPos; if (aDecodeQP) qpstr = KMMsgBase::decodeRFC1522String(aStr); else qpstr = aStr; +#define HTML_ADD(str,len) strcpy(htmlPos,str),htmlPos+=len + + htmlPos = htmlStr; for (pos=qpstr.data(),x=0; *pos; pos++,x++) { + if ((int)(htmlPos-htmlStr) >= maxLen) + { + *htmlPos = '\0'; + result += htmlStr; + htmlPos = htmlStr; + } + ch = *pos; if (aPreserveBlanks) { if (ch==' ' && pos[1]==' ') { - htmlStr += "  "; + HTML_ADD("  ", 7); for (pos++, x++; pos[1]==' '; pos++, x++) - htmlStr += " "; + HTML_ADD("  ", 7); continue; } else if (ch=='\t') { do { - htmlStr += " "; + HTML_ADD(" ", 6); x++; } while((x&7) != 0); } // else aPreserveBlanks = FALSE; } - if (ch=='<') htmlStr += "<"; - else if (ch=='>') htmlStr += ">"; - else if (ch=='\n') htmlStr += "
"; - else if (ch=='&') htmlStr += "&"; - else if ((ch=='h' && strncmp(pos,"http:",5)==0) || - (ch=='f' && strncmp(pos,"ftp:",4)==0) || - (ch=='m' && strncmp(pos,"mailto:",7)==0)) + if (ch=='<') HTML_ADD("<", 4); + else if (ch=='>') HTML_ADD(">", 4); + else if (ch=='\n') HTML_ADD("
", 4); + else if (ch=='&') HTML_ADD("&", 5); + else if ((ch=='h' && strncmp(pos,"http:", 5)==0) || + (ch=='f' && strncmp(pos,"ftp:", 4)==0) || + (ch=='m' && strncmp(pos,"mailto:", 7)==0)) { for (i=0; *pos && *pos>' ' && i<255; i++, pos++) str[i] = *pos; @@ -632,11 +648,11 @@ const QString KMReaderWin::strToHtml(const QString aStr, bool aDecodeQP, pos--; } str[i] = '\0'; - htmlStr += ""; - htmlStr += str; - htmlStr += ""; + HTML_ADD("", 2); + HTML_ADD(str, strlen(str)); + HTML_ADD("", 4); } else if (ch=='@') { @@ -666,17 +682,19 @@ const QString KMReaderWin::strToHtml(const QString aStr, bool aDecodeQP, } iStr.truncate(len); - htmlStr.truncate(htmlStr.length() - i1 + 1); - if (iStr.length()>3) - htmlStr += "" + iStr + ""; - else htmlStr += iStr; + htmlPos -= (i1 - 1); + if (iStr.length()>3) + iStr = "" + iStr + ""; + HTML_ADD(iStr.data(), iStr.length()); iStr = ""; } - else htmlStr += ch; + else *htmlPos++ = ch; } - return htmlStr; + *htmlPos = '\0'; + result += htmlStr; + return result; } @@ -840,8 +858,8 @@ void KMReaderWin::slotAtmOpen() { QString str, pname, cmd, fileName; KMMessagePart msgPart; - char* tmpName; - int old_umask; + // char* tmpName; + // int old_umask; int c; mMsg->bodyPart(mAtmCurrent, &msgPart); diff --git a/kmsettings.cpp b/kmsettings.cpp index edad4c80c..1c2a953c0 100644 --- a/kmsettings.cpp +++ b/kmsettings.cpp @@ -313,7 +313,6 @@ void KMSettings::createTabAppearance(QWidget* parent) QGroupBox* grp; KConfig* config = app->getConfig(); QPushButton* btn; - QLabel* lbl; QFont fnt; //----- group: fonts