2017-03-02 14:37:32 +00:00
|
|
|
using Dino.Entities;
|
|
|
|
|
2017-05-04 20:05:48 +00:00
|
|
|
public interface Dino.Application : GLib.Application {
|
2017-03-02 14:37:32 +00:00
|
|
|
|
2017-05-04 20:05:48 +00:00
|
|
|
public abstract Database db { get; set; }
|
|
|
|
public abstract StreamInteractor stream_interaction { get; set; }
|
|
|
|
public abstract Plugins.Registry plugin_registry { get; set; }
|
|
|
|
public abstract SearchPathGenerator? search_path_generator { get; set; }
|
2017-03-02 14:37:32 +00:00
|
|
|
|
2017-04-03 13:09:30 +00:00
|
|
|
static string print_xmpp;
|
|
|
|
|
|
|
|
private const OptionEntry[] options = {
|
|
|
|
{ "print-xmpp", 0, 0, OptionArg.STRING, ref print_xmpp, "Print XMPP stanzas identified by DESC to stderr", "DESC" },
|
|
|
|
{ null }
|
|
|
|
};
|
|
|
|
|
2017-05-04 20:05:48 +00:00
|
|
|
public void init() throws Error {
|
2017-03-12 12:19:04 +00:00
|
|
|
if (DirUtils.create_with_parents(get_storage_dir(), 0700) == -1) {
|
2017-03-30 19:26:17 +00:00
|
|
|
throw new Error(-1, 0, "Could not create storage dir \"%s\": %s", get_storage_dir(), FileUtils.error_from_errno(errno).to_string());
|
2017-03-12 12:19:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.db = new Database(Path.build_filename(get_storage_dir(), "dino.db"));
|
2017-03-02 14:37:32 +00:00
|
|
|
this.stream_interaction = new StreamInteractor(db);
|
|
|
|
|
|
|
|
AvatarManager.start(stream_interaction, db);
|
2017-04-04 13:47:00 +00:00
|
|
|
MessageProcessor.start(stream_interaction, db);
|
|
|
|
MessageStorage.start(stream_interaction, db);
|
2017-03-02 14:37:32 +00:00
|
|
|
CounterpartInteractionManager.start(stream_interaction);
|
|
|
|
PresenceManager.start(stream_interaction);
|
|
|
|
MucManager.start(stream_interaction);
|
2017-05-21 21:30:30 +00:00
|
|
|
RosterManager.start(stream_interaction, db);
|
2017-03-02 14:37:32 +00:00
|
|
|
ConversationManager.start(stream_interaction, db);
|
|
|
|
ChatInteraction.start(stream_interaction);
|
2017-03-20 21:12:20 +00:00
|
|
|
|
|
|
|
activate.connect(() => {
|
2017-04-03 13:09:30 +00:00
|
|
|
stream_interaction.connection_manager.log_options = print_xmpp;
|
2017-03-20 21:12:20 +00:00
|
|
|
restore();
|
|
|
|
});
|
2017-04-03 13:09:30 +00:00
|
|
|
add_main_option_entries(options);
|
2017-03-02 14:37:32 +00:00
|
|
|
}
|
2017-03-12 12:19:04 +00:00
|
|
|
|
|
|
|
public static string get_storage_dir() {
|
|
|
|
return Path.build_filename(Environment.get_user_data_dir(), "dino");
|
|
|
|
}
|
2017-03-20 21:12:20 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2017-03-02 14:37:32 +00:00
|
|
|
}
|
|
|
|
|