RSSyl: Allow use of .netrc by libcurl. Bug/enhancement #3309, by Vincent Pelletier
[claws.git] / src / plugins / python / composewindowtype.c
index 59ebeeadeb774ea127267ad61f85bb4869b5944f..3a54116034c7ae56d1280ac11c526260a2d40ee4 100644 (file)
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
-#include "claws-features.h"
+#  include "claws-features.h"
 #endif
 
-#include <glib.h>
-#include <glib/gi18n.h>
-
 #include "composewindowtype.h"
+#include "accounttype.h"
 
 #include "clawsmailmodule.h"
 #include "foldertype.h"
 #include "mainwindow.h"
 #include "account.h"
 #include "summaryview.h"
+#include "gtk/combobox.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
 
 #include <structmember.h>
 
@@ -42,6 +44,7 @@ typedef struct {
     PyObject *ui_manager;
     PyObject *text;
     PyObject *replyinfo;
+    PyObject *fwdinfo;
     Compose *compose;
 } clawsmail_ComposeWindowObject;
 
@@ -50,6 +53,7 @@ static void ComposeWindow_dealloc(clawsmail_ComposeWindowObject* self)
   Py_XDECREF(self->ui_manager);
   Py_XDECREF(self->text);
   Py_XDECREF(self->replyinfo);
+  Py_XDECREF(self->fwdinfo);
   self->ob_type->tp_free((PyObject*)self);
 }
 
@@ -81,6 +85,7 @@ static void composewindow_set_compose(clawsmail_ComposeWindowObject *self, Compo
   store_py_object(&(self->text), get_gobj_from_address(compose->text));
 
   store_py_object(&(self->replyinfo), clawsmail_messageinfo_new(compose->replyinfo));
+  store_py_object(&(self->fwdinfo), clawsmail_messageinfo_new(compose->fwdinfo));
 }
 
 static int ComposeWindow_init(clawsmail_ComposeWindowObject *self, PyObject *args, PyObject *kwds)
@@ -340,23 +345,11 @@ static PyObject* ComposeWindow_add_header(clawsmail_ComposeWindowObject *self, P
   return Py_None;
 }
 
-/* this is pretty ugly, as the compose struct does not maintain a pointer to the account selection combo */
 static PyObject* ComposeWindow_get_account_selection(clawsmail_ComposeWindowObject *self, PyObject *args)
 {
-  GList *children, *walk;
-
-  children = gtk_container_get_children(GTK_CONTAINER(self->compose->header_table));
-  for(walk = children; walk; walk = walk->next) {
-    if(GTK_IS_HBOX(walk->data)) {
-      GList *children2, *walk2;
-      children2 = gtk_container_get_children(GTK_CONTAINER(walk->data));
-      for(walk2 = children2; walk2; walk2 = walk2->next) {
-        if(GTK_IS_EVENT_BOX(walk2->data)) {
-          return get_gobj_from_address(gtk_container_get_children(GTK_CONTAINER(walk2->data))->data);
-        }
-      }
-    }
-  }
+  if(GTK_IS_COMBO_BOX(self->compose->account_combo))
+    return get_gobj_from_address(self->compose->account_combo);
+
   Py_INCREF(Py_None);
   return Py_None;
 }
@@ -443,6 +436,47 @@ static PyObject* ComposeWindow_set_modified(clawsmail_ComposeWindowObject *self,
   return Py_None;
 }
 
+static PyObject* get_account(clawsmail_ComposeWindowObject *self, void *closure)
+{
+  if(self->compose->account) {
+    return clawsmail_account_new(self->compose->account);
+  }
+  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,
      "set_subject(text) - set subject to text\n"
@@ -539,6 +573,16 @@ static PyMemberDef ComposeWindow_members[] = {
     {"replyinfo", T_OBJECT_EX, offsetof(clawsmail_ComposeWindowObject, replyinfo), 0,
      "replyinfo - The MessageInfo object of the message that is being replied to, or None"},
 
+    {"forwardinfo", T_OBJECT_EX, offsetof(clawsmail_ComposeWindowObject, fwdinfo), 0,
+     "forwardinfo - The MessageInfo object of the message that is being forwarded, or None"},
+
+    {NULL}
+};
+
+static PyGetSetDef ComposeWindow_getset[] = {
+    {"account", (getter)get_account, (setter)set_account,
+      "account - the account corresponding to this compose window", NULL},
+
     {NULL}
 };
 
@@ -574,7 +618,7 @@ static PyTypeObject clawsmail_ComposeWindowType = {
     0,                         /* tp_iternext */
     ComposeWindow_methods,     /* tp_methods */
     ComposeWindow_members,     /* tp_members */
-    0,                         /* tp_getset */
+    ComposeWindow_getset,      /* tp_getset */
     0,                         /* tp_base */
     0,                         /* tp_dict */
     0,                         /* tp_descr_get */
@@ -585,14 +629,14 @@ static PyTypeObject clawsmail_ComposeWindowType = {
     0,                         /* tp_new */
 };
 
-PyMODINIT_FUNC initcomposewindow(PyObject *module)
+gboolean cmpy_add_composewindow(PyObject *module)
 {
-    clawsmail_ComposeWindowType.tp_new = PyType_GenericNew;
-    if(PyType_Ready(&clawsmail_ComposeWindowType) < 0)
-        return;
+  clawsmail_ComposeWindowType.tp_new = PyType_GenericNew;
+  if(PyType_Ready(&clawsmail_ComposeWindowType) < 0)
+    return FALSE;
 
-    Py_INCREF(&clawsmail_ComposeWindowType);
-    PyModule_AddObject(module, "ComposeWindow", (PyObject*)&clawsmail_ComposeWindowType);
+  Py_INCREF(&clawsmail_ComposeWindowType);
+  return (PyModule_AddObject(module, "ComposeWindow", (PyObject*)&clawsmail_ComposeWindowType) == 0);
 }
 
 PyObject* clawsmail_compose_new(PyObject *module, Compose *compose)