Add 'gtk/' from commit '7d0dfb455aa86245231b383a92e79b3c08a12d5e'
git-subtree-dir: gtk git-subtree-mainline:c710c6e053git-subtree-split:7d0dfb455a
This commit is contained in:
50
gtk/src/application/kordophone-application.vala
Normal file
50
gtk/src/application/kordophone-application.vala
Normal file
@@ -0,0 +1,50 @@
|
||||
using Adw;
|
||||
using Gtk;
|
||||
|
||||
public class KordophoneApp : Adw.Application
|
||||
{
|
||||
private MainWindow window;
|
||||
|
||||
public KordophoneApp () {
|
||||
Object (application_id: "net.buzzert.kordophone2", flags: ApplicationFlags.FLAGS_NONE);
|
||||
}
|
||||
|
||||
protected override void startup () {
|
||||
base.startup ();
|
||||
|
||||
// Set default icon theme
|
||||
Gtk.Settings.get_default().set_property("gtk-icon-theme-name", "Adwaita");
|
||||
|
||||
// Load CSS from resources
|
||||
var provider = new Gtk.CssProvider ();
|
||||
provider.load_from_resource ("/net/buzzert/kordophone2/style.css");
|
||||
Gtk.StyleContext.add_provider_for_display (
|
||||
Gdk.Display.get_default (),
|
||||
provider,
|
||||
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
|
||||
);
|
||||
|
||||
// Setup application actions
|
||||
var quit_action = new SimpleAction("quit", null);
|
||||
quit_action.activate.connect(() => {
|
||||
this.quit();
|
||||
});
|
||||
add_action(quit_action);
|
||||
|
||||
// Warm up dbus connections
|
||||
Repository.get_instance();
|
||||
}
|
||||
|
||||
protected override void activate () {
|
||||
window = new MainWindow ();
|
||||
window.set_default_size (1200, 1000);
|
||||
window.application = this;
|
||||
|
||||
window.present ();
|
||||
}
|
||||
|
||||
public static int main (string[] args) {
|
||||
var app = new KordophoneApp ();
|
||||
return app.run (args);
|
||||
}
|
||||
}
|
||||
116
gtk/src/application/main-window.vala
Normal file
116
gtk/src/application/main-window.vala
Normal file
@@ -0,0 +1,116 @@
|
||||
using Adw;
|
||||
using Gtk;
|
||||
|
||||
public class MainWindow : Adw.ApplicationWindow
|
||||
{
|
||||
private ConversationListView conversation_list_view;
|
||||
private TranscriptContainerView transcript_container_view;
|
||||
|
||||
private EventControllerMotion _motion_controller = new EventControllerMotion();
|
||||
private bool _motion_queued = false;
|
||||
|
||||
public MainWindow () {
|
||||
Object (title: "Kordophone");
|
||||
|
||||
var split_view = new NavigationSplitView ();
|
||||
split_view.set_min_sidebar_width (400);
|
||||
set_content (split_view);
|
||||
|
||||
conversation_list_view = new ConversationListView ();
|
||||
conversation_list_view.conversation_selected.connect (conversation_selected);
|
||||
conversation_list_view.conversation_activated.connect (open_conversation_in_new_window);
|
||||
|
||||
var conversation_list_page = new NavigationPage (conversation_list_view, "Conversations");
|
||||
split_view.sidebar = conversation_list_page;
|
||||
|
||||
transcript_container_view = new TranscriptContainerView ();
|
||||
var transcript_page = new NavigationPage (transcript_container_view, "Transcript");
|
||||
split_view.content = transcript_page;
|
||||
|
||||
var show_settings_action = new SimpleAction ("settings", null);
|
||||
show_settings_action.activate.connect(show_settings);
|
||||
add_action(show_settings_action);
|
||||
|
||||
_motion_controller.motion.connect((x, y) => {
|
||||
queue_motion();
|
||||
});
|
||||
_motion_controller.set_propagation_phase(PropagationPhase.CAPTURE);
|
||||
split_view.add_controller(_motion_controller);
|
||||
}
|
||||
|
||||
private void queue_motion() {
|
||||
if (_motion_queued) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_active) {
|
||||
return;
|
||||
}
|
||||
|
||||
_motion_queued = true;
|
||||
GLib.Timeout.add(500, () => {
|
||||
_motion_queued = false;
|
||||
on_motion();
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
private void on_motion() {
|
||||
var selected_conversation = transcript_container_view.transcript_view.model?.conversation;
|
||||
if (selected_conversation == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var list_model = conversation_list_view.conversation_model;
|
||||
var conversation_in_list = list_model.get_conversation(selected_conversation.guid);
|
||||
if (conversation_in_list == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (conversation_in_list.unread_count == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
GLib.message("Marking conversation as read on motion: %s", selected_conversation.guid);
|
||||
Repository.get_instance().mark_conversation_as_read(selected_conversation.guid);
|
||||
} catch (Error e) {
|
||||
GLib.warning("Failed to mark conversation as read: %s", e.message);
|
||||
}
|
||||
}
|
||||
|
||||
private void show_settings () {
|
||||
var dialog = new PreferencesWindow (this);
|
||||
dialog.present (this);
|
||||
}
|
||||
|
||||
private void conversation_selected(Conversation conversation) {
|
||||
TranscriptView transcript_view = transcript_container_view.transcript_view;
|
||||
if (conversation == null) {
|
||||
transcript_view.model = null;
|
||||
} else {
|
||||
if (transcript_view.model == null || transcript_view.model.conversation.guid != conversation.guid) {
|
||||
transcript_view.model = new MessageListModel (conversation);
|
||||
transcript_view.title = conversation.display_name;
|
||||
|
||||
try {
|
||||
Repository.get_instance().mark_conversation_as_read(conversation.guid);
|
||||
Repository.get_instance().sync_conversation(conversation.guid);
|
||||
} catch (Error e) {
|
||||
GLib.warning("Failed to sync conversation: %s", e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void open_conversation_in_new_window(Conversation conversation) {
|
||||
var view = new TranscriptContainerView();
|
||||
view.transcript_view.model = new MessageListModel (conversation);
|
||||
view.transcript_view.title = conversation.display_name;
|
||||
|
||||
var window = new Adw.Window();
|
||||
window.set_default_size(750, 990);
|
||||
window.set_content(view);
|
||||
window.present();
|
||||
}
|
||||
}
|
||||
69
gtk/src/application/preferences-window.vala
Normal file
69
gtk/src/application/preferences-window.vala
Normal file
@@ -0,0 +1,69 @@
|
||||
using Adw;
|
||||
using Gtk;
|
||||
|
||||
public class PreferencesWindow : Adw.PreferencesDialog {
|
||||
private Adw.EntryRow server_url_row;
|
||||
private Adw.EntryRow username_row;
|
||||
private Adw.PasswordEntryRow password_row;
|
||||
private Settings settings;
|
||||
|
||||
public PreferencesWindow (Gtk.Window parent) {
|
||||
Object (
|
||||
title: "Settings"
|
||||
);
|
||||
|
||||
add_css_class ("settings-dialog");
|
||||
|
||||
var page = new PreferencesPage ();
|
||||
page.margin_top = 14;
|
||||
page.margin_bottom = 14;
|
||||
page.margin_start = 50;
|
||||
page.margin_end = 50;
|
||||
add (page);
|
||||
|
||||
var connection_group = new PreferencesGroup ();
|
||||
connection_group.title = "Connection Settings";
|
||||
page.add (connection_group);
|
||||
|
||||
server_url_row = new Adw.EntryRow ();
|
||||
server_url_row.title = "Server URL";
|
||||
connection_group.add (server_url_row);
|
||||
|
||||
username_row = new Adw.EntryRow ();
|
||||
username_row.title = "Username";
|
||||
connection_group.add (username_row);
|
||||
|
||||
password_row = new Adw.PasswordEntryRow ();
|
||||
password_row.title = "Password";
|
||||
connection_group.add (password_row);
|
||||
|
||||
settings = new Settings();
|
||||
settings.settings_ready.connect(load_settings);
|
||||
load_settings();
|
||||
|
||||
unowned var self = this;
|
||||
closed.connect(() => {
|
||||
self.save_settings();
|
||||
});
|
||||
}
|
||||
|
||||
private void load_settings() {
|
||||
try {
|
||||
username_row.text = settings.get_username();
|
||||
server_url_row.text = settings.get_server_url();
|
||||
password_row.text = settings.get_password();
|
||||
} catch (Error e) {
|
||||
warning("Failed to load settings: %s", e.message);
|
||||
}
|
||||
}
|
||||
|
||||
private void save_settings() {
|
||||
try {
|
||||
settings.set_server_url(server_url_row.text);
|
||||
settings.set_username(username_row.text);
|
||||
settings.set_password(password_row.text);
|
||||
} catch (Error e) {
|
||||
warning("Failed to save settings: %s", e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user