talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 7ba87228ec8165e64eff7cb0e97d85d085faca0c
parent 8617c2715305c5711da997f6cfde70a18a517a96
Author: Holger Berndt <hb@claws-mail.org>
Date:   Sat, 27 Jul 2013 16:34:47 +0200

Python plugin: Add folder properties

So far, only the default account is accessible
Diffstat:
Msrc/plugins/python/Makefile.am | 2++
Msrc/plugins/python/clawsmailmodule.c | 2++
Asrc/plugins/python/folderpropertiestype.c | 140+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/plugins/python/folderpropertiestype.h | 32++++++++++++++++++++++++++++++++
Msrc/plugins/python/foldertype.c | 24+++++++++++++++++++++++-
5 files changed, 199 insertions(+), 1 deletion(-)

diff --git a/src/plugins/python/Makefile.am b/src/plugins/python/Makefile.am @@ -13,6 +13,8 @@ python_la_SOURCES = \ clawsmailmodule.h \ composewindowtype.c \ composewindowtype.h \ + folderpropertiestype.c \ + folderpropertiestype.h \ foldertype.c \ foldertype.h \ messageinfotype.c \ diff --git a/src/plugins/python/clawsmailmodule.c b/src/plugins/python/clawsmailmodule.c @@ -27,6 +27,7 @@ #include "nodetype.h" #include "composewindowtype.h" +#include "folderpropertiestype.h" #include "foldertype.h" #include "messageinfotype.h" #include "accounttype.h" @@ -786,6 +787,7 @@ PyMODINIT_FUNC initclawsmail(void) ok = ok && cmpy_add_folder(cm_module); ok = ok && cmpy_add_messageinfo(cm_module); ok = ok && cmpy_add_account(cm_module); + ok = ok && cmpy_add_folderproperties(cm_module); /* initialize misc things */ if(ok) diff --git a/src/plugins/python/folderpropertiestype.c b/src/plugins/python/folderpropertiestype.c @@ -0,0 +1,140 @@ +/* Python plugin for Claws-Mail + * Copyright (C) 2013 Holger Berndt <hb@claws-mail.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +# include "claws-features.h" +#endif + +#include "folderpropertiestype.h" +#include "accounttype.h" + +#include <structmember.h> + +typedef struct { + PyObject_HEAD + FolderItemPrefs *folderitem_prefs; +} clawsmail_FolderPropertiesObject; + +static int FolderProperties_init(clawsmail_FolderPropertiesObject *self, PyObject *args, PyObject *kwds) +{ + self->folderitem_prefs = NULL; + return 0; +} + +static void FolderProperties_dealloc(clawsmail_FolderPropertiesObject* self) +{ + self->ob_type->tp_free((PyObject*)self); +} + +static PyObject* get_default_account(clawsmail_FolderPropertiesObject *self, void *closure) +{ + if(self->folderitem_prefs && self->folderitem_prefs->enable_default_account) { + PrefsAccount *account; + account = account_find_from_id(self->folderitem_prefs->default_account); + if(account) { + return clawsmail_account_new(account); + } + } + Py_RETURN_NONE; +} + +static PyGetSetDef FolderProperties_getset[] = { + {"default_account", (getter)get_default_account, (setter)NULL, + "default_account - the default account when composing from this folder", NULL}, + + {NULL} +}; + +static PyTypeObject clawsmail_FolderPropertiesType = { + PyObject_HEAD_INIT(NULL) + 0, /* ob_size*/ + "clawsmail.FolderProperties", /* tp_name*/ + sizeof(clawsmail_FolderPropertiesObject), /* tp_basicsize*/ + 0, /* tp_itemsize*/ + (destructor)FolderProperties_dealloc, /* tp_dealloc*/ + 0, /* tp_print*/ + 0, /* tp_getattr*/ + 0, /* tp_setattr*/ + 0, /* tp_compare*/ + 0, /* tp_repr*/ + 0, /* tp_as_number*/ + 0, /* tp_as_sequence*/ + 0, /* tp_as_mapping*/ + 0, /* tp_hash */ + 0, /* tp_call*/ + 0, /* tp_str*/ + 0, /* tp_getattro*/ + 0, /* tp_setattro*/ + 0, /* tp_as_buffer*/ + Py_TPFLAGS_DEFAULT, /* tp_flags*/ + "FolderProperties objects.\n\n" /* tp_doc */ + "Do not construct objects of this type yourself.", + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + FolderProperties_getset, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)FolderProperties_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + + +gboolean cmpy_add_folderproperties(PyObject *module) +{ + clawsmail_FolderPropertiesType.tp_new = PyType_GenericNew; + if(PyType_Ready(&clawsmail_FolderPropertiesType) < 0) + return FALSE; + + Py_INCREF(&clawsmail_FolderPropertiesType); + return (PyModule_AddObject(module, "FolderProperties", (PyObject*)&clawsmail_FolderPropertiesType) == 0); +} + +static gboolean update_members(clawsmail_FolderPropertiesObject *self, FolderItemPrefs *folderitem_prefs) +{ + self->folderitem_prefs = folderitem_prefs; + return TRUE; +} + +PyObject* clawsmail_folderproperties_new(FolderItemPrefs *folderitem_prefs) +{ + clawsmail_FolderPropertiesObject *ff; + + if(!folderitem_prefs) + return NULL; + + ff = (clawsmail_FolderPropertiesObject*) PyObject_CallObject((PyObject*) &clawsmail_FolderPropertiesType, NULL); + if(!ff) + return NULL; + + if(update_members(ff, folderitem_prefs)) + return (PyObject*)ff; + else { + Py_XDECREF(ff); + return NULL; + } +} diff --git a/src/plugins/python/folderpropertiestype.h b/src/plugins/python/folderpropertiestype.h @@ -0,0 +1,32 @@ +/* Python plugin for Claws-Mail + * Copyright (C) 2013 Holger Berndt <hb@claws-mail.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef FOLDERPROPERTIESTYPE_H +#define FOLDERPROPERTIESTYPE_H + +#include <glib.h> +#include <Python.h> + +#include "folder_item_prefs.h" + + +gboolean cmpy_add_folderproperties(PyObject *module); + +PyObject* clawsmail_folderproperties_new(FolderItemPrefs *folderitem_prefs); + + +#endif /* FOLDERPROPERTIESTYPE_H */ diff --git a/src/plugins/python/foldertype.c b/src/plugins/python/foldertype.c @@ -23,6 +23,7 @@ #include <glib/gi18n.h> #include "foldertype.h" +#include "folderpropertiestype.h" #include "messageinfotype.h" #include <structmember.h> @@ -33,6 +34,7 @@ typedef struct { PyObject *name; PyObject *path; PyObject *mailbox_name; + PyObject *properties; FolderItem *folderitem; } clawsmail_FolderObject; @@ -42,6 +44,7 @@ static void Folder_dealloc(clawsmail_FolderObject* self) Py_XDECREF(self->name); Py_XDECREF(self->path); Py_XDECREF(self->mailbox_name); + Py_XDECREF(self->properties); self->ob_type->tp_free((PyObject*)self); } @@ -101,6 +104,11 @@ static int Folder_init(clawsmail_FolderObject *self, PyObject *args, PyObject *k FOLDERITEM_STRING_TO_PYTHON_FOLDER_MEMBER(self, folderitem->path, "path"); FOLDERITEM_STRING_TO_PYTHON_FOLDER_MEMBER(self, folderitem->folder->name, "mailbox_name"); self->folderitem = folderitem; + self->properties = clawsmail_folderproperties_new(folderitem->prefs); + } + else { + Py_INCREF(Py_None); + self->properties = Py_None; } return 0; @@ -156,6 +164,12 @@ static PyObject* Folder_get_messages(clawsmail_FolderObject *self, PyObject *arg return retval; } +static PyObject* get_properties(clawsmail_FolderObject *self, void *closure) +{ + Py_INCREF(self->properties); + return self->properties; +} + static PyMethodDef Folder_methods[] = { {"get_identifier", (PyCFunction)Folder_get_identifier, METH_NOARGS, "get_identifier() - get identifier\n" @@ -181,6 +195,14 @@ static PyMemberDef Folder_members[] = { {NULL} }; +static PyGetSetDef Folder_getset[] = { + {"properties", (getter)get_properties, (setter)NULL, + "properties - folder properties object", NULL}, + + {NULL} +}; + + static PyTypeObject clawsmail_FolderType = { PyObject_HEAD_INIT(NULL) 0, /* ob_size*/ @@ -216,7 +238,7 @@ static PyTypeObject clawsmail_FolderType = { 0, /* tp_iternext */ Folder_methods, /* tp_methods */ Folder_members, /* tp_members */ - 0, /* tp_getset */ + Folder_getset, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */