1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-20 07:52:30 +02:00

fix menus for jreen and jabber plugins. now added when connected, removed when disconnected.

and no crashy.
This commit is contained in:
Leo Franchi 2011-03-14 16:58:36 -04:00
parent 1ac8f84020
commit de5a2b7d65
8 changed files with 108 additions and 25 deletions

View File

@ -38,6 +38,9 @@ signals:
void peerOnline( const QString& );
void peerOffline( const QString& );
void msgReceived( const QString& from, const QString& msg );
void addMenu( QMenu* menu );
void removeMenu( QMenu* menu );
};
Q_DECLARE_INTERFACE( SipPlugin, "tomahawk.Sip/1.0" )

View File

@ -286,6 +286,6 @@ SipHandler::onError( int code, const QString& msg )
else
{
SipPlugin* sip = qobject_cast<SipPlugin*>(sender());
QTimer::singleShot( 10000, sip, SLOT( connect() ) );
QTimer::singleShot( 10000, sip, SLOT( connectPlugin() ) );
}
}

View File

@ -9,15 +9,9 @@
JabberPlugin::JabberPlugin()
: p( 0 ),
m_menu ( 0 )
m_menu ( 0 ),
m_addFriendAction( 0 )
{
if( !accountName().isEmpty() )
m_menu = new QMenu(QString("Jabber (").append(accountName()).append(")"));
m_addFriendAction = m_menu->addAction("Add Friend...");
connect(m_addFriendAction, SIGNAL(triggered()),
this, SLOT(showAddFriendDialog()));
}
void
@ -86,8 +80,8 @@ JabberPlugin::connectPlugin( bool startup )
QObject::connect( p, SIGNAL( peerOffline( QString ) ), SIGNAL( peerOffline( QString ) ) );
QObject::connect( p, SIGNAL( msgReceived( QString, QString ) ), SIGNAL( msgReceived( QString, QString ) ) );
QObject::connect( p, SIGNAL( connected() ), SIGNAL( connected() ) );
QObject::connect( p, SIGNAL( disconnected() ), SIGNAL( disconnected() ) );
QObject::connect( p, SIGNAL( connected() ), SLOT( onConnected() ) );
QObject::connect( p, SIGNAL( disconnected() ), SIGNAL( onDisconnected() ) );
QObject::connect( p, SIGNAL( authError( int, QString ) ), SLOT( onAuthError( int, QString ) ) );
p->resolveHostSRV();
@ -95,6 +89,38 @@ JabberPlugin::connectPlugin( bool startup )
return true;
}
void
JabberPlugin::onConnected()
{
if( !m_menu ) {
m_menu = new QMenu( QString( "Jabber (").append( accountName() ).append( ")" ) );
m_addFriendAction = m_menu->addAction( "Add Friend..." );
connect( m_addFriendAction, SIGNAL( triggered() ),
this, SLOT( showAddFriendDialog() ) ) ;
emit addMenu( m_menu );
}
emit connected();
}
void
JabberPlugin::onDisconnected()
{
if( m_menu && m_addFriendAction ) {
emit removeMenu( m_menu );
delete m_menu;
m_menu = 0;
m_addFriendAction = 0;
}
emit disconnected();
}
void
JabberPlugin::onAuthError( int code, const QString& message )

View File

@ -32,6 +32,8 @@ public slots:
void disconnectPlugin()
{
onDisconnected();
if ( p )
p->disconnect();
@ -60,7 +62,9 @@ public slots:
private slots:
void onAuthError( int, const QString& );
void showAddFriendDialog();
void onConnected();
void onDisconnected();
private:
Jabber_p* p;
QMenu* m_menu;

View File

@ -10,14 +10,9 @@
JabberPlugin::JabberPlugin()
: p( 0 )
, m_menu( 0 )
, m_addFriendAction( 0 )
{
m_menu = new QMenu(QString("JREEN (").append(accountName()).append(")"));
m_addFriendAction = m_menu->addAction("Add Friend...");
QAction *connectAction = m_menu->addAction("Connect");
connect(m_addFriendAction, SIGNAL(triggered()),
this, SLOT(showAddFriendDialog()));
connect(connectAction, SIGNAL(triggered()), SLOT(connectPlugin()));
}
JabberPlugin::~JabberPlugin()
@ -92,8 +87,8 @@ JabberPlugin::connectPlugin( bool startup )
QObject::connect( p, SIGNAL( peerOffline( QString ) ), SIGNAL( peerOffline( QString ) ) );
QObject::connect( p, SIGNAL( msgReceived( QString, QString ) ), SIGNAL( msgReceived( QString, QString ) ) );
QObject::connect( p, SIGNAL( connected() ), SIGNAL( connected() ) );
QObject::connect( p, SIGNAL( disconnected() ), SIGNAL( disconnected() ) );
QObject::connect( p, SIGNAL( connected() ), SIGNAL( onConnected() ) );
QObject::connect( p, SIGNAL( disconnected() ), SIGNAL( onDisconnected() ) );
return true;
}
@ -101,6 +96,8 @@ JabberPlugin::connectPlugin( bool startup )
void
JabberPlugin::disconnectPlugin()
{
onDisconnected();
if ( p )
p->disconnect();
@ -108,6 +105,38 @@ JabberPlugin::disconnectPlugin()
p = 0;
}
void
JabberPlugin::onConnected()
{
if( !m_menu ) {
m_menu = new QMenu( QString( "JREEN (" ).append( accountName() ).append(")" ) );
m_addFriendAction = m_menu->addAction( "Add Friend..." );
QAction *connectAction = m_menu->addAction( "Connect" );
connect( m_addFriendAction, SIGNAL(triggered() ),
this, SLOT( showAddFriendDialog() ) );
connect( connectAction, SIGNAL( triggered() ), SLOT( connectPlugin() ) );
emit addMenu( m_menu );
}
emit connected();
}
void
JabberPlugin::onDisconnected()
{
if( m_menu && m_addFriendAction ) {
emit removeMenu( m_menu );
delete m_menu;
m_menu = 0;
m_addFriendAction = 0; // deleted by menu
}
emit disconnected();
}
void
JabberPlugin::sendMsg(const QString& to, const QString& msg)
{

View File

@ -35,6 +35,8 @@ public slots:
private slots:
void showAddFriendDialog();
void onConnected();
void onDisconnected();
private:
Jabber_p* p;

View File

@ -157,10 +157,8 @@ TomahawkWindow::TomahawkWindow( QWidget* parent )
// propagate sip menu
foreach( SipPlugin *plugin, APP->sipHandler()->plugins() )
{
if ( plugin->menu() )
{
ui->menuNetwork->addMenu( plugin->menu() );
}
connect( plugin, SIGNAL( addMenu( QMenu* ) ), this, SLOT( pluginMenuAdded( QMenu* ) ) );
connect( plugin, SIGNAL( removeMenu( QMenu* ) ), this, SLOT( pluginMenuRemoved( QMenu* ) ) );
}
loadSettings();
@ -337,6 +335,25 @@ TomahawkWindow::addPeerManually()
Servent::instance()->connectToPeer( addr, port, key );
}
void
TomahawkWindow::pluginMenuAdded( QMenu* menu )
{
ui->menuNetwork->addMenu( menu );
}
void
TomahawkWindow::pluginMenuRemoved( QMenu* menu )
{
foreach( QAction* action, ui->menuNetwork->actions() )
{
if( action->menu() == menu )
{
ui->menuNetwork->removeAction( action );
return;
}
}
}
void
TomahawkWindow::loadSpiff()

View File

@ -45,6 +45,8 @@ public slots:
void loadSpiff();
void showSettingsDialog();
void updateCollectionManually();
void pluginMenuAdded(QMenu*);
void pluginMenuRemoved(QMenu*);
private slots:
void onSipConnected();