1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-21 00:12:06 +02:00

Reimplemented toggle all accounts functionality in the Accounts widget.

Also many layout fixes in the accounts widget.
This replaces the old Go Online/Go Offline feature, but behaves a bit
differently. Specifically, it does not disconnect all resolvers or
peers.
This commit is contained in:
Teo Mrnjavac 2012-10-03 20:59:44 +02:00
parent 5b7d3f6bfd
commit 2162344173
11 changed files with 137 additions and 60 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -116,7 +116,7 @@
<file>data/sql/dbmigrate-25_to_26.sql</file>
<file>data/sql/dbmigrate-26_to_27.sql</file>
<file>data/sql/dbmigrate-27_to_28.sql</file>
<file>data/sql/dbmigrate-28_to_29.sql</file>
<file>data/sql/dbmigrate-28_to_29.sql</file>
<file>data/js/tomahawk.js</file>
<file>data/images/avatar_frame.png</file>
<file>data/images/drop-all-songs.png</file>
@ -158,5 +158,7 @@
<file>data/images/soundcloud.png</file>
<file>data/images/resolver-default.png</file>
<file>data/images/spotify-sourceicon.png</file>
<file>data/images/account-offline.png</file>
<file>data/images/account-online.png</file>
</qresource>
</RCC>

View File

@ -137,7 +137,6 @@ TomahawkWindow::TomahawkWindow( QWidget* parent )
}
// set initial state
onAccountDisconnected();
audioStopped();
vm->setQueue( m_queueView );
@ -1157,20 +1156,6 @@ TomahawkWindow::onPlaybackLoading( const Tomahawk::result_ptr& result )
}
void
TomahawkWindow::onAccountConnected()
{
ActionCollection::instance()->getAction( "toggleOnline" )->setText( tr( "Go &Offline" ) );
}
void
TomahawkWindow::onAccountDisconnected()
{
ActionCollection::instance()->getAction( "toggleOnline" )->setText( tr( "Go &Online" ) );
}
void
TomahawkWindow::onAccountError()
{

View File

@ -107,8 +107,6 @@ public slots:
void fullScreenExited();
private slots:
void onAccountConnected();
void onAccountDisconnected();
void onAccountError();
void onHistoryBackAvailable( bool avail );

View File

@ -70,8 +70,6 @@ ActionCollection::initActions()
m_actionCollection[ "togglePrivacy" ] = privacyToggle;
connect( m_actionCollection[ "togglePrivacy" ], SIGNAL( triggered() ), SLOT( togglePrivateListeningMode() ), Qt::UniqueConnection );
m_actionCollection[ "toggleOnline" ] = new QAction( tr( "Go &Online" ), this );
m_actionCollection[ "loadPlaylist" ] = new QAction( tr( "&Load Playlist" ), this );
m_actionCollection[ "renamePlaylist" ] = new QAction( tr( "&Rename Playlist" ), this );
m_actionCollection[ "copyPlaylist" ] = new QAction( tr( "&Copy Playlist Link" ), this );

View File

@ -23,13 +23,18 @@
#include "utils/TomahawkUtilsGui.h"
#include <QDebug>
#include <QPushButton>
AccountListWidget::AccountListWidget( AccountModelFactoryProxy* model, QWidget* parent )
: QWidget( parent )
, m_model( model )
{
m_layout = new QVBoxLayout( this );
QVBoxLayout* mainLayout = new QVBoxLayout( this );
TomahawkUtils::unmarginLayout( mainLayout );
m_layout = new QVBoxLayout;
TomahawkUtils::unmarginLayout( m_layout );
mainLayout->addLayout( m_layout );
mainLayout->setSpacing( 8 );
connect( m_model, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ),
this, SLOT( updateEntries( QModelIndex, QModelIndex ) ) );
@ -39,6 +44,36 @@ AccountListWidget::AccountListWidget( AccountModelFactoryProxy* model, QWidget*
this, SLOT( removeEntries( QModelIndex, int, int ) ) );
connect( m_model, SIGNAL( modelReset() ),
this, SLOT( loadAllEntries() ) );
connect( m_model, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ),
this, SLOT( updateToggleOnlineStateButton() ) );
QWidget* separatorLine = new QWidget( this );
separatorLine->setFixedHeight( 1 );
separatorLine->setContentsMargins( 0, 0, 0, 0 );
separatorLine->setStyleSheet( "QWidget { border-top: 1px solid black; }" );
mainLayout->insertWidget( 0, separatorLine );
mainLayout->addSpacing( 6 );
QLabel *connectionsLabel = new QLabel( tr( "Connections" ), this );
QFont clFont = connectionsLabel->font();
clFont.setBold( true );
clFont.setPointSize( TomahawkUtils::defaultFontSize() + 3 );
connectionsLabel->setFont( clFont );
connectionsLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
m_toggleOnlineButton = new QPushButton( tr( "Connect &All" ), this );
m_toggleOnlineButtonState = false;
connect( m_toggleOnlineButton, SIGNAL( clicked() ),
this, SLOT( toggleOnlineStateForAll() ) );
QHBoxLayout *headerLayout = new QHBoxLayout( this );
headerLayout->addWidget( connectionsLabel );
headerLayout->addSpacing( 30 );
headerLayout->addWidget( m_toggleOnlineButton );
mainLayout->insertLayout( 0, headerLayout );
updateToggleOnlineStateButton();
}
void
@ -147,3 +182,41 @@ AccountListWidget::removeEntries( const QModelIndex& parent, int start, int end
adjustSize();
qobject_cast< QWidget* >( QWidget::parent() )->adjustSize();
}
void
AccountListWidget::toggleOnlineStateForAll()
{
bool newState = !m_toggleOnlineButtonState;
foreach ( QList< AccountWidget* > awgts, m_entries )
{
foreach ( AccountWidget* awgt, awgts )
{
awgt->setConnectionState( newState );
}
}
}
void
AccountListWidget::updateToggleOnlineStateButton()
{
bool newState = false;
foreach ( QList< AccountWidget* > awgts, m_entries )
{
foreach ( AccountWidget* awgt, awgts )
{
if ( awgt->connectionState() )
{
newState = true;
goto end; //break 2 levels
}
}
}
end:;
m_toggleOnlineButtonState = newState;
m_toggleOnlineButton->setText( m_toggleOnlineButtonState ? tr( "Disconnect &All" )
: tr( "Connect &All" ) );
m_toggleOnlineButton->setIcon( m_toggleOnlineButtonState ? QIcon( RESPATH "images/account-offline.png" )
: QIcon( RESPATH "images/account-online.png" ) );
}

View File

@ -25,6 +25,7 @@
#include <QVBoxLayout>
class AccountWidget;
class QPushButton;
class AccountListWidget : public QWidget
{
@ -36,13 +37,17 @@ private slots:
void updateEntries( const QModelIndex& topLeft, const QModelIndex& bottomRight );
void updateEntry( const QPersistentModelIndex& idx );
void loadAllEntries();
void insertEntries( const QModelIndex& parent, int start, int end );
void removeEntries( const QModelIndex& parent, int start, int end );
void insertEntries( const QModelIndex& parent, int start, int end );
void removeEntries( const QModelIndex& parent, int start, int end );
void toggleOnlineStateForAll();
void updateToggleOnlineStateButton();
private:
QHash< QPersistentModelIndex, QList< AccountWidget* > > m_entries;
AccountModelFactoryProxy* m_model;
QVBoxLayout* m_layout;
QPushButton* m_toggleOnlineButton;
bool m_toggleOnlineButtonState;
};
#endif // ACCOUNTLISTWIDGET_H

View File

@ -44,15 +44,14 @@ AccountWidget::AccountWidget( QWidget* parent )
QHBoxLayout *mainLayout = new QHBoxLayout( this );
TomahawkUtils::unmarginLayout( mainLayout );
setLayout( mainLayout );
setContentsMargins( 8, 8, 8, 8 );
setContentsMargins( 0, 8, 0, 8 );
m_imageLabel = new QLabel( this );
mainLayout->addWidget( m_imageLabel );
mainLayout->setSpacing( 4 );
QGridLayout* vLayout = new QGridLayout( this );
vLayout->setMargin( 3 );
vLayout->setSpacing( 3 );
vLayout->setSpacing( 8 );
mainLayout->addLayout( vLayout );
QFrame* idContainer = new QFrame( this );
@ -95,12 +94,11 @@ AccountWidget::AccountWidget( QWidget* parent )
vLayout->addLayout( statusToggleLayout, 0, 1, 1, 1 );
statusToggleLayout->addStretch();
statusToggleLayout->addWidget( m_statusToggle );
//vLayout->addWidget( m_statusToggle, 0, 1 );
m_inviteContainer = new UnstyledFrame( this );
vLayout->addWidget( m_inviteContainer, 1, 0 );
m_inviteContainer->setFrameColor( QColor( 0x8c, 0x8c, 0x8c ) ); //from ProxyStyle
m_inviteContainer->setFixedWidth( m_inviteContainer->logicalDpiX() * 2 );
m_inviteContainer->setMinimumWidth( m_inviteContainer->logicalDpiX() * 2 );
m_inviteContainer->setContentsMargins( 1, 1, 1, 2 );
m_inviteContainer->setAttribute( Qt::WA_TranslucentBackground, false );
m_inviteContainer->setStyleSheet( "background: white" );
@ -121,12 +119,13 @@ AccountWidget::AccountWidget( QWidget* parent )
m_inviteEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
containerLayout->addWidget( m_inviteEdit );
m_inviteEdit->setFrame( false );
idContainer->setFixedWidth( m_inviteContainer->width() );
m_inviteButton = new QPushButton( this );
m_inviteButton->setMinimumWidth( m_inviteButton->logicalDpiX() * 0.8 );
m_inviteButton->setText( tr( "Invite" ) );
m_inviteButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred );
vLayout->addWidget( m_inviteButton, 1, 1 );
vLayout->setColumnStretch( 0, 1 );
#ifdef Q_OS_MAC
@ -211,6 +210,21 @@ AccountWidget::update( const QPersistentModelIndex& idx, int accountIdx )
m_statusToggle->setBackChecked( true );
setInviteWidgetsEnabled( false );
}
if ( !account->enabled() && account->connectionState() == Tomahawk::Accounts::Account::Disconnected )
{
m_spinner->fadeOut();
m_statusToggle->setBackChecked( false );
m_statusToggle->setChecked( false );
setInviteWidgetsEnabled( false );
}
else if ( account->enabled() && account->connectionState() == Tomahawk::Accounts::Account::Connected )
{
m_spinner->fadeOut();
m_statusToggle->setBackChecked( true );
m_statusToggle->setChecked( true );
setInviteWidgetsEnabled( true );
}
}
}
@ -282,3 +296,14 @@ AccountWidget::setupConnections( const QPersistentModelIndex& idx, int accountId
m_inviteEdit->setPlaceholderText( account->sipPlugin()->inviteString() );
}
}
void
AccountWidget::setConnectionState( bool state )
{
m_statusToggle->setChecked( state );
}
bool AccountWidget::connectionState() const
{
return m_statusToggle->isChecked() || m_statusToggle->backChecked();
}

View File

@ -42,6 +42,9 @@ public:
void update( const QPersistentModelIndex& idx, int accountIdx );
void setupConnections( const QPersistentModelIndex& idx, int accountIdx );
void setConnectionState( bool state );
bool connectionState() const;
private slots:
void changeAccountConnectionState( bool connected );
void sendInvite();

View File

@ -19,8 +19,8 @@
#include "AccountsToolButton.h"
#include "AccountListWidget.h"
#include "accounts/AccountManager.h"
#include "utils/TomahawkUtilsGui.h"
#include "ActionCollection.h"
#include <QLabel>
#include <QListView>
@ -48,36 +48,6 @@ AccountsToolButton::AccountsToolButton( QWidget* parent )
w->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
QVBoxLayout *wMainLayout = new QVBoxLayout( w );
w->setLayout( wMainLayout );
QLabel *connectionsLabel = new QLabel( tr( "Connections" ), w );
QToolButton *toggleOnlineButton = new QToolButton( w );
toggleOnlineButton->setIcon( QIcon( RESPATH "images/view-toggle-icon-cloud-active.png" ) ); //TODO: real icon
toggleOnlineButton->setText( tr( "Toggle Online" ) );
toggleOnlineButton->setDefaultAction( ActionCollection::instance()->getAction( "toggleOnline" ) );
QFont clFont = connectionsLabel->font();
clFont.setBold( true );
clFont.setPointSize( TomahawkUtils::defaultFontSize() + 3 );
connectionsLabel->setFont( clFont );
connectionsLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
QPushButton *settingsButton = new QPushButton( w );
settingsButton->setIcon( QIcon( RESPATH "images/account-settings.png" ) );
settingsButton->setText( tr( "Configure Accounts" ) );
connect( settingsButton, SIGNAL( clicked() ),
window(), SLOT( showSettingsDialog() ) );
QHBoxLayout *headerLayout = new QHBoxLayout( w );
headerLayout->addWidget( connectionsLabel );
headerLayout->addWidget( toggleOnlineButton );
headerLayout->addSpacing( 30 );
headerLayout->addWidget( settingsButton );
wMainLayout->addLayout( headerLayout );
QWidget *separatorLine = new QWidget( w );
separatorLine->setFixedHeight( 1 );
separatorLine->setContentsMargins( 0, 0, 0, 0 );
separatorLine->setStyleSheet( "QWidget { border-top: 1px solid black; }" );
wMainLayout->addWidget( separatorLine );
#ifdef Q_OS_MAC
w->setContentsMargins( 4, 4, 2, 2 );
@ -101,6 +71,24 @@ AccountsToolButton::AccountsToolButton( QWidget* parent )
connect( m_proxy, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ),
this, SLOT( repaint() ) );
QWidget *separatorLine = new QWidget( w );
separatorLine->setFixedHeight( 1 );
separatorLine->setContentsMargins( 0, 0, 0, 0 );
separatorLine->setStyleSheet( "QWidget { border-top: 1px solid black; }" );
wMainLayout->addWidget( separatorLine );
QPushButton *settingsButton = new QPushButton( w );
settingsButton->setIcon( QIcon( RESPATH "images/account-settings.png" ) );
settingsButton->setText( tr( "Configure Accounts" ) );
connect( settingsButton, SIGNAL( clicked() ),
window(), SLOT( showSettingsDialog() ) );
QHBoxLayout *bottomLayout = new QHBoxLayout( w );
bottomLayout->addStretch();
bottomLayout->addWidget( settingsButton );
wMainLayout->addLayout( bottomLayout );
//ToolButton stuff
m_defaultPixmap = QPixmap( RESPATH "images/account-none.png" )
.scaled( iconSize(),