Skip to content

Commit

Permalink
heap toots stick around
Browse files Browse the repository at this point in the history
  • Loading branch information
donpdonp committed Aug 20, 2019
1 parent 2080dce commit 3c560e9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub const HttpInfo = struct {
response_code: c_long,
tree: std.json.ValueTree,
column: *ColumnInfo,
toot: toot_lib.Toot()
toot: *toot_lib.Type
};

pub const ColumnAuth = struct {
Expand Down
8 changes: 4 additions & 4 deletions src/gui/gtk.zig
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub extern fn update_column_ui_schedule(in: *c_void) c_int {
return 0;
}

pub const TootPic = struct { toot: toot_lib.Type, pic: []const u8 };
pub const TootPic = struct { toot: *toot_lib.Type, pic: []const u8 };
pub extern fn toot_media_schedule(in: *c_void) c_int {
const tootpic = @ptrCast(*TootPic, @alignCast(8,in));
toot_media(tootpic.toot, tootpic.pic);
Expand Down Expand Up @@ -381,8 +381,8 @@ extern fn widget_destroy(widget: [*c]c.GtkWidget, userdata: ?*c_void) void {
c.gtk_widget_destroy(widget);
}

pub fn makeTootBox(toot: toot_lib.Toot(), colconfig: *config.ColumnConfig) [*c]c.GtkBuilder {
//warn("toot #{} gui building img {} {}\n", toot.id(), toot.imgList.count(), toot.imgList);
pub fn makeTootBox(toot: *toot_lib.Type, colconfig: *config.ColumnConfig) [*c]c.GtkBuilder {
warn("maketootbox toot #{} {*} gui building img {} {}\n", toot.id(), toot, toot.imgList.count(), toot.imgList);
const builder = c.gtk_builder_new_from_file (c"glade/toot.glade");
const tootbox = builder_get_widget(builder, c"tootbox");

Expand Down Expand Up @@ -453,7 +453,7 @@ fn photo_refresh(acct: []const u8, builder: *c.GtkBuilder) void {
c.gtk_image_set_from_pixbuf(@ptrCast([*c]c.GtkImage, avatar), pixbuf);
}

fn toot_media(toot: toot_lib.Toot(), pic: []const u8) void {
fn toot_media(toot: *toot_lib.Type, pic: []const u8) void {
if(findColumnByTootId(toot.id())) |column| {
const tootbuilder = column.guitoots.get(toot.id()).?.value;
const imageBox = builder_get_widget(tootbuilder, c"image_box");
Expand Down
12 changes: 7 additions & 5 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn profileget(column: *config.ColumnInfo) void {
var netthread = thread.create(net.go, verb, profileback) catch unreachable;
}

fn photoget(toot: toot_lib.Toot(), url: []const u8) void {
fn photoget(toot: *toot_lib.Type, url: []const u8) void {
var verb = allocator.create(thread.CommandVerb) catch unreachable;
var httpInfo = allocator.create(config.HttpInfo) catch unreachable;
httpInfo.url = url;
Expand All @@ -126,7 +126,7 @@ fn photoget(toot: toot_lib.Toot(), url: []const u8) void {
var netthread = thread.create(net.go, verb, photoback) catch unreachable;
}

fn mediaget(toot: toot_lib.Toot(), url: []const u8) void {
fn mediaget(toot: *toot_lib.Type, url: []const u8) void {
var verb = allocator.create(thread.CommandVerb) catch unreachable;
var httpInfo = allocator.create(config.HttpInfo) catch unreachable;
httpInfo.url = url;
Expand All @@ -135,6 +135,7 @@ fn mediaget(toot: toot_lib.Toot(), url: []const u8) void {
httpInfo.response_code = 0;
httpInfo.toot = toot;
verb.http = httpInfo;
warn("mediaget toot {} {*}\n", toot.id(), &toot);
var netthread = thread.create(net.go, verb, mediaback) catch unreachable;
}

Expand Down Expand Up @@ -228,9 +229,10 @@ fn netback(command: *thread.Command) void {
column.inError = false;
for(tree.root.Array.toSlice()) |jsonValue| {
const item = jsonValue.Object;
const toot = toot_lib.Type.init(item, allocator);
var toot = allocator.create(toot_lib.Type) catch unreachable;
toot.init(item, allocator);
var id = toot.id();
warn("netback json toot #{} {*}\n", toot.id(), toot.ptr);
warn("netback json create toot #{} {*}\n", toot.id(), toot);
if(column.toots.contains(toot)) {
// dupe
} else {
Expand Down Expand Up @@ -290,7 +292,7 @@ fn profileback(command: *thread.Command) void {
gui.schedule(gui.update_column_ui_schedule, @ptrCast(*c_void, reqres.column));
}

fn cache_update(toot: toot_lib.Toot()) void {
fn cache_update(toot: *toot_lib.Type) void {
var account = toot.get("account").?.value.Object;
const acct: []const u8 = account.get("acct").?.value.String;
const avatar_url: []const u8 = account.get("avatar").?.value.String;
Expand Down
13 changes: 5 additions & 8 deletions src/toot.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@ pub fn Toot() type {
const Toothashmap = std.hash_map.HashMap(K, V,
std.mem.hash_slice_u8,
std.mem.eql_slice_u8);
pub fn init(hash: Toothashmap, allocator: *Allocator) Self {
var newToot = Self{
.hashmap = hash,
.tagList = TagList.init(allocator),
.imgList = ImgList.init(allocator)
};
newToot.parseTags(allocator);
return newToot;
pub fn init(self: *Self, hash: Toothashmap, allocator: *Allocator) void {
self.hashmap = hash;
self.tagList = TagList.init(allocator);
self.imgList = ImgList.init(allocator);
self.parseTags(allocator);
}

pub fn get(self: *const Self, key: K) ?*Toothashmap.KV {
Expand Down
2 changes: 1 addition & 1 deletion src/toot_list.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Allocator = std.mem.Allocator;
const toot_lib = @import("./toot.zig");
const util = @import("./util.zig");

pub const TootList = SomeList(toot_lib.Toot());
pub const TootList = SomeList(*toot_lib.Type);

pub fn SomeList(comptime T: type) type {
return struct {
Expand Down

0 comments on commit 3c560e9

Please sign in to comment.