aboutsummaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-rw-r--r--main/src/ui/avatar_generator.vala9
-rw-r--r--main/src/ui/avatar_image.vala9
-rw-r--r--main/src/ui/conversation_selector/conversation_selector_row.vala6
-rw-r--r--main/src/ui/global_search.vala44
-rw-r--r--main/src/ui/notifications.vala6
-rw-r--r--main/src/ui/unified_window_controller.vala12
-rw-r--r--main/src/ui/util/helper.vala44
7 files changed, 79 insertions, 51 deletions
diff --git a/main/src/ui/avatar_generator.vala b/main/src/ui/avatar_generator.vala
index 012dabe4..2a6aa397 100644
--- a/main/src/ui/avatar_generator.vala
+++ b/main/src/ui/avatar_generator.vala
@@ -5,6 +5,7 @@ using Gtk;
using Dino.Entities;
using Xmpp;
+using Xmpp.Util;
namespace Dino.Ui {
@@ -259,10 +260,10 @@ public class AvatarGenerator {
}
private static void set_source_hex_color(Context ctx, string hex_color) {
- ctx.set_source_rgba((double) hex_color.substring(0, 2).to_long(null, 16) / 255,
- (double) hex_color.substring(2, 2).to_long(null, 16) / 255,
- (double) hex_color.substring(4, 2).to_long(null, 16) / 255,
- hex_color.length > 6 ? (double) hex_color.substring(6, 2).to_long(null, 16) / 255 : 1);
+ ctx.set_source_rgba((double) from_hex(hex_color.substring(0, 2)) / 255,
+ (double) from_hex(hex_color.substring(2, 2)) / 255,
+ (double) from_hex(hex_color.substring(4, 2)) / 255,
+ hex_color.length > 6 ? (double) from_hex(hex_color.substring(6, 2)) / 255 : 1);
}
}
diff --git a/main/src/ui/avatar_image.vala b/main/src/ui/avatar_image.vala
index d98e5baa..cc700f00 100644
--- a/main/src/ui/avatar_image.vala
+++ b/main/src/ui/avatar_image.vala
@@ -1,6 +1,7 @@
using Gtk;
using Dino.Entities;
using Xmpp;
+using Xmpp.Util;
namespace Dino.Ui {
@@ -74,10 +75,10 @@ public class AvatarImage : Misc {
}
private static void set_source_hex_color(Cairo.Context ctx, string hex_color) {
- ctx.set_source_rgba((double) hex_color.substring(0, 2).to_long(null, 16) / 255,
- (double) hex_color.substring(2, 2).to_long(null, 16) / 255,
- (double) hex_color.substring(4, 2).to_long(null, 16) / 255,
- hex_color.length > 6 ? (double) hex_color.substring(6, 2).to_long(null, 16) / 255 : 1);
+ ctx.set_source_rgba((double) from_hex(hex_color.substring(0, 2)) / 255,
+ (double) from_hex(hex_color.substring(2, 2)) / 255,
+ (double) from_hex(hex_color.substring(4, 2)) / 255,
+ hex_color.length > 6 ? (double) from_hex(hex_color.substring(6, 2)) / 255 : 1);
}
public override bool draw(Cairo.Context ctx_in) {
diff --git a/main/src/ui/conversation_selector/conversation_selector_row.vala b/main/src/ui/conversation_selector/conversation_selector_row.vala
index 37b8ebde..46f6c1a8 100644
--- a/main/src/ui/conversation_selector/conversation_selector_row.vala
+++ b/main/src/ui/conversation_selector/conversation_selector_row.vala
@@ -136,7 +136,11 @@ public class ConversationSelectorRow : ListBoxRow {
nick_label.label = last_message.direction == Message.DIRECTION_SENT ? _("Me") + ": " : "";
}
- message_label.label = Markup.escape_text((/\s+/).replace_literal(last_message.body, -1, 0, " "));
+ try {
+ message_label.label = Markup.escape_text((/\s+/).replace_literal(last_message.body, -1, 0, " "));
+ } catch (RegexError e) {
+ assert_not_reached();
+ }
break;
case FileItem.TYPE:
FileItem file_item = last_content_item as FileItem;
diff --git a/main/src/ui/global_search.vala b/main/src/ui/global_search.vala
index 73a61dc5..db7dbc0f 100644
--- a/main/src/ui/global_search.vala
+++ b/main/src/ui/global_search.vala
@@ -206,27 +206,31 @@ public class GlobalSearch : Overlay {
// Color the keywords
int elongated_by = 0;
- Regex highlight_regex = new Regex(regex_str);
- MatchInfo match_info;
- string markup_text_bak = markup_text.down();
- highlight_regex.match(markup_text_bak, 0, out match_info);
- for (; match_info.matches(); match_info.next()) {
- int start, end;
- match_info.fetch_pos(0, out start, out end);
- markup_text = markup_text[0:start+elongated_by] + "<span bgcolor=\"yellow\">" + markup_text[start+elongated_by:end+elongated_by] + "</span>" + markup_text[end+elongated_by:markup_text.length];
- elongated_by += "<span bgcolor=\"yellow\">".length + "</span>".length;
+ try {
+ Regex highlight_regex = new Regex(regex_str);
+ MatchInfo match_info;
+ string markup_text_bak = markup_text.down();
+ highlight_regex.match(markup_text_bak, 0, out match_info);
+ for (; match_info.matches(); match_info.next()) {
+ int start, end;
+ match_info.fetch_pos(0, out start, out end);
+ markup_text = markup_text[0:start+elongated_by] + "<span bgcolor=\"yellow\">" + markup_text[start+elongated_by:end+elongated_by] + "</span>" + markup_text[end+elongated_by:markup_text.length];
+ elongated_by += "<span bgcolor=\"yellow\">".length + "</span>".length;
+ }
+ markup_text_bak += ""; // We need markup_text_bak to live until here because url_regex.match does not copy the string
+
+ label.label = markup_text;
+ grid.attach(label, 1, 1, 1, 1);
+
+ Button button = new Button() { relief=ReliefStyle.NONE, visible=true };
+ button.clicked.connect(() => {
+ selected_item(item);
+ });
+ button.add(grid);
+ return button;
+ } catch (RegexError e) {
+ assert_not_reached();
}
- markup_text_bak += ""; // We need markup_text_bak to live until here because url_regex.match does not copy the string
-
- label.label = markup_text;
- grid.attach(label, 1, 1, 1, 1);
-
- Button button = new Button() { relief=ReliefStyle.NONE, visible=true };
- button.clicked.connect(() => {
- selected_item(item);
- });
- button.add(grid);
- return button;
}
private Grid get_context_message_widget(MessageItem item) {
diff --git a/main/src/ui/notifications.vala b/main/src/ui/notifications.vala
index b8792bee..e495e629 100644
--- a/main/src/ui/notifications.vala
+++ b/main/src/ui/notifications.vala
@@ -125,8 +125,10 @@ public class Notifications : Object {
string body = _("%s invited you to %s").printf(display_name, display_room);
notification.set_body(body);
- Cairo.ImageSurface jid_avatar = yield (new AvatarGenerator(40, 40)).draw_jid(stream_interactor, from_jid, account);
- notification.set_icon(get_pixbuf_icon(jid_avatar));
+ try {
+ Cairo.ImageSurface jid_avatar = yield (new AvatarGenerator(40, 40)).draw_jid(stream_interactor, from_jid, account);
+ notification.set_icon(get_pixbuf_icon(jid_avatar));
+ } catch (Error e) { }
Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(room_jid, account, Conversation.Type.GROUPCHAT);
notification.set_default_action_and_target_value("app.open-muc-join", new Variant.int32(conversation.id));
diff --git a/main/src/ui/unified_window_controller.vala b/main/src/ui/unified_window_controller.vala
index 1ca3daae..21725574 100644
--- a/main/src/ui/unified_window_controller.vala
+++ b/main/src/ui/unified_window_controller.vala
@@ -153,11 +153,19 @@ public class UnifiedWindowController : Object {
private void update_conversation_topic(string? subtitle = null) {
if (subtitle != null) {
- conversation_topic = (/\s+/).replace_literal(subtitle, -1, 0, " ");
+ try {
+ conversation_topic = (/\s+/).replace_literal(subtitle, -1, 0, " ");
+ } catch (RegexError e) {
+ assert_not_reached();
+ }
} else if (conversation.type_ == Conversation.Type.GROUPCHAT) {
string? subject = stream_interactor.get_module(MucManager.IDENTITY).get_groupchat_subject(conversation.counterpart, conversation.account);
if (subject != null) {
- conversation_topic = (/\s+/).replace_literal(subject, -1, 0, " ");
+ try {
+ conversation_topic = (/\s+/).replace_literal(subject, -1, 0, " ");
+ } catch (RegexError e) {
+ assert_not_reached();
+ }
} else {
conversation_topic = null;
}
diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala
index 449936fc..c3353fb6 100644
--- a/main/src/ui/util/helper.vala
+++ b/main/src/ui/util/helper.vala
@@ -188,15 +188,19 @@ public static string parse_add_markup(string s_, string? highlight_word, bool pa
}
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);
+ try {
+ 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);
+ }
+ } catch (RegexError e) {
+ assert_not_reached();
}
}
@@ -206,15 +210,19 @@ public static string parse_add_markup(string s_, string? highlight_word, bool pa
for (int i = 0; i < markup_string.length; i++) {
string markup_esc = Regex.escape_string(markup_string[i]);
- Regex regex = new Regex("(^|\\s)" + markup_esc + "(\\S.*?\\S|\\S)" + markup_esc + "($|\\s)");
- MatchInfo match_info;
- regex.match(s.down(), 0, out match_info);
- if (match_info.matches()) {
- int start, end;
- match_info.fetch_pos(2, out start, out end);
- 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);
+ try {
+ Regex regex = new Regex("(^|\\s)" + markup_esc + "(\\S.*?\\S|\\S)" + markup_esc + "($|\\s)");
+ MatchInfo match_info;
+ regex.match(s.down(), 0, out match_info);
+ if (match_info.matches()) {
+ int start, end;
+ match_info.fetch_pos(2, out start, out end);
+ 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);
+ }
+ } catch (RegexError e) {
+ assert_not_reached();
}
}
}