2017-03-11 22:52:12 +00:00
|
|
|
using Gtk;
|
|
|
|
|
|
|
|
using Dino.Entities;
|
|
|
|
using Dino.Ui;
|
2018-01-12 20:03:09 +00:00
|
|
|
using Xmpp;
|
2017-03-11 22:52:12 +00:00
|
|
|
|
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;
|
2020-02-21 02:06:27 +00:00
|
|
|
private MainWindow window;
|
|
|
|
public MainWindowController controller;
|
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; }
|
2019-11-25 22:23:06 +00:00
|
|
|
private Config config { 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-12-03 18:42:15 +00:00
|
|
|
provider.load_from_resource("/im/dino/Dino/theme.css");
|
2017-09-05 21:53:18 +00:00
|
|
|
StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), provider, STYLE_PROVIDER_PRIORITY_APPLICATION);
|
2017-03-11 22:52:12 +00:00
|
|
|
|
2017-12-14 01:01:55 +00:00
|
|
|
create_actions();
|
|
|
|
|
2019-11-26 17:42:18 +00:00
|
|
|
startup.connect(() => {
|
|
|
|
notifications = new Notifications(stream_interactor);
|
|
|
|
notifications.start();
|
|
|
|
});
|
|
|
|
|
2017-11-16 17:31:20 +00:00
|
|
|
activate.connect(() => {
|
2017-08-17 09:38:41 +00:00
|
|
|
if (window == null) {
|
2020-02-21 02:06:27 +00:00
|
|
|
controller = new MainWindowController(this, stream_interactor, db);
|
2019-11-25 22:23:06 +00:00
|
|
|
config = new Config(db);
|
2020-02-21 02:06:27 +00:00
|
|
|
window = new MainWindow(this, stream_interactor, db, config);
|
2019-01-27 14:24:58 +00:00
|
|
|
controller.set_window(window);
|
2019-10-18 12:10:50 +00:00
|
|
|
if ((get_flags() & ApplicationFlags.IS_SERVICE) == ApplicationFlags.IS_SERVICE) window.delete_event.connect(window.hide_on_delete);
|
2019-01-27 14:24:58 +00:00
|
|
|
|
2019-12-21 18:19:28 +00:00
|
|
|
notifications.conversation_selected.connect((conversation) => controller.select_conversation(conversation));
|
2017-08-17 09:38:41 +00:00
|
|
|
}
|
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":
|
2019-12-22 03:10:53 +00:00
|
|
|
show_join_muc_dialog(null, jid);
|
2017-08-25 19:20:09 +00:00
|
|
|
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();
|
2019-12-22 03:10:53 +00:00
|
|
|
Jid parsed_jid = null;
|
|
|
|
try {
|
|
|
|
parsed_jid = new Jid(jid);
|
|
|
|
} catch (InvalidJidError ignored) {
|
|
|
|
// Ignored
|
|
|
|
}
|
|
|
|
if (accounts.size == 1 && parsed_jid != null) {
|
|
|
|
Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(parsed_jid, accounts[0], Conversation.Type.CHAT);
|
2019-04-18 20:38:16 +00:00
|
|
|
stream_interactor.get_module(ConversationManager.IDENTITY).start_conversation(conversation);
|
2019-12-21 18:19:28 +00:00
|
|
|
controller.select_conversation(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) => {
|
2019-12-21 18:19:28 +00:00
|
|
|
controller.select_conversation(conversation);
|
2017-10-22 01:39:13 +00:00
|
|
|
});
|
|
|
|
dialog.present();
|
|
|
|
}
|
2017-08-17 09:38:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 01:01:55 +00:00
|
|
|
private void create_actions() {
|
2019-01-27 14:24:58 +00:00
|
|
|
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);
|
|
|
|
|
2019-12-17 22:52:05 +00:00
|
|
|
SimpleAction about_action = new SimpleAction("about", null);
|
|
|
|
about_action.activate.connect(show_about_window);
|
|
|
|
add_action(about_action);
|
|
|
|
|
2019-01-27 14:24:58 +00:00
|
|
|
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"});
|
|
|
|
|
2017-12-14 01:01:55 +00:00
|
|
|
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());
|
2019-12-21 18:19:28 +00:00
|
|
|
if (conversation != null) controller.select_conversation(conversation);
|
2017-12-14 01:01:55 +00:00
|
|
|
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);
|
2019-01-27 14:24:58 +00:00
|
|
|
|
|
|
|
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);
|
2019-12-21 18:19:28 +00:00
|
|
|
add_chat_dialog.added.connect((conversation) => controller.select_conversation(conversation));
|
2019-01-27 14:24:58 +00:00
|
|
|
add_chat_dialog.present();
|
|
|
|
});
|
|
|
|
add_action(contacts_action);
|
2019-02-05 19:44:57 +00:00
|
|
|
set_accels_for_action("app.add_chat", new string[]{"<Ctrl>T"});
|
2019-01-27 14:24:58 +00:00
|
|
|
|
|
|
|
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.present();
|
|
|
|
});
|
|
|
|
add_action(conference_action);
|
2019-02-05 19:44:57 +00:00
|
|
|
set_accels_for_action("app.add_conference", new string[]{"<Ctrl>G"});
|
2019-03-21 16:20:35 +00:00
|
|
|
|
2019-08-22 14:05:28 +00:00
|
|
|
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;
|
2019-12-22 03:10:53 +00:00
|
|
|
show_join_muc_dialog(conversation.account, conversation.counterpart.to_string());
|
2019-08-22 14:05:28 +00:00
|
|
|
});
|
|
|
|
add_action(accept_muc_invite_action);
|
|
|
|
|
2020-11-11 10:27:31 +00:00
|
|
|
SimpleAction accept_voice_request_action = new SimpleAction("accept-voice-request", new VariantType.tuple(new VariantType[]{VariantType.INT32, VariantType.STRING}));
|
2020-04-22 18:04:03 +00:00
|
|
|
accept_voice_request_action.activate.connect((variant) => {
|
2020-11-11 10:27:31 +00:00
|
|
|
int conversation_id = variant.get_child_value(0).get_int32();
|
|
|
|
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(conversation_id);
|
2020-04-22 18:04:03 +00:00
|
|
|
if (conversation == null) return;
|
2020-11-11 10:27:31 +00:00
|
|
|
|
|
|
|
string nick = variant.get_child_value(1).get_string();
|
|
|
|
stream_interactor.get_module(MucManager.IDENTITY).change_role(conversation.account, conversation.counterpart, nick, "participant");
|
2020-04-22 18:04:03 +00:00
|
|
|
});
|
|
|
|
add_action(accept_voice_request_action);
|
|
|
|
|
2019-03-21 16:20:35 +00:00
|
|
|
SimpleAction loop_conversations_action = new SimpleAction("loop_conversations", null);
|
2019-04-12 14:24:43 +00:00
|
|
|
loop_conversations_action.activate.connect(() => { window.loop_conversations(false); });
|
2019-03-21 16:20:35 +00:00
|
|
|
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);
|
2019-04-12 14:24:43 +00:00
|
|
|
loop_conversations_bw_action.activate.connect(() => { window.loop_conversations(true); });
|
2019-03-21 16:20:35 +00:00
|
|
|
add_action(loop_conversations_bw_action);
|
|
|
|
set_accels_for_action("app.loop_conversations_bw", new string[]{"<Ctrl><Shift>Tab"});
|
2019-12-17 21:54:08 +00:00
|
|
|
|
|
|
|
SimpleAction open_shortcuts_action = new SimpleAction("open_shortcuts", null);
|
|
|
|
open_shortcuts_action.activate.connect((variant) => {
|
|
|
|
Builder builder = new Builder.from_resource("/im/dino/Dino/shortcuts.ui");
|
|
|
|
var dialog = (ShortcutsWindow) builder.get_object("shortcuts-window");
|
|
|
|
dialog.set_transient_for(get_active_window());
|
|
|
|
dialog.present();
|
|
|
|
});
|
|
|
|
add_action(open_shortcuts_action);
|
2017-12-14 01:01:55 +00:00
|
|
|
}
|
|
|
|
|
2019-02-20 22:08:30 +00:00
|
|
|
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);
|
2017-12-14 01:01:55 +00:00
|
|
|
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();
|
2017-12-14 01:01:55 +00:00
|
|
|
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
|
|
|
}
|
2019-08-22 14:05:28 +00:00
|
|
|
|
2019-12-17 22:52:05 +00:00
|
|
|
private void show_about_window() {
|
2020-09-19 11:27:53 +00:00
|
|
|
string? version = Dino.VERSION.strip().length == 0 ? null : Dino.VERSION;
|
|
|
|
if (version != null && !version.contains("git")) {
|
|
|
|
switch (version.substring(0, 3)) {
|
|
|
|
case "0.2": version = @"$version - <span font_style='italic'>Mexican Caribbean Coral Reefs</span>"; break;
|
|
|
|
}
|
|
|
|
}
|
2019-12-17 22:52:05 +00:00
|
|
|
show_about_dialog(get_active_window(),
|
|
|
|
logo_icon_name: "im.dino.Dino",
|
|
|
|
program_name: "Dino",
|
2020-09-19 11:27:53 +00:00
|
|
|
version: version,
|
2019-12-17 22:52:05 +00:00
|
|
|
comments: "Dino. Communicating happiness.",
|
|
|
|
website: "https://dino.im/",
|
|
|
|
website_label: "dino.im",
|
2020-02-23 15:11:53 +00:00
|
|
|
copyright: "Copyright © 2016-2020 - Dino Team",
|
2019-12-17 22:52:05 +00:00
|
|
|
license_type: License.GPL_3_0);
|
|
|
|
}
|
|
|
|
|
2019-12-22 03:10:53 +00:00
|
|
|
private void show_join_muc_dialog(Account? account, string 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);
|
2019-08-22 14:05:28 +00:00
|
|
|
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 };
|
2019-12-22 03:10:53 +00:00
|
|
|
conference_fragment.jid = jid;
|
2019-08-22 14:05:28 +00:00
|
|
|
if (account != null) {
|
|
|
|
conference_fragment.account = account;
|
|
|
|
}
|
|
|
|
Box content_area = dialog.get_content_area();
|
|
|
|
content_area.add(conference_fragment);
|
2019-11-24 13:02:45 +00:00
|
|
|
conference_fragment.joined.connect(() => {
|
|
|
|
dialog.destroy();
|
|
|
|
});
|
2019-08-22 14:05:28 +00:00
|
|
|
dialog.response.connect((response_id) => {
|
2019-11-24 13:02:45 +00:00
|
|
|
if (response_id == ResponseType.CANCEL) {
|
2019-08-22 14:05:28 +00:00
|
|
|
dialog.destroy();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialog.present();
|
|
|
|
}
|
2017-03-11 22:52:12 +00:00
|
|
|
}
|
|
|
|
|