From ddbd4c7213fc8e05caaff308979df38a15f58bd4 Mon Sep 17 00:00:00 2001 From: Eric Gregory Date: Wed, 24 Apr 2013 12:22:32 -0700 Subject: [PATCH] Closes #5745 libgee 0.8 --- bindings/vapi/unity.deps | 6 + bindings/vapi/unity.vapi | 438 ++++++++++++++++++ debian/control | 4 +- src/CMakeLists.txt | 6 +- .../account-dialog-account-list-pane.vala | 2 +- src/client/accounts/account-dialog.vala | 4 +- src/client/composer/composer-window.vala | 3 +- .../folder-list-account-branch.vala | 3 +- src/client/geary-controller.vala | 2 +- .../models/conversation-list-store.vala | 14 +- .../notification/new-messages-monitor.vala | 5 +- src/client/sidebar/sidebar-branch.vala | 11 +- src/client/ui/folder-menu.vala | 4 +- src/client/views/conversation-viewer.vala | 7 +- .../views/formatted-conversation-data.vala | 14 +- src/dbusservice/database.vala | 4 +- src/engine/api/geary-composed-email.vala | 2 +- .../api/geary-conversation-monitor.vala | 48 +- src/engine/api/geary-credentials.vala | 12 +- src/engine/api/geary-email-flag.vala | 10 +- src/engine/api/geary-email-flags.vala | 14 +- src/engine/api/geary-email-identifier.vala | 15 +- src/engine/api/geary-email.vala | 53 +-- src/engine/api/geary-folder-path.vala | 30 +- .../api/geary-folder-supports-archive.vala | 3 +- .../api/geary-folder-supports-mark.vala | 3 +- .../api/geary-folder-supports-remove.vala | 3 +- src/engine/common/common-message-data.vala | 61 +-- src/engine/imap-db/imap-db-account.vala | 6 +- .../imap-db/imap-db-email-identifier.vala | 2 +- src/engine/imap-db/imap-db-folder.vala | 7 +- .../outbox/smtp-outbox-email-identifier.vala | 2 +- .../imap-db/outbox/smtp-outbox-folder.vala | 2 +- .../gmail/imap-engine-gmail-account.vala | 3 +- .../imap-engine-account-synchronizer.vala | 2 +- .../imap-engine-email-flag-watcher.vala | 7 +- .../imap-engine-email-prefetcher.vala | 8 +- .../imap-engine-generic-account.vala | 18 +- .../imap-engine-generic-folder.vala | 17 +- .../replay-ops/imap-engine-copy-email.vala | 3 +- .../replay-ops/imap-engine-expunge-email.vala | 3 +- .../replay-ops/imap-engine-fetch-email.vala | 2 +- .../imap-engine-list-email-by-sparse-id.vala | 7 +- .../replay-ops/imap-engine-list-email.vala | 7 +- .../replay-ops/imap-engine-mark-email.vala | 3 +- .../replay-ops/imap-engine-move-email.vala | 3 +- .../yahoo/imap-engine-yahoo-account.vala | 3 +- src/engine/imap/api/imap-email-flags.vala | 8 +- .../imap/api/imap-email-identifier.vala | 8 +- .../imap/api/imap-email-properties.vala | 12 +- .../imap/api/imap-folder-properties.vala | 2 +- src/engine/imap/message/imap-flag.vala | 10 +- .../imap/message/imap-message-data.vala | 23 +- src/engine/imap/message/imap-tag.vala | 10 +- .../transport/imap-client-connection.vala | 3 +- .../imap/transport/imap-client-session.vala | 8 +- .../nonblocking/nonblocking-mailbox.vala | 2 +- src/engine/rfc822/rfc822-message-data.vala | 11 +- src/engine/rfc822/rfc822-utils.vala | 2 +- src/engine/util/util-collection.vala | 38 +- src/engine/util/util-files.vala | 22 + .../util/util-generic-capabilities.vala | 5 +- src/engine/util/util-interfaces.vala | 79 ---- src/engine/util/util-singleton.vala | 29 +- src/engine/util/util-string.vala | 12 +- 65 files changed, 744 insertions(+), 426 deletions(-) create mode 100644 bindings/vapi/unity.deps create mode 100644 bindings/vapi/unity.vapi diff --git a/bindings/vapi/unity.deps b/bindings/vapi/unity.deps new file mode 100644 index 00000000..82127efa --- /dev/null +++ b/bindings/vapi/unity.deps @@ -0,0 +1,6 @@ +glib-2.0 +gobject-2.0 +gio-2.0 +gio-unix-2.0 +dee-1.0 +Dbusmenu-0.4 diff --git a/bindings/vapi/unity.vapi b/bindings/vapi/unity.vapi new file mode 100644 index 00000000..45147fb7 --- /dev/null +++ b/bindings/vapi/unity.vapi @@ -0,0 +1,438 @@ +/* unity.vapi generated by valac 0.18.0, do not modify. */ + +namespace Unity { + namespace IO { + [CCode (cheader_filename = "unity.h")] + public static string[] get_system_data_dirs (); + [CCode (cheader_filename = "unity.h")] + public static async GLib.FileInputStream? open_from_data_dirs (string filename) throws GLib.Error; + [CCode (cheader_filename = "unity.h")] + public static async GLib.FileInputStream? open_from_dirs (string filename, string[] dirs) throws GLib.Error; + [CCode (cheader_filename = "unity.h")] + public static async void read_stream_async (GLib.InputStream input, int io_priority = GLib.Priority.LOW, GLib.Cancellable? cancellable = null, out uint8[] data, out size_t size) throws GLib.IOError; + } + [CCode (cheader_filename = "unity.h")] + public class ActivationResponse : GLib.InitiallyUnowned { + public ActivationResponse (Unity.HandledType handled, string goto_uri = ""); + public ActivationResponse.with_preview (Unity.Preview preview); + public string goto_uri { get; set construct; } + public Unity.HandledType handled { get; construct; } + } + [CCode (cheader_filename = "unity.h")] + public class AnnotatedIcon : GLib.Object { + public AnnotatedIcon (GLib.Icon base_icon); + public string to_string (); + public Unity.CategoryType category { get; set; } + public GLib.Icon icon { get; set; } + public string ribbon { get; set; } + public Unity.IconSizeHint size_hint { get; set; } + } + [CCode (cheader_filename = "unity.h")] + public class AppInfoManager : GLib.Object { + public void clear (); + public unowned string[]? get_categories (string id); + public static Unity.AppInfoManager get_default (); + [Deprecated (replacement = "AppInfoManager.get_default")] + public static Unity.AppInfoManager get_instance (); + public unowned string[]? get_keywords (string id); + public string? get_path (string id); + public GLib.AppInfo? lookup (string id); + public async GLib.AppInfo? lookup_async (string id) throws GLib.Error; + public signal void changed (string id, GLib.AppInfo? new_appinfo); + } + [CCode (cheader_filename = "unity.h")] + public class ApplicationPreview : Unity.Preview { + public ApplicationPreview (string title, string subtitle, string description, GLib.Icon? icon, GLib.Icon? screenshot); + public void set_rating (float rating, uint num_ratings); + public GLib.Icon app_icon { get; set; } + public string copyright { get; set; } + public string last_update { get; set; } + public string license { get; set; } + } + [CCode (cheader_filename = "unity.h")] + public class AsyncPreview : Unity.Preview { + public AsyncPreview (); + [CCode (name = "unity_async_preview_preview_ready")] + public void emit_preview_ready (Unity.Preview? preview); + public AsyncPreview.with_cancellable (GLib.Cancellable cancellable); + public GLib.Cancellable cancellable { get; set construct; } + public signal void preview_ready (Unity.Preview? preview); + } + [CCode (cheader_filename = "unity.h")] + public class Category : GLib.Object { + public Category (string name, GLib.Icon icon_hint, Unity.CategoryRenderer renderer = CategoryRenderer.VERTICAL_TILE); + public Unity.CategoryRenderer default_renderer { get; construct; } + public GLib.Icon? icon_hint { get; construct; } + public string name { get; construct; } + } + [CCode (cheader_filename = "unity.h")] + public class CheckOptionFilter : Unity.OptionsFilter { + public CheckOptionFilter (string id, string display_name, GLib.Icon? icon_hint = null, bool collapsed = false); + } + [CCode (cheader_filename = "unity.h")] + public class CheckOptionFilterCompact : Unity.OptionsFilter { + public CheckOptionFilterCompact (string id, string display_name, GLib.Icon? icon_hint = null, bool collapsed = false); + } + [CCode (cheader_filename = "unity.h")] + public abstract class Filter : GLib.Object { + public Filter (); + public bool collapsed { get; construct; } + public string display_name { get; internal set construct; } + public bool filtering { get; internal set construct; } + public GLib.Icon? icon_hint { get; construct; } + public string id { get; construct; } + public Unity.FilterRenderer renderer { get; construct; } + public bool visible { get; set construct; } + public signal void changed (); + } + [CCode (cheader_filename = "unity.h")] + public class FilterOption : GLib.Object { + public FilterOption (string id, string display_name, GLib.Icon? icon_hint = null, bool active = false); + public bool active { get; internal set construct; } + public string display_name { get; construct; } + public GLib.Icon icon_hint { get; construct; } + public string id { get; construct; } + } + [CCode (cheader_filename = "unity.h")] + public class GenericPreview : Unity.Preview { + public GenericPreview (string title, string description, GLib.Icon? image); + } + [CCode (cheader_filename = "unity.h")] + public class InfoHint : GLib.InitiallyUnowned { + public InfoHint (string id, string display_name, GLib.Icon? icon_hint, string data); + public InfoHint.with_variant (string id, string display_name, GLib.Icon? icon_hint, GLib.Variant data); + public GLib.Variant data { get; construct; } + public string display_name { get; construct; } + public GLib.Icon? icon_hint { get; construct; } + public string id { get; construct; } + } + [CCode (cheader_filename = "unity.h")] + public class Inspector : GLib.Object { + public static unowned Unity.Inspector get_default (); + public string? unity_bus_name { get; } + public bool unity_running { get; } + } + [CCode (cheader_filename = "unity.h")] + public class LauncherEntry : Dee.Serializable, GLib.Object { + public static Unity.LauncherEntry get_for_app_uri (string app_uri); + public static Unity.LauncherEntry get_for_desktop_file (string desktop_file); + public static Unity.LauncherEntry get_for_desktop_id (string desktop_id); + public string app_uri { get; set construct; } + public int64 count { get; set; } + public bool count_visible { get; set; } + public double progress { get; set; } + public bool progress_visible { get; set; } + public Dbusmenu.Menuitem? quicklist { get; set; } + public bool urgent { get; set; } + } + [CCode (cheader_filename = "unity.h")] + public class LauncherFavorites : GLib.Object { + public GLib.AppInfo[] enumerate_app_infos (); + public string[] enumerate_ids (); + public static unowned Unity.LauncherFavorites get_default (); + public bool has_app_id (string app_id); + public bool has_app_info (GLib.AppInfo appinfo); + public GLib.AppInfo? lookup (string app_id); + public signal void changed (); + } + [CCode (cheader_filename = "unity.h")] + public class Lens : GLib.Object { + public Lens (string dbus_path_, string id_); + public void add_local_scope (Unity.Scope scope); + public void export () throws GLib.IOError; + public bool active { get; private set; } + public GLib.List categories { get; set; } + public string dbus_path { get; construct; } + public bool exported { get; private set; } + public GLib.List filters { get; set; } + public Unity.MergeStrategy global_merge_strategy { get; set; } + public string home_lens_default_name { get; set; } + public string id { get; construct; } + public Unity.MergeStrategy merge_strategy { get; set; } + public string search_hint { get; set; } + public bool search_in_global { get; set; } + public bool searching { get; private set; } + public string sources_display_name { get; set construct; } + public bool visible { get; set; } + } + [CCode (cheader_filename = "unity.h")] + public class LensSearch : GLib.InitiallyUnowned { + public LensSearch (string search_string, GLib.HashTable hints, Dee.SerializableModel results_model); + [CCode (cname = "unity_lens_search_finished")] + public void emit_finished (); + public bool equals (Unity.LensSearch? other); + public void set_reply_hint (string key, GLib.Variant variant); + public GLib.HashTable hints { get; construct; } + public Dee.SerializableModel results_model { get; construct; } + public string search_string { get; construct; } + [Signal (action = true)] + public signal void finished (); + } + [CCode (cheader_filename = "unity.h")] + public class MoviePreview : Unity.Preview { + public MoviePreview (string title, string subtitle, string description, GLib.Icon? image); + public void set_rating (float rating, uint num_ratings); + public string year { get; set; } + } + [CCode (cheader_filename = "unity.h")] + public class MultiRangeFilter : Unity.OptionsFilter { + public MultiRangeFilter (string id, string display_name, GLib.Icon? icon_hint = null, bool collapsed = false); + public Unity.FilterOption? get_first_active (); + public Unity.FilterOption? get_last_active (); + } + [CCode (cheader_filename = "unity.h")] + public class MusicPlayer : GLib.Object { + public MusicPlayer (string desktop); + public bool add_playlist (Unity.Playlist p); + public void edit_playlist_name (string id, string name); + public void export (); + public Unity.Playlist[] get_playlists (); + public bool remove_playlist (Unity.Playlist p); + public void unexport (); + public GLib.AppInfo app_info { get; construct; } + public bool can_go_next { get; set; } + public bool can_go_previous { get; set; } + public bool can_pause { get; set; } + public bool can_play { get; set; } + public Unity.Playlist current_playlist { get; set; } + public Unity.TrackMetadata current_track { get; set; } + public string desktop_file_name { get; construct; } + public bool is_blacklisted { get; set; } + public Unity.PlaybackState playback_state { get; set; } + public Dbusmenu.Menuitem? player_menu { get; set; } + public string title { get; set; } + public Dbusmenu.Menuitem? track_menu { get; set; } + public signal void activate_playlist (GLib.ObjectPath playlist_id); + public signal void next (); + public signal void play_pause (); + public signal void previous (); + public signal void raise (); + } + [CCode (cheader_filename = "unity.h")] + public class MusicPreview : Unity.Preview { + public enum TrackState { + STOPPED, + PLAYING, + PAUSED + } + public MusicPreview (string title, string subtitle, GLib.Icon? image); + public void add_track (Unity.TrackMetadata track); + public float current_progress { get; set; } + public Unity.MusicPreview.TrackState current_track_state { get; set; } + public string current_track_uri { get; set; } + public signal void pause (string uri); + public signal void play (string uri); + } + [CCode (cheader_filename = "unity.h")] + public class OptionsFilter : Unity.Filter { + public enum SortType { + MANUAL, + DISPLAY_NAME, + ID + } + public GLib.List options; + public OptionsFilter (); + public Unity.FilterOption add_option (string id, string display_name, GLib.Icon? icon_hint = null); + public Unity.FilterOption? get_option (string id); + public bool remove_option (string id); + public Unity.OptionsFilter.SortType sort_type { get; set; } + } + [CCode (cheader_filename = "unity.h")] + public class Playlist : GLib.Object { + public Playlist (string id); + public GLib.DateTime creation_date { get; set; } + public GLib.Icon icon { get; set; } + public string id { get; construct; } + public GLib.DateTime last_play_date { get; set; } + public GLib.DateTime modification_date { get; set; } + public string name { get; set; } + } + [CCode (cheader_filename = "unity.h")] + public class PreferencesManager : GLib.Object { + public enum RemoteContent { + ALL, + NONE + } + public static Unity.PreferencesManager get_default (); + public Unity.PreferencesManager.RemoteContent remote_content_search { get; set; } + } + [CCode (cheader_filename = "unity.h")] + public abstract class Preview : GLib.Object, Dee.Serializable { + public Preview (); + public void add_action (Unity.PreviewAction action); + public void add_info (Unity.InfoHint info_hint); + public string description_markup { get; set; } + public GLib.Icon? image { get; set; } + public string image_source_uri { get; set; } + public string subtitle { get; set; } + public string title { get; set; } + public signal void closed (); + } + [CCode (cheader_filename = "unity.h")] + public class PreviewAction : GLib.Object, Dee.Serializable { + public PreviewAction (string id, string display_name, GLib.Icon? icon_hint); + public PreviewAction.with_layout_hint (string id, string display_name, GLib.Icon? icon_hint, Unity.LayoutHint layout); + public string display_name { get; construct; } + public string extra_text { get; set; } + public GLib.HashTable? hints { get; } + public GLib.Icon? icon_hint { get; construct; } + public string id { get; construct; } + public Unity.LayoutHint layout_hint { get; construct; } + public signal Unity.ActivationResponse activated (string uri); + } + [CCode (cheader_filename = "unity.h")] + public class RadioOptionFilter : Unity.OptionsFilter { + public RadioOptionFilter (string id, string display_name, GLib.Icon? icon_hint = null, bool collapsed = false); + public Unity.FilterOption? get_active_option (); + } + [CCode (cheader_filename = "unity.h")] + public class RatingsFilter : Unity.Filter { + public RatingsFilter (string id, string display_name, GLib.Icon? icon_hint = null, bool collapsed = false); + public float rating { get; internal set construct; } + } + [CCode (cheader_filename = "unity.h")] + public class Scope : GLib.Object { + public Scope (string dbus_path_); + public void export () throws GLib.IOError; + public Unity.Filter? get_filter (string id); + public void invalidate_search (Unity.SearchType search_type); + public void queue_search_changed (Unity.SearchType search_type); + public bool active { get; set; } + public string dbus_path { get; construct; } + public bool exported { get; private set; } + public GLib.List filters { get; } + public Dee.SerializableModel global_results_model { get; } + public bool provides_personal_content { get; set; } + public Dee.SerializableModel results_model { get; } + public bool search_in_global { get; set; } + public Unity.OptionsFilter sources { get; internal set; } + public signal Unity.ActivationResponse? activate_uri (string uri); + public signal void active_sources_changed (string[] active_ids); + public signal void filters_changed (); + [Signal (detailed = true)] + public signal string generate_search_key (Unity.LensSearch search); + public signal Unity.Preview? preview_uri (string uri); + public signal void search_changed (Unity.LensSearch search, Unity.SearchType search_type, GLib.Cancellable cancellable); + } + [CCode (cheader_filename = "unity.h")] + public class SocialPreview : Unity.Preview { + public class Comment : GLib.InitiallyUnowned { + public Comment (string id, string name, string text, string time); + public string id { get; construct; } + public string name { get; construct; } + public string text { get; construct; } + public string time { get; construct; } + } + public SocialPreview (string sender, string subtitle, string content, GLib.Icon? avatar); + public void add_comment (Unity.SocialPreview.Comment comment); + public GLib.Icon avatar { get; set; } + public string content { get; set; } + public string sender { get; set; } + } + [CCode (cheader_filename = "unity.h")] + public class TrackMetadata : GLib.Object { + public TrackMetadata (); + public TrackMetadata.full (string uri, int track_no, string title, string artist, string album, uint length); + public string album { get; set; } + public GLib.Icon art_icon { get; set; } + public GLib.File art_location { get; set; } + public string artist { get; set; } + public uint length { get; set; } + public string title { get; set; } + public int track_no { get; set; } + public string uri { get; set; } + } + [CCode (cheader_filename = "unity.h")] + public interface MergeStrategy : GLib.Object { + public abstract unowned Dee.ModelIter? merge_result (Dee.Model target, GLib.Variant[] row); + } + [CCode (cheader_filename = "unity.h")] + public struct ActivePlaylistContainer { + public bool valid; + public Unity.PlaylistDetails details; + } + [CCode (cheader_filename = "unity.h")] + public struct PlaylistDetails { + public GLib.ObjectPath id; + public string name; + public string icon_name; + } + [CCode (cheader_filename = "unity.h")] + public enum CategoryRenderer { + VERTICAL_TILE, + HORIZONTAL_TILE, + LIST_TILE, + FLOW + } + [CCode (cheader_filename = "unity.h")] + public enum CategoryType { + NONE, + APPLICATION, + BOOK, + MUSIC, + MOVIE, + GAMES, + ELECTRONICS, + COMPUTERS, + OFFICE, + HOME, + GARDEN, + PETS, + TOYS, + CHILDREN, + BABY, + CLOTHES, + SHOES, + WATCHES, + SPORTS, + OUTDOORS, + GROCERY, + HEALTH, + BEAUTY, + DIY, + TOOLS, + CAR, + N_CATEGORIES + } + [CCode (cheader_filename = "unity.h")] + public enum FilterRenderer { + CHECK_OPTIONS, + RADIO_OPTIONS, + MULTIRANGE, + RATINGS, + CHECK_OPTIONS_COMPACT + } + [CCode (cheader_filename = "unity.h")] + public enum HandledType { + NOT_HANDLED, + SHOW_DASH, + HIDE_DASH, + GOTO_DASH_URI, + SHOW_PREVIEW + } + [CCode (cheader_filename = "unity.h")] + public enum IconSizeHint { + DEFAULT, + SMALL, + LARGE + } + [CCode (cheader_filename = "unity.h")] + public enum LayoutHint { + NONE, + LEFT, + RIGHT, + TOP, + BOTTOM + } + [CCode (cheader_filename = "unity.h")] + public enum PlaybackState { + PLAYING, + PAUSED + } + [CCode (cheader_filename = "unity.h")] + public enum SearchType { + DEFAULT, + GLOBAL, + N_TYPES + } +} diff --git a/debian/control b/debian/control index 99971f16..a36e742e 100644 --- a/debian/control +++ b/debian/control @@ -3,7 +3,7 @@ Section: gnome Priority: optional Maintainer: Jim Nelson Build-Depends: debhelper (>= 8), - libgee-dev (>= 0.6.0), + libgee-0.8-dev (>= 0.8.0), libglib2.0-dev (>= 2.30.0), libgtk-3-dev (>= 3.2.0), libunique-3.0-dev (>= 3.0.0), @@ -26,7 +26,7 @@ Homepage: http://www.yorba.org Package: geary Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, - libgee2 (>= 0.6.0), + libgee-0.8-2 (>= 0.8.0), libglib2.0-0 (>= 2.30.0), libgtk-3-0 (>= 3.2.0), libunique-3.0-0 (>= 3.0.0), diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 97abce96..735298c3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -347,7 +347,7 @@ pkg_check_modules(DEPS REQUIRED glib-2.0>=${TARGET_GLIB}.0 gio-2.0>=2.28.0 gtk+-3.0>=3.4.0 - gee-1.0>=0.6.0 + gee-0.8>=0.8.0 unique-3.0>=3.0.0 libnotify>=0.7.5 libcanberra>=0.28 @@ -359,7 +359,7 @@ pkg_check_modules(DEPS REQUIRED ) set(ENGINE_PACKAGES - glib-2.0 gee-1.0 gio-2.0 gmime-2.6 unique-3.0 posix sqlite3 + glib-2.0 gee-0.8 gio-2.0 gmime-2.6 unique-3.0 posix sqlite3 ) set(CLIENT_PACKAGES @@ -371,7 +371,7 @@ set(CONSOLE_PACKAGES ) set(DBUSSERVICE_PACKAGES - gee-1.0 glib-2.0 + gee-0.8 glib-2.0 ) set(GSETTINGS_DIR ${CMAKE_SOURCE_DIR}/desktop) diff --git a/src/client/accounts/account-dialog-account-list-pane.vala b/src/client/accounts/account-dialog-account-list-pane.vala index 5f2bbb00..87f07921 100644 --- a/src/client/accounts/account-dialog-account-list-pane.vala +++ b/src/client/accounts/account-dialog-account-list-pane.vala @@ -53,7 +53,7 @@ public class AccountDialogAccountListPane : AccountDialogPane { } // Sort accounts and add them to the UI. - account_list.sort((CompareFunc) Geary.AccountInformation.compare_ascending); + account_list.sort(Geary.AccountInformation.compare_ascending); foreach (Geary.AccountInformation account in account_list) on_account_added(account); diff --git a/src/client/accounts/account-dialog.vala b/src/client/accounts/account-dialog.vala index 182d06b5..91261419 100644 --- a/src/client/accounts/account-dialog.vala +++ b/src/client/accounts/account-dialog.vala @@ -153,8 +153,8 @@ public class AccountDialog : Gtk.Dialog { Geary.AccountInformation? real_info = GearyApplication.instance.get_real_account_information(info); if (real_info != null) { - validate_connection = !real_info.imap_credentials.equals(info.imap_credentials) || - (info.smtp_credentials != null && !real_info.smtp_credentials.equals(info.smtp_credentials)); + validate_connection = !real_info.imap_credentials.equal_to(info.imap_credentials) || + (info.smtp_credentials != null && !real_info.smtp_credentials.equal_to(info.smtp_credentials)); } } diff --git a/src/client/composer/composer-window.vala b/src/client/composer/composer-window.vala index 23fb8edc..493df8ff 100644 --- a/src/client/composer/composer-window.vala +++ b/src/client/composer/composer-window.vala @@ -127,7 +127,8 @@ public class ComposerWindow : Gtk.Window { public ComposeType compose_type { get; private set; default = ComposeType.NEW_MESSAGE; } private string? body_html = null; - private Gee.Set attachment_files = new Gee.HashSet(File.hash, (EqualFunc) File.equal); + private Gee.Set attachment_files = new Gee.HashSet(Geary.Files.nullable_hash, + Geary.Files.nullable_equal); private Gtk.Builder builder; private Gtk.Label from_label; diff --git a/src/client/folder-list/folder-list-account-branch.vala b/src/client/folder-list/folder-list-account-branch.vala index 6823dd37..98cfce59 100644 --- a/src/client/folder-list/folder-list-account-branch.vala +++ b/src/client/folder-list/folder-list-account-branch.vala @@ -20,8 +20,7 @@ public class FolderList.AccountBranch : Sidebar.Branch { new ThemedIcon("folder-open"), new ThemedIcon("folder")); user_folder_group = new SpecialGrouping(2, "", IconFactory.instance.get_custom_icon("tags", IconFactory.ICON_SIDEBAR)); - folder_entries = new Gee.HashMap( - Geary.Hashable.hash_func, Geary.Equalable.equal_func); + folder_entries = new Gee.HashMap(); account.information.notify["nickname"].connect(on_nicknamed_changed); diff --git a/src/client/geary-controller.vala b/src/client/geary-controller.vala index 7c77ae18..07640be9 100644 --- a/src/client/geary-controller.vala +++ b/src/client/geary-controller.vala @@ -677,7 +677,7 @@ public class GearyController { return; } - all_accounts.sort((CompareFunc) Geary.AccountInformation.compare_ascending); + all_accounts.sort(Geary.AccountInformation.compare_ascending); account_to_select = Geary.Engine.instance.get_account_instance(all_accounts.get(0)); } catch (Error e) { debug("Error selecting first inbox: %s", e.message); diff --git a/src/client/models/conversation-list-store.vala b/src/client/models/conversation-list-store.vala index eadb9e94..c053bd60 100644 --- a/src/client/models/conversation-list-store.vala +++ b/src/client/models/conversation-list-store.vala @@ -106,7 +106,7 @@ public class ConversationListStore : Gtk.ListStore { if (conversation_lowest == null) continue; - if (lowest_id == null || conversation_lowest.compare(lowest_id) < 0) + if (lowest_id == null || conversation_lowest.compare_to(lowest_id) < 0) lowest_id = conversation_lowest; } while (iter_next(ref iter)); @@ -227,13 +227,11 @@ public class ConversationListStore : Gtk.ListStore { // sort the conversations so the previews are fetched from the newest to the oldest, matching // the user experience Gee.TreeSet sorted_conversations = new Geary.Collection.FixedTreeSet( - (CompareFunc) compare_conversation_descending); + compare_conversation_descending); sorted_conversations.add_all(conversation_monitor.get_conversations()); - folder_emails = new Gee.HashSet( - Geary.Hashable.hash_func, Geary.Equalable.equal_func); - account_emails = new Gee.HashSet( - Geary.Hashable.hash_func, Geary.Equalable.equal_func); + folder_emails = new Gee.HashSet(); + account_emails = new Gee.HashSet(); foreach (Geary.Conversation conversation in sorted_conversations) { Geary.Email? need_preview = conversation.get_latest_email(); if (need_preview == null) @@ -243,7 +241,7 @@ public class ConversationListStore : Gtk.ListStore { // if all preview fields present and it's the same email, don't need to refresh if (current_preview != null - && need_preview.id.equals(current_preview.id) + && need_preview.id.equal_to(current_preview.id) && current_preview.fields.is_all_set(ConversationListStore.WITH_PREVIEW_FIELDS)) { continue; } @@ -301,7 +299,7 @@ public class ConversationListStore : Gtk.ListStore { FormattedConversationData? existing_message_data = get_message_data_at_iter(iter); - if (existing_message_data == null || !existing_message_data.preview.id.equals(last_email.id)) { + if (existing_message_data == null || !existing_message_data.preview.id.equal_to(last_email.id)) { set_row(iter, conversation, last_email); } else if (existing_message_data != null && existing_message_data.num_emails != conversation.get_count()) { diff --git a/src/client/notification/new-messages-monitor.vala b/src/client/notification/new-messages-monitor.vala index eb86fb31..8397cb99 100644 --- a/src/client/notification/new-messages-monitor.vala +++ b/src/client/notification/new-messages-monitor.vala @@ -19,8 +19,7 @@ public class NewMessagesMonitor : Geary.BaseObject { public Cancellable? cancellable = null; public int count = 0; public Gee.HashSet new_ids - = new Gee.HashSet( - Geary.Hashable.hash_func, Geary.Equalable.equal_func); + = new Gee.HashSet(); public MonitorInformation(Geary.Folder folder, Cancellable? cancellable) { this.folder = folder; @@ -180,7 +179,7 @@ public class NewMessagesMonitor : Geary.BaseObject { MonitorInformation info = folder_information.get(folder); foreach (Geary.EmailIdentifier email_id in email_ids) { - if (last_new_message != null && last_new_message.id.equals(email_id)) { + if (last_new_message != null && last_new_message.id.equal_to(email_id)) { last_new_message_folder = null; last_new_message = null; } diff --git a/src/client/sidebar/sidebar-branch.vala b/src/client/sidebar/sidebar-branch.vala index a262b1a1..ced83bb7 100644 --- a/src/client/sidebar/sidebar-branch.vala +++ b/src/client/sidebar/sidebar-branch.vala @@ -48,16 +48,13 @@ public class Sidebar.Branch : Object { this.comparator = comparator; } - private static int comparator_wrapper(void *a, void *b) { - if (a == b) + private static int comparator_wrapper(Node anode, Node bnode) { + if (anode == bnode) return 0; - Node *anode = (Node *) a; - Node *bnode = (Node *) b; + assert(anode.parent == bnode.parent); - assert(anode->parent == bnode->parent); - - return anode->parent.comparator(anode->entry, bnode->entry); + return anode.parent.comparator(anode.entry, bnode.entry); } public bool has_children() { diff --git a/src/client/ui/folder-menu.vala b/src/client/ui/folder-menu.vala index 4f8f7c88..a4b98010 100644 --- a/src/client/ui/folder-menu.vala +++ b/src/client/ui/folder-menu.vala @@ -24,7 +24,7 @@ public class FolderMenu : GtkUtil.ToggleToolbarDropdown { public void add_folder(Geary.Folder folder) { folder_list.add(folder); - folder_list.sort((CompareFunc) folder_sort); + folder_list.sort(folder_sort); int index = folder_list.index_of(folder); menu.insert(build_menu_item(folder), index); @@ -65,7 +65,7 @@ public class FolderMenu : GtkUtil.ToggleToolbarDropdown { } private static int folder_sort(Geary.Folder a, Geary.Folder b) { - return a.get_path().compare(b.get_path()); + return a.get_path().compare_to(b.get_path()); } } diff --git a/src/client/views/conversation-viewer.vala b/src/client/views/conversation-viewer.vala index b3a1be04..366df6e9 100644 --- a/src/client/views/conversation-viewer.vala +++ b/src/client/views/conversation-viewer.vala @@ -42,7 +42,7 @@ public class ConversationViewer : Gtk.Box { // List of emails in this view. public Gee.TreeSet messages { get; private set; default = - new Geary.Collection.FixedTreeSet((CompareFunc) Geary.Email.compare_date_ascending); } + new Geary.Collection.FixedTreeSet(Geary.Email.compare_date_ascending); } // The HTML viewer to view the emails. public ConversationWebView web_view { get; private set; } @@ -52,8 +52,7 @@ public class ConversationViewer : Gtk.Box { // Maps emails to their corresponding elements. private Gee.HashMap email_to_element = new - Gee.HashMap(Geary.Hashable.hash_func, - Geary.Equalable.equal_func); + Gee.HashMap(); private string? hover_url = null; private Gtk.Menu? context_menu = null; @@ -472,7 +471,7 @@ public class ConversationViewer : Gtk.Box { // Update the flags in our message set. foreach (Geary.Email message in messages) { - if (message.id.equals(email.id)) { + if (message.id.equal_to(email.id)) { message.set_flags(flags); break; } diff --git a/src/client/views/formatted-conversation-data.vala b/src/client/views/formatted-conversation-data.vala index 1d9404fc..88c2299d 100644 --- a/src/client/views/formatted-conversation-data.vala +++ b/src/client/views/formatted-conversation-data.vala @@ -19,7 +19,7 @@ public class FormattedConversationData : Geary.BaseObject { private const int FONT_SIZE_PREVIEW = 8; private const int FONT_SIZE_MESSAGE_COUNT = 8; - private class ParticipantDisplay : Geary.BaseObject, Geary.Equalable { + private class ParticipantDisplay : Geary.BaseObject, Gee.Hashable { public string key; public Geary.RFC822.MailboxAddress address; public bool is_unread; @@ -65,16 +65,16 @@ public class FormattedConversationData : Geary.BaseObject { is_unread ? "" : "", Geary.HTML.escape_markup(participant), is_unread ? "" : ""); } - public bool equals(Geary.Equalable o) { - ParticipantDisplay? other = o as ParticipantDisplay; - if (other == null) - return false; - + public bool equal_to(ParticipantDisplay other) { if (this == other) return true; return key == other.key; } + + public uint hash() { + return key.hash(); + } } private static int cell_height = -1; @@ -185,7 +185,7 @@ public class FormattedConversationData : Geary.BaseObject { // Build chronological list of AuthorDisplay records, setting to unread if any message by // that author is unread - Gee.ArrayList list = new Gee.ArrayList(Geary.Equalable.equal_func); + Gee.ArrayList list = new Gee.ArrayList(); foreach (Geary.Email message in conversation.get_emails(Geary.Conversation.Ordering.DATE_ASCENDING)) { // only display if something to display Geary.RFC822.MailboxAddresses? addresses = use_to ? message.to : message.from; diff --git a/src/dbusservice/database.vala b/src/dbusservice/database.vala index 6239c70b..10d0a331 100644 --- a/src/dbusservice/database.vala +++ b/src/dbusservice/database.vala @@ -7,11 +7,11 @@ namespace Geary.DBus { public uint db_email_hash(Geary.Email key) { - return key.id.to_hash(); + return key.id.hash(); } public bool db_email_equal(Geary.Email a, Geary.Email b) { - return a.id.equals(b.id); + return a.id.equal_to(b.id); } } diff --git a/src/engine/api/geary-composed-email.vala b/src/engine/api/geary-composed-email.vala index 46533188..947af708 100644 --- a/src/engine/api/geary-composed-email.vala +++ b/src/engine/api/geary-composed-email.vala @@ -29,7 +29,7 @@ public class Geary.ComposedEmail : BaseObject { public string? body_html { get; set; default = null; } public string? mailer { get; set; default = null; } public Gee.Set attachment_files { get; private set; - default = new Gee.HashSet(File.hash, (EqualFunc) File.equal); } + default = new Gee.HashSet(Geary.Files.nullable_hash, Geary.Files.nullable_equal); } public ComposedEmail(DateTime date, RFC822.MailboxAddresses from, RFC822.MailboxAddresses? to = null, RFC822.MailboxAddresses? cc = null, diff --git a/src/engine/api/geary-conversation-monitor.vala b/src/engine/api/geary-conversation-monitor.vala index bc8c0c0b..8bf524d2 100644 --- a/src/engine/api/geary-conversation-monitor.vala +++ b/src/engine/api/geary-conversation-monitor.vala @@ -19,18 +19,16 @@ public class Geary.ConversationMonitor : BaseObject { private int convnum; private weak Geary.ConversationMonitor? owner; - private Gee.HashMap emails = new Gee.HashMap( - Hashable.hash_func, Equalable.equal_func); - private Gee.HashMultiSet message_ids = new Gee.HashMultiSet( - Hashable.hash_func, Equalable.equal_func); + private Gee.HashMap emails = new Gee.HashMap(); + private Gee.HashMultiSet message_ids = new Gee.HashMultiSet(); private Geary.EmailIdentifier? lowest_id; // this isn't ideal but the cost of adding an email to multiple sorted sets once versus // the number of times they're accessed makes it worth it private Gee.SortedSet date_ascending = new Collection.FixedTreeSet( - (CompareFunc) compare_date_ascending); + Geary.Email.compare_date_ascending); private Gee.SortedSet date_descending = new Collection.FixedTreeSet( - (CompareFunc) compare_date_descending); + Geary.Email.compare_date_descending); public ImplConversation(Geary.ConversationMonitor owner) { convnum = next_convnum++; @@ -114,8 +112,7 @@ public class Geary.ConversationMonitor : BaseObject { date_ascending.remove(email); date_descending.remove(email); - Gee.Set removed_message_ids = new Gee.HashSet( - Hashable.hash_func, Equalable.equal_func); + Gee.Set removed_message_ids = new Gee.HashSet(); Gee.Set? ancestors = email.get_ancestors(); if (ancestors != null) { @@ -135,30 +132,10 @@ public class Geary.ConversationMonitor : BaseObject { } private void check_lowest_id(EmailIdentifier id) { - if (id.get_folder_path() != null && (lowest_id == null || id.compare(lowest_id) < 0)) + if (id.get_folder_path() != null && (lowest_id == null || id.compare_to(lowest_id) < 0)) lowest_id = id; } - private static int compare_date_ascending(Email a, Email b) { - int diff = a.date.value.compare(b.date.value); - - // stabilize the sort if the same date - return (diff != 0) ? diff : compare_id_ascending(a, b); - } - - private static int compare_date_descending(Email a, Email b) { - return compare_date_ascending(b, a); - } - - private static int compare_id_ascending(Email a, Email b) { - // Arbitrarily, "account" email ids come after "folder" email ids. - if (a.id.get_folder_path() == null && b.id.get_folder_path() != null) - return 1; - if (a.id.get_folder_path() != null && b.id.get_folder_path() == null) - return -1; - return a.id.compare(b.id); - } - public string to_string() { return "[#%d] (%d emails)".printf(convnum, emails.size); } @@ -198,9 +175,9 @@ public class Geary.ConversationMonitor : BaseObject { private bool readonly; private Gee.Set conversations = new Gee.HashSet(); private Gee.HashMap geary_id_map = new Gee.HashMap< - Geary.EmailIdentifier, ImplConversation>(Hashable.hash_func, Equalable.equal_func); + Geary.EmailIdentifier, ImplConversation>(); private Gee.HashMap message_id_map = new Gee.HashMap< - Geary.RFC822.MessageID, ImplConversation>(Hashable.hash_func, Equalable.equal_func); + Geary.RFC822.MessageID, ImplConversation>(); private Cancellable? cancellable_monitor = null; private bool retry_connection = false; private int64 last_retry_time = 0; @@ -562,8 +539,7 @@ public class Geary.ConversationMonitor : BaseObject { folder.to_string(), emails.size); // MessageIDs we're adding to each conversation. - Gee.HashSet new_message_ids = new Gee.HashSet( - Hashable.hash_func, Equalable.equal_func); + Gee.HashSet new_message_ids = new Gee.HashSet(); Gee.HashSet new_conversations = new Gee.HashSet(); Gee.MultiMap appended_conversations = new Gee.HashMultiMap< @@ -649,7 +625,7 @@ public class Geary.ConversationMonitor : BaseObject { }; Gee.ArrayList blacklist - = new Gee.ArrayList(Equalable.nullable_equal_func); + = new Gee.ArrayList(); foreach (Geary.SpecialFolderType type in blacklisted_folder_types) { try { Geary.Folder? blacklist_folder = folder.account.get_special_folder(type); @@ -699,7 +675,7 @@ public class Geary.ConversationMonitor : BaseObject { // collect their results into a single collection of addt'l emails Gee.HashMap needed_messages = new Gee.HashMap< - Geary.EmailIdentifier, Geary.Email>(Hashable.hash_func, Equalable.equal_func); + Geary.EmailIdentifier, Geary.Email>(); foreach (int id in batch.get_ids()) { LocalSearchOperation op = (LocalSearchOperation) batch.get_operation(id); if (op.emails != null) { @@ -806,7 +782,7 @@ public class Geary.ConversationMonitor : BaseObject { Geary.EmailIdentifier? earliest_id = null; foreach (Geary.Conversation conversation in conversations) { Geary.EmailIdentifier? id = conversation.get_lowest_email_id(); - if (id != null && (earliest_id == null || id.compare(earliest_id) < 0)) + if (id != null && (earliest_id == null || id.compare_to(earliest_id) < 0)) earliest_id = id; } diff --git a/src/engine/api/geary-credentials.vala b/src/engine/api/geary-credentials.vala index d3201a8d..7b8a2ab2 100644 --- a/src/engine/api/geary-credentials.vala +++ b/src/engine/api/geary-credentials.vala @@ -18,7 +18,7 @@ * in the background and asking the user to reauthenticate each time is deemed inconvenient. */ -public class Geary.Credentials : BaseObject, Geary.Equalable { +public class Geary.Credentials : BaseObject, Gee.Hashable { public string? user { get; set; } public string? pass { get; set; } @@ -43,15 +43,15 @@ public class Geary.Credentials : BaseObject, Geary.Equalable { return user; } - public bool equals(Equalable other) { - Geary.Credentials? c = other as Geary.Credentials; - if (c == null) - return false; - + public bool equal_to(Geary.Credentials c) { if (this == c) return true; return user == c.user && pass == c.pass; } + + public uint hash() { + return to_string().hash(); + } } diff --git a/src/engine/api/geary-email-flag.vala b/src/engine/api/geary-email-flag.vala index be6fcfbc..f25277b3 100644 --- a/src/engine/api/geary-email-flag.vala +++ b/src/engine/api/geary-email-flag.vala @@ -4,25 +4,21 @@ * (version 2.1 or later). See the COPYING file in this distribution. */ -public class Geary.EmailFlag : BaseObject, Geary.Equalable, Geary.Hashable { +public class Geary.EmailFlag : BaseObject, Gee.Hashable { private string name; public EmailFlag(string name) { this.name = name; } - public bool equals(Equalable o) { - EmailFlag? other = o as EmailFlag; - if (other == null) - return false; - + public bool equal_to(Geary.EmailFlag other) { if (this == other) return true; return name.down() == other.name.down(); } - public uint to_hash() { + public uint hash() { return name.down().hash(); } diff --git a/src/engine/api/geary-email-flags.vala b/src/engine/api/geary-email-flags.vala index 04b34af3..bd3a3caf 100644 --- a/src/engine/api/geary-email-flags.vala +++ b/src/engine/api/geary-email-flags.vala @@ -4,7 +4,7 @@ * (version 2.1 or later). See the COPYING file in this distribution. */ -public class Geary.EmailFlags : BaseObject, Geary.Equalable { +public class Geary.EmailFlags : BaseObject, Gee.Hashable { private static EmailFlag? _unread = null; public static EmailFlag UNREAD { get { if (_unread == null) @@ -21,7 +21,7 @@ public class Geary.EmailFlags : BaseObject, Geary.Equalable { return _flagged; } } - private Gee.Set list = new Gee.HashSet(Hashable.hash_func, Equalable.equal_func); + private Gee.Set list = new Gee.HashSet(); public virtual signal void added(Gee.Collection flags) { } @@ -96,11 +96,7 @@ public class Geary.EmailFlags : BaseObject, Geary.Equalable { return contains(FLAGGED); } - public bool equals(Equalable o) { - Geary.EmailFlags? other = o as Geary.EmailFlags; - if (other == null) - return false; - + public bool equal_to(Geary.EmailFlags other) { if (this == other) return true; @@ -115,6 +111,10 @@ public class Geary.EmailFlags : BaseObject, Geary.Equalable { return true; } + public uint hash() { + return Geary.String.stri_hash(to_string()); + } + public string to_string() { string ret = "["; foreach (EmailFlag flag in list) { diff --git a/src/engine/api/geary-email-identifier.vala b/src/engine/api/geary-email-identifier.vala index 582f7242..ccca5de3 100644 --- a/src/engine/api/geary-email-identifier.vala +++ b/src/engine/api/geary-email-identifier.vala @@ -23,7 +23,8 @@ * passed to equals() and compare(). This may be added in the future. */ -public abstract class Geary.EmailIdentifier : BaseObject, Geary.Equalable, Geary.Comparable, Geary.Hashable { +public abstract class Geary.EmailIdentifier : BaseObject, Gee.Comparable, + Gee.Hashable { public int64 ordering { get; protected set; } protected EmailIdentifier(int64 ordering) { @@ -36,19 +37,15 @@ public abstract class Geary.EmailIdentifier : BaseObject, Geary.Equalable, Geary return null; } - public virtual uint to_hash() { - return Geary.Hashable.int64_hash(ordering); + public virtual uint hash() { + return Geary.Collection.int64_hash(ordering); } // Virtual default implementation not provided because base class *must* verify that the // Equalable is of its own type. - public abstract bool equals(Geary.Equalable other); + public abstract bool equal_to(Geary.EmailIdentifier e); - public virtual int compare(Geary.Comparable o) { - Geary.EmailIdentifier? other = o as Geary.EmailIdentifier; - if (other == null) - return -1; - + public virtual int compare_to(Geary.EmailIdentifier other) { if (this == other) return 0; diff --git a/src/engine/api/geary-email.vala b/src/engine/api/geary-email.vala index 2bc3f460..61c991e8 100644 --- a/src/engine/api/geary-email.vala +++ b/src/engine/api/geary-email.vala @@ -287,8 +287,7 @@ public class Geary.Email : BaseObject { * this method to return a complete list. */ public Gee.Set? get_ancestors() { - Gee.Set ancestors = new Gee.HashSet( - Hashable.hash_func, Equalable.equal_func); + Gee.Set ancestors = new Gee.HashSet(); // the email's Message-ID counts as its lineage if (message_id != null) @@ -348,50 +347,47 @@ public class Geary.Email : BaseObject { * CompareFunc to sort Email by date. If the date field is not available on both Emails, their * identifiers are compared. */ - public static int compare_date_ascending(void* a, void *b) { - Geary.Email *aemail = (Geary.Email *) a; - Geary.Email *bemail = (Geary.Email *) b; - + public static int compare_date_ascending(Geary.Email aemail, Geary.Email bemail) { int diff = 0; - if (aemail->date != null && bemail->date != null) - diff = aemail->date.value.compare(bemail->date.value); + if (aemail.date != null && bemail.date != null) + diff = aemail.date.value.compare(bemail.date.value); // stabilize sort by using the mail's ordering, which is always unique in a folder - return (diff != 0) ? diff : aemail->id.compare(bemail->id); + return (diff != 0) ? diff : aemail.id.compare_to(bemail.id); } /** * CompareFunc to sort Email by date. If the date field is not available on both Emails, their * identifiers are compared. */ - public static int compare_date_descending(void* a, void *b) { - return compare_date_ascending(b, a); + public static int compare_date_descending(Geary.Email aemail, Geary.Email bemail) { + return compare_date_ascending(bemail, aemail); } /** * CompareFunc to sort Email by EmailIdentifier. */ - public static int compare_id_ascending(void* a, void *b) { - return ((Email *) a)->id.compare(((Email *) b)->id); + public static int compare_id_ascending(Geary.Email aemail, Geary.Email bemail) { + return aemail.id.compare_to(bemail.id); } /** * CompareFunc to sort Email by EmailIdentifier. */ - public static int compare_id_descending(void* a, void *b) { - return compare_id_ascending(b, a); + public static int compare_id_descending(Geary.Email aemail, Geary.Email bemail) { + return compare_id_ascending(bemail, aemail); } /** * CompareFunc to sort Email by EmailProperties.total_bytes. If not available, emails are * compared by EmailIdentifier. */ - public static int compare_size_ascending(void *a, void *b) { - Geary.EmailProperties? aprop = (Geary.EmailProperties) ((Geary.Email *) a)->properties; - Geary.EmailProperties? bprop = (Geary.EmailProperties) ((Geary.Email *) b)->properties; + public static int compare_size_ascending(Geary.Email aemail, Geary.Email bemail) { + Geary.EmailProperties? aprop = (Geary.EmailProperties) aemail.properties; + Geary.EmailProperties? bprop = (Geary.EmailProperties) bemail.properties; if (aprop == null || bprop == null) - return compare_id_ascending(a, b); + return compare_id_ascending(aemail, bemail); long asize = aprop.total_bytes; long bsize = bprop.total_bytes; @@ -401,39 +397,36 @@ public class Geary.Email : BaseObject { else if (asize > bsize) return 1; else - return compare_id_ascending(a, b); + return compare_id_ascending(aemail, bemail); } /** * CompareFunc to sort Email by EmailProperties.total_bytes. If not available, emails are * compared by EmailIdentifier. */ - public static int compare_size_descending(void *a, void *b) { - return compare_size_ascending(b, a); + public static int compare_size_descending(Geary.Email aemail, Geary.Email bemail) { + return compare_size_ascending(bemail, aemail); } /** * CompareFunc to sort Email by EmailProperties.date_received. If not available, emails are * compared by EmailIdentifier. */ - public static int compare_date_received_ascending(void *a, void *b) { - Geary.Email aemail = (Geary.Email) a; - Geary.Email bemail = (Geary.Email) b; - + public static int compare_date_received_ascending(Geary.Email aemail, Geary.Email bemail) { if (aemail.properties == null || bemail.properties == null) - return compare_id_ascending(a, b); + return compare_id_ascending(aemail, bemail); int cmp = aemail.properties.date_received.compare(bemail.properties.date_received); - return (cmp != 0) ? cmp : compare_id_ascending(a, b); + return (cmp != 0) ? cmp : compare_id_ascending(aemail, bemail); } /** * CompareFunc to sort Email by EmailProperties.date_received. If not available, emails are * compared by EmailIdentifier. */ - public static int compare_date_received_descending(void *a, void *b) { - return compare_date_received_ascending(b, a); + public static int compare_date_received_descending(Geary.Email aemail, Geary.Email bemail) { + return compare_date_received_ascending(bemail, aemail); } } diff --git a/src/engine/api/geary-folder-path.vala b/src/engine/api/geary-folder-path.vala index 17115b0f..90ddc248 100644 --- a/src/engine/api/geary-folder-path.vala +++ b/src/engine/api/geary-folder-path.vala @@ -4,13 +4,14 @@ * (version 2.1 or later). See the COPYING file in this distribution. */ -public class Geary.FolderPath : BaseObject, Hashable, Equalable, Comparable { +public class Geary.FolderPath : BaseObject, Gee.Hashable, + Gee.Comparable { public string basename { get; private set; } private Gee.List? path = null; private string? fullpath = null; private string? fullpath_separator = null; - private uint hash = uint.MAX; + private uint stored_hash = uint.MAX; protected FolderPath(string basename) { assert(this is FolderRoot); @@ -123,11 +124,7 @@ public class Geary.FolderPath : BaseObject, Hashable, Equalable, Comparable { * are less-than longer paths, assuming the path elements are equal up to the shorter path's * length. */ - public int compare(Comparable o) { - FolderPath? other = o as FolderPath; - if (other == null) - return -1; - + public int compare_to(Geary.FolderPath other) { if (this == other) return 0; @@ -149,9 +146,9 @@ public class Geary.FolderPath : BaseObject, Hashable, Equalable, Comparable { return this_list.size - other_list.size; } - public uint to_hash() { - if (hash != uint.MAX) - return hash; + public uint hash() { + if (stored_hash != uint.MAX) + return stored_hash; bool cs = get_root().case_sensitive; @@ -162,23 +159,16 @@ public class Geary.FolderPath : BaseObject, Hashable, Equalable, Comparable { for (int ctr = 1; ctr < path_length; ctr++) calc ^= get_folder_at(ctr).get_basename_hash(cs); - hash = calc; + stored_hash = calc; - return hash; + return stored_hash; } private bool is_basename_equal(string cmp, bool cs) { return cs ? (basename == cmp) : (basename.down() == cmp.down()); } - public bool equals(Equalable o) { - FolderPath? other = o as FolderPath; - if (o == null) - return false; - - if (o == this) - return true; - + public bool equal_to(Geary.FolderPath other) { int path_length = get_path_length(); if (other.get_path_length() != path_length) return false; diff --git a/src/engine/api/geary-folder-supports-archive.vala b/src/engine/api/geary-folder-supports-archive.vala index 6c00dbbb..a7d1b4f8 100644 --- a/src/engine/api/geary-folder-supports-archive.vala +++ b/src/engine/api/geary-folder-supports-archive.vala @@ -28,8 +28,7 @@ public interface Geary.FolderSupportsArchive : Geary.Folder { */ public virtual async void archive_single_email_async(Geary.EmailIdentifier email_id, Cancellable? cancellable = null) throws Error { - Gee.ArrayList ids = new Gee.ArrayList( - Equalable.equal_func); + Gee.ArrayList ids = new Gee.ArrayList(); ids.add(email_id); yield archive_email_async(ids, cancellable); diff --git a/src/engine/api/geary-folder-supports-mark.vala b/src/engine/api/geary-folder-supports-mark.vala index e0c9313a..1cdfb0f9 100644 --- a/src/engine/api/geary-folder-supports-mark.vala +++ b/src/engine/api/geary-folder-supports-mark.vala @@ -26,8 +26,7 @@ public interface Geary.FolderSupportsMark : Geary.Folder { public virtual async void mark_single_email_async(Geary.EmailIdentifier to_mark, Geary.EmailFlags? flags_to_add, Geary.EmailFlags? flags_to_remove, Cancellable? cancellable = null) throws Error { - Gee.ArrayList list = new Gee.ArrayList( - Equalable.equal_func); + Gee.ArrayList list = new Gee.ArrayList(); list.add(to_mark); yield mark_email_async(list, flags_to_add, flags_to_remove, cancellable); diff --git a/src/engine/api/geary-folder-supports-remove.vala b/src/engine/api/geary-folder-supports-remove.vala index fe478635..f10567c6 100644 --- a/src/engine/api/geary-folder-supports-remove.vala +++ b/src/engine/api/geary-folder-supports-remove.vala @@ -29,8 +29,7 @@ public interface Geary.FolderSupportsRemove : Geary.Folder { */ public virtual async void remove_single_email_async(Geary.EmailIdentifier email_id, Cancellable? cancellable = null) throws Error { - Gee.ArrayList ids = new Gee.ArrayList( - Equalable.equal_func); + Gee.ArrayList ids = new Gee.ArrayList(); ids.add(email_id); yield remove_email_async(ids, cancellable); diff --git a/src/engine/common/common-message-data.vala b/src/engine/common/common-message-data.vala index 7ba9337e..e332ee3d 100644 --- a/src/engine/common/common-message-data.vala +++ b/src/engine/common/common-message-data.vala @@ -18,10 +18,11 @@ public abstract class Geary.Common.MessageData : BaseObject { public abstract string to_string(); } -public abstract class Geary.Common.StringMessageData : Geary.Common.MessageData, Hashable, Equalable { +public abstract class Geary.Common.StringMessageData : Geary.Common.MessageData, + Gee.Hashable { public string value { get; private set; } - private uint hash = uint.MAX; + private uint stored_hash = uint.MAX; public StringMessageData(string value) { this.value = value; @@ -30,22 +31,18 @@ public abstract class Geary.Common.StringMessageData : Geary.Common.MessageData, /** * Default definition of equals is case-sensitive comparison. */ - public virtual bool equals(Equalable e) { - StringMessageData? other = e as StringMessageData; - if (other == null) - return false; - + public virtual bool equal_to(StringMessageData other) { if (this == other) return true; - if (to_hash() != other.to_hash()) + if (hash() != other.hash()) return false; return (value == other.value); } - public virtual uint to_hash() { - return (hash != uint.MAX) ? hash : (hash = str_hash(value)); + public virtual uint hash() { + return (stored_hash != uint.MAX) ? stored_hash : (stored_hash = str_hash(value)); } public override string to_string() { @@ -53,28 +50,24 @@ public abstract class Geary.Common.StringMessageData : Geary.Common.MessageData, } } -public abstract class Geary.Common.IntMessageData : Geary.Common.MessageData, Hashable, Equalable { +public abstract class Geary.Common.IntMessageData : Geary.Common.MessageData, Gee.Hashable { public int value { get; private set; } - private uint hash = uint.MAX; + private uint stored_hash = uint.MAX; public IntMessageData(int value) { this.value = value; } - public virtual bool equals(Equalable e) { - IntMessageData? other = e as IntMessageData; - if (other == null) - return false; - + public virtual bool equal_to(Geary.Common.IntMessageData other) { if (this == other) return true; return (value == other.value); } - public virtual uint to_hash() { - return (hash != uint.MAX) ? hash : (hash = int_hash(value)); + public virtual uint hash() { + return (stored_hash != uint.MAX) ? stored_hash : (stored_hash = int_hash(value)); } public override string to_string() { @@ -82,28 +75,25 @@ public abstract class Geary.Common.IntMessageData : Geary.Common.MessageData, Ha } } -public abstract class Geary.Common.LongMessageData : Geary.Common.MessageData, Hashable, Equalable { +public abstract class Geary.Common.LongMessageData : Geary.Common.MessageData, + Gee.Hashable { public long value { get; private set; } - private uint hash = uint.MAX; + private uint stored_hash = uint.MAX; public LongMessageData(long value) { this.value = value; } - public virtual bool equals(Equalable e) { - LongMessageData? other = e as LongMessageData; - if (other == null) - return false; - + public virtual bool equal_to(Geary.Common.LongMessageData other) { if (this == other) return true; return (value == other.value); } - public virtual uint to_hash() { - return (hash != uint.MAX) ? hash : (hash = int64_hash((int64) value)); + public virtual uint hash() { + return (stored_hash != uint.MAX) ? stored_hash : (stored_hash = int64_hash((int64) value)); } public override string to_string() { @@ -111,28 +101,25 @@ public abstract class Geary.Common.LongMessageData : Geary.Common.MessageData, H } } -public abstract class Geary.Common.Int64MessageData : Geary.Common.MessageData, Hashable, Equalable { +public abstract class Geary.Common.Int64MessageData : Geary.Common.MessageData, + Gee.Hashable { public int64 value { get; private set; } - private uint hash = uint.MAX; + private uint stored_hash = uint.MAX; public Int64MessageData(int64 value) { this.value = value; } - public virtual bool equals(Equalable e) { - Int64MessageData? other = e as Int64MessageData; - if (other == null) - return false; - + public virtual bool equal_to(Geary.Common.Int64MessageData other) { if (this == other) return true; return (value == other.value); } - public virtual uint to_hash() { - return (hash != uint.MAX) ? hash : (hash = int64_hash(value)); + public virtual uint hash() { + return (stored_hash != uint.MAX) ? stored_hash : (stored_hash = int64_hash(value)); } public override string to_string() { diff --git a/src/engine/imap-db/imap-db-account.vala b/src/engine/imap-db/imap-db-account.vala index 80334454..f7f5016a 100644 --- a/src/engine/imap-db/imap-db-account.vala +++ b/src/engine/imap-db/imap-db-account.vala @@ -22,7 +22,7 @@ private class Geary.ImapDB.Account : BaseObject { private AccountInformation account_information; private ImapDB.Database? db = null; private Gee.HashMap folder_refs = - new Gee.HashMap(Hashable.hash_func, Equalable.equal_func); + new Gee.HashMap(); public ContactStore contact_store { get; private set; } public Account(Geary.AccountInformation account_information) { @@ -233,9 +233,9 @@ private class Geary.ImapDB.Account : BaseObject { // TODO: A better solution here would be to only pull the FolderProperties if the Folder // object itself doesn't already exist Gee.HashMap id_map = new Gee.HashMap< - Geary.FolderPath, int64?>(Hashable.hash_func, Equalable.equal_func); + Geary.FolderPath, int64?>(); Gee.HashMap prop_map = new Gee.HashMap< - Geary.FolderPath, Geary.Imap.FolderProperties>(Hashable.hash_func, Equalable.equal_func); + Geary.FolderPath, Geary.Imap.FolderProperties>(); yield db.exec_transaction_async(Db.TransactionType.RO, (cx) => { int64 parent_id = Db.INVALID_ROWID; if (parent != null) { diff --git a/src/engine/imap-db/imap-db-email-identifier.vala b/src/engine/imap-db/imap-db-email-identifier.vala index 207a42ee..c1f4c39e 100644 --- a/src/engine/imap-db/imap-db-email-identifier.vala +++ b/src/engine/imap-db/imap-db-email-identifier.vala @@ -9,7 +9,7 @@ private class Geary.ImapDB.EmailIdentifier : Geary.EmailIdentifier { base (message_id); } - public override bool equals(Geary.Equalable o) { + public override bool equal_to(Geary.EmailIdentifier o) { Geary.ImapDB.EmailIdentifier? other = o as Geary.ImapDB.EmailIdentifier; if (other == null) return false; diff --git a/src/engine/imap-db/imap-db-folder.vala b/src/engine/imap-db/imap-db-folder.vala index 0580514a..370887a3 100644 --- a/src/engine/imap-db/imap-db-folder.vala +++ b/src/engine/imap-db/imap-db-folder.vala @@ -62,8 +62,7 @@ private class Geary.ImapDB.Folder : BaseObject, Geary.ReferenceSemantics { private string account_owner_email; private int64 folder_id; private Geary.Imap.FolderProperties properties; - private Gee.HashSet marked_removed = new Gee.HashSet( - Hashable.hash_func, Equalable.equal_func); + private Gee.HashSet marked_removed = new Gee.HashSet(); internal Folder(ImapDB.Database db, Geary.FolderPath path, ContactStore contact_store, string account_owner_email, int64 folder_id, Geary.Imap.FolderProperties properties) { @@ -660,7 +659,7 @@ private class Geary.ImapDB.Folder : BaseObject, Geary.ReferenceSemantics { return null; Gee.HashMap map = new Gee.HashMap< - Geary.EmailIdentifier, Geary.Email.Field>(Hashable.hash_func, Equalable.equal_func); + Geary.EmailIdentifier, Geary.Email.Field>(); // Break up the work Gee.List list = new Gee.ArrayList(); @@ -1054,7 +1053,7 @@ private class Geary.ImapDB.Folder : BaseObject, Geary.ReferenceSemantics { Db.Statement fetch_stmt = cx.prepare("SELECT flags FROM MessageTable WHERE id=?"); Gee.Map map = new Gee.HashMap< - Geary.EmailIdentifier, Geary.EmailFlags>(Hashable.hash_func, Equalable.equal_func); + Geary.EmailIdentifier, Geary.EmailFlags>(); foreach (Geary.EmailIdentifier id in ids) { int64 message_id = do_find_message(cx, id, ListFlags.NONE, cancellable); diff --git a/src/engine/imap-db/outbox/smtp-outbox-email-identifier.vala b/src/engine/imap-db/outbox/smtp-outbox-email-identifier.vala index e906e7ca..dccfccfc 100644 --- a/src/engine/imap-db/outbox/smtp-outbox-email-identifier.vala +++ b/src/engine/imap-db/outbox/smtp-outbox-email-identifier.vala @@ -9,7 +9,7 @@ private class Geary.SmtpOutboxEmailIdentifier : Geary.EmailIdentifier { base (ordering); } - public override bool equals(Geary.Equalable o) { + public override bool equal_to(Geary.EmailIdentifier o) { SmtpOutboxEmailIdentifier? other = o as SmtpOutboxEmailIdentifier; if (other == null) return false; diff --git a/src/engine/imap-db/outbox/smtp-outbox-folder.vala b/src/engine/imap-db/outbox/smtp-outbox-folder.vala index ee993b63..245654a0 100644 --- a/src/engine/imap-db/outbox/smtp-outbox-folder.vala +++ b/src/engine/imap-db/outbox/smtp-outbox-folder.vala @@ -413,7 +413,7 @@ private class Geary.SmtpOutboxFolder : Geary.AbstractFolder, Geary.FolderSupport check_open(); Gee.Map map = new Gee.HashMap< - Geary.EmailIdentifier, Geary.Email.Field>(Hashable.hash_func, Equalable.equal_func); + Geary.EmailIdentifier, Geary.Email.Field>(); yield db.exec_transaction_async(Db.TransactionType.RO, (cx) => { Db.Statement stmt = cx.prepare( "SELECT id FROM SmtpOutboxTable WHERE ordering=?"); diff --git a/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala b/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala index 012773d4..278f97c7 100644 --- a/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala +++ b/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala @@ -41,8 +41,7 @@ private class Geary.ImapEngine.GmailAccount : Geary.ImapEngine.GenericAccount { base (name, account_information, remote, local); if (path_type_map == null) { - path_type_map = new Gee.HashMap( - Hashable.hash_func, Equalable.equal_func); + path_type_map = new Gee.HashMap(); path_type_map.set(new Geary.FolderRoot(Imap.Account.INBOX_NAME, Imap.Account.ASSUMED_SEPARATOR, Imap.Folder.CASE_SENSITIVE), SpecialFolderType.INBOX); diff --git a/src/engine/imap-engine/imap-engine-account-synchronizer.vala b/src/engine/imap-engine/imap-engine-account-synchronizer.vala index ef411650..46f1c0f1 100644 --- a/src/engine/imap-engine/imap-engine-account-synchronizer.vala +++ b/src/engine/imap-engine/imap-engine-account-synchronizer.vala @@ -120,7 +120,7 @@ private class Geary.ImapEngine.AccountSynchronizer : Geary.BaseObject { return cmp; // sort by path to stabilize the sort - return a.get_path().compare(b.get_path()); + return a.get_path().compare_to(b.get_path()); } // Lower the score, the higher the importance. diff --git a/src/engine/imap-engine/imap-engine-email-flag-watcher.vala b/src/engine/imap-engine/imap-engine-email-flag-watcher.vala index 18da0d1b..d2950175 100644 --- a/src/engine/imap-engine/imap-engine-email-flag-watcher.vala +++ b/src/engine/imap-engine/imap-engine-email-flag-watcher.vala @@ -109,7 +109,7 @@ private class Geary.ImapEngine.EmailFlagWatcher : BaseObject { // Get all email identifiers in the local folder; also, update the low and count arguments Gee.HashMap local_map = new Gee.HashMap< - Geary.EmailIdentifier, Geary.EmailFlags>(Geary.Hashable.hash_func, Geary.Equalable.equal_func); + Geary.EmailIdentifier, Geary.EmailFlags>(); foreach (Geary.Email e in list_local) { if (low == -1) low = e.position; @@ -131,13 +131,12 @@ private class Geary.ImapEngine.EmailFlagWatcher : BaseObject { // Build map of emails that have changed. Gee.HashMap changed_map = - new Gee.HashMap(Geary.Hashable.hash_func, - Geary.Equalable.equal_func); + new Gee.HashMap(); foreach (Geary.Email e in list_remote) { if (!local_map.has_key(e.id)) continue; - if (!local_map.get(e.id).equals(e.email_flags)) + if (!local_map.get(e.id).equal_to(e.email_flags)) changed_map.set(e.id, e.email_flags); } diff --git a/src/engine/imap-engine/imap-engine-email-prefetcher.vala b/src/engine/imap-engine/imap-engine-email-prefetcher.vala index 56571c16..6d1b027b 100644 --- a/src/engine/imap-engine/imap-engine-email-prefetcher.vala +++ b/src/engine/imap-engine/imap-engine-email-prefetcher.vala @@ -20,8 +20,7 @@ public class Geary.ImapEngine.EmailPrefetcher : Object { private unowned Geary.Folder folder; private int start_delay_sec; private NonblockingMutex mutex = new NonblockingMutex(); - private Gee.HashSet prefetch_ids = new Gee.HashSet( - Hashable.hash_func, Equalable.equal_func); + private Gee.HashSet prefetch_ids = new Gee.HashSet(); private uint schedule_id = 0; private Cancellable cancellable = new Cancellable(); @@ -119,8 +118,7 @@ public class Geary.ImapEngine.EmailPrefetcher : Object { low = Numeric.int_floor(low - PREFETCH_CHUNKS, 1); - Gee.HashSet ids = new Gee.HashSet( - Hashable.hash_func, Equalable.equal_func); + Gee.HashSet ids = new Gee.HashSet(); foreach (Geary.Email email in list) ids.add(email.id); @@ -176,7 +174,7 @@ public class Geary.ImapEngine.EmailPrefetcher : Object { private async void do_prefetch_batch() throws Error { // snarf up all requested EmailIdentifiers for this round Gee.HashSet ids = prefetch_ids; - prefetch_ids = new Gee.HashSet(Hashable.hash_func, Equalable.equal_func); + prefetch_ids = new Gee.HashSet(); if (ids.size == 0) return; diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala b/src/engine/imap-engine/imap-engine-generic-account.vala index 7dde3aa8..66e27584 100644 --- a/src/engine/imap-engine/imap-engine-generic-account.vala +++ b/src/engine/imap-engine/imap-engine-generic-account.vala @@ -14,11 +14,10 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount { private ImapDB.Account local; private bool open = false; private Gee.HashMap properties_map = new Gee.HashMap< - FolderPath, Imap.FolderProperties>(Hashable.hash_func, Equalable.equal_func); + FolderPath, Imap.FolderProperties>(); private Gee.HashMap existing_folders = new Gee.HashMap< - FolderPath, GenericFolder>(Hashable.hash_func, Equalable.equal_func); - private Gee.HashMap local_only = new Gee.HashMap( - Hashable.hash_func, Equalable.equal_func); + FolderPath, GenericFolder>(); + private Gee.HashMap local_only = new Gee.HashMap(); private uint refresh_folder_timeout_id = 0; private bool in_refresh_enumerate = false; private Cancellable refresh_cancellable = new Cancellable(); @@ -179,7 +178,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount { foreach(FolderPath path in existing_folders.keys) { FolderPath? path_parent = path.get_parent(); if ((parent == null && path_parent == null) || - (parent != null && path_parent != null && path_parent.equals(parent))) { + (parent != null && path_parent != null && path_parent.equal_to(parent))) { matches.add(existing_folders.get(path)); } } @@ -317,8 +316,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount { } // update all remote folders properties in the local store and active in the system - Gee.HashSet altered_paths = new Gee.HashSet( - Hashable.hash_func, Equalable.equal_func); + Gee.HashSet altered_paths = new Gee.HashSet(); foreach (Imap.Folder remote_folder in remote_folders) { // only worry about alterations if the remote is openable if (remote_folder.get_properties().is_openable.is_possible()) { @@ -347,14 +345,12 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount { } // Get local paths of all engine (local) folders - Gee.Set local_paths = new Gee.HashSet( - Geary.Hashable.hash_func, Geary.Equalable.equal_func); + Gee.Set local_paths = new Gee.HashSet(); foreach (Geary.Folder local_folder in engine_folders) local_paths.add(local_folder.get_path()); // Get remote paths of all remote folders - Gee.Set remote_paths = new Gee.HashSet( - Geary.Hashable.hash_func, Geary.Equalable.equal_func); + Gee.Set remote_paths = new Gee.HashSet(); foreach (Geary.Imap.Folder remote_folder in remote_folders) { remote_paths.add(remote_folder.get_path()); diff --git a/src/engine/imap-engine/imap-engine-generic-folder.vala b/src/engine/imap-engine/imap-engine-generic-folder.vala index 38bb22c4..dc908cce 100644 --- a/src/engine/imap-engine/imap-engine-generic-folder.vala +++ b/src/engine/imap-engine/imap-engine-generic-folder.vala @@ -151,7 +151,7 @@ private class Geary.ImapEngine.GenericFolder : Geary.AbstractFolder, Geary.Folde Gee.Collection all_locally_appended_ids = new Gee.ArrayList(); Gee.Collection all_removed_ids = new Gee.ArrayList(); Gee.Map all_flags_changed = new Gee.HashMap(Hashable.hash_func, Equalable.equal_func); + Geary.EmailFlags>(); Geary.Imap.EmailIdentifier current_start_id = new Geary.Imap.EmailIdentifier(earliest_uid, local_folder.get_path()); for (;;) { @@ -218,7 +218,7 @@ private class Geary.ImapEngine.GenericFolder : Geary.AbstractFolder, Geary.Folde Geary.Imap.EmailFlags? local_email_flags = (Geary.Imap.EmailFlags) local_email.email_flags; Geary.Imap.EmailFlags remote_email_flags = (Geary.Imap.EmailFlags) remote_email.email_flags; - if ((local_email_flags == null) || !local_email_flags.equals(remote_email_flags)) { + if ((local_email_flags == null) || !local_email_flags.equal_to(remote_email_flags)) { // check before writebehind if (replay_queue.query_local_writebehind_operation(ReplayOperation.WritebehindOperation.UPDATE_FLAGS, remote_email.id, (Imap.EmailFlags) remote_email.email_flags)) { @@ -364,8 +364,8 @@ private class Geary.ImapEngine.GenericFolder : Geary.AbstractFolder, Geary.Folde // if gone past both local and remote extremes, time to exit // TODO: If UIDNEXT isn't available on server, will need to fetch the highest UID - if (current_start_id.uid.compare(latest_uid) >= 0 - && current_start_id.uid.compare(remote_properties.uid_next) >= 0) + if (current_start_id.uid.compare_to(latest_uid) >= 0 + && current_start_id.uid.compare_to(remote_properties.uid_next) >= 0) break; } @@ -618,10 +618,8 @@ private class Geary.ImapEngine.GenericFolder : Geary.AbstractFolder, Geary.Folde debug("do_replay_appended_messages %s: remote_count=%d new_remote_count=%d", to_string(), remote_count, new_remote_count); - Gee.HashSet created = new Gee.HashSet( - Hashable.hash_func, Equalable.equal_func); - Gee.HashSet appended = new Gee.HashSet( - Hashable.hash_func, Equalable.equal_func); + Gee.HashSet created = new Gee.HashSet(); + Gee.HashSet appended = new Gee.HashSet(); try { // If remote doesn't fully open, then don't fire signal, as we'll be unable to @@ -1066,8 +1064,7 @@ private class Geary.ImapEngine.GenericFolder : Geary.AbstractFolder, Geary.Folde int mutex_token = yield normalize_email_positions_mutex.claim_async(cancellable); - Gee.HashSet created_ids = new Gee.HashSet( - Hashable.hash_func, Equalable.equal_func); + Gee.HashSet created_ids = new Gee.HashSet(); Error? error = null; try { local_count = yield local_folder.get_email_count_async(ImapDB.Folder.ListFlags.NONE, diff --git a/src/engine/imap-engine/replay-ops/imap-engine-copy-email.vala b/src/engine/imap-engine/replay-ops/imap-engine-copy-email.vala index abe33299..34966d65 100644 --- a/src/engine/imap-engine/replay-ops/imap-engine-copy-email.vala +++ b/src/engine/imap-engine/replay-ops/imap-engine-copy-email.vala @@ -6,8 +6,7 @@ private class Geary.ImapEngine.CopyEmail : Geary.ImapEngine.SendReplayOperation { private GenericFolder engine; - private Gee.List to_copy = new Gee.ArrayList( - Equalable.equal_func); + private Gee.List to_copy = new Gee.ArrayList(); private Geary.FolderPath destination; private Cancellable? cancellable; diff --git a/src/engine/imap-engine/replay-ops/imap-engine-expunge-email.vala b/src/engine/imap-engine/replay-ops/imap-engine-expunge-email.vala index b8eaa684..5af26e3f 100644 --- a/src/engine/imap-engine/replay-ops/imap-engine-expunge-email.vala +++ b/src/engine/imap-engine/replay-ops/imap-engine-expunge-email.vala @@ -6,8 +6,7 @@ private class Geary.ImapEngine.ExpungeEmail : Geary.ImapEngine.SendReplayOperation { private GenericFolder engine; - private Gee.List to_remove = new Gee.ArrayList( - Equalable.equal_func); + private Gee.List to_remove = new Gee.ArrayList(); private Cancellable? cancellable; private int original_count = 0; diff --git a/src/engine/imap-engine/replay-ops/imap-engine-fetch-email.vala b/src/engine/imap-engine/replay-ops/imap-engine-fetch-email.vala index 042826be..0315ee23 100644 --- a/src/engine/imap-engine/replay-ops/imap-engine-fetch-email.vala +++ b/src/engine/imap-engine/replay-ops/imap-engine-fetch-email.vala @@ -84,7 +84,7 @@ private class Geary.ImapEngine.FetchEmail : Geary.ImapEngine.SendReplayOperation public override bool query_local_writebehind_operation(ReplayOperation.WritebehindOperation op, EmailIdentifier id, Imap.EmailFlags? flags) { - if (!this.id.equals(id)) + if (!this.id.equal_to(id)) return true; switch (op) { diff --git a/src/engine/imap-engine/replay-ops/imap-engine-list-email-by-sparse-id.vala b/src/engine/imap-engine/replay-ops/imap-engine-list-email-by-sparse-id.vala index 63ae3e5d..f8c7d11c 100644 --- a/src/engine/imap-engine/replay-ops/imap-engine-list-email-by-sparse-id.vala +++ b/src/engine/imap-engine/replay-ops/imap-engine-list-email-by-sparse-id.vala @@ -73,8 +73,7 @@ private class Geary.ImapEngine.ListEmailBySparseID : Geary.ImapEngine.SendReplay } private GenericFolder owner; - private Gee.HashSet ids = new Gee.HashSet( - Hashable.hash_func, Equalable.equal_func); + private Gee.HashSet ids = new Gee.HashSet(); private Geary.Email.Field required_fields; private Folder.ListFlags flags; private bool local_only; @@ -83,7 +82,7 @@ private class Geary.ImapEngine.ListEmailBySparseID : Geary.ImapEngine.SendReplay private unowned EmailCallback cb; private Cancellable? cancellable; private Gee.HashMultiMap unfulfilled = new Gee.HashMultiMap< - Geary.Email.Field, Geary.EmailIdentifier>(null, null, Hashable.hash_func, Equalable.equal_func); + Geary.Email.Field, Geary.EmailIdentifier>(); public ListEmailBySparseID(GenericFolder owner, Gee.Collection ids, Geary.Email.Field required_fields, Folder.ListFlags flags, Gee.List? accumulator, @@ -173,7 +172,7 @@ private class Geary.ImapEngine.ListEmailBySparseID : Geary.ImapEngine.SendReplay if (accumulator != null) { Gee.HashSet wb_removed = new Gee.HashSet(); foreach (Geary.Email email in accumulator) { - if (email.id.equals(id)) + if (email.id.equal_to(id)) wb_removed.add(email); } diff --git a/src/engine/imap-engine/replay-ops/imap-engine-list-email.vala b/src/engine/imap-engine/replay-ops/imap-engine-list-email.vala index 143677b5..fd50b237 100644 --- a/src/engine/imap-engine/replay-ops/imap-engine-list-email.vala +++ b/src/engine/imap-engine/replay-ops/imap-engine-list-email.vala @@ -55,7 +55,7 @@ private class Geary.ImapEngine.ListEmail : Geary.ImapEngine.SendReplayOperation private Gee.List? local_list = null; private int local_list_size = 0; private Gee.HashMultiMap unfulfilled = new Gee.HashMultiMap< - Geary.Email.Field, Geary.EmailIdentifier>(null, null, Hashable.hash_func, Equalable.equal_func); + Geary.Email.Field, Geary.EmailIdentifier>(); public ListEmail(GenericFolder engine, int low, int count, Geary.Email.Field required_fields, Folder.ListFlags flags, Gee.List? accumulator, EmailCallback? cb, Cancellable? cancellable) { @@ -215,7 +215,7 @@ private class Geary.ImapEngine.ListEmail : Geary.ImapEngine.SendReplayOperation if (accumulator != null) { Gee.HashSet wb_removed = new Gee.HashSet(); foreach (Geary.Email email in accumulator) { - if (email.id.equals(id)) + if (email.id.equal_to(id)) wb_removed.add(email); } @@ -372,8 +372,7 @@ private class Geary.ImapEngine.ListEmail : Geary.ImapEngine.SendReplayOperation assert(create_op.merged != null); // report locally added (non-duplicate, not unknown) emails & collect emails post-merge - Gee.HashSet created_ids = new Gee.HashSet( - Hashable.hash_func, Equalable.equal_func); + Gee.HashSet created_ids = new Gee.HashSet(); foreach (Geary.Email email in create_op.created.keys) { // true means created if (create_op.created.get(email)) diff --git a/src/engine/imap-engine/replay-ops/imap-engine-mark-email.vala b/src/engine/imap-engine/replay-ops/imap-engine-mark-email.vala index d327dcd8..f95a3226 100644 --- a/src/engine/imap-engine/replay-ops/imap-engine-mark-email.vala +++ b/src/engine/imap-engine/replay-ops/imap-engine-mark-email.vala @@ -6,8 +6,7 @@ private class Geary.ImapEngine.MarkEmail : Geary.ImapEngine.SendReplayOperation { private GenericFolder engine; - private Gee.List to_mark = new Gee.ArrayList( - Equalable.equal_func); + private Gee.List to_mark = new Gee.ArrayList(); private Geary.EmailFlags? flags_to_add; private Geary.EmailFlags? flags_to_remove; private Gee.Map? original_flags = null; diff --git a/src/engine/imap-engine/replay-ops/imap-engine-move-email.vala b/src/engine/imap-engine/replay-ops/imap-engine-move-email.vala index 356dbf9c..0c5e36cd 100644 --- a/src/engine/imap-engine/replay-ops/imap-engine-move-email.vala +++ b/src/engine/imap-engine/replay-ops/imap-engine-move-email.vala @@ -6,8 +6,7 @@ private class Geary.ImapEngine.MoveEmail : Geary.ImapEngine.SendReplayOperation { private GenericFolder engine; - private Gee.List to_move = new Gee.ArrayList( - Equalable.equal_func); + private Gee.List to_move = new Gee.ArrayList(); private Geary.FolderPath destination; private Cancellable? cancellable; private int original_count = 0; diff --git a/src/engine/imap-engine/yahoo/imap-engine-yahoo-account.vala b/src/engine/imap-engine/yahoo/imap-engine-yahoo-account.vala index f914bab0..578d3e3c 100644 --- a/src/engine/imap-engine/yahoo/imap-engine-yahoo-account.vala +++ b/src/engine/imap-engine/yahoo/imap-engine-yahoo-account.vala @@ -38,8 +38,7 @@ private class Geary.ImapEngine.YahooAccount : Geary.ImapEngine.GenericAccount { base (name, account_information, remote, local); if (special_map == null) { - special_map = new Gee.HashMap( - Hashable.hash_func, Equalable.equal_func); + special_map = new Gee.HashMap(); special_map.set(new Geary.FolderRoot(Imap.Account.INBOX_NAME, Imap.Account.ASSUMED_SEPARATOR, false), Geary.SpecialFolderType.INBOX); diff --git a/src/engine/imap/api/imap-email-flags.vala b/src/engine/imap/api/imap-email-flags.vala index 15774aa5..94c30a84 100644 --- a/src/engine/imap/api/imap-email-flags.vala +++ b/src/engine/imap/api/imap-email-flags.vala @@ -19,10 +19,10 @@ public class Geary.Imap.EmailFlags : Geary.EmailFlags { protected override void notify_added(Gee.Collection added) { foreach (EmailFlag flag in added) { - if (flag.equals(UNREAD)) + if (flag.equal_to(UNREAD)) message_flags.remove(MessageFlag.SEEN); - if (flag.equals(FLAGGED)) + if (flag.equal_to(FLAGGED)) message_flags.add(MessageFlag.FLAGGED); } @@ -31,10 +31,10 @@ public class Geary.Imap.EmailFlags : Geary.EmailFlags { protected override void notify_removed(Gee.Collection removed) { foreach (EmailFlag flag in removed) { - if (flag.equals(UNREAD)) + if (flag.equal_to(UNREAD)) message_flags.add(MessageFlag.SEEN); - if (flag.equals(FLAGGED)) + if (flag.equal_to(FLAGGED)) message_flags.remove(MessageFlag.FLAGGED); } diff --git a/src/engine/imap/api/imap-email-identifier.vala b/src/engine/imap/api/imap-email-identifier.vala index 4b237660..322cda48 100644 --- a/src/engine/imap/api/imap-email-identifier.vala +++ b/src/engine/imap/api/imap-email-identifier.vala @@ -19,11 +19,11 @@ private class Geary.Imap.EmailIdentifier : Geary.EmailIdentifier { return folder_path; } - public override uint to_hash() { - return uid.to_hash(); + public override uint hash() { + return uid.hash(); } - public override bool equals(Equalable o) { + public override bool equal_to(Geary.EmailIdentifier o) { Geary.Imap.EmailIdentifier? other = o as Geary.Imap.EmailIdentifier; if (other == null) return false; @@ -31,7 +31,7 @@ private class Geary.Imap.EmailIdentifier : Geary.EmailIdentifier { if (this == other) return true; - return uid.equals(other.uid) && folder_path.equals(other.folder_path); + return uid.equal_to(other.uid) && folder_path.equal_to(other.folder_path); } public override string to_string() { diff --git a/src/engine/imap/api/imap-email-properties.vala b/src/engine/imap/api/imap-email-properties.vala index cc2c6760..7d682138 100644 --- a/src/engine/imap/api/imap-email-properties.vala +++ b/src/engine/imap/api/imap-email-properties.vala @@ -4,7 +4,7 @@ * (version 2.1 or later). See the COPYING file in this distribution. */ -public class Geary.Imap.EmailProperties : Geary.EmailProperties, Equalable { +public class Geary.Imap.EmailProperties : Geary.EmailProperties, Gee.Hashable { public InternalDate? internaldate { get; private set; } public RFC822.Size? rfc822_size { get; private set; } @@ -15,11 +15,7 @@ public class Geary.Imap.EmailProperties : Geary.EmailProperties, Equalable { this.rfc822_size = rfc822_size; } - public bool equals(Equalable e) { - Imap.EmailProperties? other = e as Imap.EmailProperties; - if (other == null) - return false; - + public bool equal_to(Geary.Imap.EmailProperties other) { if (this == other) return true; @@ -34,6 +30,10 @@ public class Geary.Imap.EmailProperties : Geary.EmailProperties, Equalable { return true; } + public uint hash() { + return to_string().hash(); + } + public override string to_string() { return "internaldate:%s/size:%s".printf((internaldate != null) ? internaldate.to_string() : "(none)", (rfc822_size != null) ? rfc822_size.to_string() : "(none)"); diff --git a/src/engine/imap/api/imap-folder-properties.vala b/src/engine/imap/api/imap-folder-properties.vala index 010ce86c..7f95a141 100644 --- a/src/engine/imap/api/imap-folder-properties.vala +++ b/src/engine/imap/api/imap-folder-properties.vala @@ -60,7 +60,7 @@ public class Geary.Imap.FolderProperties : Geary.FolderProperties { */ public Trillian have_contents_changed(Geary.Imap.FolderProperties other) { // UIDNEXT changes indicate messages have been added, but not if they've been removed - if (uid_next != null && other.uid_next != null && !uid_next.equals(other.uid_next)) + if (uid_next != null && other.uid_next != null && !uid_next.equal_to(other.uid_next)) return Trillian.TRUE; // Gmail includes Chat messages in STATUS results but not in SELECT/EXAMINE diff --git a/src/engine/imap/message/imap-flag.vala b/src/engine/imap/message/imap-flag.vala index 4546b2e5..d9fec068 100644 --- a/src/engine/imap/message/imap-flag.vala +++ b/src/engine/imap/message/imap-flag.vala @@ -4,7 +4,7 @@ * (version 2.1 or later). See the COPYING file in this distribution. */ -public abstract class Geary.Imap.Flag : BaseObject, Equalable, Hashable { +public abstract class Geary.Imap.Flag : BaseObject, Gee.Hashable { public string value { get; private set; } public Flag(string value) { @@ -19,15 +19,11 @@ public abstract class Geary.Imap.Flag : BaseObject, Equalable, Hashable { return this.value.down() == value.down(); } - public bool equals(Equalable b) { - Flag? flag = b as Flag; - if (flag == null) - return false; - + public bool equal_to(Geary.Imap.Flag flag) { return (flag == this) ? true : flag.equals_string(value); } - public uint to_hash() { + public uint hash() { return str_hash(value.down()); } diff --git a/src/engine/imap/message/imap-message-data.vala b/src/engine/imap/message/imap-message-data.vala index 8fcacb3c..0ca7eed9 100644 --- a/src/engine/imap/message/imap-message-data.vala +++ b/src/engine/imap/message/imap-message-data.vala @@ -19,7 +19,7 @@ public interface Geary.Imap.MessageData : Geary.Common.MessageData { } -public class Geary.Imap.UID : Geary.Common.Int64MessageData, Geary.Imap.MessageData, Comparable { +public class Geary.Imap.UID : Geary.Common.Int64MessageData, Geary.Imap.MessageData, Gee.Comparable { // Using statics because int32.MAX is static, not const (??) public static int64 MIN = 1; public static int64 MAX = int32.MAX; @@ -63,11 +63,7 @@ public class Geary.Imap.UID : Geary.Common.Int64MessageData, Geary.Imap.MessageD return new UID(Numeric.int64_floor(value - 1, MIN)); } - public virtual int compare(Comparable o) { - UID? other = o as UID; - if (other == null) - return -1; - + public virtual int compare_to(Geary.Imap.UID other) { if (value < other.value) return -1; else if (value > other.value) @@ -94,13 +90,14 @@ public class Geary.Imap.MessageNumber : Geary.Common.IntMessageData, Geary.Imap. } } -public abstract class Geary.Imap.Flags : Geary.Common.MessageData, Geary.Imap.MessageData, Equalable { +public abstract class Geary.Imap.Flags : Geary.Common.MessageData, Geary.Imap.MessageData, + Gee.Hashable { public int size { get { return list.size; } } protected Gee.Set list; public Flags(Gee.Collection flags) { - list = new Gee.HashSet(Hashable.hash_func, Equalable.equal_func); + list = new Gee.HashSet(); list.add_all(flags); } @@ -120,11 +117,7 @@ public abstract class Geary.Imap.Flags : Geary.Common.MessageData, Geary.Imap.Me return to_string(); } - public bool equals(Equalable e) { - Imap.Flags? other = e as Imap.Flags; - if (other == null) - return false; - + public bool equal_to(Geary.Imap.Flags other) { if (this == other) return true; @@ -150,6 +143,10 @@ public abstract class Geary.Imap.Flags : Geary.Common.MessageData, Geary.Imap.Me return builder.str; } + + public uint hash() { + return to_string().hash(); + } } public class Geary.Imap.MessageFlags : Geary.Imap.Flags { diff --git a/src/engine/imap/message/imap-tag.vala b/src/engine/imap/message/imap-tag.vala index cbc86845..c2ba17e1 100644 --- a/src/engine/imap/message/imap-tag.vala +++ b/src/engine/imap/message/imap-tag.vala @@ -4,7 +4,7 @@ * (version 2.1 or later). See the COPYING file in this distribution. */ -public class Geary.Imap.Tag : StringParameter, Hashable, Equalable { +public class Geary.Imap.Tag : StringParameter, Gee.Hashable { public const string UNTAGGED_VALUE = "*"; public const string CONTINUATION_VALUE = "+"; public const string UNASSIGNED_VALUE = "----"; @@ -54,15 +54,11 @@ public class Geary.Imap.Tag : StringParameter, Hashable, Equalable { return (value != UNASSIGNED_VALUE) && (value != CONTINUATION_VALUE); } - public uint to_hash() { + public uint hash() { return str_hash(value); } - public bool equals(Equalable e) { - Tag? tag = e as Tag; - if (tag == null) - return false; - + public bool equal_to(Geary.Imap.Tag tag) { if (this == tag) return true; diff --git a/src/engine/imap/transport/imap-client-connection.vala b/src/engine/imap/transport/imap-client-connection.vala index d97138a0..e8b3e8ca 100644 --- a/src/engine/imap/transport/imap-client-connection.vala +++ b/src/engine/imap/transport/imap-client-connection.vala @@ -89,8 +89,7 @@ public class Geary.Imap.ClientConnection : BaseObject { private char tag_prefix = 'a'; private uint flush_timeout_id = 0; private bool idle_when_quiet = false; - private Gee.HashSet posted_idle_tags = new Gee.HashSet(Hashable.hash_func, - Equalable.equal_func); + private Gee.HashSet posted_idle_tags = new Gee.HashSet(); private uint timeout_id = 0; private uint timeout_cmd_count = 0; diff --git a/src/engine/imap/transport/imap-client-session.vala b/src/engine/imap/transport/imap-client-session.vala index 05f74f54..4eab5a6e 100644 --- a/src/engine/imap/transport/imap-client-session.vala +++ b/src/engine/imap/transport/imap-client-session.vala @@ -181,10 +181,8 @@ public class Geary.Imap.ClientSession : BaseObject { private ClientConnection? cx = null; private string? current_mailbox = null; private bool current_mailbox_readonly = false; - private Gee.HashMap tag_cb = new Gee.HashMap( - Hashable.hash_func, Equalable.equal_func); - private Gee.HashMap tag_response = new Gee.HashMap( - Hashable.hash_func, Equalable.equal_func); + private Gee.HashMap tag_cb = new Gee.HashMap(); + private Gee.HashMap tag_response = new Gee.HashMap(); private Capabilities capabilities = new Capabilities(0); private int next_capabilities_revision = 1; private CommandResponse current_cmd_response = new CommandResponse(); @@ -1311,7 +1309,7 @@ public class Geary.Imap.ClientSession : BaseObject { assert(removed); assert(cmd_response.is_sealed()); - assert(cmd_response.status_response.tag.equals(cmd.tag)); + assert(cmd_response.status_response.tag.equal_to(cmd.tag)); if (!imap_server_pipeline && claim_stub != NonblockingMutex.INVALID_TOKEN) { try { diff --git a/src/engine/nonblocking/nonblocking-mailbox.vala b/src/engine/nonblocking/nonblocking-mailbox.vala index 3d9f9770..ad560743 100644 --- a/src/engine/nonblocking/nonblocking-mailbox.vala +++ b/src/engine/nonblocking/nonblocking-mailbox.vala @@ -17,7 +17,7 @@ public class Geary.NonblockingMailbox : BaseObject { if (comparator == null) queue = new Gee.LinkedList(); else - queue = new Gee.PriorityQueue(comparator); + queue = new Gee.PriorityQueue(); } public bool send(G msg) { diff --git a/src/engine/rfc822/rfc822-message-data.vala b/src/engine/rfc822/rfc822-message-data.vala index 32ed3e2e..b8780f71 100644 --- a/src/engine/rfc822/rfc822-message-data.vala +++ b/src/engine/rfc822/rfc822-message-data.vala @@ -97,7 +97,8 @@ public class Geary.RFC822.MessageIDList : Geary.Common.MessageData, Geary.RFC822 } } -public class Geary.RFC822.Date : Geary.RFC822.MessageData, Geary.Common.MessageData, Equalable, Hashable { +public class Geary.RFC822.Date : Geary.RFC822.MessageData, Geary.Common.MessageData, + Gee.Hashable { public string original { get; private set; } public DateTime value { get; private set; } public time_t as_time_t { get; private set; } @@ -111,18 +112,14 @@ public class Geary.RFC822.Date : Geary.RFC822.MessageData, Geary.Common.MessageD original = iso8601; } - public virtual bool equals(Equalable e) { - RFC822.Date? other = e as RFC822.Date; - if (other == null) - return false; - + public virtual bool equal_to(Geary.RFC822.Date other) { if (this == other) return true; return value.equal(other.value); } - public virtual uint to_hash() { + public virtual uint hash() { return value.hash(); } diff --git a/src/engine/rfc822/rfc822-utils.vala b/src/engine/rfc822/rfc822-utils.vala index b61b9489..f9e26240 100644 --- a/src/engine/rfc822/rfc822-utils.vala +++ b/src/engine/rfc822/rfc822-utils.vala @@ -92,7 +92,7 @@ public string reply_references(Geary.Email source) { // 2. If there's an In-Reply-To Message-ID and it's not the last Message-ID on the // References list, append it - if (source.in_reply_to != null && list.size > 0 && !list.last().equals(source.in_reply_to)) + if (source.in_reply_to != null && list.size > 0 && !list.last().equal_to(source.in_reply_to)) list.add(source.in_reply_to); // 3. Append the source's Message-ID, if available. diff --git a/src/engine/util/util-collection.vala b/src/engine/util/util-collection.vala index 2a7c68e6..624b2cab 100644 --- a/src/engine/util/util-collection.vala +++ b/src/engine/util/util-collection.vala @@ -31,11 +31,45 @@ public bool are_sets_equal(Gee.Set a, Gee.Set b) { return true; } +/** + * To be used by a Hashable's to_hash() method. + */ +public static uint int64_hash(int64 value) { + return hash_memory(&value, sizeof(int64)); +} + +/** + * To be used as a raw HashFunc where an int64 is being stored directly. + */ +public static uint bare_int64_hash(void *ptr) { + return hash_memory(ptr, sizeof(int64)); +} + +/** + * A HashFunc for DateTime. + */ +public static uint date_time_hash(void *a) { + return ((DateTime) a).hash(); +} + +/** + * A rotating-XOR hash that can be used to hash memory buffers of any size. Use only if + * equality is determined by memory contents. + */ +public static uint hash_memory(void *ptr, size_t bytes) { + uint8 *u8 = (uint8 *) ptr; + uint hash = 0; + for (int ctr = 0; ctr < bytes; ctr++) + hash = (hash << 4) ^ (hash >> 28) ^ (*u8++); + + return hash; +} + // This *must* be used in place of Gee,TreeSet until the fix for this bug is widely distributed: // https://bugzilla.gnome.org/show_bug.cgi?id=695045 public class FixedTreeSet : Gee.TreeSet { - public FixedTreeSet(CompareFunc? compare_func = null) { - base (compare_func); + public FixedTreeSet(owned GLib.CompareDataFunc? compare_func = null) { + base ( (owned) compare_func); } ~FixedTreeSet() { diff --git a/src/engine/util/util-files.vala b/src/engine/util/util-files.vala index e4f8b6cc..61649e82 100644 --- a/src/engine/util/util-files.vala +++ b/src/engine/util/util-files.vala @@ -54,5 +54,27 @@ public async void recursive_delete_async(File folder, Cancellable? cancellable = } } +public uint hash(File file) { + return file.hash(); +} + +public bool equal(File a, File b) { + return a.equal(b); +} + +public uint nullable_hash(File? file) { + return (file != null) ? file.hash() : 0; +} + +public bool nullable_equal(File? a, File? b) { + if (a == null && b == null) + return true; + + if (a == null || b == null) + return false; + + return a.equal(b); +} + } diff --git a/src/engine/util/util-generic-capabilities.vala b/src/engine/util/util-generic-capabilities.vala index 7afe6e2c..971b120b 100644 --- a/src/engine/util/util-generic-capabilities.vala +++ b/src/engine/util/util-generic-capabilities.vala @@ -8,8 +8,11 @@ public class Geary.GenericCapabilities : BaseObject { public string name_separator { get; private set; } public string? value_separator { get; private set; } + // All params must be nullable to support both libgee 0.8.0 and 0.8.6 (for Quantal and Rarring, respectively.) + // This behavior was changed in the following libgee commit: + // https://git.gnome.org/browse/libgee/commit/?id=5a35303cb04154d0e929a7d8895d4a4812ba7a1c private Gee.HashMultiMap map = new Gee.HashMultiMap( - String.stri_hash, String.stri_equal, String.nullable_stri_hash, String.nullable_stri_equal); + String.nullable_stri_hash, String.nullable_stri_equal, String.nullable_stri_hash, String.nullable_stri_equal); /** * Creates an empty set of capabilities. diff --git a/src/engine/util/util-interfaces.vala b/src/engine/util/util-interfaces.vala index 6b154c64..0ad0abe2 100644 --- a/src/engine/util/util-interfaces.vala +++ b/src/engine/util/util-interfaces.vala @@ -41,82 +41,3 @@ public interface Geary.Comparable { } } -public interface Geary.Equalable { - public abstract bool equals(Equalable other); - - /** - * An EqualFunc for any object that implements Equalable. - */ - public static bool equal_func(void *a, void *b) { - return ((Equalable *) a)->equals((Equalable *) b); - } - - /** - * EqualFunc for nullable objects that implement Equalable. - */ - public static bool nullable_equal_func(void *a, void *b) { - if (a == null || b == null) - return (a == null && b == null); - return equal_func(a, b); - } - - /** - * The EqualsFunc counterpart to Hashable.bare_int64_hash(). - */ - public static bool bare_int64_equals(void *a, void *b) { - return *((int64 *) a) == *((int64 *) b); - } - - /** - * An EqualFunc for DateTime. - */ - public static bool date_time_equal(void *a, void *b) { - return ((DateTime) a).equal((DateTime) b); - } -} - -public interface Geary.Hashable { - public abstract uint to_hash(); - - /** - * A HashFunc for any object that implements Hashable. - */ - public static uint hash_func(void *ptr) { - return ((Hashable *) ptr)->to_hash(); - } - - /** - * To be used by a Hashable's to_hash() method. - */ - public static uint int64_hash(int64 value) { - return hash_memory(&value, sizeof(int64)); - } - - /** - * To be used as a raw HashFunc where an int64 is being stored directly. - */ - public static uint bare_int64_hash(void *ptr) { - return hash_memory(ptr, sizeof(int64)); - } - - /** - * A HashFunc for DateTime. - */ - public static uint date_time_hash(void *a) { - return ((DateTime) a).hash(); - } - - /** - * A rotating-XOR hash that can be used to hash memory buffers of any size. Use only if - * equality is determined by memory contents. - */ - public static uint hash_memory(void *ptr, size_t bytes) { - uint8 *u8 = (uint8 *) ptr; - uint hash = 0; - for (int ctr = 0; ctr < bytes; ctr++) - hash = (hash << 4) ^ (hash >> 28) ^ (*u8++); - - return hash; - } -} - diff --git a/src/engine/util/util-singleton.vala b/src/engine/util/util-singleton.vala index 1f168143..8d35744f 100644 --- a/src/engine/util/util-singleton.vala +++ b/src/engine/util/util-singleton.vala @@ -8,7 +8,10 @@ * Singleton is a simple way of creating a one-item read-only collection. */ private class Geary.Singleton : Gee.AbstractCollection { - private class IteratorImpl : BaseObject, Gee.Iterator { + private class IteratorImpl : BaseObject, Gee.Traversable, Gee.Iterator { + public bool read_only { get { return true; } } + public bool valid { get { return !done; } } + private G item; private bool done = false; @@ -16,12 +19,6 @@ private class Geary.Singleton : Gee.AbstractCollection { this.item = item; } - public bool first() { - done = false; - - return true; - } - public new G? get() { return item; } @@ -41,23 +38,27 @@ private class Geary.Singleton : Gee.AbstractCollection { public void remove() { message("Geary.Singleton is read-only"); - } + } + + public new bool @foreach(Gee.ForallFunc f) { + return f(item); + } } + public override bool read_only { get { return true; } } public G item { get; private set; } public override int size { get { return 1; } } - private EqualFunc equal_func; + private Gee.EqualDataFunc equal_func; - public Singleton(G item, EqualFunc? equal_func = null) { + public Singleton(G item, owned Gee.EqualDataFunc? equal_func = null) { this.item = item; if (equal_func != null) - this.equal_func = equal_func; - else if (typeof(G).is_a(typeof(Geary.Equalable))) - this.equal_func = Geary.Equalable.equal_func; - else + this.equal_func = (owned) equal_func; + else { this.equal_func = Gee.Functions.get_equal_func_for(typeof(G)); + } } public override bool add(G element) { diff --git a/src/engine/util/util-string.vala b/src/engine/util/util-string.vala index 5d3afd10..8f53e75a 100644 --- a/src/engine/util/util-string.vala +++ b/src/engine/util/util-string.vala @@ -48,23 +48,23 @@ public inline bool ascii_equali(string a, string b) { return ascii_cmpi(a, b) == 0; } -public uint stri_hash(void *str) { - return str_hash(((string *) str)->down()); +public uint stri_hash(string str) { + return str_hash(str.down()); } -public uint nullable_stri_hash(void *str) { +public uint nullable_stri_hash(string? str) { return (str != null) ? stri_hash(str) : 0; } -public bool stri_equal(void *a, void *b) { - return str_equal(((string *) a)->down(), ((string *) b)->down()); +public bool stri_equal(string a, string b) { + return str_equal(a.down(), b.down()); } public bool equals_ci(string a, string b) { return a.down() == b.down(); } -public bool nullable_stri_equal(void *a, void *b) { +public bool nullable_stri_equal(string? a, string? b) { if (a == null) return (b == null);