plugin interface: Refactor "flags" option in "channels" list to be more clear with bit operators

This commit is contained in:
BakasuraRCE 2020-07-29 09:47:05 -05:00 committed by Patrick
parent 0a85d79dff
commit e03fab07ed

View File

@ -115,6 +115,32 @@ enum
HOOK_DELETED = 1 << 7 /* marked for deletion */ HOOK_DELETED = 1 << 7 /* marked for deletion */
}; };
enum
{
CHANNEL_FLAG_CONNECTED = 1 << 0,
CHANNEL_FLAG_CONNECING = 1 << 1,
CHANNEL_FLAG_AWAY = 1 << 2,
CHANNEL_FLAG_END_OF_MOTD = 1 << 3,
CHANNEL_FLAG_HAS_WHOX = 1 << 4,
CHANNEL_FLAG_HAS_IDMSG = 1 << 5,
CHANNEL_FLAG_HIDE_JOIN_PARTS = 1 << 6,
CHANNEL_FLAG_HIDE_JOIN_PARTS_UNSET = 1 << 7,
CHANNEL_FLAG_BEEP = 1 << 8,
CHANNEL_FLAG_BEEP_UNSET = 1 << 9,
CHANNEL_FLAG_UNUSED = 1 << 10,
CHANNEL_FLAG_LOGGING = 1 << 11,
CHANNEL_FLAG_LOGGING_UNSET = 1 << 12,
CHANNEL_FLAG_SCROLLBACK = 1 << 13,
CHANNEL_FLAG_SCROLLBACK_UNSET = 1 << 14,
CHANNEL_FLAG_STRIP_COLORS = 1 << 15,
CHANNEL_FLAG_STRIP_COLORS_UNSET = 1 << 16,
CHANNEL_FLAG_TRAY = 1 << 17,
CHANNEL_FLAG_TRAY_UNSET = 1 << 18,
CHANNEL_FLAG_TASKBAR = 1 << 19,
CHANNEL_FLAG_TASKBAR_UNSET = 1 << 20,
CHANNEL_FLAG_COUNT = 21
};
GSList *plugin_list = NULL; /* export for plugingui.c */ GSList *plugin_list = NULL; /* export for plugingui.c */
static GSList *hook_list = NULL; static GSList *hook_list = NULL;
@ -1521,7 +1547,11 @@ hexchat_list_int (hexchat_plugin *ph, hexchat_list *xlist, const char *name)
{ {
guint32 hash = str_hash (name); guint32 hash = str_hash (name);
gpointer data = ph->context; gpointer data = ph->context;
int tmp = 0;
int channel_flag;
int channel_flags[CHANNEL_FLAG_COUNT];
int channel_flags_used = 0;
int type = LIST_CHANNELS; int type = LIST_CHANNELS;
/* a NULL xlist is a shortcut to current "channels" context */ /* a NULL xlist is a shortcut to current "channels" context */
@ -1582,48 +1612,36 @@ hexchat_list_int (hexchat_plugin *ph, hexchat_list *xlist, const char *name)
case 0xd1b: /* id */ case 0xd1b: /* id */
return ((struct session *)data)->server->id; return ((struct session *)data)->server->id;
case 0x5cfee87: /* flags */ case 0x5cfee87: /* flags */
/* used if alert_taskbar is unset */ /* 20 */ channel_flags[0] = ((struct session *)data)->server->connected;
tmp <<= 1; channel_flags[1] = ((struct session *)data)->server->connecting;
tmp |= ((struct session *)data)->alert_taskbar; /* 19 */ channel_flags[2] = ((struct session *)data)->server->is_away;
tmp <<= 1; channel_flags[3] = ((struct session *)data)->server->end_of_motd;
/* used if alert_tray is unset */ /* 18 */ channel_flags[4] = ((struct session *)data)->server->have_whox;
tmp <<= 1; channel_flags[5] = ((struct session *)data)->server->have_idmsg;
tmp |= ((struct session *)data)->alert_tray; /* 17 */ channel_flags[6] = ((struct session *)data)->text_hidejoinpart;
tmp <<= 1; channel_flags[7] = ((struct session *)data)->text_hidejoinpart == SET_DEFAULT;
/* used if text_strip is unset */ /* 16 */ channel_flags[8] = ((struct session *)data)->alert_beep;
tmp <<= 1; channel_flags[9] = ((struct session *)data)->alert_beep == SET_DEFAULT;
tmp |= ((struct session *)data)->text_strip; /* 15 */ channel_flags[10] = 0; /* unused for historical reasons */
tmp <<= 1; channel_flags[11] = ((struct session *)data)->text_logging;
/* used if text_scrollback is unset */ /* 14 */ channel_flags[12] = ((struct session *)data)->text_logging == SET_DEFAULT;
tmp <<= 1; channel_flags[13] = ((struct session *)data)->text_scrollback;
tmp |= ((struct session *)data)->text_scrollback; /* 13 */ channel_flags[14] = ((struct session *)data)->text_scrollback == SET_DEFAULT;
tmp <<= 1; channel_flags[15] = ((struct session *)data)->text_strip;
/* used if text_logging is unset */ /* 12 */ channel_flags[16] = ((struct session *)data)->text_strip == SET_DEFAULT;
tmp <<= 1; channel_flags[17] = ((struct session *)data)->alert_tray;
tmp |= ((struct session *)data)->text_logging; /* 11 */ channel_flags[18] = ((struct session *)data)->alert_tray == SET_DEFAULT;
tmp <<= 1; channel_flags[19] = ((struct session *)data)->alert_taskbar;
/* unused for historical reasons */ /* 10 */ channel_flags[20] = ((struct session *)data)->alert_taskbar == SET_DEFAULT;
tmp <<= 1;
/* used if alert_beep is unset */ /* 9 */ /* Set flags */
tmp <<= 1; for (channel_flag = 0; channel_flag < CHANNEL_FLAG_COUNT; ++channel_flag) {
tmp |= ((struct session *)data)->alert_beep; /* 8 */ if (channel_flags[channel_flag]) {
tmp <<= 1; channel_flags_used |= 1 << channel_flag;
/* used if text_hidejoinpart is unset */ /* 7 */ }
tmp <<= 1; }
tmp |= ((struct session *)data)->text_hidejoinpart; /* 6 */
tmp <<= 1; return channel_flags_used;
tmp |= ((struct session *)data)->server->have_idmsg; /* 5 */
tmp <<= 1;
tmp |= ((struct session *)data)->server->have_whox; /* 4 */
tmp <<= 1;
tmp |= ((struct session *)data)->server->end_of_motd;/* 3 */
tmp <<= 1;
tmp |= ((struct session *)data)->server->is_away; /* 2 */
tmp <<= 1;
tmp |= ((struct session *)data)->server->connecting; /* 1 */
tmp <<= 1;
tmp |= ((struct session *)data)->server->connected; /* 0 */
return tmp;
case 0x1a192: /* lag */ case 0x1a192: /* lag */
return ((struct session *)data)->server->lag; return ((struct session *)data)->server->lag;
case 0x1916144c: /* maxmodes */ case 0x1916144c: /* maxmodes */