Private
Public Access
1
0

Add 'gtk/' from commit '7d0dfb455aa86245231b383a92e79b3c08a12d5e'

git-subtree-dir: gtk
git-subtree-mainline: c710c6e053
git-subtree-split: 7d0dfb455a
This commit is contained in:
2025-09-06 19:34:30 -07:00
39 changed files with 3599 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
public class AttributionInfo : Object {
// Picture width
public int64 width;
// Picture height
public int64 height;
public static AttributionInfo from_variant(Variant variant) {
var attribution_info = new AttributionInfo();
VariantDict dict = new VariantDict(variant);
attribution_info.width = dict.lookup_value("width", VariantType.INT32)?.get_int32() ?? 0;
attribution_info.height = dict.lookup_value("height", VariantType.INT32)?.get_int32() ?? 0;
return attribution_info;
}
}
public class AttachmentMetadata : Object {
public AttributionInfo? attribution_info = null;
public static AttachmentMetadata from_variant(Variant variant) {
var metadata = new AttachmentMetadata();
VariantDict dict = new VariantDict(variant);
metadata.attribution_info = AttributionInfo.from_variant(dict.lookup_value("attribution_info", VariantType.DICTIONARY));
return metadata;
}
}
public class AttachmentInfo : Object {
public string? path;
public string? preview_path;
public bool? downloaded;
public bool? preview_downloaded;
public AttachmentInfo(string? path, string? preview_path, bool? downloaded, bool? preview_downloaded) {
this.path = path;
this.preview_path = preview_path;
this.downloaded = downloaded;
this.preview_downloaded = preview_downloaded;
}
}
public class Attachment : Object {
public string guid;
public string path;
public string preview_path;
public bool downloaded;
public bool preview_downloaded;
public AttachmentMetadata? metadata;
public Attachment(string guid, AttachmentMetadata? metadata) {
this.guid = guid;
this.metadata = metadata;
}
public Attachment.from_variant(Variant variant) {
VariantIter iter;
variant.get("a{sv}", out iter);
string key;
Variant val;
while (iter.next("{sv}", out key, out val)) {
switch (key) {
case "guid":
this.guid = val.get_string();
break;
case "path":
this.path = val.get_string();
break;
case "preview_path":
this.preview_path = val.get_string();
break;
case "downloaded":
this.downloaded = val.get_boolean();
break;
case "preview_downloaded":
this.preview_downloaded = val.get_boolean();
break;
case "metadata":
this.metadata = AttachmentMetadata.from_variant(val);
break;
}
}
}
}

View File

@@ -0,0 +1,72 @@
using GLib;
public class Conversation : Object {
public string guid { get; set; default = ""; }
public string last_message_preview { get; set; default = ""; }
public int64 date { get; set; default = 0; }
public string[] participants { get; set; default = new string[0]; }
public int unread_count { get; set; default = 0; }
public bool is_unread { get { return unread_count > 0; } }
public string display_name {
owned get {
if (_display_name != null && _display_name.length > 0) {
return _display_name;
}
if (participants.length == 1) {
return participants[0];
}
if (participants.length > 1) {
return string.joinv(", ", participants);
}
return "Untitled";
}
}
private string? _display_name = null;
public Conversation.from_hash_table(HashTable<string, Variant> conversation_data) {
guid = conversation_data["guid"].get_string();
if (conversation_data.contains("last_message_preview")) {
last_message_preview = conversation_data["last_message_preview"].get_string();
}
if (conversation_data.contains("participants")) {
participants = conversation_data["participants"].dup_strv();
}
if (conversation_data.contains("unread_count")) {
unread_count = conversation_data["unread_count"].get_int32();
}
if (conversation_data.contains("date")) {
date = conversation_data["date"].get_int64();
}
if (conversation_data.contains("display_name")) {
_display_name = conversation_data["display_name"].get_string();
}
}
public bool equals(Conversation other) {
if (other == null) return false;
if (guid != other.guid) return false;
if (date != other.date) return false;
if (unread_count != other.unread_count) return false;
if (last_message_preview != other.last_message_preview) return false;
if (_display_name != other._display_name) return false;
// Compare participants arrays
if (participants.length != other.participants.length) return false;
for (int i = 0; i < participants.length; i++) {
if (participants[i] != other.participants[i]) return false;
}
return true;
}
}

View File

@@ -0,0 +1,90 @@
using GLib;
using Gee;
public class Message : Object, Comparable<Message>, Hashable<Message>
{
public string guid { get; set; default = ""; }
public string text { get; set; default = ""; }
public DateTime date { get; set; default = new DateTime.now_local(); }
public string sender { get; set; default = null; }
public Attachment[] attachments { get; set; default = {}; }
public bool should_animate = false;
public bool from_me {
get {
// Hm, this may have been accidental.
return sender == "(Me)";
}
}
public bool is_attachment_marker {
get {
uint8[] attachment_marker_str = { 0xEF, 0xBF, 0xBC, 0x00 };
if (text.length > attachment_marker_str.length) {
return false;
}
return (string)attachment_marker_str == text;
}
}
public string markup {
owned get {
const string link_regex_pattern = "https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)";
try {
var regex = new GLib.Regex(link_regex_pattern);
var escaped_text = GLib.Markup.escape_text(this.text);
return regex.replace(escaped_text, escaped_text.length, 0, "<u>\\0</u>");
} catch (GLib.RegexError e) {
GLib.warning("Error linking text: %s", e.message);
return GLib.Markup.escape_text(this.text);
}
}
}
public Message(string text, DateTime date, string? sender) {
this.text = text;
this.date = date;
this.sender = sender;
}
public Message.from_hash_table(HashTable<string, Variant> message_data) {
guid = message_data["id"].get_string();
text = message_data["text"].get_string();
sender = message_data["sender"].get_string();
date = new DateTime.from_unix_utc(message_data["date"].get_int64());
// Attachments
var attachments_variant = message_data["attachments"];
var attachments = new Gee.ArrayList<Attachment>();
if (attachments_variant != null) {
for (int i = 0; i < attachments_variant.n_children(); i++) {
var attachment_variant = attachments_variant.get_child_value(i);
var attachment = new Attachment.from_variant(attachment_variant);
attachments.add(attachment);
}
}
this.attachments = attachments.to_array();
}
public int compare_to(Message other) {
if (guid == other.guid) {
return 0;
}
return 1;
}
public bool equal_to(Message other) {
return guid == other.guid;
}
public uint hash() {
return guid.hash();
}
}