[Xfce4-commits] <postler:master> Render smarter inbox labels and add a display name
Christian Dywan
noreply at xfce.org
Sat Jan 8 00:50:01 CET 2011
Updating branch refs/heads/master
to 13592c762d306bc3006f0e6ed99411177a89a58f (commit)
from 237e914fef8806febc0e4ebccabb627777840b7d (commit)
commit 13592c762d306bc3006f0e6ed99411177a89a58f
Author: Christian Dywan <christian at twotoasts.de>
Date: Sat Jan 8 00:45:50 2011 +0100
Render smarter inbox labels and add a display name
A single account is "Inbox", a unique provider is "gmail"
Fixes: https://bugs.launchpad.net/postler/+bug/699740
postler/postler-accounts.vala | 33 ++++++++++++++++++++++++++++++++-
postler/postler-folders.vala | 22 ++++++----------------
postler/postler-service.vala | 2 +-
3 files changed, 39 insertions(+), 18 deletions(-)
diff --git a/postler/postler-accounts.vala b/postler/postler-accounts.vala
index 49b6437..6314ca4 100644
--- a/postler/postler-accounts.vala
+++ b/postler/postler-accounts.vala
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2010 Christian Dywan <christian at twotoasts.de>
+ Copyright (C) 2011 Christian Dywan <christian at twotoasts.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -75,6 +75,7 @@ namespace Postler {
public class AccountInfo : GLib.Object {
public string name;
+ public string display_name;
public AccountType type;
public string realname;
public string address;
@@ -158,6 +159,33 @@ public class Postler.Accounts : GLib.Object {
reload ();
}
+ void update_display_names () {
+ /* A single account is "Inbox", a unique provider is "gmail" */
+ uint num_accounts = 0;
+ foreach (var info in infos) {
+ if (info.type != AccountType.SEARCH)
+ num_accounts++;
+ string? domain = (info.address ?? info.name).rstr ("@");
+ if (domain != null) {
+ foreach (var account_info in infos) {
+ unowned string address = account_info.address ?? account_info.name;
+ if (account_info != info && domain in address) {
+ domain = null;
+ break;
+ }
+ }
+ domain = domain != null ? domain.next_char () : null;
+ if (domain != null)
+ domain = domain.split (".", 2)[0];
+ }
+ info.display_name = domain ?? info.name;
+ }
+ if (num_accounts == 1)
+ foreach (var info in infos)
+ if (info.type != AccountType.SEARCH)
+ info.display_name = _("Inbox");
+ }
+
void write_keyfile () throws Error {
if (DirUtils.create_with_parents (config_path, 0700) != 0)
throw new GLib.FileError.FAILED (_("Config folder couldn't be created."));
@@ -175,6 +203,8 @@ public class Postler.Accounts : GLib.Object {
}
else if (infos.length () == 0)
FileUtils.unlink (filename);
+
+ update_display_names ();
}
public void update () {
@@ -321,6 +351,7 @@ public class Postler.Accounts : GLib.Object {
}
}
infos.reverse ();
+ update_display_names ();
}
public string[] get_folders () {
diff --git a/postler/postler-folders.vala b/postler/postler-folders.vala
index a841cae..08f6ed0 100644
--- a/postler/postler-folders.vala
+++ b/postler/postler-folders.vala
@@ -44,7 +44,7 @@ public class Postler.Folders : Gtk.TreeView {
/* Local folders */
local_info = new AccountInfo ();
- local_info.name = _("Local");
+ local_info.display_name = _("Local");
local_info.type = AccountType.MAILDIR;
local_info.path = null;
unowned string mail = Environment.get_variable ("MAILDIR");
@@ -135,17 +135,7 @@ public class Postler.Folders : Gtk.TreeView {
return name;
}
- public bool populate_accounts (GLib.List<AccountInfo> infos, int count=-1) {
- int num_accounts = 0;
- if (count > -1)
- num_accounts = count;
- else {
- foreach (unowned AccountInfo account_info in infos) {
- if (account_info.type != AccountType.SEARCH)
- num_accounts++;
- }
- }
- bool one_account = num_accounts < 2;
+ public bool populate_accounts (GLib.List<AccountInfo> infos) {
bool need_update = false;
/* foreach (unowned AccountInfo account_info in infos) { */
@@ -191,11 +181,11 @@ public class Postler.Folders : Gtk.TreeView {
monitor.changed.connect ((monitor, file, other, event) => {
var account_infos = new GLib.List<AccountInfo> ();
account_infos.prepend (account_info);
- populate_accounts (account_infos, num_accounts);
+ populate_accounts (account_infos);
});
store.insert_with_values (out account_iter, null, -1,
Columns.ICON, Gtk.STOCK_DIALOG_ERROR,
- Columns.NAME, account_info.name,
+ Columns.NAME, account_info.display_name,
Columns.ELLIPSIZE, Pango.EllipsizeMode.MIDDLE,
Columns.LOCATION, null,
Columns.INFO, account_info,
@@ -256,7 +246,7 @@ public class Postler.Folders : Gtk.TreeView {
account_info.path + "/" + name + "/new");
var monitor = msg_dir.monitor_directory (0, null);
string path = store.get_string_from_iter (account_iter);
- string label = one_account ? _("Inbox") : account_info.name;
+ string label = account_info.display_name;
monitor.changed.connect ((monitor, file, other, event) => {
unread_monitor_changed (msg_dir, path, label);
});
@@ -276,7 +266,7 @@ public class Postler.Folders : Gtk.TreeView {
monitor.changed.connect ((monitor, file, other, event) => {
var account_infos = new GLib.List<AccountInfo> ();
account_infos.prepend (account_info);
- populate_accounts (account_infos, num_accounts);
+ populate_accounts (account_infos);
});
unowned MailFolder folder = account_info.get_localized_folder (name);
diff --git a/postler/postler-service.vala b/postler/postler-service.vala
index 6c80020..0583ddb 100644
--- a/postler/postler-service.vala
+++ b/postler/postler-service.vala
@@ -49,7 +49,7 @@ namespace Postler {
return;
var item = new Indicate.Indicator.with_server (indicator);
- item.set_property ("name", info.name);
+ item.set_property ("name", info.display_name);
item.set_property ("url", info.path);
item.set_property ("draw-attention", "true");
item.user_display.connect ((item) => {
More information about the Xfce4-commits
mailing list