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/>.
20 # include "claws-features.h"
23 #include "accounttype.h"
25 #include <structmember.h>
29 PrefsAccount *account;
30 } clawsmail_AccountObject;
32 static int Account_init(clawsmail_AccountObject *self, PyObject *args, PyObject *kwds)
39 static void Account_dealloc(clawsmail_AccountObject* self)
41 self->ob_type->tp_free((PyObject*)self);
44 static int Account_compare(clawsmail_AccountObject *obj1, clawsmail_AccountObject *obj2)
46 if(obj1->account->account_id < obj2->account->account_id)
48 else if(obj1->account->account_id > obj2->account->account_id)
54 static PyObject* Account_str(clawsmail_AccountObject *self)
56 return PyString_FromFormat("Account: %s", self->account->account_name);
59 static PyObject* get_account_name(clawsmail_AccountObject *self, void *closure)
61 if(self->account && self->account->account_name)
62 return PyString_FromString(self->account->account_name);
66 static PyObject* get_address(clawsmail_AccountObject *self, void *closure)
68 if(self->account && self->account->address)
69 return PyString_FromString(self->account->address);
73 static PyObject* get_is_default(clawsmail_AccountObject *self, void *closure)
75 if(self->account->is_default)
80 static PyGetSetDef Account_getset[] = {
81 {"account_name", (getter)get_account_name, (setter)NULL,
82 "account_name - name of the account", NULL},
84 {"address", (getter)get_address, (setter)NULL,
85 "address - address of the account", NULL},
87 {"is_default", (getter)get_is_default, (setter)NULL,
88 "is_default - whether this account is the default account", NULL},
93 static PyTypeObject clawsmail_AccountType = {
94 PyObject_HEAD_INIT(NULL)
96 "clawsmail.Account", /* tp_name*/
97 sizeof(clawsmail_AccountObject), /* tp_basicsize*/
99 (destructor)Account_dealloc, /* tp_dealloc*/
103 (cmpfunc)Account_compare, /* tp_compare*/
106 0, /* tp_as_sequence*/
107 0, /* tp_as_mapping*/
110 (reprfunc)Account_str, /* tp_str*/
114 Py_TPFLAGS_DEFAULT, /* tp_flags*/
115 "Account objects.\n\n" /* tp_doc */
116 "Do not construct objects of this type yourself.",
119 0, /* tp_richcompare */
120 0, /* tp_weaklistoffset */
125 Account_getset, /* tp_getset */
128 0, /* tp_descr_get */
129 0, /* tp_descr_set */
130 0, /* tp_dictoffset */
131 (initproc)Account_init, /* tp_init */
137 gboolean cmpy_add_account(PyObject *module)
139 clawsmail_AccountType.tp_new = PyType_GenericNew;
140 if(PyType_Ready(&clawsmail_AccountType) < 0)
143 Py_INCREF(&clawsmail_AccountType);
144 return (PyModule_AddObject(module, "Account", (PyObject*)&clawsmail_AccountType) == 0);
147 PyObject* clawsmail_account_new(PrefsAccount *account)
149 clawsmail_AccountObject *ff;
154 ff = (clawsmail_AccountObject*) PyObject_CallObject((PyObject*) &clawsmail_AccountType, NULL);
158 ff->account = account;
159 return (PyObject*)ff;