Skip to content

Commit

Permalink
Improve folder ordering and naming
Browse files Browse the repository at this point in the history
  • Loading branch information
matzipan committed Sep 26, 2023
1 parent 327dae7 commit a405645
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 10 deletions.
86 changes: 77 additions & 9 deletions src/models/folders_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,69 @@ use std::rc::Rc;
use crate::models;
use crate::services;

use super::Folder;

enum FolderType {
Inbox,
Important,
Starred,
Sent,
Drafts,
Archive,
All,
Spam,
Bin,
Other,
}

fn get_order_index_for_folder_type(folder_type: FolderType) -> u32 {
match folder_type {
FolderType::Inbox => 1,
FolderType::Important => 2,
FolderType::Starred => 3,
FolderType::Sent => 4,
FolderType::Drafts => 5,
FolderType::Archive => 6,
FolderType::All => 7,
FolderType::Spam => 8,
FolderType::Bin => 9,
FolderType::Other => 10,
}
}

fn get_folder_type_from_folder(folder: &Folder) -> FolderType {
match folder.folder_name.as_str() {
"INBOX" => FolderType::Inbox,
"Important" => FolderType::Important,
"Sent" => FolderType::Sent,
"Spam" => FolderType::Spam,
"Junk" => FolderType::Spam,
"Drafts" => FolderType::Drafts,
"Archive" => FolderType::Archive,
"All" => FolderType::All,
"Starred" => FolderType::Starred,
"Bin" => FolderType::Bin,
"Trash" => FolderType::Bin,
&_ => FolderType::Other,
}
}

pub fn get_folder_presentation_name(folder: &Folder) -> &str {
let folder_type = get_folder_type_from_folder(folder);
match folder_type {
FolderType::Inbox => "Inbox",
FolderType::Important => "Important",
FolderType::Starred => "Starred",
FolderType::Sent => "Sent",
FolderType::Drafts => "Drafts",
FolderType::Archive => "Archive",
FolderType::All => "All",
FolderType::Spam => "Spam",
FolderType::Bin => "Bin",
FolderType::Other => &folder.folder_name,
}
}

pub mod model {
use super::*;
use row_data::FolderRowData;
Expand Down Expand Up @@ -93,16 +156,21 @@ pub mod model {
.expect("Unable to get bare identities"),
);

let mut folders_list = self_
.store
.borrow()
.as_ref()
.unwrap()
.get_folders(&self_.bare_identities.borrow()[0])
.expect("Unable to get folders");

folders_list.sort_unstable_by_key(|folder| {
let folder_type = get_folder_type_from_folder(folder);
get_order_index_for_folder_type(folder_type)
});

// @TODO add support for multiple identities
self_.folders.replace(
self_
.store
.borrow()
.as_ref()
.unwrap()
.get_folders(&self_.bare_identities.borrow()[0])
.expect("Unable to get folders"),
);
self_.folders.replace(folders_list);

let new_count = self_.n_items();

Expand Down
4 changes: 3 additions & 1 deletion src/ui/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ use self::folder_conversation_item::FolderConversationItem;
use self::folders_list_item::FoldersListItem;
use self::message_view::MessageView;

use crate::models::folders_list::get_folder_presentation_name;

mod imp {
use gtk::{
glib::{ParamSpec, Value},
Expand Down Expand Up @@ -150,7 +152,7 @@ mod imp {

let name_label = gtk::Label::new(None);

name_label.set_text(&folder.folder_name);
name_label.set_text(get_folder_presentation_name(folder));
name_label.set_halign(gtk::Align::Start);

box_item.append(&name_label);
Expand Down

0 comments on commit a405645

Please sign in to comment.