commit 9166dc63e4d2f3f4d62293b48706cfa9b9a0afc1
parent fa8fd46c1f9945fd21ab78e5eaeaf89fa6e9df15
Author: Holger Berndt <hb@claws-mail.org>
Date: Thu, 14 Aug 2014 23:41:00 +0200
Python plugin: Make 'account' property of ComposeWindow read/write
Diffstat:
3 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/src/plugins/python/accounttype.c b/src/plugins/python/accounttype.c
@@ -160,3 +160,15 @@ PyObject* clawsmail_account_new(PrefsAccount *account)
ff->account = account;
return (PyObject*)ff;
}
+
+gboolean clawsmail_account_check(PyObject *self)
+{
+ return (PyObject_TypeCheck(self, &clawsmail_AccountType) != 0);
+}
+
+PrefsAccount* clawsmail_account_get_account(PyObject *self)
+{
+ g_return_val_if_fail(clawsmail_account_check(self), NULL);
+
+ return ((clawsmail_AccountObject*)self)->account;
+}
diff --git a/src/plugins/python/accounttype.h b/src/plugins/python/accounttype.h
@@ -27,5 +27,7 @@ gboolean cmpy_add_account(PyObject *module);
PyObject* clawsmail_account_new(PrefsAccount *account);
+gboolean clawsmail_account_check(PyObject *self);
+PrefsAccount* clawsmail_account_get_account(PyObject *self);
#endif /* ACCOUNTTYPE_H */
diff --git a/src/plugins/python/composewindowtype.c b/src/plugins/python/composewindowtype.c
@@ -30,6 +30,7 @@
#include "mainwindow.h"
#include "account.h"
#include "summaryview.h"
+#include "gtk/combobox.h"
#include <glib.h>
#include <glib/gi18n.h>
@@ -443,6 +444,38 @@ static PyObject* get_account(clawsmail_ComposeWindowObject *self, void *closure)
Py_RETURN_NONE;
}
+static int set_account(clawsmail_ComposeWindowObject *self, PyObject *value, void *closure)
+{
+ PrefsAccount *target_account;
+
+ if(value == NULL) {
+ PyErr_SetString(PyExc_TypeError, "Cannot delete 'account' attribute");
+ return -1;
+ }
+
+ if(!clawsmail_account_check(value)) {
+ PyErr_SetString(PyExc_TypeError, "ComposeWindow.account: Can only assign an account");
+ return -1;
+ }
+
+
+ target_account = clawsmail_account_get_account(value);
+ if(!target_account) {
+ PyErr_SetString(PyExc_TypeError, "Account value broken");
+ return -1;
+ }
+
+ if(!self->compose || !self->compose->account_combo) {
+ PyErr_SetString(PyExc_RuntimeError, "ComposeWindow: Cannot access account");
+ return -1;
+ }
+
+ combobox_select_by_data(GTK_COMBO_BOX(self->compose->account_combo), target_account->account_id);
+
+ return 0;
+}
+
+
static PyMethodDef ComposeWindow_methods[] = {
{"set_subject", (PyCFunction)ComposeWindow_set_subject, METH_VARARGS,
@@ -547,7 +580,7 @@ static PyMemberDef ComposeWindow_members[] = {
};
static PyGetSetDef ComposeWindow_getset[] = {
- {"account", (getter)get_account, (setter)NULL,
+ {"account", (getter)get_account, (setter)set_account,
"account - the account corresponding to this compose window", NULL},
{NULL}