RSSyl: Allow use of .netrc by libcurl. Bug/enhancement #3309, by Vincent Pelletier
[claws.git] / src / plugins / python / folderpropertiestype.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 "folderpropertiestype.h"
24 #include "accounttype.h"
25
26 #include <structmember.h>
27
28 typedef struct {
29     PyObject_HEAD
30     FolderItemPrefs *folderitem_prefs;
31 } clawsmail_FolderPropertiesObject;
32
33 static int FolderProperties_init(clawsmail_FolderPropertiesObject *self, PyObject *args, PyObject *kwds)
34 {
35   self->folderitem_prefs = NULL;
36   return 0;
37 }
38
39 static void FolderProperties_dealloc(clawsmail_FolderPropertiesObject* self)
40 {
41   self->ob_type->tp_free((PyObject*)self);
42 }
43
44 static PyObject* get_default_account(clawsmail_FolderPropertiesObject *self, void *closure)
45 {
46   if(self->folderitem_prefs && self->folderitem_prefs->enable_default_account) {
47     PrefsAccount *account;
48     account = account_find_from_id(self->folderitem_prefs->default_account);
49     if(account) {
50       return clawsmail_account_new(account);
51     }
52   }
53   Py_RETURN_NONE;
54 }
55
56 static PyGetSetDef FolderProperties_getset[] = {
57     {"default_account", (getter)get_default_account, (setter)NULL,
58      "default_account - the default account when composing from this folder", NULL},
59
60     {NULL}
61 };
62
63 static PyTypeObject clawsmail_FolderPropertiesType = {
64     PyObject_HEAD_INIT(NULL)
65     0,                         /* ob_size*/
66     "clawsmail.FolderProperties", /* tp_name*/
67     sizeof(clawsmail_FolderPropertiesObject), /* tp_basicsize*/
68     0,                         /* tp_itemsize*/
69     (destructor)FolderProperties_dealloc, /* tp_dealloc*/
70     0,                         /* tp_print*/
71     0,                         /* tp_getattr*/
72     0,                         /* tp_setattr*/
73     0,                         /* tp_compare*/
74     0,                         /* tp_repr*/
75     0,                         /* tp_as_number*/
76     0,                         /* tp_as_sequence*/
77     0,                         /* tp_as_mapping*/
78     0,                         /* tp_hash */
79     0,                         /* tp_call*/
80     0,                         /* tp_str*/
81     0,                         /* tp_getattro*/
82     0,                         /* tp_setattro*/
83     0,                         /* tp_as_buffer*/
84     Py_TPFLAGS_DEFAULT,        /* tp_flags*/
85     "FolderProperties objects.\n\n" /* tp_doc */
86     "Do not construct objects of this type yourself.",
87     0,                         /* tp_traverse */
88     0,                         /* tp_clear */
89     0,                         /* tp_richcompare */
90     0,                         /* tp_weaklistoffset */
91     0,                         /* tp_iter */
92     0,                         /* tp_iternext */
93     0,                         /* tp_methods */
94     0,                         /* tp_members */
95     FolderProperties_getset,   /* tp_getset */
96     0,                         /* tp_base */
97     0,                         /* tp_dict */
98     0,                         /* tp_descr_get */
99     0,                         /* tp_descr_set */
100     0,                         /* tp_dictoffset */
101     (initproc)FolderProperties_init, /* tp_init */
102     0,                         /* tp_alloc */
103     0,                         /* tp_new */
104 };
105
106
107 gboolean cmpy_add_folderproperties(PyObject *module)
108 {
109   clawsmail_FolderPropertiesType.tp_new = PyType_GenericNew;
110   if(PyType_Ready(&clawsmail_FolderPropertiesType) < 0)
111     return FALSE;
112
113   Py_INCREF(&clawsmail_FolderPropertiesType);
114   return (PyModule_AddObject(module, "FolderProperties", (PyObject*)&clawsmail_FolderPropertiesType) == 0);
115 }
116
117 static gboolean update_members(clawsmail_FolderPropertiesObject *self, FolderItemPrefs *folderitem_prefs)
118 {
119   self->folderitem_prefs = folderitem_prefs;
120   return TRUE;
121 }
122
123 PyObject* clawsmail_folderproperties_new(FolderItemPrefs *folderitem_prefs)
124 {
125   clawsmail_FolderPropertiesObject *ff;
126
127   if(!folderitem_prefs)
128     return NULL;
129
130   ff = (clawsmail_FolderPropertiesObject*) PyObject_CallObject((PyObject*) &clawsmail_FolderPropertiesType, NULL);
131   if(!ff)
132     return NULL;
133
134   if(update_members(ff, folderitem_prefs))
135     return (PyObject*)ff;
136   else {
137     Py_XDECREF(ff);
138     return NULL;
139   }
140 }