[Telepathy-commits] [telepathy-qt4/master] Manually rebase 54a2c7ff9a62a0954910edc0541c023ae8b04ef5
Stefan Eilers
stefan at eilers-online.net
Tue Feb 3 09:52:00 PST 2009
Added signals if an account was modified or removed
---
TelepathyQt4/Prototype/AccountManager.cpp | 42 ++++++++++++++++++++++------
TelepathyQt4/Prototype/AccountManager.h | 15 +++++++++-
tests/prototype/prototype.cpp | 42 +++++++++++++++++++---------
3 files changed, 75 insertions(+), 24 deletions(-)
diff --git a/TelepathyQt4/Prototype/AccountManager.cpp b/TelepathyQt4/Prototype/AccountManager.cpp
index 00ea6c3..265d0b8 100644
--- a/TelepathyQt4/Prototype/AccountManager.cpp
+++ b/TelepathyQt4/Prototype/AccountManager.cpp
@@ -106,6 +106,17 @@ public:
m_validAccountHandles.remove( handle );
}
}
+
+ void connectAccountToManager( const TpPrototype::Account* account, TpPrototype::AccountManager* dest )
+ {
+ QObject::connect( account, SIGNAL( signalRemoved() ),
+ dest, SLOT( slotAccountRemoved() ) );
+ QObject::connect( account, SIGNAL( signalPropertiesChanged( const QVariantMap& ) ),
+ dest, SLOT( slotAccountUpdated() ) );
+ QObject::connect( account, SIGNAL( signalPresenceChanged() ),
+ dest, SLOT( slotAccountUpdated() ) );
+ }
+
};
AccountManager::AccountManager( QObject* parent ):
@@ -256,10 +267,7 @@ void AccountManager::slotAccountValidityChanged( const QDBusObjectPath& account,
qDebug() << "AccountManager::slotAccountValidityChanged: Add new account to list";
#endif
TpPrototype::Account* new_account = new Account( account.path(), this );
- connect( new_account, SIGNAL( signalRemoved() ),
- this, SLOT( slotAccountRemoved() ) );
- connect( new_account, SIGNAL( signalPropertiesChanged( const QVariantMap& ) ),
- this, SLOT( slotPropertiesChanged() ) );
+ d->connectAccountToManager( new_account, this );
d->m_validAccountHandles.insert( account.path(), QPointer<Account>( new_account ) );
update_occurred = true;
emit signalNewAccountAvailable( new_account );
@@ -272,6 +280,7 @@ void AccountManager::slotAccountValidityChanged( const QDBusObjectPath& account,
#ifdef ENABLE_DEBUG_OUTPUT_
qDebug() << "AccountManager::slotAccountValidityChanged: Remove account from list";
#endif
+ emit signalAccountRemoved( d->m_validAccountHandles.value( account.path() ) );
d->removeAccount( account.path() );
update_occurred = true;
}
@@ -285,16 +294,32 @@ void AccountManager::slotAccountRemoved( const QDBusObjectPath& account )
#ifdef ENABLE_DEBUG_OUTPUT_
qDebug() << "AccountManager::slotAccountRemoved() <external>";
#endif
+ Account* account_object = d->m_validAccountHandles.value( account.path() );
+ if ( !account_object )
+ {
+#ifdef ENABLE_DEBUG_OUTPUT_
+ qDebug() << "AccountManager::slotAccountRemoved():Account already removed";
+#endif
+ return;
+ }
+
+ // These signals are emitted if an account was removed extarnally.
+ // The signals were already emitted by slotAccountRemoved() if the account was removed locally
+ emit signalAccountRemoved( account_object );
d->removeAccount( account.path() );
emit signalAccountsUpdated();
}
-void AccountManager::slotPropertiesChanged()
+void AccountManager::slotAccountUpdated()
{
#ifdef ENABLE_DEBUG_OUTPUT_
qDebug() << "AccountManager::slotPropertiesChanged()";
#endif
+ Account* account = qobject_cast<Account*>( sender() );
+ Q_ASSERT( account );
+
+ emit signalAccountUpdated( account );
emit signalAccountsUpdated();
}
@@ -310,6 +335,7 @@ void AccountManager::slotAccountRemoved()
{
QString handle = account->handle();
d->removeAccount( handle );
+ emit signalAccountRemoved( account );
emit signalAccountsUpdated();
}
}
@@ -343,11 +369,9 @@ void AccountManager::init()
{
Account* account = new Account( account_handle.path(), this );
- connect( account, SIGNAL( signalRemoved() ),
- this, SLOT( slotAccountRemoved() ) );
- connect( account, SIGNAL( signalPropertiesChanged( const QVariantMap& ) ),
- this, SLOT( slotPropertiesChanged() ) );
+ d->connectAccountToManager( account, this );
d->m_validAccountHandles.insert( account_handle.path(), QPointer<Account>( account ) );
+ emit signalNewAccountAvailable( account );
emit signalAccountsUpdated();
}
diff --git a/TelepathyQt4/Prototype/AccountManager.h b/TelepathyQt4/Prototype/AccountManager.h
index 12304d3..94f9607 100644
--- a/TelepathyQt4/Prototype/AccountManager.h
+++ b/TelepathyQt4/Prototype/AccountManager.h
@@ -116,6 +116,19 @@ signals:
* This signal is emitted if a new account was created by a contact manager
*/
void signalNewAccountAvailable( TpPrototype::Account* account );
+
+ /**
+ * An account was removed.
+ * This signal is emitted after an account was removed. Do not use <i>account</i> after receiving this signal!
+ */
+ void signalAccountRemoved( TpPrototype::Account* account );
+
+ /**
+ * An account was updated.
+ * This signal is emitted after an account was updated.
+ */
+ void signalAccountUpdated( TpPrototype::Account* account );
+
protected:
/**
* Constructor. The account manager cannot be instantiated directly. Use instance() for it!
@@ -127,7 +140,7 @@ protected slots:
void slotAccountValidityChanged( const QDBusObjectPath& account, bool valid );
void slotAccountRemoved( const QDBusObjectPath& account );
void slotAccountRemoved();
- void slotPropertiesChanged();
+ void slotAccountUpdated();
private:
void init();
diff --git a/tests/prototype/prototype.cpp b/tests/prototype/prototype.cpp
index 321a9cf..ab43f8a 100644
--- a/tests/prototype/prototype.cpp
+++ b/tests/prototype/prototype.cpp
@@ -93,7 +93,7 @@ void UnitTests::testMissionControlBindings()
QDBusPendingReply<uint> reply = mission_control.GetPresenceActual();
reply.waitForFinished();
- QVERIFY2( reply.isFinished(),
+ QVERIFY2( reply.isFinished(),
"Reply from GetPresenceActual() is not finished but should be.." );
QDBusError error = reply.error();
@@ -108,12 +108,12 @@ void UnitTests::testMissionControlBindings()
#ifdef ENABLE_DEBUG_OUTPUT_
qDebug() << "GetPresenceActual: Return: " << reply.value();
-#endif
+#endif
QDBusPendingReply<QString, QDBusObjectPath> reply2 = mission_control.GetConnection( "blah" );
reply2.waitForFinished();
- QVERIFY2( reply2.isFinished(),
+ QVERIFY2( reply2.isFinished(),
"Reply from GetConnection() is not finished but should be.." );
error = reply2.error();
@@ -147,7 +147,7 @@ void UnitTests::testConnectToJabberServer()
parameter_map.insert( "port", static_cast<uint>(5222) );
// 2. Request a connection to the Jabber server
- QDBusPendingReply<QString, QDBusObjectPath> reply = cm_interface.RequestConnection( "jabber",
+ QDBusPendingReply<QString, QDBusObjectPath> reply = cm_interface.RequestConnection( "jabber",
parameter_map );
reply.waitForFinished();
@@ -260,7 +260,7 @@ void UnitTests::testAccountManager_createAccount()
Telepathy::registerTypes();
Telepathy::Client::AccountManagerInterface accountmanager_interface( "org.freedesktop.Telepathy.AccountManager",
- "/org/freedesktop/Telepathy/AccountManager",
+ "/org/freedesktop/Telepathy/AccountManager",
this );
QSignalSpy spy_validity_changed( &accountmanager_interface, SIGNAL( AccountValidityChanged( const QDBusObjectPath&, bool ) ) );
@@ -321,7 +321,7 @@ void UnitTests::testAccountManager_listAccount()
void UnitTests::testAccountManager_showProperties()
{
Telepathy::Client::AccountManagerInterface accountmanager_interface( "org.freedesktop.Telepathy.AccountManager",
- "/org/freedesktop/Telepathy/AccountManager",
+ "/org/freedesktop/Telepathy/AccountManager",
this );
Telepathy::registerTypes();
QStringList object_path_list_valid = objectPathListToStringList(accountmanager_interface.ValidAccounts());
@@ -376,7 +376,7 @@ void UnitTests::testAccountManager_removeAccount()
foreach( QString path, object_path_list_valid )
{
Telepathy::Client::AccountInterface account_interface( "org.freedesktop.Telepathy.AccountManager",
- path,
+ path,
this );
#if 1 // Disable to remove all accounts
@@ -407,11 +407,11 @@ void UnitTests::testAccountManager_removeAccount()
QEXPECT_FAIL( "", "There is currently no signal emitted on AccountInterface::Remove(). This needs to be analyzed further!", Continue );
QVERIFY2( spy_removed.count() == 1, "RemoveAccount does not emits the signal Removed()!" );
}
- }
+ }
{
// Check whether there are really no accounts left..
Telepathy::Client::AccountManagerInterface accountmanager_interface( "org.freedesktop.Telepathy.AccountManager",
- "/org/freedesktop/Telepathy/AccountManager",
+ "/org/freedesktop/Telepathy/AccountManager",
this );
Telepathy::registerTypes();
QStringList object_path_list_valid = objectPathListToStringList(accountmanager_interface.ValidAccounts());
@@ -442,7 +442,7 @@ void UnitTests::testPrototypeAccountManager()
parameter_map.insert( "server", "localhost" );
parameter_map.insert( "resource", "Telepathy" );
parameter_map.insert( "port", static_cast<uint>(5222) );
-#if 1 // Disable this temporarily if the accounts were not deleted properly
+#if 1// Disable this temporarily if the accounts were not deleted properly
if ( 0 != account_manager->count() )
{
QList<QPointer<TpPrototype::Account> > account_list = account_manager->accountList();
@@ -453,13 +453,16 @@ void UnitTests::testPrototypeAccountManager()
}
QVERIFY( 0 == account_manager->count() );
+ QSignalSpy spy_create_account( account_manager, SIGNAL( signalNewAccountAvailable( TpPrototype::Account* ) ) );
+ QCOMPARE( spy_create_account.isValid(), true );
+
QVERIFY( true == account_manager->createAccount( "gabble", "jabber", "Ich 1", parameter_map ) );
QVERIFY( true == account_manager->createAccount( "gabble", "jabber", "Ich 2", parameter_map ) );
QVERIFY( true == account_manager->createAccount( "gabble", "jabber", "Ich 3", parameter_map ) );
+
+ QVERIFY2( waitForSignal( &spy_create_account, 3 ), "Received no signals after createAccount() ");
#endif
- QTest::qWait( 1000 );
-
QVERIFY( 3 == account_manager->count() );
QList<QPointer<TpPrototype::Account> > account_list = account_manager->accountList();
@@ -468,6 +471,9 @@ void UnitTests::testPrototypeAccountManager()
//qDebug() << "Parameters: " << account_list.at(0)->parameters();
//qDebug() << "Properties: " << account_list.at(0)->properties();
+ QSignalSpy spy_update_account( account_manager, SIGNAL( signalAccountUpdated( TpPrototype::Account* ) ) );
+ QCOMPARE( spy_update_account.isValid(), true );
+
QVariant enabled_flag = account_list.at(0)->properties().value( "Enabled" );
QCOMPARE( enabled_flag.toBool(), false );
QVariantMap new_properties;
@@ -489,13 +495,21 @@ void UnitTests::testPrototypeAccountManager()
#endif
QVERIFY( old_parameters != updated_parameters );
QVERIFY( updated_parameters.value( "resource" ) == g_newResourceName );
+
+ QVERIFY2( waitForSignal( &spy_update_account, 2 ), "Received no signals after removeAccount() ");
+ QSignalSpy spy_remove_account( account_manager, SIGNAL( signalAccountRemoved( TpPrototype::Account* ) ) );
+ QCOMPARE( spy_remove_account.isValid(), true );
+
+ int count = 0;
foreach( TpPrototype::Account* account, account_list )
{
+ ++count;
QVERIFY( true == account->remove() );
}
- QTest::qWait( 1000 );
+ QVERIFY2( waitForSignal( &spy_remove_account, count ), "Received no signals after removeAccount() ");
+
QVERIFY( 0 == account_manager->count() );
}
@@ -980,7 +994,7 @@ void UnitTests::testCapabilityManager()
delete connection;
- QTest::qWait( 1000 );
+ QTest::qWait( 1000 );
}
#undef ENABLE_DEBUG_OUTPUT
--
1.5.6.5
More information about the telepathy-commits
mailing list