Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor use of ListView #1314

Draft
wants to merge 5 commits into
base: feat/listbox-listview
Choose a base branch
from
Draft
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
needs: [ lint ]
container:
image: bilelmoussaoui/flatpak-github-actions:gnome-43
image: bilelmoussaoui/flatpak-github-actions:gnome-47
options: --privileged
strategy:
matrix:
@@ -39,7 +39,7 @@ jobs:
uses: docker/setup-qemu-action@v2
with:
platforms: arm64
- uses: flatpak/flatpak-github-actions/flatpak-builder@v6
- uses: flathub-infra/flatpak-github-actions/flatpak-builder@4388a4c5fc8bab58e1dfb7fc63267dca0f7b4976
with:
bundle: "dev.geopjr.Tuba.Devel.flatpak"
run-tests: true
33 changes: 28 additions & 5 deletions build-aux/dev.geopjr.Tuba.Devel.json
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
"runtime": "org.gnome.Platform",
"runtime-version": "47",
"sdk": "org.gnome.Sdk",
"sdk-extensions": [ "org.freedesktop.Sdk.Extension.llvm19" ],
"command": "dev.geopjr.Tuba",
"finish-args": [
"--device=dri",
@@ -26,12 +27,23 @@
],
"modules": [
{
"name" : "libspelling",
"buildsystem" : "meson",
"config-opts" : [
"name": "libspelling",
"buildsystem": "meson",
"config-opts": [
"-Ddocs=false"
],
"sources" : [
"build-options": {
"arch": {
"aarch64": {
"append-path": "/usr/lib/sdk/llvm19/bin",
"prepend-ld-library-path": "/usr/lib/sdk/llvm19/lib",
"env": {
"CC": "clang"
}
}
}
},
"sources": [
{
"type": "git",
"url": "https://gitlab.gnome.org/GNOME/libspelling.git",
@@ -43,9 +55,20 @@
"name": "tuba",
"builddir": true,
"buildsystem": "meson",
"config-opts" : [
"config-opts": [
"-Ddevel=true"
],
"build-options": {
"arch": {
"aarch64": {
"append-path": "/usr/lib/sdk/llvm19/bin",
"prepend-ld-library-path": "/usr/lib/sdk/llvm19/lib",
"env": {
"CC": "clang"
}
}
}
},
"sources": [
{
"type": "dir",
14 changes: 0 additions & 14 deletions data/style.css
Original file line number Diff line number Diff line change
@@ -61,11 +61,6 @@ headerbar.flat.no-title .title {
margin: 0px;
}

.ttl-thread-line {
background: var(--window-fg-color);
opacity: .1;
}

.ttl-code {
padding: 12px;
background: rgba(150, 150, 150, .1);
@@ -351,15 +346,6 @@ headerbar.flat.no-title .title {
font-weight: initial;
}

.ttl-thread-line.top {
margin-top: -18px;
margin-bottom: -3px;
}

.ttl-thread-line.bottom {
margin-bottom: -20px;
}

.attachment-overlay-icon {
border-radius: 100%;
min-height: 64px;
25 changes: 0 additions & 25 deletions data/ui/widgets/status.ui
Original file line number Diff line number Diff line change
@@ -36,18 +36,6 @@
<property name="icon_size">1</property>
</object>
</child>
<child>
<object class="GtkImage" id="thread_line_top">
<property name="visible">0</property>
<property name="width_request">4</property>
<property name="halign">center</property>
<property name="pixel-size">4</property>
<style>
<class name="ttl-thread-line" />
<class name="top" />
</style>
</object>
</child>
<child>
<object class="GtkOverlay" id="avatar_overlay">
<property name="margin_top">3</property>
@@ -63,19 +51,6 @@
</child>
</object>
</child>
<child>
<object class="GtkImage" id="thread_line_bottom">
<property name="visible">0</property>
<property name="width_request">4</property>
<property name="vexpand">1</property>
<property name="halign">center</property>
<property name="pixel-size">4</property>
<style>
<class name="ttl-thread-line" />
<class name="bottom" />
</style>
</object>
</child>
</object>
</child>
<child>
2 changes: 1 addition & 1 deletion src/API/Conversation.vala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public class Tuba.API.Conversation : Entity, Widgetizable {
public class Tuba.API.Conversation : Entity, WidgetizableForListView {

public string id { get; set; }
public Gee.ArrayList<API.Account>? accounts { get; set; }
10 changes: 8 additions & 2 deletions src/API/Status.vala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public class Tuba.API.Status : Entity, Widgetizable, SearchResult {
public class Tuba.API.Status : Entity, WidgetizableForListView, SearchResult {

~Status () {
debug (@"[OBJ] Destroyed $(uri ?? "")");
@@ -219,7 +219,13 @@ public class Tuba.API.Status : Entity, Widgetizable, SearchResult {
}

public override Gtk.Widget to_widget () {
return new Widgets.Status (this);
return new Widgets.Status ();
}

public override void fill_widget_with_content (Gtk.Widget widget) throws Oopsie {
((Widgets.Status) widget).kind_instigator = this.account;
((Widgets.Status) widget).status = this;
((Widgets.Status) widget).init (this);
}

public override void open () {
4 changes: 4 additions & 0 deletions src/Dialogs/Composer/AttachmentsPage.vala
Original file line number Diff line number Diff line change
@@ -356,6 +356,10 @@ public class Tuba.AttachmentsPage : ComposerPage {
&& accounts.active.instance_info.configuration.media_attachments != null
&& accounts.active.instance_info.configuration.media_attachments.supported_mime_types != null
&& accounts.active.instance_info.configuration.media_attachments.supported_mime_types.size > 0
&& !(
accounts.active.instance_info.configuration.media_attachments.supported_mime_types.size == 1
&& accounts.active.instance_info.configuration.media_attachments.supported_mime_types[0] == "application/octet-stream"
)
) {
supported_mimes = accounts.active.instance_info.configuration.media_attachments.supported_mime_types;
}
6 changes: 1 addition & 5 deletions src/Dialogs/Report.vala
Original file line number Diff line number Diff line change
@@ -475,11 +475,7 @@ public class Tuba.Dialogs.Report : Adw.Dialog {
widget_status.can_target = false;
widget_status.focusable = false;
widget_status.actions.visible = false;
#if USE_LISTVIEW
widget_status.can_be_opened = false;
#else
widget_status.activatable = false;
#endif
widget_status.can_be_opened = false;
listbox.append (new StatusRow (checkbutton, widget_status));
});

14 changes: 4 additions & 10 deletions src/Views/Base.vala
Original file line number Diff line number Diff line change
@@ -68,11 +68,7 @@ public class Tuba.Views.Base : Adw.BreakpointBin {
// [GtkChild] protected unowned Adw.Clamp clamp;
// [GtkChild] protected unowned Gtk.Box column_view;
[GtkChild] protected unowned Gtk.Stack states;
#if USE_LISTVIEW
[GtkChild] protected unowned Adw.ClampScrollable content_box;
#else
[GtkChild] protected unowned Adw.Clamp content_box;
#endif
[GtkChild] protected unowned Adw.ClampScrollable content_box;
[GtkChild] protected unowned Gtk.Button status_button;
[GtkChild] unowned Gtk.Image status_image;
[GtkChild] unowned Gtk.Stack status_stack;
@@ -186,11 +182,9 @@ public class Tuba.Views.Base : Adw.BreakpointBin {
base.dispose ();
}

#if !USE_LISTVIEW
public virtual void unbind_listboxes () {
this.last_widget = null;
}
#endif
public virtual void unbind_listboxes () {
this.last_widget = null;
}

protected virtual void build_actions () {}

101 changes: 28 additions & 73 deletions src/Views/ContentBase.vala
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
public class Tuba.Views.ContentBase : Views.Base {

#if USE_LISTVIEW
protected Gtk.ListView content;
#else
protected Gtk.ListBox content;
#endif
protected Gtk.ListBox content;
protected signal void reached_close_to_top ();
public GLib.ListStore model;
private bool bottom_reached_locked = false;
@@ -16,32 +11,21 @@ public class Tuba.Views.ContentBase : Views.Base {
construct {
model = new GLib.ListStore (typeof (Widgetizable));

#if USE_LISTVIEW
Gtk.SignalListItemFactory signallistitemfactory = new Gtk.SignalListItemFactory ();
signallistitemfactory.bind.connect (bind_listitem_cb);

content = new Gtk.ListView (new Gtk.NoSelection (model), signallistitemfactory) {
css_classes = { "contentbase", "content", "background" },
single_click_activate = true
};

content.activate.connect (on_content_item_activated);
model.items_changed.connect (on_content_changed);
#else
model.items_changed.connect (on_content_changed);
content = new Gtk.ListBox () {
selection_mode = Gtk.SelectionMode.NONE,
css_classes = { "content", "background" }
};

content.row_activated.connect (on_content_item_activated);
content.bind_model (model, on_create_model_widget);
#endif
model.items_changed.connect (on_content_changed);

content = new Gtk.ListBox () {
selection_mode = Gtk.SelectionMode.NONE,
css_classes = { "fake-content", "background" }
};

content.row_activated.connect (on_content_item_activated);
content.bind_model (model, on_create_model_widget);
content_box.child = content;

scrolled.vadjustment.value_changed.connect (on_scrolled_vadjustment_value_change);
scroll_to_top_rev.bind_property ("child-revealed", scroll_to_top_rev, "visible", GLib.BindingFlags.SYNC_CREATE);
}

~ContentBase () {
debug ("Destroying ContentBase");
}
@@ -71,26 +55,9 @@ public class Tuba.Views.ContentBase : Views.Base {
scroll_to_top_rev.reveal_child = reveal;
}

#if USE_LISTVIEW
protected virtual void bind_listitem_cb (GLib.Object item) {
((Gtk.ListItem) item).child = on_create_model_widget (((Gtk.ListItem) item).item);

var gtklistitemwidget = ((Gtk.ListItem) item).child.get_parent ();
if (gtklistitemwidget != null) {
gtklistitemwidget.add_css_class ("card");
gtklistitemwidget.add_css_class ("card-spacing");
gtklistitemwidget.focusable = true;

// Thread lines overflow slightly
gtklistitemwidget.overflow = Gtk.Overflow.HIDDEN;
}
}
#endif

public override void dispose () {
#if !USE_LISTVIEW
unbind_listboxes ();
#endif
unbind_listboxes ();
base.dispose ();
}

@@ -114,31 +81,25 @@ public class Tuba.Views.ContentBase : Views.Base {
}
}

#if !USE_LISTVIEW
public override void unbind_listboxes () {
if (content != null)
content.bind_model (null, null);
base.unbind_listboxes ();
}
#endif
public override void unbind_listboxes () {
if (content != null)
content.bind_model (null, null);
base.unbind_listboxes ();
}

public virtual Gtk.Widget on_create_model_widget (Object obj) {
var obj_widgetable = obj as Widgetizable;
if (obj_widgetable == null)
Process.exit (0);
try {
#if !USE_LISTVIEW
Gtk.Widget widget = obj_widgetable.to_widget ();
widget.add_css_class ("card");
widget.add_css_class ("card-spacing");
widget.focusable = true;

// Thread lines overflow slightly
widget.overflow = Gtk.Overflow.HIDDEN;
return widget;
#else
return obj_widgetable.to_widget ();
#endif
Gtk.Widget widget = obj_widgetable.to_widget ();
widget.add_css_class ("card");
widget.add_css_class ("card-spacing");
widget.focusable = true;

// Thread lines overflow slightly
widget.overflow = Gtk.Overflow.HIDDEN;
return widget;
} catch (Oopsie e) {
warning (@"Error on_create_model_widget: $(e.message)");
Process.exit (0);
@@ -155,13 +116,7 @@ public class Tuba.Views.ContentBase : Views.Base {
}, Priority.LOW);
}

#if USE_LISTVIEW
public virtual void on_content_item_activated (uint pos) {
((Widgetizable) ((ListModel) content.model).get_item (pos)).open ();
}
#else
public virtual void on_content_item_activated (Gtk.ListBoxRow row) {
Signal.emit_by_name (row, "open");
}
#endif
public virtual void on_content_item_activated (Gtk.ListBoxRow row) {
Signal.emit_by_name (row, "open");
}
}
Loading