anotherim-desktop/main/src/ui/application.vala

187 lines
8.7 KiB
Vala
Raw Normal View History

2017-03-11 22:52:12 +00:00
using Gtk;
using Dino.Entities;
using Dino.Ui;
using Xmpp;
2017-03-11 22:52:12 +00:00
public class Dino.Ui.Application : Gtk.Application, Dino.Application {
2017-03-11 22:52:12 +00:00
private Notifications notifications;
private UnifiedWindow window;
private UnifiedWindowController controller;
2017-03-11 22:52:12 +00:00
public Database db { get; set; }
2017-08-21 15:16:25 +00:00
public Dino.Entities.Settings settings { get; set; }
private Config config { get; set; }
2017-08-25 19:20:09 +00:00
public StreamInteractor stream_interactor { get; set; }
public Plugins.Registry plugin_registry { get; set; default = new Plugins.Registry(); }
public SearchPathGenerator? search_path_generator { get; set; }
public Application() throws Error {
Object(application_id: "im.dino.Dino", flags: ApplicationFlags.HANDLES_OPEN);
init();
Environment.set_application_name("Dino");
Window.set_default_icon_name("im.dino.Dino");
2017-08-29 19:55:15 +00:00
CssProvider provider = new CssProvider();
provider.load_from_resource("/im/dino/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
create_actions();
startup.connect(() => {
notifications = new Notifications(stream_interactor);
notifications.start();
});
2017-11-16 17:31:20 +00:00
activate.connect(() => {
if (window == null) {
controller = new UnifiedWindowController(this, stream_interactor, db);
config = new Config(db);
window = new UnifiedWindow(this, stream_interactor, db, config);
controller.set_window(window);
if ((get_flags() & ApplicationFlags.IS_SERVICE) == ApplicationFlags.IS_SERVICE) window.delete_event.connect(window.hide_on_delete);
notifications.conversation_selected.connect((conversation) => window.on_conversation_selected(conversation));
}
2017-05-30 20:47:16 +00:00
window.present();
});
2017-03-11 22:52:12 +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":
show_join_muc_dialog(null, new Jid(jid));
2017-08-25 19:20:09 +00:00
break;
case "message":
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);
stream_interactor.get_module(ConversationManager.IDENTITY).start_conversation(conversation);
2017-08-25 19:20:09 +00:00
window.on_conversation_selected(conversation);
} else {
AddChatDialog dialog = new AddChatDialog(stream_interactor, stream_interactor.get_accounts());
dialog.set_filter(jid);
dialog.set_transient_for(window);
dialog.added.connect((conversation) => {
window.on_conversation_selected(conversation);
});
dialog.present();
}
break;
}
}
private void create_actions() {
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);
set_accels_for_action("app.quit", new string[]{"<Ctrl>Q"});
SimpleAction open_conversation_action = new SimpleAction("open-conversation", VariantType.INT32);
open_conversation_action.activate.connect((variant) => {
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32());
if (conversation != null) window.on_conversation_selected(conversation);
window.present();
});
add_action(open_conversation_action);
SimpleAction deny_subscription_action = new SimpleAction("deny-subscription", VariantType.INT32);
deny_subscription_action.activate.connect((variant) => {
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32());
if (conversation == null) return;
stream_interactor.get_module(PresenceManager.IDENTITY).deny_subscription(conversation.account, conversation.counterpart);
});
add_action(deny_subscription_action);
SimpleAction contacts_action = new SimpleAction("add_chat", null);
contacts_action.activate.connect(() => {
AddChatDialog add_chat_dialog = new AddChatDialog(stream_interactor, stream_interactor.get_accounts());
add_chat_dialog.set_transient_for(window);
add_chat_dialog.added.connect((conversation) => {
window.on_conversation_selected(conversation);
});
add_chat_dialog.present();
});
add_action(contacts_action);
set_accels_for_action("app.add_chat", new string[]{"<Ctrl>T"});
SimpleAction conference_action = new SimpleAction("add_conference", null);
conference_action.activate.connect(() => {
AddConferenceDialog add_conference_dialog = new AddConferenceDialog(stream_interactor);
add_conference_dialog.set_transient_for(window);
add_conference_dialog.conversation_opened.connect(conversation => controller.select_conversation(conversation));
add_conference_dialog.present();
});
add_action(conference_action);
set_accels_for_action("app.add_conference", new string[]{"<Ctrl>G"});
SimpleAction accept_muc_invite_action = new SimpleAction("open-muc-join", VariantType.INT32);
accept_muc_invite_action.activate.connect((variant) => {
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32());
if (conversation == null) return;
show_join_muc_dialog(conversation.account, conversation.counterpart);
});
add_action(accept_muc_invite_action);
SimpleAction loop_conversations_action = new SimpleAction("loop_conversations", null);
loop_conversations_action.activate.connect(() => { window.loop_conversations(false); });
add_action(loop_conversations_action);
set_accels_for_action("app.loop_conversations", new string[]{"<Ctrl>Tab"});
SimpleAction loop_conversations_bw_action = new SimpleAction("loop_conversations_bw", null);
loop_conversations_bw_action.activate.connect(() => { window.loop_conversations(true); });
add_action(loop_conversations_bw_action);
set_accels_for_action("app.loop_conversations_bw", new string[]{"<Ctrl><Shift>Tab"});
}
public bool use_csd() {
return Environment.get_variable("GTK_CSD") != "0";
}
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);
dialog.set_transient_for(get_active_window());
2017-03-11 22:52:12 +00:00
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(get_active_window());
2017-05-30 20:47:16 +00:00
dialog.present();
2017-03-11 22:52:12 +00:00
}
private void show_join_muc_dialog(Account? account, Jid jid) {
2019-10-16 01:25:44 +00:00
Dialog dialog = new Dialog.with_buttons(_("Join Channel"), window, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.USE_HEADER_BAR, _("Join"), ResponseType.OK, _("Cancel"), ResponseType.CANCEL);
dialog.modal = true;
Button ok_button = dialog.get_widget_for_response(ResponseType.OK) as Button;
ok_button.get_style_context().add_class("suggested-action");
ConferenceDetailsFragment conference_fragment = new ConferenceDetailsFragment(stream_interactor) { ok_button=ok_button };
conference_fragment.jid = jid.to_string();
if (account != null) {
conference_fragment.account = account;
}
Box content_area = dialog.get_content_area();
content_area.add(conference_fragment);
conference_fragment.joined.connect(() => {
dialog.destroy();
});
dialog.response.connect((response_id) => {
if (response_id == ResponseType.CANCEL) {
dialog.destroy();
}
});
dialog.present();
}
2017-03-11 22:52:12 +00:00
}