Mercurial > ~mikael > mcabber > hg
annotate mcabber/src/screen.c @ 374:bd5638c21834
Improve logging system (traces)
There are now two trace logging levels:
* tracelog_level = 1:
Most messages from the log window are written to disk (LPRINT_LOG)
* tracelog_level =2:
LPRINT_LOG & LPRINT_DEBUG messages are written to disk
The trace file name is set with the "tracelog_file" option.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Mon, 25 Jul 2005 21:46:35 +0100 |
parents | af2f8ddf6a1b |
children | 4c6e8392e465 d59e9b8c91d3 |
rev | line source |
---|---|
307 | 1 /* |
2 * screen.c -- UI stuff | |
3 * | |
4 * Copyright (C) 2005 Mikael Berthe <bmikael@lists.lilotux.net> | |
5 * Parts of this file come from the Cabber project <cabber@ajmacias.com> | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or (at | |
10 * your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
20 * USA | |
21 */ | |
22 | |
24 | 23 #include <stdio.h> |
24 #include <stdlib.h> | |
25 #include <string.h> | |
26 #include <ncurses.h> | |
27 #include <panel.h> | |
28 #include <time.h> | |
29 #include <ctype.h> | |
30 #include <locale.h> | |
232 | 31 #include <langinfo.h> |
24 | 32 |
33 #include "screen.h" | |
81 | 34 #include "hbuf.h" |
47 | 35 #include "commands.h" |
95 | 36 #include "compl.h" |
81 | 37 #include "roster.h" |
180 | 38 #include "histolog.h" |
279
f5dd437c057b
Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
276
diff
changeset
|
39 #include "settings.h" |
81 | 40 #include "utils.h" |
24 | 41 #include "list.h" |
42 | |
43 #define window_entry(n) list_entry(n, window_entry_t, list) | |
44 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
45 static inline void check_offset(int); |
151 | 46 |
24 | 47 LIST_HEAD(window_list); |
48 | |
49 typedef struct _window_entry_t { | |
50 WINDOW *win; | |
108 | 51 PANEL *panel; |
52 char *name; | |
53 GList *hbuf; | |
181 | 54 GList *top; // If top is NULL, we'll display the last lines |
55 char cleared; // For ex, user has issued a /clear command... | |
24 | 56 struct list_head list; |
57 } window_entry_t; | |
58 | |
59 | |
60 static WINDOW *rosterWnd, *chatWnd, *inputWnd; | |
61 static WINDOW *logWnd, *logWnd_border; | |
62 static PANEL *rosterPanel, *chatPanel, *inputPanel; | |
63 static PANEL *logPanel, *logPanel_border; | |
64 static int maxY, maxX; | |
65 static window_entry_t *currentWindow; | |
66 | |
67 static int chatmode; | |
238 | 68 static int multimode; |
69 static char *multiline; | |
30 | 70 int update_roster; |
232 | 71 int utf8_mode = 0; |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
72 static bool Autoaway; |
332
a1901741890e
scr_LogPrint() can be called before ncurses initialization
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
73 static bool Curses; |
24 | 74 |
174 | 75 static char inputLine[INPUTLINE_LENGTH+1]; |
76 static char *ptr_inputline; | |
77 static short int inputline_offset; | |
78 static int completion_started; | |
173 | 79 static GList *cmdhisto; |
80 static GList *cmdhisto_cur; | |
174 | 81 static char cmdhisto_backup[INPUTLINE_LENGTH+1]; |
24 | 82 |
83 | |
99 | 84 /* Functions */ |
24 | 85 |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
86 static int scr_WindowWidth(WINDOW * win) |
24 | 87 { |
88 int x, y; | |
89 getmaxyx(win, y, x); | |
90 return x; | |
91 } | |
92 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
93 static void scr_draw_box(WINDOW * win, int y, int x, int height, int width, |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
94 int Color, chtype box, chtype border) |
24 | 95 { |
96 int i, j; | |
97 | |
98 wattrset(win, COLOR_PAIR(Color)); | |
99 for (i = 0; i < height; i++) { | |
100 wmove(win, y + i, x); | |
101 for (j = 0; j < width; j++) | |
102 if (!i && !j) | |
103 waddch(win, border | ACS_ULCORNER); | |
104 else if (i == height - 1 && !j) | |
105 waddch(win, border | ACS_LLCORNER); | |
106 else if (!i && j == width - 1) | |
107 waddch(win, box | ACS_URCORNER); | |
108 else if (i == height - 1 && j == width - 1) | |
109 waddch(win, box | ACS_LRCORNER); | |
110 else if (!i) | |
111 waddch(win, border | ACS_HLINE); | |
112 else if (i == height - 1) | |
113 waddch(win, box | ACS_HLINE); | |
114 else if (!j) | |
115 waddch(win, border | ACS_VLINE); | |
116 else if (j == width - 1) | |
117 waddch(win, box | ACS_VLINE); | |
118 else | |
119 waddch(win, box | ' '); | |
120 } | |
121 } | |
122 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
123 static int FindColor(const char *name) |
24 | 124 { |
125 if (!strcmp(name, "default")) | |
126 return -1; | |
127 if (!strcmp(name, "black")) | |
128 return COLOR_BLACK; | |
129 if (!strcmp(name, "red")) | |
130 return COLOR_RED; | |
131 if (!strcmp(name, "green")) | |
132 return COLOR_GREEN; | |
133 if (!strcmp(name, "yellow")) | |
134 return COLOR_YELLOW; | |
135 if (!strcmp(name, "blue")) | |
136 return COLOR_BLUE; | |
137 if (!strcmp(name, "magenta")) | |
138 return COLOR_MAGENTA; | |
139 if (!strcmp(name, "cyan")) | |
140 return COLOR_CYAN; | |
141 if (!strcmp(name, "white")) | |
142 return COLOR_WHITE; | |
143 | |
144 return -1; | |
145 } | |
146 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
147 static void ParseColors(void) |
24 | 148 { |
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
149 const char *colors[8] = { |
24 | 150 "", "", |
267 | 151 "general", |
139 | 152 "newmsg", |
267 | 153 "rosterselect", |
154 "rosternormal", | |
24 | 155 NULL |
156 }; | |
157 | |
158 char *tmp = malloc(1024); | |
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
159 const char *color; |
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
160 const char *background = settings_opt_get("color_background"); |
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
161 const char *backselected = settings_opt_get("color_backselected"); |
24 | 162 int i = 0; |
163 | |
267 | 164 // Default values |
165 if (!background) background = "blue"; | |
166 if (!backselected) backselected = "cyan"; | |
167 | |
24 | 168 while (colors[i]) { |
169 sprintf(tmp, "color_%s", colors[i]); | |
279
f5dd437c057b
Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
276
diff
changeset
|
170 color = settings_opt_get(tmp); |
24 | 171 |
172 switch (i + 1) { | |
173 case 1: | |
174 init_pair(1, COLOR_BLACK, COLOR_WHITE); | |
175 break; | |
176 case 2: | |
177 init_pair(2, COLOR_WHITE, COLOR_BLACK); | |
178 break; | |
179 case 3: | |
267 | 180 init_pair(3, ((color) ? FindColor(color) : COLOR_WHITE), |
181 FindColor(background)); | |
24 | 182 break; |
183 case 4: | |
267 | 184 init_pair(4, ((color) ? FindColor(color) : COLOR_RED), |
185 FindColor(background)); | |
24 | 186 break; |
187 case 5: | |
267 | 188 init_pair(5, ((color) ? FindColor(color) : COLOR_BLACK), |
189 FindColor(backselected)); | |
24 | 190 break; |
191 case 6: | |
267 | 192 init_pair(6, ((color) ? FindColor(color) : COLOR_MAGENTA), |
193 FindColor(background)); | |
24 | 194 break; |
195 } | |
196 i++; | |
197 } | |
198 } | |
199 | |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
200 void scr_InitCurses(void) |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
201 { |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
202 initscr(); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
203 noecho(); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
204 raw(); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
205 halfdelay(5); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
206 start_color(); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
207 use_default_colors(); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
208 Curses = TRUE; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
209 |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
210 ParseColors(); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
211 |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
212 getmaxyx(stdscr, maxY, maxX); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
213 if (maxY < LOG_WIN_HEIGHT+2) |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
214 maxY = LOG_WIN_HEIGHT+2; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
215 inputLine[0] = 0; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
216 ptr_inputline = inputLine; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
217 |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
218 setlocale(LC_CTYPE, ""); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
219 utf8_mode = (strcmp(nl_langinfo(CODESET), "UTF-8") == 0); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
220 |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
221 return; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
222 } |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
223 |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
224 void scr_TerminateCurses(void) |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
225 { |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
226 if (!Curses) return; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
227 clear(); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
228 refresh(); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
229 endwin(); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
230 Curses = FALSE; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
231 return; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
232 } |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
233 |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
234 // scr_LogPrint(...) |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
235 // Display a message in the log window. |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
236 void scr_LogPrint(unsigned int flag, const char *fmt, ...) |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
237 { |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
238 time_t timestamp; |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
239 char *buffer, *b2; |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
240 va_list ap; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
241 |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
242 if (!flag) return; |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
243 |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
244 do { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
245 buffer = (char *) calloc(1, 1088); |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
246 } while (!buffer); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
247 |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
248 timestamp = time(NULL); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
249 strftime(buffer, 64, "[%H:%M:%S] ", localtime(×tamp)); |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
250 for (b2 = buffer ; *b2 ; b2++) |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
251 ; |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
252 va_start(ap, fmt); |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
253 vsnprintf(b2, 1024, fmt, ap); |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
254 va_end(ap); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
255 |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
256 if (flag & LPRINT_NORMAL) { |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
257 if (Curses) { |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
258 wprintw(logWnd, "\n%s", buffer); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
259 update_panels(); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
260 doupdate(); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
261 } else { |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
262 printf("%s\n", buffer); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
263 } |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
264 } |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
265 if (flag & (LPRINT_LOG|LPRINT_DEBUG)) { |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
266 strcat(buffer, "\n"); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
267 ut_WriteLog(flag, buffer); |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
268 } |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
269 free(buffer); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
270 } |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
271 |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
272 static window_entry_t *scr_CreateBuddyPanel(const char *title, int dont_show) |
24 | 273 { |
151 | 274 int x; |
275 int y; | |
276 int lines; | |
277 int cols; | |
153 | 278 window_entry_t *tmp; |
279 | |
280 do { | |
281 tmp = calloc(1, sizeof(window_entry_t)); | |
282 } while (!tmp); | |
24 | 283 |
151 | 284 // Dimensions |
285 x = ROSTER_WIDTH; | |
286 y = 0; | |
287 lines = CHAT_WIN_HEIGHT; | |
288 cols = maxX - ROSTER_WIDTH; | |
289 | |
24 | 290 tmp->win = newwin(lines, cols, y, x); |
154 | 291 while (!tmp->win) { |
292 usleep(250); | |
293 tmp->win = newwin(lines, cols, y, x); | |
294 } | |
168 | 295 wbkgd(tmp->win, COLOR_PAIR(COLOR_GENERAL)); |
24 | 296 tmp->panel = new_panel(tmp->win); |
153 | 297 tmp->name = (char *) calloc(1, 96); |
298 strncpy(tmp->name, title, 96); | |
24 | 299 |
143 | 300 if (!dont_show) { |
24 | 301 currentWindow = tmp; |
302 } else { | |
303 if (currentWindow) | |
304 top_panel(currentWindow->panel); | |
305 else | |
306 top_panel(chatPanel); | |
307 } | |
143 | 308 update_panels(); |
24 | 309 |
181 | 310 // Load buddy history from file (if enabled) |
185 | 311 hlog_read_history(title, &tmp->hbuf, maxX - ROSTER_WIDTH - PREFIX_WIDTH); |
181 | 312 |
24 | 313 list_add_tail(&tmp->list, &window_list); |
314 | |
315 return tmp; | |
316 } | |
317 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
318 static window_entry_t *scr_SearchWindow(const char *winId) |
24 | 319 { |
320 struct list_head *pos, *n; | |
321 window_entry_t *search_entry = NULL; | |
322 | |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
323 if (!winId) return NULL; |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
324 |
24 | 325 list_for_each_safe(pos, n, &window_list) { |
326 search_entry = window_entry(pos); | |
327 if (search_entry->name) { | |
328 if (!strcasecmp(search_entry->name, winId)) { | |
329 return search_entry; | |
330 } | |
331 } | |
332 } | |
333 return NULL; | |
334 } | |
335 | |
143 | 336 // scr_UpdateWindow() |
337 // (Re-)Display the given chat window. | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
338 static void scr_UpdateWindow(window_entry_t *win_entry) |
74 | 339 { |
340 int n; | |
341 int width; | |
184 | 342 hbb_line **lines, *line; |
74 | 343 GList *hbuf_head; |
184 | 344 char date[32]; |
74 | 345 |
108 | 346 width = scr_WindowWidth(win_entry->win); |
347 | |
348 // Should the window be empty? | |
349 if (win_entry->cleared) { | |
168 | 350 werase(win_entry->win); |
108 | 351 return; |
352 } | |
353 | |
105 | 354 // win_entry->top is the top message of the screen. If it set to NULL, we |
355 // are displaying the last messages. | |
356 | |
74 | 357 // We will show the last CHAT_WIN_HEIGHT lines. |
358 // Let's find out where it begins. | |
105 | 359 if (!win_entry->top || |
360 (g_list_position(g_list_first(win_entry->hbuf), win_entry->top) == -1)) { | |
361 // Move up CHAT_WIN_HEIGHT lines | |
362 win_entry->hbuf = g_list_last(win_entry->hbuf); | |
363 hbuf_head = win_entry->hbuf; | |
364 win_entry->top = NULL; // (Just to make sure) | |
365 n = 0; | |
366 while (hbuf_head && (n < CHAT_WIN_HEIGHT-1) && g_list_previous(hbuf_head)) { | |
367 hbuf_head = g_list_previous(hbuf_head); | |
368 n++; | |
369 } | |
370 } else | |
371 hbuf_head = win_entry->top; | |
74 | 372 |
373 // Get the last CHAT_WIN_HEIGHT lines. | |
374 lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT); | |
375 | |
376 // Display these lines | |
377 for (n = 0; n < CHAT_WIN_HEIGHT; n++) { | |
168 | 378 wmove(win_entry->win, n, 0); |
184 | 379 line = *(lines+n); |
185 | 380 // NOTE: update PREFIX_WIDTH if you change the date format!! |
381 // You need to set it to the whole prefix length + 1 | |
184 | 382 if (line) { |
383 if (line->timestamp) { | |
185 | 384 strftime(date, 35, "%m-%d %H:%M", localtime(&line->timestamp)); |
184 | 385 } else |
185 | 386 strcpy(date, " "); |
197 | 387 if (line->flags & HBB_PREFIX_INFO) { |
388 char dir = '*'; | |
389 if (line->flags & HBB_PREFIX_IN) | |
390 dir = '<'; | |
391 else if (line->flags & HBB_PREFIX_OUT) | |
392 dir = '>'; | |
393 wprintw(win_entry->win, "%.11s *%c* ", date, dir); | |
325
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
394 } else if (line->flags & HBB_PREFIX_ERR) { |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
395 char dir = '#'; |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
396 if (line->flags & HBB_PREFIX_IN) |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
397 dir = '<'; |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
398 else if (line->flags & HBB_PREFIX_OUT) |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
399 dir = '>'; |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
400 wprintw(win_entry->win, "%.11s #%c# ", date, dir); |
197 | 401 } else if (line->flags & HBB_PREFIX_IN) |
185 | 402 wprintw(win_entry->win, "%.11s <== ", date); |
184 | 403 else if (line->flags & HBB_PREFIX_OUT) |
185 | 404 wprintw(win_entry->win, "%.11s --> ", date); |
75 | 405 else { |
185 | 406 wprintw(win_entry->win, "%.11s ", date); |
75 | 407 } |
184 | 408 wprintw(win_entry->win, "%s", line->text); // line |
168 | 409 wclrtoeol(win_entry->win); |
184 | 410 g_free(line->text); |
168 | 411 } else { |
412 wclrtobot(win_entry->win); | |
413 break; | |
75 | 414 } |
74 | 415 } |
416 g_free(lines); | |
417 } | |
418 | |
143 | 419 // scr_ShowWindow() |
420 // Display the chat window with the given identifier. | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
421 static void scr_ShowWindow(const char *winId) |
24 | 422 { |
74 | 423 window_entry_t *win_entry = scr_SearchWindow(winId); |
424 | |
181 | 425 if (!win_entry) |
180 | 426 win_entry = scr_CreateBuddyPanel(winId, FALSE); |
74 | 427 |
180 | 428 top_panel(win_entry->panel); |
429 currentWindow = win_entry; | |
430 chatmode = TRUE; | |
431 roster_msg_setflag(winId, FALSE); | |
432 roster_setflags(winId, ROSTER_FLAG_LOCK, TRUE); | |
433 update_roster = TRUE; | |
74 | 434 |
180 | 435 // Refresh the window |
436 scr_UpdateWindow(win_entry); | |
437 | |
438 // Finished :) | |
439 update_panels(); | |
142 | 440 |
441 top_panel(inputPanel); | |
24 | 442 } |
443 | |
143 | 444 // scr_ShowBuddyWindow() |
445 // Display the chat window buffer for the current buddy. | |
24 | 446 void scr_ShowBuddyWindow(void) |
447 { | |
105 | 448 const gchar *jid; |
140 | 449 |
105 | 450 if (!current_buddy) |
140 | 451 jid = NULL; |
452 else | |
453 jid = CURRENT_JID; | |
454 | |
455 if (!jid) { | |
456 top_panel(chatPanel); | |
143 | 457 top_panel(inputPanel); |
140 | 458 currentWindow = NULL; |
105 | 459 return; |
140 | 460 } |
461 | |
105 | 462 scr_ShowWindow(jid); |
24 | 463 } |
464 | |
143 | 465 // scr_WriteInWindow() |
466 // Write some text in the winId window (this usually is a jid). | |
467 // Lines are splitted when they are too long to fit in the chat window. | |
468 // If this window doesn't exist, it is created. | |
184 | 469 void scr_WriteInWindow(const char *winId, const char *text, time_t timestamp, |
470 unsigned int prefix_flags, int force_show) | |
24 | 471 { |
74 | 472 window_entry_t *win_entry; |
24 | 473 int dont_show = FALSE; |
474 | |
74 | 475 // Look for the window entry. |
476 win_entry = scr_SearchWindow(winId); | |
477 | |
478 // Do we have to really show the window? | |
24 | 479 if (!chatmode) |
480 dont_show = TRUE; | |
74 | 481 else if ((!force_show) && ((!currentWindow || (currentWindow != win_entry)))) |
24 | 482 dont_show = TRUE; |
483 | |
74 | 484 // If the window entry doesn't exist yet, let's create it. |
485 if (win_entry == NULL) { | |
151 | 486 win_entry = scr_CreateBuddyPanel(winId, dont_show); |
24 | 487 } |
488 | |
220 | 489 // The message must be displayed -> update top pointer |
490 if (win_entry->cleared) | |
491 win_entry->top = g_list_last(win_entry->hbuf); | |
492 | |
184 | 493 hbuf_add_line(&win_entry->hbuf, text, timestamp, prefix_flags, |
185 | 494 maxX - ROSTER_WIDTH - PREFIX_WIDTH); |
74 | 495 |
108 | 496 if (win_entry->cleared) { |
220 | 497 win_entry->cleared = FALSE; |
498 if (g_list_next(win_entry->top)) | |
499 win_entry->top = g_list_next(win_entry->top); | |
500 } | |
501 | |
502 // Make sure the last line appears in the window; update top if necessary | |
503 if (win_entry->top) { | |
504 int dist; | |
505 GList *first = g_list_first(win_entry->hbuf); | |
506 dist = g_list_position(first, g_list_last(win_entry->hbuf)) - | |
507 g_list_position(first, win_entry->top); | |
508 if (dist >= CHAT_WIN_HEIGHT) | |
509 win_entry->top = NULL; | |
108 | 510 } |
511 | |
24 | 512 if (!dont_show) { |
74 | 513 // Show and refresh the window |
514 top_panel(win_entry->panel); | |
515 scr_UpdateWindow(win_entry); | |
142 | 516 top_panel(inputPanel); |
24 | 517 update_panels(); |
518 doupdate(); | |
519 } else { | |
148 | 520 roster_msg_setflag(winId, TRUE); |
30 | 521 update_roster = TRUE; |
24 | 522 } |
523 } | |
524 | |
151 | 525 // scr_DrawMainWindow() |
157 | 526 // Set fullinit to TRUE to also create panels. Set it to FALSE for a resize. |
151 | 527 // |
528 // I think it could be improved a _lot_ but I'm really not an ncurses | |
529 // expert... :-\ Mikael. | |
530 // | |
531 void scr_DrawMainWindow(unsigned int fullinit) | |
24 | 532 { |
157 | 533 if (fullinit) { |
534 /* Create windows */ | |
535 rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WIDTH, 0, 0); | |
536 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH, 0, ROSTER_WIDTH); | |
537 logWnd_border = newwin(LOG_WIN_HEIGHT, maxX, CHAT_WIN_HEIGHT, 0); | |
538 logWnd = newwin(LOG_WIN_HEIGHT-2, maxX-2, CHAT_WIN_HEIGHT+1, 1); | |
539 inputWnd = newwin(1, maxX, maxY-1, 0); | |
358
6e4e667c5571
Fix a segfault when starting mcabber in a really small terminal
Mikael Berthe <mikael@lilotux.net>
parents:
339
diff
changeset
|
540 if (!rosterWnd || !chatWnd || !logWnd || !inputWnd) { |
6e4e667c5571
Fix a segfault when starting mcabber in a really small terminal
Mikael Berthe <mikael@lilotux.net>
parents:
339
diff
changeset
|
541 scr_TerminateCurses(); |
6e4e667c5571
Fix a segfault when starting mcabber in a really small terminal
Mikael Berthe <mikael@lilotux.net>
parents:
339
diff
changeset
|
542 fprintf(stderr, "Cannot create windows!\n"); |
6e4e667c5571
Fix a segfault when starting mcabber in a really small terminal
Mikael Berthe <mikael@lilotux.net>
parents:
339
diff
changeset
|
543 exit(EXIT_FAILURE); |
6e4e667c5571
Fix a segfault when starting mcabber in a really small terminal
Mikael Berthe <mikael@lilotux.net>
parents:
339
diff
changeset
|
544 } |
168 | 545 wbkgd(rosterWnd, COLOR_PAIR(COLOR_GENERAL)); |
546 wbkgd(chatWnd, COLOR_PAIR(COLOR_GENERAL)); | |
547 wbkgd(logWnd_border, COLOR_PAIR(COLOR_GENERAL)); | |
548 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL)); | |
157 | 549 } else { |
550 /* Resize windows */ | |
551 wresize(rosterWnd, CHAT_WIN_HEIGHT, ROSTER_WIDTH); | |
552 wresize(chatWnd, CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH); | |
553 | |
554 wresize(logWnd_border, LOG_WIN_HEIGHT, maxX); | |
555 wresize(logWnd, LOG_WIN_HEIGHT-2, maxX-2); | |
556 mvwin(logWnd_border, CHAT_WIN_HEIGHT, 0); | |
557 mvwin(logWnd, CHAT_WIN_HEIGHT+1, 1); | |
558 | |
559 wresize(inputWnd, 1, maxX); | |
560 mvwin(inputWnd, maxY-1, 0); | |
168 | 561 |
562 werase(chatWnd); | |
157 | 563 } |
151 | 564 |
565 /* Draw/init windows */ | |
566 | |
74 | 567 mvwprintw(chatWnd, 0, 0, "This is the status window"); |
24 | 568 |
151 | 569 // - Draw/clear the log window |
24 | 570 scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX, COLOR_GENERAL, 0, 0); |
157 | 571 // Auto-scrolling in log window |
74 | 572 scrollok(logWnd, TRUE); |
24 | 573 |
574 | |
151 | 575 if (fullinit) { |
157 | 576 // Enable keypad (+ special keys) |
577 keypad(inputWnd, TRUE); | |
578 | |
151 | 579 // Create panels |
580 rosterPanel = new_panel(rosterWnd); | |
581 chatPanel = new_panel(chatWnd); | |
582 logPanel_border = new_panel(logWnd_border); | |
583 logPanel = new_panel(logWnd); | |
584 inputPanel = new_panel(inputWnd); | |
232 | 585 |
586 if (utf8_mode) | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
587 scr_LogPrint(LPRINT_NORMAL, "WARNING: UTF-8 not yet supported!"); |
157 | 588 } else { |
589 // Update panels | |
590 replace_panel(rosterPanel, rosterWnd); | |
591 replace_panel(chatPanel, chatWnd); | |
592 replace_panel(logPanel, logWnd); | |
593 replace_panel(logPanel_border, logWnd_border); | |
594 replace_panel(inputPanel, inputWnd); | |
151 | 595 } |
596 | |
597 // We'll need to redraw the roster | |
149 | 598 update_roster = TRUE; |
24 | 599 return; |
600 } | |
601 | |
151 | 602 // scr_Resize() |
603 // Function called when the window is resized. | |
157 | 604 // - Resize windows |
151 | 605 // - Rewrap lines in each buddy buffer |
606 void scr_Resize() | |
607 { | |
608 struct list_head *pos, *n; | |
609 window_entry_t *search_entry; | |
610 int x, y, lines, cols; | |
611 | |
612 // First, update the global variables | |
613 getmaxyx(stdscr, maxY, maxX); | |
167 | 614 if (maxY < LOG_WIN_HEIGHT+2) |
615 maxY = LOG_WIN_HEIGHT+2; | |
151 | 616 // Make sure the cursor stays inside the window |
617 check_offset(0); | |
618 | |
157 | 619 // Resize windows and update panels |
151 | 620 scr_DrawMainWindow(FALSE); |
621 | |
622 // Resize all buddy windows | |
623 x = ROSTER_WIDTH; | |
624 y = 0; | |
625 lines = CHAT_WIN_HEIGHT; | |
626 cols = maxX - ROSTER_WIDTH; | |
627 | |
628 list_for_each_safe(pos, n, &window_list) { | |
629 search_entry = window_entry(pos); | |
630 if (search_entry->win) { | |
189 | 631 GList *rescue_top; |
157 | 632 // Resize buddy window (no need to move it) |
633 wresize(search_entry->win, lines, cols); | |
168 | 634 werase(search_entry->win); |
151 | 635 // If a panel exists, replace the old window with the new |
636 if (search_entry->panel) { | |
637 replace_panel(search_entry->panel, search_entry->win); | |
638 } | |
639 // Redo line wrapping | |
189 | 640 rescue_top = hbuf_previous_persistent(search_entry->top); |
151 | 641 hbuf_rebuild(&search_entry->hbuf, |
185 | 642 maxX - ROSTER_WIDTH - PREFIX_WIDTH); |
189 | 643 if (g_list_position(g_list_first(search_entry->hbuf), search_entry->top) == -1) |
644 search_entry->top = rescue_top; | |
151 | 645 } |
646 } | |
647 | |
648 // Refresh current buddy window | |
157 | 649 if (chatmode) |
151 | 650 scr_ShowBuddyWindow(); |
651 } | |
652 | |
143 | 653 // scr_DrawRoster() |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
654 // Display the buddylist (not really the roster) on the screen |
81 | 655 void scr_DrawRoster(void) |
24 | 656 { |
81 | 657 static guint offset = 0; |
658 char name[ROSTER_WIDTH]; | |
659 int maxx, maxy; | |
660 GList *buddy; | |
661 int i, n; | |
662 int rOffset; | |
164 | 663 enum imstatus currentstatus = jb_getstatus(); |
81 | 664 |
123 | 665 // We can reset update_roster |
666 update_roster = FALSE; | |
667 | |
81 | 668 getmaxyx(rosterWnd, maxy, maxx); |
669 maxx --; // last char is for vertical border | |
670 name[ROSTER_WIDTH-7] = 0; | |
671 | |
672 // cleanup of roster window | |
168 | 673 werase(rosterWnd); |
674 // Redraw the vertical line (not very good...) | |
81 | 675 wattrset(rosterWnd, COLOR_PAIR(COLOR_GENERAL)); |
168 | 676 for (i=0 ; i < CHAT_WIN_HEIGHT ; i++) |
677 mvwaddch(rosterWnd, i, ROSTER_WIDTH-1, ACS_VLINE); | |
81 | 678 |
679 // Leave now if buddylist is empty | |
680 if (!buddylist) { | |
681 offset = 0; | |
123 | 682 update_panels(); |
683 doupdate(); | |
81 | 684 return; |
685 } | |
686 | |
84 | 687 // Update offset if necessary |
688 i = g_list_position(buddylist, current_buddy); | |
689 if (i == -1) { // This is bad | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
690 scr_LogPrint(LPRINT_NORMAL, "Doh! Can't find current selected buddy!!"); |
84 | 691 return; |
692 } else if (i < offset) { | |
693 offset = i; | |
694 } else if (i+1 > offset + maxy) { | |
695 offset = i + 1 - maxy; | |
696 } | |
81 | 697 |
698 buddy = buddylist; | |
699 rOffset = offset; | |
700 | |
84 | 701 for (i=0; i<maxy && buddy; buddy = g_list_next(buddy)) { |
81 | 702 |
703 char status = '?'; | |
704 char pending = ' '; | |
705 enum imstatus budstate; | |
149 | 706 unsigned short ismsg = buddy_getflags(BUDDATA(buddy)) & ROSTER_FLAG_MSG; |
707 unsigned short isgrp = buddy_gettype(BUDDATA(buddy)) & ROSTER_TYPE_GROUP; | |
708 unsigned short ishid = buddy_getflags(BUDDATA(buddy)) & ROSTER_FLAG_HIDE; | |
81 | 709 |
710 if (rOffset > 0) { | |
711 rOffset--; | |
712 continue; | |
713 } | |
714 | |
149 | 715 // Display message notice if there is a message flag, but not |
716 // for unfolded groups. | |
717 if (ismsg && (!isgrp || ishid)) { | |
81 | 718 pending = '#'; |
719 } | |
720 | |
721 budstate = buddy_getstatus(BUDDATA(buddy)); | |
164 | 722 if (budstate >= 0 && budstate < imstatus_size && currentstatus != offline) |
81 | 723 status = imstatus2char[budstate]; |
724 if (buddy == current_buddy) { | |
725 wattrset(rosterWnd, COLOR_PAIR(COLOR_BD_DESSEL)); | |
726 // The 3 following lines aim to color the whole line | |
727 wmove(rosterWnd, i, 0); | |
728 for (n = 0; n < maxx; n++) | |
729 waddch(rosterWnd, ' '); | |
730 } else { | |
149 | 731 if (pending == '#') |
139 | 732 wattrset(rosterWnd, COLOR_PAIR(COLOR_NMSG)); |
733 else | |
734 wattrset(rosterWnd, COLOR_PAIR(COLOR_BD_DES)); | |
81 | 735 } |
736 | |
737 strncpy(name, buddy_getname(BUDDATA(buddy)), ROSTER_WIDTH-7); | |
149 | 738 if (isgrp) { |
133 | 739 char *sep; |
149 | 740 if (ishid) |
133 | 741 sep = "+++"; |
742 else | |
743 sep = "---"; | |
744 mvwprintw(rosterWnd, i, 0, " %c%s %s", pending, sep, name); | |
745 } | |
126 | 746 else |
747 mvwprintw(rosterWnd, i, 0, " %c[%c] %s", pending, status, name); | |
84 | 748 |
749 i++; | |
81 | 750 } |
751 | |
142 | 752 top_panel(inputPanel); |
81 | 753 update_panels(); |
754 doupdate(); | |
24 | 755 } |
756 | |
184 | 757 void scr_WriteMessage(const char *jid, const char *text, time_t timestamp, |
758 guint prefix_flags) | |
24 | 759 { |
184 | 760 if (!timestamp) timestamp = time(NULL); |
761 | |
762 scr_WriteInWindow(jid, text, timestamp, prefix_flags, FALSE); | |
47 | 763 } |
764 | |
190 | 765 // If prefix is NULL, HBB_PREFIX_IN is supposed. |
184 | 766 void scr_WriteIncomingMessage(const char *jidfrom, const char *text, |
190 | 767 time_t timestamp, guint prefix) |
47 | 768 { |
190 | 769 if (!prefix) prefix = HBB_PREFIX_IN; |
75 | 770 // FIXME expand tabs / filter out special chars... |
190 | 771 scr_WriteMessage(jidfrom, text, timestamp, prefix); |
24 | 772 update_panels(); |
773 doupdate(); | |
774 } | |
775 | |
50 | 776 void scr_WriteOutgoingMessage(const char *jidto, const char *text) |
47 | 777 { |
184 | 778 scr_WriteMessage(jidto, text, 0, HBB_PREFIX_OUT); |
47 | 779 scr_ShowWindow(jidto); |
780 } | |
781 | |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
782 void inline set_autoaway(bool setaway) |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
783 { |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
784 static enum imstatus oldstatus; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
785 Autoaway = setaway; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
786 |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
787 if (setaway) { |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
788 const char *msg; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
789 oldstatus = jb_getstatus(); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
790 msg = settings_opt_get("message_autoaway"); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
791 if (!msg) msg = MSG_AUTOAWAY; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
792 jb_setstatus(away, msg); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
793 } else { |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
794 // Back |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
795 jb_setstatus(oldstatus, NULL); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
796 } |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
797 } |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
798 |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
799 // Check if we should enter/leave automatic away status |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
800 void scr_CheckAutoAway(bool activity) |
24 | 801 { |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
802 static time_t LastActivity; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
803 enum imstatus cur_st; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
804 unsigned int autoaway_timeout = settings_opt_get_int("autoaway"); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
805 |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
806 if (Autoaway && activity) set_autoaway(FALSE); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
807 if (!autoaway_timeout) return; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
808 if (!LastActivity || activity) time(&LastActivity); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
809 |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
810 cur_st = jb_getstatus(); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
811 // Auto-away is disabled for the following states |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
812 if ((cur_st != available) && (cur_st != freeforchat)) |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
813 return; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
814 |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
815 if (!activity) { |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
816 time_t now; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
817 time(&now); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
818 if (!Autoaway && (now > LastActivity + autoaway_timeout)) |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
819 set_autoaway(TRUE); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
820 } |
24 | 821 } |
822 | |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
823 // set_current_buddy(newbuddy) |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
824 // Set the current_buddy to newbuddy (if not NULL) |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
825 // Lock the newbuddy, and unlock the previous current_buddy |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
826 static void set_current_buddy(GList *newbuddy) |
24 | 827 { |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
828 enum imstatus prev_st = imstatus_size; |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
829 /* prev_st initialized to imstatus_size, which is used as "undef" value. |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
830 * We are sure prev_st will get a different status value after the |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
831 * buddy_getstatus() call. |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
832 */ |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
833 |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
834 if (!current_buddy || !newbuddy) return; |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
835 if (newbuddy == current_buddy) return; |
24 | 836 |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
837 prev_st = buddy_getstatus(BUDDATA(current_buddy)); |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
838 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); |
330 | 839 if (chatmode) |
840 alternate_buddy = current_buddy; | |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
841 current_buddy = newbuddy; |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
842 // Lock the buddy in the buddylist if we're in chat mode |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
843 if (chatmode) |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
844 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE); |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
845 // We should rebuild the buddylist but not everytime |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
846 // Here we check if we were locking a buddy who is actually offline, |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
847 // and hide_offline_buddies is TRUE. In which case we need to rebuild. |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
848 if (prev_st == offline && buddylist_get_hide_offline_buddies()) |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
849 buddylist_build(); |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
850 update_roster = TRUE; |
24 | 851 } |
852 | |
143 | 853 // scr_RosterTop() |
854 // Go to the first buddy in the buddylist | |
105 | 855 void scr_RosterTop(void) |
104 | 856 { |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
857 set_current_buddy(buddylist); |
104 | 858 if (chatmode) |
859 scr_ShowBuddyWindow(); | |
860 } | |
861 | |
143 | 862 // scr_RosterBottom() |
863 // Go to the last buddy in the buddylist | |
105 | 864 void scr_RosterBottom(void) |
104 | 865 { |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
866 set_current_buddy(g_list_last(buddylist)); |
104 | 867 if (chatmode) |
868 scr_ShowBuddyWindow(); | |
869 } | |
870 | |
143 | 871 // scr_RosterUp() |
872 // Go to the previous buddy in the buddylist | |
105 | 873 void scr_RosterUp(void) |
81 | 874 { |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
875 set_current_buddy(g_list_previous(current_buddy)); |
104 | 876 if (chatmode) |
877 scr_ShowBuddyWindow(); | |
81 | 878 } |
879 | |
143 | 880 // scr_RosterDown() |
881 // Go to the next buddy in the buddylist | |
105 | 882 void scr_RosterDown(void) |
81 | 883 { |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
884 set_current_buddy(g_list_next(current_buddy)); |
104 | 885 if (chatmode) |
886 scr_ShowBuddyWindow(); | |
81 | 887 } |
888 | |
265 | 889 // scr_RosterSearch(str) |
890 // Look forward for a buddy with jid/name containing str. | |
891 void scr_RosterSearch(char *str) | |
892 { | |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
893 set_current_buddy(buddy_search(str)); |
265 | 894 if (chatmode) |
895 scr_ShowBuddyWindow(); | |
896 } | |
897 | |
236 | 898 // scr_RosterUnreadMessage(next) |
899 // Go to a new message. If next is not null, try to go to the next new | |
900 // message. If it is not possible or if next is NULL, go to the first new | |
901 // message from unread_list. | |
902 void scr_RosterUnreadMessage(int next) | |
903 { | |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
904 gpointer unread_ptr; |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
905 gpointer refbuddata; |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
906 gpointer ngroup; |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
907 GList *nbuddy; |
236 | 908 |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
909 if (!current_buddy) return; |
236 | 910 |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
911 if (next) refbuddata = BUDDATA(current_buddy); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
912 else refbuddata = NULL; |
236 | 913 |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
914 unread_ptr = unread_msg(refbuddata); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
915 if (!unread_ptr) return; |
236 | 916 |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
917 // If buddy is in a folded group, we need to expand it |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
918 ngroup = buddy_getgroup(unread_ptr); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
919 if (buddy_getflags(ngroup) & ROSTER_FLAG_HIDE) { |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
920 buddy_setflags(ngroup, ROSTER_FLAG_HIDE, FALSE); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
921 buddylist_build(); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
922 } |
236 | 923 |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
924 nbuddy = g_list_find(buddylist, unread_ptr); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
925 if (nbuddy) { |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
926 set_current_buddy(nbuddy); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
927 if (chatmode) scr_ShowBuddyWindow(); |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
928 } else |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
929 scr_LogPrint(LPRINT_LOGNORM, "Error: nbuddy == NULL"); // should not happen |
236 | 930 } |
931 | |
330 | 932 // scr_RosterJumpAlternate() |
933 // Try to jump to alternate (== previous) buddy | |
934 void scr_RosterJumpAlternate(void) | |
105 | 935 { |
330 | 936 if (!alternate_buddy || g_list_position(buddylist, alternate_buddy) == -1) |
937 return; | |
938 set_current_buddy(alternate_buddy); | |
939 if (chatmode) | |
940 scr_ShowBuddyWindow(); | |
941 } | |
942 | |
369
499170ed71c9
Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents:
365
diff
changeset
|
943 // scr_BufferScrollUpDown() |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
944 // Scroll up/down the current buddy window, half a screen. |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
945 // (up if updown == -1, down if updown == 1) |
369
499170ed71c9
Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents:
365
diff
changeset
|
946 void scr_BufferScrollUpDown(int updown) |
105 | 947 { |
948 window_entry_t *win_entry; | |
949 int n, nblines; | |
950 GList *hbuf_top; | |
951 | |
952 // Get win_entry | |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
953 if (!current_buddy) return; |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
954 win_entry = scr_SearchWindow(CURRENT_JID); |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
955 if (!win_entry) return; |
105 | 956 |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
957 // Scroll half a screen (or less) |
105 | 958 nblines = CHAT_WIN_HEIGHT/2-1; |
959 hbuf_top = win_entry->top; | |
960 | |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
961 if (updown == -1) { // UP |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
962 if (!hbuf_top) { |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
963 hbuf_top = g_list_last(win_entry->hbuf); |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
964 if (!win_entry->cleared) |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
965 nblines *= 3; |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
966 else |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
967 win_entry->cleared = FALSE; |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
968 } |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
969 for (n=0 ; hbuf_top && n < nblines && g_list_previous(hbuf_top) ; n++) |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
970 hbuf_top = g_list_previous(hbuf_top); |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
971 win_entry->top = hbuf_top; |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
972 } else { // DOWN |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
973 for (n=0 ; hbuf_top && n < nblines ; n++) |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
974 hbuf_top = g_list_next(hbuf_top); |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
975 win_entry->top = hbuf_top; |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
976 // Check if we are at the bottom |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
977 for (n=0 ; hbuf_top && n < CHAT_WIN_HEIGHT-1 ; n++) |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
978 hbuf_top = g_list_next(hbuf_top); |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
979 if (!hbuf_top) |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
980 win_entry->top = NULL; // End reached |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
981 } |
105 | 982 |
983 // Refresh the window | |
984 scr_UpdateWindow(win_entry); | |
985 | |
986 // Finished :) | |
987 update_panels(); | |
988 doupdate(); | |
989 } | |
990 | |
369
499170ed71c9
Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents:
365
diff
changeset
|
991 // scr_BufferClear() |
143 | 992 // Clear the current buddy window (used for the /clear command) |
369
499170ed71c9
Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents:
365
diff
changeset
|
993 void scr_BufferClear(void) |
108 | 994 { |
995 window_entry_t *win_entry; | |
996 | |
997 // Get win_entry | |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
998 if (!current_buddy) return; |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
999 win_entry = scr_SearchWindow(CURRENT_JID); |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1000 if (!win_entry) return; |
108 | 1001 |
1002 win_entry->cleared = TRUE; | |
109 | 1003 win_entry->top = NULL; |
108 | 1004 |
1005 // Refresh the window | |
1006 scr_UpdateWindow(win_entry); | |
1007 | |
1008 // Finished :) | |
1009 update_panels(); | |
1010 doupdate(); | |
1011 } | |
1012 | |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1013 // scr_BufferTopBottom() |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1014 // Jump to the head/tail of the current buddy window |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1015 // (top if topbottom == -1, bottom topbottom == 1) |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1016 void scr_BufferTopBottom(int topbottom) |
187 | 1017 { |
1018 window_entry_t *win_entry; | |
1019 | |
1020 // Get win_entry | |
1021 if (!current_buddy) return; | |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1022 win_entry = scr_SearchWindow(CURRENT_JID); |
187 | 1023 if (!win_entry) return; |
1024 | |
1025 win_entry->cleared = FALSE; | |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1026 if (topbottom == 1) |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1027 win_entry->top = NULL; |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1028 else |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1029 win_entry->top = g_list_first(win_entry->hbuf); |
187 | 1030 |
1031 // Refresh the window | |
1032 scr_UpdateWindow(win_entry); | |
1033 | |
1034 // Finished :) | |
1035 update_panels(); | |
1036 doupdate(); | |
1037 } | |
1038 | |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1039 // scr_BufferSearch(direction, text) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1040 // Jump to the next line containing text |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1041 // (backward search if direction == -1, forward if topbottom == 1) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1042 void scr_BufferSearch(int direction, const char *text) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1043 { |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1044 window_entry_t *win_entry; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1045 GList *current_line, *search_res; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1046 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1047 // Get win_entry |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1048 if (!current_buddy) return; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1049 win_entry = scr_SearchWindow(CURRENT_JID); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1050 if (!win_entry) return; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1051 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1052 if (win_entry->top) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1053 current_line = win_entry->top; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1054 else |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1055 current_line = g_list_last(win_entry->hbuf); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1056 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1057 search_res = hbuf_search(current_line, direction, text); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1058 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1059 if (search_res) { |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1060 win_entry->cleared = FALSE; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1061 win_entry->top = search_res; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1062 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1063 // Refresh the window |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1064 scr_UpdateWindow(win_entry); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1065 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1066 // Finished :) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1067 update_panels(); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1068 doupdate(); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1069 } else |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
1070 scr_LogPrint(LPRINT_NORMAL, "Search string not found"); |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1071 } |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1072 |
143 | 1073 // scr_set_chatmode() |
261 | 1074 // Public function to (un)set chatmode... |
129 | 1075 inline void scr_set_chatmode(int enable) |
1076 { | |
1077 chatmode = enable; | |
1078 } | |
1079 | |
238 | 1080 // scr_get_multimode() |
261 | 1081 // Public function to get multimode status... |
238 | 1082 inline int scr_get_multimode() |
1083 { | |
1084 return multimode; | |
1085 } | |
1086 | |
1087 // scr_set_multimode() | |
261 | 1088 // Public function to (un)set multimode... |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
252
diff
changeset
|
1089 // Convention: |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
252
diff
changeset
|
1090 // 0 = disabled / 1 = multimode / 2 = multimode verbatim (commands disabled) |
238 | 1091 inline void scr_set_multimode(int enable) |
1092 { | |
1093 if (multiline) { | |
1094 g_free(multiline); | |
1095 multiline = NULL; | |
1096 } | |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
252
diff
changeset
|
1097 multimode = enable; |
238 | 1098 } |
1099 | |
1100 // scr_get_multiline() | |
261 | 1101 // Public function to get the current multi-line. |
238 | 1102 inline const char *scr_get_multiline() |
1103 { | |
1104 if (multimode && multiline) | |
1105 return multiline; | |
1106 else | |
1107 return ""; | |
1108 } | |
1109 | |
1110 // scr_append_multiline(line) | |
1111 // Public function to append a line to the current multi-line message. | |
1112 // Skip empty leading lines. | |
1113 void scr_append_multiline(const char *line) | |
1114 { | |
1115 static int num; | |
1116 | |
1117 if (!multimode) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
1118 scr_LogPrint(LPRINT_NORMAL, "Error: Not in multi-line message mode!"); |
238 | 1119 return; |
1120 } | |
1121 if (multiline) { | |
1122 int len = strlen(multiline)+strlen(line)+2; | |
252 | 1123 if (len >= HBB_BLOCKSIZE - 1) { |
238 | 1124 // We don't handle single messages with size > HBB_BLOCKSIZE |
1125 // (see hbuf) | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
1126 scr_LogPrint(LPRINT_NORMAL, "Your multi-line message is too big, " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
1127 "this line has not been added."); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
1128 scr_LogPrint(LPRINT_NORMAL, "Please send this part now..."); |
238 | 1129 return; |
1130 } | |
276
627925d885de
Limit the number of lines in multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
271
diff
changeset
|
1131 if (num >= MULTILINE_MAX_LINE_NUMBER) { |
627925d885de
Limit the number of lines in multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
271
diff
changeset
|
1132 // We don't allow too many lines; however the maximum is arbitrary |
627925d885de
Limit the number of lines in multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
271
diff
changeset
|
1133 // (It should be < 1000 yet) |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
1134 scr_LogPrint(LPRINT_NORMAL, "Your message has too many lines, " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
1135 "this one has not been added."); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
1136 scr_LogPrint(LPRINT_NORMAL, "Please send this part now..."); |
276
627925d885de
Limit the number of lines in multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
271
diff
changeset
|
1137 return; |
627925d885de
Limit the number of lines in multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
271
diff
changeset
|
1138 } |
238 | 1139 multiline = g_renew(char, multiline, len); |
1140 strcat(multiline, "\n"); | |
1141 strcat(multiline, line); | |
1142 num++; | |
1143 } else { | |
1144 // First message line (we skip leading empty lines) | |
1145 num = 0; | |
1146 if (line[0]) { | |
1147 multiline = g_new(char, strlen(line)+1); | |
1148 strcpy(multiline, line); | |
1149 num++; | |
1150 } else | |
1151 return; | |
1152 } | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
1153 scr_LogPrint(LPRINT_NORMAL, "Multi-line mode: line #%d added [%.25s...", |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
1154 num, line); |
238 | 1155 } |
1156 | |
173 | 1157 // scr_cmdhisto_addline() |
1158 // Add a line to the inputLine history | |
1159 inline void scr_cmdhisto_addline(char *line) | |
1160 { | |
1161 if (!line || !*line) return; | |
1162 | |
1163 cmdhisto = g_list_append(cmdhisto, g_strdup(line)); | |
1164 } | |
1165 | |
1166 // scr_cmdhisto_prev() | |
1167 // Look for previous line beginning w/ the given mask in the inputLine history | |
175 | 1168 // Returns NULL if none found |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
1169 static const char *scr_cmdhisto_prev(char *mask, guint len) |
173 | 1170 { |
1171 GList *hl; | |
1172 if (!cmdhisto_cur) { | |
1173 hl = g_list_last(cmdhisto); | |
174 | 1174 if (hl) { // backup current line |
1175 strncpy(cmdhisto_backup, mask, INPUTLINE_LENGTH); | |
1176 } | |
173 | 1177 } else { |
1178 hl = g_list_previous(cmdhisto_cur); | |
1179 } | |
1180 while (hl) { | |
1181 if (!strncmp((char*)hl->data, mask, len)) { | |
1182 // Found a match | |
1183 cmdhisto_cur = hl; | |
1184 return (const char*)hl->data; | |
1185 } | |
1186 hl = g_list_previous(hl); | |
1187 } | |
1188 return NULL; | |
1189 } | |
1190 | |
1191 // scr_cmdhisto_next() | |
1192 // Look for next line beginning w/ the given mask in the inputLine history | |
175 | 1193 // Returns NULL if none found |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
1194 static const char *scr_cmdhisto_next(char *mask, guint len) |
173 | 1195 { |
1196 GList *hl; | |
1197 if (!cmdhisto_cur) return NULL; | |
1198 hl = cmdhisto_cur; | |
1199 while ((hl = g_list_next(hl)) != NULL) | |
1200 if (!strncmp((char*)hl->data, mask, len)) { | |
1201 // Found a match | |
1202 cmdhisto_cur = hl; | |
1203 return (const char*)hl->data; | |
1204 } | |
175 | 1205 // If the "backuped" line matches, we'll use it |
1206 if (strncmp(cmdhisto_backup, mask, len)) return NULL; // No match | |
174 | 1207 cmdhisto_cur = NULL; |
1208 return cmdhisto_backup; | |
173 | 1209 } |
1210 | |
195 | 1211 // readline_transpose_chars() |
1212 // Drag the character before point forward over the character at | |
1213 // point, moving point forward as well. If point is at the end of | |
1214 // the line, then this transposes the two characters before point. | |
1215 void readline_transpose_chars() | |
1216 { | |
1217 char swp; | |
1218 | |
1219 if (ptr_inputline == inputLine) return; | |
1220 | |
1221 if (!*ptr_inputline) { // We're at EOL | |
1222 // If line is only 1 char long, nothing to do... | |
1223 if (ptr_inputline == inputLine+1) return; | |
1224 // Transpose the two previous characters | |
1225 swp = *(ptr_inputline-2); | |
1226 *(ptr_inputline-2) = *(ptr_inputline-1); | |
1227 *(ptr_inputline-1) = swp; | |
1228 } else { | |
196 | 1229 // Swap the two characters before the cursor and move right. |
195 | 1230 swp = *(ptr_inputline-1); |
1231 *(ptr_inputline-1) = *ptr_inputline; | |
1232 *ptr_inputline++ = swp; | |
1233 check_offset(1); | |
1234 } | |
1235 } | |
1236 | |
1237 // readline_backward_kill_word() | |
194 | 1238 // Kill the word before the cursor, in input line |
195 | 1239 void readline_backward_kill_word() |
194 | 1240 { |
1241 char *c, *old = ptr_inputline; | |
1242 int spaceallowed = 1; | |
1243 | |
1244 if (ptr_inputline == inputLine) return; | |
1245 | |
1246 for (c = ptr_inputline-1 ; c > inputLine ; c--) | |
1247 if (!isalnum(*c)) { | |
1248 if (*c == ' ') | |
1249 if (!spaceallowed) break; | |
1250 } else spaceallowed = 0; | |
1251 | |
1252 if (c != inputLine || *c != ' ') | |
1253 if ((c < ptr_inputline-1) && (!isalnum(*c))) | |
1254 c++; | |
1255 | |
1256 // Modify the line | |
1257 ptr_inputline = c; | |
1258 for (;;) { | |
1259 *c = *old++; | |
1260 if (!*c++) break; | |
1261 } | |
195 | 1262 check_offset(-1); |
194 | 1263 } |
1264 | |
98 | 1265 // which_row() |
1266 // Tells which row our cursor is in, in the command line. | |
1267 // -1 -> normal text | |
1268 // 0 -> command | |
1269 // 1 -> parameter 1 (etc.) | |
102 | 1270 // If > 0, then *p_row is set to the beginning of the row |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
1271 static int which_row(char **p_row) |
98 | 1272 { |
1273 int row = -1; | |
1274 char *p; | |
1275 int quote = FALSE; | |
1276 | |
1277 // Not a command? | |
1278 if ((ptr_inputline == inputLine) || (inputLine[0] != '/')) | |
1279 return -1; | |
1280 | |
1281 // This is a command | |
1282 row = 0; | |
1283 for (p = inputLine ; p < ptr_inputline ; p++) { | |
1284 if (quote) { | |
1285 if (*p == '"' && *(p-1) != '\\') | |
1286 quote = FALSE; | |
1287 continue; | |
1288 } | |
1289 if (*p == '"' && *(p-1) != '\\') { | |
1290 quote = TRUE; | |
121 | 1291 } else if (*p == ' ') { |
1292 if (*(p-1) != ' ') | |
1293 row++; | |
102 | 1294 *p_row = p+1; |
1295 } | |
98 | 1296 } |
1297 return row; | |
1298 } | |
1299 | |
143 | 1300 // scr_insert_text() |
1301 // Insert the given text at the current cursor position. | |
1302 // The cursor is moved. We don't check if the cursor still is in the screen | |
1303 // after, the caller should do that. | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
1304 static void scr_insert_text(const char *text) |
98 | 1305 { |
1306 char tmpLine[INPUTLINE_LENGTH+1]; | |
1307 int len = strlen(text); | |
1308 // Check the line isn't too long | |
1309 if (strlen(inputLine) + len >= INPUTLINE_LENGTH) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
1310 scr_LogPrint(LPRINT_LOGNORM, "Cannot insert text, line too long."); |
98 | 1311 return; |
1312 } | |
1313 | |
1314 strcpy(tmpLine, ptr_inputline); | |
1315 strcpy(ptr_inputline, text); ptr_inputline += len; | |
1316 strcpy(ptr_inputline, tmpLine); | |
1317 } | |
1318 | |
143 | 1319 // scr_handle_tab() |
1320 // Function called when tab is pressed. | |
1321 // Initiate or continue a completion... | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
1322 static void scr_handle_tab(void) |
98 | 1323 { |
102 | 1324 int nrow; |
1325 char *row; | |
1326 const char *cchar; | |
103 | 1327 guint compl_categ; |
98 | 1328 |
102 | 1329 nrow = which_row(&row); |
98 | 1330 |
103 | 1331 // a) No completion if no leading slash ('cause not a command) |
1332 // b) We can't have more than 2 parameters (we use 2 flags) | |
1333 if (nrow < 0 || nrow > 2) return; | |
102 | 1334 |
103 | 1335 if (nrow == 0) { // Command completion |
1336 row = &inputLine[1]; | |
1337 compl_categ = COMPL_CMD; | |
1338 } else { // Other completion, depending on the command | |
285 | 1339 int alias = FALSE; |
1340 cmd *com; | |
1341 char *xpline = expandalias(inputLine); | |
1342 com = cmd_get(xpline); | |
1343 if (xpline != inputLine) { | |
1344 // This is an alias, so we can't complete rows > 0 | |
1345 alias = TRUE; | |
1346 g_free(xpline); | |
1347 } | |
1348 if ((!com && (!alias || !completion_started)) || !row) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
1349 scr_LogPrint(LPRINT_NORMAL, "I cannot complete that..."); |
103 | 1350 return; |
1351 } | |
285 | 1352 if (!alias) |
1353 compl_categ = com->completion_flags[nrow-1]; | |
1354 else | |
1355 compl_categ = 0; | |
103 | 1356 } |
1357 | |
1358 if (!completion_started) { | |
1359 GSList *list = compl_get_category_list(compl_categ); | |
1360 if (list) { | |
1361 char *prefix = g_strndup(row, ptr_inputline-row); | |
1362 // Init completion | |
1363 new_completion(prefix, list); | |
1364 g_free(prefix); | |
1365 // Now complete | |
98 | 1366 cchar = complete(); |
1367 if (cchar) | |
1368 scr_insert_text(cchar); | |
103 | 1369 completion_started = TRUE; |
98 | 1370 } |
103 | 1371 } else { // Completion already initialized |
1372 char *c; | |
1373 guint back = cancel_completion(); | |
1374 // Remove $back chars | |
1375 ptr_inputline -= back; | |
1376 c = ptr_inputline; | |
1377 for ( ; *c ; c++) | |
1378 *c = *(c+back); | |
1379 // Now complete again | |
1380 cchar = complete(); | |
1381 if (cchar) | |
1382 scr_insert_text(cchar); | |
102 | 1383 } |
98 | 1384 } |
1385 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
1386 static void scr_cancel_current_completion(void) |
98 | 1387 { |
1388 char *c; | |
1389 guint back = cancel_completion(); | |
1390 // Remove $back chars | |
1391 ptr_inputline -= back; | |
1392 c = ptr_inputline; | |
1393 for ( ; *c ; c++) | |
1394 *c = *(c+back); | |
1395 } | |
1396 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
1397 static void scr_end_current_completion(void) |
98 | 1398 { |
1399 done_completion(); | |
1400 completion_started = FALSE; | |
1401 } | |
1402 | |
24 | 1403 // check_offset(int direction) |
1404 // Check inputline_offset value, and make sure the cursor is inside the | |
1405 // screen. | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
1406 static inline void check_offset(int direction) |
24 | 1407 { |
1408 // Left side | |
1409 if (inputline_offset && direction <= 0) { | |
1410 while (ptr_inputline <= (char*)&inputLine + inputline_offset) { | |
1411 if (inputline_offset) { | |
1412 inputline_offset -= 5; | |
1413 if (inputline_offset < 0) | |
1414 inputline_offset = 0; | |
1415 } | |
1416 } | |
1417 } | |
1418 // Right side | |
1419 if (direction >= 0) { | |
1420 while (ptr_inputline >= inputline_offset + (char*)&inputLine + maxX) | |
1421 inputline_offset += 5; | |
1422 } | |
1423 } | |
1424 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
1425 static inline void refresh_inputline(void) |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1426 { |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1427 mvwprintw(inputWnd, 0,0, "%s", inputLine + inputline_offset); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1428 wclrtoeol(inputWnd); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1429 if (*ptr_inputline) |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1430 wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine - inputline_offset); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1431 } |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1432 |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1433 void scr_handle_sigint(void) |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1434 { |
365
ddb6593bedc9
Fix segfault when mcabber receives an INT signal (Ctrl-C) early
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1435 if (!Curses) return; |
315
65aa05520556
First Ctrl-C now also leaves multi-line message mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1436 // Leave multi-line mode |
65aa05520556
First Ctrl-C now also leaves multi-line message mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1437 process_command("/msay abort"); |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1438 // Same as Ctrl-g, now |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1439 scr_cancel_current_completion(); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1440 scr_end_current_completion(); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1441 check_offset(-1); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1442 refresh_inputline(); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1443 } |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1444 |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1445 int scr_Getch(void) |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1446 { |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1447 int ch; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1448 ch = wgetch(inputWnd); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1449 return ch; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1450 } |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1451 |
44 | 1452 // process_key(key) |
1453 // Handle the pressed key, in the command line (bottom). | |
29 | 1454 int process_key(int key) |
24 | 1455 { |
1456 if (isprint(key)) { | |
1457 char tmpLine[INPUTLINE_LENGTH+1]; | |
1458 | |
1459 // Check the line isn't too long | |
1460 if (strlen(inputLine) >= INPUTLINE_LENGTH) | |
1461 return 0; | |
1462 | |
1463 // Insert char | |
1464 strcpy(tmpLine, ptr_inputline); | |
1465 *ptr_inputline++ = key; | |
1466 strcpy(ptr_inputline, tmpLine); | |
1467 check_offset(1); | |
1468 } else { | |
1469 switch(key) { | |
232 | 1470 case 8: // Ctrl-h |
1471 case 127: // Backspace too | |
24 | 1472 case KEY_BACKSPACE: |
1473 if (ptr_inputline != (char*)&inputLine) { | |
42 | 1474 char *c = --ptr_inputline; |
1475 for ( ; *c ; c++) | |
1476 *c = *(c+1); | |
24 | 1477 check_offset(-1); |
1478 } | |
1479 break; | |
238 | 1480 case KEY_DC:// Del |
24 | 1481 if (*ptr_inputline) |
1482 strcpy(ptr_inputline, ptr_inputline+1); | |
1483 break; | |
1484 case KEY_LEFT: | |
1485 if (ptr_inputline != (char*)&inputLine) { | |
1486 ptr_inputline--; | |
1487 check_offset(-1); | |
1488 } | |
1489 break; | |
1490 case KEY_RIGHT: | |
1491 if (*ptr_inputline) | |
1492 ptr_inputline++; | |
1493 check_offset(1); | |
1494 break; | |
98 | 1495 case 7: // Ctrl-g |
1496 scr_cancel_current_completion(); | |
1497 scr_end_current_completion(); | |
1498 check_offset(-1); | |
1499 break; | |
24 | 1500 case 9: // Tab |
98 | 1501 scr_handle_tab(); |
1502 check_offset(0); | |
24 | 1503 break; |
1504 case '\n': // Enter | |
263 | 1505 case 15: // Ctrl-o ("accept-line-and-down-history") |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1506 scr_CheckAutoAway(TRUE); |
29 | 1507 if (process_line(inputLine)) |
24 | 1508 return 255; |
173 | 1509 // Add line to history |
1510 scr_cmdhisto_addline(inputLine); | |
1511 // Reset the line | |
24 | 1512 ptr_inputline = inputLine; |
1513 *ptr_inputline = 0; | |
1514 inputline_offset = 0; | |
263 | 1515 |
1516 if (key == '\n') // Enter | |
1517 { | |
1518 // Reset history line pointer | |
1519 cmdhisto_cur = NULL; | |
1520 } else { // down-history | |
1521 // Use next history line instead of a blank line | |
1522 const char *l = scr_cmdhisto_next("", 0); | |
1523 if (l) | |
1524 strcpy(inputLine, l); | |
1525 // Reset backup history line | |
1526 cmdhisto_backup[0] = 0; | |
1527 } | |
24 | 1528 break; |
1529 case KEY_UP: | |
175 | 1530 { |
1531 const char *l = scr_cmdhisto_prev(inputLine, | |
1532 ptr_inputline-inputLine); | |
1533 if (l) { | |
1534 strcpy(inputLine, l); | |
1535 } | |
1536 } | |
24 | 1537 break; |
1538 case KEY_DOWN: | |
175 | 1539 { |
1540 const char *l = scr_cmdhisto_next(inputLine, | |
1541 ptr_inputline-inputLine); | |
1542 if (l) { | |
1543 strcpy(inputLine, l); | |
1544 } | |
1545 } | |
24 | 1546 break; |
1547 case KEY_PPAGE: | |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1548 scr_CheckAutoAway(TRUE); |
175 | 1549 scr_RosterUp(); |
24 | 1550 break; |
1551 case KEY_NPAGE: | |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1552 scr_CheckAutoAway(TRUE); |
175 | 1553 scr_RosterDown(); |
24 | 1554 break; |
1555 case KEY_HOME: | |
1556 case 1: | |
1557 ptr_inputline = inputLine; | |
1558 inputline_offset = 0; | |
1559 break; | |
1560 case KEY_END: | |
1561 case 5: | |
1562 for (; *ptr_inputline; ptr_inputline++) ; | |
1563 check_offset(1); | |
1564 break; | |
1565 case 21: // Ctrl-u | |
1566 strcpy(inputLine, ptr_inputline); | |
1567 ptr_inputline = inputLine; | |
1568 inputline_offset = 0; | |
1569 break; | |
1570 case KEY_EOL: | |
1571 case 11: // Ctrl-k | |
1572 *ptr_inputline = 0; | |
1573 break; | |
1574 case 16: // Ctrl-p | |
369
499170ed71c9
Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents:
365
diff
changeset
|
1575 scr_BufferScrollUpDown(-1); |
24 | 1576 break; |
1577 case 14: // Ctrl-n | |
369
499170ed71c9
Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents:
365
diff
changeset
|
1578 scr_BufferScrollUpDown(1); |
24 | 1579 break; |
196 | 1580 case 17: // Ctrl-q |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1581 scr_CheckAutoAway(TRUE); |
236 | 1582 scr_RosterUnreadMessage(1); // next unread message |
196 | 1583 break; |
195 | 1584 case 20: // Ctrl-t |
1585 readline_transpose_chars(); | |
1586 break; | |
194 | 1587 case 23: // Ctrl-w |
195 | 1588 readline_backward_kill_word(); |
194 | 1589 break; |
24 | 1590 case 27: // ESC |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1591 scr_CheckAutoAway(TRUE); |
24 | 1592 currentWindow = NULL; |
1593 chatmode = FALSE; | |
119 | 1594 if (current_buddy) |
1595 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); | |
24 | 1596 top_panel(chatPanel); |
1597 top_panel(inputPanel); | |
157 | 1598 update_panels(); |
24 | 1599 break; |
151 | 1600 case 12: // Ctrl-l |
1601 case KEY_RESIZE: | |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1602 scr_CheckAutoAway(TRUE); |
151 | 1603 scr_Resize(); |
1604 break; | |
24 | 1605 default: |
288 | 1606 { |
1607 const gchar *boundcmd = isbound(key); | |
1608 if (boundcmd) { | |
1609 gchar *cmd = g_strdup_printf("/%s", boundcmd); | |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1610 scr_CheckAutoAway(TRUE); |
288 | 1611 if (process_command(cmd)) |
1612 return 255; | |
1613 g_free(cmd); | |
1614 } else { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
1615 scr_LogPrint(LPRINT_NORMAL, "Unknown key=%d", key); |
288 | 1616 if (utf8_mode) |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
1617 scr_LogPrint(LPRINT_NORMAL, |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
1618 "WARNING: UTF-8 not yet supported!"); |
288 | 1619 } |
1620 } | |
24 | 1621 } |
1622 } | |
157 | 1623 if (completion_started && key != 9 && key != KEY_RESIZE) |
98 | 1624 scr_end_current_completion(); |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1625 refresh_inputline(); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1626 if (!update_roster) |
157 | 1627 doupdate(); |
24 | 1628 return 0; |
1629 } |