[Xfce4-commits] <postler:master> Remove account awareness from messages to content
Christian Dywan
noreply at xfce.org
Sat Jul 2 17:08:06 CEST 2011
Updating branch refs/heads/master
to 9b2bcea2bc2f04739dccbff6df8e0878b6882137 (commit)
from 1e1af39ff36e313af95912ccf70e5b55b872d99b (commit)
commit 9b2bcea2bc2f04739dccbff6df8e0878b6882137
Author: Christian Dywan <christian at twotoasts.de>
Date: Fri Jul 1 22:52:49 2011 +0200
Remove account awareness from messages to content
postler/postler-accounts.vala | 4 --
postler/postler-bureau.vala | 16 +++----
postler/postler-content.vala | 12 +++---
postler/postler-folders.vala | 2 +-
postler/postler-message.vala | 15 +++++++
postler/postler-messages.vala | 93 ++++++++--------------------------------
6 files changed, 47 insertions(+), 95 deletions(-)
diff --git a/postler/postler-accounts.vala b/postler/postler-accounts.vala
index fdb0bc2..636b033 100644
--- a/postler/postler-accounts.vala
+++ b/postler/postler-accounts.vala
@@ -108,10 +108,6 @@ namespace Postler {
return folders[type];
}
- public bool can_delete () {
- return type == AccountType.SEARCH || folders[FolderType.TRASH] != null;
- }
-
public void set_folder (FolderType type, string folder) {
folders[type] = folder;
}
diff --git a/postler/postler-bureau.vala b/postler/postler-bureau.vala
index 5e70519..0dc4bea 100644
--- a/postler/postler-bureau.vala
+++ b/postler/postler-bureau.vala
@@ -134,16 +134,14 @@ public class Postler.Bureau : Gtk.Window {
}
void action_archive () {
- string folder = Path.get_basename (folders.selected_location);
- if (folder != messages.account_info.get_folder (FolderType.ARCHIVE))
+ if (messages.selected_folder_type != FolderType.ARCHIVE)
messages.move_selected (FolderType.ARCHIVE);
else
messages.move_selected (FolderType.INBOX);
}
void action_junk () {
- string folder = Path.get_basename (folders.selected_location);
- if (folder != messages.account_info.get_folder (FolderType.JUNK))
+ if (messages.selected_folder_type != FolderType.JUNK)
messages.move_selected (FolderType.JUNK);
else
messages.move_selected (FolderType.INBOX);
@@ -740,13 +738,11 @@ public class Postler.Bureau : Gtk.Window {
Postler.Messages messages = object as Postler.Messages;
bool state = messages.selected_message != null;
actions.get_action ("MessageFlag").sensitive = state;
- actions.get_action ("MessageArchive").sensitive = state
- && messages.account_info.get_folder (FolderType.ARCHIVE) != null;
+ actions.get_action ("MessageArchive").sensitive = state;
var action = actions.get_action ("MessageJunk");
- action.sensitive = state
- && messages.account_info.get_folder (FolderType.JUNK) != null;
+ action.sensitive = state;
action = actions.get_action ("MessageDelete");
- action.sensitive = state && messages.account_info.can_delete ();
+ action.sensitive = state;
});
var scrolled = new Postler.ScrolledWindow (messages);
messages_box.pack_end (scrolled, true, true, 0);
@@ -881,7 +877,7 @@ public class Postler.Bureau : Gtk.Window {
/* Never focus hidden widgets: assertion `WIDGET_REALIZED_FOR_EVENT */
if (messages.visible) {
messages.grab_focus ();
- messages.populate ("%INBOX", new Postler.AccountInfo ());
+ messages.populate ("%INBOX", FolderType.INBOX);
}
}
}
diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index 7517d03..27e6ee7 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -15,7 +15,6 @@ struct Postler.EmoticonMapping {
}
public class Postler.Content : WebKit.WebView {
- AccountInfo? selected_account;
public Message message { get; private set; }
string reply;
@@ -633,11 +632,11 @@ public class Postler.Content : WebKit.WebView {
public string? choose_from (Message the_message) {
/* See if recipient is among the accounts, otherwise pick a fallback */
+ var accounts = new Accounts ();
string? recipient = the_message.get_field ("to");
if (recipient != null) {
string from = Postler.Contact.address_from_string (recipient);
- var accounts = new Accounts ();
- foreach (var info in accounts.get_infos ()) {
+ foreach (unowned AccountInfo info in accounts.get_infos ()) {
if (info.address == null)
continue;
foreach (string address in info.address.split (",")) {
@@ -646,8 +645,10 @@ public class Postler.Content : WebKit.WebView {
}
}
}
- if (selected_account != null && selected_account.address != null)
- return selected_account.address.split (",")[0];
+ if (the_message.uri != null) {
+ var account_info = the_message.get_account (accounts);
+ return account_info.address.split (",")[0];
+ }
return null;
}
@@ -683,7 +684,6 @@ public class Postler.Content : WebKit.WebView {
}
public async bool display (Message the_message, AccountInfo? account_info=null) {
- selected_account = account_info;
try {
GLib.List<Message> thread;
if (the_message.stream != null) {
diff --git a/postler/postler-folders.vala b/postler/postler-folders.vala
index 2919ec9..f0b7a11 100644
--- a/postler/postler-folders.vala
+++ b/postler/postler-folders.vala
@@ -63,7 +63,7 @@ public class Postler.Folders : Gtk.Toolbar {
selected_label = label;
selected_type = folder_type;
selected_location = uri;
- messages.populate (uri, new Postler.AccountInfo ());
+ messages.populate (uri, folder_type);
});
return button;
}
diff --git a/postler/postler-message.vala b/postler/postler-message.vala
index 5eb1cd5..eda8159 100644
--- a/postler/postler-message.vala
+++ b/postler/postler-message.vala
@@ -228,6 +228,21 @@ namespace Postler {
file.move (destination_file, GLib.FileCopyFlags.NONE);
}
+ public AccountInfo? get_account (Accounts accounts) {
+ return_val_if_fail (uri != null, null);
+ /* Look for the account belonging to the message */
+ string folder = uri.substring (0, uri.pointer_to_offset (uri.rstr ("/")));
+ return_val_if_fail (folder.has_suffix ("/new") || folder.has_suffix ("/cur"), null);
+ folder = folder.substring (0, folder.pointer_to_offset (folder.rstr ("/")));
+ folder = folder.substring (0, folder.pointer_to_offset (folder.rstr ("/")));
+ folder = folder.substring (7, -1);
+ foreach (unowned AccountInfo info in accounts.get_infos ()) {
+ if (info.type != AccountType.SEARCH && info.path.has_prefix (folder))
+ return info;
+ }
+ return new AccountInfo ();
+ }
+
public Message.from_file (GLib.File file,
GLib.Cancellable? cancellable = null) throws GLib.Error {
read_from_file (file, cancellable);
diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index 2157d1a..459561a 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -18,15 +18,10 @@ public class Postler.Messages : Gtk.TreeView {
public Postler.Content content { get; set; }
public bool hide_read { get; set; }
+ public FolderType selected_folder_type { get; private set; }
public string? location { get; private set; }
- public AccountInfo account_info { get; private set; }
public Message? selected_message { get; private set; }
- string to_or_from;
- string[] headers = {};
- string[] filters = {};
- string[] folders = {};
-
enum Columns {
MESSAGE
}
@@ -283,7 +278,7 @@ public class Postler.Messages : Gtk.TreeView {
content_display_window.connect (content_new_window);
notify["hide-read"].connect (() => {
- search (filters[0] ?? "", headers[0] ?? "");
+ populate ("search:unread/1", FolderType.GENERIC);
});
}
@@ -398,62 +393,30 @@ public class Postler.Messages : Gtk.TreeView {
}
public void search (string filter, string header="subject") {
- headers = {};
- filters = {};
- populate (location, account_info, filter.down (), header);
+ populate (location, FolderType.GENERIC, filter.down (), header);
}
- public async bool populate (string? location, AccountInfo account_info,
+ public async bool populate (string location, FolderType folder_type,
string? filter=null, string? header=null) {
clear ();
- if (location == null)
- return true;
- if (Path.is_absolute (location)
- && !FileUtils.test (location + "/cur", FileTest.EXISTS))
- return true;
var now = GLib.Date ();
now.set_time_val (GLib.TimeVal ());
- string basename = Path.get_basename (location);
- if (basename == account_info.get_folder (FolderType.SENT)
- || basename == account_info.get_folder (FolderType.QUEUE)
- || basename == account_info.get_folder (FolderType.DRAFTS))
- to_or_from = "to";
- else
- to_or_from = "from";
+ selected_folder_type = folder_type;
var messages = new GLib.List<Message> ();
try {
if (location != this.location) {
- folders = {};
- headers = {};
- filters = {};
client = new Client ();
/* FIXME: The client emits, the callback isn't called */
client.got_message.connect (got_message);
- /* TODO: pass search: URI */
if (location.has_prefix ("search:"))
messages = yield client.get_messages ("%/INBOX/%");
else
messages = yield client.get_messages ("file://" + location + "%");
}
- if (filters[0] == null) {
- headers = { filter != null && filter != "" ? header : null };
- filters = { filter != "" ? filter : null };
-
- if (location.has_prefix ("search:")) {
- string query = location.substring (7);
- string[] parts = query.split ("/", 2);
- return_val_if_fail (parts[0] != null && parts[1] != null, false);
- headers += parts[0];
- if (filters[0] == null)
- filters = { parts[1].down () };
- filters += parts[1].down ();
- }
- }
-
foreach (var message in messages) {
store.insert_with_values (null, null, 0,
Columns.MESSAGE, message);
@@ -461,7 +424,7 @@ public class Postler.Messages : Gtk.TreeView {
/* Show error for failed search, ie. no results */
int n_messages = store.iter_n_children (null);
- if (filters[0] != null && n_messages == 0) {
+ if (location.has_prefix ("search:") && n_messages == 0) {
display_error (_("No messages found"),
_("Check the spelling or try a different filter."));
get_selection().set_select_function( () => { return false; });
@@ -481,7 +444,6 @@ public class Postler.Messages : Gtk.TreeView {
/* Avoid changing 'location' to not cause property notification */
if (this.location != location)
this.location = location;
- this.account_info = account_info;
return false;
}
@@ -602,7 +564,7 @@ public class Postler.Messages : Gtk.TreeView {
void display_message (Gtk.TreeIter iter) {
toggle_message_flag (iter, MessageFlags.MARK_READ, (message, result) => {
- content.display (message as Message, account_info);
+ content.display (message as Message);
});
}
@@ -622,7 +584,7 @@ public class Postler.Messages : Gtk.TreeView {
}
public void delete_selected () {
- if (location.has_suffix ("/" + account_info.get_folder (FolderType.TRASH)))
+ if (selected_folder_type == FolderType.TRASH)
move_selected (null);
else
move_selected (FolderType.TRASH);
@@ -691,16 +653,8 @@ public class Postler.Messages : Gtk.TreeView {
string? destination_path;
if (type == null)
destination_path = null;
- else if (account_info.type == AccountType.SEARCH)
+ else
destination_path = "/"; /* Nonsense path, in case of later errors */
- else {
- return_if_fail (account_info.get_folder (type) != null);
- destination_path = account_info.path + "/" + account_info.get_folder (type);
- if (!ensure_folder (destination_path)) {
- GLib.critical (_("Folders for moving messages couldn't be created."));
- return;
- }
- }
GLib.List<Gtk.TreePath> paths;
var references = new GLib.List<Gtk.TreeRowReference> ();
@@ -715,26 +669,17 @@ public class Postler.Messages : Gtk.TreeView {
Message message;
model.get (iter, Columns.MESSAGE, out message);
try {
- if (account_info.type == AccountType.SEARCH) {
- /* Look for the account belonging to the message */
- string location = message.get_path ();
- string inbox_folder = location.substring (0,
- location.pointer_to_offset (location.rstr ("/")));
- return_if_fail (inbox_folder.has_suffix ("/INBOX/new")
- || inbox_folder.has_suffix ("/INBOX/cur"));
- string account_folder = inbox_folder.slice (0, -10);
- string? folder_name = null;
- foreach (var info in accounts.get_infos ()) {
- if (info.path == account_folder) {
- folder_name = info.get_folder (type);
- break;
- }
- }
- return_if_fail (folder_name != null);
- destination_path = account_folder + "/" + folder_name;
- return_if_fail (destination_path != null);
+ AccountInfo account_info = message.get_account (accounts);
+ return_if_fail (account_info != null);
+ string? folder_name = null;
+ foreach (var info in accounts.get_infos ()) {
+ if (info.path == account_info.path) {
+ folder_name = info.get_folder (type);
+ break;
}
-
+ }
+ destination_path = account_info.path + "/" + folder_name;
+ return_if_fail (destination_path != null);
message.move (destination_path);
/* Move to next, more recent message row */
More information about the Xfce4-commits
mailing list