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