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

Change plugin structure to fix adding friends.

This commit is contained in:
Dominik Schmidt
2011-02-16 18:38:14 +01:00
parent af0d628a75
commit 4153dc00ec
13 changed files with 86 additions and 23 deletions

View File

@@ -1,2 +1,7 @@
#include <sip/SipPlugin.h>
QMenu*
SipPlugin::menu()
{
return 0;
}

View File

@@ -3,6 +3,7 @@
#include <QObject>
#include <QString>
#include <QMenu>
#include "dllmacro.h"
@@ -17,6 +18,8 @@ public:
virtual bool isValid() = 0;
virtual const QString name() = 0;
virtual const QString accountName() = 0;
virtual QMenu *menu();
public slots:
virtual bool connectPlugin( bool startup = false ) = 0;

View File

@@ -27,6 +27,12 @@ SipHandler::~SipHandler()
disconnectPlugins();
}
QList< SipPlugin* >
SipHandler::plugins() const
{
return m_plugins;
}
void
SipHandler::onSettingsChanged()

View File

@@ -1,11 +1,11 @@
#ifndef SIPHANDLER_H
#define SIPHANDLER_H
#include "sip/SipPlugin.h"
#include <QDebug>
#include <QObject>
class SipPlugin;
class SipHandler : public QObject
{
Q_OBJECT
@@ -16,6 +16,8 @@ public:
SipHandler( QObject* parent );
~SipHandler();
QList< SipPlugin* > plugins() const;
public slots:
void addContact( const QString& id ) { qDebug() << Q_FUNC_INFO << id; }

View File

@@ -2,9 +2,22 @@
#include "tomahawksettings.h"
#include "tomahawk/tomahawkapp.h"
#include <QtPlugin>
#include <QStringList>
#include <QInputDialog>
#include <QLineEdit>
JabberPlugin::JabberPlugin()
: p( 0 )
{
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
JabberPlugin::setProxy( QNetworkProxy* proxy )
@@ -19,6 +32,17 @@ JabberPlugin::name()
return QString( MYNAME );
}
const QString
JabberPlugin::accountName()
{
return TomahawkSettings::instance()->jabberUsername();
}
QMenu*
JabberPlugin::menu()
{
return m_menu;
}
bool
JabberPlugin::connectPlugin( bool startup )
@@ -74,4 +98,18 @@ JabberPlugin::onAuthError( int code, const QString& message )
emit error( SipPlugin::ConnectionError, message );
}
void
JabberPlugin::showAddFriendDialog()
{
bool ok;
QString id = QInputDialog::getText( TomahawkApp::instance()->mainWindow(), tr( "Add Friend" ),
tr( "Enter Jabber ID:" ), QLineEdit::Normal,
"", &ok );
if ( !ok )
return;
qDebug() << "Attempting to add jabber contact to roster:" << id;
addContact( id );
}
Q_EXPORT_PLUGIN2( sip, JabberPlugin )

View File

@@ -14,9 +14,7 @@ class SIPDLLEXPORT JabberPlugin : public SipPlugin
Q_INTERFACES( SipPlugin )
public:
JabberPlugin()
: p( 0 )
{}
JabberPlugin();
virtual ~JabberPlugin() { delete p; }
@@ -24,6 +22,9 @@ public:
virtual bool isValid() { return true; }
virtual const QString name();
virtual const QString accountName();
virtual QMenu* menu();
void setProxy( QNetworkProxy* proxy );
public slots:
@@ -58,9 +59,12 @@ public slots:
private slots:
void onAuthError( int, const QString& );
void showAddFriendDialog();
private:
Jabber_p* p;
QMenu* m_menu;
QAction* m_addFriendAction;
};
#endif

View File

@@ -53,6 +53,12 @@ TwitterPlugin::name()
return QString( MYNAME );
}
const QString
TwitterPlugin::accountName()
{
return QString( TomahawkSettings::instance()->twitterScreenName() );
}
bool
TwitterPlugin::connectPlugin( bool /*startup*/ )
{

View File

@@ -32,6 +32,7 @@ public:
virtual bool isValid();
virtual const QString name();
virtual const QString accountName();
public slots:
virtual bool connectPlugin( bool startup );

View File

@@ -8,6 +8,12 @@ ZeroconfPlugin::name()
return QString( MYNAME );
}
const QString
ZeroconfPlugin::accountName()
{
return QString();
}
bool
ZeroconfPlugin::connectPlugin( bool /*startup*/ )
{

View File

@@ -24,6 +24,7 @@ public:
virtual bool isValid() { return true; }
virtual const QString name();
virtual const QString accountName();
public slots:
virtual bool connectPlugin( bool startup );

View File

@@ -121,6 +121,15 @@ TomahawkWindow::TomahawkWindow( QWidget* parent )
statusBar()->addPermanentWidget( m_audioControls, 1 );
// propagate sip menu
foreach(SipPlugin *plugin, APP->sipHandler()->plugins())
{
if(plugin->menu())
{
ui->menuNetwork->addMenu(plugin->menu());
}
}
loadSettings();
setupSignals();
@@ -177,7 +186,6 @@ TomahawkWindow::setupSignals()
connect( ui->actionPreferences, SIGNAL( triggered() ), SLOT( showSettingsDialog() ) );
connect( ui->actionToggleConnect, SIGNAL( triggered() ), APP->sipHandler(), SLOT( toggleConnect() ) );
connect( ui->actionAddPeerManually, SIGNAL( triggered() ), SLOT( addPeerManually() ) );
connect( ui->actionAddFriendManually, SIGNAL( triggered() ), SLOT( addFriendManually() ) );
connect( ui->actionRescanCollection, SIGNAL( triggered() ), SLOT( updateCollectionManually() ) );
connect( ui->actionLoadXSPF, SIGNAL( triggered() ), SLOT( loadSpiff() ));
connect( ui->actionCreatePlaylist, SIGNAL( triggered() ), SLOT( createPlaylist() ));
@@ -277,21 +285,6 @@ TomahawkWindow::addPeerManually()
}
void
TomahawkWindow::addFriendManually()
{
bool ok;
QString id = QInputDialog::getText( this, tr( "Add Friend" ),
tr( "Enter Jabber ID:" ), QLineEdit::Normal,
"", &ok );
if ( !ok )
return;
qDebug() << "Attempting to add jabber contact to roster:" << id;
APP->sipHandler()->addContact( id );
}
void
TomahawkWindow::loadSpiff()
{

View File

@@ -52,7 +52,6 @@ private slots:
void onSipError();
void addPeerManually();
void addFriendManually();
void onPlaybackLoading( const Tomahawk::result_ptr& result );

View File

@@ -69,7 +69,6 @@
<addaction name="actionToggleConnect"/>
<addaction name="separator"/>
<addaction name="actionAddPeerManually"/>
<addaction name="actionAddFriendManually"/>
</widget>
<widget class="QMenu" name="menu_Help">
<property name="title">