1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-30 17:20:26 +02:00

* Fixed a few ScanManager issues.

* Added changed() signal to TomahawkSettings and hooked up ScanManager and SipHandler to it.
This commit is contained in:
Christian Muehlhaeuser
2011-02-15 08:23:12 +01:00
parent 35484b0357
commit 795d71213e
12 changed files with 107 additions and 88 deletions

View File

@@ -13,12 +13,15 @@
class DLLEXPORT TomahawkSettings : public QSettings
{
Q_OBJECT
public:
static TomahawkSettings* instance();
explicit TomahawkSettings( QObject* parent = 0 );
virtual ~TomahawkSettings();
void applyChanges() { emit changed(); }
/// General settings
QString scannerPath() const; /// QDesktopServices::MusicLocation by default
void setScannerPath( const QString& path );
@@ -135,11 +138,13 @@ public:
void setXmppBotPort( const int port );
/// Script resolver settings
QStringList scriptResolvers() const;
void setScriptResolvers( const QStringList& resolver );
void addScriptResolver( const QString& resolver );
signals:
void changed();
private:
static TomahawkSettings* s_instance;
};

View File

@@ -8,6 +8,7 @@
using namespace Tomahawk;
MusicScanner::MusicScanner( const QString& dir, quint32 bs )
: QObject()
, m_dir( dir )
@@ -30,6 +31,7 @@ MusicScanner::MusicScanner( const QString& dir, quint32 bs )
// m_ext2mime.insert( "mp4", "audio/mp4" );
}
void
MusicScanner::startScan()
{
@@ -75,7 +77,7 @@ MusicScanner::scan()
connect( m_dirLister, SIGNAL( finished( const QMap<QString, unsigned int>& ) ),
SLOT( listerFinished( const QMap<QString, unsigned int>& ) ), Qt::QueuedConnection );
connect( m_dirLister, SIGNAL( destroyed(QObject*) ), this, SLOT( listerDestroyed(QObject*) ) );
connect( m_dirLister, SIGNAL( destroyed( QObject* ) ), SLOT( listerDestroyed( QObject* ) ) );
m_dirListerThreadController->start();
QMetaObject::invokeMethod( m_dirLister, "go" );
@@ -106,6 +108,7 @@ MusicScanner::listerFinished( const QMap<QString, unsigned int>& newmtimes )
qDebug() << s;
m_dirLister->deleteLater();
deleteLater();
}
@@ -118,6 +121,7 @@ MusicScanner::listerDestroyed( QObject* dirLister )
m_dirListerThreadController = 0;
}
void
MusicScanner::commitBatch( const QVariantList& tracks )
{

View File

@@ -1,9 +1,11 @@
#include "scanmanager.h"
#include "musicscanner.h"
#include <QDebug>
#include <QThread>
#include "musicscanner.h"
#include "tomahawksettings.h"
ScanManager* ScanManager::s_instance = 0;
@@ -20,6 +22,8 @@ ScanManager::ScanManager( QObject* parent )
, m_musicScannerThreadController( 0 )
{
s_instance = this;
connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( onSettingsChanged() ) );
}
@@ -32,6 +36,15 @@ ScanManager::~ScanManager()
m_scanner = 0;
}
void
ScanManager::onSettingsChanged()
{
if ( TomahawkSettings::instance()->hasScannerPath() )
runManualScan( TomahawkSettings::instance()->scannerPath() );
}
void
ScanManager::runManualScan( const QString& path )
{
@@ -41,13 +54,13 @@ ScanManager::runManualScan( const QString &path )
m_musicScannerThreadController = new QThread( this );
MusicScanner* m_scanner = new MusicScanner( path );
m_scanner->moveToThread( m_musicScannerThreadController );
connect( m_scanner, SIGNAL( finished() ), m_scanner, SLOT( deleteLater() ) );
connect( m_scanner, SIGNAL( destroyed(QObject*) ), this, SLOT( scanDestroyed(QObject*) ) );
connect( m_scanner, SIGNAL( destroyed( QObject* ) ), this, SLOT( scannerDestroyed( QObject* ) ) );
m_musicScannerThreadController->start( QThread::IdlePriority );
QMetaObject::invokeMethod( m_scanner, "startScan" );
}
}
void
ScanManager::scannerDestroyed( QObject* scanner )
{
@@ -56,3 +69,4 @@ ScanManager::scannerDestroyed( QObject* scanner )
m_musicScannerThreadController->deleteLater();
m_musicScannerThreadController = 0;
}

View File

@@ -11,6 +11,7 @@ class QThread;
class ScanManager : public QObject
{
Q_OBJECT
public:
static ScanManager* instance();
@@ -22,6 +23,8 @@ public:
private slots:
void scannerDestroyed( QObject* scanner );
void onSettingsChanged();
private:
static ScanManager* s_instance;

View File

@@ -107,20 +107,7 @@ SettingsDialog::~SettingsDialog()
{
TomahawkSettings* s = TomahawkSettings::instance();
// if jabber or scan dir changed, reconnect/rescan
bool rescan = ui->lineEditMusicPath->text() != s->scannerPath();
bool rejabber = false;
if ( ui->jabberUsername->text() != s->jabberUsername() ||
ui->jabberPassword->text() != s->jabberPassword() ||
ui->jabberServer->text() != s->jabberServer() ||
(uint)(ui->jabberPort->value()) != s->jabberPort()
)
{
rejabber = true;
}
s->setHttpEnabled( ui->checkBoxHttp->checkState() == Qt::Checked );
s->setPreferStaticHostPort( ui->checkBoxStaticPreferred->checkState() == Qt::Checked );
s->setExternalAddressMode( ui->checkBoxUpnp->checkState() == Qt::Checked ? TomahawkSettings::Upnp : TomahawkSettings::Lan );
@@ -140,19 +127,13 @@ SettingsDialog::~SettingsDialog()
s->setLastFmPassword( ui->lineEditLastfmPassword->text() );
QStringList resolvers;
for( int i = 0; i < ui->scriptList->topLevelItemCount(); i++ ) {
for( int i = 0; i < ui->scriptList->topLevelItemCount(); i++ )
{
resolvers << ui->scriptList->topLevelItem( i )->data( 1, Qt::DisplayRole ).toString();
}
s->setScriptResolvers( resolvers );
if( rescan )
ScanManager::instance()->runManualScan( s->scannerPath() );
if( rejabber )
{
APP->sipHandler()->disconnectPlugins();
APP->sipHandler()->connectPlugins();
}
s->applyChanges();
}
else
qDebug() << "Settings dialog cancelled, NOT saving prefs.";
@@ -255,8 +236,8 @@ SettingsDialog::onLastFmFinished()
qDebug() << "ERROR from last.fm:" << lfm.text();
ui->pushButtonTestLastfmLogin->setText( tr( "Failed" ) );
ui->pushButtonTestLastfmLogin->setEnabled( true );
} else
}
else
{
ui->pushButtonTestLastfmLogin->setText( tr( "Success" ) );
ui->pushButtonTestLastfmLogin->setEnabled( false );
@@ -278,6 +259,7 @@ SettingsDialog::onLastFmFinished()
#endif
}
void
SettingsDialog::authenticateTwitter()
{
@@ -308,6 +290,7 @@ SettingsDialog::authenticateTwitter()
}
}
void
SettingsDialog::startPostGotTomahawkStatus()
{
@@ -327,6 +310,7 @@ SettingsDialog::startPostGotTomahawkStatus()
credVerifier->verify();
}
void
SettingsDialog::postGotTomahawkStatusAuthVerifyReply( const QTweetUser &user )
{
@@ -348,6 +332,7 @@ SettingsDialog::postGotTomahawkStatusAuthVerifyReply( const QTweetUser &user )
statUpdate->post( QString( "Got Tomahawk? {" ) + Database::instance()->dbid() + QString( "} (" ) + uuid.mid( 1, 8 ) + QString( ")" ) );
}
void
SettingsDialog::postGotTomahawkStatusUpdateReply( const QTweetStatus& status )
{
@@ -356,6 +341,8 @@ SettingsDialog::postGotTomahawkStatusUpdateReply( const QTweetStatus& status )
else
QMessageBox::information( 0, QString("Tweeted!"), QString("Your tweet has been posted!") );
}
void
SettingsDialog::postGotTomahawkStatusUpdateError( QTweetNetBase::ErrorCode code, const QString& errorMsg )
{
@@ -364,6 +351,7 @@ SettingsDialog::postGotTomahawkStatusUpdateError( QTweetNetBase::ErrorCode code,
QMessageBox::critical( 0, QString("Tweetin' Error"), QString("There was an error posting your status -- sorry!") );
}
ProxyDialog::ProxyDialog( QWidget *parent )
: QDialog( parent )
, ui( new Ui::ProxyDialog )
@@ -422,6 +410,7 @@ ProxyDialog::saveSettings()
QNetworkProxy::setApplicationProxy( proxy );
}
void
SettingsDialog::addScriptResolver()
{
@@ -434,6 +423,7 @@ SettingsDialog::addScriptResolver()
}
}
void
SettingsDialog::removeScriptResolver()
{
@@ -446,6 +436,7 @@ SettingsDialog::removeScriptResolver()
}
}
void
SettingsDialog::scriptSelectionChanged()
{

View File

@@ -37,7 +37,7 @@ public:
explicit SettingsDialog( QWidget* parent = 0 );
~SettingsDialog();
Q_SIGNALS:
signals:
void settingsChanged();
protected:
@@ -45,10 +45,10 @@ protected:
private slots:
void onRejected();
void showPathSelector();
void toggleUpnp( bool preferStaticEnabled );
void showProxySettings();
void testLastFmLogin();

View File

@@ -9,6 +9,7 @@
#include "database/database.h"
#include "network/controlconnection.h"
#include "sourcelist.h"
#include "tomahawksettings.h"
SipHandler::SipHandler( QObject* parent )
@@ -16,6 +17,8 @@ SipHandler::SipHandler( QObject* parent )
, m_connected( false )
{
loadPlugins( findPlugins() );
connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( onSettingsChanged() ) );
}
@@ -25,6 +28,14 @@ SipHandler::~SipHandler()
}
void
SipHandler::onSettingsChanged()
{
disconnectPlugins();
connectPlugins();
}
QStringList
SipHandler::findPlugins()
{
@@ -122,8 +133,12 @@ SipHandler::connectPlugins( bool startup, const QString &pluginName )
if ( pluginName.isEmpty() || ( !pluginName.isEmpty() && sip->name() == pluginName ) )
sip->connectPlugin( startup );
}
if ( pluginName.isEmpty() )
{
m_connected = true;
}
}
void
@@ -134,6 +149,7 @@ SipHandler::disconnectPlugins( const QString &pluginName )
if ( pluginName.isEmpty() || ( !pluginName.isEmpty() && sip->name() == pluginName ) )
sip->disconnectPlugin();
}
if ( pluginName.isEmpty() )
{
SourceList::instance()->removeAllRemote();
@@ -141,6 +157,7 @@ SipHandler::disconnectPlugins( const QString &pluginName )
}
}
void
SipHandler::toggleConnect()
{

View File

@@ -34,6 +34,8 @@ private slots:
void onPeerOnline( const QString& );
void onError( int code, const QString& msg );
void onSettingsChanged();
private:
QStringList findPlugins();
void loadPlugins( const QStringList& paths );

View File

@@ -12,12 +12,14 @@ JabberPlugin::setProxy( QNetworkProxy* proxy )
p->setProxy( proxy );
}
const QString
JabberPlugin::name()
{
return QString( MYNAME );
}
bool
JabberPlugin::connectPlugin( bool startup )
{

View File

@@ -31,39 +31,26 @@ public slots:
void disconnectPlugin()
{
QMetaObject::invokeMethod( p,
"disconnect",
Qt::QueuedConnection
);
if ( p )
p->disconnect();
}
void sendMsg( const QString& to, const QString& msg )
{
QMetaObject::invokeMethod( p,
"sendMsg",
Qt::QueuedConnection,
Q_ARG(const QString, to),
Q_ARG(const QString, msg)
);
if ( p )
p->sendMsg( to, msg );
}
void broadcastMsg( const QString &msg )
{
QMetaObject::invokeMethod( p,
"broadcastMsg",
Qt::QueuedConnection,
Q_ARG(const QString, msg)
);
if ( p )
p->broadcastMsg( msg );
}
void addContact( const QString &jid, const QString& msg = QString() )
{
QMetaObject::invokeMethod( p,
"addContact",
Qt::QueuedConnection,
Q_ARG(const QString, jid),
Q_ARG(const QString, msg)
);
if ( p )
p->addContact( jid, msg );
}
private slots:

View File

@@ -232,9 +232,6 @@ TomahawkWindow::showSettingsDialog()
qDebug() << Q_FUNC_INFO;
SettingsDialog win;
win.exec();
// settings are written in SettingsDialog destructor, bleh
QTimer::singleShot( 0, this, SIGNAL( settingsChanged() ) );
}

View File

@@ -34,9 +34,6 @@ public:
void setWindowTitle( const QString& title );
signals:
void settingsChanged();
protected:
void changeEvent( QEvent* e );
void closeEvent( QCloseEvent* e );