Python plugin: Let Account objects compare equal if they refer to the same account
authorHolger Berndt <hb@claws-mail.org>
Sat, 27 Jul 2013 15:25:54 +0000 (17:25 +0200)
committerHolger Berndt <hb@claws-mail.org>
Sat, 27 Jul 2013 15:28:21 +0000 (17:28 +0200)
src/plugins/python/accounttype.c

index 56c7c7be6232703001e6d8e6e594ea855597cf67..9d42aa15a6e93cb9890b8f262334a882b87f643f 100644 (file)
@@ -52,6 +52,16 @@ static void Account_dealloc(clawsmail_AccountObject* self)
   self->ob_type->tp_free((PyObject*)self);
 }
 
+static int Account_compare(clawsmail_AccountObject *obj1, clawsmail_AccountObject *obj2)
+{
+  if(obj1->account->account_id < obj2->account->account_id)
+    return -1;
+  else if(obj1->account->account_id > obj2->account->account_id)
+    return 1;
+  else
+    return 0;
+}
+
 static PyObject* Account_str(PyObject *self)
 {
   PyObject *str;
@@ -106,7 +116,7 @@ static PyTypeObject clawsmail_AccountType = {
     0,                         /* tp_print*/
     0,                         /* tp_getattr*/
     0,                         /* tp_setattr*/
-    0,                         /* tp_compare*/
+    (cmpfunc)Account_compare,  /* tp_compare*/
     0,                         /* tp_repr*/
     0,                         /* tp_as_number*/
     0,                         /* tp_as_sequence*/