mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 16:29:43 +01:00
* Split out BinaryExtractWorker and SharedTimeLine into separate files.
This commit is contained in:
parent
a3d11225a3
commit
f160947ddc
@ -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
|
||||
|
104
src/libtomahawk/utils/BinaryExtractWorker.cpp
Normal file
104
src/libtomahawk/utils/BinaryExtractWorker.cpp
Normal file
@ -0,0 +1,104 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "BinaryExtractWorker.h"
|
||||
|
||||
#include <QVariant>
|
||||
#include <QDir>
|
||||
#include <QProcess>
|
||||
|
||||
#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
|
||||
}
|
||||
|
||||
}
|
59
src/libtomahawk/utils/BinaryExtractWorker.h
Normal file
59
src/libtomahawk/utils/BinaryExtractWorker.h
Normal file
@ -0,0 +1,59 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef BINARYEXTRACTWORKER_H
|
||||
#define BINARYEXTRACTWORKER_H
|
||||
|
||||
#include <QThread>
|
||||
|
||||
#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
|
@ -23,6 +23,7 @@
|
||||
#include "Artist.h"
|
||||
#include "Album.h"
|
||||
#include "Query.h"
|
||||
#include "utils/SharedTimeLine.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QTimeLine>
|
||||
|
64
src/libtomahawk/utils/SharedTimeLine.cpp
Normal file
64
src/libtomahawk/utils/SharedTimeLine.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
60
src/libtomahawk/utils/SharedTimeLine.h
Normal file
60
src/libtomahawk/utils/SharedTimeLine.h
Normal file
@ -0,0 +1,60 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SHAREDTIMELINE_H
|
||||
#define SHAREDTIMELINE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QTimeLine>
|
||||
|
||||
#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
|
@ -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 <lastfm/ws.h>
|
||||
@ -55,7 +57,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef QCA2_FOUND
|
||||
#include <QtCrypto>
|
||||
#include <QtCrypto>
|
||||
#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 )
|
||||
{
|
||||
|
@ -26,12 +26,10 @@
|
||||
#include <QtCore/QThread>
|
||||
#include <QtNetwork/QNetworkProxy>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QTimeLine>
|
||||
#include <Typedefs.h>
|
||||
|
||||
#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 );
|
||||
|
@ -20,6 +20,7 @@
|
||||
#ifndef FADINGPIXMAP_H
|
||||
#define FADINGPIXMAP_H
|
||||
|
||||
#include "utils/SharedTimeLine.h"
|
||||
#include "utils/TomahawkUtils.h"
|
||||
|
||||
#include <QLabel>
|
||||
|
Loading…
x
Reference in New Issue
Block a user