[Xfce4-commits] <postler:master> Update accountrc after changing accounts
Christian Dywan
noreply at xfce.org
Tue Nov 30 17:20:04 CET 2010
Updating branch refs/heads/master
to 3062139bebde6db1b2da7f4022372f037adab61a (commit)
from 35f81f8c100cca7651e45004778e68f1c8cca954 (commit)
commit 3062139bebde6db1b2da7f4022372f037adab61a
Author: Bernd Prünster <bernd.pruenster at gmail.com>
Date: Mon Nov 29 23:52:49 2010 +0100
Update accountrc after changing accounts
When an account is added or modified, keyfile values are updated,
default values won't be saved.
Search accounts load and save a search path now.
Fixes: https://bugs.launchpad.net/postler/+bug/671696
postler/postler-accounts.vala | 84 ++++++++++++++++++++++++++++++++++++++---
postler/postler-folders.vala | 7 +--
2 files changed, 81 insertions(+), 10 deletions(-)
diff --git a/postler/postler-accounts.vala b/postler/postler-accounts.vala
index ead98dc..219b959 100644
--- a/postler/postler-accounts.vala
+++ b/postler/postler-accounts.vala
@@ -69,6 +69,7 @@ namespace Postler {
{ null, null, N_("Junk"), junk_folders, junk_folders.length }
};
const MailFolder generic_folder = { null, Gtk.STOCK_DIRECTORY, null, null };
+ const string hide_folder_default = "Apple Mail To Do";
public class AccountInfo : GLib.Object {
public string name;
@@ -85,7 +86,7 @@ namespace Postler {
public string sync;
public string reply;
public string organization;
- public string hide = "Apple Mail To Do";
+ public string hide = hide_folder_default;
public string[]? folders = { null, null, null, null, null, null, null };
public unowned string? get_folder (FolderType type) {
@@ -153,6 +154,78 @@ public class Postler.Accounts : GLib.Object {
reload ();
}
+ void update_accountrc () {
+ try {
+ foreach (AccountInfo account_info in infos) {
+ string group = account_info.name ?? account_info.address;
+ if (account_info.name != null)
+ keyfile.set_string (group, "name", account_info.name);
+
+ if (account_info.type == AccountType.MAILDIR) {
+ keyfile.set_string (group, "type", "maildir");
+ if (account_info.path != null
+ && !account_info.path.contains (data_path))
+ keyfile.set_string (group, "path", account_info.path);
+ if (account_info.hide != null
+ && account_info.hide != hide_folder_default)
+ keyfile.set_string (group, "hide", account_info.hide);
+ }
+ else if (account_info.type == AccountType.IMAP) {
+ keyfile.set_string (group, "type", "imap");
+ if (account_info.realname != null)
+ keyfile.set_string (group, "realname", account_info.realname);
+ if (account_info.address != null)
+ keyfile.set_string (group, "address", account_info.address);
+ if (account_info.username != null)
+ keyfile.set_string (group, "username", account_info.username);
+ if (account_info.password != null)
+ keyfile.set_string (group, "password", account_info.password);
+ if (account_info.prefix != null)
+ keyfile.set_string (group, "prefix", account_info.prefix);
+ if (account_info.receive != null)
+ keyfile.set_string (group, "receive", account_info.receive);
+ if (account_info.send != null)
+ keyfile.set_string (group, "send", account_info.send);
+ if (account_info.certificate != null)
+ keyfile.set_string (group, "certificate",
+ account_info.certificate);
+ if (account_info.sync != null)
+ keyfile.set_string (group, "sync", account_info.sync);
+ if (account_info.reply != null)
+ keyfile.set_string (group, "reply", account_info.reply);
+ if (account_info.organization != null)
+ keyfile.set_string (group, "organization",
+ account_info.organization);
+ if (account_info.hide != null
+ && account_info.hide != hide_folder_default)
+ keyfile.set_string (group, "hide", account_info.hide);
+ }
+ else if (account_info.type == AccountType.SEARCH) {
+ keyfile.set_string (group, "type", "search");
+ if (account_info.path != null)
+ keyfile.set_string (group, "path", account_info.path);
+ }
+ else
+ assert_not_reached ();
+ }
+ FileUtils.set_contents (config_path, keyfile.to_data ());
+ }
+ catch (GLib.Error error) {
+ GLib.critical ("Failed to save \"%s\": %s", config_path, error.message);
+ }
+ }
+
+ void delete_account (AccountInfo info) {
+ try {
+ string group = info.name ?? info.address;
+ keyfile.remove_group (group);
+ FileUtils.set_contents (config_path, keyfile.to_data ());
+ }
+ catch (GLib.Error error) {
+ GLib.critical ("Failed to save \"%s\": %s", config_path, error.message);
+ }
+ }
+
void reload () {
infos = new GLib.List<AccountInfo> ();
var info = new AccountInfo ();
@@ -228,9 +301,8 @@ public class Postler.Accounts : GLib.Object {
}
else if (type == "search") {
info.type = AccountType.SEARCH;
- info.path = "search:%s/%s".printf (
- keyfile.get_string (group, "header"),
- keyfile.get_string (group, "filter"));
+ if (keyfile.has_key (group, "path"))
+ info.path = keyfile.get_string (group, "path");
}
else
throw new GLib.FileError.FAILED (
@@ -261,12 +333,12 @@ public class Postler.Accounts : GLib.Object {
if (info.type == AccountType.IMAP)
info.path = data_path + info.name;
infos.append (info);
- /* TODO: Update accountrc file */
+ update_accountrc ();
}
public virtual signal void remove_info (AccountInfo info) {
infos.remove (info);
- /* TODO: Update accountrc file */
+ delete_account (info);
}
string? get_tool_configuration_filename (string? send, AccountInfo info) throws GLib.FileError {
diff --git a/postler/postler-folders.vala b/postler/postler-folders.vala
index 1a78c2b..d4fab10 100644
--- a/postler/postler-folders.vala
+++ b/postler/postler-folders.vala
@@ -395,10 +395,9 @@ public class Postler.Folders : Gtk.TreeView {
Columns.INFO, out account_info);
if (account_info != null) {
account_info.hide += "," + name;
- var account_infos = new GLib.List<AccountInfo> ();
- account_infos.prepend (account_info);
- populate_accounts (account_infos);
- /* FIXME: Update accounts */
+ accounts.remove_info (account_info);
+ accounts.add_info (account_info);
+ populate ();
}
}
});
More information about the Xfce4-commits
mailing list