From 86c87deb0e0184e5bc83edf574a110152e88e923 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Thu, 25 Nov 2010 07:48:04 +0100 Subject: [PATCH] * 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. --- include/tomahawk/tomahawkapp.h | 1 + src/jabber/jabber.h | 61 +++++++++++++++++++++------------- src/jabber/jabber_p.cpp | 29 +++++++++++++++- src/jabber/jabber_p.h | 4 ++- src/tomahawkapp.cpp | 7 ++++ src/tomahawkwindow.cpp | 59 +++++++++++++++++++++++--------- src/tomahawkwindow.h | 2 ++ src/tomahawkwindow.ui | 25 +++++++++----- 8 files changed, 138 insertions(+), 50 deletions(-) diff --git a/include/tomahawk/tomahawkapp.h b/include/tomahawk/tomahawkapp.h index e29e3484f..1477e4b11 100644 --- a/include/tomahawk/tomahawkapp.h +++ b/include/tomahawk/tomahawkapp.h @@ -96,6 +96,7 @@ signals: public slots: QSharedPointer getIODeviceForUrl( const Tomahawk::result_ptr& result ); void reconnectJabber(); + void jabberAddContact( const QString& jid ); private slots: void jabberMessage( const QString&, const QString& ); diff --git a/src/jabber/jabber.h b/src/jabber/jabber.h index 1fa66e172..0baa9ff8f 100644 --- a/src/jabber/jabber.h +++ b/src/jabber/jabber.h @@ -1,14 +1,17 @@ #ifndef JABBER_H #define JABBER_H + /* Pimpl of jabber_p, which inherits from a gazillion gloox classes and it littered with public methods. */ + #include "jabber_p.h" class Jabber : public QObject { - Q_OBJECT +Q_OBJECT + public: Jabber( const QString &jid, const QString password, const QString server = "", const int port=-1 ) @@ -30,29 +33,29 @@ public slots: void start() { - //connect( &p, SIGNAL(finished()), - // this, SIGNAL(finished()) ); + //connect( &p, SIGNAL( finished() ), + // this, SIGNAL( finished() ) ); - connect( &p, SIGNAL(msgReceived(QString,QString)), - this, SIGNAL(msgReceived(QString,QString)) ); + connect( &p, SIGNAL( msgReceived( QString, QString ) ), + this, SIGNAL( msgReceived( QString, QString ) ) ); - connect( &p, SIGNAL(peerOnline(QString)), - this, SIGNAL(peerOnline(QString)) ); + connect( &p, SIGNAL( peerOnline( QString ) ), + this, SIGNAL( peerOnline( QString ) ) ); - connect( &p, SIGNAL(peerOffline(QString)), - this, SIGNAL(peerOffline(QString)) ); + connect( &p, SIGNAL( peerOffline( QString ) ), + this, SIGNAL( peerOffline( QString ) ) ); - connect( &p, SIGNAL(connected()), - this, SIGNAL(connected()) ); + connect( &p, SIGNAL( connected() ), + this, SIGNAL( connected() ) ); - connect( &p, SIGNAL(disconnected()), - this, SIGNAL(disconnected()) ); + connect( &p, SIGNAL( disconnected() ), + this, SIGNAL( disconnected() ) ); - connect( &p, SIGNAL(jidChanged(QString)), - this, SIGNAL(jidChanged(QString)) ); + connect( &p, SIGNAL( jidChanged( QString ) ), + this, SIGNAL( jidChanged( QString ) ) ); - connect( &p, SIGNAL(authError(int,const QString&)), - this, SIGNAL(authError(int,const QString&)) ); + connect( &p, SIGNAL( authError( int, const QString& ) ), + this, SIGNAL( authError( int, const QString& ) ) ); 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, "sendMsg", @@ -75,7 +78,7 @@ public slots: ); } - void broadcastMsg(const QString &msg) + void broadcastMsg( const QString &msg ) { QMetaObject::invokeMethod( &p, "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: //void finished(); - void msgReceived(const QString&, const QString&); //from, msg - void peerOnline(const QString&); - void peerOffline(const QString&); + void msgReceived( const QString&, const QString& ); + void peerOnline( const QString& ); + void peerOffline( const QString& ); void connected(); void disconnected(); - void jidChanged(const QString&); - void authError(int, const QString&); + void jidChanged( const QString& ); + void authError( int, const QString& ); private: Jabber_p p; diff --git a/src/jabber/jabber_p.cpp b/src/jabber/jabber_p.cpp index a13bcedc2..dea6f6604 100644 --- a/src/jabber/jabber_p.cpp +++ b/src/jabber/jabber_p.cpp @@ -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 void @@ -521,11 +538,21 @@ void Jabber_p::handleSelfPresence( const RosterItem& item, const std::string& resource, Presence::PresenceType presence, const std::string& msg ) { -// qDebug() << Q_FUNC_INFO; 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 Jabber_p::handleSubscriptionRequest( const JID& jid, const std::string& /*msg*/ ) { diff --git a/src/jabber/jabber_p.h b/src/jabber/jabber_p.h index acccd7bce..66ab35f77 100644 --- a/src/jabber/jabber_p.h +++ b/src/jabber/jabber_p.h @@ -92,6 +92,7 @@ public: gloox::Presence::PresenceType presence, const std::string& /*msg*/ ); virtual void handleSelfPresence( const gloox::RosterItem& item, const std::string& resource, 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 handleUnsubscriptionRequest( const gloox::JID& jid, const std::string& /*msg*/ ); virtual void handleNonrosterPresence( const gloox::Presence& presence ); @@ -121,7 +122,8 @@ signals: public slots: void go(); 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: void doJabberRecv(); diff --git a/src/tomahawkapp.cpp b/src/tomahawkapp.cpp index 6f49a24eb..250ed8fc8 100644 --- a/src/tomahawkapp.cpp +++ b/src/tomahawkapp.cpp @@ -480,6 +480,13 @@ TomahawkApp::reconnectJabber() } +void +TomahawkApp::jabberAddContact( const QString& jid ) +{ + m_jabber->addContact( jid ); +} + + void TomahawkApp::jabberAuthError( int code, const QString& msg ) { diff --git a/src/tomahawkwindow.cpp b/src/tomahawkwindow.cpp index dd064398b..e620d047f 100644 --- a/src/tomahawkwindow.cpp +++ b/src/tomahawkwindow.cpp @@ -2,6 +2,7 @@ #include "ui_tomahawkwindow.h" #include +#include #include #include #include @@ -55,7 +56,6 @@ TomahawkWindow::TomahawkWindow( QWidget* parent ) #ifndef Q_WS_MAC ui->centralWidget->layout()->setContentsMargins( 4, 4, 4, 2 ); #else -// ui->actionProgress->setAttribute( Qt::WA_MacShowFocusRect, 0 ); // ui->playlistView->setAttribute( Qt::WA_MacShowFocusRect, 0 ); ui->sourceTreeView->setAttribute( Qt::WA_MacShowFocusRect, 0 ); #endif @@ -71,7 +71,7 @@ TomahawkWindow::TomahawkWindow( QWidget* parent ) toolbar->setMovable( false ); toolbar->setFloatable( false ); toolbar->installEventFilter( new WidgetDragFilter( toolbar ) ); - + statusBar()->addPermanentWidget( m_audioControls, 1 ); loadSettings(); @@ -110,12 +110,6 @@ TomahawkWindow::saveSettings() void TomahawkWindow::setupSignals() { - connect( ui->actionExit, SIGNAL( triggered() ), - qApp, SLOT( closeAllWindows() ) ); - - connect( ui->actionLoadXSPF, SIGNAL( triggered() ), SLOT( loadSpiff() )); - connect( ui->actionCreatePlaylist, SIGNAL( triggered() ), SLOT( createPlaylist() )); - // connect( m_topbar, SIGNAL( filterTextChanged( const QString& ) ), playlistManager(), SLOT( setFilter( const QString& ) ) ); @@ -133,10 +127,10 @@ TomahawkWindow::setupSignals() m_topbar, SLOT( setNumShown( unsigned int ) ) ); connect( m_topbar, SIGNAL( flatMode() ), - m_playlistManager, SLOT( setTableMode() ) ); + playlistManager(), SLOT( setTableMode() ) ); connect( m_topbar, SIGNAL( artistMode() ), - m_playlistManager, SLOT( setTreeMode() ) ); + playlistManager(), SLOT( setTreeMode() ) ); // connect( playlistManager(), SIGNAL( repeatModeChanged( PlaylistInterface::RepeatMode ) ), @@ -152,8 +146,12 @@ TomahawkWindow::setupSignals() // connect( ui->actionPreferences, SIGNAL( triggered() ), SLOT( showSettingsDialog() ) ); connect( ui->actionAddPeerManually, SIGNAL( triggered() ), SLOT( addPeerManually() ) ); + connect( ui->actionAddFriendManually, SIGNAL( triggered() ), SLOT( addFriendManually() ) ); 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* TomahawkWindow::playlistManager() { @@ -225,16 +238,15 @@ void TomahawkWindow::addPeerManually() { TomahawkSettings* s = APP->settings(); - // stealing this for connecting to peers for now: 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, s->value( "connip" ).toString(), &ok ); // FIXME if ( !ok ) return; 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, s->value( "connport", "50210" ).toString(), &ok ); if ( !ok ) @@ -242,17 +254,32 @@ TomahawkWindow::addPeerManually() s->setValue( "connport", ports ); 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, "whitelist", &ok ); if ( !ok ) return; - qDebug() << "Attempting to connect to " << addr; + qDebug() << "Attempting to connect to" << addr; 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 TomahawkWindow::loadSpiff() { diff --git a/src/tomahawkwindow.h b/src/tomahawkwindow.h index 347fb7e6a..2649dc1b3 100644 --- a/src/tomahawkwindow.h +++ b/src/tomahawkwindow.h @@ -40,6 +40,7 @@ signals: protected: void changeEvent( QEvent* e ); + void closeEvent( QCloseEvent* e ); public slots: void createPlaylist(); @@ -50,6 +51,7 @@ private slots: void scanFinished(); void rescanCollectionManually(); void addPeerManually(); + void addFriendManually(); void onPlaybackLoading( const Tomahawk::result_ptr& result ); diff --git a/src/tomahawkwindow.ui b/src/tomahawkwindow.ui index 221992fb7..386a5db0d 100644 --- a/src/tomahawkwindow.ui +++ b/src/tomahawkwindow.ui @@ -50,7 +50,7 @@ - Music &Player + &Music Player @@ -66,15 +66,16 @@ - Network + &Network + &Help - + @@ -96,12 +97,17 @@ - &Add Peer Manually + Add &Peer Manually... + + + + + Add &Friend... - Re&scan Collection + Re&scan Collection... @@ -114,7 +120,7 @@ - Load &XSPF + Load &XSPF... @@ -122,9 +128,12 @@ Create &New Playlist... - + - About &Tomahawk + About &Tomahawk... + + + QAction::AboutRole