From f160947ddc36bc4011fcf15cfcd4aa33d73b2fa7 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 23 May 2012 10:07:29 +0200 Subject: [PATCH] * Split out BinaryExtractWorker and SharedTimeLine into separate files. --- src/libtomahawk/CMakeLists.txt | 2 + src/libtomahawk/utils/BinaryExtractWorker.cpp | 104 ++++++++++++++ src/libtomahawk/utils/BinaryExtractWorker.h | 59 ++++++++ src/libtomahawk/utils/PixmapDelegateFader.h | 1 + src/libtomahawk/utils/SharedTimeLine.cpp | 64 +++++++++ src/libtomahawk/utils/SharedTimeLine.h | 60 ++++++++ src/libtomahawk/utils/TomahawkUtils.cpp | 135 +----------------- src/libtomahawk/utils/TomahawkUtils.h | 30 ---- src/libtomahawk/widgets/FadingPixmap.h | 1 + 9 files changed, 294 insertions(+), 162 deletions(-) create mode 100644 src/libtomahawk/utils/BinaryExtractWorker.cpp create mode 100644 src/libtomahawk/utils/BinaryExtractWorker.h create mode 100644 src/libtomahawk/utils/SharedTimeLine.cpp create mode 100644 src/libtomahawk/utils/SharedTimeLine.h diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 170b72524..1e5029426 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -122,6 +122,8 @@ set( libGuiSources utils/SmartPointerList.h utils/AnimatedSpinner.cpp utils/BinaryInstallerHelper.cpp + utils/BinaryExtractWorker.cpp + utils/SharedTimeLine.cpp widgets/AnimatedCounterLabel.cpp widgets/CheckDirTree.cpp diff --git a/src/libtomahawk/utils/BinaryExtractWorker.cpp b/src/libtomahawk/utils/BinaryExtractWorker.cpp new file mode 100644 index 000000000..f05031c57 --- /dev/null +++ b/src/libtomahawk/utils/BinaryExtractWorker.cpp @@ -0,0 +1,104 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2010-2011, Leo Franchi + * Copyright 2010-2012, Jeff Mitchell + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "BinaryExtractWorker.h" + +#include +#include +#include + +#include "utils/TomahawkUtils.h" +#include "utils/Logger.h" + + +namespace TomahawkUtils +{ + +void +BinaryExtractWorker::run() +{ + ScopedDeleter deleter( this ); + +#ifdef Q_OS_MAC + // Platform-specific handling of resolver payload now. We know it's good + // Unzip the file. + QFileInfo info( m_zipFileName ); + QDir tmpDir = QDir::tempPath(); + if ( !tmpDir.mkdir( info.baseName() ) ) + { + qWarning() << "Failed to create temporary directory to unzip in:" << tmpDir.absolutePath(); + return; + } + tmpDir.cd( info.baseName() ); + TomahawkUtils::unzipFileInFolder( info.absoluteFilePath(), tmpDir ); + + // On OSX it just contains 1 file, the resolver executable itself. For now. We just copy it to + // the Tomahawk.app/Contents/MacOS/ folder alongside the Tomahawk executable. + const QString dest = QCoreApplication::applicationDirPath(); + // Find the filename + const QDir toList( tmpDir.absolutePath() ); + const QStringList files = toList.entryList( QStringList(), QDir::Files ); + Q_ASSERT( files.size() == 1 ); + + const QString src = toList.absoluteFilePath( files.first() ); + qDebug() << "OS X: Copying binary resolver from to:" << src << dest; + + copyWithAuthentication( src, dest, m_receiver ); + + return; +#elif defined(Q_OS_WIN) || defined(Q_OS_LINUX) + // We unzip directly to the target location, just like normal attica resolvers + Q_ASSERT( m_receiver ); + if ( !m_receiver ) + return; + + const QString resolverId = m_receiver->property( "resolverid" ).toString(); + + Q_ASSERT( !resolverId.isEmpty() ); + if ( resolverId.isEmpty() ) + return; + + const QDir resolverPath( extractScriptPayload( m_zipFileName, resolverId ) ); + +#ifdef Q_OS_WIN + const QStringList files = resolverPath.entryList( QStringList() << "*.exe", QDir::Files ); +#elif defined(Q_OS_LINUX) + const QStringList files = resolverPath.entryList( QStringList() << "*_tomahawkresolver", QDir::Files ); +#endif + + qDebug() << "Found executables in unzipped binary resolver dir:" << files; + Q_ASSERT( files.size() == 1 ); + if ( files.size() < 1 ) + return; + + const QString resolverToUse = resolverPath.absoluteFilePath( files.first() ); + +#ifdef Q_OS_LINUX + QProcess p; + p.start( "chmod", QStringList() << "744" << resolverToUse, QIODevice::ReadOnly ); + p.waitForFinished(); +#endif + + QMetaObject::invokeMethod( m_receiver, "installSucceeded", Qt::QueuedConnection, Q_ARG( QString, resolverToUse ) ); + +#endif +} + +} diff --git a/src/libtomahawk/utils/BinaryExtractWorker.h b/src/libtomahawk/utils/BinaryExtractWorker.h new file mode 100644 index 000000000..52fceb301 --- /dev/null +++ b/src/libtomahawk/utils/BinaryExtractWorker.h @@ -0,0 +1,59 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2010-2011, Leo Franchi + * Copyright 2010-2012, Jeff Mitchell + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef BINARYEXTRACTWORKER_H +#define BINARYEXTRACTWORKER_H + +#include + +#include "DllMacro.h" + +namespace TomahawkUtils +{ + +class ScopedDeleter +{ +public: + ScopedDeleter( QObject* o ) : m_o( 0 ) {} + ~ScopedDeleter() { m_o->deleteLater(); } + +private: + QObject* m_o; +}; + + +class BinaryExtractWorker : public QThread +{ + Q_OBJECT +public: + BinaryExtractWorker( const QString& zipFilename, QObject* receiver ) : m_zipFileName( zipFilename ), m_receiver( receiver ) {} + virtual ~BinaryExtractWorker() {} + +protected: + virtual void run(); + +private: + QString m_zipFileName; + QObject* m_receiver; +}; + +} + +#endif \ No newline at end of file diff --git a/src/libtomahawk/utils/PixmapDelegateFader.h b/src/libtomahawk/utils/PixmapDelegateFader.h index ee0a71ac7..f79c58774 100644 --- a/src/libtomahawk/utils/PixmapDelegateFader.h +++ b/src/libtomahawk/utils/PixmapDelegateFader.h @@ -23,6 +23,7 @@ #include "Artist.h" #include "Album.h" #include "Query.h" +#include "utils/SharedTimeLine.h" #include #include diff --git a/src/libtomahawk/utils/SharedTimeLine.cpp b/src/libtomahawk/utils/SharedTimeLine.cpp new file mode 100644 index 000000000..cb48befed --- /dev/null +++ b/src/libtomahawk/utils/SharedTimeLine.cpp @@ -0,0 +1,64 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2010-2011, Leo Franchi + * Copyright 2010-2012, Jeff Mitchell + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "SharedTimeLine.h" + + +namespace TomahawkUtils +{ + +SharedTimeLine::SharedTimeLine() + : QObject( 0 ) + , m_refcount( 0 ) +{ + m_timeline.setCurveShape( QTimeLine::LinearCurve ); + m_timeline.setFrameRange( 0, INT_MAX ); + m_timeline.setDuration( INT_MAX ); + m_timeline.setUpdateInterval( 40 ); + connect( &m_timeline, SIGNAL( frameChanged( int ) ), SIGNAL( frameChanged( int ) ) ); +} + + +void +SharedTimeLine::connectNotify( const char* signal ) +{ + if ( signal == QMetaObject::normalizedSignature( SIGNAL( frameChanged( int ) ) ) ) { + m_refcount++; + if ( m_timeline.state() != QTimeLine::Running ) + m_timeline.start(); + } +} + + +void +SharedTimeLine::disconnectNotify( const char* signal ) +{ + if ( signal == QMetaObject::normalizedSignature( SIGNAL( frameChanged( int ) ) ) ) + { + m_refcount--; + if ( m_timeline.state() == QTimeLine::Running && m_refcount == 0 ) + { + m_timeline.stop(); + deleteLater(); + } + } +} + +} \ No newline at end of file diff --git a/src/libtomahawk/utils/SharedTimeLine.h b/src/libtomahawk/utils/SharedTimeLine.h new file mode 100644 index 000000000..5d8d59602 --- /dev/null +++ b/src/libtomahawk/utils/SharedTimeLine.h @@ -0,0 +1,60 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2010-2011, Leo Franchi + * Copyright 2010-2012, Jeff Mitchell + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef SHAREDTIMELINE_H +#define SHAREDTIMELINE_H + +#include +#include + +#include "DllMacro.h" + +namespace TomahawkUtils +{ + +class DLLEXPORT SharedTimeLine : public QObject +{ + Q_OBJECT + + public: + SharedTimeLine(); + + virtual ~SharedTimeLine() {} + + int currentFrame() { return m_timeline.currentFrame(); } + + void setUpdateInterval( int msec ) { if ( msec != m_timeline.updateInterval() ) m_timeline.setUpdateInterval( msec ); } + + signals: + void frameChanged( int ); + + protected slots: + virtual void connectNotify( const char *signal ); + + virtual void disconnectNotify( const char *signal ); + + private: + int m_refcount; + QTimeLine m_timeline; +}; + +} + +#endif \ No newline at end of file diff --git a/src/libtomahawk/utils/TomahawkUtils.cpp b/src/libtomahawk/utils/TomahawkUtils.cpp index 6560ebc04..5adba5422 100644 --- a/src/libtomahawk/utils/TomahawkUtils.cpp +++ b/src/libtomahawk/utils/TomahawkUtils.cpp @@ -25,6 +25,8 @@ #include "utils/TomahawkUtils.h" #include "utils/Logger.h" #include "Source.h" +#include "BinaryExtractWorker.h" +#include "SharedTimeLine.h" #ifdef LIBLASTFM_FOUND #include @@ -55,7 +57,7 @@ #endif #ifdef QCA2_FOUND -#include + #include #endif namespace TomahawkUtils @@ -648,43 +650,6 @@ crash() } -SharedTimeLine::SharedTimeLine() - : QObject( 0 ) - , m_refcount( 0 ) -{ - m_timeline.setCurveShape( QTimeLine::LinearCurve ); - m_timeline.setFrameRange( 0, INT_MAX ); - m_timeline.setDuration( INT_MAX ); - m_timeline.setUpdateInterval( 40 ); - connect( &m_timeline, SIGNAL( frameChanged( int ) ), SIGNAL( frameChanged( int ) ) ); -} - -void -SharedTimeLine::connectNotify( const char* signal ) -{ - if ( signal == QMetaObject::normalizedSignature( SIGNAL( frameChanged( int ) ) ) ) { - m_refcount++; - if ( m_timeline.state() != QTimeLine::Running ) - m_timeline.start(); - } -} - - -void -SharedTimeLine::disconnectNotify( const char* signal ) -{ - if ( signal == QMetaObject::normalizedSignature( SIGNAL( frameChanged( int ) ) ) ) - { - m_refcount--; - if ( m_timeline.state() == QTimeLine::Running && m_refcount == 0 ) - { - m_timeline.stop(); - deleteLater(); - } - } -} - - bool verifyFile( const QString &filePath, const QString &signature ) { @@ -772,7 +737,6 @@ extractScriptPayload( const QString& filename, const QString& resolverId ) } resolverDir.cd( QString( "atticaresolvers/%1" ).arg( resolverId ) ); - if ( !unzipFileInFolder( filename, resolverDir ) ) { qWarning() << "Failed to unzip resolver. Ooops."; @@ -846,99 +810,6 @@ unzipFileInFolder( const QString &zipFileName, const QDir &folder ) } -class ScopedDeleter -{ -public: - ScopedDeleter( QObject* o ) : m_o( 0 ) {} - ~ScopedDeleter() { m_o->deleteLater(); } - -private: - QObject* m_o; -}; - - -class BinaryExtractWorker : public QThread -{ - Q_OBJECT -public: - BinaryExtractWorker( const QString& zipFilename, QObject* receiver ) : m_zipFileName( zipFilename ), m_receiver( receiver ) {} - virtual ~BinaryExtractWorker() {} - -protected: - virtual void run() - { - ScopedDeleter deleter( this ); - -#ifdef Q_OS_MAC - // Platform-specific handling of resolver payload now. We know it's good - // Unzip the file. - QFileInfo info( m_zipFileName ); - QDir tmpDir = QDir::tempPath(); - if ( !tmpDir.mkdir( info.baseName() ) ) - { - qWarning() << "Failed to create temporary directory to unzip in:" << tmpDir.absolutePath(); - return; - } - tmpDir.cd( info.baseName() ); - TomahawkUtils::unzipFileInFolder( info.absoluteFilePath(), tmpDir ); - - // On OSX it just contains 1 file, the resolver executable itself. For now. We just copy it to - // the Tomahawk.app/Contents/MacOS/ folder alongside the Tomahawk executable. - const QString dest = QCoreApplication::applicationDirPath(); - // Find the filename - const QDir toList( tmpDir.absolutePath() ); - const QStringList files = toList.entryList( QStringList(), QDir::Files ); - Q_ASSERT( files.size() == 1 ); - - const QString src = toList.absoluteFilePath( files.first() ); - qDebug() << "OS X: Copying binary resolver from to:" << src << dest; - - copyWithAuthentication( src, dest, m_receiver ); - - return; -#elif defined(Q_OS_WIN) || defined(Q_OS_LINUX) - // We unzip directly to the target location, just like normal attica resolvers - Q_ASSERT( m_receiver ); - if ( !m_receiver ) - return; - - const QString resolverId = m_receiver->property( "resolverid" ).toString(); - - Q_ASSERT( !resolverId.isEmpty() ); - if ( resolverId.isEmpty() ) - return; - - - const QDir resolverPath( extractScriptPayload( m_zipFileName, resolverId ) ); - -#ifdef Q_OS_WIN - const QStringList files = resolverPath.entryList( QStringList() << "*.exe", QDir::Files ); -#elif defined(Q_OS_LINUX) - const QStringList files = resolverPath.entryList( QStringList() << "*_tomahawkresolver", QDir::Files ); -#endif - - qDebug() << "Found executables in unzipped binary resolver dir:" << files; - Q_ASSERT( files.size() == 1 ); - if ( files.size() < 1 ) - return; - - const QString resolverToUse = resolverPath.absoluteFilePath( files.first() ); - -#ifdef Q_OS_LINUX - QProcess p; - p.start( "chmod", QStringList() << "744" << resolverToUse, QIODevice::ReadOnly ); - p.waitForFinished(); -#endif - - QMetaObject::invokeMethod( m_receiver, "installSucceeded", Qt::QueuedConnection, Q_ARG( QString, resolverToUse ) ); - -#endif - } -private: - QString m_zipFileName; - QObject* m_receiver; -}; - void extractBinaryResolver( const QString& zipFilename, QObject* receiver ) { diff --git a/src/libtomahawk/utils/TomahawkUtils.h b/src/libtomahawk/utils/TomahawkUtils.h index 27350e3e1..c3b256ca2 100644 --- a/src/libtomahawk/utils/TomahawkUtils.h +++ b/src/libtomahawk/utils/TomahawkUtils.h @@ -26,12 +26,10 @@ #include #include #include -#include #include #define RESPATH ":/data/" - class QDir; class QNetworkAccessManager; @@ -64,33 +62,6 @@ namespace TomahawkUtils }; - class DLLEXPORT SharedTimeLine : public QObject - { - Q_OBJECT - - public: - SharedTimeLine(); - - virtual ~SharedTimeLine() {} - - int currentFrame() { return m_timeline.currentFrame(); } - - void setUpdateInterval( int msec ) { if ( msec != m_timeline.updateInterval() ) m_timeline.setUpdateInterval( msec ); } - - signals: - void frameChanged( int ); - - protected slots: - virtual void connectNotify( const char *signal ); - - virtual void disconnectNotify( const char *signal ); - - private: - int m_refcount; - QTimeLine m_timeline; - }; - - class DLLEXPORT NetworkProxyFactory : public QNetworkProxyFactory { public: @@ -143,7 +114,6 @@ namespace TomahawkUtils DLLEXPORT QString extractScriptPayload( const QString& filename, const QString& resolverId ); DLLEXPORT bool unzipFileInFolder( const QString& zipFileName, const QDir& folder ); - // Extracting may be asynchronous, pass in a receiver object with the following slots: // extractSucceeded( const QString& path ) and extractFailed() to be notified/ DLLEXPORT void extractBinaryResolver( const QString& zipFilename, QObject* receiver ); diff --git a/src/libtomahawk/widgets/FadingPixmap.h b/src/libtomahawk/widgets/FadingPixmap.h index 9096e2a40..5e4928817 100644 --- a/src/libtomahawk/widgets/FadingPixmap.h +++ b/src/libtomahawk/widgets/FadingPixmap.h @@ -20,6 +20,7 @@ #ifndef FADINGPIXMAP_H #define FADINGPIXMAP_H +#include "utils/SharedTimeLine.h" #include "utils/TomahawkUtils.h" #include