fix bug 2979, 'claws fails to load (empty) folderlist.xml and shows account wizard'
[claws.git] / src / folder.h
index c86820cbc5459a75c95edb5cdc2e0a731c70a99b..44f69bb2c25d30a015a5ff8b676eb86780826179 100644 (file)
@@ -2,7 +2,7 @@
 
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2011 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -129,12 +129,12 @@ typedef void (*FolderItemFunc)    (FolderItem     *item,
                                         gpointer        data);
 
 
-#include "folder_item_prefs.h"
-
-#include "procmsg.h"
-#include "msgcache.h"
+#include "proctypes.h"
 #include "xml.h"
 #include "prefs_account.h"
+#include "matchertypes.h"
+
+struct _MsgCache;
 
 struct _Folder
 {
@@ -160,6 +160,23 @@ struct _Folder
        GHashTable *newsart;
 };
 
+/**
+ * Callback used to convey progress information of a specific search.
+ *
+ * \param data User-provided data
+ * \param on_server Whether or not the current progress information originated from the
+ *                  server
+ * \param at Number of the last message processed
+ * \param matched Number of messages with definitive matches found so far
+ * \param total Number of messages to be processed
+ *
+ * \note
+ * Even if the mailserver does not support progress reports, an instance of this type
+ * should be invoked when serverside search starts and ends, with \c at set to \c 0 and
+ * \c total, respectively.
+ */
+typedef gboolean (*SearchProgressNotify)(gpointer data, gboolean on_server, guint at, guint matched, guint total);
+
 struct _FolderClass
 {
        /**
@@ -176,6 +193,13 @@ struct _FolderClass
         * user. Can be upper and lowercase unlike the idstr.
         */
        gchar      *uistr;
+       /**
+       * A boolean to indicate whether or not the FolderClass supports search on the
+       * server. If \c TRUE, setting \c on_server in \c search_msgs offloads search to
+       * the server.
+       */
+       gboolean    supports_server_search;
+
        
        /* virtual functions */
 
@@ -506,6 +530,58 @@ struct _FolderClass
                                                 FolderItem     *dest,
                                                 MsgInfoList    *msglist,
                                                 GHashTable     *relation);
+
+       /**
+        * Search the given FolderItem for messages matching \c predicate.
+        * The search may be offloaded to the server if the \c folder
+        * supports server side search, as indicated by \c supports_server_search.
+        *
+        * \param folder The \c Folder of the container FolderItem
+        * \param container The \c FolderItem containing the messages to be searched
+        * \param msgs The \c MsgNumberList results will be saved to.
+        *             If <tt>*msgs != NULL</tt>, the search will be restricted to
+        *             messages whose numbers are contained therein.
+        *             If \c on_server is considered \c FALSE, messages are guaranteed to
+        *             be processed in the order they are listed in \c msgs.
+        *             On error, \c msgs will not be changed.
+        * \param on_server Whether or not the search should be offloaded to the server.
+        *                  If \c on_server is not \c NULL and points to a \c TRUE value,
+        *                  search will be done on the server. If \c predicate contains
+        *                  one or more atoms the server does not support, the value
+        *                  pointed to by \c on_server will be set to \c FALSE upon return.
+        *                  In this case, \c msgs must still contain a valid superset of
+        *                  messages actually matched by \c predicate, or this method must
+        *                  return an error.
+        *                  \c on_server may only point to a \c TRUE value if
+        *                  \c supports_server_search is also \c TRUE.
+        *                  \c NULL and pointer to \c FALSE are considered equivalent and
+        *                  will start a client-only search.
+        * \param predicate The \c MatcherList to use in the search
+        * \param progress_cb Called for every message searched.
+        *                    When search is offloaded to the server, this function
+        *                    may or may not be called, depending on the implementation.
+        *                    The second argument of this function will be the number of
+        *                    messages already processed.
+        *                    Return \c FALSE from this function to end the search.
+        *                    May be \c NULL, no calls will be made in this case.
+        * \param progress_data First argument value for \c progress_cb
+        * \return Number of messages that matched \c predicate on success, a negative
+        *         number otherwise.
+        *
+        * \note
+        * When search is stopped by returning \c FALSE from \c progress_cb, \c msgs will
+        * contain all messages found until the point of cancellation. The number of
+        * messages found will be returned as indicated above.
+        */
+       gint            (*search_msgs)          (Folder                 *folder,
+                                                FolderItem             *container,
+                                                MsgNumberList          **msgs,
+                                                gboolean               *on_server,
+                                                MatcherList            *predicate,
+                                                SearchProgressNotify   progress_cb,
+                                                gpointer               progress_data);
+
+
        /**
         * Remove a message from a \c FolderItem.
         *
@@ -633,6 +709,8 @@ enum {
        ITEM_SCANNING
 };
 
+struct _FolderItemPrefs;
+
 struct _FolderItem
 {
        SpecialFolderItemType stype;
@@ -657,7 +735,7 @@ struct _FolderItem
 
        gint last_num;
 
-       MsgCache *cache;
+       struct _MsgCache *cache;
        gboolean cache_dirty;
        gboolean mark_dirty;
        gboolean tags_dirty;
@@ -693,7 +771,7 @@ struct _FolderItem
 
        gpointer data;
 
-       FolderItemPrefs * prefs;
+       struct _FolderItemPrefs * prefs;
        
        /* for faster search of special parents */
        SpecialFolderItemType parent_stype;
@@ -834,6 +912,8 @@ MsgInfo *folder_item_get_msginfo    (FolderItem     *item,
 MsgInfo *folder_item_get_msginfo_by_msgid(FolderItem   *item,
                                         const gchar    *msgid);
 GSList *folder_item_get_msg_list       (FolderItem     *item);
+MsgNumberList *folder_item_get_number_list(FolderItem *item);
+
 /* return value is locale charset */
 gchar *folder_item_fetch_msg           (FolderItem     *item,
                                         gint            num);
@@ -860,6 +940,13 @@ gint   folder_item_copy_msg                (FolderItem     *dest,
                                         MsgInfo        *msginfo);
 gint   folder_item_copy_msgs           (FolderItem     *dest,
                                         GSList         *msglist);
+gint   folder_item_search_msgs         (Folder                 *folder,
+                                        FolderItem             *container,
+                                        MsgNumberList          **msgs,
+                                        gboolean               *on_server,
+                                        MatcherList            *predicate,
+                                        SearchProgressNotify   progress_cb,
+                                        gpointer               progress_data);
 gint   folder_item_remove_msg          (FolderItem     *item,
                                         gint            num);
 gint   folder_item_remove_msgs         (FolderItem     *item,
@@ -886,6 +973,7 @@ void folder_item_update_freeze              (void);
 void folder_item_update_thaw           (void);
 void folder_item_set_batch             (FolderItem *item, gboolean batch);
 gboolean folder_has_parent_of_type     (FolderItem *item, SpecialFolderItemType type);
+gboolean folder_is_child_of            (FolderItem *item, FolderItem *possibleChild);
 void folder_synchronise                        (Folder *folder);
 gboolean folder_want_synchronise       (Folder *folder);
 gboolean folder_subscribe              (const gchar *uri);
@@ -900,4 +988,15 @@ void folder_item_synchronise               (FolderItem *item);
 void folder_item_discard_cache         (FolderItem *item);
 void folder_item_commit_tags(FolderItem *item, MsgInfo *msginfo, GSList *tags_set, GSList *tags_unset);
 
+
+
+gint folder_item_search_msgs_local     (Folder                 *folder,
+                                        FolderItem             *container,
+                                        MsgNumberList          **msgs,
+                                        gboolean               *on_server,
+                                        MatcherList            *predicate,
+                                        SearchProgressNotify   progress_cb,
+                                        gpointer               progress_data);
+
+gchar *folder_get_list_path    (void);
 #endif /* __FOLDER_H__ */