Skip to content

Commit

Permalink
start to look at media attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
donpdonp committed Jul 6, 2019
1 parent 3b40678 commit 62222a5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
20 changes: 19 additions & 1 deletion glade/column.glade
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<object class="GtkBox" id="column_topbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
Expand Down Expand Up @@ -54,6 +54,24 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkEventBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-select-color</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
Expand Down
4 changes: 4 additions & 0 deletions src/gui/gtk.zig
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ pub fn makeTootBox(toot: toot_lib.TootType) [*c]c.GtkWidget {
50, -1, 1, null);
c.gtk_image_set_from_pixbuf(@ptrCast([*c]c.GtkImage, avatar), pixbuf);

var images = toot.get("media_attachments").?.value.Array;
for(images.toSlice()) |image| {
warn("toot image {}\n", image.Object.get("url").?.value.String);
}
return tootbox;
}

Expand Down
14 changes: 3 additions & 11 deletions src/html.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,29 @@ const c = @cImport({
@cInclude("gumbo.h");
});

// static void* malloc_wrapper(void* unused, size_t size) { return malloc(size); }
// static void free_wrapper(void* unused, void* ptr) { free(ptr); }
// const GumboOptions kGumboDefaultOptions = {&malloc_wrapper, &free_wrapper, NULL,
// 8, false, -1, GUMBO_TAG_LAST, GUMBO_NAMESPACE_HTML};

pub fn parse(html: []const u8, allocator: *Allocator) *Node {
// const GumboOptions kGumboDefaultOptions = {&malloc_wrapper, &free_wrapper, NULL, 8, false, -1, GUMBO_TAG_LAST, GUMBO_NAMESPACE_HTML};
var options = c.GumboOptions{.allocator = c.kGumboDefaultOptions.allocator,
.deallocator = c.kGumboDefaultOptions.deallocator, .userdata = null, .tab_stop = 0,
.stop_on_first_error = false, .max_errors = 0,
.deallocator = c.kGumboDefaultOptions.deallocator, .userdata = null, .tab_stop = 8,
.stop_on_first_error = false, .max_errors = -1,
.fragment_context = c.GumboTag.GUMBO_TAG_BODY,
.fragment_namespace = c.GumboNamespaceEnum.GUMBO_NAMESPACE_HTML};
var doc = c.gumbo_parse_with_options(&options, html.ptr, html.len);
var root = doc.*.root;
var tagType = root.*.type;
var tagName = root.*.v.element.tag;
warn("parsed: {}\n", html);
return root;
}

pub fn search(node: *Node) void {
if (node.type == c.GumboNodeType.GUMBO_NODE_ELEMENT) {
warn("SearchStart {*} {}\n", node, node.v.element.tag);
if(node.v.element.tag == c.GumboTag.GUMBO_TAG_A) {
warn("A TAG found\n");
}
var children = node.v.element.children;
warn("children len {}\n", children.length);
var idx = u32(0);
while(idx < children.length) : (idx += 1) {
const cnode = children.data[idx];
warn("child {*}\n", cnode);
if(cnode) |chld| {
search(@ptrCast(*Node, @alignCast(8, chld)));
}
Expand Down

0 comments on commit 62222a5

Please sign in to comment.