aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/util
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/ui/util')
-rw-r--r--main/src/ui/util/data_forms.vala57
-rw-r--r--main/src/ui/util/helper.vala71
2 files changed, 123 insertions, 5 deletions
diff --git a/main/src/ui/util/data_forms.vala b/main/src/ui/util/data_forms.vala
new file mode 100644
index 00000000..11308462
--- /dev/null
+++ b/main/src/ui/util/data_forms.vala
@@ -0,0 +1,57 @@
+using Gee;
+using Gtk;
+
+using Dino.Entities;
+using Xmpp.Xep;
+
+namespace Dino.Ui.Util {
+
+public static Widget? get_data_form_fild_widget(DataForms.DataForm.Field field) {
+ if (field.type_ == null) return null;
+ switch (field.type_) {
+ case DataForms.DataForm.Type.BOOLEAN:
+ DataForms.DataForm.BooleanField boolean_field = field as DataForms.DataForm.BooleanField;
+ Switch sw = new Switch() { active=boolean_field.value, valign=Align.CENTER, visible=true };
+ sw.state_set.connect((state) => {
+ boolean_field.value = state;
+ return false;
+ });
+ return sw;
+ case DataForms.DataForm.Type.JID_MULTI:
+ return null;
+ case DataForms.DataForm.Type.LIST_SINGLE:
+ DataForms.DataForm.ListSingleField list_single_field = field as DataForms.DataForm.ListSingleField;
+ ComboBoxText combobox = new ComboBoxText() { valign=Align.CENTER, visible=true };
+ for (int i = 0; i < list_single_field.options.size; i++) {
+ DataForms.DataForm.Option option = list_single_field.options[i];
+ combobox.append(option.value, option.label);
+ if (option.value == list_single_field.value) combobox.active = i;
+ }
+ combobox.changed.connect(() => {
+ list_single_field.value = combobox.get_active_id();
+ });
+ return combobox;
+ case DataForms.DataForm.Type.LIST_MULTI:
+ return null;
+ case DataForms.DataForm.Type.TEXT_PRIVATE:
+ DataForms.DataForm.TextPrivateField text_private_field = field as DataForms.DataForm.TextPrivateField;
+ Entry entry = new Entry() { text=text_private_field.value ?? "", valign=Align.CENTER, visible=true, visibility=false };
+ entry.key_release_event.connect(() => {
+ text_private_field.value = entry.text;
+ return false;
+ });
+ return entry;
+ case DataForms.DataForm.Type.TEXT_SINGLE:
+ DataForms.DataForm.TextSingleField text_single_field = field as DataForms.DataForm.TextSingleField;
+ Entry entry = new Entry() { text=text_single_field.value ?? "", valign=Align.CENTER, visible=true };
+ entry.key_release_event.connect(() => {
+ text_single_field.value = entry.text;
+ return false;
+ });
+ return entry;
+ default:
+ return null;
+ }
+}
+
+}
diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala
index 3cadfffb..e51b8344 100644
--- a/main/src/ui/util/helper.vala
+++ b/main/src/ui/util/helper.vala
@@ -59,7 +59,13 @@ public static string get_conversation_display_name(StreamInteractor stream_inter
}
public static string get_display_name(StreamInteractor stream_interactor, Jid jid, Account account) {
- if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) {
+ if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat(jid, account)) {
+ string room_name = stream_interactor.get_module(MucManager.IDENTITY).get_room_name(account, jid);
+ if (room_name != null && room_name != jid.localpart) {
+ return room_name;
+ }
+ return jid.bare_jid.to_string();
+ } else if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) {
return jid.resourcepart;
} else {
if (jid.equals_bare(account.bare_jid)) {
@@ -118,10 +124,6 @@ public static void force_background(Gtk.Widget widget, string color, string sele
force_css(widget, force_background_css.printf(selector, color));
}
-public static void force_base_background(Gtk.Widget widget, string selector = "*") {
- force_background(widget, "@theme_base_color", selector);
-}
-
public static void force_color(Gtk.Widget widget, string color, string selector = "*") {
force_css(widget, force_color_css.printf(selector, color));
}
@@ -142,4 +144,63 @@ public static bool is_24h_format() {
return settings_format == "24h" || p_format == " ";
}
+public static string parse_add_markup(string s_, string? highlight_word, bool parse_links, bool parse_text_markup, bool already_escaped_ = false) {
+ string s = s_;
+ bool already_escaped = already_escaped_;
+
+ if (parse_links) {
+ Regex url_regex = new Regex("""(?i)\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))""");
+ MatchInfo match_info;
+ url_regex.match(s.down(), 0, out match_info);
+ if (match_info.matches()) {
+ int start, end;
+ match_info.fetch_pos(0, out start, out end);
+ string link = s[start:end];
+ return parse_add_markup(s[0:start], highlight_word, parse_links, parse_text_markup, already_escaped) +
+ "<a href=\"" + Markup.escape_text(link) + "\">" + parse_add_markup(link, highlight_word, false, false, already_escaped) + "</a>" +
+ parse_add_markup(s[end:s.length], highlight_word, parse_links, parse_text_markup, already_escaped);
+ }
+ }
+
+ if (!already_escaped) {
+ s = Markup.escape_text(s);
+ already_escaped = true;
+ }
+
+ if (highlight_word != null) {
+ Regex highlight_regex = new Regex("\\b" + Regex.escape_string(highlight_word.down()) + "\\b");
+ MatchInfo match_info;
+ highlight_regex.match(s.down(), 0, out match_info);
+ if (match_info.matches()) {
+ int start, end;
+ match_info.fetch_pos(0, out start, out end);
+ return parse_add_markup(s[0:start], highlight_word, parse_links, parse_text_markup, already_escaped) +
+ "<b>" + s[start:end] + "</b>" +
+ parse_add_markup(s[end:s.length], highlight_word, parse_links, parse_text_markup, already_escaped);
+ }
+ }
+
+ if (parse_text_markup) {
+ string[] markup_string = new string[]{"`", "_", "*"};
+ string[] convenience_tag = new string[]{"tt", "i", "b"};
+
+ for (int i = 0; i < markup_string.length; i++) {
+ Regex regex = new Regex(Regex.escape_string(markup_string[i]) + ".+" + Regex.escape_string(markup_string[i]));
+ MatchInfo match_info;
+ regex.match(s.down(), 0, out match_info);
+ if (match_info.matches()) {
+ int start, end;
+ match_info.fetch_pos(0, out start, out end);
+ start += markup_string[i].length;
+ end -= markup_string[i].length;
+ return parse_add_markup(s[0:start], highlight_word, parse_links, parse_text_markup, already_escaped) +
+ @"<$(convenience_tag[i])>" + s[start:end] + @"</$(convenience_tag[i])>" +
+ parse_add_markup(s[end:s.length], highlight_word, parse_links, parse_text_markup, already_escaped);
+ }
+ }
+ }
+
+ return s;
+}
+
}