-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(PreviewCard): BookWyrm support (#255)
- Loading branch information
Showing
12 changed files
with
257 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -317,3 +317,6 @@ GtkSourceAssistant.completion list row{ | |
border-radius: 6px 6px 0px 0px; | ||
} | ||
|
||
.bkwm-desc { | ||
padding: 12px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
public class Tuba.API.BookWyrm : Entity, Widgetizable { | ||
public string id { get; set; default=""; } | ||
public string openlibraryKey { get; set; default=""; } | ||
public string title { get; set; default=""; } | ||
public string description { get; set; default=""; } | ||
public string isbn13 { get; set; default=""; } | ||
public string publishedDate { get; set; default=""; } | ||
public API.BookWyrmCover? cover { get; set; default=null; } | ||
public Gee.ArrayList<string>? authors { get; set; default=null; } | ||
|
||
public static BookWyrm from (Json.Node node) throws Error { | ||
return Entity.from_json (typeof (API.BookWyrm), node) as API.BookWyrm; | ||
} | ||
|
||
public override Gtk.Widget to_widget () { | ||
return new Widgets.BookWyrmPage (this); | ||
} | ||
|
||
public override void open () {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public class Tuba.API.BookWyrmAuthor : Entity { | ||
public string id { get; set; default=""; } | ||
public string openlibraryKey { get; set; default=""; } | ||
public string name { get; set; default=""; } | ||
|
||
public static BookWyrmAuthor from (Json.Node node) throws Error { | ||
return Entity.from_json (typeof (API.BookWyrmAuthor), node) as API.BookWyrmAuthor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public class Tuba.API.BookWyrmCover : Entity { | ||
public string url { get; set; default=""; } | ||
public string name { get; set; default=""; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sources += files( | ||
'Author.vala', | ||
'Cover.vala' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
public class Tuba.Widgets.BookWyrmPage : Gtk.Box { | ||
public API.BookWyrm book { get; private set; } | ||
private Gtk.Picture cover; | ||
|
||
// setting labels as selectable before they | ||
// are visible, causes them to be already | ||
// selected when they become visible | ||
private Gtk.Label [] selectable_labels = {}; | ||
public bool selectable { | ||
set { | ||
foreach (var label in selectable_labels) { | ||
label.selectable = value; | ||
} | ||
} | ||
} | ||
|
||
construct { | ||
orientation = Gtk.Orientation.VERTICAL; | ||
spacing = 12; | ||
margin_bottom = 12; | ||
cover = new Gtk.Picture () { | ||
height_request = 200, | ||
css_classes = { "attachment-picture" } | ||
}; | ||
|
||
#if GTK_4_8 | ||
cover.set_property ("content-fit", 2); | ||
#endif | ||
} | ||
~BookWyrmPage () { | ||
message ("Destroying BookWyrmPage"); | ||
selectable_labels = {}; | ||
} | ||
|
||
public BookWyrmPage (API.BookWyrm t_obj) { | ||
book = t_obj; | ||
|
||
var header_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 32); | ||
if (t_obj.cover != null && t_obj.cover.url != null && t_obj.cover.url != "") { | ||
header_box.append (cover); | ||
image_cache.request_paintable (t_obj.cover.url, on_cache_response); | ||
|
||
if (t_obj.cover.name != "") { | ||
cover.alternative_text = cover.tooltip_text = t_obj.cover.name; | ||
} | ||
} | ||
|
||
var title_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 6) { | ||
valign = Gtk.Align.CENTER, | ||
hexpand = true | ||
}; | ||
var book_title = new Gtk.Label (t_obj.title) { | ||
wrap = true, | ||
css_classes = { "title-1" }, | ||
halign = Gtk.Align.START | ||
}; | ||
selectable_labels += book_title; | ||
title_box.append (book_title); | ||
|
||
if (t_obj.authors != null && t_obj.authors.size > 0) { | ||
Gtk.Label author_label = null; | ||
foreach (var author in t_obj.authors) { | ||
new Request.GET (@"$author.json") | ||
.then ((sess, msg, in_stream) => { | ||
var parser = Network.get_parser_from_inputstream(in_stream); | ||
var node = network.parse_node (parser); | ||
var author_obj = API.BookWyrmAuthor.from (node); | ||
if (author_obj.id == author) { | ||
if (author_label == null) { | ||
author_label = new Gtk.Label (@"by <a href=\"$(author_obj.id)\">$(author_obj.name)</a>") { | ||
wrap = true, | ||
use_markup = true, | ||
halign = Gtk.Align.START | ||
}; | ||
title_box.insert_child_after (author_label, book_title); | ||
} else { | ||
author_label.label += @", <a href=\"$(author_obj.id)\">$(author_obj.name)</a>"; | ||
} | ||
} | ||
}) | ||
.exec (); | ||
} | ||
} | ||
|
||
header_box.append (title_box); | ||
append (header_box); | ||
|
||
var btn_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12); | ||
|
||
var bw_btn = new Gtk.Button.with_label("BookWyrm"); | ||
bw_btn.clicked.connect (open_on_bw); | ||
btn_box.append (bw_btn); | ||
|
||
if (t_obj.openlibraryKey != "") { | ||
var ol_btn = new Gtk.Button.with_label("OpenLibrary"); | ||
ol_btn.clicked.connect (open_on_openlibrary); | ||
btn_box.append (ol_btn); | ||
} | ||
|
||
append (btn_box); | ||
|
||
if (t_obj.description != "") { | ||
var description_label = new Gtk.Label (HtmlUtils.remove_tags (t_obj.description)) { | ||
wrap = true, | ||
css_classes = { "card", "bkwm-desc" } | ||
}; | ||
selectable_labels += description_label; | ||
append (description_label); | ||
} | ||
|
||
if (t_obj.isbn13 != "") { | ||
var isbn_label = new Gtk.Label (@"ISBN: $(t_obj.isbn13)") { | ||
wrap=true | ||
}; | ||
selectable_labels += isbn_label; | ||
append (isbn_label); | ||
} | ||
|
||
if (t_obj.publishedDate != "") { | ||
var date_parsed = new GLib.DateTime.from_iso8601 (t_obj.publishedDate, null); | ||
if (date_parsed != null) | ||
append (new Gtk.Label (@"Published: $(date_parsed.format("%x"))") { wrap=true }); | ||
} | ||
} | ||
|
||
void on_cache_response (bool is_loaded, owned Gdk.Paintable? data) { | ||
cover.paintable = data; | ||
} | ||
|
||
void open_on_openlibrary () { | ||
Host.open_uri (@"https://openlibrary.org/books/$(book.openlibraryKey)"); | ||
} | ||
|
||
void open_on_bw () { | ||
Host.open_uri (book.id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters