1 /*
2  * win_types.h
3  * vim: expandtab:ts=4:sts=4:sw=4
4  *
5  * Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
6  *
7  * This file is part of Profanity.
8  *
9  * Profanity is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * Profanity is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with Profanity.  If not, see <https://www.gnu.org/licenses/>.
21  *
22  * In addition, as a special exception, the copyright holders give permission to
23  * link the code of portions of this program with the OpenSSL library under
24  * certain conditions as described in each individual source file, and
25  * distribute linked combinations including the two.
26  *
27  * You must obey the GNU General Public License in all respects for all of the
28  * code used other than OpenSSL. If you modify file(s) with this exception, you
29  * may extend this exception to your version of the file(s), but you are not
30  * obligated to do so. If you do not wish to do so, delete this exception
31  * statement from your version. If you delete this exception statement from all
32  * source files in the program, then also delete it here.
33  *
34  */
35 
36 #ifndef UI_WIN_TYPES_H
37 #define UI_WIN_TYPES_H
38 
39 #include "config.h"
40 
41 #include <wchar.h>
42 #include <glib.h>
43 
44 #ifdef HAVE_NCURSESW_NCURSES_H
45 #include <ncursesw/ncurses.h>
46 #elif HAVE_NCURSES_H
47 #include <ncurses.h>
48 #elif HAVE_CURSES_H
49 #include <curses.h>
50 #endif
51 
52 #include "tools/autocomplete.h"
53 #include "ui/buffer.h"
54 #include "xmpp/chat_state.h"
55 
56 #define LAYOUT_SPLIT_MEMCHECK   12345671
57 #define PROFCHATWIN_MEMCHECK    22374522
58 #define PROFMUCWIN_MEMCHECK     52345276
59 #define PROFPRIVATEWIN_MEMCHECK 77437483
60 #define PROFCONFWIN_MEMCHECK    64334685
61 #define PROFXMLWIN_MEMCHECK     87333463
62 #define PROFPLUGINWIN_MEMCHECK  43434777
63 
64 typedef enum {
65     FIELD_HIDDEN,
66     FIELD_TEXT_SINGLE,
67     FIELD_TEXT_PRIVATE,
68     FIELD_TEXT_MULTI,
69     FIELD_BOOLEAN,
70     FIELD_LIST_SINGLE,
71     FIELD_LIST_MULTI,
72     FIELD_JID_SINGLE,
73     FIELD_JID_MULTI,
74     FIELD_FIXED,
75     FIELD_UNKNOWN
76 } form_field_type_t;
77 
78 typedef struct form_option_t
79 {
80     char* label;
81     char* value;
82 } FormOption;
83 
84 typedef struct form_field_t
85 {
86     char* label;
87     char* type;
88     form_field_type_t type_t;
89     char* var;
90     char* description;
91     gboolean required;
92     GSList* values;
93     GSList* options;
94     Autocomplete value_ac;
95 } FormField;
96 
97 typedef struct data_form_t
98 {
99     char* type;
100     char* title;
101     char* instructions;
102     GSList* fields;
103     GHashTable* var_to_tag;
104     GHashTable* tag_to_var;
105     Autocomplete tag_ac;
106     gboolean modified;
107 } DataForm;
108 
109 typedef enum {
110     LAYOUT_SIMPLE,
111     LAYOUT_SPLIT
112 } layout_type_t;
113 
114 typedef struct prof_layout_t
115 {
116     layout_type_t type;
117     WINDOW* win;
118     ProfBuff buffer;
119     int y_pos;
120     int paged;
121 } ProfLayout;
122 
123 typedef struct prof_layout_simple_t
124 {
125     ProfLayout base;
126 } ProfLayoutSimple;
127 
128 typedef struct prof_layout_split_t
129 {
130     ProfLayout base;
131     WINDOW* subwin;
132     int sub_y_pos;
133     unsigned long memcheck;
134 } ProfLayoutSplit;
135 
136 typedef enum {
137     WIN_CONSOLE,
138     WIN_CHAT,
139     WIN_MUC,
140     WIN_CONFIG,
141     WIN_PRIVATE,
142     WIN_XML,
143     WIN_PLUGIN
144 } win_type_t;
145 
146 typedef struct prof_win_t
147 {
148     win_type_t type;
149     ProfLayout* layout;
150     Autocomplete urls_ac;
151 } ProfWin;
152 
153 typedef struct prof_console_win_t
154 {
155     ProfWin window;
156 } ProfConsoleWin;
157 
158 typedef struct prof_chat_win_t
159 {
160     ProfWin window;
161     char* barejid;
162     int unread;
163     ChatState* state;
164     gboolean is_otr;
165     gboolean otr_is_trusted;
166     gboolean pgp_send;
167     gboolean pgp_recv;
168     gboolean is_omemo;
169     gboolean is_ox; // XEP-0373: OpenPGP for XMPP
170     char* resource_override;
171     gboolean history_shown;
172     unsigned long memcheck;
173     char* enctext;
174     char* incoming_char;
175     char* outgoing_char;
176     // For LMC
177     char* last_message;
178     char* last_msg_id;
179     gboolean has_attention;
180 } ProfChatWin;
181 
182 typedef struct prof_muc_win_t
183 {
184     ProfWin window;
185     char* roomjid;
186     char* room_name;
187     int unread;
188     gboolean unread_mentions;
189     gboolean unread_triggers;
190     gboolean showjid;
191     gboolean showoffline;
192     gboolean is_omemo;
193     unsigned long memcheck;
194     char* enctext;
195     char* message_char;
196     GDateTime* last_msg_timestamp;
197     // For LMC
198     char* last_message;
199     char* last_msg_id;
200     gboolean has_attention;
201 } ProfMucWin;
202 
203 typedef struct prof_conf_win_t ProfConfWin;
204 typedef void (*ProfConfWinCallback)(ProfConfWin*);
205 
206 struct prof_conf_win_t
207 {
208     ProfWin window;
209     char* roomjid;
210     DataForm* form;
211     unsigned long memcheck;
212     ProfConfWinCallback submit;
213     ProfConfWinCallback cancel;
214     const void* userdata;
215 };
216 
217 typedef struct prof_private_win_t
218 {
219     ProfWin window;
220     char* fulljid;
221     int unread;
222     unsigned long memcheck;
223     gboolean occupant_offline;
224     gboolean room_left;
225 } ProfPrivateWin;
226 
227 typedef struct prof_xml_win_t
228 {
229     ProfWin window;
230     unsigned long memcheck;
231 } ProfXMLWin;
232 
233 typedef struct prof_plugin_win_t
234 {
235     ProfWin window;
236     char* tag;
237     char* plugin_name;
238     unsigned long memcheck;
239 } ProfPluginWin;
240 
241 #endif
242