Import release 2.0.3
This commit is contained in:
@@ -35,6 +35,8 @@
|
||||
#include <QFile>
|
||||
#include <QUuid>
|
||||
#include <QPainter>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
#ifdef KMESSDEBUG_SHAREDMETHODS
|
||||
#define KMESSDEBUG_SHARED_OPENEXTERNAL
|
||||
@@ -179,7 +181,7 @@ QByteArray KMessShared::deriveKey ( const QByteArray &keyToDerive, const QByteAr
|
||||
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Draws an icon with an overlay from two pixmaps.
|
||||
*
|
||||
* This method takes the two pixmaps and draws them over each other, returning a new pixmap with 'overlay'
|
||||
@@ -216,7 +218,7 @@ QPixmap KMessShared::drawIconOverlay( const QPixmap icon, const QPixmap overlay,
|
||||
|
||||
const int x = width - overlayWidth;
|
||||
const int y = height - overlayHeight;
|
||||
|
||||
|
||||
// thanks, Amarok, for the code and the idea :)
|
||||
QPixmap result( width, height );
|
||||
result.fill( Qt::transparent );
|
||||
@@ -561,7 +563,7 @@ void KMessShared::openEmailClient( const QString &mailto, const QString &folder,
|
||||
*
|
||||
* If startingNumber is 1, there is actually no suffix; but this is never a problem if you
|
||||
* correctly handle this method returning false, reading the existing file using the suffix,
|
||||
* and writing a new file using startingNumber.
|
||||
* and writing a new file using startingNumber.
|
||||
*
|
||||
* For example, calling selectNextFile( "/", "name", suffix, "ext", startingNumber ):
|
||||
* - if startingNumber is zero and "/name.ext" doesn't exist, returns false,
|
||||
@@ -671,3 +673,60 @@ bool KMessShared::selectNextFile( const QString &directory, const QString &baseN
|
||||
|
||||
|
||||
|
||||
|
||||
// Truncate an UTF-8 multibyte string to a fixed byte size
|
||||
QString KMessShared::fixStringToByteSize( const QString &string, quint32 size )
|
||||
{
|
||||
// Check if truncating is not needed
|
||||
if( string.isEmpty() || size == 0 )
|
||||
{
|
||||
return string;
|
||||
}
|
||||
|
||||
// Seek through the string one multibyte char at a time, and count their actual size in bytes
|
||||
quint32 validPos = 0;
|
||||
for( quint32 pos = 0; (qint32)pos < string.length(); ++pos )
|
||||
{
|
||||
QChar character( string.at( pos ) );
|
||||
|
||||
quint32 skip = 0;
|
||||
quint32 more;
|
||||
|
||||
// Character ranges from http://en.wikipedia.org/wiki/UTF-8
|
||||
if( character <= 0x007f )
|
||||
{
|
||||
more = 1;
|
||||
}
|
||||
else if( character <= 0x07FF )
|
||||
{
|
||||
more = 2;
|
||||
}
|
||||
else if( character <= 0xd7ff )
|
||||
{
|
||||
more = 3;
|
||||
}
|
||||
else if( character <= 0xDFFF )
|
||||
{
|
||||
// Surrogate area, consume next char as well
|
||||
more = 4;
|
||||
skip = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
more = 3;
|
||||
}
|
||||
|
||||
// The next character would make the string too long: cut it here
|
||||
if( validPos + more > size )
|
||||
{
|
||||
return QString::fromUtf8( string.toUtf8().left( validPos ) );
|
||||
}
|
||||
|
||||
validPos += more;
|
||||
pos += skip;
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user