Skip to content

Commit 935966c

Browse files
committed
Implement folder list display
1 parent de2733b commit 935966c

File tree

5 files changed

+187
-43
lines changed

5 files changed

+187
-43
lines changed

src/controllers/application.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,10 @@ impl Application {
222222
let conversations = identity
223223
.get_conversations_for_folder(&identity.get_folders().unwrap().iter().find(|&x| x.folder_name == "INBOX").unwrap())
224224
.expect("BLA");
225+
let folders = identity.get_folders().expect("BLA");
225226

226-
main_window.borrow().show_conversations(conversations);
227+
main_window.borrow().load_conversations(conversations);
228+
main_window.borrow().load_folders(folders);
227229

228230
welcome_dialog.borrow().hide();
229231
main_window.borrow().show();
@@ -234,7 +236,7 @@ impl Application {
234236

235237
let conversations = identity.get_conversations_for_folder(&folder).expect("BLA");
236238

237-
main_window.borrow().show_conversations(conversations);
239+
main_window.borrow().load_conversations(conversations);
238240
}
239241
ApplicationMessage::ShowConversation { conversation } => {
240242
main_window.borrow().show_conversation(conversation);

src/models/folders_list.rs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ use crate::models;
1212

1313
pub mod model {
1414
use super::*;
15-
use row_data::ConversationRowData;
15+
use row_data::FolderRowData;
1616
mod imp {
1717
use super::*;
1818

1919
#[derive(Debug)]
20-
pub struct FolderModel(pub RefCell<Vec<ConversationRowData>>);
20+
pub struct FolderListModel(pub RefCell<Vec<FolderRowData>>);
2121
// Basic declaration of our type for the GObject type system
2222

2323
#[glib::object_subclass]
24-
impl ObjectSubclass for FolderModel {
25-
const NAME: &'static str = "FolderModel";
26-
type Type = super::FolderModel;
24+
impl ObjectSubclass for FolderListModel {
25+
const NAME: &'static str = "FolderListModel";
26+
type Type = super::FolderListModel;
2727
type ParentType = glib::Object;
2828
type Interfaces = (gio::ListModel,);
2929

@@ -32,10 +32,10 @@ pub mod model {
3232
Self(RefCell::new(Vec::new()))
3333
}
3434
}
35-
impl ObjectImpl for FolderModel {}
36-
impl ListModelImpl for FolderModel {
35+
impl ObjectImpl for FolderListModel {}
36+
impl ListModelImpl for FolderListModel {
3737
fn item_type(&self, _list_model: &Self::Type) -> glib::Type {
38-
ConversationRowData::static_type()
38+
FolderRowData::static_type()
3939
}
4040
fn n_items(&self, _list_model: &Self::Type) -> u32 {
4141
self.0.borrow().len() as u32
@@ -47,16 +47,16 @@ pub mod model {
4747
}
4848
// Public part of the Model type.
4949
glib::wrapper! {
50-
pub struct FolderModel(ObjectSubclass<imp::FolderModel>) @implements gio::ListModel;
50+
pub struct FolderListModel(ObjectSubclass<imp::FolderListModel>) @implements gio::ListModel;
5151
}
5252
// Constructor for new instances. This simply calls glib::Object::new()
53-
impl FolderModel {
53+
impl FolderListModel {
5454
#[allow(clippy::new_without_default)]
55-
pub fn new() -> FolderModel {
56-
glib::Object::new(&[]).expect("Failed to create FolderModel")
55+
pub fn new() -> FolderListModel {
56+
glib::Object::new(&[]).expect("Failed to create FolderListModel")
5757
}
58-
pub fn append(&self, obj: &ConversationRowData) {
59-
let self_ = imp::FolderModel::from_instance(self);
58+
pub fn append(&self, obj: &FolderRowData) {
59+
let self_ = imp::FolderListModel::from_instance(self);
6060
let index = {
6161
// Borrow the data only once and ensure the borrow guard is dropped
6262
// before we emit the items_changed signal because the view
@@ -69,15 +69,15 @@ pub mod model {
6969
self.items_changed(index as u32, 0, 1);
7070
}
7171
pub fn remove(&self, index: u32) {
72-
let self_ = imp::FolderModel::from_instance(self);
72+
let self_ = imp::FolderListModel::from_instance(self);
7373
self_.0.borrow_mut().remove(index as usize);
7474
// Emits a signal that 1 item was removed, 0 added at the position index
7575
self.items_changed(index, 1, 0);
7676
}
7777
}
7878
}
7979

80-
// This row data wrapper is needed because the FolderModel get_item_type method
80+
// This row data wrapper is needed because the FolderListModel get_item_type method
8181
// needs to have a GObject type to return to the bind_model method
8282
pub mod row_data {
8383
use super::*;
@@ -88,42 +88,42 @@ pub mod row_data {
8888

8989
// The actual data structure that stores our values. This is not accessible
9090
// directly from the outside.
91-
pub struct ConversationRowData {
92-
pub conversation: Rc<RefCell<Option<models::Message>>>,
91+
pub struct FolderRowData {
92+
pub folder: Rc<RefCell<Option<models::Folder>>>,
9393
}
9494

9595
// Basic declaration of our type for the GObject type system
9696
#[glib::object_subclass]
97-
impl ObjectSubclass for ConversationRowData {
98-
const NAME: &'static str = "ConversationRowData";
99-
type Type = super::ConversationRowData;
97+
impl ObjectSubclass for FolderRowData {
98+
const NAME: &'static str = "FolderRowData";
99+
type Type = super::FolderRowData;
100100
type ParentType = glib::Object;
101101
// Called once at the very beginning of instantiation of each instance and
102102
// creates the data structure that contains all our state
103103
fn new() -> Self {
104104
Self {
105-
conversation: Default::default(),
105+
folder: Default::default(),
106106
}
107107
}
108108
}
109-
impl ObjectImpl for ConversationRowData {}
109+
impl ObjectImpl for FolderRowData {}
110110
}
111111

112112
// The public part
113113
glib::wrapper! {
114-
pub struct ConversationRowData(ObjectSubclass<imp::ConversationRowData>);
114+
pub struct FolderRowData(ObjectSubclass<imp::FolderRowData>);
115115
}
116-
impl ConversationRowData {
117-
pub fn new() -> ConversationRowData {
116+
impl FolderRowData {
117+
pub fn new() -> FolderRowData {
118118
glib::Object::new(&[]).expect("Failed to create row data")
119119
}
120-
pub fn set_conversation(&self, conversation: models::Message) {
121-
let self_ = imp::ConversationRowData::from_instance(self);
122-
self_.conversation.replace(Some(conversation));
120+
pub fn set_folder(&self, folder: models::Folder) {
121+
let self_ = imp::FolderRowData::from_instance(self);
122+
self_.folder.replace(Some(folder));
123123
}
124-
pub fn get_conversation(&self) -> Rc<RefCell<Option<models::Message>>> {
125-
let self_ = imp::ConversationRowData::from_instance(self);
126-
self_.conversation.clone()
124+
pub fn get_folder(&self) -> Rc<RefCell<Option<models::Folder>>> {
125+
let self_ = imp::FolderRowData::from_instance(self);
126+
self_.folder.clone()
127127
}
128128
}
129129
}

src/models/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod conversation_messages_list;
22
mod database;
33
pub mod folder_conversations_list;
4+
pub mod folders_list;
45
mod identity;
56

67
pub use database::{BareIdentity, Folder, IdentityType, Message, MessageFlags, NewBareIdentity, NewFolder, NewMessage};

src/ui/stylesheet.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@define-color headerbar_background_color rgb(247,172,55);
22
@define-color headerbar_color rgba(30,30,30,0.7);
3+
@define-color background_secondary_color rgba(238,238,238);
34

45
headerbar {
56
background: @headerbar_background_color;
@@ -28,7 +29,7 @@ headerbar button:active {
2829

2930
.welcome_dialog .button { margin-top: 30px; }
3031

31-
.conversation_viewer { background: #eee; }
32+
.conversation_viewer { background: @background_secondary_color; }
3233

3334
.conversation_viewer .conversation_message_item { background: #fff; }
3435

@@ -94,3 +95,7 @@ headerbar button:active {
9495
.folder_conversation_item.unseen:selected .subject, .folder_conversation_item.unseen:selected .unseen_dot {
9596
color: #fff;
9697
}
98+
99+
.folders_sidebar {
100+
background-color: @background_secondary_color;
101+
}

0 commit comments

Comments
 (0)