2017-03-11 22:52:12 +00:00
|
|
|
using Gtk;
|
|
|
|
|
|
|
|
using Dino.Entities;
|
|
|
|
using Dino.Ui;
|
|
|
|
|
2017-05-04 20:05:48 +00:00
|
|
|
public class Dino.Ui.Application : Gtk.Application, Dino.Application {
|
2017-03-11 22:52:12 +00:00
|
|
|
private Notifications notifications;
|
2017-03-17 22:21:23 +00:00
|
|
|
private UnifiedWindow window;
|
2017-03-11 22:52:12 +00:00
|
|
|
|
2017-05-04 20:05:48 +00:00
|
|
|
public Database db { get; set; }
|
2017-08-21 15:16:25 +00:00
|
|
|
public Dino.Entities.Settings settings { get; set; }
|
2017-08-25 19:20:09 +00:00
|
|
|
public StreamInteractor stream_interactor { get; set; }
|
2017-05-04 20:05:48 +00:00
|
|
|
public Plugins.Registry plugin_registry { get; set; default = new Plugins.Registry(); }
|
|
|
|
public SearchPathGenerator? search_path_generator { get; set; }
|
|
|
|
|
2017-03-12 12:19:04 +00:00
|
|
|
public Application() throws Error {
|
2017-12-03 14:40:16 +00:00
|
|
|
Object(application_id: "im.dino.Dino", flags: ApplicationFlags.HANDLES_OPEN);
|
2017-05-04 20:05:48 +00:00
|
|
|
init();
|
2017-03-12 12:19:04 +00:00
|
|
|
Environment.set_application_name("Dino");
|
2017-12-03 14:40:16 +00:00
|
|
|
Window.set_default_icon_name("im.dino.Dino");
|
2017-08-29 19:55:15 +00:00
|
|
|
|
|
|
|
CssProvider provider = new CssProvider();
|
2017-09-05 21:53:18 +00:00
|
|
|
provider.load_from_resource("/im/dino/theme.css");
|
|
|
|
StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), provider, STYLE_PROVIDER_PRIORITY_APPLICATION);
|
2017-03-11 22:52:12 +00:00
|
|
|
|
2017-11-16 17:31:20 +00:00
|
|
|
activate.connect(() => {
|
2017-08-17 09:38:41 +00:00
|
|
|
if (window == null) {
|
|
|
|
create_set_app_menu();
|
2017-08-25 19:20:09 +00:00
|
|
|
window = new UnifiedWindow(this, stream_interactor);
|
|
|
|
notifications = new Notifications(stream_interactor, window);
|
2017-08-17 09:38:41 +00:00
|
|
|
notifications.start();
|
|
|
|
notifications.conversation_selected.connect(window.on_conversation_selected);
|
|
|
|
}
|
2017-05-30 20:47:16 +00:00
|
|
|
window.present();
|
2017-03-20 21:12:20 +00:00
|
|
|
});
|
2017-03-11 22:52:12 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 09:38:41 +00:00
|
|
|
public void handle_uri(string jid, string query, Gee.Map<string, string> options) {
|
|
|
|
switch (query) {
|
2017-08-25 19:20:09 +00:00
|
|
|
case "join":
|
|
|
|
Dialog dialog = new Dialog.with_buttons(_("Join Conference"), window, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.USE_HEADER_BAR, _("Join"), ResponseType.OK, _("Cancel"), ResponseType.CANCEL);
|
|
|
|
dialog.modal = true;
|
2017-10-28 20:02:32 +00:00
|
|
|
Button ok_button = dialog.get_widget_for_response(ResponseType.OK) as Button;
|
2017-08-25 19:20:09 +00:00
|
|
|
ok_button.get_style_context().add_class("suggested-action");
|
2017-10-28 20:02:32 +00:00
|
|
|
ConferenceDetailsFragment conference_fragment = new ConferenceDetailsFragment(stream_interactor, ok_button);
|
2017-08-25 19:20:09 +00:00
|
|
|
conference_fragment.jid = jid;
|
|
|
|
conference_fragment.set_editable();
|
|
|
|
Box content_area = dialog.get_content_area();
|
|
|
|
content_area.add(conference_fragment);
|
|
|
|
dialog.response.connect((response_id) => {
|
|
|
|
if (response_id == ResponseType.OK) {
|
|
|
|
stream_interactor.get_module(MucManager.IDENTITY).join(conference_fragment.account, new Jid(conference_fragment.jid), conference_fragment.nick, conference_fragment.password);
|
|
|
|
dialog.destroy();
|
|
|
|
} else if (response_id == ResponseType.CANCEL) {
|
|
|
|
dialog.destroy();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialog.present();
|
|
|
|
break;
|
2017-08-17 09:38:41 +00:00
|
|
|
case "message":
|
2017-10-22 01:39:13 +00:00
|
|
|
Gee.List<Account> accounts = stream_interactor.get_accounts();
|
|
|
|
if (accounts.size == 1) {
|
|
|
|
Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(new Jid(jid), accounts[0], Conversation.Type.CHAT);
|
2017-08-25 19:20:09 +00:00
|
|
|
stream_interactor.get_module(ConversationManager.IDENTITY).start_conversation(conversation, true);
|
|
|
|
window.on_conversation_selected(conversation);
|
2017-10-22 01:39:13 +00:00
|
|
|
} else {
|
2017-10-28 20:02:32 +00:00
|
|
|
AddChatDialog dialog = new AddChatDialog(stream_interactor, stream_interactor.get_accounts());
|
2017-10-22 01:39:13 +00:00
|
|
|
dialog.set_filter(jid);
|
|
|
|
dialog.set_transient_for(window);
|
2017-10-28 20:02:32 +00:00
|
|
|
dialog.added.connect((conversation) => {
|
2017-10-22 01:39:13 +00:00
|
|
|
window.on_conversation_selected(conversation);
|
|
|
|
});
|
|
|
|
dialog.present();
|
|
|
|
}
|
2017-08-17 09:38:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-11 22:52:12 +00:00
|
|
|
private void show_accounts_window() {
|
2017-08-25 19:20:09 +00:00
|
|
|
ManageAccounts.Dialog dialog = new ManageAccounts.Dialog(stream_interactor, db);
|
2017-03-11 22:52:12 +00:00
|
|
|
dialog.set_transient_for(window);
|
|
|
|
dialog.account_enabled.connect(add_connection);
|
|
|
|
dialog.account_disabled.connect(remove_connection);
|
2017-05-30 20:47:16 +00:00
|
|
|
dialog.present();
|
2017-03-11 22:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void show_settings_window() {
|
|
|
|
SettingsDialog dialog = new SettingsDialog();
|
|
|
|
dialog.set_transient_for(window);
|
2017-05-30 20:47:16 +00:00
|
|
|
dialog.present();
|
2017-03-11 22:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void create_set_app_menu() {
|
|
|
|
SimpleAction accounts_action = new SimpleAction("accounts", null);
|
|
|
|
accounts_action.activate.connect(show_accounts_window);
|
|
|
|
add_action(accounts_action);
|
|
|
|
|
|
|
|
SimpleAction settings_action = new SimpleAction("settings", null);
|
|
|
|
settings_action.activate.connect(show_settings_window);
|
|
|
|
add_action(settings_action);
|
|
|
|
|
|
|
|
SimpleAction quit_action = new SimpleAction("quit", null);
|
|
|
|
quit_action.activate.connect(quit);
|
|
|
|
add_action(quit_action);
|
2017-11-06 00:02:13 +00:00
|
|
|
set_accels_for_action("app.quit", new string[]{"<Ctrl>Q"});
|
2017-03-11 22:52:12 +00:00
|
|
|
|
2017-08-17 19:24:01 +00:00
|
|
|
Builder builder = new Builder.from_resource("/im/dino/menu_app.ui");
|
2017-03-11 22:52:12 +00:00
|
|
|
MenuModel menu = builder.get_object("menu_app") as MenuModel;
|
|
|
|
|
|
|
|
set_app_menu(menu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|