1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-18 11:51:44 +02:00

* You can now add jabber friends within Tomahawk (Menu Network -> Add Friend).

* If the mainwindow (not the app itself) gets closed, it will now hide in the SysTray.
* Cleaned up menus.
This commit is contained in:
Christian Muehlhaeuser
2010-11-25 07:48:04 +01:00
parent b175bc5324
commit 86c87deb0e
8 changed files with 138 additions and 50 deletions

View File

@@ -96,6 +96,7 @@ signals:
public slots: public slots:
QSharedPointer<QIODevice> getIODeviceForUrl( const Tomahawk::result_ptr& result ); QSharedPointer<QIODevice> getIODeviceForUrl( const Tomahawk::result_ptr& result );
void reconnectJabber(); void reconnectJabber();
void jabberAddContact( const QString& jid );
private slots: private slots:
void jabberMessage( const QString&, const QString& ); void jabberMessage( const QString&, const QString& );

View File

@@ -1,14 +1,17 @@
#ifndef JABBER_H #ifndef JABBER_H
#define JABBER_H #define JABBER_H
/* /*
Pimpl of jabber_p, which inherits from a gazillion gloox classes Pimpl of jabber_p, which inherits from a gazillion gloox classes
and it littered with public methods. and it littered with public methods.
*/ */
#include "jabber_p.h" #include "jabber_p.h"
class Jabber : public QObject class Jabber : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
Jabber( const QString &jid, const QString password, const QString server = "", const int port=-1 ) Jabber( const QString &jid, const QString password, const QString server = "", const int port=-1 )
@@ -30,29 +33,29 @@ public slots:
void start() void start()
{ {
//connect( &p, SIGNAL(finished()), //connect( &p, SIGNAL( finished() ),
// this, SIGNAL(finished()) ); // this, SIGNAL( finished() ) );
connect( &p, SIGNAL(msgReceived(QString,QString)), connect( &p, SIGNAL( msgReceived( QString, QString ) ),
this, SIGNAL(msgReceived(QString,QString)) ); this, SIGNAL( msgReceived( QString, QString ) ) );
connect( &p, SIGNAL(peerOnline(QString)), connect( &p, SIGNAL( peerOnline( QString ) ),
this, SIGNAL(peerOnline(QString)) ); this, SIGNAL( peerOnline( QString ) ) );
connect( &p, SIGNAL(peerOffline(QString)), connect( &p, SIGNAL( peerOffline( QString ) ),
this, SIGNAL(peerOffline(QString)) ); this, SIGNAL( peerOffline( QString ) ) );
connect( &p, SIGNAL(connected()), connect( &p, SIGNAL( connected() ),
this, SIGNAL(connected()) ); this, SIGNAL( connected() ) );
connect( &p, SIGNAL(disconnected()), connect( &p, SIGNAL( disconnected() ),
this, SIGNAL(disconnected()) ); this, SIGNAL( disconnected() ) );
connect( &p, SIGNAL(jidChanged(QString)), connect( &p, SIGNAL( jidChanged( QString ) ),
this, SIGNAL(jidChanged(QString)) ); this, SIGNAL( jidChanged( QString ) ) );
connect( &p, SIGNAL(authError(int,const QString&)), connect( &p, SIGNAL( authError( int, const QString& ) ),
this, SIGNAL(authError(int,const QString&)) ); this, SIGNAL( authError( int, const QString& ) ) );
p.go(); p.go();
} }
@@ -65,7 +68,7 @@ public slots:
); );
} }
void sendMsg(const QString& to, const QString& msg) void sendMsg( const QString& to, const QString& msg )
{ {
QMetaObject::invokeMethod( &p, QMetaObject::invokeMethod( &p,
"sendMsg", "sendMsg",
@@ -75,7 +78,7 @@ public slots:
); );
} }
void broadcastMsg(const QString &msg) void broadcastMsg( const QString &msg )
{ {
QMetaObject::invokeMethod( &p, QMetaObject::invokeMethod( &p,
"broadcastMsg", "broadcastMsg",
@@ -84,16 +87,26 @@ public slots:
); );
} }
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)
);
}
signals: signals:
//void finished(); //void finished();
void msgReceived(const QString&, const QString&); //from, msg void msgReceived( const QString&, const QString& );
void peerOnline(const QString&); void peerOnline( const QString& );
void peerOffline(const QString&); void peerOffline( const QString& );
void connected(); void connected();
void disconnected(); void disconnected();
void jidChanged(const QString&); void jidChanged( const QString& );
void authError(int, const QString&); void authError( int, const QString& );
private: private:
Jabber_p p; Jabber_p p;

View File

@@ -207,6 +207,23 @@ Jabber_p::broadcastMsg( const QString &msg )
} }
void
Jabber_p::addContact( const QString& jid, const QString& msg )
{
if ( QThread::currentThread() != thread() )
{
QMetaObject::invokeMethod( this, "addContact",
Qt::QueuedConnection,
Q_ARG(const QString, jid),
Q_ARG(const QString, msg)
);
return;
}
handleSubscription(JID(jid.toStdString()), msg.toStdString());
return;
}
/// GLOOX IMPL STUFF FOLLOWS /// GLOOX IMPL STUFF FOLLOWS
void void
@@ -521,11 +538,21 @@ void
Jabber_p::handleSelfPresence( const RosterItem& item, const std::string& resource, Jabber_p::handleSelfPresence( const RosterItem& item, const std::string& resource,
Presence::PresenceType presence, const std::string& msg ) Presence::PresenceType presence, const std::string& msg )
{ {
// qDebug() << Q_FUNC_INFO;
handleRosterPresence( item, resource, presence, msg ); handleRosterPresence( item, resource, presence, msg );
} }
bool
Jabber_p::handleSubscription( const JID& jid, const std::string& /*msg*/ )
{
qDebug() << Q_FUNC_INFO << jid.bare().c_str();
StringList groups;
m_client->rosterManager()->subscribe( jid, "", groups, "" );
return true;
}
bool bool
Jabber_p::handleSubscriptionRequest( const JID& jid, const std::string& /*msg*/ ) Jabber_p::handleSubscriptionRequest( const JID& jid, const std::string& /*msg*/ )
{ {

View File

@@ -92,6 +92,7 @@ public:
gloox::Presence::PresenceType presence, const std::string& /*msg*/ ); gloox::Presence::PresenceType presence, const std::string& /*msg*/ );
virtual void handleSelfPresence( const gloox::RosterItem& item, const std::string& resource, virtual void handleSelfPresence( const gloox::RosterItem& item, const std::string& resource,
gloox::Presence::PresenceType presence, const std::string& msg ); gloox::Presence::PresenceType presence, const std::string& msg );
virtual bool handleSubscription( const gloox::JID& jid, const std::string& /*msg*/ );
virtual bool handleSubscriptionRequest( const gloox::JID& jid, const std::string& /*msg*/ ); virtual bool handleSubscriptionRequest( const gloox::JID& jid, const std::string& /*msg*/ );
virtual bool handleUnsubscriptionRequest( const gloox::JID& jid, const std::string& /*msg*/ ); virtual bool handleUnsubscriptionRequest( const gloox::JID& jid, const std::string& /*msg*/ );
virtual void handleNonrosterPresence( const gloox::Presence& presence ); virtual void handleNonrosterPresence( const gloox::Presence& presence );
@@ -121,7 +122,8 @@ signals:
public slots: public slots:
void go(); void go();
void sendMsg( const QString& to, const QString& msg ); void sendMsg( const QString& to, const QString& msg );
void broadcastMsg( const QString &msg ); void broadcastMsg( const QString& msg );
void addContact( const QString& jid, const QString& msg = QString() );
private slots: private slots:
void doJabberRecv(); void doJabberRecv();

View File

@@ -480,6 +480,13 @@ TomahawkApp::reconnectJabber()
} }
void
TomahawkApp::jabberAddContact( const QString& jid )
{
m_jabber->addContact( jid );
}
void void
TomahawkApp::jabberAuthError( int code, const QString& msg ) TomahawkApp::jabberAuthError( int code, const QString& msg )
{ {

View File

@@ -2,6 +2,7 @@
#include "ui_tomahawkwindow.h" #include "ui_tomahawkwindow.h"
#include <QAction> #include <QAction>
#include <QCloseEvent>
#include <QInputDialog> #include <QInputDialog>
#include <QPixmap> #include <QPixmap>
#include <QPropertyAnimation> #include <QPropertyAnimation>
@@ -55,7 +56,6 @@ TomahawkWindow::TomahawkWindow( QWidget* parent )
#ifndef Q_WS_MAC #ifndef Q_WS_MAC
ui->centralWidget->layout()->setContentsMargins( 4, 4, 4, 2 ); ui->centralWidget->layout()->setContentsMargins( 4, 4, 4, 2 );
#else #else
// ui->actionProgress->setAttribute( Qt::WA_MacShowFocusRect, 0 );
// ui->playlistView->setAttribute( Qt::WA_MacShowFocusRect, 0 ); // ui->playlistView->setAttribute( Qt::WA_MacShowFocusRect, 0 );
ui->sourceTreeView->setAttribute( Qt::WA_MacShowFocusRect, 0 ); ui->sourceTreeView->setAttribute( Qt::WA_MacShowFocusRect, 0 );
#endif #endif
@@ -110,12 +110,6 @@ TomahawkWindow::saveSettings()
void void
TomahawkWindow::setupSignals() TomahawkWindow::setupSignals()
{ {
connect( ui->actionExit, SIGNAL( triggered() ),
qApp, SLOT( closeAllWindows() ) );
connect( ui->actionLoadXSPF, SIGNAL( triggered() ), SLOT( loadSpiff() ));
connect( ui->actionCreatePlaylist, SIGNAL( triggered() ), SLOT( createPlaylist() ));
// <Playlist> // <Playlist>
connect( m_topbar, SIGNAL( filterTextChanged( const QString& ) ), connect( m_topbar, SIGNAL( filterTextChanged( const QString& ) ),
playlistManager(), SLOT( setFilter( const QString& ) ) ); playlistManager(), SLOT( setFilter( const QString& ) ) );
@@ -133,10 +127,10 @@ TomahawkWindow::setupSignals()
m_topbar, SLOT( setNumShown( unsigned int ) ) ); m_topbar, SLOT( setNumShown( unsigned int ) ) );
connect( m_topbar, SIGNAL( flatMode() ), connect( m_topbar, SIGNAL( flatMode() ),
m_playlistManager, SLOT( setTableMode() ) ); playlistManager(), SLOT( setTableMode() ) );
connect( m_topbar, SIGNAL( artistMode() ), connect( m_topbar, SIGNAL( artistMode() ),
m_playlistManager, SLOT( setTreeMode() ) ); playlistManager(), SLOT( setTreeMode() ) );
// <From PlaylistManager> // <From PlaylistManager>
connect( playlistManager(), SIGNAL( repeatModeChanged( PlaylistInterface::RepeatMode ) ), connect( playlistManager(), SIGNAL( repeatModeChanged( PlaylistInterface::RepeatMode ) ),
@@ -152,8 +146,12 @@ TomahawkWindow::setupSignals()
// <Menu Items> // <Menu Items>
connect( ui->actionPreferences, SIGNAL( triggered() ), SLOT( showSettingsDialog() ) ); connect( ui->actionPreferences, SIGNAL( triggered() ), SLOT( showSettingsDialog() ) );
connect( ui->actionAddPeerManually, SIGNAL( triggered() ), SLOT( addPeerManually() ) ); connect( ui->actionAddPeerManually, SIGNAL( triggered() ), SLOT( addPeerManually() ) );
connect( ui->actionAddFriendManually, SIGNAL( triggered() ), SLOT( addFriendManually() ) );
connect( ui->actionRescanCollection, SIGNAL( triggered() ), SLOT( rescanCollectionManually() ) ); connect( ui->actionRescanCollection, SIGNAL( triggered() ), SLOT( rescanCollectionManually() ) );
connect( ui->actionAbout_Tomahawk, SIGNAL( triggered() ), SLOT( showAboutTomahawk() ) ); connect( ui->actionLoadXSPF, SIGNAL( triggered() ), SLOT( loadSpiff() ));
connect( ui->actionCreatePlaylist, SIGNAL( triggered() ), SLOT( createPlaylist() ));
connect( ui->actionAboutTomahawk, SIGNAL( triggered() ), SLOT( showAboutTomahawk() ) );
connect( ui->actionExit, SIGNAL( triggered() ), APP, SLOT( quit() ) );
} }
@@ -174,6 +172,21 @@ TomahawkWindow::changeEvent( QEvent* e )
} }
void
TomahawkWindow::closeEvent( QCloseEvent* e )
{
if ( QSystemTrayIcon::isSystemTrayAvailable() )
{
e->ignore();
hide();
}
else
{
e->accept();
}
}
PlaylistManager* PlaylistManager*
TomahawkWindow::playlistManager() TomahawkWindow::playlistManager()
{ {
@@ -225,16 +238,15 @@ void
TomahawkWindow::addPeerManually() TomahawkWindow::addPeerManually()
{ {
TomahawkSettings* s = APP->settings(); TomahawkSettings* s = APP->settings();
// stealing this for connecting to peers for now:
bool ok; bool ok;
QString addr = QInputDialog::getText( this, tr( "Connect to peer" ), QString addr = QInputDialog::getText( this, tr( "Connect To Peer" ),
tr( "Enter peer address:" ), QLineEdit::Normal, tr( "Enter peer address:" ), QLineEdit::Normal,
s->value( "connip" ).toString(), &ok ); // FIXME s->value( "connip" ).toString(), &ok ); // FIXME
if ( !ok ) if ( !ok )
return; return;
s->setValue( "connip", addr ); s->setValue( "connip", addr );
QString ports = QInputDialog::getText( this, tr( "Connect to peer" ), QString ports = QInputDialog::getText( this, tr( "Connect To Peer" ),
tr( "Enter peer port:" ), QLineEdit::Normal, tr( "Enter peer port:" ), QLineEdit::Normal,
s->value( "connport", "50210" ).toString(), &ok ); s->value( "connport", "50210" ).toString(), &ok );
if ( !ok ) if ( !ok )
@@ -242,17 +254,32 @@ TomahawkWindow::addPeerManually()
s->setValue( "connport", ports ); s->setValue( "connport", ports );
int port = ports.toInt(); int port = ports.toInt();
QString key = QInputDialog::getText( this, tr( "Connect to peer" ), QString key = QInputDialog::getText( this, tr( "Connect To Peer" ),
tr( "Enter peer key:" ), QLineEdit::Normal, tr( "Enter peer key:" ), QLineEdit::Normal,
"whitelist", &ok ); "whitelist", &ok );
if ( !ok ) if ( !ok )
return; return;
qDebug() << "Attempting to connect to " << addr; qDebug() << "Attempting to connect to" << addr;
APP->servent().connectToPeer( addr, port, key ); APP->servent().connectToPeer( addr, port, key );
} }
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->jabberAddContact( id );
}
void void
TomahawkWindow::loadSpiff() TomahawkWindow::loadSpiff()
{ {

View File

@@ -40,6 +40,7 @@ signals:
protected: protected:
void changeEvent( QEvent* e ); void changeEvent( QEvent* e );
void closeEvent( QCloseEvent* e );
public slots: public slots:
void createPlaylist(); void createPlaylist();
@@ -50,6 +51,7 @@ private slots:
void scanFinished(); void scanFinished();
void rescanCollectionManually(); void rescanCollectionManually();
void addPeerManually(); void addPeerManually();
void addFriendManually();
void onPlaybackLoading( const Tomahawk::result_ptr& result ); void onPlaybackLoading( const Tomahawk::result_ptr& result );

View File

@@ -50,7 +50,7 @@
</widget> </widget>
<widget class="QMenu" name="menuApp"> <widget class="QMenu" name="menuApp">
<property name="title"> <property name="title">
<string>Music &amp;Player</string> <string>&amp;Music Player</string>
</property> </property>
<addaction name="actionRescanCollection"/> <addaction name="actionRescanCollection"/>
<addaction name="separator"/> <addaction name="separator"/>
@@ -66,15 +66,16 @@
</widget> </widget>
<widget class="QMenu" name="menuNetwork"> <widget class="QMenu" name="menuNetwork">
<property name="title"> <property name="title">
<string>Network</string> <string>&amp;Network</string>
</property> </property>
<addaction name="actionAddPeerManually"/> <addaction name="actionAddPeerManually"/>
<addaction name="actionAddFriendManually"/>
</widget> </widget>
<widget class="QMenu" name="menu_Help"> <widget class="QMenu" name="menu_Help">
<property name="title"> <property name="title">
<string>&amp;Help</string> <string>&amp;Help</string>
</property> </property>
<addaction name="actionAbout_Tomahawk"/> <addaction name="actionAboutTomahawk"/>
</widget> </widget>
<addaction name="menuApp"/> <addaction name="menuApp"/>
<addaction name="menuPlaylist"/> <addaction name="menuPlaylist"/>
@@ -96,12 +97,17 @@
</action> </action>
<action name="actionAddPeerManually"> <action name="actionAddPeerManually">
<property name="text"> <property name="text">
<string>&amp;Add Peer Manually</string> <string>Add &amp;Peer Manually...</string>
</property>
</action>
<action name="actionAddFriendManually">
<property name="text">
<string>Add &amp;Friend...</string>
</property> </property>
</action> </action>
<action name="actionRescanCollection"> <action name="actionRescanCollection">
<property name="text"> <property name="text">
<string>Re&amp;scan Collection</string> <string>Re&amp;scan Collection...</string>
</property> </property>
</action> </action>
<action name="actionPreferences"> <action name="actionPreferences">
@@ -114,7 +120,7 @@
</action> </action>
<action name="actionLoadXSPF"> <action name="actionLoadXSPF">
<property name="text"> <property name="text">
<string>Load &amp;XSPF</string> <string>Load &amp;XSPF...</string>
</property> </property>
</action> </action>
<action name="actionCreatePlaylist"> <action name="actionCreatePlaylist">
@@ -122,9 +128,12 @@
<string>Create &amp;New Playlist...</string> <string>Create &amp;New Playlist...</string>
</property> </property>
</action> </action>
<action name="actionAbout_Tomahawk"> <action name="actionAboutTomahawk">
<property name="text"> <property name="text">
<string>About &amp;Tomahawk</string> <string>About &amp;Tomahawk...</string>
</property>
<property name="menuRole">
<enum>QAction::AboutRole</enum>
</property> </property>
</action> </action>
</widget> </widget>