[Xfce4-commits] <postler:master> Implement flag updates, and marking messages as read when opening
Christian Dywan
noreply at xfce.org
Sat Jul 10 00:24:10 CEST 2010
Updating branch refs/heads/master
to 8ffe3a6aa4a3f414a06e8a1563b15b9e109d1790 (commit)
from cef287838a650dbc392cee4aacd986ec1cd14e2d (commit)
commit 8ffe3a6aa4a3f414a06e8a1563b15b9e109d1790
Author: Christian Dywan <christian at twotoasts.de>
Date: Tue Jun 29 18:18:03 2010 +0200
Implement flag updates, and marking messages as read when opening
postler/postler-messages.vala | 66 +++++++++++++++++++++++++++++++++++++++--
tests/parsing.vala | 20 ++++++++++++
tests/wscript_build | 2 +-
3 files changed, 84 insertions(+), 4 deletions(-)
diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index 45661f9..41b692b 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -336,14 +336,24 @@ public class Postler.Messages : Gtk.TreeView {
return GLib.Time.local (timestamp).format ("%x %X");
}
+ static string flags_from_filename (string filename) {
+ unowned string? flagstart = null;
+ unowned string? versionstart = filename.chr (-1, ':');
+ if (versionstart != null)
+ flagstart = versionstart.chr (-1, ',');
+ if (flagstart != null)
+ return flagstart.substring (1);
+ return "";
+ }
+
static string parse_flags (string name, out string flagged, out int weight) {
/* format "unique:2,DFPRST", ordered alphabetically */
unowned string status = Gtk.STOCK_NEW;
- unowned string flagstart = name.chr (-1, ':');
- if (flagstart == null)
+ string flags = flags_from_filename (name);
+ if (flags == "")
return status;
- foreach (var character in name.to_utf8 ()) {
+ foreach (var character in flags.to_utf8 ()) {
switch (character) {
case 'D':
status = STOCK_EMBLEM_DRAFT;
@@ -563,9 +573,58 @@ public class Postler.Messages : Gtk.TreeView {
return false;
}
+ internal static string toggle_flag (string location, char flag) {
+ string folder = Path.get_dirname (location);
+ if (folder.has_suffix ("/new"))
+ folder = folder.slice (0, -4) + "/cur";
+ string flags = flags_from_filename (location);
+ var new_flags = new StringBuilder ();
+ bool did_include_flag = false;
+ foreach (var character in flags.to_utf8 ()) {
+ if (character < flag)
+ new_flags.append_c (character);
+ else if (character == flag)
+ did_include_flag = true;
+ else if (character > flag) {
+ if (!did_include_flag) {
+ did_include_flag = true;
+ new_flags.append_c (flag);
+ }
+ new_flags.append_c (character);
+ }
+ }
+ if (!did_include_flag)
+ new_flags.append_c (flag);
+ return folder + "/" + generate_maildir_filename (new_flags.str);
+ }
+
+ void toggle_message_flag (Gtk.TreeIter sort_iter, ref string location, char flag) {
+ string new_location = toggle_flag (location, flag);
+ if (FileUtils.rename (location, new_location) == 0) {
+ location = new_location;
+ int font_weight = Pango.Weight.BOLD;
+ string? flagged = null;
+ string status = parse_flags (location, out flagged, out font_weight);
+
+ Gtk.TreeIter child_iter;
+ sort.convert_iter_to_child_iter (out child_iter, sort_iter);
+ store.set (child_iter,
+ Columns.FLAGGED, flagged,
+ Columns.STATUS, status,
+ Columns.LOCATION, location,
+ Columns.WEIGHT, font_weight);
+ }
+ }
+
+ void mark_message_read (Gtk.TreeIter sort_iter, ref string location) {
+ if (!flags_from_filename (location).contains ("S"))
+ toggle_message_flag (sort_iter, ref location, 'S');
+ }
+
void display_message (Gtk.TreeIter sort_iter) {
string location;
sort.get (sort_iter, Columns.LOCATION, out location);
+ mark_message_read (sort_iter, ref location);
content.display (location);
selected_location = location;
}
@@ -673,6 +732,7 @@ public class Postler.Messages : Gtk.TreeView {
if (path != null && sort.get_iter (out sort_iter, path)) {
string location;
sort.get (sort_iter, Columns.LOCATION, out location);
+ mark_message_read (sort_iter, ref location);
Postler.App.spawn_module ("content", location);
}
}
diff --git a/tests/parsing.vala b/tests/parsing.vala
index ffa5e9f..bba7015 100644
--- a/tests/parsing.vala
+++ b/tests/parsing.vala
@@ -20,6 +20,25 @@ struct TestCase {
public string expected;
}
+const TestCase[] filenames = {
+ { "127.162_10.blutschink,U=129:2,", ":2,S" },
+ { "127.162_10.blutschink,U=129:2,S", ":2," },
+ { "127.162_10.blutschink,U=129:2,T", ":2,ST" },
+ { "127.162_10.blutschink,U=129:2,D", ":2,DS" },
+ { "127.162_10.blutschink,U=129:2,DT", ":2,DST" },
+ { "127.162_10.blutschink,U=129:2,DST", ":2,DT" }
+};
+
+void parsing_filename_flags () {
+ foreach (var filename in filenames) {
+ string toggled = Postler.Messages.toggle_flag (filename.data, 'S');
+ string expected = filename.expected;
+ if (expected == null)
+ expected = filename.data.chr (-1, ':');
+ assert_string_equal (toggled.chr (-1, ':'), expected);
+ }
+}
+
const TestCase[] addresses = {
{ "Klaus <klaus at heim.at>", "Klaus klaus at heim.at" },
{ "Klaus Kaufmann <klausk at heim.at>", "Klaus Kaufmann klausk at heim.at" },
@@ -100,6 +119,7 @@ void parsing_headers_encoded () {
void main (string[] args) {
Test.init (ref args);
+ Test.add_func ("/parsing/filename/flags", parsing_filename_flags);
Test.add_func ("/parsing/headers/address", parsing_headers_address);
Test.add_func ("/parsing/headers/linkify", parsing_headers_linkify);
Test.add_func ("/parsing/headers/mailer", parsing_headers_mailer);
diff --git a/tests/wscript_build b/tests/wscript_build
index 84fb785..dfdaa25 100644
--- a/tests/wscript_build
+++ b/tests/wscript_build
@@ -36,7 +36,7 @@ for test in tests:
obj.source = source
obj.find_sources_in_dirs ('../postler', excludes=['postler-reader.vala'])
obj.vapi_dirs = '../postler'
- obj.packages = 'config postler gio-2.0 gtk+-2.0 unique-1.0 webkit-1.0'
+ obj.packages = 'config postler posix gio-2.0 gtk+-2.0 unique-1.0 webkit-1.0'
obj.uselib = 'GIO GTK UNIQUE WEBKIT'
obj.unit_test = 1
More information about the Xfce4-commits
mailing list