]> git.notmuchmail.org Git - notmuch/blob - bindings/ruby/query.c
Merge in ruby bindings.
[notmuch] / bindings / ruby / query.c
1 /* The Ruby interface to the notmuch mail library
2  *
3  * Copyright © 2010 Ali Polatel
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see http://www.gnu.org/licenses/ .
17  *
18  * Author: Ali Polatel <alip@exherbo.org>
19  */
20
21 #include "defs.h"
22
23 /*
24  * call-seq: QUERY.destroy => nil
25  *
26  * Destroys the query, freeing all resources allocated for it.
27  */
28 VALUE
29 notmuch_rb_query_destroy(VALUE self)
30 {
31     notmuch_query_t *query;
32
33     Data_Get_Notmuch_Query(self, query);
34
35     notmuch_query_destroy(query);
36     DATA_PTR(self) = NULL;
37
38     return Qnil;
39 }
40
41 /*
42  * call-seq: QUERY.sort=(fixnum) => nil
43  *
44  * Set sort type of the +QUERY+
45  */
46 VALUE
47 notmuch_rb_query_set_sort(VALUE self, VALUE sortv)
48 {
49     notmuch_query_t *query;
50
51     Data_Get_Notmuch_Query(self, query);
52
53     if (!FIXNUM_P(sortv))
54         rb_raise(rb_eTypeError, "Not a Fixnum");
55
56     notmuch_query_set_sort(query, FIX2UINT(sortv));
57
58     return Qnil;
59 }
60
61 /*
62  * call-seq: QUERY.search_threads => THREADS
63  *
64  * Search for threads
65  */
66 VALUE
67 notmuch_rb_query_search_threads(VALUE self)
68 {
69     notmuch_query_t *query;
70     notmuch_threads_t *threads;
71
72     Data_Get_Notmuch_Query(self, query);
73
74     threads = notmuch_query_search_threads(query);
75     if (!threads)
76         rb_raise(notmuch_rb_eMemoryError, "Out of memory");
77
78     return Data_Wrap_Struct(notmuch_rb_cThreads, NULL, NULL, threads);
79 }
80
81 /*
82  * call-seq: QUERY.search_messages => MESSAGES
83  *
84  * Search for messages
85  */
86 VALUE
87 notmuch_rb_query_search_messages(VALUE self)
88 {
89     notmuch_query_t *query;
90     notmuch_messages_t *messages;
91
92     Data_Get_Notmuch_Query(self, query);
93
94     messages = notmuch_query_search_messages(query);
95     if (!messages)
96         rb_raise(notmuch_rb_eMemoryError, "Out of memory");
97
98     return Data_Wrap_Struct(notmuch_rb_cMessages, NULL, NULL, messages);
99 }