From 1b09361c51b3ce1dbdff7a543ddf29ae06472390 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 23 Nov 2011 09:18:31 +0100 Subject: [PATCH] * DRY: Moved md5() helper method to TomahawkUtils. --- .../infoplugins/generic/RoviPlugin.cpp | 8 +--- .../infoplugins/generic/lastfmplugin.cpp | 14 ++----- src/libtomahawk/utils/tomahawkutils.cpp | 39 ++++++++++++------- src/libtomahawk/utils/tomahawkutils.h | 9 ++--- src/settingsdialog.cpp | 9 +---- 5 files changed, 33 insertions(+), 46 deletions(-) diff --git a/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.cpp index 3ae3edfc4..6720c2c34 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.cpp @@ -26,12 +26,6 @@ using namespace Tomahawk::InfoSystem; -static QString -md5( const QByteArray& src ) -{ - QByteArray const digest = QCryptographicHash::hash( src, QCryptographicHash::Md5 ); - return QString::fromLatin1( digest.toHex() ).rightJustified( 32, '0' ); -} RoviPlugin::RoviPlugin() : InfoPlugin() @@ -191,6 +185,6 @@ QByteArray RoviPlugin::generateSig() const { QByteArray raw = m_apiKey + m_secret + QString::number( QDateTime::currentMSecsSinceEpoch() / 1000 ).toLatin1(); - return md5( raw ).toLatin1(); + return TomahawkUtils::md5( raw ).toLatin1(); } diff --git a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp index ff4a64996..2bd08e650 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include @@ -38,13 +37,6 @@ using namespace Tomahawk::InfoSystem; -static QString -md5( const QByteArray& src ) -{ - QByteArray const digest = QCryptographicHash::hash( src, QCryptographicHash::Md5 ); - return QString::fromLatin1( digest.toHex() ).rightJustified( 32, '0' ); -} - LastFmPlugin::LastFmPlugin() : InfoPlugin() @@ -429,9 +421,9 @@ LastFmPlugin::notInCacheSlot( QHash criteria, Tomahawk::InfoSy c[ "id" ] = "chart.getHypedArtists"; c[ "label" ] = "Hyped Artists"; artist_charts.append( c ); - - + + QVariantMap charts; charts.insert( "Tracks", QVariant::fromValue< QList< InfoStringHash > >( track_charts ) ); charts.insert( "Artists", QVariant::fromValue< QList< InfoStringHash > >( artist_charts ) ); @@ -777,7 +769,7 @@ LastFmPlugin::createScrobbler() if( TomahawkSettings::instance()->lastFmSessionKey().isEmpty() ) // no session key, so get one { qDebug() << "LastFmPlugin::createScrobbler Session key is empty"; - QString authToken = md5( ( lastfm::ws::Username.toLower() + md5( m_pw.toUtf8() ) ).toUtf8() ); + QString authToken = TomahawkUtils::md5( ( lastfm::ws::Username.toLower() + TomahawkUtils::md5( m_pw.toUtf8() ) ).toUtf8() ); QMap query; query[ "method" ] = "auth.getMobileSession"; diff --git a/src/libtomahawk/utils/tomahawkutils.cpp b/src/libtomahawk/utils/tomahawkutils.cpp index 4fac3f113..876338d0c 100644 --- a/src/libtomahawk/utils/tomahawkutils.cpp +++ b/src/libtomahawk/utils/tomahawkutils.cpp @@ -27,14 +27,15 @@ #include #endif -#include -#include -#include +#include +#include +#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #ifdef Q_WS_WIN #include @@ -543,14 +544,6 @@ newerVersion( const QString& oldVersion, const QString& newVersion ) } -void -crash() -{ - volatile int* a = (int*)(NULL); - *a = 1; -} - - // taken from util/fileutils.cpp in kdevplatform bool removeDirectory( const QString& dir ) @@ -584,4 +577,20 @@ quint64 infosystemRequestId() return result; } + +QString +md5( const QByteArray& data ) +{ + QByteArray const digest = QCryptographicHash::hash( data, QCryptographicHash::Md5 ); + return QString::fromLatin1( digest.toHex() ).rightJustified( 32, '0' ); +} + + +void +crash() +{ + volatile int* a = (int*)(NULL); + *a = 1; +} + } // ns diff --git a/src/libtomahawk/utils/tomahawkutils.h b/src/libtomahawk/utils/tomahawkutils.h index 10845b8d0..c631bf7a0 100644 --- a/src/libtomahawk/utils/tomahawkutils.h +++ b/src/libtomahawk/utils/tomahawkutils.h @@ -81,16 +81,15 @@ namespace TomahawkUtils DLLEXPORT bool newerVersion( const QString& oldVersion, const QString& newVersion ); DLLEXPORT NetworkProxyFactory* proxyFactory( bool noMutexLocker = false ); - DLLEXPORT QNetworkAccessManager* nam(); - DLLEXPORT void setProxyFactory( TomahawkUtils::NetworkProxyFactory* factory, bool noMutexLocker = false ); + DLLEXPORT QNetworkAccessManager* nam(); DLLEXPORT void setNam( QNetworkAccessManager* nam, bool noMutexLocker = false ); + DLLEXPORT quint64 infosystemRequestId(); - DLLEXPORT void crash(); - + DLLEXPORT QString md5( const QByteArray& data ); DLLEXPORT bool removeDirectory( const QString& dir ); - DLLEXPORT quint64 infosystemRequestId(); + DLLEXPORT void crash(); } #endif // TOMAHAWKUTILS_H diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 891620857..4eb2ab02e 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -22,7 +22,6 @@ #include "utils/tomahawkutilsgui.h" -#include #include #include #include @@ -59,12 +58,6 @@ #include "ui_proxydialog.h" #include "ui_stackedsettingsdialog.h" -static QString -md5( const QByteArray& src ) -{ - QByteArray const digest = QCryptographicHash::hash( src, QCryptographicHash::Md5 ); - return QString::fromLatin1( digest.toHex() ).rightJustified( 32, '0' ); -} SettingsDialog::SettingsDialog( QWidget *parent ) : QDialog( parent ) @@ -409,7 +402,7 @@ SettingsDialog::testLastFmLogin() ui->pushButtonTestLastfmLogin->setEnabled( false ); ui->pushButtonTestLastfmLogin->setText( "Testing..." ); - QString authToken = md5( ( ui->lineEditLastfmUsername->text().toLower() + md5( ui->lineEditLastfmPassword->text().toUtf8() ) ).toUtf8() ); + QString authToken = TomahawkUtils::md5( ( ui->lineEditLastfmUsername->text().toLower() + TomahawkUtils::md5( ui->lineEditLastfmPassword->text().toUtf8() ) ).toUtf8() ); // now authenticate w/ last.fm and get our session key QMap query;