1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Refactor /roster show/hide (#1251)

Refactor /roster show/hide
This commit is contained in:
Daniel Lublin 2020-01-12 22:02:32 +01:00 committed by Michael Vetter
parent 33fca40b58
commit 4420463541

View File

@ -2506,156 +2506,67 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args)
return TRUE; return TRUE;
// show/hide roster // show/hide roster
} else if (g_strcmp0(args[0], "show") == 0) { } else if ((g_strcmp0(args[0], "show") == 0) || (g_strcmp0(args[0], "hide") == 0)) {
preference_t pref;
const char *pref_str;
if (args[1] == NULL) { if (args[1] == NULL) {
cons_show("Roster enabled."); pref = PREF_ROSTER;
prefs_set_boolean(PREF_ROSTER, TRUE); pref_str = "";
if (conn_status == JABBER_CONNECTED) {
ui_show_roster();
}
return TRUE;
} else if (g_strcmp0(args[1], "offline") == 0) { } else if (g_strcmp0(args[1], "offline") == 0) {
cons_show("Roster offline enabled"); pref = PREF_ROSTER_OFFLINE;
prefs_set_boolean(PREF_ROSTER_OFFLINE, TRUE); pref_str = "offline";
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else if (g_strcmp0(args[1], "resource") == 0) { } else if (g_strcmp0(args[1], "resource") == 0) {
cons_show("Roster resource enabled"); pref = PREF_ROSTER_RESOURCE;
prefs_set_boolean(PREF_ROSTER_RESOURCE, TRUE); pref_str = "resource";
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else if (g_strcmp0(args[1], "presence") == 0) { } else if (g_strcmp0(args[1], "presence") == 0) {
cons_show("Roster presence enabled"); pref = PREF_ROSTER_PRESENCE;
prefs_set_boolean(PREF_ROSTER_PRESENCE, TRUE); pref_str = "presence";
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else if (g_strcmp0(args[1], "status") == 0) { } else if (g_strcmp0(args[1], "status") == 0) {
cons_show("Roster status enabled"); pref = PREF_ROSTER_STATUS;
prefs_set_boolean(PREF_ROSTER_STATUS, TRUE); pref_str = "status";
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else if (g_strcmp0(args[1], "empty") == 0) { } else if (g_strcmp0(args[1], "empty") == 0) {
cons_show("Roster empty enabled"); pref = PREF_ROSTER_EMPTY;
prefs_set_boolean(PREF_ROSTER_EMPTY, TRUE); pref_str = "empty";
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else if (g_strcmp0(args[1], "priority") == 0) { } else if (g_strcmp0(args[1], "priority") == 0) {
cons_show("Roster priority enabled"); pref = PREF_ROSTER_PRIORITY;
prefs_set_boolean(PREF_ROSTER_PRIORITY, TRUE); pref_str = "priority";
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else if (g_strcmp0(args[1], "contacts") == 0) { } else if (g_strcmp0(args[1], "contacts") == 0) {
cons_show("Roster contacts enabled"); pref = PREF_ROSTER_CONTACTS;
prefs_set_boolean(PREF_ROSTER_CONTACTS, TRUE); pref_str = "contacts";
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else if (g_strcmp0(args[1], "rooms") == 0) { } else if (g_strcmp0(args[1], "rooms") == 0) {
cons_show("Roster rooms enabled"); pref = PREF_ROSTER_ROOMS;
prefs_set_boolean(PREF_ROSTER_ROOMS, TRUE); pref_str = "rooms";
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else if (g_strcmp0(args[1], "unsubscribed") == 0) { } else if (g_strcmp0(args[1], "unsubscribed") == 0) {
cons_show("Roster unsubscribed enabled"); pref = PREF_ROSTER_UNSUBSCRIBED;
prefs_set_boolean(PREF_ROSTER_UNSUBSCRIBED, TRUE); pref_str = "unsubscribed";
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else { } else {
cons_bad_cmd_usage(command); cons_bad_cmd_usage(command);
return TRUE; return TRUE;
} }
} else if (g_strcmp0(args[0], "hide") == 0) {
if (args[1] == NULL) { gboolean val;
cons_show("Roster disabled."); if (g_strcmp0(args[0], "show") == 0) {
prefs_set_boolean(PREF_ROSTER, FALSE); val = TRUE;
} else { // "hide"
val = FALSE;
}
cons_show("Roster%s%s %s (was %s)", strlen(pref_str) == 0 ? "" : " ", pref_str,
val == TRUE ? "enabled" : "disabled",
prefs_get_boolean(pref) == TRUE ? "enabled" : "disabled");
prefs_set_boolean(pref, val);
if (conn_status == JABBER_CONNECTED) { if (conn_status == JABBER_CONNECTED) {
if (pref == PREF_ROSTER) {
if (val == TRUE) {
ui_show_roster();
} else {
ui_hide_roster(); ui_hide_roster();
} }
return TRUE;
} else if (g_strcmp0(args[1], "offline") == 0) {
cons_show("Roster offline disabled");
prefs_set_boolean(PREF_ROSTER_OFFLINE, FALSE);
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else if (g_strcmp0(args[1], "resource") == 0) {
cons_show("Roster resource disabled");
prefs_set_boolean(PREF_ROSTER_RESOURCE, FALSE);
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else if (g_strcmp0(args[1], "presence") == 0) {
cons_show("Roster presence disabled");
prefs_set_boolean(PREF_ROSTER_PRESENCE, FALSE);
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else if (g_strcmp0(args[1], "status") == 0) {
cons_show("Roster status disabled");
prefs_set_boolean(PREF_ROSTER_STATUS, FALSE);
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else if (g_strcmp0(args[1], "empty") == 0) {
cons_show("Roster empty disabled");
prefs_set_boolean(PREF_ROSTER_EMPTY, FALSE);
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else if (g_strcmp0(args[1], "priority") == 0) {
cons_show("Roster priority disabled");
prefs_set_boolean(PREF_ROSTER_PRIORITY, FALSE);
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else if (g_strcmp0(args[1], "contacts") == 0) {
cons_show("Roster contacts disabled");
prefs_set_boolean(PREF_ROSTER_CONTACTS, FALSE);
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else if (g_strcmp0(args[1], "rooms") == 0) {
cons_show("Roster rooms disabled");
prefs_set_boolean(PREF_ROSTER_ROOMS, FALSE);
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else if (g_strcmp0(args[1], "unsubscribed") == 0) {
cons_show("Roster unsubscribed disabled");
prefs_set_boolean(PREF_ROSTER_UNSUBSCRIBED, FALSE);
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else { } else {
cons_bad_cmd_usage(command); rosterwin_roster();
return TRUE;
} }
}
return TRUE;
// roster grouping // roster grouping
} else if (g_strcmp0(args[0], "by") == 0) { } else if (g_strcmp0(args[0], "by") == 0) {