From 6f3225979cb497db99381556adb7e42119b44ec3 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Mon, 20 Mar 2017 22:12:20 +0100 Subject: Select conversation on startup, placeholder for "No conversation selected", start services before UI --- libdino/src/application.vala | 18 ++++++++++++++++++ libdino/src/service/conversation_manager.vala | 15 +++++++++++++++ libdino/src/service/stream_interactor.vala | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) (limited to 'libdino') diff --git a/libdino/src/application.vala b/libdino/src/application.vala index 4b5fd274..9cabf0f4 100644 --- a/libdino/src/application.vala +++ b/libdino/src/application.vala @@ -29,10 +29,28 @@ public class Dino.Application : Gtk.Application { RosterManager.start(stream_interaction); ConversationManager.start(stream_interaction, db); ChatInteraction.start(stream_interaction); + + activate.connect(() => { + restore(); + }); } public static string get_storage_dir() { return Path.build_filename(Environment.get_user_data_dir(), "dino"); } + + protected void add_connection(Account account) { + stream_interaction.connect(account); + } + + protected void remove_connection(Account account) { + stream_interaction.disconnect(account); + } + + private void restore() { + foreach (Account account in db.get_accounts()) { + if (account.enabled) add_connection(account); + } + } } diff --git a/libdino/src/service/conversation_manager.vala b/libdino/src/service/conversation_manager.vala index ada9ee9d..10c6ac51 100644 --- a/libdino/src/service/conversation_manager.vala +++ b/libdino/src/service/conversation_manager.vala @@ -9,6 +9,7 @@ public class ConversationManager : StreamInteractionModule, Object { public string id { get { return IDENTITY.id; } } public signal void conversation_activated(Conversation conversation); + public signal void conversation_deactivated(Conversation conversation); private StreamInteractor stream_interactor; private Database db; @@ -37,6 +38,16 @@ public class ConversationManager : StreamInteractionModule, Object { return null; } + public Gee.List get_active_conversations() { + ArrayList ret = new ArrayList(Conversation.equals_func); + foreach (Account account in conversations.keys) { + foreach (Conversation conversation in conversations[account].values) { + if(conversation.active) ret.add(conversation); + } + } + return ret; + } + public Conversation get_add_conversation(Jid jid, Account account) { ensure_add_conversation(jid, account, Conversation.Type.CHAT); return get_conversation(jid, account); @@ -52,7 +63,11 @@ public class ConversationManager : StreamInteractionModule, Object { conversation_activated(conversation); } } + } + public void close_conversation(Conversation conversation) { + conversation.active = false; + conversation_deactivated(conversation); } private void on_account_added(Account account) { diff --git a/libdino/src/service/stream_interactor.vala b/libdino/src/service/stream_interactor.vala index bdc1ac96..81ddfebd 100644 --- a/libdino/src/service/stream_interactor.vala +++ b/libdino/src/service/stream_interactor.vala @@ -72,7 +72,7 @@ public class ModuleIdentity : Object { } public T? cast(StreamInteractionModule module) { - return (T?) module; + return module.get_type().is_a(typeof(T)) ? (T?) module : null; } public bool matches(StreamInteractionModule module) { -- cgit v1.2.3-70-g09d2