Skip to content

Commit 1833ff6

Browse files
committed
sidebar: Port to Adw.ViewSwitcherSidebar
1 parent 5b21c1e commit 1833ff6

File tree

10 files changed

+62
-145
lines changed

10 files changed

+62
-145
lines changed

openemail/gtk/contacts.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
# SPDX-FileContributor: kramo
44

55
from contextlib import suppress
6+
from typing import Any
67

78
from gi.repository import Adw, GObject, Gtk
89

910
from openemail import PREFIX, store, tasks
11+
from openemail._property import Property
1012
from openemail.core.model import Address
1113
from openemail.store import DictStore, People
1214

@@ -34,6 +36,20 @@ class Contacts(Adw.NavigationPage):
3436
address: Adw.EntryRow = child
3537
address_form: Form = child
3638

39+
contact_requests_filter: Gtk.BoolFilter = child
40+
41+
counter = Property(int)
42+
43+
def __init__(self, **kwargs: Any) -> None:
44+
super().__init__(**kwargs)
45+
46+
store.settings.connect(
47+
"changed::contact-requests",
48+
lambda *_: self.contact_requests_filter.changed(
49+
Gtk.FilterChange.MORE_STRICT
50+
),
51+
)
52+
3753
@Gtk.Template.Callback()
3854
def _new_contact(self, *_args):
3955
self.address_form.reset()

openemail/gtk/content.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
from .contacts import Contacts
1616
from .messages import Broadcasts, Drafts, Inbox, Outbox, Sent, Trash
17-
from .navigation_row import NavigationRow
1817
from .profile_settings import ProfileSettings
1918

2019
for t in Contacts, Broadcasts, Drafts, Inbox, Outbox, Sent, Trash, ComposeSheet:
@@ -33,7 +32,6 @@ class Content(Adw.BreakpointBin):
3332
split_view: Adw.OverlaySplitView = child
3433

3534
sidebar_toolbar_view: Adw.ToolbarView = child
36-
sidebar: Gtk.ListBox = child
3735
stack: Adw.ViewStack = child
3836
profile_settings: ProfileSettings = child
3937

@@ -55,9 +53,6 @@ def header_bar_layout(self) -> str:
5553
def __init__(self, **kwargs: Any):
5654
super().__init__(**kwargs)
5755

58-
self.sidebar.set_header_func(self._header_func)
59-
self.sidebar.select_row(self.sidebar.get_row_at_index(0))
60-
6156
Property.bind(Profile.of(client.user), "image", self, "profile-image")
6257
Property.bind(
6358
Notifier(), "sending", self.sidebar_toolbar_view, "reveal-bottom-bars"
@@ -68,24 +63,8 @@ def __init__(self, **kwargs: Any):
6863
lambda *_: self.notify("header-bar-layout"),
6964
)
7065

71-
def _header_func(self, row: NavigationRow, *_args):
72-
row.set_header(
73-
Gtk.Separator(
74-
margin_start=9,
75-
margin_end=9,
76-
)
77-
if row.separator
78-
else None
79-
)
80-
8166
@Gtk.Template.Callback()
82-
def _on_row_selected(self, _obj, row: NavigationRow | None):
83-
if not row:
84-
return
85-
86-
self.sidebar.select_row(row)
87-
self.stack.props.visible_child = row.page.props.child
88-
67+
def _close_sidebar(self, *_args):
8968
if self.split_view.props.collapsed:
9069
self.split_view.props.show_sidebar = False
9170

openemail/gtk/messages.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919

2020
class _Messages(Adw.NavigationPage):
21+
counter = Property(int)
22+
2123
def __init__(
2224
self,
2325
model: Gio.ListModel,
@@ -47,6 +49,17 @@ def __init__(
4749

4850
self.props.child = self.page
4951

52+
unread: Gtk.FilterListModel = self._get_object("unread")
53+
unread.bind_property(
54+
"n-items", self, "counter", GObject.BindingFlags.SYNC_CREATE
55+
)
56+
57+
unread_filter = self._get_object("unread_filter")
58+
store.settings.connect(
59+
"changed::unread-messages",
60+
lambda *_: unread_filter.changed(Gtk.FilterChange.MORE_STRICT),
61+
)
62+
5063
def _get_object(self, name: str) -> Any: # noqa: ANN401
5164
return self.builder.get_object(name)
5265

openemail/gtk/navigation_row.py

Lines changed: 0 additions & 51 deletions
This file was deleted.

openemail/gtk/ui/contacts.blp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ $People people {}
55

66
template $Contacts: Adw.NavigationPage {
77
title: _("Contacts");
8+
counter: bind contact_requests.n-items;
89

910
child: $Page page {
1011
title: bind template.title;
@@ -108,3 +109,11 @@ $Form address_form {
108109
type: address;
109110
}
110111
}
112+
113+
FilterListModel contact_requests {
114+
filter: BoolFilter contact_requests_filter {
115+
expression: expr item as <$Profile>.contact-request;
116+
};
117+
118+
model: bind people.all;
119+
}

openemail/gtk/ui/content.blp

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -119,45 +119,9 @@ template $Content: Adw.BreakpointBin {
119119
]
120120
}
121121

122-
content: ScrolledWindow {
123-
hscrollbar-policy: never;
124-
125-
child: ListBox sidebar {
126-
row-selected => $_on_row_selected();
127-
128-
$NavigationRow {
129-
page: bind inbox_page;
130-
}
131-
132-
$NavigationRow {
133-
page: bind outbox_page;
134-
}
135-
136-
$NavigationRow {
137-
page: bind sent_page;
138-
}
139-
140-
$NavigationRow {
141-
page: bind drafts_page;
142-
}
143-
144-
$NavigationRow {
145-
page: bind trash_page;
146-
}
147-
148-
$NavigationRow {
149-
page: bind broadcasts_page;
150-
separator: true;
151-
}
152-
153-
$NavigationRow {
154-
page: bind contacts_page;
155-
}
156-
157-
styles [
158-
"navigation-sidebar",
159-
]
160-
};
122+
content: Adw.ViewSwitcherSidebar {
123+
stack: stack;
124+
activated => $_close_sidebar();
161125
};
162126
};
163127
};
@@ -171,6 +135,7 @@ template $Content: Adw.BreakpointBin {
171135
Adw.ViewStackPage inbox_page {
172136
icon-name: "inbox-symbolic";
173137
title: bind inbox.title;
138+
badge-number: bind inbox.counter;
174139

175140
child: $Inbox inbox {};
176141
}
@@ -192,27 +157,32 @@ template $Content: Adw.BreakpointBin {
192157
Adw.ViewStackPage drafts_page {
193158
icon-name: "drafts-symbolic";
194159
title: bind drafts.title;
160+
badge-number: bind drafts.counter;
195161

196162
child: $Drafts drafts {};
197163
}
198164

199165
Adw.ViewStackPage trash_page {
200166
icon-name: "trash-symbolic";
201167
title: bind trash.title;
168+
badge-number: bind trash.counter;
202169

203170
child: $Trash trash {};
204171
}
205172

206173
Adw.ViewStackPage broadcasts_page {
174+
starts-section: true;
207175
icon-name: "broadcasts-symbolic";
208176
title: bind broadcasts.title;
177+
badge-number: bind broadcasts.counter;
209178

210179
child: $Broadcasts broadcasts {};
211180
}
212181

213182
Adw.ViewStackPage contacts_page {
214183
icon-name: "contacts-symbolic";
215184
title: bind contacts.title;
185+
badge-number: bind contacts.counter;
216186

217187
child: $Contacts contacts {};
218188
}

openemail/gtk/ui/meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ blueprints = custom_target(
99
'message-row.blp',
1010
'message-view.blp',
1111
'messages.blp',
12-
'navigation-row.blp',
1312
'page.blp',
1413
'preferences.blp',
1514
'profile-settings.blp',

openemail/gtk/ui/messages.blp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ $Page page {
3838
};
3939
}
4040

41+
FilterListModel unread {
42+
filter: AnyFilter unread_filter {
43+
BoolFilter {
44+
expression: expr item as <$Message>.new;
45+
}
46+
47+
BoolFilter {
48+
expression: expr item as <$Message>.is_draft;
49+
}
50+
};
51+
52+
model: bind page.model;
53+
}
54+
4155
/* Folder */
4256
Adw.StatusPage no_messages {
4357
icon-name: "mailbox-symbolic";

openemail/gtk/ui/navigation-row.blp

Lines changed: 0 additions & 31 deletions
This file was deleted.

openemail/gtk/ui/ui.gresource.xml.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<file>message-row.ui</file>
1111
<file>message-view.ui</file>
1212
<file>messages.ui</file>
13-
<file>navigation-row.ui</file>
1413
<file>page.ui</file>
1514
<file>preferences.ui</file>
1615
<file>profile-settings.ui</file>

0 commit comments

Comments
 (0)