Improve some sieve-related translations
[claws.git] / src / plugins / python / mailboxtype.c
blob08408539ab748cccd06957a6742461e0768c8027
1 /* Python plugin for Claws Mail
2 * Copyright (C) 2013 Holger Berndt <hb@claws-mail.org>
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.
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.
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/>.
18 #ifdef HAVE_CONFIG_H
19 # include "config.h"
20 # include "claws-features.h"
21 #endif
23 #include "mailboxtype.h"
25 #include <glib.h>
26 #include <glib/gi18n.h>
28 #include <structmember.h>
30 typedef struct {
31 PyObject_HEAD
32 Folder *folder;
33 } clawsmail_MailboxObject;
35 static int Mailbox_init(clawsmail_MailboxObject *self, PyObject *args, PyObject *kwds)
37 self->folder = NULL;
38 return 0;
41 static void Mailbox_dealloc(clawsmail_MailboxObject* self)
43 self->folder = NULL;
44 Py_TYPE(self)->tp_free((PyObject*)self);
47 static PyObject* Mailbox_str(clawsmail_MailboxObject *self)
49 if(self->folder && self->folder->name)
50 return PyUnicode_FromFormat("Mailbox: %s", self->folder->name);
51 Py_RETURN_NONE;
54 static PyObject* get_name(clawsmail_MailboxObject *self, void *closure)
56 if(self->folder && self->folder->name)
57 return PyUnicode_FromString(self->folder->name);
58 Py_RETURN_NONE;
61 static PyGetSetDef Mailbox_getset[] = {
62 {"name", (getter)get_name, (setter)NULL,
63 "name - name of the mailbox", NULL},
65 {NULL}
68 static PyTypeObject clawsmail_MailboxType = {
69 PyVarObject_HEAD_INIT(NULL, 0)
70 "clawsmail.Mailbox", /* tp_name*/
71 sizeof(clawsmail_MailboxObject), /* tp_basicsize*/
72 0, /* tp_itemsize*/
73 (destructor)Mailbox_dealloc, /* tp_dealloc*/
74 0, /* tp_print*/
75 0, /* tp_getattr*/
76 0, /* tp_setattr*/
77 0, /* tp_compare*/
78 0, /* tp_repr*/
79 0, /* tp_as_number*/
80 0, /* tp_as_sequence*/
81 0, /* tp_as_mapping*/
82 0, /* tp_hash */
83 0, /* tp_call*/
84 (reprfunc)Mailbox_str, /* tp_str*/
85 0, /* tp_getattro*/
86 0, /* tp_setattro*/
87 0, /* tp_as_buffer*/
88 Py_TPFLAGS_DEFAULT, /* tp_flags*/
89 "Mailbox objects.\n\n" /* tp_doc */
90 "Do not construct objects of this type yourself.",
91 0, /* tp_traverse */
92 0, /* tp_clear */
93 0, /* tp_richcompare */
94 0, /* tp_weaklistoffset */
95 0, /* tp_iter */
96 0, /* tp_iternext */
97 0, /* tp_methods */
98 0, /* tp_members */
99 Mailbox_getset, /* tp_getset */
100 0, /* tp_base */
101 0, /* tp_dict */
102 0, /* tp_descr_get */
103 0, /* tp_descr_set */
104 0, /* tp_dictoffset */
105 (initproc)Mailbox_init, /* tp_init */
106 0, /* tp_alloc */
107 0, /* tp_new */
108 0, /* tp_free */
109 0, /* tp_is_gc */
110 0, /* tp_bases */
111 0, /* tp_mro */
112 0, /* tp_cache */
113 0, /* tp_subclasses */
114 0, /* tp_weaklist */
115 0, /* tp_del */
116 #if ((PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 6) || \
117 (PY_MAJOR_VERSION == 3))
118 0, /* tp_version_tag */
119 #endif
120 #if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 4)
121 0, /* tp_finalize */
122 #endif
125 gboolean cmpy_add_mailbox(PyObject *module)
127 clawsmail_MailboxType.tp_new = PyType_GenericNew;
128 if(PyType_Ready(&clawsmail_MailboxType) < 0)
129 return FALSE;
131 Py_INCREF(&clawsmail_MailboxType);
132 return (PyModule_AddObject(module, "Mailbox", (PyObject*)&clawsmail_MailboxType) == 0);
135 PyObject* clawsmail_mailbox_new(Folder *folder)
137 clawsmail_MailboxObject *ff;
139 if(!folder)
140 return NULL;
142 ff = (clawsmail_MailboxObject*) PyObject_CallObject((PyObject*) &clawsmail_MailboxType, NULL);
143 if(!ff)
144 return NULL;
146 ff->folder = folder;
147 return (PyObject*)ff;
150 Folder* clawsmail_mailbox_get_folder(PyObject *self)
152 return ((clawsmail_MailboxObject*)self)->folder;
155 PyTypeObject* clawsmail_mailbox_get_type_object()
157 return &clawsmail_MailboxType;
160 gboolean clawsmail_mailbox_check(PyObject *self)
162 return (PyObject_TypeCheck(self, &clawsmail_MailboxType) != 0);