summaryrefslogtreecommitdiff
path: root/tubes
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2012-03-23 10:18:25 +0000
committerMatúš Kukan <matus.kukan@gmail.com>2012-07-17 16:39:42 +0200
commit1fd537d7582178114005cd3e3c0b90d4db7719cd (patch)
tree91712333d18e4ee7a9c2d983a9f76703657d8105 /tubes
parent0338b92fd4feccbae6d7a4f0a5046ad149fac387 (diff)
WIP
Diffstat (limited to 'tubes')
-rw-r--r--tubes/inc/tubes/contact-list.hxx5
-rw-r--r--tubes/inc/tubes/manager.hxx8
-rw-r--r--tubes/qa/test_manager.cxx10
-rw-r--r--tubes/source/contact-list.cxx43
-rw-r--r--tubes/source/manager.cxx25
5 files changed, 37 insertions, 54 deletions
diff --git a/tubes/inc/tubes/contact-list.hxx b/tubes/inc/tubes/contact-list.hxx
index bf1e0f79d149..a17b1103d96f 100644
--- a/tubes/inc/tubes/contact-list.hxx
+++ b/tubes/inc/tubes/contact-list.hxx
@@ -42,12 +42,9 @@ typedef ::std::vector< AccountContactPair > AccountContactPairV;
class TUBES_DLLPUBLIC ContactList
{
public:
- ContactList();
+ ContactList(TpAccountManager *pAccountManager);
~ContactList();
- typedef void (*PrepareCallback)( GError *errorOr0, void *user_data );
- void prepare( PrepareCallback callback, void *user_data );
-
AccountContactPairV getContacts();
private:
diff --git a/tubes/inc/tubes/manager.hxx b/tubes/inc/tubes/manager.hxx
index aa6a027726af..3d557ad5b458 100644
--- a/tubes/inc/tubes/manager.hxx
+++ b/tubes/inc/tubes/manager.hxx
@@ -33,6 +33,7 @@
#include "tubes/tubesdllapi.h"
#include "tubes/conference.hxx"
#include "tubes/packet.hxx"
+#include "tubes/contact-list.hxx"
#include <rtl/ustring.hxx>
#include <salhelper/thread.hxx>
#include <rtl/ref.hxx>
@@ -82,7 +83,7 @@ public:
TeleManager( const Link& rLink, bool bCreateOwnGMainLoop = false );
~TeleManager();
- /** Prepare the Telepathy Account Manager.
+ /** Prepare the Telepathy Account Manager. Requires connect() to have succeeded.
Invokes an async call that is not ready until meAccountManagerStatus is
set! Until that is AMS_PREPARED nothing else will work.
@@ -92,6 +93,11 @@ public:
void prepareAccountManager();
AccountManagerStatus getAccountManagerStatus() const;
+ /** Fetches the contact list. Returns 0 before connect() is called successfully.
+ Is non-functional until prepareAccountManager().
+ */
+ ContactList* getContactList();
+
#if 0
/** Start a group session in a MUC.
diff --git a/tubes/qa/test_manager.cxx b/tubes/qa/test_manager.cxx
index 31148efe5f13..4e588adcf926 100644
--- a/tubes/qa/test_manager.cxx
+++ b/tubes/qa/test_manager.cxx
@@ -168,14 +168,14 @@ void TestTeleTubes::spinMainLoop()
void TestTeleTubes::testContactList()
{
- ContactList cl;
- cl.prepare( TeleTestTubes_ContactListPrepared, this );
- spinMainLoop();
+ CPPUNIT_ASSERT( mpManager1);
+ CPPUNIT_ASSERT( mpManager1->getAccountManagerStatus() == TeleManager::AMS_PREPARED);
+
+ ContactList *cl = mpManager1->getContactList();
- /* Okay, now everything's prepared, we can get contacts synchronously. */
AccountContactPairV pairs;
- pairs = cl.getContacts();
+ pairs = cl->getContacts();
guint i;
/* FIXME: this is racy, because we can't be 100% sure that MC has finished
diff --git a/tubes/source/contact-list.cxx b/tubes/source/contact-list.cxx
index 602bb63d30d0..4cedc501a322 100644
--- a/tubes/source/contact-list.cxx
+++ b/tubes/source/contact-list.cxx
@@ -34,11 +34,12 @@
#include <tubes/contact-list.hxx>
#include <tubes/manager.hxx>
-ContactList::ContactList()
+ContactList::ContactList(TpAccountManager *pAccountManager)
+ : mpAccountManager(pAccountManager)
{
- g_type_init();
-
- mpAccountManager = tp_account_manager_dup ();
+ SAL_WARN_IF( !mpAccountManager, "tubes",
+ "ContactList::ContactList: passed a null account manager");
+ g_object_ref( mpAccountManager);
/* Tell the client factory (which creates and prepares proxy objects) to
* get the features we need ready before giving us any objects.
@@ -80,40 +81,6 @@ contact_supports_libo_dtube (TpContact *contact)
TP_HANDLE_TYPE_CONTACT, TeleManager::getFullServiceName().getStr());
}
-typedef ::std::pair< ContactList::PrepareCallback, void * > Foo;
-
-static void
-account_manager_prepared_cb (GObject *object,
- GAsyncResult *res,
- gpointer user_data)
-{
- Foo *data = reinterpret_cast<Foo *>(user_data);
- GError *error = NULL;
-
- if (!tp_proxy_prepare_finish (object, res, &error))
- {
- data->first( error, data->second );
- g_clear_error(&error);
- }
- else
- {
- data->first( NULL, data->second );
- }
-
- delete data;
-}
-
-void ContactList::prepare(
- ContactList::PrepareCallback callback,
- void* user_data)
-{
- Foo *data = new Foo(callback, user_data);
-
- /* This will call back immediately (in an idle) if the manager is already
- * prepared, which is fine-ish */
- tp_proxy_prepare_async (mpAccountManager, NULL, account_manager_prepared_cb, data);
-}
-
AccountContactPairV ContactList::getContacts()
{
GList *accounts;
diff --git a/tubes/source/manager.cxx b/tubes/source/manager.cxx
index 8b8655f6bcc6..d3eeefe195a5 100644
--- a/tubes/source/manager.cxx
+++ b/tubes/source/manager.cxx
@@ -82,6 +82,7 @@ public:
TpAccountManager* mpAccountManager;
TeleManager::AccountManagerStatus meAccountManagerStatus;
bool mbAccountManagerReadyHandlerInvoked;
+ ContactList* mpContactList;
TeleManagerImpl();
~TeleManagerImpl();
@@ -400,6 +401,15 @@ bool TeleManager::connect()
if (!pFactory)
return false;
+ TpAccountManager* pAccountManager = tp_account_manager_new_with_factory (
+ TP_SIMPLE_CLIENT_FACTORY (pFactory));
+ tp_account_manager_set_default( pAccountManager);
+
+ /* Takes our ref. */
+ pImpl->mpAccountManager = pAccountManager;
+
+ pImpl->mpContactList = new ContactList(pAccountManager);
+
pImpl->mpClient = tp_simple_handler_new_with_factory(
TP_SIMPLE_CLIENT_FACTORY (pFactory), // factory
FALSE, // bypass_approval
@@ -613,13 +623,10 @@ void TeleManager::prepareAccountManager()
SAL_WARN_IF( pImpl->meAccountManagerStatus != AMS_UNINITIALIZED, "tubes",
"TeleManager::prepareAccountManager: yet another attempt");
+ SAL_WARN_IF( !pImpl->mpAccountManager, "tubes",
+ "TeleManager::prepareAccountManager: called before ::connect()");
if (!pImpl->mpAccountManager)
- {
- pImpl->mpAccountManager = tp_account_manager_dup();
- SAL_WARN_IF( !pImpl->mpAccountManager, "tubes", "TeleManager::prepareAccountManager: no account manager");
- if (!pImpl->mpAccountManager)
- return;
- }
+ return;
pImpl->meAccountManagerStatus = AMS_INPREPARATION;
setAccountManagerReadyHandlerInvoked( false);
@@ -647,6 +654,10 @@ bool TeleManager::isAccountManagerReadyHandlerInvoked() const
return pImpl->mbAccountManagerReadyHandlerInvoked;
}
+ContactList* TeleManager::getContactList()
+{
+ return pImpl->mpContactList;
+}
TpAccount* TeleManager::getAccount( const rtl::OString& rAccountID )
{
@@ -962,6 +973,8 @@ TeleManagerImpl::~TeleManagerImpl()
g_object_unref( mpDBus);
if (mpAccountManager)
g_object_unref( mpAccountManager);
+ if (mpContactList)
+ delete mpContactList;
if (mpLoop)
g_main_loop_unref( mpLoop);
}