Skip to content

Commit

Permalink
Implement folder list display
Browse files Browse the repository at this point in the history
  • Loading branch information
matzipan committed Jul 24, 2021
1 parent de2733b commit 935966c
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 43 deletions.
6 changes: 4 additions & 2 deletions src/controllers/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,10 @@ impl Application {
let conversations = identity
.get_conversations_for_folder(&identity.get_folders().unwrap().iter().find(|&x| x.folder_name == "INBOX").unwrap())
.expect("BLA");
let folders = identity.get_folders().expect("BLA");

main_window.borrow().show_conversations(conversations);
main_window.borrow().load_conversations(conversations);
main_window.borrow().load_folders(folders);

welcome_dialog.borrow().hide();
main_window.borrow().show();
Expand All @@ -234,7 +236,7 @@ impl Application {

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

main_window.borrow().show_conversations(conversations);
main_window.borrow().load_conversations(conversations);
}
ApplicationMessage::ShowConversation { conversation } => {
main_window.borrow().show_conversation(conversation);
Expand Down
64 changes: 32 additions & 32 deletions src/models/folders_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ use crate::models;

pub mod model {
use super::*;
use row_data::ConversationRowData;
use row_data::FolderRowData;
mod imp {
use super::*;

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

#[glib::object_subclass]
impl ObjectSubclass for FolderModel {
const NAME: &'static str = "FolderModel";
type Type = super::FolderModel;
impl ObjectSubclass for FolderListModel {
const NAME: &'static str = "FolderListModel";
type Type = super::FolderListModel;
type ParentType = glib::Object;
type Interfaces = (gio::ListModel,);

Expand All @@ -32,10 +32,10 @@ pub mod model {
Self(RefCell::new(Vec::new()))
}
}
impl ObjectImpl for FolderModel {}
impl ListModelImpl for FolderModel {
impl ObjectImpl for FolderListModel {}
impl ListModelImpl for FolderListModel {
fn item_type(&self, _list_model: &Self::Type) -> glib::Type {
ConversationRowData::static_type()
FolderRowData::static_type()
}
fn n_items(&self, _list_model: &Self::Type) -> u32 {
self.0.borrow().len() as u32
Expand All @@ -47,16 +47,16 @@ pub mod model {
}
// Public part of the Model type.
glib::wrapper! {
pub struct FolderModel(ObjectSubclass<imp::FolderModel>) @implements gio::ListModel;
pub struct FolderListModel(ObjectSubclass<imp::FolderListModel>) @implements gio::ListModel;
}
// Constructor for new instances. This simply calls glib::Object::new()
impl FolderModel {
impl FolderListModel {
#[allow(clippy::new_without_default)]
pub fn new() -> FolderModel {
glib::Object::new(&[]).expect("Failed to create FolderModel")
pub fn new() -> FolderListModel {
glib::Object::new(&[]).expect("Failed to create FolderListModel")
}
pub fn append(&self, obj: &ConversationRowData) {
let self_ = imp::FolderModel::from_instance(self);
pub fn append(&self, obj: &FolderRowData) {
let self_ = imp::FolderListModel::from_instance(self);
let index = {
// Borrow the data only once and ensure the borrow guard is dropped
// before we emit the items_changed signal because the view
Expand All @@ -69,15 +69,15 @@ pub mod model {
self.items_changed(index as u32, 0, 1);
}
pub fn remove(&self, index: u32) {
let self_ = imp::FolderModel::from_instance(self);
let self_ = imp::FolderListModel::from_instance(self);
self_.0.borrow_mut().remove(index as usize);
// Emits a signal that 1 item was removed, 0 added at the position index
self.items_changed(index, 1, 0);
}
}
}

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

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

// Basic declaration of our type for the GObject type system
#[glib::object_subclass]
impl ObjectSubclass for ConversationRowData {
const NAME: &'static str = "ConversationRowData";
type Type = super::ConversationRowData;
impl ObjectSubclass for FolderRowData {
const NAME: &'static str = "FolderRowData";
type Type = super::FolderRowData;
type ParentType = glib::Object;
// Called once at the very beginning of instantiation of each instance and
// creates the data structure that contains all our state
fn new() -> Self {
Self {
conversation: Default::default(),
folder: Default::default(),
}
}
}
impl ObjectImpl for ConversationRowData {}
impl ObjectImpl for FolderRowData {}
}

// The public part
glib::wrapper! {
pub struct ConversationRowData(ObjectSubclass<imp::ConversationRowData>);
pub struct FolderRowData(ObjectSubclass<imp::FolderRowData>);
}
impl ConversationRowData {
pub fn new() -> ConversationRowData {
impl FolderRowData {
pub fn new() -> FolderRowData {
glib::Object::new(&[]).expect("Failed to create row data")
}
pub fn set_conversation(&self, conversation: models::Message) {
let self_ = imp::ConversationRowData::from_instance(self);
self_.conversation.replace(Some(conversation));
pub fn set_folder(&self, folder: models::Folder) {
let self_ = imp::FolderRowData::from_instance(self);
self_.folder.replace(Some(folder));
}
pub fn get_conversation(&self) -> Rc<RefCell<Option<models::Message>>> {
let self_ = imp::ConversationRowData::from_instance(self);
self_.conversation.clone()
pub fn get_folder(&self) -> Rc<RefCell<Option<models::Folder>>> {
let self_ = imp::FolderRowData::from_instance(self);
self_.folder.clone()
}
}
}
1 change: 1 addition & 0 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod conversation_messages_list;
mod database;
pub mod folder_conversations_list;
pub mod folders_list;
mod identity;

pub use database::{BareIdentity, Folder, IdentityType, Message, MessageFlags, NewBareIdentity, NewFolder, NewMessage};
Expand Down
7 changes: 6 additions & 1 deletion src/ui/stylesheet.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@define-color headerbar_background_color rgb(247,172,55);
@define-color headerbar_color rgba(30,30,30,0.7);
@define-color background_secondary_color rgba(238,238,238);

headerbar {
background: @headerbar_background_color;
Expand Down Expand Up @@ -28,7 +29,7 @@ headerbar button:active {

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

.conversation_viewer { background: #eee; }
.conversation_viewer { background: @background_secondary_color; }

.conversation_viewer .conversation_message_item { background: #fff; }

Expand Down Expand Up @@ -94,3 +95,7 @@ headerbar button:active {
.folder_conversation_item.unseen:selected .subject, .folder_conversation_item.unseen:selected .unseen_dot {
color: #fff;
}

.folders_sidebar {
background-color: @background_secondary_color;
}
Loading

0 comments on commit 935966c

Please sign in to comment.