mcabber/mcabber/settings.c
changeset 2341 c78988260b9f
parent 2340 6eeef7be58f3
equal deleted inserted replaced
2340:6eeef7be58f3 2341:c78988260b9f
   653   return NULL;
   653   return NULL;
   654 }
   654 }
   655 
   655 
   656 /* otr settings */
   656 /* otr settings */
   657 
   657 
   658 #ifdef HAVE_LIBOTR
       
   659 static void remove_default_policies(char *k, char *policy, void *defaultp)
       
   660 {
       
   661   if (*(enum otr_policy *)policy == *(enum otr_policy *)defaultp) {
       
   662     g_hash_table_remove(otrpolicy, k);
       
   663   }
       
   664 }
       
   665 #endif
       
   666 
       
   667 void settings_otr_setpolicy(const char *bjid, guint value)
   658 void settings_otr_setpolicy(const char *bjid, guint value)
   668 {
   659 {
   669 #ifdef HAVE_LIBOTR
   660 #ifdef HAVE_LIBOTR
   670   enum otr_policy *otrdata;
   661   enum otr_policy *otrdata;
   671 
   662 
   672   if (!bjid) {
   663   if (!bjid) { // no jid -> default policy
   673     default_policy = value;
   664     default_policy = value;
   674     /* refresh hash */
   665   } else { //policy for some specific jid
   675     settings_foreach(SETTINGS_TYPE_OTR, &remove_default_policies, &value);
   666     otrdata = g_hash_table_lookup(otrpolicy, bjid);
   676     return;
   667 
   677   }
       
   678 
       
   679   otrdata = g_hash_table_lookup(otrpolicy, bjid);
       
   680 
       
   681   if (value == default_policy) {
       
   682     if (otrdata) {
   668     if (otrdata) {
   683       g_hash_table_remove(otrpolicy, bjid);
   669       *otrdata = value;
   684     }
   670     } else {
   685   } else if (otrdata) {
   671       otrdata = g_new(enum otr_policy, 1);
   686     *otrdata = value;
   672       *otrdata = value;
   687   } else {
   673       g_hash_table_insert(otrpolicy, g_strdup(bjid), otrdata);
   688     otrdata = g_new(enum otr_policy, 1);
   674     }
   689     *otrdata = value;
       
   690     g_hash_table_insert(otrpolicy, g_strdup(bjid), otrdata);
       
   691   }
   675   }
   692 #endif
   676 #endif
   693 }
   677 }
   694 
   678 
   695 guint settings_otr_getpolicy(const char *bjid)
   679 guint settings_otr_getpolicy(const char *bjid)