Import release 2.0rc1
This commit is contained in:
+136
-29
@@ -24,6 +24,8 @@
|
||||
#include "../network/soap/passportloginservice.h"
|
||||
#include "kmessconfig.h"
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include <KRun>
|
||||
#include <KUrl>
|
||||
#include <KShell>
|
||||
@@ -31,6 +33,8 @@
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include <QFile>
|
||||
#include <QUuid>
|
||||
#include <QPainter>
|
||||
|
||||
#ifdef KMESSDEBUG_SHAREDMETHODS
|
||||
#define KMESSDEBUG_SHARED_OPENEXTERNAL
|
||||
@@ -175,6 +179,58 @@ 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'
|
||||
* as an overlay, with given width and height. If -1 are given as width and height, the size of 'icon'
|
||||
* is taken as the end size. -1 is the default for both width and height.
|
||||
*
|
||||
* Note that the icon always sticks to the top left, whatever the size is, and the overlay always sticks to
|
||||
* the bottom right.
|
||||
*
|
||||
* @param icon The icon which will be displayed as the "main image".
|
||||
* @param overlay The overlay which will be displayed over the icon.
|
||||
* @param width Width of the returned icon.
|
||||
* @param height Height of the returned icon.
|
||||
* @param sizeFactor the size of the overlay, compared with the size of the result image; if 1, it fills the image, if .5, the overlay is half the size.
|
||||
* @param iconSizeFactor the size of the icon, compared with the size of the result image; if 1, it fills the image (background), if .5, it's half the size.
|
||||
* @returns the icon with the overlay overlayed on it.
|
||||
*/
|
||||
QPixmap KMessShared::drawIconOverlay( const QPixmap icon, const QPixmap overlay, int width, int height, float sizeFactor, float iconSizeFactor )
|
||||
{
|
||||
if( width == -1 )
|
||||
{
|
||||
width = icon.size().width();
|
||||
}
|
||||
if( height == -1 )
|
||||
{
|
||||
height = icon.size().height();
|
||||
}
|
||||
|
||||
const int imageWidth = width * iconSizeFactor;
|
||||
const int imageHeight = height * iconSizeFactor;
|
||||
|
||||
const int overlayWidth = width * sizeFactor;
|
||||
const int overlayHeight = height * sizeFactor;
|
||||
|
||||
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 );
|
||||
|
||||
QPainter p( &result );
|
||||
p.drawPixmap( 0, 0, icon. scaled( imageWidth, imageHeight ) );
|
||||
p.drawPixmap( x, y, overlay.scaled( overlayWidth, overlayHeight ) );
|
||||
p.end();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Generate a random GUID.
|
||||
*
|
||||
@@ -184,6 +240,10 @@ QByteArray KMessShared::deriveKey ( const QByteArray &keyToDerive, const QByteAr
|
||||
*/
|
||||
QString KMessShared::generateGUID()
|
||||
{
|
||||
// much easier than the code below :)
|
||||
return QUuid::createUuid().toString().toUpper();
|
||||
|
||||
/*
|
||||
// This code is based on Kopete, but much shorter.
|
||||
QString guid( "{"
|
||||
+ QString::number((rand() & 0xAAFF) + 0x1111, 16)
|
||||
@@ -200,6 +260,7 @@ QString KMessShared::generateGUID()
|
||||
+ QString::number((rand() & 0xAAFF) + 0x1111, 16)
|
||||
+ "}" );
|
||||
return guid.toUpper();
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -209,11 +270,14 @@ QString KMessShared::generateGUID()
|
||||
*
|
||||
* For use in MSNP2P, the value will not be below 4
|
||||
*
|
||||
* @return A random value between 4 and 4294967295.
|
||||
* @return A random value between 4 and RAND_MAX.
|
||||
*/
|
||||
quint32 KMessShared::generateID()
|
||||
{
|
||||
return (rand() & 0x00FFFFFC);
|
||||
//return (rand() & 0x00FFFFFC);
|
||||
// seed the RNG properly.
|
||||
srand(time(NULL));
|
||||
return (rand() + 100); // at least 3 digits for an ID (as per ticket #294??).
|
||||
}
|
||||
|
||||
|
||||
@@ -490,23 +554,45 @@ void KMessShared::openEmailClient( const QString &mailto, const QString &folder,
|
||||
/**
|
||||
* Select the next available file.
|
||||
*
|
||||
* This method searches for numbered files and returns the last existing file,
|
||||
* and the first number available for file creation.
|
||||
* This method searches for numbered files and tries to find the last *existing* file.
|
||||
* If it returns false, ( baseName + "." + extension ) can be created directly; otherwise,
|
||||
* ( baseName + suffix + "." + extension ) is the last file that does exist and to create
|
||||
* a new file, use ( baseName + "." + startingNumber + "." + extension ).
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* For example, calling selectNextFile( "/", "name", suffix, "ext", startingNumber ) returns:
|
||||
* - if "/name.ext" doesn't exists, returns false, startingNumber = 1
|
||||
* - if "/name.ext" exists, returns true, startingNumber = 1
|
||||
* - if "/name.1.ext" and "/name.2.ext" exist, returns true, suffix = ".2",
|
||||
* startingNumber = 3
|
||||
* For example, calling selectNextFile( "/", "name", suffix, "ext", startingNumber ):
|
||||
* - if startingNumber is zero and "/name.ext" doesn't exist, returns false,
|
||||
* suffix = "", startingNumber varies depending on if anything after name.ext exists
|
||||
* (ie if name.1.ext exists but name.2.ext doesn't, startingNumber = 2)
|
||||
* - else if "/name.1.ext" doesn't exist, returns true, suffix = "", startingNumber = 1
|
||||
* (so the last existing file will be "name.ext", which is true)
|
||||
* - else if "/name.2.ext" doesn't exist, returns true, suffix = ".1", startingNumber = 2
|
||||
* - and so forth
|
||||
*
|
||||
* @param directory Path where the files will be searched, followed by '/'.
|
||||
* <code>// Create a new unique file:
|
||||
int startingNumber = 0;
|
||||
QString suffix;
|
||||
if( KMessShared::selectNextFile( "/kmess/data/directory/", "logFile", suffix, "html", startingNumber ) )
|
||||
{
|
||||
// The base name exists, create a numbered file
|
||||
path = "/kmess/data/directory/logFile." + QString::number( startingNumber ) . ".html";
|
||||
}
|
||||
else
|
||||
{
|
||||
// The base name doesn't exist, use it instead
|
||||
path = "/kmess/data/directory/logFile.html";
|
||||
}
|
||||
</code>
|
||||
* @param directory (in) Path where the files will be searched, followed by '/'.
|
||||
* May be relative.
|
||||
* @param baseName Common name for the files, without the extension, see above.
|
||||
* @param suffix Append to the baseName to get the name of the last
|
||||
* @param baseName (in) Common name for the files, without the extension, see above.
|
||||
* @param suffix (out) Append to the baseName to get the name of the last
|
||||
* existing numbered file.
|
||||
* @param extension Extension of the file to search for, see above.
|
||||
* @param startingNumber File number to start from, set to zero to start with
|
||||
* @param extension (in) Extension of the file to search for, see above.
|
||||
* @param startingNumber (in/out) File number to start from, set to zero to start with
|
||||
* the common name alone. Gets updated with the number of
|
||||
* the first available file.
|
||||
* @return bool If the file in the updated fileName param exists or not.
|
||||
@@ -515,31 +601,38 @@ bool KMessShared::selectNextFile( const QString &directory, const QString &baseN
|
||||
{
|
||||
QString path( directory + baseName + "." );
|
||||
|
||||
// "baseName.ext" doesn't exist, find the next available file
|
||||
if( startingNumber == 0 && ! QFile::exists( path + extension ) )
|
||||
// if startingNumber is nonzero, we never allow to return the base file
|
||||
// this is important if the base file exists but .1.xml doesn't exist;
|
||||
// if this boolean is true it will return .1.xml and return false, if it's
|
||||
// false it will be allowed to return .xml and return true.
|
||||
// HACK XXX FIXME - Fix this damn method for 2.0! We can't have this legacy code like this.
|
||||
bool returnBaseFileAllowed = startingNumber == 0;
|
||||
|
||||
if( returnBaseFileAllowed && ! QFile::exists( path + extension ) )
|
||||
{
|
||||
#ifdef KMESSDEBUG_SHAREDMETHODS
|
||||
kDebug() << "Initial file" << ( path + extension ) << "does not exist, finding next available.";
|
||||
#endif
|
||||
// "baseName.ext" doesn't exist, so return false
|
||||
// but first find the next available file for writing
|
||||
while( QFile::exists( path + QString::number( ++startingNumber ) + "." + extension ) ) ;
|
||||
|
||||
#ifdef KMESSDEBUG_SHAREDMETHODS
|
||||
kDebug() << "Next available:" << path << startingNumber;
|
||||
kDebug() << "Base file " << ( baseName + "." + extension) << "does not exist. Next sequential file is: " << ( baseName + "." + QString::number( startingNumber ) + "." + extension );
|
||||
#endif
|
||||
|
||||
suffix = "";
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef KMESSDEBUG_SHAREDMETHODS
|
||||
kDebug() << "Initial file exists, finding the last numbered.";
|
||||
kDebug() << "Base file" << ( baseName + "." + extension ) << "exists, finding the last existing numbered file";
|
||||
#endif
|
||||
|
||||
// "baseName.ext" exists, find the last existing numbered one
|
||||
|
||||
// Start the sequence number from 1
|
||||
if( startingNumber == 0 )
|
||||
// Start the search sequence number from 1
|
||||
if( startingNumber < 1 )
|
||||
{
|
||||
startingNumber = 1;
|
||||
}
|
||||
|
||||
// find the last existing file
|
||||
while( QFile::exists( path + QString::number( startingNumber ) + "." + extension ) )
|
||||
{
|
||||
startingNumber++;
|
||||
@@ -548,19 +641,33 @@ bool KMessShared::selectNextFile( const QString &directory, const QString &baseN
|
||||
// Found the first non-existing file
|
||||
if( startingNumber == 1 )
|
||||
{
|
||||
// Select the first numbered file
|
||||
suffix = QString();
|
||||
if( returnBaseFileAllowed )
|
||||
{
|
||||
// the last existing file is the base filename, without a suffix
|
||||
suffix = QString();
|
||||
}
|
||||
else
|
||||
{
|
||||
suffix = ".1";
|
||||
#ifdef KMESSDEBUG_SHAREDMETHODS
|
||||
kDebug() << "Called with nonzero startingNumber, so I'm not allowed to return the base file!"
|
||||
<< "Returning " << ( baseName + suffix + "." + extension ) << " which doesn't exist.";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
suffix = "." + QString::number( startingNumber - 1 ); // That's the number of the last existing file
|
||||
// the last existing file is the previously checked file in the loop
|
||||
suffix = "." + QString::number( startingNumber - 1 );
|
||||
}
|
||||
|
||||
#ifdef KMESSDEBUG_SHAREDMETHODS
|
||||
kDebug() << "Last existent file name:" << ( baseName + suffix );
|
||||
kDebug() << "Last existing file name:" << ( baseName + suffix + "." + extension );
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user