1 Return-Path: <meskio@sindominio.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 882A5417340
\r
6 for <notmuch@notmuchmail.org>; Sat, 20 Mar 2010 03:21:42 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5
\r
12 tests=[BAYES_00=-1.9] autolearn=ham
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id zQ5iSnDOmwm7 for <notmuch@notmuchmail.org>;
\r
16 Sat, 20 Mar 2010 03:21:40 -0700 (PDT)
\r
17 Received: from flatline.sindominio.net (flatline.sindominio.net [82.144.4.26])
\r
18 by olra.theworths.org (Postfix) with ESMTP id DEB23431FC1
\r
19 for <notmuch@notmuchmail.org>; Sat, 20 Mar 2010 03:21:39 -0700 (PDT)
\r
20 Received: from localhost (localhost.localdomain [127.0.0.1])
\r
21 by flatline.sindominio.net (Postfix) with ESMTP id C66F2262E3E;
\r
22 Sat, 20 Mar 2010 11:21:38 +0100 (CET)
\r
23 X-Virus-Scanned: Debian amavisd-new at sindominio.net
\r
24 Received: from flatline.sindominio.net ([127.0.0.1])
\r
25 by localhost (flatline.sindominio.net [127.0.0.1]) (amavisd-new,
\r
27 with ESMTP id Yiiim5dMf4NV; Sat, 20 Mar 2010 11:21:35 +0100 (CET)
\r
28 Received: from blackspot (heal.cauterized.net [89.140.131.167])
\r
29 by flatline.sindominio.net (Postfix) with ESMTPA id 6EA72262E3B;
\r
30 Sat, 20 Mar 2010 11:21:28 +0100 (CET)
\r
31 Received: by blackspot (Postfix, from userid 1000)
\r
32 id 0FF728BDFC; Sat, 20 Mar 2010 11:24:51 +0100 (CET)
\r
33 From: Ruben Pollan <meskio@sindominio.net>
\r
34 To: notmuch@notmuchmail.org
\r
35 Date: Sat, 20 Mar 2010 11:23:22 +0100
\r
36 Message-Id: <1269080605-5617-3-git-send-email-meskio@sindominio.net>
\r
37 X-Mailer: git-send-email 1.7.0
\r
38 In-Reply-To: <873a09jt2t.fsf@yoom.home.cworth.org>
\r
39 References: <873a09jt2t.fsf@yoom.home.cworth.org>
\r
40 Subject: [notmuch] [PATCH 2/5] Added backwards iterator to messages
\r
41 X-BeenThere: notmuch@notmuchmail.org
\r
42 X-Mailman-Version: 2.1.13
\r
44 List-Id: "Use and development of the notmuch mail system."
\r
45 <notmuch.notmuchmail.org>
\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
47 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
49 List-Post: <mailto:notmuch@notmuchmail.org>
\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
52 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
53 X-List-Received-Date: Sat, 20 Mar 2010 10:21:42 -0000
\r
55 Added the functions notmuch_messages_move_to_prevoius,
\r
56 notmuch_messages_move_to_last and notmuch_messages_move_to_first to
\r
57 notmuch library. With them is possible to iterate backwards on messages.
\r
59 * notmuch_messages_move_to_prevoius do the opposite than
\r
60 notmuch_messages_move_to_next, getting the messages iterator one
\r
63 * notmuch_messages_move_to_last move the iterator to the first last
\r
66 * notmuch_messages_move_to_first move the iterator to the first valid
\r
69 lib/messages.c | 31 +++++++++++++++++++++++++++++
\r
70 lib/notmuch-private.h | 10 +++++++++
\r
71 lib/notmuch.h | 28 ++++++++++++++++++++++++++
\r
72 lib/query.cc | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
\r
73 4 files changed, 121 insertions(+), 0 deletions(-)
\r
75 diff --git a/lib/messages.c b/lib/messages.c
\r
76 index 2a85774..975e4b1 100644
\r
77 --- a/lib/messages.c
\r
78 +++ b/lib/messages.c
\r
79 @@ -90,6 +90,7 @@ _notmuch_messages_create (notmuch_message_list_t *list)
\r
81 messages->is_of_list_type = TRUE;
\r
82 messages->iterator = list->head;
\r
83 + messages->list = list;
\r
87 @@ -134,6 +135,15 @@ notmuch_messages_get (notmuch_messages_t *messages)
\r
91 +notmuch_messages_move_to_first (notmuch_messages_t *messages)
\r
93 + if (! messages->is_of_list_type)
\r
94 + return _notmuch_mset_messages_move_to_first (messages);
\r
96 + messages->iterator = messages->list->head;
\r
100 notmuch_messages_move_to_next (notmuch_messages_t *messages)
\r
102 if (! messages->is_of_list_type)
\r
103 @@ -146,6 +156,27 @@ notmuch_messages_move_to_next (notmuch_messages_t *messages)
\r
107 +notmuch_messages_move_to_last (notmuch_messages_t *messages)
\r
109 + if (! messages->is_of_list_type)
\r
110 + return _notmuch_mset_messages_move_to_last (messages);
\r
112 + messages->iterator = messages->list->tail;
\r
116 +notmuch_messages_move_to_previous (notmuch_messages_t *messages)
\r
118 + if (! messages->is_of_list_type)
\r
119 + return _notmuch_mset_messages_move_to_previous (messages);
\r
121 + if (messages->iterator == NULL)
\r
124 + messages->iterator = messages->iterator->prev;
\r
128 notmuch_messages_destroy (notmuch_messages_t *messages)
\r
130 talloc_free (messages);
\r
131 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
\r
132 index 3b3f0eb..2269d2b 100644
\r
133 --- a/lib/notmuch-private.h
\r
134 +++ b/lib/notmuch-private.h
\r
135 @@ -364,6 +364,7 @@ typedef struct _notmuch_message_list {
\r
136 struct _notmuch_messages {
\r
137 notmuch_bool_t is_of_list_type;
\r
138 notmuch_message_node_t *iterator;
\r
139 + notmuch_message_list_t *list;
\r
142 notmuch_message_list_t *
\r
143 @@ -389,8 +390,17 @@ notmuch_message_t *
\r
144 _notmuch_mset_messages_get (notmuch_messages_t *messages);
\r
147 +_notmuch_mset_messages_move_to_first (notmuch_messages_t *messages);
\r
150 _notmuch_mset_messages_move_to_next (notmuch_messages_t *messages);
\r
153 +_notmuch_mset_messages_move_to_last (notmuch_messages_t *messages);
\r
156 +_notmuch_mset_messages_move_to_previous (notmuch_messages_t *messages);
\r
161 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
162 index 0d9cb0f..753f3bb 100644
\r
163 --- a/lib/notmuch.h
\r
164 +++ b/lib/notmuch.h
\r
165 @@ -645,6 +645,15 @@ notmuch_messages_valid (notmuch_messages_t *messages);
\r
166 notmuch_message_t *
\r
167 notmuch_messages_get (notmuch_messages_t *messages);
\r
169 +/* Move the 'messages' iterator to the first message.
\r
171 + * After that the 'messages' iterator will be set to the first valid
\r
172 + * message, so it can be use to iterate with
\r
173 + * notmuch_messages_move_to_next.
\r
176 +notmuch_messages_move_to_first (notmuch_messages_t *messages);
\r
178 /* Move the 'messages' iterator to the next message.
\r
180 * If 'messages' is already pointing at the last message then the
\r
181 @@ -658,6 +667,25 @@ notmuch_messages_get (notmuch_messages_t *messages);
\r
183 notmuch_messages_move_to_next (notmuch_messages_t *messages);
\r
185 +/* Move the 'messages' iterator to the last message.
\r
187 + * After that the 'messages' iterator will be set to the last valid
\r
188 + * message, so it can be use to iterate with
\r
189 + * notmuch_messages_move_to_previous.
\r
192 +notmuch_messages_move_to_last (notmuch_messages_t *messages);
\r
194 +/* Move the 'messages' iterator to the previous message.
\r
196 + * If 'messages' is already pointing at the first message then the
\r
197 + * iterator will be moved to a point just beyond that first message,
\r
198 + * (where notmuch_messages_valid will return FALSE and
\r
199 + * notmuch_messages_get will return NULL).
\r
202 +notmuch_messages_move_to_previous (notmuch_messages_t *messages);
\r
204 /* Destroy a notmuch_messages_t object.
\r
206 * It's not strictly necessary to call this function. All memory from
\r
207 diff --git a/lib/query.cc b/lib/query.cc
\r
208 index 9266d35..970c35a 100644
\r
211 @@ -35,6 +35,7 @@ typedef struct _notmuch_mset_messages {
\r
212 notmuch_messages_t base;
\r
213 notmuch_database_t *notmuch;
\r
214 Xapian::MSetIterator iterator;
\r
215 + Xapian::MSetIterator iterator_begin;
\r
216 Xapian::MSetIterator iterator_end;
\r
217 } notmuch_mset_messages_t;
\r
219 @@ -86,6 +87,7 @@ static int
\r
220 _notmuch_messages_destructor (notmuch_mset_messages_t *messages)
\r
222 messages->iterator.~MSetIterator ();
\r
223 + messages->iterator_begin.~MSetIterator ();
\r
224 messages->iterator_end.~MSetIterator ();
\r
227 @@ -108,6 +110,7 @@ notmuch_query_search_messages (notmuch_query_t *query)
\r
228 messages->base.iterator = NULL;
\r
229 messages->notmuch = notmuch;
\r
230 new (&messages->iterator) Xapian::MSetIterator ();
\r
231 + new (&messages->iterator_begin) Xapian::MSetIterator ();
\r
232 new (&messages->iterator_end) Xapian::MSetIterator ();
\r
234 talloc_set_destructor (messages, _notmuch_messages_destructor);
\r
235 @@ -157,6 +160,7 @@ notmuch_query_search_messages (notmuch_query_t *query)
\r
236 mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount ());
\r
238 messages->iterator = mset.begin ();
\r
239 + messages->iterator_begin = mset.begin ();
\r
240 messages->iterator_end = mset.end ();
\r
242 } catch (const Xapian::Error &error) {
\r
243 @@ -208,6 +212,16 @@ _notmuch_mset_messages_get (notmuch_messages_t *messages)
\r
247 +_notmuch_mset_messages_move_to_first (notmuch_messages_t *messages)
\r
249 + notmuch_mset_messages_t *mset_messages;
\r
251 + mset_messages = (notmuch_mset_messages_t *) messages;
\r
253 + mset_messages->iterator = mset_messages->iterator_begin;
\r
257 _notmuch_mset_messages_move_to_next (notmuch_messages_t *messages)
\r
259 notmuch_mset_messages_t *mset_messages;
\r
260 @@ -217,6 +231,44 @@ _notmuch_mset_messages_move_to_next (notmuch_messages_t *messages)
\r
261 mset_messages->iterator++;
\r
265 +_notmuch_mset_messages_move_to_last (notmuch_messages_t *messages)
\r
267 + notmuch_mset_messages_t *mset_messages;
\r
269 + mset_messages = (notmuch_mset_messages_t *) messages;
\r
271 + mset_messages->iterator = mset_messages->iterator_end;
\r
272 + mset_messages->iterator--;
\r
276 +_notmuch_mset_messages_move_to_previous (notmuch_messages_t *messages)
\r
278 + notmuch_mset_messages_t *mset_messages;
\r
280 + mset_messages = (notmuch_mset_messages_t *) messages;
\r
282 + if (mset_messages->iterator == mset_messages->iterator_begin)
\r
285 + * Xapian iterators can not be beyond the first element, so we
\r
286 + * assign the iterator_end to mark the iterator as invalid in case
\r
287 + * of move_to_previous with the iterator at the beginning
\r
289 + mset_messages->iterator = mset_messages->iterator_end;
\r
291 + else if (_notmuch_mset_messages_valid (messages))
\r
294 + * If is valid move the iterator. To emulate the same behavior
\r
295 + * than notmuch_messages_t the iterator won't be updated if is
\r
298 + mset_messages->iterator--;
\r
302 /* Glib objects force use to use a talloc destructor as well, (but not
\r
303 * nearly as ugly as the for messages due to C++ objects). At
\r
304 * this point, I'd really like to have some talloc-friendly
\r