[ekiga] Moved the engine chat stack to the new organisation
- From: Julien Puydt <jpuydt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ekiga] Moved the engine chat stack to the new organisation
- Date: Wed, 26 Feb 2014 09:32:19 +0000 (UTC)
commit 75469c5be2fbcfdc0e62ae7d2e23edc8db75c1ac
Author: Julien Puydt <jpuydt free fr>
Date: Sun Feb 16 08:43:56 2014 +0100
Moved the engine chat stack to the new organisation
lib/Makefile.am | 5 +-
lib/engine/chat/chat-core.cpp | 26 ++++-
lib/engine/chat/chat-core.h | 31 ++----
lib/engine/chat/conversation.h | 16 +++-
lib/engine/chat/dialect-impl.h | 228 ++++++++++++----------------------------
lib/engine/chat/dialect.h | 42 ++++----
6 files changed, 132 insertions(+), 216 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 9d0b5c6..942b0b2 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -218,10 +218,7 @@ libekiga_la_SOURCES += \
engine/chat/chat-core.cpp \
engine/chat/dialect.h \
engine/chat/dialect-impl.h \
- engine/chat/conversation.h \
- engine/chat/chat.h \
- engine/chat/chat-simple.h \
- engine/chat/chat-multiple.h
+ engine/chat/conversation.h
##
# Sources of the friend-or-foe stack
diff --git a/lib/engine/chat/chat-core.cpp b/lib/engine/chat/chat-core.cpp
index 4b7eb67..5aa6e87 100644
--- a/lib/engine/chat/chat-core.cpp
+++ b/lib/engine/chat/chat-core.cpp
@@ -42,7 +42,8 @@ Ekiga::ChatCore::~ChatCore ()
void
Ekiga::ChatCore::add_dialect (DialectPtr dialect)
{
- dialects.push_back (dialect);
+ add_object (dialect);
+ dialect->updated.connect (boost::ref (updated));
dialect->questions.connect (boost::ref (questions));
dialect_added (dialect);
}
@@ -52,19 +53,34 @@ Ekiga::ChatCore::visit_dialects (boost::function1<bool, DialectPtr > visitor) co
{
bool go_on = true;
- for (std::list<DialectPtr >::const_iterator iter = dialects.begin ();
- iter != dialects.end () && go_on;
+ for (const_iterator iter = begin ();
+ iter != end () && go_on;
iter++)
go_on = visitor (*iter);
}
+int
+Ekiga::ChatCore::get_unread_messages_count () const
+{
+ int result = 0;
+
+ for (const_iterator iter = begin ();
+ iter != end ();
+ ++iter) {
+
+ result += (*iter)->get_unread_messages_count ();
+ }
+
+ return result;
+}
+
bool
Ekiga::ChatCore::populate_menu (MenuBuilder &builder)
{
bool result = false;
- for (std::list<DialectPtr >::iterator iter = dialects.begin ();
- iter != dialects.end ();
+ for (iterator iter = begin ();
+ iter != end ();
++iter)
result = (*iter)->populate_menu (builder) || result;
diff --git a/lib/engine/chat/chat-core.h b/lib/engine/chat/chat-core.h
index 444663c..ca9b0df 100644
--- a/lib/engine/chat/chat-core.h
+++ b/lib/engine/chat/chat-core.h
@@ -1,7 +1,7 @@
/*
* Ekiga -- A VoIP and Video-Conferencing application
- * Copyright (C) 2000-2009 Damien Sandras <dsandras seconix com>
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -28,7 +28,7 @@
* chat-core.h - description
* ------------------------------------------
* begin : written in 2007 by Julien Puydt
- * copyright : (c) 2007 by Julien Puydt
+ * copyright : (c) 2007-2014 by Julien Puydt
* description : declaration of the main chat managing object
*
*/
@@ -36,13 +36,11 @@
#ifndef __CHAT_CORE_H__
#define __CHAT_CORE_H__
+#include "reflister.h"
+
#include "services.h"
#include "dialect.h"
-/* FIXME: probably it should have a decorator system, so we can for example
- * hook a logger
- */
-
namespace Ekiga
{
/**
@@ -55,7 +53,9 @@ namespace Ekiga
* Notice that you give dialects to this object as references, so they won't
* be freed here : it's up to you to free them somehow.
*/
- class ChatCore: public Service
+ class ChatCore:
+ public Service,
+ public RefLister<Dialect>
{
public:
@@ -97,15 +97,16 @@ namespace Ekiga
*/
void visit_dialects (boost::function1<bool, DialectPtr > visitor) const;
+ /** This method makes it easy to know how many unread messages
+ * there are
+ */
+ int get_unread_messages_count () const;
+
/** This signal is emitted when an Ekiga::Dialect has been added to
* the ChatCore service.
*/
boost::signals2::signal<void(DialectPtr)> dialect_added;
- private:
-
- std::list<DialectPtr > dialects;
-
/*** Misc ***/
public:
@@ -114,14 +115,6 @@ namespace Ekiga
*/
bool populate_menu (MenuBuilder &builder);
- /** This signal is emitted when the ChatCore service has been updated.
- */
- boost::signals2::signal<void(void)> updated;
-
- /** This chain allows the ChatCore to present forms to the user
- */
- ChainOfResponsibility<FormRequestPtr> questions;
-
};
/**
diff --git a/lib/engine/chat/conversation.h b/lib/engine/chat/conversation.h
index a368492..12cb312 100644
--- a/lib/engine/chat/conversation.h
+++ b/lib/engine/chat/conversation.h
@@ -60,7 +60,8 @@ namespace Ekiga {
*
* <if code comes here that's a problem>
*/
- const std::map<const std::string, const std::string> payload;
+ typedef typename std::map<std::string, std::string> payload_type;
+ const payload_type payload;
};
class Conversation: public LiveObject
@@ -81,17 +82,26 @@ namespace Ekiga {
*/
virtual void visit_messages (boost::function1<bool, const Message&>) const = 0;
+ /* Send a message through this conversation
+ * @param: the message to send
+ * @return: whether we could send
+ */
+ virtual bool send_message (const Message::payload_type&) = 0;
+
/* This couple of methods makes it possible to count how many
* messages haven't been read by the user: the conversation
* increments its unread counter everytime a message is received,
* and everytime a view is seen (has the focus, not just exists),
* it resets it to zero.
*/
- virtual int get_unred_messages_number () const = 0;
- virtual void reset_unread_messages_number () const = 0;
+ virtual int get_unread_messages_count () const = 0;
+ virtual void reset_unread_messages_count () = 0;
/* views which already exist need to know only about new messages */
boost::signals2::signal<void(const Message&)> message_received;
+
+ /* This signal is emitted when the user requested to see this */
+ boost::signals2::signal<void(void)> user_requested;
};
typedef boost::shared_ptr<Conversation> ConversationPtr;
diff --git a/lib/engine/chat/dialect-impl.h b/lib/engine/chat/dialect-impl.h
index 1006c66..74b6da2 100644
--- a/lib/engine/chat/dialect-impl.h
+++ b/lib/engine/chat/dialect-impl.h
@@ -1,7 +1,7 @@
/*
* Ekiga -- A VoIP and Video-Conferencing application
- * Copyright (C) 2000-2009 Damien Sandras <dsandras seconix com>
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -28,7 +28,7 @@
* dialect.h - description
* ------------------------------------------
* begin : written in 2008 by Julien Puydt
- * copyright : (c) 2008 by Julien Puydt
+ * copyright : (c) 2008-2014 by Julien Puydt
* description : basic implementation of a real chat backend
*
*/
@@ -38,16 +38,14 @@
#include "dialect.h"
-#include "scoped-connections.h"
-#include "map-key-iterator.h"
-#include "map-key-const-iterator.h"
+#include "reflister.h"
namespace Ekiga
{
- template<typename SimpleChatType = SimpleChat,
- typename MultipleChatType = MultipleChat>
+ template<typename ConversationType = Conversation>
class DialectImpl:
public Dialect,
+ public RefLister<ConversationType>,
public boost::signals2::trackable
{
public:
@@ -56,208 +54,114 @@ namespace Ekiga
*/
DialectImpl ();
- /** Triggers a callback for all simple chats of the Dialect.
- * @param: The callback (the return value means "go on" and allows
- * stopping the visit)
+ /** Aggregates the number of unread messages in all conversations
+ * within the dialect
*/
- void visit_simple_chats (boost::function1<bool, SimpleChatPtr > visitor) const;
+ int get_unread_messages_count () const;
- /** Triggers a callback for all multiple chats of the Dialect.
+ /** Triggers a callback for all conversations of the Dialect
* @param: The callback (the return value means "go on" and allows
* stopping the visit)
*/
- void visit_multiple_chats (boost::function1<bool, MultipleChatPtr > visitor) const;
+ void visit_conversations (boost::function1<bool, ConversationPtr> visitor) const;
protected:
- /* More STL-like ways to access the chats within this Ekiga::DialectImpl
- */
- typedef typename std::map<boost::shared_ptr<SimpleChatType>,
boost::shared_ptr<Ekiga::scoped_connections> > simple_chats_type;
- typedef typename std::map<boost::shared_ptr<MultipleChatType>,
boost::shared_ptr<Ekiga::scoped_connections> > multiple_chats_type;
-
- typedef typename Ekiga::map_key_iterator<simple_chats_type> simple_iterator;
- typedef typename Ekiga::map_key_const_iterator<simple_chats_type> simple_const_iterator;
- typedef typename Ekiga::map_key_iterator<multiple_chats_type> multiple_iterator;
- typedef typename Ekiga::map_key_const_iterator<multiple_chats_type> multiple_const_iterator;
-
- simple_iterator simple_begin ();
- simple_iterator simple_end ();
+ using RefLister<ConversationType>::add_connection;
- simple_const_iterator simple_begin () const;
- simple_const_iterator simple_end () const;
-
- multiple_iterator multiple_begin ();
- multiple_iterator multiple_end ();
-
- multiple_const_iterator multiple_begin () const;
- multiple_const_iterator multiple_end () const;
-
- /** Adds a SimpleChat to the Ekiga::Dialect.
- * @param The SimpleChat to be added.
- * @return: The Ekiga::Dialect 'simple_chat_added' signal is emitted.
- */
- void add_simple_chat (boost::shared_ptr<SimpleChatType> chat);
-
- /** Removes a SimpleChat from the Ekiga::Dialect.
- * @param The SimpleChat to be removed.
+ /* More STL-like ways to access the chats within this Ekiga::DialectImpl
*/
- void remove_simple_chat (boost::shared_ptr<SimpleChatType> chat);
-
- /** Adds a MultipleChat to the Ekiga::Dialect.
- * @param The MultipleChat to be added.
- * @return: The Ekiga::Dialect 'multiple_chat_added' signal is emitted.
+ typedef typename RefLister<ConversationType>::iterator iterator;
+ typedef typename RefLister<ConversationType>::const_iterator const_iterator;
+
+ iterator begin ();
+ iterator end ();
+
+ const_iterator begin () const;
+ const_iterator end () const;
+
+ /** Adds a Conversation to the Ekiga::Dialect.
+ * @param The Conversation to be added
+ * @return: The Ekiga::Dialect 'conversation_added' signal is emitted.
*/
- void add_multiple_chat (boost::shared_ptr<MultipleChatType> chat);
+ void add_conversation (boost::shared_ptr<ConversationType> conversation);
- /** Removes a MultipleChat from the Ekiga::Dialect.
- * @param The MultipleChat to be removed.
+ /** Removes a Conversation from the Ekiga::Dialect.
+ * @param The Conversation to be removed.
*/
- void remove_multiple_chat (boost::shared_ptr<MultipleChatType> chat);
-
- private:
-
- simple_chats_type simple_chats;
- multiple_chats_type multiple_chats;
+ void remove_conversation (boost::shared_ptr<ConversationType> conversation);
- void on_simple_chat_removed (boost::shared_ptr<SimpleChatType> chat);
-
- void on_multiple_chat_removed (boost::shared_ptr<MultipleChatType> chat);
};
};
-template<typename SimpleChatType, typename MultipleChatType>
-Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::DialectImpl ()
+template<typename ConversationType>
+Ekiga::DialectImpl<ConversationType>::DialectImpl ()
{
+ RefLister<ConversationType>::object_added.connect (boost::ref (conversation_added));
+ RefLister<ConversationType>::object_removed.connect (boost::ref (conversation_removed));
+ RefLister<ConversationType>::object_updated.connect (boost::ref (conversation_updated));
}
-template<typename SimpleChatType, typename MultipleChatType>
-void
-Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::visit_simple_chats (boost::function1<bool,
SimpleChatPtr > visitor) const
+template<typename ConversationType>
+int
+Ekiga::DialectImpl<ConversationType>::get_unread_messages_count () const
{
- bool go_on = true;
-
- for (typename simple_chats_type::const_iterator iter = simple_chats.begin ();
- go_on && iter != simple_chats.end ();
- iter++) {
+ int count = 0;
+ for (const_iterator iter = begin (); iter != end (); ++iter)
+ count += (*iter)->get_unread_messages_count ();
- go_on = visitor (iter->first);
- }
+ return count;
}
-template<typename SimpleChatType, typename MultipleChatType>
+template<typename ConversationType>
void
-Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::visit_multiple_chats (boost::function1<bool,
MultipleChatPtr > visitor) const
+Ekiga::DialectImpl<ConversationType>::visit_conversations (boost::function1<bool, ConversationPtr> visitor)
const
{
- bool go_on = true;
-
- for (typename multiple_chats_type::const_iterator iter = multiple_chats.begin ();
- go_on && iter != multiple_chats.end ();
- iter++) {
-
- go_on = visitor (iter->first);
- }
-}
-
-template<typename SimpleChatType, typename MultipleChatType>
-typename Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::simple_iterator
-Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::simple_begin ()
-{
- return simple_iterator (simple_chats.begin ());
+ RefLister<ConversationType>::visit_objects (visitor);
}
-template<typename SimpleChatType, typename MultipleChatType>
-typename Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::simple_iterator
-Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::simple_end ()
+template<typename ConversationType>
+typename Ekiga::DialectImpl<ConversationType>::iterator
+Ekiga::DialectImpl<ConversationType>::begin ()
{
- return simple_iterator (simple_chats.end ());
+ return RefLister<ConversationType>::begin ();
}
-template<typename SimpleChatType, typename MultipleChatType>
-typename Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::simple_const_iterator
-Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::simple_begin () const
+template<typename ConversationType>
+typename Ekiga::DialectImpl<ConversationType>::iterator
+Ekiga::DialectImpl<ConversationType>::end ()
{
- return simple_const_iterator (simple_chats.begin ());
+ return RefLister<ConversationType>::end ();
}
-template<typename SimpleChatType, typename MultipleChatType>
-typename Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::simple_const_iterator
-Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::simple_end () const
+template<typename ConversationType>
+typename Ekiga::DialectImpl<ConversationType>::const_iterator
+Ekiga::DialectImpl<ConversationType>::begin () const
{
- return simple_const_iterator (simple_chats.end ());
+ return RefLister<ConversationType>::begin ();
}
-template<typename SimpleChatType, typename MultipleChatType>
-typename Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::multiple_iterator
-Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::multiple_begin ()
+template<typename ConversationType>
+typename Ekiga::DialectImpl<ConversationType>::const_iterator
+Ekiga::DialectImpl<ConversationType>::end () const
{
- return multiple_iterator (multiple_chats.begin ());
+ return RefLister<ConversationType>::end ();
}
-template<typename SimpleChatType, typename MultipleChatType>
-typename Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::multiple_iterator
-Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::multiple_end ()
-{
- return multiple_iterator (multiple_chats.end ());
-}
-
-template<typename SimpleChatType, typename MultipleChatType>
-typename Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::multiple_const_iterator
-Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::multiple_begin () const
-{
- return multiple_const_iterator (multiple_chats.begin ());
-}
-
-template<typename SimpleChatType, typename MultipleChatType>
-typename Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::multiple_const_iterator
-Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::multiple_end () const
-{
- return multiple_const_iterator (multiple_chats.end ());
-}
-
-template<typename SimpleChatType, typename MultipleChatType>
+template<typename ConversationType>
void
-Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::add_simple_chat (boost::shared_ptr<SimpleChatType>
chat)
+Ekiga::DialectImpl<ConversationType>::add_conversation (boost::shared_ptr<ConversationType> conversation)
{
- simple_chats[chat] = boost::shared_ptr<scoped_connections> (new scoped_connections);
- simple_chats[chat]->add (chat->removed.connect (boost::bind (&Ekiga::DialectImpl<SimpleChatType,
MultipleChatType>::on_simple_chat_removed, this, chat)));
- simple_chat_added (chat);
-}
+ conversation->questions.connect (boost::ref (questions));
-template<typename SimpleChatType, typename MultipleChatType>
-void
-Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::remove_simple_chat (boost::shared_ptr<SimpleChatType>
chat)
-{
- chat->removed ();
-}
-
-template<typename SimpleChatType, typename MultipleChatType>
-void
-Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::add_multiple_chat (boost::shared_ptr<MultipleChatType>
chat)
-{
- multiple_chats[chat] = boost::shared_ptr<scoped_connections> (new scoped_connections);
- multiple_chats[chat]->add (chat->removed.connect (boost::bind (&Ekiga::DialectImpl<SimpleChatType,
MultipleChatType>::on_multiple_chat_removed, this, chat)));
- multiple_chat_added (chat);
-}
-
-template<typename SimpleChatType, typename MultipleChatType>
-void
-Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::remove_multiple_chat
(boost::shared_ptr<MultipleChatType> chat)
-{
- chat->removed ();
-}
-
-template<typename SimpleChatType, typename MultipleChatType>
-void
-Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::on_simple_chat_removed
(boost::shared_ptr<SimpleChatType> chat)
-{
- simple_chats.erase (chat);
+ this->add_object (conversation);
}
-template<typename SimpleChatType, typename MultipleChatType>
+template<typename ConversationType>
void
-Ekiga::DialectImpl<SimpleChatType, MultipleChatType>::on_multiple_chat_removed
(boost::shared_ptr<MultipleChatType> chat)
+Ekiga::DialectImpl<ConversationType>::remove_conversation (boost::shared_ptr<ConversationType> conversation)
{
- multiple_chats.erase (chat);
+ this->remove_object (conversation);
}
#endif
diff --git a/lib/engine/chat/dialect.h b/lib/engine/chat/dialect.h
index 0af7832..501c9e8 100644
--- a/lib/engine/chat/dialect.h
+++ b/lib/engine/chat/dialect.h
@@ -37,13 +37,12 @@
#ifndef __DIALECT_H__
#define __DIALECT_H__
-#include "chat-simple.h"
-#include "chat-multiple.h"
+#include "conversation.h"
namespace Ekiga
{
- class Dialect
+ class Dialect: public virtual LiveObject
{
public:
@@ -51,37 +50,34 @@ namespace Ekiga
*/
virtual ~Dialect () {}
- /** Triggers a callback for all simple chats of the Dialect.
- * @param: The callback (the return value means "go on" and allows
- * stopping the visit)
+ /** Aggregates the number of unread messages in all conversations
+ * within the dialect
*/
- virtual void visit_simple_chats (boost::function1<bool, SimpleChatPtr > visitor) const = 0;
+ virtual int get_unread_messages_count () const = 0;
- /** Triggers a callback for all multiple chats of the Dialect.
+ /** Triggers a callback for all conversations of the Dialect
* @param: The callback (the return value means "go on" and allows
* stopping the visit)
*/
- virtual void visit_multiple_chats (boost::function1<bool, MultipleChatPtr > visitor) const = 0;
-
-
- /** Feed possible actions on this Dialect to the given MenuBuilder
- * @param A MenuBuilder object to populate.
- */
- virtual bool populate_menu (MenuBuilder &) = 0;
+ virtual void visit_conversations (boost::function1<bool, ConversationPtr> visitor) const = 0;
- /** This signal is emitted when an Ekiga::SimpleChat has been added to
- * the dialect.
+ /**
+ * This signal is emitted when an Ekiga::Conversation has been added
+ * to the dialect.
*/
- boost::signals2::signal<void(SimpleChatPtr)> simple_chat_added;
+ boost::signals2::signal<void(ConversationPtr)> conversation_added;
- /** This signal is emitted when an Ekiga::MultipleChat has been added to
- * the dialect.
+ /**
+ * This signal is emitted when an Ekiga::Conversation has been removed
+ * from the dialect.
*/
- boost::signals2::signal<void(MultipleChatPtr)> multiple_chat_added;
+ boost::signals2::signal<void(ConversationPtr)> conversation_removed;
- /** This chain allows the Dialect to present forms to the user.
+ /**
+ * This signal is emitted when an Ekiga::Conversation has been updated
+ * in the dialect.
*/
- ChainOfResponsibility<FormRequestPtr> questions;
+ boost::signals2::signal<void(ConversationPtr)> conversation_updated;
};
typedef boost::shared_ptr<Dialect> DialectPtr;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]