2017-03-17 22:21:23 +00:00
|
|
|
using Gee;
|
2018-07-29 21:24:53 +00:00
|
|
|
using Gdk;
|
2017-03-02 14:37:32 +00:00
|
|
|
using Gtk;
|
|
|
|
|
|
|
|
using Dino.Entities;
|
|
|
|
|
2017-03-10 17:07:28 +00:00
|
|
|
namespace Dino.Ui {
|
|
|
|
|
2023-07-04 01:54:23 +00:00
|
|
|
public class MainWindow : Adw.ApplicationWindow {
|
2017-03-17 22:21:23 +00:00
|
|
|
|
2019-01-27 14:24:58 +00:00
|
|
|
public signal void conversation_selected(Conversation conversation);
|
|
|
|
|
2019-04-12 15:43:47 +00:00
|
|
|
public new string? title { get; set; }
|
|
|
|
public string? subtitle { get; set; }
|
2019-01-27 14:24:58 +00:00
|
|
|
|
2022-02-14 13:55:59 +00:00
|
|
|
public WelcomePlaceholder welcome_placeholder = new WelcomePlaceholder();
|
|
|
|
public NoAccountsPlaceholder accounts_placeholder = new NoAccountsPlaceholder();
|
2020-02-21 01:11:23 +00:00
|
|
|
public ConversationView conversation_view;
|
2019-04-12 15:43:47 +00:00
|
|
|
public ConversationSelector conversation_selector;
|
2019-01-27 14:24:58 +00:00
|
|
|
public ConversationTitlebar conversation_titlebar;
|
2022-02-14 13:55:59 +00:00
|
|
|
public Widget conversation_list_titlebar;
|
|
|
|
public Box box = new Box(Orientation.VERTICAL, 0) { orientation=Orientation.VERTICAL };
|
2022-09-12 14:43:30 +00:00
|
|
|
public Adw.Leaflet leaflet;
|
2022-09-12 14:07:14 +00:00
|
|
|
public Box left_box;
|
|
|
|
public Box right_box;
|
2023-01-24 17:57:04 +00:00
|
|
|
public Adw.Flap search_flap;
|
2022-02-14 13:55:59 +00:00
|
|
|
public GlobalSearch global_search;
|
|
|
|
private Stack stack = new Stack();
|
2019-09-30 00:11:23 +00:00
|
|
|
private Stack left_stack;
|
|
|
|
private Stack right_stack;
|
2017-03-02 14:37:32 +00:00
|
|
|
|
|
|
|
private StreamInteractor stream_interactor;
|
2018-11-16 15:27:31 +00:00
|
|
|
private Database db;
|
2019-11-25 22:23:06 +00:00
|
|
|
private Config config;
|
2017-03-02 14:37:32 +00:00
|
|
|
|
2022-02-14 13:55:59 +00:00
|
|
|
class construct {
|
|
|
|
var shortcut = new Shortcut(new KeyvalTrigger(Key.F, ModifierType.CONTROL_MASK), new CallbackAction((widget, args) => {
|
2023-01-24 17:57:04 +00:00
|
|
|
((MainWindow) widget).search_flap.reveal_flap = true;
|
2022-02-14 13:55:59 +00:00
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
add_shortcut(shortcut);
|
|
|
|
}
|
|
|
|
|
2020-02-21 02:06:27 +00:00
|
|
|
public MainWindow(Application application, StreamInteractor stream_interactor, Database db, Config config) {
|
2017-12-31 19:19:51 +00:00
|
|
|
Object(application : application);
|
2018-11-16 15:27:31 +00:00
|
|
|
this.stream_interactor = stream_interactor;
|
|
|
|
this.db = db;
|
2019-11-25 22:23:06 +00:00
|
|
|
this.config = config;
|
|
|
|
|
2022-02-14 13:55:59 +00:00
|
|
|
this.title = "Dino";
|
2017-12-31 19:19:51 +00:00
|
|
|
|
2022-05-14 12:45:59 +00:00
|
|
|
this.add_css_class("dino-main");
|
2022-02-14 13:55:59 +00:00
|
|
|
|
|
|
|
((Widget)this).realize.connect(restore_window_size);
|
|
|
|
|
2017-03-17 22:21:23 +00:00
|
|
|
setup_unified();
|
2022-09-12 14:07:14 +00:00
|
|
|
setup_headerbar();
|
2017-03-20 21:12:20 +00:00
|
|
|
setup_stack();
|
2018-07-04 21:38:28 +00:00
|
|
|
}
|
|
|
|
|
2017-03-17 22:21:23 +00:00
|
|
|
private void setup_unified() {
|
2018-07-04 21:38:28 +00:00
|
|
|
Builder builder = new Builder.from_resource("/im/dino/Dino/unified_main_content.ui");
|
2022-09-12 14:43:30 +00:00
|
|
|
leaflet = (Adw.Leaflet) builder.get_object("leaflet");
|
|
|
|
box.append(leaflet);
|
2022-09-12 14:07:14 +00:00
|
|
|
left_box = (Box) builder.get_object("left_box");
|
|
|
|
right_box = (Box) builder.get_object("right_box");
|
2019-09-30 00:11:23 +00:00
|
|
|
left_stack = (Stack) builder.get_object("left_stack");
|
|
|
|
right_stack = (Stack) builder.get_object("right_stack");
|
2020-02-21 01:11:23 +00:00
|
|
|
conversation_view = (ConversationView) builder.get_object("conversation_view");
|
2023-01-24 17:57:04 +00:00
|
|
|
search_flap = (Adw.Flap) builder.get_object("search_flap");
|
2022-02-14 13:55:59 +00:00
|
|
|
conversation_selector = ((ConversationSelector) builder.get_object("conversation_list")).init(stream_interactor);
|
2022-09-12 14:43:30 +00:00
|
|
|
conversation_selector.conversation_selected.connect_after(() => leaflet.navigate(Adw.NavigationDirection.FORWARD));
|
2022-02-14 13:55:59 +00:00
|
|
|
|
2023-01-24 17:57:04 +00:00
|
|
|
Adw.Bin search_frame = (Adw.Bin) builder.get_object("search_frame");
|
2022-02-14 13:55:59 +00:00
|
|
|
global_search = new GlobalSearch(stream_interactor);
|
|
|
|
search_frame.set_child(global_search.get_widget());
|
2017-03-17 22:21:23 +00:00
|
|
|
}
|
2017-03-02 14:37:32 +00:00
|
|
|
|
2017-03-17 22:21:23 +00:00
|
|
|
private void setup_headerbar() {
|
2019-01-27 14:24:58 +00:00
|
|
|
if (Util.use_csd()) {
|
2022-02-14 13:55:59 +00:00
|
|
|
conversation_list_titlebar = get_conversation_list_titlebar_csd();
|
|
|
|
conversation_titlebar = new ConversationTitlebarCsd();
|
2022-09-12 14:43:30 +00:00
|
|
|
leaflet.bind_property("folded", conversation_list_titlebar, "show-end-title-buttons", BindingFlags.SYNC_CREATE);
|
|
|
|
leaflet.bind_property("folded", conversation_titlebar.get_widget(), "show-start-title-buttons", BindingFlags.SYNC_CREATE);
|
2019-01-27 14:24:58 +00:00
|
|
|
} else {
|
2022-09-12 14:07:14 +00:00
|
|
|
Label title_label = new Label("Dino");
|
|
|
|
HeaderBar titlebar = new HeaderBar() { title_widget=title_label, show_title_buttons=true };
|
|
|
|
box.prepend(titlebar);
|
|
|
|
|
2022-02-14 13:55:59 +00:00
|
|
|
conversation_list_titlebar = new ConversationListTitlebar();
|
|
|
|
conversation_titlebar = new ConversationTitlebarNoCsd();
|
2017-04-04 17:55:24 +00:00
|
|
|
}
|
2022-09-12 14:07:14 +00:00
|
|
|
left_box.prepend(conversation_list_titlebar);
|
|
|
|
right_box.prepend(conversation_titlebar.get_widget());
|
2022-09-12 14:43:30 +00:00
|
|
|
leaflet.notify["folded"].connect_after(() => conversation_titlebar.back_button_visible = leaflet.folded);
|
|
|
|
conversation_titlebar.back_pressed.connect(() => leaflet.navigate(Adw.NavigationDirection.BACK));
|
2017-03-17 22:21:23 +00:00
|
|
|
}
|
2017-03-02 14:37:32 +00:00
|
|
|
|
2017-03-20 21:12:20 +00:00
|
|
|
private void setup_stack() {
|
2019-01-27 14:24:58 +00:00
|
|
|
stack.add_named(box, "main");
|
2018-11-16 15:27:31 +00:00
|
|
|
stack.add_named(welcome_placeholder, "welcome_placeholder");
|
2017-03-20 21:12:20 +00:00
|
|
|
stack.add_named(accounts_placeholder, "accounts_placeholder");
|
2022-09-12 14:07:14 +00:00
|
|
|
set_content(stack);
|
2017-03-17 22:21:23 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 02:04:15 +00:00
|
|
|
public enum StackState {
|
|
|
|
CLEAN_START,
|
|
|
|
NO_ACTIVE_ACCOUNTS,
|
|
|
|
NO_ACTIVE_CONVERSATIONS,
|
|
|
|
CONVERSATION
|
|
|
|
}
|
|
|
|
|
|
|
|
public void set_stack_state(StackState stack_state) {
|
|
|
|
if (stack_state == StackState.CONVERSATION) {
|
|
|
|
left_stack.set_visible_child_name("content");
|
|
|
|
right_stack.set_visible_child_name("content");
|
|
|
|
|
|
|
|
stack.set_visible_child_name("main");
|
|
|
|
} else if (stack_state == StackState.CLEAN_START || stack_state == StackState.NO_ACTIVE_ACCOUNTS) {
|
|
|
|
if (stack_state == StackState.CLEAN_START) {
|
2018-11-16 15:27:31 +00:00
|
|
|
stack.set_visible_child_name("welcome_placeholder");
|
2020-02-21 02:04:15 +00:00
|
|
|
} else if (stack_state == StackState.NO_ACTIVE_ACCOUNTS) {
|
2018-11-16 15:27:31 +00:00
|
|
|
stack.set_visible_child_name("accounts_placeholder");
|
2019-01-27 14:24:58 +00:00
|
|
|
}
|
2020-02-21 02:04:15 +00:00
|
|
|
} else if (stack_state == StackState.NO_ACTIVE_CONVERSATIONS) {
|
2019-09-30 00:11:23 +00:00
|
|
|
stack.set_visible_child_name("main");
|
|
|
|
left_stack.set_visible_child_name("placeholder");
|
|
|
|
right_stack.set_visible_child_name("placeholder");
|
2017-12-31 19:19:51 +00:00
|
|
|
}
|
2017-03-02 14:37:32 +00:00
|
|
|
}
|
2019-04-12 14:24:43 +00:00
|
|
|
|
|
|
|
public void loop_conversations(bool backwards) {
|
2019-04-12 15:43:47 +00:00
|
|
|
conversation_selector.loop_conversations(backwards);
|
2019-04-12 14:24:43 +00:00
|
|
|
}
|
2019-11-25 22:23:06 +00:00
|
|
|
|
|
|
|
public void restore_window_size() {
|
|
|
|
Gdk.Display? display = Gdk.Display.get_default();
|
|
|
|
if (display != null) {
|
2022-02-14 13:55:59 +00:00
|
|
|
Gdk.Surface? surface = get_surface();
|
|
|
|
Gdk.Monitor? monitor = display.get_monitor_at_surface(surface);
|
2019-11-25 22:23:06 +00:00
|
|
|
|
|
|
|
if (monitor != null &&
|
|
|
|
config.window_width <= monitor.geometry.width &&
|
|
|
|
config.window_height <= monitor.geometry.height) {
|
|
|
|
set_default_size(config.window_width, config.window_height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (config.window_maximize) {
|
|
|
|
maximize();
|
|
|
|
}
|
|
|
|
|
2022-02-14 13:55:59 +00:00
|
|
|
((Widget)this).unrealize.connect(() => {
|
2019-11-25 22:23:06 +00:00
|
|
|
save_window_size();
|
2022-02-14 13:55:59 +00:00
|
|
|
config.window_maximize = this.maximized;
|
2019-11-25 22:23:06 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void save_window_size() {
|
2022-02-14 13:55:59 +00:00
|
|
|
if (this.maximized) return;
|
2019-11-25 22:23:06 +00:00
|
|
|
|
|
|
|
Gdk.Display? display = get_display();
|
2022-02-14 13:55:59 +00:00
|
|
|
Gdk.Surface? surface = get_surface();
|
|
|
|
if (display != null && surface != null) {
|
|
|
|
Gdk.Monitor monitor = display.get_monitor_at_surface(surface);
|
2019-11-25 22:23:06 +00:00
|
|
|
|
|
|
|
// Only store if the values have changed and are reasonable-looking.
|
2022-02-14 13:55:59 +00:00
|
|
|
if (config.window_width != default_width && default_width > 0 && default_width <= monitor.geometry.width) {
|
|
|
|
config.window_width = default_width;
|
2019-11-25 22:23:06 +00:00
|
|
|
}
|
2022-02-14 13:55:59 +00:00
|
|
|
if (config.window_height != default_height && default_height > 0 && default_height <= monitor.geometry.height) {
|
|
|
|
config.window_height = default_height;
|
2019-11-25 22:23:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-02 14:37:32 +00:00
|
|
|
}
|
|
|
|
|
2021-03-09 16:04:43 +00:00
|
|
|
public class WelcomePlaceholder : MainWindowPlaceholder {
|
|
|
|
public WelcomePlaceholder() {
|
2022-12-25 17:04:26 +00:00
|
|
|
status_page.title = _("Welcome to Dino!");
|
|
|
|
status_page.description = _("Sign in or create an account to get started.");
|
2019-01-06 17:31:40 +00:00
|
|
|
primary_button.label = _("Set up account");
|
2022-12-25 17:04:26 +00:00
|
|
|
primary_button.visible = true;
|
2018-11-16 15:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-21 02:06:27 +00:00
|
|
|
public class NoAccountsPlaceholder : MainWindowPlaceholder {
|
2017-03-20 21:12:20 +00:00
|
|
|
public NoAccountsPlaceholder() {
|
2022-12-25 17:04:26 +00:00
|
|
|
status_page.title = _("No active accounts");
|
2017-04-07 09:09:47 +00:00
|
|
|
primary_button.label = _("Manage accounts");
|
2022-12-25 17:04:26 +00:00
|
|
|
primary_button.visible = true;
|
2017-03-20 21:12:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-03 18:42:15 +00:00
|
|
|
[GtkTemplate (ui = "/im/dino/Dino/unified_window_placeholder.ui")]
|
2020-02-21 02:06:27 +00:00
|
|
|
public class MainWindowPlaceholder : Box {
|
2022-12-25 17:04:26 +00:00
|
|
|
[GtkChild] public unowned Adw.StatusPage status_page;
|
2021-10-11 21:08:50 +00:00
|
|
|
[GtkChild] public unowned Button primary_button;
|
|
|
|
[GtkChild] public unowned Button secondary_button;
|
2017-03-17 22:21:23 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:44:15 +00:00
|
|
|
}
|