/* * console.c * * Copyright (C) 2012 - 2019 James Booth * * This file is part of Profanity. * * Profanity is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Profanity is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Profanity. If not, see . * * In addition, as a special exception, the copyright holders give permission to * link the code of portions of this program with the OpenSSL library under * certain conditions as described in each individual source file, and * distribute linked combinations including the two. * * You must obey the GNU General Public License in all respects for all of the * code used other than OpenSSL. If you modify file(s) with this exception, you * may extend this exception to your version of the file(s), but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. If you delete this exception statement from all * source files in the program, then also delete it here. * */ #include #include #include #ifdef HAVE_NCURSESW_NCURSES_H #include #elif HAVE_NCURSES_H #include #endif #include "common.h" #include "log.h" #include "config/preferences.h" #include "config/theme.h" #include "command/cmd_defs.h" #include "ui/window_list.h" #include "ui/ui.h" #include "ui/window.h" #include "ui/statusbar.h" #include "xmpp/xmpp.h" #include "xmpp/muc.h" #include "xmpp/roster_list.h" #ifdef HAVE_GIT_VERSION #include "gitversion.h" #endif static void _cons_splash_logo(void); void _show_roster_contacts(GSList *list, gboolean show_groups); void cons_debug(const char *const msg, ...) { ProfWin *console = wins_get_console(); if (strcmp(PACKAGE_STATUS, "development") == 0) { va_list arg; va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); win_println(console, THEME_DEFAULT, '-', "%s", fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); } } void cons_show(const char *const msg, ...) { ProfWin *console = wins_get_console(); va_list arg; va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); win_println(console, THEME_DEFAULT, '-', "%s", fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); } void cons_show_padded(int pad, const char *const msg, ...) { ProfWin *console = wins_get_console(); va_list arg; va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); win_println_indent(console, pad, "%s", fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); } void cons_show_help(const char *const cmd, CommandHelp *help) { ProfWin *console = wins_get_console(); cons_show(""); win_println(console, THEME_HELP_HEADER, '-', "%s", &cmd[1]); win_print(console, THEME_HELP_HEADER, '-', ""); int i; for (i = 0; i < strlen(cmd) - 1 ; i++) { win_append(console, THEME_HELP_HEADER, "-"); } win_appendln(console, THEME_HELP_HEADER, ""); cons_show(""); win_println(console, THEME_HELP_HEADER, '-', "Synopsis"); ui_show_lines(console, help->synopsis); cons_show(""); win_println(console, THEME_HELP_HEADER, '-', "Description"); win_println(console, THEME_DEFAULT, '-', "%s", help->desc); int maxlen = 0; for (i = 0; help->args[i][0] != NULL; i++) { if (strlen(help->args[i][0]) > maxlen) maxlen = strlen(help->args[i][0]); } if (i > 0) { cons_show(""); win_println(console, THEME_HELP_HEADER, '-', "Arguments"); for (i = 0; help->args[i][0] != NULL; i++) { win_println_indent(console, maxlen + 3, "%-*s: %s", maxlen + 1, help->args[i][0], help->args[i][1]); } } if (g_strv_length((gchar**)help->examples) > 0) { cons_show(""); win_println(console, THEME_HELP_HEADER, '-', "Examples"); ui_show_lines(console, help->examples); } } void cons_bad_cmd_usage(const char *const cmd) { GString *msg = g_string_new(""); g_string_printf(msg, "Invalid usage, see '/help %s' for details.", &cmd[1]); cons_show(""); cons_show(msg->str); g_string_free(msg, TRUE); } void cons_show_error(const char *const msg, ...) { ProfWin *console = wins_get_console(); va_list arg; va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); win_println(console, THEME_ERROR, '-', "%s", fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); cons_alert(); } void cons_show_tlscert_summary(TLSCertificate *cert) { if (!cert) { return; } cons_show("Subject : %s", cert->subject_commonname); cons_show("Issuer : %s", cert->issuer_commonname); cons_show("Fingerprint : %s", cert->fingerprint); } void cons_show_tlscert(TLSCertificate *cert) { if (!cert) { return; } cons_show("Certificate:"); cons_show(" Subject:"); if (cert->subject_commonname) { cons_show(" Common name : %s", cert->subject_commonname); } if (cert->subject_distinguishedname) { cons_show(" Distinguished name : %s", cert->subject_distinguishedname); } if (cert->subject_organisation) { cons_show(" Organisation : %s", cert->subject_organisation); } if (cert->subject_organisation_unit) { cons_show(" Organisation unit : %s", cert->subject_organisation_unit); } if (cert->subject_email) { cons_show(" Email : %s", cert->subject_email); } if (cert->subject_state) { cons_show(" State : %s", cert->subject_state); } if (cert->subject_country) { cons_show(" Country : %s", cert->subject_country); } if (cert->subject_serialnumber) { cons_show(" Serial number : %s", cert->subject_serialnumber); } cons_show(" Issuer:"); if (cert->issuer_commonname) { cons_show(" Common name : %s", cert->issuer_commonname); } if (cert->issuer_distinguishedname) { cons_show(" Distinguished name : %s", cert->issuer_distinguishedname); } if (cert->issuer_organisation) { cons_show(" Organisation : %s", cert->issuer_organisation); } if (cert->issuer_organisation_unit) { cons_show(" Organisation unit : %s", cert->issuer_organisation_unit); } if (cert->issuer_email) { cons_show(" Email : %s", cert->issuer_email); } if (cert->issuer_state) { cons_show(" State : %s", cert->issuer_state); } if (cert->issuer_country) { cons_show(" Country : %s", cert->issuer_country); } if (cert->issuer_serialnumber) { cons_show
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ranger.applications</title>
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="ranger.html"><font color="#ffffff">ranger</font></a>.applications</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/hut/ranger/ranger/applications.pyc">/home/hut/ranger/ranger/applications.pyc</a></font></td></tr></table>
    <p><tt>This&nbsp;module&nbsp;provides&nbsp;helper&nbsp;functions/classes&nbsp;for&nbsp;ranger.defaults.apps.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
    
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="os.html">os</a><br>
</td><td width="25%" valign=top><a href="sys.html">sys</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
    
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="ranger.shared.html#FileManagerAware">ranger.shared.FileManagerAware</a>(<a href="ranger.shared.html#Awareness">ranger.shared.Awareness</a>)
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="ranger.applications.html#Applications">Applications</a>
</font></dt></dl>
</dd>
</dl>
 <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="Applications">class <strong>Applications</strong></a>(<a href="ranger.shared.html#FileManagerAware">ranger.shared.FileManagerAware</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>This&nbsp;class&nbsp;contains&nbsp;definitions&nbsp;on&nbsp;how&nbsp;to&nbsp;run&nbsp;programs&nbsp;and&nbsp;should<br>
be&nbsp;extended&nbsp;in&nbsp;ranger.defaults.apps<br>
&nbsp;<br>
The&nbsp;user&nbsp;can&nbsp;decide&nbsp;what&nbsp;program&nbsp;to&nbsp;run,&nbsp;and&nbsp;if&nbsp;he&nbsp;uses&nbsp;eg.&nbsp;'vim',&nbsp;the<br>
function&nbsp;app_vim()&nbsp;will&nbsp;be&nbsp;called.&nbsp;&nbsp;However,&nbsp;usually&nbsp;the&nbsp;user<br>
simply&nbsp;wants&nbsp;to&nbsp;"start"&nbsp;the&nbsp;file&nbsp;without&nbsp;specific&nbsp;instructions.<br>
In&nbsp;such&nbsp;a&nbsp;case,&nbsp;app_default()&nbsp;is&nbsp;called,&nbsp;where&nbsp;you&nbsp;should&nbsp;examine<br>
the&nbsp;context&nbsp;and&nbsp;decide&nbsp;which&nbsp;program&nbsp;to&nbsp;use.<br>
&nbsp;<br>
All&nbsp;app&nbsp;functions&nbsp;have&nbsp;a&nbsp;name&nbsp;starting&nbsp;with&nbsp;app_&nbsp;and&nbsp;return&nbsp;a&nbsp;string<br>
containing&nbsp;the&nbsp;whole&nbsp;command&nbsp;or&nbsp;a&nbsp;tuple&nbsp;containing&nbsp;a&nbsp;list&nbsp;of&nbsp;the<br>
arguments.&nbsp;They&nbsp;are&nbsp;supplied&nbsp;with&nbsp;one&nbsp;argument,&nbsp;which&nbsp;is&nbsp;the<br>
AppContext&nbsp;instance.<br>
&nbsp;<br>
You&nbsp;should&nbsp;define&nbsp;at&nbsp;least&nbsp;app_default,&nbsp;app_pager&nbsp;and&nbsp;app_editor&nbsp;since<br>
internal&nbsp;functions&nbsp;depend&nbsp;on&nbsp;those.&nbsp;&nbsp;Here&nbsp;are&nbsp;sample&nbsp;implementations:<br>
&nbsp;<br>
def&nbsp;app_default(self,&nbsp;context):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;context.file.media:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;context.file.video:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;detach&nbsp;videos&nbsp;from&nbsp;the&nbsp;filemanager<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;context.flags&nbsp;+=&nbsp;'d'<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;app_mplayer(context)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;app_editor(context)<br>
&nbsp;<br>
def&nbsp;app_pager(self,&nbsp;context):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;('less',&nbsp;)&nbsp;+&nbsp;tuple(context)<br>
&nbsp;<br>
def&nbsp;app_editor(self,&nbsp;context):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;('vim',&nbsp;)&nbsp;+&nbsp;tuple(context)<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="ranger.applications.html#Applications">Applications</a></dd>
<dd><a href="ranger.shared.html#FileManagerAware">ranger.shared.FileManagerAware</a></dd>
<dd><a href="ranger.shared.html#Awareness">ranger.shared.Awareness</a></dd>
<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="Applications-all"><strong>all</strong></a>(self)</dt><dd><tt>Returns&nbsp;a&nbsp;list&nbsp;with&nbsp;all&nbsp;application&nbsp;functions</tt></dd></dl>

<dl><dt><a name="Applications-app_self"><strong>app_self</strong></a>(self, context)</dt><dd><tt>Run&nbsp;the&nbsp;file&nbsp;itself</tt></dd></dl>

<dl><dt><a name="Applications-apply"><strong>apply</strong></a>(self, app, context)</dt></dl>

<dl><dt><a name="Applications-either"><strong>either</strong></a>(self, context, *args)</dt></dl>

<dl><dt><a name="Applications-get"><strong>get</strong></a>(self, app)</dt><dd><tt>Looks&nbsp;for&nbsp;an&nbsp;application,&nbsp;returns&nbsp;app_default&nbsp;if&nbsp;it&nbsp;doesn't&nbsp;exist</tt></dd></dl>

<dl><dt><a name="Applications-has"><strong>has</strong></a>(self, app)</dt><dd><tt>Returns&nbsp;whether&nbsp;an&nbsp;application&nbsp;is&nbsp;defined</tt></dd></dl>

<hr>
Data and other attributes inherited from <a href="ranger.shared.html#FileManagerAware">ranger.shared.FileManagerAware</a>:<br>
<dl><dt><strong>fm</strong> = None</dl>

<hr>
Data descriptors inherited from <a href="ranger.shared.html#Awareness">ranger.shared.Awareness</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
    
<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt><a name="-depends_on"><strong>depends_on</strong></a>(*args)</dt></dl>
 <dl><dt><a name="-tup"><strong>tup</strong></a>(*args)</dt><dd><tt>This&nbsp;helper&nbsp;function&nbsp;creates&nbsp;a&nbsp;tuple&nbsp;out&nbsp;of&nbsp;the&nbsp;arguments.<br>
&nbsp;<br>
('a',&nbsp;)&nbsp;+&nbsp;tuple(some_iterator)<br>
is&nbsp;equivalent&nbsp;to:<br>
<a href="#-tup">tup</a>('a',&nbsp;*some_iterator)</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
    
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><strong>PIPE</strong> = -1</td></tr></table>
</body></html>
timeout (/autoping) : OFF"); } else if (autoping_timeout == 1) { cons_show("Autoping timeout (/autoping) : 1 second"); } else { cons_show("Autoping timeout (/autoping) : %d seconds", autoping_timeout); } } void cons_show_connection_prefs(void) { cons_show("Connection preferences:"); cons_show(""); cons_reconnect_setting(); cons_autoping_setting(); cons_autoconnect_setting(); cons_rooms_cache_setting(); cons_alert(); } void cons_show_otr_prefs(void) { cons_show("OTR preferences:"); cons_show(""); char *policy_value = prefs_get_string(PREF_OTR_POLICY); cons_show("OTR policy (/otr policy) : %s", policy_value); prefs_free_string(policy_value); char *log_value = prefs_get_string(PREF_OTR_LOG); if (strcmp(log_value, "on") == 0) { cons_show("OTR logging (/otr log) : ON"); } else if (strcmp(log_value, "off") == 0) { cons_show("OTR logging (/otr log) : OFF"); } else { cons_show("OTR logging (/otr log) : Redacted"); } prefs_free_string(log_value); char ch = prefs_get_otr_char(); cons_show("OTR char (/otr char) : %c", ch); cons_alert(); } void cons_show_pgp_prefs(void) { cons_show("PGP preferences:"); cons_show(""); char *log_value = prefs_get_string(PREF_PGP_LOG); if (strcmp(log_value, "on") == 0) { cons_show("PGP logging (/pgp log) : ON"); } else if (strcmp(log_value, "off") == 0) { cons_show("PGP logging (/pgp log) : OFF"); } else { cons_show("PGP logging (/pgp log) : Redacted"); } prefs_free_string(log_value); char ch = prefs_get_pgp_char(); cons_show("PGP char (/pgp char) : %c", ch); cons_alert(); } void cons_show_omemo_prefs(void) { cons_show("OMEMO preferences:"); cons_show(""); char *log_value = prefs_get_string(PREF_OMEMO_LOG); if (strcmp(log_value, "on") == 0) { cons_show("OMEMO logging (/omemo log) : ON"); } else if (strcmp(log_value, "off") == 0) { cons_show("OMEMO logging (/omemo log) : OFF"); } else { cons_show("OMEMO logging (/omemo log) : Redacted"); } prefs_free_string(log_value); char ch = prefs_get_omemo_char(); cons_show("OMEMO char (/omemo char) : %c", ch); cons_alert(); } void cons_show_themes(GSList *themes) { cons_show(""); if (themes == NULL) { cons_show("No available themes."); } else { cons_show("Available themes:"); while (themes) { cons_show(themes->data); themes = g_slist_next(themes); } } cons_alert(); } void cons_show_scripts(GSList *scripts) { cons_show(""); if (scripts == NULL) { cons_show("No scripts available."); } else { cons_show("Scripts:"); while (scripts) { cons_show(scripts->data); scripts = g_slist_next(scripts); } } cons_alert(); } void cons_show_script(const char *const script, GSList *commands) { cons_show(""); if (commands == NULL) { cons_show("Script not found: %s", script); } else { cons_show("%s:", script); while (commands) { cons_show(" %s", commands->data); commands = g_slist_next(commands); } } cons_alert(); } void cons_prefs(void) { cons_show(""); cons_show_ui_prefs(); cons_show(""); cons_show_desktop_prefs(); cons_show(""); cons_show_chat_prefs(); cons_show(""); cons_show_log_prefs(); cons_show(""); cons_show_presence_prefs(); cons_show(""); cons_show_connection_prefs(); cons_show(""); cons_show_otr_prefs(); cons_show(""); cons_show_pgp_prefs(); cons_show(""); cons_show_omemo_prefs(); cons_show(""); cons_alert(); } void cons_help(void) { int pad = strlen("/help commands connection") + 3; cons_show(""); cons_show("Choose a help option:"); cons_show(""); cons_show_padded(pad, "/help commands : List all commands."); cons_show_padded(pad, "/help commands chat : List chat commands."); cons_show_padded(pad, "/help commands groupchat : List groupchat commands."); cons_show_padded(pad, "/help commands roster : List commands for manipulating your roster."); cons_show_padded(pad, "/help commands presence : List commands to change your presence."); cons_show_padded(pad, "/help commands discovery : List service discovery commands."); cons_show_padded(pad, "/help commands connection : List commands related to managing your connection."); cons_show_padded(pad, "/help commands ui : List commands for manipulating the user interface."); cons_show_padded(pad, "/help commands plugins : List plugin commands."); cons_show_padded(pad, "/help [command] : Detailed help on a specific command."); cons_show_padded(pad, "/help navigation : How to navigate around Profanity."); cons_show(""); cons_alert(); } void cons_navigation_help(void) { ProfWin *console = wins_get_console(); cons_show(""); win_println(console, THEME_HELP_HEADER, '-', "Navigation"); cons_show("Alt-1..Alt-0, F1..F10 : Choose window."); cons_show("Alt-LEFT, Alt-RIGHT : Previous/next chat window."); cons_show("PAGEUP, PAGEDOWN : Page the main window."); cons_show("Alt-PAGEUP, Alt-PAGEDOWN : Page occupants/roster panel."); cons_show(""); cons_show("/win : Focus window n, where n is the window number."); cons_show("/win : Focus window with name, where name is the recipient, room or window title."); cons_show(""); cons_show("See '/help win' for more information."); cons_alert(); } void cons_show_roster_group(const char *const group, GSList *list) { cons_show(""); if (list) { cons_show("%s:", group); } else { cons_show("No group named %s exists.", group); } _show_roster_contacts(list, FALSE); cons_alert(); } void cons_show_roster(GSList *list) { cons_show(""); cons_show("Roster: jid (nick) - subscription - groups"); _show_roster_contacts(list, TRUE); cons_alert(); } void cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity) { const char *show = string_from_resource_presence(resource->presence); char *display_str = p_contact_create_display_string(contact, resource->name); ProfWin *console = wins_get_console(); win_show_status_string(console, display_str, show, resource->status, last_activity, "++", "online"); free(display_str); } void cons_show_contact_offline(PContact contact, char *resource, char *status) { char *display_str = p_contact_create_display_string(contact, resource); ProfWin *console = wins_get_console(); win_show_status_string(console, display_str, "offline", status, NULL, "--", "offline"); free(display_str); } void cons_show_contacts(GSList *list) { ProfWin *console = wins_get_console(); GSList *curr = list; while(curr) { PContact contact = curr->data; if ((strcmp(p_contact_subscription(contact), "to") == 0) || (strcmp(p_contact_subscription(contact), "both") == 0)) { win_show_contact(console, contact); } curr = g_slist_next(curr); } cons_alert(); } void cons_alert(void) { ProfWin *current = wins_get_current(); if (current->type != WIN_CONSOLE) { status_bar_new(1, WIN_CONSOLE, "console"); } } char* cons_get_string(ProfConsoleWin *conswin) { assert(conswin != NULL); return strdup("Console"); } void _cons_theme_bar_prop(theme_item_t theme, char *prop) { ProfWin *console = wins_get_console(); GString *propstr = g_string_new(" "); g_string_append_printf(propstr, "%-24s", prop); win_print(console, THEME_TEXT, '-', "%s", propstr->str); g_string_free(propstr, TRUE); GString *valstr = g_string_new(" "); char *setting = theme_get_string(prop); g_string_append_printf(valstr, "%s ", setting); theme_free_string(setting); win_append(console, theme, "%s", valstr->str); win_appendln(console, THEME_TEXT, ""); g_string_free(valstr, TRUE); } void _cons_theme_prop(theme_item_t theme, char *prop) { ProfWin *console = wins_get_console(); GString *propstr = g_string_new(" "); g_string_append_printf(propstr, "%-24s", prop); win_print(console, THEME_TEXT, '-', "%s", propstr->str); g_string_free(propstr, TRUE); GString *valstr = g_string_new(""); char *setting = theme_get_string(prop); g_string_append_printf(valstr, "%s", setting); theme_free_string(setting); win_appendln(console, theme, "%s", valstr->str); g_string_free(valstr, TRUE); } void cons_theme_properties(void) { cons_show("Current colours:"); _cons_theme_bar_prop(THEME_TITLE_TEXT, "titlebar.text"); _cons_theme_bar_prop(THEME_TITLE_BRACKET, "titlebar.brackets"); _cons_theme_bar_prop(THEME_TITLE_UNENCRYPTED, "titlebar.unencrypted"); _cons_theme_bar_prop(THEME_TITLE_ENCRYPTED, "titlebar.encrypted"); _cons_theme_bar_prop(THEME_TITLE_UNTRUSTED, "titlebar.untrusted"); _cons_theme_bar_prop(THEME_TITLE_TRUSTED, "titlebar.trusted"); _cons_theme_bar_prop(THEME_TITLE_CHAT, "titlebar.chat"); _cons_theme_bar_prop(THEME_TITLE_ONLINE, "titlebar.online"); _cons_theme_bar_prop(THEME_TITLE_AWAY, "titlebar.away"); _cons_theme_bar_prop(THEME_TITLE_XA, "titlebar.xa"); _cons_theme_bar_prop(THEME_TITLE_DND, "titlebar.dnd"); _cons_theme_bar_prop(THEME_TITLE_OFFLINE, "titlebar.offline"); _cons_theme_bar_prop(THEME_STATUS_TEXT, "statusbar.text"); _cons_theme_bar_prop(THEME_STATUS_BRACKET, "statusbar.brackets"); _cons_theme_bar_prop(THEME_STATUS_ACTIVE, "statusbar.active"); _cons_theme_bar_prop(THEME_STATUS_NEW, "statusbar.new"); _cons_theme_bar_prop(THEME_STATUS_TIME, "statusbar.time"); _cons_theme_prop(THEME_TIME, "main.time"); _cons_theme_prop(THEME_TEXT, "main.text"); _cons_theme_prop(THEME_SPLASH, "main.splash"); _cons_theme_prop(THEME_ERROR, "error"); _cons_theme_prop(THEME_OTR_STARTED_TRUSTED, "otr.started.trusted"); _cons_theme_prop(THEME_OTR_STARTED_UNTRUSTED, "otr.started.untrusted"); _cons_theme_prop(THEME_OTR_ENDED, "otr.ended"); _cons_theme_prop(THEME_OTR_TRUSTED, "otr.trusted"); _cons_theme_prop(THEME_OTR_UNTRUSTED, "otr.untrusted"); _cons_theme_prop(THEME_ME, "me"); _cons_theme_prop(THEME_TEXT_ME, "main.text.me"); _cons_theme_prop(THEME_THEM, "them"); _cons_theme_prop(THEME_TEXT_THEM, "main.text.them"); _cons_theme_prop(THEME_CHAT, "chat"); _cons_theme_prop(THEME_ONLINE, "online"); _cons_theme_prop(THEME_AWAY, "away"); _cons_theme_prop(THEME_XA, "xa"); _cons_theme_prop(THEME_DND, "dnd"); _cons_theme_prop(THEME_OFFLINE, "offline"); _cons_theme_prop(THEME_SUBSCRIBED, "subscribed"); _cons_theme_prop(THEME_UNSUBSCRIBED, "unsubscribed"); _cons_theme_prop(THEME_INCOMING, "incoming"); _cons_theme_prop(THEME_MENTION, "mention"); _cons_theme_prop(THEME_TRIGGER, "trigger"); _cons_theme_prop(THEME_TYPING, "typing"); _cons_theme_prop(THEME_GONE, "gone"); _cons_theme_prop(THEME_ROOMINFO, "roominfo"); _cons_theme_prop(THEME_ROOMMENTION, "roommention"); _cons_theme_prop(THEME_ROOMMENTION_TERM, "roommention.term"); _cons_theme_prop(THEME_ROOMTRIGGER, "roomtrigger"); _cons_theme_prop(THEME_ROOMTRIGGER_TERM, "roomtrigger.term"); _cons_theme_prop(THEME_ROSTER_HEADER, "roster.header"); _cons_theme_prop(THEME_ROSTER_CHAT, "roster.chat"); _cons_theme_prop(THEME_ROSTER_ONLINE, "roster.online"); _cons_theme_prop(THEME_ROSTER_AWAY, "roster.away"); _cons_theme_prop(THEME_ROSTER_XA, "roster.xa"); _cons_theme_prop(THEME_ROSTER_DND, "roster.dnd"); _cons_theme_prop(THEME_ROSTER_OFFLINE, "roster.offline"); _cons_theme_prop(THEME_ROSTER_CHAT_ACTIVE, "roster.chat.active"); _cons_theme_prop(THEME_ROSTER_ONLINE_ACTIVE, "roster.online.active"); _cons_theme_prop(THEME_ROSTER_AWAY_ACTIVE, "roster.away.active"); _cons_theme_prop(THEME_ROSTER_XA_ACTIVE, "roster.xa.active"); _cons_theme_prop(THEME_ROSTER_DND_ACTIVE, "roster.dnd.active"); _cons_theme_prop(THEME_ROSTER_OFFLINE_ACTIVE, "roster.offline.active"); _cons_theme_prop(THEME_ROSTER_CHAT_UNREAD, "roster.chat.unread"); _cons_theme_prop(THEME_ROSTER_ONLINE_UNREAD, "roster.online.unread"); _cons_theme_prop(THEME_ROSTER_AWAY_UNREAD, "roster.away.unread"); _cons_theme_prop(THEME_ROSTER_XA_UNREAD, "roster.xa.unread"); _cons_theme_prop(THEME_ROSTER_DND_UNREAD, "roster.dnd.unread"); _cons_theme_prop(THEME_ROSTER_OFFLINE_UNREAD, "roster.offline.unread"); _cons_theme_prop(THEME_ROSTER_ROOM, "roster.room"); _cons_theme_prop(THEME_ROSTER_ROOM_UNREAD, "roster.room.unread"); _cons_theme_prop(THEME_ROSTER_ROOM_TRIGGER, "roster.room.trigger"); _cons_theme_prop(THEME_ROSTER_ROOM_MENTION, "roster.room.mention"); _cons_theme_prop(THEME_OCCUPANTS_HEADER, "occupants.header"); _cons_theme_prop(THEME_RECEIPT_SENT, "receipt.sent"); _cons_theme_prop(THEME_INPUT_TEXT, "input.text"); cons_show(""); } void cons_theme_colours(void) { /* * { "default", -1 }, { "white", COLOR_WHITE }, { "green", COLOR_GREEN }, { "red", COLOR_RED }, { "yellow", COLOR_YELLOW }, { "blue", COLOR_BLUE }, { "cyan", COLOR_CYAN }, { "black", COLOR_BLACK }, { "magenta", COLOR_MAGENTA }, */ ProfWin *console = wins_get_console(); cons_show("Available colours:"); win_print(console, THEME_WHITE, '-', " white "); win_appendln(console, THEME_WHITE_BOLD, " bold_white"); win_print(console, THEME_GREEN, '-', " green "); win_appendln(console, THEME_GREEN_BOLD, " bold_green"); win_print(console, THEME_RED, '-', " red "); win_appendln(console, THEME_RED_BOLD, " bold_red"); win_print(console, THEME_YELLOW, '-', " yellow "); win_appendln(console, THEME_YELLOW_BOLD, " bold_yellow"); win_print(console, THEME_BLUE, '-', " blue "); win_appendln(console, THEME_BLUE_BOLD, " bold_blue"); win_print(console, THEME_CYAN, '-', " cyan "); win_appendln(console, THEME_CYAN_BOLD, " bold_cyan"); win_print(console, THEME_MAGENTA, '-', " magenta "); win_appendln(console, THEME_MAGENTA_BOLD, " bold_magenta"); win_print(console, THEME_BLACK, '-', " black "); win_appendln(console, THEME_BLACK_BOLD, " bold_black"); cons_show(""); } static void _cons_splash_logo(void) { ProfWin *console = wins_get_console(); win_println(console, THEME_DEFAULT, '-', "Welcome to"); win_println(console, THEME_SPLASH, '-', " ___ _ "); win_println(console, THEME_SPLASH, '-', " / __) (_)_ "); win_println(console, THEME_SPLASH, '-', " ____ ___ ___ | |__ ____ ____ _| |_ _ _ "); win_println(console, THEME_SPLASH, '-', "| _ \\ / __) _ \\| __) _ | _ \\| | _) | | |"); win_println(console, THEME_SPLASH, '-', "| | ) | | | (_) | | | ( | | | | | | |_| |_| |"); win_println(console, THEME_SPLASH, '-', "| ||_/|_| \\___/|_| \\_||_|_| |_|_|\\___)__ |"); win_println(console, THEME_SPLASH, '-', "|_| (____/ "); win_println(console, THEME_SPLASH, '-', ""); if (strcmp(PACKAGE_STATUS, "development") == 0) { #ifdef HAVE_GIT_VERSION win_println(console, THEME_DEFAULT, '-', "Version %sdev.%s.%s", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION); #else win_println(console, THEME_DEFAULT, "Version %sdev", PACKAGE_VERSION); #endif } else { win_println(console, THEME_DEFAULT, '-', "Version %s", PACKAGE_VERSION); } } void _show_roster_contacts(GSList *list, gboolean show_groups) { ProfWin *console = wins_get_console(); GSList *curr = list; while(curr) { PContact contact = curr->data; GString *title = g_string_new(" "); title = g_string_append(title, p_contact_barejid(contact)); if (p_contact_name(contact)) { title = g_string_append(title, " ("); title = g_string_append(title, p_contact_name(contact)); title = g_string_append(title, ")"); } const char *presence = p_contact_presence(contact); theme_item_t presence_colour = THEME_TEXT; if (p_contact_subscribed(contact)) { presence_colour = theme_main_presence_attrs(presence); } else { presence_colour = theme_main_presence_attrs("offline"); } win_print(console, presence_colour, '-', "%s", title->str); g_string_free(title, TRUE); win_append(console, THEME_DEFAULT, " - "); GString *sub = g_string_new(""); sub = g_string_append(sub, p_contact_subscription(contact)); if (p_contact_pending_out(contact)) { sub = g_string_append(sub, ", request sent"); } if (presence_sub_request_exists(p_contact_barejid(contact))) { sub = g_string_append(sub, ", request received"); } if (p_contact_subscribed(contact)) { presence_colour = THEME_SUBSCRIBED; } else { presence_colour = THEME_UNSUBSCRIBED; } if (show_groups) { win_append(console, presence_colour, "%s", sub->str); } else { win_appendln(console, presence_colour, "%s", sub->str); } g_string_free(sub, TRUE); if (show_groups) { GSList *groups = p_contact_groups(contact); if (groups) { GString *groups_str = g_string_new(" - "); while (groups) { g_string_append(groups_str, groups->data); if (g_slist_next(groups)) { g_string_append(groups_str, ", "); } groups = g_slist_next(groups); } win_appendln(console, THEME_DEFAULT, "%s", groups_str->str); g_string_free(groups_str, TRUE); } else { win_appendln(console, THEME_DEFAULT, " "); } } curr = g_slist_next(curr); } }