diff options
Diffstat (limited to 'libkdepim/linklocator.cpp')
-rw-r--r-- | libkdepim/linklocator.cpp | 136 |
1 files changed, 68 insertions, 68 deletions
diff --git a/libkdepim/linklocator.cpp b/libkdepim/linklocator.cpp index 6058392a0..0ea0fa680 100644 --- a/libkdepim/linklocator.cpp +++ b/libkdepim/linklocator.cpp @@ -28,19 +28,19 @@ #include <kmdcodec.h> #include <kdebug.h> -#include <qstylesheet.h> -#include <qfile.h> -#include <qregexp.h> +#include <tqstylesheet.h> +#include <tqfile.h> +#include <tqregexp.h> #include <limits.h> -QMap<QString, QString> *LinkLocator::s_smileyEmoticonNameMap = 0; -QMap<QString, QString> *LinkLocator::s_smileyEmoticonHTMLCache = 0; +TQMap<TQString, TQString> *LinkLocator::s_smileyEmoticonNameMap = 0; +TQMap<TQString, TQString> *LinkLocator::s_smileyEmoticonHTMLCache = 0; -static KStaticDeleter< QMap<QString, QString> > smileyMapDeleter; -static KStaticDeleter< QMap<QString, QString> > smileyCacheDeleter; +static KStaticDeleter< TQMap<TQString, TQString> > smileyMapDeleter; +static KStaticDeleter< TQMap<TQString, TQString> > smileyCacheDeleter; -LinkLocator::LinkLocator(const QString& text, int pos) +LinkLocator::LinkLocator(const TQString& text, int pos) : mText(text), mPos(pos), mMaxUrlLen(4096), mMaxAddressLen(255) { // If you change either of the above values for maxUrlLen or @@ -51,9 +51,9 @@ LinkLocator::LinkLocator(const QString& text, int pos) if ( !s_smileyEmoticonNameMap ) { smileyMapDeleter.setObject( s_smileyEmoticonNameMap, - new QMap<QString, QString>() ); + new TQMap<TQString, TQString>() ); for ( int i = 0; i < EmotIcons::EnumSindex::COUNT; ++i ) { - QString imageName( EmotIcons::EnumSindex::enumToString[i] ); + TQString imageName( EmotIcons::EnumSindex::enumToString[i] ); imageName.truncate( imageName.length() - 2 ); //remove the _0 bit s_smileyEmoticonNameMap->insert( EmotIcons::smiley(i), imageName ); } @@ -61,7 +61,7 @@ LinkLocator::LinkLocator(const QString& text, int pos) if ( !s_smileyEmoticonHTMLCache ) smileyCacheDeleter.setObject( s_smileyEmoticonHTMLCache, - new QMap<QString, QString>() ); + new TQMap<TQString, TQString>() ); } void LinkLocator::setMaxUrlLen(int length) @@ -84,20 +84,20 @@ int LinkLocator::maxAddressLen() const return mMaxAddressLen; } -QString LinkLocator::getUrl() +TQString LinkLocator::getUrl() { - QString url; + TQString url; if(atUrl()) { // handle cases like this: <link>http://foobar.org/</link> int start = mPos; while(mPos < (int)mText.length() && mText[mPos] > ' ' && mText[mPos] != '"' && - QString("<>()[]").find(mText[mPos]) == -1) + TQString("<>()[]").find(mText[mPos]) == -1) { ++mPos; } /* some URLs really end with: # / & - _ */ - const QString allowedSpecialChars = QString("#/&-_"); + const TQString allowedSpecialChars = TQString("#/&-_"); while(mPos > start && mText[mPos-1].isPunct() && allowedSpecialChars.find(mText[mPos-1]) == -1 ) { @@ -123,7 +123,7 @@ bool LinkLocator::atUrl() const { // the following characters are allowed in a dot-atom (RFC 2822): // a-z A-Z 0-9 . ! # $ % & ' * + - / = ? ^ _ ` { | } ~ - const QString allowedSpecialChars = QString(".!#$%&'*+-/=?^_`{|}~"); + const TQString allowedSpecialChars = TQString(".!#$%&'*+-/=?^_`{|}~"); // the character directly before the URL must not be a letter, a number or // any other character allowed in a dot-atom (RFC 2822). @@ -131,7 +131,7 @@ bool LinkLocator::atUrl() const ( allowedSpecialChars.find( mText[mPos-1] ) != -1 ) ) ) return false; - QChar ch = mText[mPos]; + TQChar ch = mText[mPos]; return (ch=='h' && ( mText.mid(mPos, 7) == "http://" || mText.mid(mPos, 8) == "https://") ) || (ch=='v' && mText.mid(mPos, 6) == "vnc://") || @@ -147,7 +147,7 @@ bool LinkLocator::atUrl() const // note: no "file:" for security reasons } -bool LinkLocator::isEmptyUrl(const QString& url) +bool LinkLocator::isEmptyUrl(const TQString& url) { return url.isEmpty() || url == "http://" || @@ -165,14 +165,14 @@ bool LinkLocator::isEmptyUrl(const QString& url) url == "news://"; } -QString LinkLocator::getEmailAddress() +TQString LinkLocator::getEmailAddress() { - QString address; + TQString address; if ( mText[mPos] == '@' ) { // the following characters are allowed in a dot-atom (RFC 2822): // a-z A-Z 0-9 . ! # $ % & ' * + - / = ? ^ _ ` { | } ~ - const QString allowedSpecialChars = QString(".!#$%&'*+-/=?^_`{|}~"); + const TQString allowedSpecialChars = TQString(".!#$%&'*+-/=?^_`{|}~"); // determine the local part of the email address int start = mPos - 1; @@ -181,7 +181,7 @@ QString LinkLocator::getEmailAddress() mText[start] == '@' || // allow @ to find invalid email addresses allowedSpecialChars.find( mText[start] ) != -1 ) ) { if ( mText[start] == '@' ) - return QString(); // local part contains '@' -> no email address + return TQString(); // local part contains '@' -> no email address --start; } ++start; @@ -189,7 +189,7 @@ QString LinkLocator::getEmailAddress() while ( ( start < mPos ) && !mText[start].isLetterOrNumber() ) ++start; if ( start == mPos ) - return QString(); // local part is empty -> no email address + return TQString(); // local part is empty -> no email address // determine the domain part of the email address int dotPos = INT_MAX; @@ -200,7 +200,7 @@ QString LinkLocator::getEmailAddress() mText[end] == '.' || mText[end] == '-' ) ) { if ( mText[end] == '@' ) - return QString(); // domain part contains '@' -> no email address + return TQString(); // domain part contains '@' -> no email address if ( mText[end] == '.' ) dotPos = QMIN( dotPos, end ); // remember index of first dot in domain ++end; @@ -209,12 +209,12 @@ QString LinkLocator::getEmailAddress() while ( ( end > mPos ) && !mText[end - 1].isLetterOrNumber() ) --end; if ( end == mPos ) - return QString(); // domain part is empty -> no email address + return TQString(); // domain part is empty -> no email address if ( dotPos >= end ) - return QString(); // domain part doesn't contain a dot + return TQString(); // domain part doesn't contain a dot if ( end - start > maxAddressLen() ) - return QString(); // too long -> most likely no email address + return TQString(); // too long -> most likely no email address address = mText.mid( start, end - start ); mPos = end - 1; @@ -222,19 +222,19 @@ QString LinkLocator::getEmailAddress() return address; } -QString LinkLocator::convertToHtml(const QString& plainText, int flags, +TQString LinkLocator::convertToHtml(const TQString& plainText, int flags, int maxUrlLen, int maxAddressLen) { LinkLocator locator(plainText); locator.setMaxUrlLen(maxUrlLen); locator.setMaxAddressLen(maxAddressLen); - QString str; - QString result((QChar*)0, (int)locator.mText.length() * 2); - QChar ch; + TQString str; + TQString result((TQChar*)0, (int)locator.mText.length() * 2); + TQChar ch; int x; bool startOfLine = true; - QString emoticon; + TQString emoticon; for (locator.mPos = 0, x = 0; locator.mPos < (int)locator.mText.length(); locator.mPos++, x++) { @@ -297,7 +297,7 @@ QString LinkLocator::convertToHtml(const QString& plainText, int flags, str = locator.getUrl(); if (!str.isEmpty()) { - QString hyperlink; + TQString hyperlink; if(str.left(4) == "www.") hyperlink = "http://" + str; else if(str.left(4) == "ftp.") @@ -315,7 +315,7 @@ QString LinkLocator::convertToHtml(const QString& plainText, int flags, { // len is the length of the local part int len = str.find('@'); - QString localPart = str.left(len); + TQString localPart = str.left(len); // remove the local part from the result (as '&'s have been expanded to // & we have to take care of the 4 additional characters per '&') @@ -350,32 +350,32 @@ QString LinkLocator::convertToHtml(const QString& plainText, int flags, return result; } -QString LinkLocator::pngToDataUrl( const QString & iconPath ) +TQString LinkLocator::pngToDataUrl( const TQString & iconPath ) { if ( iconPath.isEmpty() ) - return QString::null; + return TQString::null; - QFile pngFile( iconPath ); + TQFile pngFile( iconPath ); if ( !pngFile.open( IO_ReadOnly | IO_Raw ) ) - return QString::null; + return TQString::null; - QByteArray ba = pngFile.readAll(); + TQByteArray ba = pngFile.readAll(); pngFile.close(); - return QString::fromLatin1("data:image/png;base64,%1") + return TQString::fromLatin1("data:image/png;base64,%1") .arg( KCodecs::base64Encode( ba ) ); } -QString LinkLocator::getEmoticon() +TQString LinkLocator::getEmoticon() { // smileys have to be prepended by whitespace if ( ( mPos > 0 ) && !mText[mPos-1].isSpace() ) - return QString::null; + return TQString::null; // since smileys start with ':', ';', '(' or '8' short circuit method - const QChar ch = mText[mPos]; + const TQChar ch = mText[mPos]; if ( ch !=':' && ch != ';' && ch != '(' && ch != '8' ) - return QString::null; + return TQString::null; // find the end of the smiley (a smiley is at most 4 chars long and ends at // lineend or whitespace) @@ -387,44 +387,44 @@ QString LinkLocator::getEmoticon() !mText[mPos+smileyLen].isSpace() ) smileyLen++; if ( smileyLen < MinSmileyLen || smileyLen > MaxSmileyLen ) - return QString::null; + return TQString::null; - const QString smiley = mText.mid( mPos, smileyLen ); + const TQString smiley = mText.mid( mPos, smileyLen ); if ( !s_smileyEmoticonNameMap->contains( smiley ) ) - return QString::null; // that's not a (known) smiley + return TQString::null; // that's not a (known) smiley - QString htmlRep; + TQString htmlRep; if ( s_smileyEmoticonHTMLCache->contains( smiley ) ) { htmlRep = (*s_smileyEmoticonHTMLCache)[smiley]; } else { - const QString imageName = (*s_smileyEmoticonNameMap)[smiley]; + const TQString imageName = (*s_smileyEmoticonNameMap)[smiley]; #if KDE_IS_VERSION( 3, 3, 91 ) - const QString iconPath = locate( "emoticons", + const TQString iconPath = locate( "emoticons", EmotIcons::theme() + - QString::fromLatin1( "/" ) + - imageName + QString::fromLatin1(".png") ); + TQString::fromLatin1( "/" ) + + imageName + TQString::fromLatin1(".png") ); #else - const QString iconPath = locate( "data", - QString::fromLatin1( "kopete/pics/emoticons/" )+ + const TQString iconPath = locate( "data", + TQString::fromLatin1( "kopete/pics/emoticons/" )+ EmotIcons::theme() + - QString::fromLatin1( "/" ) + - imageName + QString::fromLatin1(".png") ); + TQString::fromLatin1( "/" ) + + imageName + TQString::fromLatin1(".png") ); #endif - const QString dataUrl = pngToDataUrl( iconPath ); + const TQString dataUrl = pngToDataUrl( iconPath ); if ( dataUrl.isEmpty() ) { - htmlRep = QString::null; + htmlRep = TQString::null; } else { // create an image tag (the text in attribute alt is used // for copy & paste) representing the smiley - htmlRep = QString("<img class=\"pimsmileyimg\" src=\"%1\" " + htmlRep = TQString("<img class=\"pimsmileyimg\" src=\"%1\" " "alt=\"%2\" title=\"%3\" width=\"16\" height=\"16\"/>") .arg( dataUrl, - QStyleSheet::escape( smiley ), - QStyleSheet::escape( smiley ) ); + TQStyleSheet::escape( smiley ), + TQStyleSheet::escape( smiley ) ); } s_smileyEmoticonHTMLCache->insert( smiley, htmlRep ); } @@ -435,22 +435,22 @@ QString LinkLocator::getEmoticon() return htmlRep; } -QString LinkLocator::highlightedText() +TQString LinkLocator::highlightedText() { // formating symbols must be prepended with a whitespace if ( ( mPos > 0 ) && !mText[mPos-1].isSpace() ) - return QString::null; + return TQString::null; - const QChar ch = mText[mPos]; + const TQChar ch = mText[mPos]; if ( ch != '/' && ch != '*' && ch != '_' ) - return QString::null; + return TQString::null; - QRegExp re = QRegExp( QString("\\%1([0-9A-Za-z]+)\\%2").arg( ch ).arg( ch ) ); + TQRegExp re = TQRegExp( TQString("\\%1([0-9A-Za-z]+)\\%2").arg( ch ).arg( ch ) ); if ( re.search( mText, mPos ) == mPos ) { uint length = re.matchedLength(); // there must be a whitespace after the closing formating symbol if ( mPos + length < mText.length() && !mText[mPos + length].isSpace() ) - return QString::null; + return TQString::null; mPos += length - 1; switch ( ch.latin1() ) { case '*': @@ -461,6 +461,6 @@ QString LinkLocator::highlightedText() return "<i>" + re.cap( 1 ) + "</i>"; } } - return QString::null; + return TQString::null; } |