[geary/wip/730682-refine-convo-list: 7/12] Minor code clean up.
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/730682-refine-convo-list: 7/12] Minor code clean up.
- Date: Sun, 15 Oct 2017 10:46:39 +0000 (UTC)
commit 3d45f5cd51f96af0c6e2c13d351b9f6556a6e70d
Author: Michael James Gratton <mike vee net>
Date: Sun Oct 15 07:37:12 2017 +1030
Minor code clean up.
* src/client/components/main-window.vala: Reorg members and
rename some vars.
* src/client/conversation-list/conversation-list.vala: Rename
set_model to bind_model to ensure call sites can't pass in
a model other than the one it actually needs.
src/client/components/main-window.vala | 22 ++++++++++---------
.../conversation-list/conversation-list-item.vala | 3 +-
.../conversation-list/conversation-list-model.vala | 17 +++++++++------
.../conversation-list/conversation-list.vala | 4 +-
4 files changed, 25 insertions(+), 21 deletions(-)
---
diff --git a/src/client/components/main-window.vala b/src/client/components/main-window.vala
index 0d5deb0..c734351 100644
--- a/src/client/components/main-window.vala
+++ b/src/client/components/main-window.vala
@@ -15,11 +15,6 @@ public class MainWindow : Gtk.ApplicationWindow {
set { base.set_application(value); }
}
- public Geary.Folder? current_folder { get; private set; default = null; }
-
- private Geary.AggregateProgressMonitor progress_monitor = new Geary.AggregateProgressMonitor();
- private Geary.ProgressMonitor? folder_progress = null;
-
// Used to save/load the window state between sessions.
public int window_width { get; set; }
public int window_height { get; set; }
@@ -33,8 +28,15 @@ public class MainWindow : Gtk.ApplicationWindow {
public ConversationList conversation_list { get; private set; }
public ConversationViewer conversation_viewer { get; private set; default = new ConversationViewer(); }
public StatusBar status_bar { get; private set; default = new StatusBar(); }
+
+ public Geary.Folder? current_folder { get; private set; default = null; }
+
+ private Geary.AggregateProgressMonitor progress_monitor = new Geary.AggregateProgressMonitor();
+ private Geary.ProgressMonitor? folder_progress = null;
private Gee.Set<Geary.App.Conversation> selected_conversations = new
Gee.HashSet<Geary.App.Conversation>();
+
private MonitoredSpinner spinner = new MonitoredSpinner();
+
[GtkChild]
private Gtk.Box main_layout;
[GtkChild]
@@ -283,17 +285,17 @@ public class MainWindow : Gtk.ApplicationWindow {
this.progress_monitor.remove(old_model.conversations.progress_monitor);
}
- Geary.App.ConversationMonitor? conversations =
+ Geary.App.ConversationMonitor? new_monitor =
this.application.controller.current_conversations;
- if (conversations != null) {
+ if (new_monitor != null) {
ConversationListStore new_model =
- new ConversationListStore(conversations);
+ new ConversationListStore(new_monitor);
+ this.progress_monitor.add(new_monitor.progress_monitor);
this.progress_monitor.add(new_model.preview_monitor);
- this.progress_monitor.add(conversations.progress_monitor);
this.conversation_list_view.set_model(new_model);
- this.conversation_list.set_model(conversations);
+ this.conversation_list.bind_model(new_monitor);
}
if (old_model != null) {
diff --git a/src/client/conversation-list/conversation-list-item.vala
b/src/client/conversation-list/conversation-list-item.vala
index 1d1dbea..0a6ea0c 100644
--- a/src/client/conversation-list/conversation-list-item.vala
+++ b/src/client/conversation-list/conversation-list-item.vala
@@ -15,8 +15,7 @@ public class ConversationListItem : Gtk.Grid {
private const string UNREAD_CLASS = "geary-unread";
// Translators: This stands in place for the user's name in the
- // list of participants in a conversation. Should be short,
- // ideally.
+ // list of participants in a conversation.
private const string ME = _("Me");
private class ParticipantDisplay : Geary.BaseObject, Gee.Hashable<ParticipantDisplay> {
diff --git a/src/client/conversation-list/conversation-list-model.vala
b/src/client/conversation-list/conversation-list-model.vala
index 93dafa6..802c102 100644
--- a/src/client/conversation-list/conversation-list-model.vala
+++ b/src/client/conversation-list/conversation-list-model.vala
@@ -65,6 +65,9 @@ public class ConversationListModel : Geary.BaseObject, GLib.ListModel {
return this.conversations.get_item(position) as Geary.App.Conversation;
}
+ // XXX Something like this should be enabled so that if flags like
+ // received date changes, the ordering will change to reflect
+ // that.
// private void update(Geary.App.Conversation target) {
// // XXX this is horribly inefficient
// this.conversations.sort((a, b) => {
@@ -76,14 +79,14 @@ public class ConversationListModel : Geary.BaseObject, GLib.ListModel {
private uint get_index(Geary.App.Conversation target)
throws Error {
// Yet Another Binary Search Implementation :<
- uint lower = 0;
- uint upper = get_n_items();
- while (lower <= upper) {
- uint mid = (uint) Math.floor((upper + lower) / 2);
+ int lower = 0;
+ int upper = ((int) get_n_items()) - 1;
+ while (lower < upper) {
+ int mid = (int) Math.floor((upper + lower) / 2);
int cmp = model_sort(get_conversation(mid), target);
- if (cmp < 1) {
+ if (cmp < 0) {
lower = mid + 1;
- } else if (cmp > 1) {
+ } else if (cmp > 0) {
upper = mid - 1;
} else {
return mid;
@@ -110,7 +113,7 @@ public class ConversationListModel : Geary.BaseObject, GLib.ListModel {
try {
this.conversations.remove(get_index(convo));
} catch (Error err) {
- debug("Failed to remove conversation");
+ debug("Failed to remove conversation: %s", err.message);
}
}
}
diff --git a/src/client/conversation-list/conversation-list.vala
b/src/client/conversation-list/conversation-list.vala
index 6ef40f5..ddb2735 100644
--- a/src/client/conversation-list/conversation-list.vala
+++ b/src/client/conversation-list/conversation-list.vala
@@ -47,12 +47,12 @@ public class ConversationList : Gtk.ListBox {
});
}
- public void set_model(Geary.App.ConversationMonitor monitor) {
+ public new void bind_model(Geary.App.ConversationMonitor monitor) {
this.model = new ConversationListModel(monitor);
Geary.Folder displayed = monitor.folder;
Gee.List<Geary.RFC822.MailboxAddress> account_addresses =
displayed.account.information.get_all_mailboxes();
bool use_to = (displayed != null) && displayed.special_folder_type.is_outgoing();
- bind_model(this.model, (convo) => {
+ base.bind_model(this.model, (convo) => {
return new ConversationListItem(convo as Geary.App.Conversation,
account_addresses,
use_to,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]