Fix warning: excess elements in struct initializer
[claws.git] / src / plugins / python / mailboxtype.c
1 /* Python plugin for Claws-Mail
2  * Copyright (C) 2013 Holger Berndt <hb@claws-mail.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #ifdef HAVE_CONFIG_H
19 #  include "config.h"
20 #  include "claws-features.h"
21 #endif
22
23 #include "mailboxtype.h"
24
25 #include <glib.h>
26 #include <glib/gi18n.h>
27
28 #include <structmember.h>
29
30 typedef struct {
31     PyObject_HEAD
32     Folder *folder;
33 } clawsmail_MailboxObject;
34
35 static int Mailbox_init(clawsmail_MailboxObject *self, PyObject *args, PyObject *kwds)
36 {
37   self->folder = NULL;
38   return 0;
39 }
40
41 static void Mailbox_dealloc(clawsmail_MailboxObject* self)
42 {
43   self->folder = NULL;
44   self->ob_type->tp_free((PyObject*)self);
45 }
46
47 static PyObject* Mailbox_str(clawsmail_MailboxObject *self)
48 {
49   if(self->folder && self->folder->name)
50     return PyString_FromFormat("Mailbox: %s", self->folder->name);
51   Py_RETURN_NONE;
52 }
53
54 static PyObject* get_name(clawsmail_MailboxObject *self, void *closure)
55 {
56   if(self->folder && self->folder->name)
57     return PyString_FromString(self->folder->name);
58   Py_RETURN_NONE;
59 }
60
61 static PyGetSetDef Mailbox_getset[] = {
62    {"name", (getter)get_name, (setter)NULL,
63     "name - name of the mailbox", NULL},
64
65    {NULL}
66 };
67
68 static PyTypeObject clawsmail_MailboxType = {
69     PyObject_HEAD_INIT(NULL)
70     0,                         /* ob_size*/
71     "clawsmail.Mailbox",       /* tp_name*/
72     sizeof(clawsmail_MailboxObject), /* tp_basicsize*/
73     0,                         /* tp_itemsize*/
74     (destructor)Mailbox_dealloc, /* tp_dealloc*/
75     0,                         /* tp_print*/
76     0,                         /* tp_getattr*/
77     0,                         /* tp_setattr*/
78     0,                         /* tp_compare*/
79     0,                         /* tp_repr*/
80     0,                         /* tp_as_number*/
81     0,                         /* tp_as_sequence*/
82     0,                         /* tp_as_mapping*/
83     0,                         /* tp_hash */
84     0,                         /* tp_call*/
85     (reprfunc)Mailbox_str,     /* tp_str*/
86     0,                         /* tp_getattro*/
87     0,                         /* tp_setattro*/
88     0,                         /* tp_as_buffer*/
89     Py_TPFLAGS_DEFAULT,        /* tp_flags*/
90     "Mailbox objects.\n\n"     /* tp_doc */
91     "Do not construct objects of this type yourself.",
92     0,                         /* tp_traverse */
93     0,                         /* tp_clear */
94     0,                         /* tp_richcompare */
95     0,                         /* tp_weaklistoffset */
96     0,                         /* tp_iter */
97     0,                         /* tp_iternext */
98     0,                         /* tp_methods */
99     0,                         /* tp_members */
100     Mailbox_getset,            /* tp_getset */
101     0,                         /* tp_base */
102     0,                         /* tp_dict */
103     0,                         /* tp_descr_get */
104     0,                         /* tp_descr_set */
105     0,                         /* tp_dictoffset */
106     (initproc)Mailbox_init,    /* tp_init */
107     0,                         /* tp_alloc */
108     0,                         /* tp_new */
109     0,                         /* tp_free */
110         0,                         /* tp_is_gc */
111         0,                         /* tp_bases */
112         0,                         /* tp_mro */
113         0,                         /* tp_cache */
114         0,                         /* tp_subclasses */
115         0,                         /* tp_weaklist */
116         0,                         /* tp_del */
117 #if ((PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 6) || \
118      (PY_MAJOR_VERSION == 3))
119     0,                         /* tp_version_tag */
120 #endif
121 #if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 4)
122     0,                         /* tp_finalize */
123 #endif
124 };
125
126 gboolean cmpy_add_mailbox(PyObject *module)
127 {
128   clawsmail_MailboxType.tp_new = PyType_GenericNew;
129   if(PyType_Ready(&clawsmail_MailboxType) < 0)
130     return FALSE;
131
132   Py_INCREF(&clawsmail_MailboxType);
133   return (PyModule_AddObject(module, "Mailbox", (PyObject*)&clawsmail_MailboxType) == 0);
134 }
135
136 PyObject* clawsmail_mailbox_new(Folder *folder)
137 {
138   clawsmail_MailboxObject *ff;
139
140   if(!folder)
141     return NULL;
142
143   ff = (clawsmail_MailboxObject*) PyObject_CallObject((PyObject*) &clawsmail_MailboxType, NULL);
144   if(!ff)
145     return NULL;
146
147   ff->folder = folder;
148   return (PyObject*)ff;
149 }
150
151 Folder* clawsmail_mailbox_get_folder(PyObject *self)
152 {
153   return ((clawsmail_MailboxObject*)self)->folder;
154 }
155
156 PyTypeObject* clawsmail_mailbox_get_type_object()
157 {
158   return &clawsmail_MailboxType;
159 }
160
161 gboolean clawsmail_mailbox_check(PyObject *self)
162 {
163   return (PyObject_TypeCheck(self, &clawsmail_MailboxType) != 0);
164 }