From 21f49bbfcb012feee0164720460629077ddaab0b Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 28 Mar 2011 04:01:43 +0200 Subject: [PATCH 1/4] * Updated changelog. --- ChangeLog | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 57ebcf0d8..45f0b1d5c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ Version 0.0.2: + * Don't reconnect to Jabber if the settings dialog is closed successfully + but the Jabber settings haven't changed. * Don't run a rescan of the local collection if the settings dialog is closed successfully but the path hasn't changed. * Don't attempt to connect to unavailable Twitter peers over and over. @@ -10,9 +12,9 @@ Version 0.0.2: the Tomahawk XMPP presence. * Incompatible change: Twitter SIP protocol has changed slightly. 0.0.1 clients will not be able to talk to newer clients. - * Hopefully fix crashes during Twitter authentication. + * Hopefully fixed crashes during Twitter authentication. * Don't let long playlist or summary names force a large Tomahawk window. - * Fixed Jabber auth: Freshly added contacts never showed up. + * Tomahawk now asks you to authorize new contacts. Version 0.0.1: * First public release. From 3f1274b90a158f4cb56887121e01a926b52a9175 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Sun, 27 Mar 2011 22:45:14 -0400 Subject: [PATCH 2/4] Recovering from faulty merge... Revert "* Forgot to add one file." This reverts commit 0bf3a1b8e792c0bf729f0ec352481d0d69021cf1. --- src/libtomahawk/sip/SipPlugin.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libtomahawk/sip/SipPlugin.h b/src/libtomahawk/sip/SipPlugin.h index 47af2fcf3..4c2b17f1e 100644 --- a/src/libtomahawk/sip/SipPlugin.h +++ b/src/libtomahawk/sip/SipPlugin.h @@ -44,7 +44,6 @@ public: public slots: virtual bool connectPlugin( bool startup = false ) = 0; virtual void disconnectPlugin() = 0; - virtual void checkSettings() = 0; virtual void addContact( const QString &jid, const QString& msg = QString() ) = 0; virtual void sendMsg( const QString& to, const QString& msg ) = 0; From 5a0807974017c2e06f8c78f3a9c5b8140130eaf8 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Sun, 27 Mar 2011 22:45:31 -0400 Subject: [PATCH 3/4] Recovering from faulty merge... Revert "* Fixed SIP plugins always reconnecting when the SettingsDialog was closed." This reverts commit 057825bf970dbb9021d2ae46866dcfd49bde532d. --- src/sip/SipHandler.cpp | 28 ++++++++++++++---------- src/sip/SipHandler.h | 1 - src/sip/jabber/jabber.cpp | 43 ++++++------------------------------- src/sip/jabber/jabber.h | 11 ++-------- src/sip/jabber/jabber_p.cpp | 2 +- src/sip/twitter/twitter.cpp | 23 +++++++++++--------- src/sip/twitter/twitter.h | 3 ++- src/sip/zeroconf/zeroconf.h | 2 +- 8 files changed, 43 insertions(+), 70 deletions(-) diff --git a/src/sip/SipHandler.cpp b/src/sip/SipHandler.cpp index 7d77b5fc7..d09fe9d7e 100644 --- a/src/sip/SipHandler.cpp +++ b/src/sip/SipHandler.cpp @@ -28,6 +28,7 @@ #include "network/controlconnection.h" #include "sourcelist.h" #include "tomahawksettings.h" +#include "tomahawk/tomahawkapp.h" #include "config.h" @@ -58,7 +59,8 @@ SipHandler::plugins() const void SipHandler::onSettingsChanged() { - checkSettings(); + disconnectPlugins(); + connectPlugins(); } @@ -164,19 +166,23 @@ SipHandler::pluginLoaded( const QString& name ) const } -void -SipHandler::checkSettings() -{ - foreach( SipPlugin* sip, m_plugins ) - { - sip->checkSettings(); - } -} - - void SipHandler::connectPlugins( bool startup, const QString &pluginName ) { +#ifndef TOMAHAWK_HEADLESS + if ( !TomahawkSettings::instance()->acceptedLegalWarning() ) + { + int result = QMessageBox::question( + TomahawkApp::instance()->mainWindow(), "Legal Warning", + "By pressing OK below, you agree that your use of Tomahawk will be in accordance with any applicable laws, including copyright and intellectual property laws, in effect in your country of residence, and indemify the Tomahawk developers and project from liability should you choose to break those laws.\n\nFor more information, please see http://gettomahawk.com/legal", + "I Do Not Agree", "I Agree" + ); + if ( result != 1 ) + return; + else + TomahawkSettings::instance()->setAcceptedLegalWarning( true ); + } +#endif foreach( SipPlugin* sip, m_plugins ) { if ( pluginName.isEmpty() || ( !pluginName.isEmpty() && sip->name() == pluginName ) ) diff --git a/src/sip/SipHandler.h b/src/sip/SipHandler.h index 0d3dcfa63..f127dcc16 100644 --- a/src/sip/SipHandler.h +++ b/src/sip/SipHandler.h @@ -39,7 +39,6 @@ public: public slots: void addContact( const QString& id ) { qDebug() << Q_FUNC_INFO << id; } - void checkSettings(); void connectPlugins( bool startup = false, const QString &pluginName = QString() ); void disconnectPlugins( const QString &pluginName = QString() ); void toggleConnect(); diff --git a/src/sip/jabber/jabber.cpp b/src/sip/jabber/jabber.cpp index 05a49141e..761335d5f 100644 --- a/src/sip/jabber/jabber.cpp +++ b/src/sip/jabber/jabber.cpp @@ -76,14 +76,12 @@ JabberPlugin::connectPlugin( bool startup ) if ( startup && !TomahawkSettings::instance()->jabberAutoConnect() ) return false; - m_currentUsername = TomahawkSettings::instance()->jabberUsername(); - m_currentPassword = TomahawkSettings::instance()->jabberPassword(); - m_currentServer = TomahawkSettings::instance()->jabberServer(); - m_currentPort = TomahawkSettings::instance()->jabberPort(); + QString jid = TomahawkSettings::instance()->jabberUsername(); + QString server = TomahawkSettings::instance()->jabberServer(); + QString password = TomahawkSettings::instance()->jabberPassword(); + unsigned int port = TomahawkSettings::instance()->jabberPort(); - QString server = m_currentServer; - - QStringList splitJid = m_currentUsername.split( '@', QString::SkipEmptyParts ); + QStringList splitJid = jid.split( '@', QString::SkipEmptyParts ); if ( splitJid.size() < 2 ) { qDebug() << "JID did not have an @ in it, could not find a server part"; @@ -93,14 +91,14 @@ JabberPlugin::connectPlugin( bool startup ) if ( server.isEmpty() ) server = splitJid[1]; - if ( m_currentPort < 1 || m_currentPort > 65535 || m_currentUsername.isEmpty() || m_currentPassword.isEmpty() ) + if ( port < 1 || port > 65535 || jid.isEmpty() || password.isEmpty() ) { qDebug() << "Jabber credentials look wrong, not connecting"; return false; } delete p; - p = new Jabber_p( m_currentUsername, m_currentPassword, server, m_currentPort ); + p = new Jabber_p( jid, password, server, port ); QObject::connect( p, SIGNAL( peerOnline( QString ) ), SIGNAL( peerOnline( QString ) ) ); QObject::connect( p, SIGNAL( peerOffline( QString ) ), SIGNAL( peerOffline( QString ) ) ); @@ -176,31 +174,4 @@ JabberPlugin::showAddFriendDialog() addContact( id ); } - -void -JabberPlugin::checkSettings() -{ - bool reconnect = false; - - if ( m_currentUsername != TomahawkSettings::instance()->jabberUsername() ) - reconnect = true; - if ( m_currentPassword != TomahawkSettings::instance()->jabberPassword() ) - reconnect = true; - if ( m_currentServer != TomahawkSettings::instance()->jabberServer() ) - reconnect = true; - if ( m_currentPort != TomahawkSettings::instance()->jabberPort() ) - reconnect = true; - - m_currentUsername = TomahawkSettings::instance()->jabberUsername(); - m_currentPassword = TomahawkSettings::instance()->jabberPassword(); - m_currentServer = TomahawkSettings::instance()->jabberServer(); - m_currentPort = TomahawkSettings::instance()->jabberPort(); - - if ( reconnect && ( p || TomahawkSettings::instance()->jabberAutoConnect() ) ) - { - disconnectPlugin(); - connectPlugin( false ); - } -} - Q_EXPORT_PLUGIN2( sip, JabberPlugin ) diff --git a/src/sip/jabber/jabber.h b/src/sip/jabber/jabber.h index a5bd18a9b..c702fed71 100644 --- a/src/sip/jabber/jabber.h +++ b/src/sip/jabber/jabber.h @@ -51,7 +51,7 @@ public slots: void disconnectPlugin() { onDisconnected(); - + if ( p ) p->disconnect(); @@ -59,8 +59,6 @@ public slots: p = 0; } - void checkSettings(); - void sendMsg( const QString& to, const QString& msg ) { if ( p ) @@ -84,16 +82,11 @@ private slots: void showAddFriendDialog(); void onConnected(); void onDisconnected(); - + private: Jabber_p* p; QMenu* m_menu; QAction* m_addFriendAction; - - QString m_currentServer; - QString m_currentUsername; - QString m_currentPassword; - unsigned int m_currentPort; }; #endif diff --git a/src/sip/jabber/jabber_p.cpp b/src/sip/jabber/jabber_p.cpp index 8513ef144..4425b1a93 100644 --- a/src/sip/jabber/jabber_p.cpp +++ b/src/sip/jabber/jabber_p.cpp @@ -27,8 +27,8 @@ #include #include #include -#include #include +#include using namespace gloox; using namespace std; diff --git a/src/sip/twitter/twitter.cpp b/src/sip/twitter/twitter.cpp index d7e0d8464..ba8b3f1ef 100644 --- a/src/sip/twitter/twitter.cpp +++ b/src/sip/twitter/twitter.cpp @@ -168,6 +168,7 @@ TwitterPlugin::disconnectPlugin() m_twitterAuth.data()->deleteLater(); m_cachedPeers.empty(); + m_attemptedConnects.empty(); delete m_twitterAuth.data(); m_isOnline = false; } @@ -583,14 +584,16 @@ TwitterPlugin::registerOffer( const QString &screenName, const QHash< QString, Q qDebug() << "TwitterPlugin did not send offer because external address is " << Servent::instance()->externalAddress() << " and external port is " << Servent::instance()->externalPort(); } - if ( m_isOnline && _peerData.contains( "host" ) && _peerData.contains( "port" ) && _peerData.contains( "pkey" ) ) - QMetaObject::invokeMethod( this, "makeConnection", Q_ARG( QString, screenName ), QGenericArgument( "QHash< QString, QVariant >", (const void*)&_peerData ) ); - if ( peersChanged ) { m_cachedPeers[screenName] = QVariant::fromValue< QHash< QString, QVariant > >( _peerData ); TomahawkSettings::instance()->setTwitterCachedPeers( m_cachedPeers ); + m_attemptedConnects[screenName] = false; } + + if ( m_isOnline && _peerData.contains( "host" ) && _peerData.contains( "port" ) && _peerData.contains( "pkey" ) ) + QMetaObject::invokeMethod( this, "makeConnection", Q_ARG( QString, screenName ), QGenericArgument( "QHash< QString, QVariant >", (const void*)&_peerData ) ); + } void @@ -611,6 +614,11 @@ void TwitterPlugin::makeConnection( const QString &screenName, const QHash< QString, QVariant > &peerData ) { qDebug() << Q_FUNC_INFO; + if ( m_attemptedConnects.contains( screenName ) && m_attemptedConnects[screenName] ) + { + qDebug() << "Already attempted to connect to this peer with no change in their status, not trying again for now"; + return; + } if ( !peerData.contains( "host" ) || !peerData.contains( "port" ) || !peerData.contains( "pkey" ) || !peerData.contains( "node" ) ) { qDebug() << "TwitterPlugin could not find host and/or port and/or pkey for peer " << screenName; @@ -623,6 +631,7 @@ TwitterPlugin::makeConnection( const QString &screenName, const QHash< QString, peerData["pkey"].toString(), friendlyName, peerData["node"].toString() ); + m_attemptedConnects[screenName] = true; } void @@ -630,6 +639,7 @@ TwitterPlugin::directMessagePosted( const QTweetDMStatus& message ) { qDebug() << Q_FUNC_INFO; qDebug() << "TwitterPlugin sent message to " << message.recipientScreenName() << " containing: " << message.text(); + } void @@ -646,11 +656,4 @@ TwitterPlugin::directMessageDestroyed( const QTweetDMStatus& message ) qDebug() << "TwitterPlugin destroyed message " << message.text(); } -void -TwitterPlugin::checkSettings() -{ - disconnectPlugin(); - connectPlugin( false ); -} - Q_EXPORT_PLUGIN2( sip, TwitterPlugin ) diff --git a/src/sip/twitter/twitter.h b/src/sip/twitter/twitter.h index c0da00d7f..b0dc213b3 100644 --- a/src/sip/twitter/twitter.h +++ b/src/sip/twitter/twitter.h @@ -59,8 +59,8 @@ public: public slots: virtual bool connectPlugin( bool startup ); + void disconnectPlugin(); - void checkSettings(); void sendMsg( const QString& to, const QString& msg ) { @@ -108,6 +108,7 @@ private: qint64 m_cachedMentionsSinceId; qint64 m_cachedDirectMessagesSinceId; QHash< QString, QVariant > m_cachedPeers; + QHash< QString, bool > m_attemptedConnects; QSet m_keyCache; bool m_finishedFriends; bool m_finishedMentions; diff --git a/src/sip/zeroconf/zeroconf.h b/src/sip/zeroconf/zeroconf.h index d538f9a67..8c04fa507 100644 --- a/src/sip/zeroconf/zeroconf.h +++ b/src/sip/zeroconf/zeroconf.h @@ -52,8 +52,8 @@ public: public slots: virtual bool connectPlugin( bool startup ); + void disconnectPlugin(); - void checkSettings() {} void sendMsg( const QString& to, const QString& msg ) { From 6a2c2b147d3a15eb6a42b6b1f8e0471ca90034eb Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 28 Mar 2011 05:01:28 +0200 Subject: [PATCH 4/4] * Merged back my fixes. --- src/libtomahawk/sip/SipPlugin.h | 1 + src/sip/SipHandler.cpp | 13 +++++++++-- src/sip/SipHandler.h | 1 + src/sip/jabber/jabber.cpp | 41 +++++++++++++++++++++++++++------ src/sip/jabber/jabber.h | 7 ++++++ src/sip/twitter/twitter.cpp | 7 ++++++ src/sip/twitter/twitter.h | 2 +- src/sip/zeroconf/zeroconf.h | 2 +- 8 files changed, 63 insertions(+), 11 deletions(-) diff --git a/src/libtomahawk/sip/SipPlugin.h b/src/libtomahawk/sip/SipPlugin.h index 4c2b17f1e..47af2fcf3 100644 --- a/src/libtomahawk/sip/SipPlugin.h +++ b/src/libtomahawk/sip/SipPlugin.h @@ -44,6 +44,7 @@ public: public slots: virtual bool connectPlugin( bool startup = false ) = 0; virtual void disconnectPlugin() = 0; + virtual void checkSettings() = 0; virtual void addContact( const QString &jid, const QString& msg = QString() ) = 0; virtual void sendMsg( const QString& to, const QString& msg ) = 0; diff --git a/src/sip/SipHandler.cpp b/src/sip/SipHandler.cpp index d09fe9d7e..a8284a93e 100644 --- a/src/sip/SipHandler.cpp +++ b/src/sip/SipHandler.cpp @@ -59,8 +59,7 @@ SipHandler::plugins() const void SipHandler::onSettingsChanged() { - disconnectPlugins(); - connectPlugins(); + checkSettings(); } @@ -166,6 +165,16 @@ SipHandler::pluginLoaded( const QString& name ) const } +void +SipHandler::checkSettings() +{ + foreach( SipPlugin* sip, m_plugins ) + { + sip->checkSettings(); + } +} + + void SipHandler::connectPlugins( bool startup, const QString &pluginName ) { diff --git a/src/sip/SipHandler.h b/src/sip/SipHandler.h index f127dcc16..0d3dcfa63 100644 --- a/src/sip/SipHandler.h +++ b/src/sip/SipHandler.h @@ -39,6 +39,7 @@ public: public slots: void addContact( const QString& id ) { qDebug() << Q_FUNC_INFO << id; } + void checkSettings(); void connectPlugins( bool startup = false, const QString &pluginName = QString() ); void disconnectPlugins( const QString &pluginName = QString() ); void toggleConnect(); diff --git a/src/sip/jabber/jabber.cpp b/src/sip/jabber/jabber.cpp index 761335d5f..ce62909c4 100644 --- a/src/sip/jabber/jabber.cpp +++ b/src/sip/jabber/jabber.cpp @@ -76,12 +76,13 @@ JabberPlugin::connectPlugin( bool startup ) if ( startup && !TomahawkSettings::instance()->jabberAutoConnect() ) return false; - QString jid = TomahawkSettings::instance()->jabberUsername(); - QString server = TomahawkSettings::instance()->jabberServer(); - QString password = TomahawkSettings::instance()->jabberPassword(); - unsigned int port = TomahawkSettings::instance()->jabberPort(); + m_currentUsername = TomahawkSettings::instance()->jabberUsername(); + m_currentServer = TomahawkSettings::instance()->jabberServer(); + m_currentPassword = TomahawkSettings::instance()->jabberPassword(); + m_currentPort = TomahawkSettings::instance()->jabberPort(); + QString server = m_currentServer; - QStringList splitJid = jid.split( '@', QString::SkipEmptyParts ); + QStringList splitJid = m_currentUsername.split( '@', QString::SkipEmptyParts ); if ( splitJid.size() < 2 ) { qDebug() << "JID did not have an @ in it, could not find a server part"; @@ -91,14 +92,14 @@ JabberPlugin::connectPlugin( bool startup ) if ( server.isEmpty() ) server = splitJid[1]; - if ( port < 1 || port > 65535 || jid.isEmpty() || password.isEmpty() ) + if ( m_currentPort < 1 || m_currentPort > 65535 || m_currentUsername.isEmpty() || m_currentPassword.isEmpty() ) { qDebug() << "Jabber credentials look wrong, not connecting"; return false; } delete p; - p = new Jabber_p( jid, password, server, port ); + p = new Jabber_p( m_currentUsername, m_currentPassword, server, m_currentPort ); QObject::connect( p, SIGNAL( peerOnline( QString ) ), SIGNAL( peerOnline( QString ) ) ); QObject::connect( p, SIGNAL( peerOffline( QString ) ), SIGNAL( peerOffline( QString ) ) ); @@ -174,4 +175,30 @@ JabberPlugin::showAddFriendDialog() addContact( id ); } + +void +JabberPlugin::checkSettings() +{ + bool reconnect = false; + if ( m_currentUsername != TomahawkSettings::instance()->jabberUsername() ) + reconnect = true; + if ( m_currentPassword != TomahawkSettings::instance()->jabberPassword() ) + reconnect = true; + if ( m_currentServer != TomahawkSettings::instance()->jabberServer() ) + reconnect = true; + if ( m_currentPort != TomahawkSettings::instance()->jabberPort() ) + reconnect = true; + + m_currentUsername = TomahawkSettings::instance()->jabberUsername(); + m_currentPassword = TomahawkSettings::instance()->jabberPassword(); + m_currentServer = TomahawkSettings::instance()->jabberServer(); + m_currentPort = TomahawkSettings::instance()->jabberPort(); + + if ( reconnect && ( p || TomahawkSettings::instance()->jabberAutoConnect() ) ) + { + disconnectPlugin(); + connectPlugin( false ); + } +} + Q_EXPORT_PLUGIN2( sip, JabberPlugin ) diff --git a/src/sip/jabber/jabber.h b/src/sip/jabber/jabber.h index c702fed71..b3d868896 100644 --- a/src/sip/jabber/jabber.h +++ b/src/sip/jabber/jabber.h @@ -59,6 +59,8 @@ public slots: p = 0; } + void checkSettings(); + void sendMsg( const QString& to, const QString& msg ) { if ( p ) @@ -87,6 +89,11 @@ private: Jabber_p* p; QMenu* m_menu; QAction* m_addFriendAction; + + QString m_currentUsername; + QString m_currentPassword; + QString m_currentServer; + unsigned int m_currentPort; }; #endif diff --git a/src/sip/twitter/twitter.cpp b/src/sip/twitter/twitter.cpp index ba8b3f1ef..843de4505 100644 --- a/src/sip/twitter/twitter.cpp +++ b/src/sip/twitter/twitter.cpp @@ -656,4 +656,11 @@ TwitterPlugin::directMessageDestroyed( const QTweetDMStatus& message ) qDebug() << "TwitterPlugin destroyed message " << message.text(); } +void +TwitterPlugin::checkSettings() +{ + disconnectPlugin(); + connectPlugin( false ); +} + Q_EXPORT_PLUGIN2( sip, TwitterPlugin ) diff --git a/src/sip/twitter/twitter.h b/src/sip/twitter/twitter.h index b0dc213b3..4e8a98a31 100644 --- a/src/sip/twitter/twitter.h +++ b/src/sip/twitter/twitter.h @@ -59,8 +59,8 @@ public: public slots: virtual bool connectPlugin( bool startup ); - void disconnectPlugin(); + void checkSettings(); void sendMsg( const QString& to, const QString& msg ) { diff --git a/src/sip/zeroconf/zeroconf.h b/src/sip/zeroconf/zeroconf.h index 8c04fa507..d538f9a67 100644 --- a/src/sip/zeroconf/zeroconf.h +++ b/src/sip/zeroconf/zeroconf.h @@ -52,8 +52,8 @@ public: public slots: virtual bool connectPlugin( bool startup ); - void disconnectPlugin(); + void checkSettings() {} void sendMsg( const QString& to, const QString& msg ) {