1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Inclued stdlib

This commit is contained in:
U-DIR\kieran.thandi 2015-11-30 22:34:24 +00:00
parent 9888fb9f64
commit b818dddb32

View File

@ -1,347 +1,348 @@
/* /*
* mucconfwin.c * mucconfwin.c
* *
* Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com> * Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
* *
* This file is part of Profanity. * This file is part of Profanity.
* *
* Profanity is free software: you can redistribute it and/or modify * Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Profanity is distributed in the hope that it will be useful, * Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <http://www.gnu.org/licenses/>. * along with Profanity. If not, see <http://www.gnu.org/licenses/>.
* *
* In addition, as a special exception, the copyright holders give permission to * 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 * link the code of portions of this program with the OpenSSL library under
* certain conditions as described in each individual source file, and * certain conditions as described in each individual source file, and
* distribute linked combinations including the two. * distribute linked combinations including the two.
* *
* You must obey the GNU General Public License in all respects for all of the * 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 * 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 * 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 * 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 * statement from your version. If you delete this exception statement from all
* source files in the program, then also delete it here. * source files in the program, then also delete it here.
* *
*/ */
#include <assert.h> #include <assert.h>
#include <stdlib.h>
#include "ui/ui.h"
#include "ui/window.h" #include "ui/ui.h"
#include "ui/win_types.h" #include "ui/window.h"
#include "window_list.h" #include "ui/win_types.h"
#include "window_list.h"
static void _mucconfwin_form_field(ProfWin *window, char *tag, FormField *field);
static void _mucconfwin_form_field(ProfWin *window, char *tag, FormField *field);
void
mucconfwin_show_form(ProfMucConfWin *confwin) void
{ mucconfwin_show_form(ProfMucConfWin *confwin)
ProfWin *window = (ProfWin*) confwin; {
if (confwin->form->title) { ProfWin *window = (ProfWin*) confwin;
win_print(window, '-', 0, NULL, NO_EOL, 0, "", "Form title: "); if (confwin->form->title) {
win_print(window, '-', 0, NULL, NO_DATE, 0, "", confwin->form->title); win_print(window, '-', 0, NULL, NO_EOL, 0, "", "Form title: ");
} else { win_print(window, '-', 0, NULL, NO_DATE, 0, "", confwin->form->title);
win_vprint(window, '-', 0, NULL, 0, 0, "", "Configuration for room %s.", confwin->roomjid); } else {
} win_vprint(window, '-', 0, NULL, 0, 0, "", "Configuration for room %s.", confwin->roomjid);
win_print(window, '-', 0, NULL, 0, 0, "", ""); }
win_print(window, '-', 0, NULL, 0, 0, "", "");
mucconfwin_form_help(confwin);
mucconfwin_form_help(confwin);
GSList *fields = confwin->form->fields;
GSList *curr_field = fields; GSList *fields = confwin->form->fields;
while (curr_field) { GSList *curr_field = fields;
FormField *field = curr_field->data; while (curr_field) {
FormField *field = curr_field->data;
if ((g_strcmp0(field->type, "fixed") == 0) && field->values) {
if (field->values) { if ((g_strcmp0(field->type, "fixed") == 0) && field->values) {
char *value = field->values->data; if (field->values) {
win_print(window, '-', 0, NULL, 0, 0, "", value); char *value = field->values->data;
} win_print(window, '-', 0, NULL, 0, 0, "", value);
} else if (g_strcmp0(field->type, "hidden") != 0 && field->var) { }
char *tag = g_hash_table_lookup(confwin->form->var_to_tag, field->var); } else if (g_strcmp0(field->type, "hidden") != 0 && field->var) {
_mucconfwin_form_field(window, tag, field); char *tag = g_hash_table_lookup(confwin->form->var_to_tag, field->var);
} _mucconfwin_form_field(window, tag, field);
}
curr_field = g_slist_next(curr_field);
} curr_field = g_slist_next(curr_field);
} }
}
void
mucconfwin_show_form_field(ProfMucConfWin *confwin, DataForm *form, char *tag) void
{ mucconfwin_show_form_field(ProfMucConfWin *confwin, DataForm *form, char *tag)
assert(confwin != NULL); {
assert(confwin != NULL);
FormField *field = form_get_field_by_tag(form, tag);
ProfWin *window = (ProfWin*)confwin; FormField *field = form_get_field_by_tag(form, tag);
_mucconfwin_form_field(window, tag, field); ProfWin *window = (ProfWin*)confwin;
win_println(window, 0, ""); _mucconfwin_form_field(window, tag, field);
} win_println(window, 0, "");
}
void
mucconfwin_handle_configuration(ProfMucConfWin *confwin, DataForm *form) void
{ mucconfwin_handle_configuration(ProfMucConfWin *confwin, DataForm *form)
assert(confwin != NULL); {
assert(confwin != NULL);
ProfWin *window = (ProfWin*)confwin;
ui_focus_win(window); ProfWin *window = (ProfWin*)confwin;
ui_focus_win(window);
mucconfwin_show_form(confwin);
mucconfwin_show_form(confwin);
win_print(window, '-', 0, NULL, 0, 0, "", "");
win_print(window, '-', 0, NULL, 0, 0, "", "Use '/form submit' to save changes."); win_print(window, '-', 0, NULL, 0, 0, "", "");
win_print(window, '-', 0, NULL, 0, 0, "", "Use '/form cancel' to cancel changes."); win_print(window, '-', 0, NULL, 0, 0, "", "Use '/form submit' to save changes.");
win_print(window, '-', 0, NULL, 0, 0, "", "See '/form help' for more information."); win_print(window, '-', 0, NULL, 0, 0, "", "Use '/form cancel' to cancel changes.");
win_print(window, '-', 0, NULL, 0, 0, "", ""); win_print(window, '-', 0, NULL, 0, 0, "", "See '/form help' for more information.");
} win_print(window, '-', 0, NULL, 0, 0, "", "");
}
void
mucconfwin_field_help(ProfMucConfWin *confwin, char *tag) void
{ mucconfwin_field_help(ProfMucConfWin *confwin, char *tag)
assert(confwin != NULL); {
assert(confwin != NULL);
ProfWin *window = (ProfWin*) confwin;
FormField *field = form_get_field_by_tag(confwin->form, tag); ProfWin *window = (ProfWin*) confwin;
if (field) { FormField *field = form_get_field_by_tag(confwin->form, tag);
win_print(window, '-', 0, NULL, NO_EOL, 0, "", field->label); if (field) {
if (field->required) { win_print(window, '-', 0, NULL, NO_EOL, 0, "", field->label);
win_print(window, '-', 0, NULL, NO_DATE, 0, "", " (Required):"); if (field->required) {
} else { win_print(window, '-', 0, NULL, NO_DATE, 0, "", " (Required):");
win_print(window, '-', 0, NULL, NO_DATE, 0, "", ":"); } else {
} win_print(window, '-', 0, NULL, NO_DATE, 0, "", ":");
if (field->description) { }
win_vprint(window, '-', 0, NULL, 0, 0, "", " Description : %s", field->description); if (field->description) {
} win_vprint(window, '-', 0, NULL, 0, 0, "", " Description : %s", field->description);
win_vprint(window, '-', 0, NULL, 0, 0, "", " Type : %s", field->type); }
win_vprint(window, '-', 0, NULL, 0, 0, "", " Type : %s", field->type);
int num_values = 0;
GSList *curr_option = NULL; int num_values = 0;
FormOption *option = NULL; GSList *curr_option = NULL;
FormOption *option = NULL;
switch (field->type_t) {
case FIELD_TEXT_SINGLE: switch (field->type_t) {
case FIELD_TEXT_PRIVATE: case FIELD_TEXT_SINGLE:
win_vprint(window, '-', 0, NULL, 0, 0, "", " Set : /%s <value>", tag); case FIELD_TEXT_PRIVATE:
win_print(window, '-', 0, NULL, 0, 0, "", " Where : <value> is any text"); win_vprint(window, '-', 0, NULL, 0, 0, "", " Set : /%s <value>", tag);
break; win_print(window, '-', 0, NULL, 0, 0, "", " Where : <value> is any text");
case FIELD_TEXT_MULTI: break;
num_values = form_get_value_count(confwin->form, tag); case FIELD_TEXT_MULTI:
win_vprint(window, '-', 0, NULL, 0, 0, "", " Add : /%s add <value>", tag); num_values = form_get_value_count(confwin->form, tag);
win_print(window, '-', 0, NULL, 0, 0, "", " Where : <value> is any text"); win_vprint(window, '-', 0, NULL, 0, 0, "", " Add : /%s add <value>", tag);
if (num_values > 0) { win_print(window, '-', 0, NULL, 0, 0, "", " Where : <value> is any text");
win_vprint(window, '-', 0, NULL, 0, 0, "", " Remove : /%s remove <value>", tag); if (num_values > 0) {
win_vprint(window, '-', 0, NULL, 0, 0, "", " Where : <value> between 'val1' and 'val%d'", num_values); win_vprint(window, '-', 0, NULL, 0, 0, "", " Remove : /%s remove <value>", tag);
} win_vprint(window, '-', 0, NULL, 0, 0, "", " Where : <value> between 'val1' and 'val%d'", num_values);
break; }
case FIELD_BOOLEAN: break;
win_vprint(window, '-', 0, NULL, 0, 0, "", " Set : /%s <value>", tag); case FIELD_BOOLEAN:
win_print(window, '-', 0, NULL, 0, 0, "", " Where : <value> is either 'on' or 'off'"); win_vprint(window, '-', 0, NULL, 0, 0, "", " Set : /%s <value>", tag);
break; win_print(window, '-', 0, NULL, 0, 0, "", " Where : <value> is either 'on' or 'off'");
case FIELD_LIST_SINGLE: break;
win_vprint(window, '-', 0, NULL, 0, 0, "", " Set : /%s <value>", tag); case FIELD_LIST_SINGLE:
win_print(window, '-', 0, NULL, 0, 0, "", " Where : <value> is one of"); win_vprint(window, '-', 0, NULL, 0, 0, "", " Set : /%s <value>", tag);
curr_option = field->options; win_print(window, '-', 0, NULL, 0, 0, "", " Where : <value> is one of");
while (curr_option) { curr_option = field->options;
option = curr_option->data; while (curr_option) {
win_vprint(window, '-', 0, NULL, 0, 0, "", " %s", option->value); option = curr_option->data;
curr_option = g_slist_next(curr_option); win_vprint(window, '-', 0, NULL, 0, 0, "", " %s", option->value);
} curr_option = g_slist_next(curr_option);
break; }
case FIELD_LIST_MULTI: break;
win_vprint(window, '-', 0, NULL, 0, 0, "", " Add : /%s add <value>", tag); case FIELD_LIST_MULTI:
win_vprint(window, '-', 0, NULL, 0, 0, "", " Remove : /%s remove <value>", tag); win_vprint(window, '-', 0, NULL, 0, 0, "", " Add : /%s add <value>", tag);
win_print(window, '-', 0, NULL, 0, 0, "", " Where : <value> is one of"); win_vprint(window, '-', 0, NULL, 0, 0, "", " Remove : /%s remove <value>", tag);
curr_option = field->options; win_print(window, '-', 0, NULL, 0, 0, "", " Where : <value> is one of");
while (curr_option) { curr_option = field->options;
option = curr_option->data; while (curr_option) {
win_vprint(window, '-', 0, NULL, 0, 0, "", " %s", option->value); option = curr_option->data;
curr_option = g_slist_next(curr_option); win_vprint(window, '-', 0, NULL, 0, 0, "", " %s", option->value);
} curr_option = g_slist_next(curr_option);
break; }
case FIELD_JID_SINGLE: break;
win_vprint(window, '-', 0, NULL, 0, 0, "", " Set : /%s <value>", tag); case FIELD_JID_SINGLE:
win_print(window, '-', 0, NULL, 0, 0, "", " Where : <value> is a valid Jabber ID"); win_vprint(window, '-', 0, NULL, 0, 0, "", " Set : /%s <value>", tag);
break; win_print(window, '-', 0, NULL, 0, 0, "", " Where : <value> is a valid Jabber ID");
case FIELD_JID_MULTI: break;
win_vprint(window, '-', 0, NULL, 0, 0, "", " Add : /%s add <value>", tag); case FIELD_JID_MULTI:
win_vprint(window, '-', 0, NULL, 0, 0, "", " Remove : /%s remove <value>", tag); win_vprint(window, '-', 0, NULL, 0, 0, "", " Add : /%s add <value>", tag);
win_print(window, '-', 0, NULL, 0, 0, "", " Where : <value> is a valid Jabber ID"); win_vprint(window, '-', 0, NULL, 0, 0, "", " Remove : /%s remove <value>", tag);
break; win_print(window, '-', 0, NULL, 0, 0, "", " Where : <value> is a valid Jabber ID");
case FIELD_FIXED: break;
case FIELD_UNKNOWN: case FIELD_FIXED:
case FIELD_HIDDEN: case FIELD_UNKNOWN:
default: case FIELD_HIDDEN:
break; default:
} break;
} else { }
win_vprint(window, '-', 0, NULL, 0, 0, "", "No such field %s", tag); } else {
} win_vprint(window, '-', 0, NULL, 0, 0, "", "No such field %s", tag);
} }
}
void
mucconfwin_form_help(ProfMucConfWin *confwin) void
{ mucconfwin_form_help(ProfMucConfWin *confwin)
assert(confwin != NULL); {
assert(confwin != NULL);
if (confwin->form->instructions) {
ProfWin *window = (ProfWin*) confwin; if (confwin->form->instructions) {
win_print(window, '-', 0, NULL, 0, 0, "", "Supplied instructions:"); ProfWin *window = (ProfWin*) confwin;
win_print(window, '-', 0, NULL, 0, 0, "", confwin->form->instructions); win_print(window, '-', 0, NULL, 0, 0, "", "Supplied instructions:");
win_print(window, '-', 0, NULL, 0, 0, "", ""); win_print(window, '-', 0, NULL, 0, 0, "", confwin->form->instructions);
} win_print(window, '-', 0, NULL, 0, 0, "", "");
} }
}
static void
_mucconfwin_form_field(ProfWin *window, char *tag, FormField *field) static void
{ _mucconfwin_form_field(ProfWin *window, char *tag, FormField *field)
win_vprint(window, '-', 0, NULL, NO_EOL, THEME_AWAY, "", "[%s] ", tag); {
win_vprint(window, '-', 0, NULL, NO_EOL | NO_DATE, 0, "", "%s", field->label); win_vprint(window, '-', 0, NULL, NO_EOL, THEME_AWAY, "", "[%s] ", tag);
if (field->required) { win_vprint(window, '-', 0, NULL, NO_EOL | NO_DATE, 0, "", "%s", field->label);
win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " (required): "); if (field->required) {
} else { win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " (required): ");
win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ": "); } else {
} win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ": ");
}
GSList *values = field->values;
GSList *curr_value = values; GSList *values = field->values;
GSList *curr_value = values;
switch (field->type_t) {
case FIELD_HIDDEN: switch (field->type_t) {
break; case FIELD_HIDDEN:
case FIELD_TEXT_SINGLE: break;
if (curr_value) { case FIELD_TEXT_SINGLE:
char *value = curr_value->data; if (curr_value) {
if (value) { char *value = curr_value->data;
if (g_strcmp0(field->var, "muc#roomconfig_roomsecret") == 0) { if (value) {
win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", "[hidden]"); if (g_strcmp0(field->var, "muc#roomconfig_roomsecret") == 0) {
} else { win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", "[hidden]");
win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", value); } else {
} win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", value);
} }
} }
win_newline(window); }
break; win_newline(window);
case FIELD_TEXT_PRIVATE: break;
if (curr_value) { case FIELD_TEXT_PRIVATE:
char *value = curr_value->data; if (curr_value) {
if (value) { char *value = curr_value->data;
win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", "[hidden]"); if (value) {
} win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", "[hidden]");
} }
win_newline(window); }
break; win_newline(window);
case FIELD_TEXT_MULTI: break;
win_newline(window); case FIELD_TEXT_MULTI:
int index = 1; win_newline(window);
while (curr_value) { int index = 1;
char *value = curr_value->data; while (curr_value) {
GString *val_tag = g_string_new(""); char *value = curr_value->data;
g_string_printf(val_tag, "val%d", index++); GString *val_tag = g_string_new("");
win_vprint(window, '-', 0, NULL, 0, THEME_ONLINE, "", " [%s] %s", val_tag->str, value); g_string_printf(val_tag, "val%d", index++);
g_string_free(val_tag, TRUE); win_vprint(window, '-', 0, NULL, 0, THEME_ONLINE, "", " [%s] %s", val_tag->str, value);
curr_value = g_slist_next(curr_value); g_string_free(val_tag, TRUE);
} curr_value = g_slist_next(curr_value);
break; }
case FIELD_BOOLEAN: break;
if (curr_value == NULL) { case FIELD_BOOLEAN:
win_print(window, '-', 0, NULL, NO_DATE, THEME_OFFLINE, "", "FALSE"); if (curr_value == NULL) {
} else { win_print(window, '-', 0, NULL, NO_DATE, THEME_OFFLINE, "", "FALSE");
char *value = curr_value->data; } else {
if (value == NULL) { char *value = curr_value->data;
win_print(window, '-', 0, NULL, NO_DATE, THEME_OFFLINE, "", "FALSE"); if (value == NULL) {
} else { win_print(window, '-', 0, NULL, NO_DATE, THEME_OFFLINE, "", "FALSE");
if (g_strcmp0(value, "0") == 0) { } else {
win_print(window, '-', 0, NULL, NO_DATE, THEME_OFFLINE, "", "FALSE"); if (g_strcmp0(value, "0") == 0) {
} else { win_print(window, '-', 0, NULL, NO_DATE, THEME_OFFLINE, "", "FALSE");
win_print(window, '-', 0, NULL, NO_DATE, THEME_ONLINE, "", "TRUE"); } else {
} win_print(window, '-', 0, NULL, NO_DATE, THEME_ONLINE, "", "TRUE");
} }
} }
break; }
case FIELD_LIST_SINGLE: break;
if (curr_value) { case FIELD_LIST_SINGLE:
win_newline(window); if (curr_value) {
char *value = curr_value->data; win_newline(window);
GSList *options = field->options; char *value = curr_value->data;
GSList *curr_option = options; GSList *options = field->options;
while (curr_option) { GSList *curr_option = options;
FormOption *option = curr_option->data; while (curr_option) {
if (g_strcmp0(option->value, value) == 0) { FormOption *option = curr_option->data;
win_vprint(window, '-', 0, NULL, 0, THEME_ONLINE, "", " [%s] %s", option->value, option->label); if (g_strcmp0(option->value, value) == 0) {
} else { win_vprint(window, '-', 0, NULL, 0, THEME_ONLINE, "", " [%s] %s", option->value, option->label);
win_vprint(window, '-', 0, NULL, 0, THEME_OFFLINE, "", " [%s] %s", option->value, option->label); } else {
} win_vprint(window, '-', 0, NULL, 0, THEME_OFFLINE, "", " [%s] %s", option->value, option->label);
curr_option = g_slist_next(curr_option); }
} curr_option = g_slist_next(curr_option);
} }
break; }
case FIELD_LIST_MULTI: break;
if (curr_value) { case FIELD_LIST_MULTI:
win_newline(window); if (curr_value) {
GSList *options = field->options; win_newline(window);
GSList *curr_option = options; GSList *options = field->options;
while (curr_option) { GSList *curr_option = options;
FormOption *option = curr_option->data; while (curr_option) {
if (g_slist_find_custom(curr_value, option->value, (GCompareFunc)g_strcmp0)) { FormOption *option = curr_option->data;
win_vprint(window, '-', 0, NULL, 0, THEME_ONLINE, "", " [%s] %s", option->value, option->label); if (g_slist_find_custom(curr_value, option->value, (GCompareFunc)g_strcmp0)) {
} else { win_vprint(window, '-', 0, NULL, 0, THEME_ONLINE, "", " [%s] %s", option->value, option->label);
win_vprint(window, '-', 0, NULL, 0, THEME_OFFLINE, "", " [%s] %s", option->value, option->label); } else {
} win_vprint(window, '-', 0, NULL, 0, THEME_OFFLINE, "", " [%s] %s", option->value, option->label);
curr_option = g_slist_next(curr_option); }
} curr_option = g_slist_next(curr_option);
} }
break; }
case FIELD_JID_SINGLE: break;
if (curr_value) { case FIELD_JID_SINGLE:
char *value = curr_value->data; if (curr_value) {
if (value) { char *value = curr_value->data;
win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", value); if (value) {
} win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", value);
} }
win_newline(window); }
break; win_newline(window);
case FIELD_JID_MULTI: break;
win_newline(window); case FIELD_JID_MULTI:
while (curr_value) { win_newline(window);
char *value = curr_value->data; while (curr_value) {
win_vprint(window, '-', 0, NULL, 0, THEME_ONLINE, "", " %s", value); char *value = curr_value->data;
curr_value = g_slist_next(curr_value); win_vprint(window, '-', 0, NULL, 0, THEME_ONLINE, "", " %s", value);
} curr_value = g_slist_next(curr_value);
break; }
case FIELD_FIXED: break;
if (curr_value) { case FIELD_FIXED:
char *value = curr_value->data; if (curr_value) {
if (value) { char *value = curr_value->data;
win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", value); if (value) {
} win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", value);
} }
win_newline(window); }
break; win_newline(window);
default: break;
break; default:
} break;
} }
}
char*
mucconfwin_get_string(ProfMucConfWin *confwin) char*
{ mucconfwin_get_string(ProfMucConfWin *confwin)
assert(confwin != NULL); {
assert(confwin != NULL);
GString *res = g_string_new("");
GString *res = g_string_new("");
char *title = win_get_title((ProfWin*)confwin);
g_string_append(res, title); char *title = win_get_title((ProfWin*)confwin);
free(title); g_string_append(res, title);
free(title);
char *resstr = res->str;
g_string_free(res, FALSE); char *resstr = res->str;
g_string_free(res, FALSE);
return resstr;
} return resstr;
}