Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Port to GTK4 #310

Merged
merged 52 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
77a37d4
Let's do this
Apr 6, 2021
42eafdf
Almost made it compile
Apr 6, 2021
8fb55a8
Now it compiles
Apr 7, 2021
0618b18
Fix base.ui
Apr 8, 2021
e3f4c8a
Fix TabbedBase
Apr 8, 2021
04a1033
Add sidebar view
Apr 9, 2021
138c6b8
Clean ui files
Apr 9, 2021
2e80689
Sidebar: add account switching mode
Apr 9, 2021
514ee97
Populate sidebar with account actions
Apr 11, 2021
3392547
Fix preferences
Apr 11, 2021
d6bdbd7
Fix view title
Apr 12, 2021
48c1d01
Fix thread view
Apr 13, 2021
d17bd2d
Refactor Streams. Again.
Apr 14, 2021
192b32d
Initial Profile view redesign
Apr 17, 2021
161a5c5
New cache system idea
Apr 20, 2021
808fb95
Save window size
Apr 20, 2021
b80a4ec
Account switching
Apr 21, 2021
b7f5559
Fix NewAccount dialog
Apr 21, 2021
b91cb3d
Sidebar: implement account manager mode
Apr 22, 2021
e501716
Add sidebar toggle button
May 15, 2021
4f51c19
Change some timeline icons
May 15, 2021
3d58e44
Rework image cache
May 16, 2021
5c1a9fe
Leaks. Leaks everywhere.
May 16, 2021
5d49e98
Fix Adw.Avatars not being destroyed. Kinda.
May 18, 2021
59c6013
Fix some leaks for GTK 4.3
Jun 15, 2021
a2d5cbf
Doing something controversial
Jun 18, 2021
cdfe8da
Clean up
Jun 18, 2021
6e10056
Reimplement status actions
Jul 2, 2021
1d25465
Cosmetic tweaks
Jul 5, 2021
9e13b5f
Add desktop notifications
Jul 10, 2021
c454e9c
Profile View: move note field up
Jul 10, 2021
04a062f
Work on notifications
Jul 11, 2021
190eb49
Notifications...
Jul 12, 2021
4344d43
Stuff
Jul 14, 2021
12838b3
Add Background widget
Jul 14, 2021
e7a8d54
Remove old Compose dialog
Jul 16, 2021
2b07c00
Add cw field to Composer
Jul 16, 2021
22f42de
Figure out DropDowns
Jul 16, 2021
960da9f
Make composer actually work
Jul 17, 2021
041fcba
Fix symbolic icon recoloring
Jul 17, 2021
81eb396
Initial attachment box
Jul 18, 2021
f059607
Attachment styling
Jul 19, 2021
b2f589a
Open attachments on click
Jul 19, 2021
414825f
Rename Desktop to Host
Jul 19, 2021
e2c6088
Display attachment descriptions
Jul 19, 2021
01f8a82
ImageCache: Store paintables instead of pixbufs
Jul 19, 2021
1709d41
Cosmetics
Jul 19, 2021
eae389f
Composer: Support replies
Jul 23, 2021
179e721
Remove NYI stuff
Jul 23, 2021
f8458ba
Make sidebar useful
Jul 23, 2021
1b60716
Lists are broken
Jul 23, 2021
bb7c1a8
Bump version
Jul 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rework image cache
  • Loading branch information
Bleak Grey committed May 16, 2021
commit 3d58e440a2c2528da0fb5bf2bc7f8a7a4b6809f6
4 changes: 1 addition & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ sources = files(
'src/Services/Accounts/Mastodon/Account.vala',
'src/Services/Streams/Streams.vala',
'src/Services/Streams/Streamable.vala',
'src/Services/Cache.vala',
'src/Services/Cache/AbstractCache.vala',
'src/Services/Cache/EntityCache.vala',
'src/Services/Cache/ImageCache.vala',
'src/Services/Network/Network.vala',
'src/Services/Network/Request.vala',
'src/Services/Settings.vala',
Expand All @@ -69,8 +69,6 @@ sources = files(
'src/Widgets/Conversation.vala',
'src/Widgets/VisibilityPopover.vala',
'src/Widgets/Attachment/Box.vala',
'src/Widgets/Attachment/Slot.vala',
'src/Widgets/Attachment/Picture.vala',
'src/Widgets/AdaptiveButton.vala',
'src/Widgets/MarkupView.vala',
'src/Dialogs/Saveable.vala',
Expand Down
5 changes: 2 additions & 3 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ namespace Tootle {
public static Settings settings;
public static AccountStore accounts;
public static Network network;
public static Cache cache;
public static Streams streams;

public static EntityCache entity_cache;
public static ImageCache image_cache;

public static bool start_hidden = false;

Expand All @@ -30,7 +30,6 @@ namespace Tootle {
public Settings app_settings { get {return Tootle.settings; } }
public AccountStore app_accounts { get {return Tootle.accounts; } }
public Network app_network { get {return Tootle.network; } }
public Cache app_cache { get {return Tootle.cache; } }
public Streams app_streams { get {return Tootle.streams; } }

public signal void refresh ();
Expand Down Expand Up @@ -87,8 +86,8 @@ namespace Tootle {
settings = new Settings ();
streams = new Streams ();
network = new Network ();
cache = new Cache ();
entity_cache = new EntityCache ();
image_cache = new ImageCache ();
accounts = new SecretAccountStore();
accounts.init ();

Expand Down
156 changes: 0 additions & 156 deletions src/Services/Cache.vala

This file was deleted.

19 changes: 15 additions & 4 deletions src/Services/Cache/AbstractCache.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ public class Tootle.AbstractCache : Object {
while (iter.has_next ()) {
iter.next ();
var obj = iter.get_value ();
var min_ref_count = obj.get_data<uint> (DATA_MIN_REF_COUNT);
var remove = obj.ref_count <= min_ref_count;
assert (obj != null);

if (remove) {
var min_ref_count = obj.get_data<uint> (DATA_MIN_REF_COUNT);
if ("jpg" in iter.get_key ()) {
warning (@"Key \"$(iter.get_key ())\": $(obj.ref_count)/$(min_ref_count)");
}
if (obj.ref_count <= min_ref_count) {
cleared++;
Value url = Value (typeof (string));
obj.get_property ("url", ref url);
Expand Down Expand Up @@ -61,13 +64,21 @@ public class Tootle.AbstractCache : Object {
return items.has_key (get_key (id));
}

public void insert (string id, owned Object obj) {
public string insert (string id, owned Object obj) {
var key = get_key (id);
message ("Inserting: "+key);
items.@set (key, (owned) obj);

var nobj = items.@get (key);
nobj.set_data<uint> (DATA_MIN_REF_COUNT, nobj.ref_count);

return key;
}

public void nuke () {
message ("Clearing cache");
items.clear ();
items_in_progress.clear ();
}

}
88 changes: 88 additions & 0 deletions src/Services/Cache/ImageCache.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using Gdk;

public class Tootle.ImageCache : AbstractCache {

// [Signal (detailed = true)]
// public signal void on_item_changed (bool is_loaded, owned Pixbuf? data);

public delegate void OnItemChangedFn (bool is_loaded, owned Pixbuf? data);

protected Pixbuf decode_image (owned Soup.Message msg) throws Error {
Pixbuf? pixbuf = null;
var code = msg.status_code;
if (code != Soup.Status.OK) {
var error = network.describe_error (code);
throw new Oopsie.INSTANCE (@"Server returned $error");
}

var data = msg.response_body.flatten ().data;
var stream = new MemoryInputStream.from_data (data);
pixbuf = new Pixbuf.from_stream (stream);
stream.close ();

if (pixbuf == null)
throw new Oopsie.INSTANCE ("Returned pixbuf is null");

return pixbuf;
}

public void request_pixbuf (string? url, owned OnItemChangedFn cb) {
if (url == null)
return;

var key = get_key (url);
if (contains (key)) {
cb (true, lookup (key) as Pixbuf);
return;
}

var download_msg = items_in_progress.@get (key);
if (download_msg == null) {
// This image isn't cached, so we need to download it first.

download_msg = new Soup.Message ("GET", url);
ulong id = 0;
id = download_msg.finished.connect (() => {
Pixbuf? pixbuf = null;
try {
pixbuf = decode_image (download_msg);
}
catch (Error e) {
warning (@"Failed to download image at \"$url\". $(e.message).");
cb (true, null);
return;
}

// message (@"[*] $key");
insert (url, pixbuf);
items_in_progress.unset (key);

cb (true, pixbuf);

download_msg.disconnect (id);
});

network.queue (download_msg, (sess, mess) => {
// no one cares
},
(code, reason) => {
cb (true, null);
});

cb (false, null);

items_in_progress.@set (key, download_msg);
}
else {
// This image is either cached or already downloading, so we can serve the result immediately.

//message ("[/]: %s", key);
ulong id = 0;
id = download_msg.finished.connect_after (() => {
cb (true, lookup (key) as Pixbuf);
download_msg.disconnect (id);
});
}
}

}
Loading