2025-04-28 17:29:32 -07:00
|
|
|
using Adw;
|
|
|
|
|
using Gtk;
|
|
|
|
|
|
|
|
|
|
public class MainWindow : Adw.ApplicationWindow
|
|
|
|
|
{
|
2025-04-30 19:50:36 -07:00
|
|
|
private ConversationListView conversation_list_view;
|
2025-05-03 22:47:56 -07:00
|
|
|
private TranscriptContainerView transcript_container_view;
|
2025-04-30 19:50:36 -07:00
|
|
|
|
2025-04-28 17:29:32 -07:00
|
|
|
public MainWindow () {
|
|
|
|
|
Object (title: "Kordophone");
|
|
|
|
|
|
|
|
|
|
var split_view = new NavigationSplitView ();
|
|
|
|
|
split_view.set_min_sidebar_width (400);
|
|
|
|
|
set_content (split_view);
|
|
|
|
|
|
2025-04-30 19:50:36 -07:00
|
|
|
conversation_list_view = new ConversationListView ();
|
|
|
|
|
conversation_list_view.conversation_selected.connect (conversation_selected);
|
|
|
|
|
|
|
|
|
|
var conversation_list_page = new NavigationPage (conversation_list_view, "Conversations");
|
2025-04-28 17:29:32 -07:00
|
|
|
split_view.sidebar = conversation_list_page;
|
2025-04-30 15:58:47 -07:00
|
|
|
|
2025-05-03 22:47:56 -07:00
|
|
|
transcript_container_view = new TranscriptContainerView ();
|
|
|
|
|
transcript_container_view.on_send.connect (on_transcript_send);
|
2025-05-02 15:09:12 -07:00
|
|
|
|
2025-05-03 22:47:56 -07:00
|
|
|
var transcript_page = new NavigationPage (transcript_container_view, "Transcript");
|
2025-05-02 15:09:12 -07:00
|
|
|
split_view.content = transcript_page;
|
2025-05-03 01:11:26 -07:00
|
|
|
|
|
|
|
|
var show_settings_action = new SimpleAction ("settings", null);
|
|
|
|
|
show_settings_action.activate.connect(show_settings);
|
|
|
|
|
add_action(show_settings_action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void show_settings () {
|
|
|
|
|
var dialog = new PreferencesWindow (this);
|
|
|
|
|
dialog.present (this);
|
2025-04-28 17:29:32 -07:00
|
|
|
}
|
2025-04-30 19:50:36 -07:00
|
|
|
|
2025-05-03 23:26:53 -07:00
|
|
|
private void conversation_selected(Conversation conversation) {
|
|
|
|
|
TranscriptView transcript_view = transcript_container_view.transcript_view;
|
|
|
|
|
if (conversation == null) {
|
|
|
|
|
transcript_view.model = null;
|
2025-04-30 19:50:36 -07:00
|
|
|
} else {
|
2025-05-03 23:26:53 -07:00
|
|
|
if (transcript_view.model == null || transcript_view.model.conversation_guid != conversation.guid) {
|
|
|
|
|
transcript_view.model = new MessageListModel (conversation.guid);
|
|
|
|
|
transcript_view.title = conversation.display_name;
|
2025-05-03 22:47:56 -07:00
|
|
|
|
|
|
|
|
try {
|
2025-06-18 15:00:54 -07:00
|
|
|
Repository.get_instance().mark_conversation_as_read(conversation.guid);
|
2025-05-03 23:26:53 -07:00
|
|
|
Repository.get_instance().sync_conversation(conversation.guid);
|
2025-05-03 22:47:56 -07:00
|
|
|
} catch (Error e) {
|
|
|
|
|
GLib.warning("Failed to sync conversation: %s", e.message);
|
|
|
|
|
}
|
2025-05-03 21:45:17 -07:00
|
|
|
}
|
2025-05-02 15:09:12 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-12 19:26:49 -07:00
|
|
|
private void on_transcript_send(TranscriptContainerView view) {
|
|
|
|
|
var body = view.message_body;
|
|
|
|
|
var attachment_guids = view.attachment_guids;
|
|
|
|
|
|
2025-06-13 17:14:23 -07:00
|
|
|
// Strip empty space at the beginning and end of the body
|
|
|
|
|
body = body.strip();
|
|
|
|
|
|
2025-05-03 22:47:56 -07:00
|
|
|
if (transcript_container_view.transcript_view.model == null) {
|
2025-05-02 15:09:12 -07:00
|
|
|
GLib.warning("No conversation selected");
|
|
|
|
|
return;
|
2025-04-30 19:50:36 -07:00
|
|
|
}
|
2025-05-02 15:09:12 -07:00
|
|
|
|
2025-05-03 22:47:56 -07:00
|
|
|
var selected_conversation = transcript_container_view.transcript_view.model.conversation_guid;
|
2025-05-02 15:09:12 -07:00
|
|
|
if (selected_conversation == null) {
|
|
|
|
|
GLib.warning("No conversation selected");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-03 22:47:56 -07:00
|
|
|
try {
|
2025-06-12 19:46:53 -07:00
|
|
|
Repository.get_instance().send_message(selected_conversation, body, attachment_guids.to_array());
|
2025-05-03 22:47:56 -07:00
|
|
|
} catch (Error e) {
|
|
|
|
|
GLib.warning("Failed to send message: %s", e.message);
|
|
|
|
|
}
|
2025-04-30 19:50:36 -07:00
|
|
|
}
|
2025-06-17 20:52:21 -07:00
|
|
|
}
|