2018-04-28 18:27:10 +02:00
|
|
|
using Gtk;
|
|
|
|
|
|
|
|
public class Tootle.RichLabel : Gtk.Label {
|
|
|
|
|
|
|
|
public weak Mention[]? mentions;
|
|
|
|
|
2018-05-18 23:14:12 +02:00
|
|
|
public RichLabel (string text) {
|
2018-06-06 16:19:11 +02:00
|
|
|
set_label (text);
|
2018-04-28 18:27:10 +02:00
|
|
|
set_use_markup (true);
|
2018-05-18 23:14:12 +02:00
|
|
|
activate_link.connect (open_link);
|
2018-04-28 18:27:10 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 16:19:11 +02:00
|
|
|
public static string escape_entities (string content) {
|
|
|
|
return content
|
|
|
|
.replace ("&", "&")
|
|
|
|
.replace ("'", "'");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string restore_entities (string content) {
|
|
|
|
return content
|
|
|
|
.replace ("&", "&")
|
|
|
|
.replace ("'", "'");
|
|
|
|
}
|
|
|
|
|
|
|
|
public new void set_label (string text) {
|
|
|
|
base.set_markup (escape_entities (text));
|
|
|
|
}
|
|
|
|
|
2018-05-04 22:57:31 +02:00
|
|
|
public void wrap_words () {
|
|
|
|
halign = Gtk.Align.START;
|
|
|
|
single_line_mode = false;
|
|
|
|
set_line_wrap (true);
|
|
|
|
wrap_mode = Pango.WrapMode.WORD_CHAR;
|
|
|
|
justify = Gtk.Justification.LEFT;
|
|
|
|
xalign = 0;
|
|
|
|
}
|
|
|
|
|
2018-04-28 18:27:10 +02:00
|
|
|
public bool open_link (string url){
|
|
|
|
if (mentions != null){
|
2018-05-04 22:57:31 +02:00
|
|
|
foreach (Mention mention in mentions) {
|
2018-04-28 18:27:10 +02:00
|
|
|
if (url == mention.url){
|
|
|
|
AccountView.open_from_id (mention.id);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 16:43:10 +02:00
|
|
|
if ("/tags/" in url){
|
|
|
|
var encoded = url.split("/tags/")[1];
|
|
|
|
var hashtag = Soup.URI.decode (encoded);
|
2018-06-13 15:13:41 +02:00
|
|
|
|
|
|
|
var msg_url = "%s/api/v1/streaming/?stream=hashtag&access_token=%s&tag=%s"
|
|
|
|
.printf (accounts.formal.instance, accounts.formal.token, encoded);
|
|
|
|
var msg = new Soup.Message("GET", msg_url);
|
|
|
|
|
|
|
|
var timeline = new TimelineView ("tag/" + hashtag);
|
|
|
|
timeline.notificator = new Notificator (msg);
|
|
|
|
timeline.notificator.status_added.connect ((ref status) => {
|
|
|
|
if (settings.live_updates)
|
|
|
|
timeline.on_status_added (ref status);
|
|
|
|
});
|
|
|
|
window.open_view (timeline);
|
|
|
|
|
2018-05-14 16:43:10 +02:00
|
|
|
return true;
|
|
|
|
}
|
2018-04-28 18:27:10 +02:00
|
|
|
|
|
|
|
if ("/@" in url){
|
2018-05-16 11:11:54 +02:00
|
|
|
var uri = new Soup.URI (url);
|
|
|
|
var username = url.split("/@")[1];
|
2018-06-02 10:37:28 +02:00
|
|
|
|
|
|
|
if ("/" in username)
|
|
|
|
StatusView.open_from_link (url);
|
|
|
|
else
|
|
|
|
AccountView.open_from_name ("@" + username + "@" + uri.get_host ());
|
|
|
|
|
2018-04-28 18:27:10 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-07 13:43:55 +02:00
|
|
|
Desktop.open_uri (url);
|
2018-04-28 18:27:10 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|