struct t_gui_hotlist * gui_hotlist_add (struct t_gui_buffer *buffer, enum t_gui_hotlist_priority priority, struct timeval *creation_time) { struct t_gui_hotlist *new_hotlist, *ptr_hotlist; int i, count[GUI_HOTLIST_NUM_PRIORITIES], rc; char *value, str_value[32]; if (!buffer || !gui_add_hotlist) return NULL; /* do not add core buffer if upgrading */ if (weechat_upgrading && (buffer == gui_buffer_search_main ())) return NULL; if (priority > GUI_HOTLIST_MAX) priority = GUI_HOTLIST_MAX; /* check if priority is OK according to buffer notify level value */ if (!gui_hotlist_check_buffer_notify (buffer, priority)) return NULL; /* create hashtable if needed (to evaluate conditions) */ if (!gui_hotlist_hashtable_add_conditions_pointers) { gui_hotlist_hashtable_add_conditions_pointers = hashtable_new ( 32, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_POINTER, NULL, NULL); if (!gui_hotlist_hashtable_add_conditions_pointers) return NULL; } if (!gui_hotlist_hashtable_add_conditions_vars) { gui_hotlist_hashtable_add_conditions_vars = hashtable_new ( 32, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_STRING, NULL, NULL); if (!gui_hotlist_hashtable_add_conditions_vars) return NULL; } if (!gui_hotlist_hashtable_add_conditions_options) { gui_hotlist_hashtable_add_conditions_options = hashtable_new ( 32, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_STRING, NULL, NULL); if (!gui_hotlist_hashtable_add_conditions_options) return NULL; hashtable_set (gui_hotlist_hashtable_add_conditions_options, "type", "condition"); } /* set data in hashtables */ hashtable_set (gui_hotlist_hashtable_add_conditions_pointers, "window", gui_current_window); hashtable_set (gui_hotlist_hashtable_add_conditions_pointers, "buffer", buffer); snprintf (str_value, sizeof (str_value), "%d", priority); hashtable_set (gui_hotlist_hashtable_add_conditions_vars, "priority", str_value); /* check if conditions are true */ value = eval_expression (CONFIG_STRING(config_look_hotlist_add_conditions), gui_hotlist_hashtable_add_conditions_pointers, gui_hotlist_hashtable_add_conditions_vars, gui_hotlist_hashtable_add_conditions_options); rc = (value && (strcmp (value, "1") == 0)); if (value) free (value); if (!rc) return NULL; /* init count */ for (i = 0; i < GUI_HOTLIST_NUM_PRIORITIES; i++) { count[i] = 0; } ptr_hotlist = gui_hotlist_search (gui_hotlist, buffer); if (ptr_hotlist) { /* return if priority is greater or equal than the one to add */ if (ptr_hotlist->priority >= priority) { ptr_hotlist->count[priority]++; gui_hotlist_changed_signal (); return ptr_hotlist; } /* * if buffer is present with lower priority: save counts, remove it * and go on */ memcpy (count, ptr_hotlist->count, sizeof (ptr_hotlist->count)); gui_hotlist_free (&gui_hotlist, &last_gui_hotlist, ptr_hotlist); } new_hotlist = malloc (sizeof (*new_hotlist)); if (!new_hotlist) return NULL; new_hotlist->priority = priority; if (creation_time) { memcpy (&(new_hotlist->creation_time), creation_time, sizeof (*creation_time)); } else gettimeofday (&(new_hotlist->creation_time), NULL); new_hotlist->buffer = buffer; memcpy (new_hotlist->count, count, sizeof (new_hotlist->count)); new_hotlist->count[priority]++; new_hotlist->next_hotlist = NULL; new_hotlist->prev_hotlist = NULL; gui_hotlist_add_hotlist (&gui_hotlist, &last_gui_hotlist, new_hotlist); gui_hotlist_changed_signal (); return new_hotlist; }
struct t_gui_hotlist * gui_hotlist_add (struct t_gui_buffer *buffer, enum t_gui_hotlist_priority priority, struct timeval *creation_time) { struct t_gui_hotlist *new_hotlist, *ptr_hotlist; int i, count[GUI_HOTLIST_NUM_PRIORITIES]; const char *away; if (!buffer || !gui_add_hotlist) return NULL; /* do not add core buffer if upgrading */ if (weechat_upgrading && (buffer == gui_buffer_search_main ())) return NULL; /* do not add buffer if it is displayed and away is not set */ away = hashtable_get (buffer->local_variables, "away"); if ((buffer->num_displayed > 0) && ((!away || !away[0]) || !CONFIG_BOOLEAN(config_look_hotlist_add_buffer_if_away))) return NULL; if (priority > GUI_HOTLIST_MAX) priority = GUI_HOTLIST_MAX; /* check if priority is OK according to buffer notify level value */ if (!gui_hotlist_check_buffer_notify (buffer, priority)) return NULL; /* init count */ for (i = 0; i < GUI_HOTLIST_NUM_PRIORITIES; i++) { count[i] = 0; } ptr_hotlist = gui_hotlist_search (gui_hotlist, buffer); if (ptr_hotlist) { /* return if priority is greater or equal than the one to add */ if (ptr_hotlist->priority >= priority) { ptr_hotlist->count[priority]++; gui_hotlist_changed_signal (); return ptr_hotlist; } /* * if buffer is present with lower priority: save counts, remove it * and go on */ memcpy (count, ptr_hotlist->count, sizeof (ptr_hotlist->count)); gui_hotlist_free (&gui_hotlist, &last_gui_hotlist, ptr_hotlist); } new_hotlist = malloc (sizeof (*new_hotlist)); if (!new_hotlist) { log_printf (_("Error: not enough memory to add a buffer to " "hotlist")); return NULL; } new_hotlist->priority = priority; if (creation_time) { memcpy (&(new_hotlist->creation_time), creation_time, sizeof (*creation_time)); } else gettimeofday (&(new_hotlist->creation_time), NULL); new_hotlist->buffer = buffer; memcpy (new_hotlist->count, count, sizeof (new_hotlist->count)); new_hotlist->count[priority]++; new_hotlist->next_hotlist = NULL; new_hotlist->prev_hotlist = NULL; gui_hotlist_add_hotlist (&gui_hotlist, &last_gui_hotlist, new_hotlist); gui_hotlist_changed_signal (); return new_hotlist; }