Permalink
Browse files

Hide the share action from AudioControls if there's no InfoPlugin that

can be used to share a track.
  • Loading branch information...
teo committed Jan 16, 2013
1 parent 7d94df1 commit acf324279a335a36b734c3e34d628231e3dca4bc
View
@@ -2,6 +2,7 @@
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
+ * Copyright 2013, Teo Mrnjavac <teo@kde.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
@@ -151,6 +152,10 @@ AudioControls::AudioControls( QWidget* parent )
ui->pauseButton->setContentsMargins( 0, 0, 0, 0 );
ui->stackedLayout->setSizeConstraint( QLayout::SetFixedSize );
+ connect( InfoSystem::InfoSystem::instance(), SIGNAL( updatedSupportedPushTypes( Tomahawk::InfoSystem::InfoTypeSet ) ),
+ this, SLOT( onInfoSystemPushTypesUpdated( Tomahawk::InfoSystem::InfoTypeSet ) ) );
+ onInfoSystemPushTypesUpdated( InfoSystem::InfoSystem::instance()->supportedPushTypes() );
+
onPlaybackStopped(); // initial state
}
@@ -272,7 +277,7 @@ AudioControls::onPlaybackLoading( const Tomahawk::result_ptr& result )
ui->loveButton->setEnabled( true );
ui->loveButton->setVisible( true );
ui->socialButton->setEnabled( true );
- ui->socialButton->setVisible( true );
+ ui->socialButton->setVisible( m_shouldShowShareAction );
ui->ownerButton->setEnabled( true );
ui->ownerButton->setVisible( true );
@@ -351,6 +356,25 @@ AudioControls::onSocialActionsLoaded()
}
+void
+AudioControls::onInfoSystemPushTypesUpdated( InfoSystem::InfoTypeSet supportedTypes )
+{
@lfranchi

lfranchi Jan 16, 2013

Member

You could write these 8 lines as:

m_shouldShowShareAction = supportedTypes.contains( InfoSystem::InfoShareTrack )

:)

+ if ( supportedTypes.contains( InfoSystem::InfoShareTrack ) )
+ {
+ m_shouldShowShareAction = true;
+ }
+ else
+ {
+ m_shouldShowShareAction = false;
+ }
+
+ if ( AudioEngine::instance()->state() == AudioEngine::Stopped )
+ ui->socialButton->setVisible( false );
+ else
+ ui->socialButton->setVisible( m_shouldShowShareAction );
+}
+
+
void
AudioControls::setSocialActions()
{
View
@@ -89,6 +89,8 @@ private slots:
void onCoverUpdated();
void onSocialActionsLoaded();
+ void onInfoSystemPushTypesUpdated( Tomahawk::InfoSystem::InfoTypeSet supportedTypes );
+
private:
void setCover();
void setSocialActions();
@@ -100,6 +102,7 @@ private slots:
Tomahawk::result_ptr m_currentTrack;
Tomahawk::PlaylistModes::RepeatMode m_repeatMode;
bool m_shuffled;
+ bool m_shouldShowShareAction;
QTimer m_phononTickCheckTimer;
QTimeLine m_sliderTimeLine;
@@ -173,6 +173,12 @@ InfoSystem::init()
connect( worker, SIGNAL( finished( QString, Tomahawk::InfoSystem::InfoType ) ),
this, SIGNAL( finished( QString, Tomahawk::InfoSystem::InfoType ) ), Qt::UniqueConnection );
+ qRegisterMetaType< Tomahawk::InfoSystem::InfoTypeSet >();
+ connect( worker, SIGNAL( updatedSupportedGetTypes( Tomahawk::InfoSystem::InfoTypeSet ) ),
+ this, SLOT( receiveUpdatedSupportedGetTypes( Tomahawk::InfoSystem::InfoTypeSet ) ) );
+ connect( worker, SIGNAL( updatedSupportedPushTypes( Tomahawk::InfoSystem::InfoTypeSet ) ),
+ this, SLOT( receiveUpdatedSupportedPushTypes( Tomahawk::InfoSystem::InfoTypeSet ) ) );
+
QMetaObject::invokeMethod( worker, "init", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoSystemCache*, cache ) );
m_inited = true;
@@ -269,6 +269,7 @@ Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoType );
Q_DECLARE_METATYPE( QList< Tomahawk::InfoSystem::InfoStringHash > );
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoPluginPtr );
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoPlugin* );
+Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoTypeSet );
Q_DECLARE_INTERFACE( Tomahawk::InfoSystem::InfoPlugin, "tomahawk.InfoPlugin/1.0" )

0 comments on commit acf3242

Please sign in to comment.