Mercurial > ~mikael > mcabber > hg
annotate mcabber/src/screen.c @ 329:7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 17 Jul 2005 21:16:15 +0100 |
parents | 83d129adde03 |
children | a9013124ede6 |
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() |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
660 // Display the buddylist (not really the roster) 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 | |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
810 // set_current_buddy(newbuddy) |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
811 // 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
|
812 // 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
|
813 static void set_current_buddy(GList *newbuddy) |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
814 { |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
815 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
|
816 /* 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
|
817 * 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
|
818 * buddy_getstatus() call. |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
819 */ |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
820 |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
821 if (!current_buddy || !newbuddy) return; |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
822 if (newbuddy == current_buddy) return; |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
823 |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
824 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
|
825 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
826 current_buddy = newbuddy; |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
827 // 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
|
828 if (chatmode) |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
829 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
|
830 // 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
|
831 // 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
|
832 // 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
|
833 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
|
834 buddylist_build(); |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
835 update_roster = TRUE; |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
836 } |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
837 |
143 | 838 // scr_RosterTop() |
839 // Go to the first buddy in the buddylist | |
105 | 840 void scr_RosterTop(void) |
104 | 841 { |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
842 set_current_buddy(buddylist); |
104 | 843 if (chatmode) |
844 scr_ShowBuddyWindow(); | |
845 } | |
846 | |
143 | 847 // scr_RosterBottom() |
848 // Go to the last buddy in the buddylist | |
105 | 849 void scr_RosterBottom(void) |
104 | 850 { |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
851 set_current_buddy(g_list_last(buddylist)); |
104 | 852 if (chatmode) |
853 scr_ShowBuddyWindow(); | |
854 } | |
855 | |
143 | 856 // scr_RosterUp() |
857 // Go to the previous buddy in the buddylist | |
105 | 858 void scr_RosterUp(void) |
81 | 859 { |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
860 set_current_buddy(g_list_previous(current_buddy)); |
104 | 861 if (chatmode) |
862 scr_ShowBuddyWindow(); | |
81 | 863 } |
864 | |
143 | 865 // scr_RosterDown() |
866 // Go to the next buddy in the buddylist | |
105 | 867 void scr_RosterDown(void) |
81 | 868 { |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
869 set_current_buddy(g_list_next(current_buddy)); |
104 | 870 if (chatmode) |
871 scr_ShowBuddyWindow(); | |
81 | 872 } |
873 | |
265 | 874 // scr_RosterSearch(str) |
875 // Look forward for a buddy with jid/name containing str. | |
876 void scr_RosterSearch(char *str) | |
877 { | |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
878 set_current_buddy(buddy_search(str)); |
265 | 879 if (chatmode) |
880 scr_ShowBuddyWindow(); | |
881 } | |
882 | |
236 | 883 // scr_RosterUnreadMessage(next) |
884 // Go to a new message. If next is not null, try to go to the next new | |
885 // message. If it is not possible or if next is NULL, go to the first new | |
886 // message from unread_list. | |
887 void scr_RosterUnreadMessage(int next) | |
888 { | |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
889 gpointer unread_ptr; |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
890 gpointer refbuddata; |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
891 gpointer ngroup; |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
892 GList *nbuddy; |
236 | 893 |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
894 if (!current_buddy) return; |
236 | 895 |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
896 if (next) refbuddata = BUDDATA(current_buddy); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
897 else refbuddata = NULL; |
236 | 898 |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
899 unread_ptr = unread_msg(refbuddata); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
900 if (!unread_ptr) return; |
236 | 901 |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
902 // 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
|
903 ngroup = buddy_getgroup(unread_ptr); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
904 if (buddy_getflags(ngroup) & ROSTER_FLAG_HIDE) { |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
905 buddy_setflags(ngroup, ROSTER_FLAG_HIDE, FALSE); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
906 buddylist_build(); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
907 } |
236 | 908 |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
909 nbuddy = g_list_find(buddylist, unread_ptr); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
910 if (nbuddy) { |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
911 set_current_buddy(nbuddy); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
912 if (chatmode) scr_ShowBuddyWindow(); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
913 } else scr_LogPrint("Error: nbuddy == NULL"); |
236 | 914 } |
915 | |
143 | 916 // scr_ScrollUp() |
917 // Scroll up the current buddy window, half a screen. | |
105 | 918 void scr_ScrollUp(void) |
919 { | |
920 const gchar *jid; | |
921 window_entry_t *win_entry; | |
922 int n, nblines; | |
923 GList *hbuf_top; | |
924 | |
925 // Get win_entry | |
926 if (!current_buddy) | |
927 return; | |
928 jid = CURRENT_JID; | |
929 if (!jid) | |
930 return; | |
931 win_entry = scr_SearchWindow(jid); | |
932 if (!win_entry) | |
933 return; | |
934 | |
935 // Scroll up half a screen (or less) | |
936 nblines = CHAT_WIN_HEIGHT/2-1; | |
937 hbuf_top = win_entry->top; | |
938 if (!hbuf_top) { | |
939 hbuf_top = g_list_last(win_entry->hbuf); | |
109 | 940 if (!win_entry->cleared) |
941 nblines *= 3; | |
942 else | |
943 win_entry->cleared = FALSE; | |
105 | 944 } |
945 | |
946 n = 0; | |
947 while (hbuf_top && n < nblines && g_list_previous(hbuf_top)) { | |
948 hbuf_top = g_list_previous(hbuf_top); | |
949 n++; | |
950 } | |
951 win_entry->top = hbuf_top; | |
952 | |
953 // Refresh the window | |
954 scr_UpdateWindow(win_entry); | |
955 | |
956 // Finished :) | |
957 update_panels(); | |
958 doupdate(); | |
959 } | |
960 | |
143 | 961 // scr_ScrollDown() |
962 // Scroll down the current buddy window, half a screen. | |
105 | 963 void scr_ScrollDown(void) |
964 { | |
965 const gchar *jid; | |
966 window_entry_t *win_entry; | |
967 int n, nblines; | |
968 GList *hbuf_top; | |
969 | |
970 // Get win_entry | |
971 if (!current_buddy) | |
972 return; | |
973 jid = CURRENT_JID; | |
974 if (!jid) | |
975 return; | |
976 win_entry = scr_SearchWindow(jid); | |
977 if (!win_entry) | |
978 return; | |
979 | |
980 // Scroll down half a screen (or less) | |
981 nblines = CHAT_WIN_HEIGHT/2-1; | |
982 hbuf_top = win_entry->top; | |
983 | |
984 for (n=0 ; hbuf_top && n < nblines ; n++) | |
985 hbuf_top = g_list_next(hbuf_top); | |
986 win_entry->top = hbuf_top; | |
987 // Check if we are at the bottom | |
988 for (n=0 ; hbuf_top && n < CHAT_WIN_HEIGHT-1 ; n++) | |
989 hbuf_top = g_list_next(hbuf_top); | |
990 if (!hbuf_top) | |
991 win_entry->top = NULL; // End reached | |
992 | |
993 // Refresh the window | |
994 scr_UpdateWindow(win_entry); | |
995 | |
996 // Finished :) | |
997 update_panels(); | |
998 doupdate(); | |
999 } | |
1000 | |
143 | 1001 // scr_Clear() |
1002 // Clear the current buddy window (used for the /clear command) | |
108 | 1003 void scr_Clear(void) |
1004 { | |
1005 const gchar *jid; | |
1006 window_entry_t *win_entry; | |
1007 | |
1008 // Get win_entry | |
1009 if (!current_buddy) | |
1010 return; | |
1011 jid = CURRENT_JID; | |
1012 if (!jid) | |
1013 return; | |
1014 win_entry = scr_SearchWindow(jid); | |
1015 if (!win_entry) | |
1016 return; | |
1017 | |
1018 win_entry->cleared = TRUE; | |
109 | 1019 win_entry->top = NULL; |
108 | 1020 |
1021 // Refresh the window | |
1022 scr_UpdateWindow(win_entry); | |
1023 | |
1024 // Finished :) | |
1025 update_panels(); | |
1026 doupdate(); | |
1027 } | |
1028 | |
187 | 1029 // scr_BufferTop() |
1030 // Jump to the head of the current buddy window | |
1031 void scr_BufferTop(void) | |
1032 { | |
1033 const gchar *jid; | |
1034 window_entry_t *win_entry; | |
1035 | |
1036 // Get win_entry | |
1037 if (!current_buddy) return; | |
1038 jid = CURRENT_JID; | |
1039 if (!jid) return; | |
1040 win_entry = scr_SearchWindow(jid); | |
1041 | |
1042 if (!win_entry) return; | |
1043 | |
1044 win_entry->cleared = FALSE; | |
1045 win_entry->top = g_list_first(win_entry->hbuf); | |
1046 | |
1047 // Refresh the window | |
1048 scr_UpdateWindow(win_entry); | |
1049 | |
1050 // Finished :) | |
1051 update_panels(); | |
1052 doupdate(); | |
1053 } | |
1054 | |
1055 // scr_BufferBottom() | |
1056 // Jump to the end of the current buddy window | |
1057 void scr_BufferBottom(void) | |
1058 { | |
1059 const gchar *jid; | |
1060 window_entry_t *win_entry; | |
1061 | |
1062 // Get win_entry | |
1063 if (!current_buddy) return; | |
1064 jid = CURRENT_JID; | |
1065 if (!jid) return; | |
1066 win_entry = scr_SearchWindow(jid); | |
1067 | |
1068 if (!win_entry) return; | |
1069 | |
1070 win_entry->cleared = FALSE; | |
1071 win_entry->top = NULL; | |
1072 | |
1073 // Refresh the window | |
1074 scr_UpdateWindow(win_entry); | |
1075 | |
1076 // Finished :) | |
1077 update_panels(); | |
1078 doupdate(); | |
1079 } | |
1080 | |
44 | 1081 // scr_LogPrint(...) |
1082 // Display a message in the log window. | |
24 | 1083 void scr_LogPrint(const char *fmt, ...) |
1084 { | |
1085 time_t timestamp; | |
1086 char *buffer; | |
1087 va_list ap; | |
1088 | |
153 | 1089 do { |
157 | 1090 buffer = (char *) calloc(1, 1024); |
153 | 1091 } while (!buffer); |
24 | 1092 |
1093 timestamp = time(NULL); | |
1094 strftime(buffer, 64, "[%H:%M:%S] ", localtime(×tamp)); | |
1095 wprintw(logWnd, "\n%s", buffer); | |
1096 | |
1097 va_start(ap, fmt); | |
153 | 1098 vsnprintf(buffer, 1024, fmt, ap); |
24 | 1099 va_end(ap); |
1100 | |
1101 wprintw(logWnd, "%s", buffer); | |
1102 free(buffer); | |
1103 | |
1104 update_panels(); | |
1105 doupdate(); | |
1106 } | |
1107 | |
143 | 1108 // scr_set_chatmode() |
261 | 1109 // Public function to (un)set chatmode... |
129 | 1110 inline void scr_set_chatmode(int enable) |
1111 { | |
1112 chatmode = enable; | |
1113 } | |
1114 | |
238 | 1115 // scr_get_multimode() |
261 | 1116 // Public function to get multimode status... |
238 | 1117 inline int scr_get_multimode() |
1118 { | |
1119 return multimode; | |
1120 } | |
1121 | |
1122 // scr_set_multimode() | |
261 | 1123 // Public function to (un)set multimode... |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
252
diff
changeset
|
1124 // Convention: |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
252
diff
changeset
|
1125 // 0 = disabled / 1 = multimode / 2 = multimode verbatim (commands disabled) |
238 | 1126 inline void scr_set_multimode(int enable) |
1127 { | |
1128 if (multiline) { | |
1129 g_free(multiline); | |
1130 multiline = NULL; | |
1131 } | |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
252
diff
changeset
|
1132 multimode = enable; |
238 | 1133 } |
1134 | |
1135 // scr_get_multiline() | |
261 | 1136 // Public function to get the current multi-line. |
238 | 1137 inline const char *scr_get_multiline() |
1138 { | |
1139 if (multimode && multiline) | |
1140 return multiline; | |
1141 else | |
1142 return ""; | |
1143 } | |
1144 | |
1145 // scr_append_multiline(line) | |
1146 // Public function to append a line to the current multi-line message. | |
1147 // Skip empty leading lines. | |
1148 void scr_append_multiline(const char *line) | |
1149 { | |
1150 static int num; | |
1151 | |
1152 if (!multimode) { | |
1153 scr_LogPrint("Error: Not in multi-line message mode!"); | |
1154 return; | |
1155 } | |
1156 if (multiline) { | |
1157 int len = strlen(multiline)+strlen(line)+2; | |
252 | 1158 if (len >= HBB_BLOCKSIZE - 1) { |
238 | 1159 // We don't handle single messages with size > HBB_BLOCKSIZE |
1160 // (see hbuf) | |
1161 scr_LogPrint("Your multi-line message is too big, this line has " | |
1162 "not been added."); | |
1163 scr_LogPrint("Please send this part now..."); | |
1164 return; | |
1165 } | |
276
627925d885de
Limit the number of lines in multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
271
diff
changeset
|
1166 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
|
1167 // 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
|
1168 // (It should be < 1000 yet) |
627925d885de
Limit the number of lines in multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
271
diff
changeset
|
1169 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
|
1170 "not been added."); |
627925d885de
Limit the number of lines in multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
271
diff
changeset
|
1171 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
|
1172 return; |
627925d885de
Limit the number of lines in multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
271
diff
changeset
|
1173 } |
238 | 1174 multiline = g_renew(char, multiline, len); |
1175 strcat(multiline, "\n"); | |
1176 strcat(multiline, line); | |
1177 num++; | |
1178 } else { | |
1179 // First message line (we skip leading empty lines) | |
1180 num = 0; | |
1181 if (line[0]) { | |
1182 multiline = g_new(char, strlen(line)+1); | |
1183 strcpy(multiline, line); | |
1184 num++; | |
1185 } else | |
1186 return; | |
1187 } | |
1188 scr_LogPrint("Multi-line mode: line #%d added [%.25s...", num, line); | |
1189 } | |
1190 | |
173 | 1191 // scr_cmdhisto_addline() |
1192 // Add a line to the inputLine history | |
1193 inline void scr_cmdhisto_addline(char *line) | |
1194 { | |
1195 if (!line || !*line) return; | |
1196 | |
1197 cmdhisto = g_list_append(cmdhisto, g_strdup(line)); | |
1198 } | |
1199 | |
1200 // scr_cmdhisto_prev() | |
1201 // Look for previous line beginning w/ the given mask in the inputLine history | |
175 | 1202 // Returns NULL if none found |
173 | 1203 const char *scr_cmdhisto_prev(char *mask, guint len) |
1204 { | |
1205 GList *hl; | |
1206 if (!cmdhisto_cur) { | |
1207 hl = g_list_last(cmdhisto); | |
174 | 1208 if (hl) { // backup current line |
1209 strncpy(cmdhisto_backup, mask, INPUTLINE_LENGTH); | |
1210 } | |
173 | 1211 } else { |
1212 hl = g_list_previous(cmdhisto_cur); | |
1213 } | |
1214 while (hl) { | |
1215 if (!strncmp((char*)hl->data, mask, len)) { | |
1216 // Found a match | |
1217 cmdhisto_cur = hl; | |
1218 return (const char*)hl->data; | |
1219 } | |
1220 hl = g_list_previous(hl); | |
1221 } | |
1222 return NULL; | |
1223 } | |
1224 | |
1225 // scr_cmdhisto_next() | |
1226 // Look for next line beginning w/ the given mask in the inputLine history | |
175 | 1227 // Returns NULL if none found |
173 | 1228 const char *scr_cmdhisto_next(char *mask, guint len) |
1229 { | |
1230 GList *hl; | |
1231 if (!cmdhisto_cur) return NULL; | |
1232 hl = cmdhisto_cur; | |
1233 while ((hl = g_list_next(hl)) != NULL) | |
1234 if (!strncmp((char*)hl->data, mask, len)) { | |
1235 // Found a match | |
1236 cmdhisto_cur = hl; | |
1237 return (const char*)hl->data; | |
1238 } | |
175 | 1239 // If the "backuped" line matches, we'll use it |
1240 if (strncmp(cmdhisto_backup, mask, len)) return NULL; // No match | |
174 | 1241 cmdhisto_cur = NULL; |
1242 return cmdhisto_backup; | |
173 | 1243 } |
1244 | |
195 | 1245 // readline_transpose_chars() |
1246 // Drag the character before point forward over the character at | |
1247 // point, moving point forward as well. If point is at the end of | |
1248 // the line, then this transposes the two characters before point. | |
1249 void readline_transpose_chars() | |
1250 { | |
1251 char swp; | |
1252 | |
1253 if (ptr_inputline == inputLine) return; | |
1254 | |
1255 if (!*ptr_inputline) { // We're at EOL | |
1256 // If line is only 1 char long, nothing to do... | |
1257 if (ptr_inputline == inputLine+1) return; | |
1258 // Transpose the two previous characters | |
1259 swp = *(ptr_inputline-2); | |
1260 *(ptr_inputline-2) = *(ptr_inputline-1); | |
1261 *(ptr_inputline-1) = swp; | |
1262 } else { | |
196 | 1263 // Swap the two characters before the cursor and move right. |
195 | 1264 swp = *(ptr_inputline-1); |
1265 *(ptr_inputline-1) = *ptr_inputline; | |
1266 *ptr_inputline++ = swp; | |
1267 check_offset(1); | |
1268 } | |
1269 } | |
1270 | |
1271 // readline_backward_kill_word() | |
194 | 1272 // Kill the word before the cursor, in input line |
195 | 1273 void readline_backward_kill_word() |
194 | 1274 { |
1275 char *c, *old = ptr_inputline; | |
1276 int spaceallowed = 1; | |
1277 | |
1278 if (ptr_inputline == inputLine) return; | |
1279 | |
1280 for (c = ptr_inputline-1 ; c > inputLine ; c--) | |
1281 if (!isalnum(*c)) { | |
1282 if (*c == ' ') | |
1283 if (!spaceallowed) break; | |
1284 } else spaceallowed = 0; | |
1285 | |
1286 if (c != inputLine || *c != ' ') | |
1287 if ((c < ptr_inputline-1) && (!isalnum(*c))) | |
1288 c++; | |
1289 | |
1290 // Modify the line | |
1291 ptr_inputline = c; | |
1292 for (;;) { | |
1293 *c = *old++; | |
1294 if (!*c++) break; | |
1295 } | |
195 | 1296 check_offset(-1); |
194 | 1297 } |
1298 | |
98 | 1299 // which_row() |
1300 // Tells which row our cursor is in, in the command line. | |
1301 // -1 -> normal text | |
1302 // 0 -> command | |
1303 // 1 -> parameter 1 (etc.) | |
102 | 1304 // If > 0, then *p_row is set to the beginning of the row |
1305 int which_row(char **p_row) | |
98 | 1306 { |
1307 int row = -1; | |
1308 char *p; | |
1309 int quote = FALSE; | |
1310 | |
1311 // Not a command? | |
1312 if ((ptr_inputline == inputLine) || (inputLine[0] != '/')) | |
1313 return -1; | |
1314 | |
1315 // This is a command | |
1316 row = 0; | |
1317 for (p = inputLine ; p < ptr_inputline ; p++) { | |
1318 if (quote) { | |
1319 if (*p == '"' && *(p-1) != '\\') | |
1320 quote = FALSE; | |
1321 continue; | |
1322 } | |
1323 if (*p == '"' && *(p-1) != '\\') { | |
1324 quote = TRUE; | |
121 | 1325 } else if (*p == ' ') { |
1326 if (*(p-1) != ' ') | |
1327 row++; | |
102 | 1328 *p_row = p+1; |
1329 } | |
98 | 1330 } |
1331 return row; | |
1332 } | |
1333 | |
143 | 1334 // scr_insert_text() |
1335 // Insert the given text at the current cursor position. | |
1336 // The cursor is moved. We don't check if the cursor still is in the screen | |
1337 // after, the caller should do that. | |
98 | 1338 void scr_insert_text(const char *text) |
1339 { | |
1340 char tmpLine[INPUTLINE_LENGTH+1]; | |
1341 int len = strlen(text); | |
1342 // Check the line isn't too long | |
1343 if (strlen(inputLine) + len >= INPUTLINE_LENGTH) { | |
1344 scr_LogPrint("Cannot insert text, line too long."); | |
1345 return; | |
1346 } | |
1347 | |
1348 strcpy(tmpLine, ptr_inputline); | |
1349 strcpy(ptr_inputline, text); ptr_inputline += len; | |
1350 strcpy(ptr_inputline, tmpLine); | |
1351 } | |
1352 | |
143 | 1353 // scr_handle_tab() |
1354 // Function called when tab is pressed. | |
1355 // Initiate or continue a completion... | |
98 | 1356 void scr_handle_tab(void) |
1357 { | |
102 | 1358 int nrow; |
1359 char *row; | |
1360 const char *cchar; | |
103 | 1361 guint compl_categ; |
98 | 1362 |
102 | 1363 nrow = which_row(&row); |
98 | 1364 |
103 | 1365 // a) No completion if no leading slash ('cause not a command) |
1366 // b) We can't have more than 2 parameters (we use 2 flags) | |
1367 if (nrow < 0 || nrow > 2) return; | |
102 | 1368 |
103 | 1369 if (nrow == 0) { // Command completion |
1370 row = &inputLine[1]; | |
1371 compl_categ = COMPL_CMD; | |
1372 } else { // Other completion, depending on the command | |
285 | 1373 int alias = FALSE; |
1374 cmd *com; | |
1375 char *xpline = expandalias(inputLine); | |
1376 com = cmd_get(xpline); | |
1377 if (xpline != inputLine) { | |
1378 // This is an alias, so we can't complete rows > 0 | |
1379 alias = TRUE; | |
1380 g_free(xpline); | |
1381 } | |
1382 if ((!com && (!alias || !completion_started)) || !row) { | |
103 | 1383 scr_LogPrint("I cannot complete that..."); |
1384 return; | |
1385 } | |
285 | 1386 if (!alias) |
1387 compl_categ = com->completion_flags[nrow-1]; | |
1388 else | |
1389 compl_categ = 0; | |
103 | 1390 } |
1391 | |
1392 if (!completion_started) { | |
1393 GSList *list = compl_get_category_list(compl_categ); | |
1394 if (list) { | |
1395 char *prefix = g_strndup(row, ptr_inputline-row); | |
1396 // Init completion | |
1397 new_completion(prefix, list); | |
1398 g_free(prefix); | |
1399 // Now complete | |
98 | 1400 cchar = complete(); |
1401 if (cchar) | |
1402 scr_insert_text(cchar); | |
103 | 1403 completion_started = TRUE; |
98 | 1404 } |
103 | 1405 } else { // Completion already initialized |
1406 char *c; | |
1407 guint back = cancel_completion(); | |
1408 // Remove $back chars | |
1409 ptr_inputline -= back; | |
1410 c = ptr_inputline; | |
1411 for ( ; *c ; c++) | |
1412 *c = *(c+back); | |
1413 // Now complete again | |
1414 cchar = complete(); | |
1415 if (cchar) | |
1416 scr_insert_text(cchar); | |
102 | 1417 } |
98 | 1418 } |
1419 | |
1420 void scr_cancel_current_completion(void) | |
1421 { | |
1422 char *c; | |
1423 guint back = cancel_completion(); | |
1424 // Remove $back chars | |
1425 ptr_inputline -= back; | |
1426 c = ptr_inputline; | |
1427 for ( ; *c ; c++) | |
1428 *c = *(c+back); | |
1429 } | |
1430 | |
1431 void scr_end_current_completion(void) | |
1432 { | |
1433 done_completion(); | |
1434 completion_started = FALSE; | |
1435 } | |
1436 | |
24 | 1437 // check_offset(int direction) |
1438 // Check inputline_offset value, and make sure the cursor is inside the | |
1439 // screen. | |
1440 inline void check_offset(int direction) | |
1441 { | |
1442 // Left side | |
1443 if (inputline_offset && direction <= 0) { | |
1444 while (ptr_inputline <= (char*)&inputLine + inputline_offset) { | |
1445 if (inputline_offset) { | |
1446 inputline_offset -= 5; | |
1447 if (inputline_offset < 0) | |
1448 inputline_offset = 0; | |
1449 } | |
1450 } | |
1451 } | |
1452 // Right side | |
1453 if (direction >= 0) { | |
1454 while (ptr_inputline >= inputline_offset + (char*)&inputLine + maxX) | |
1455 inputline_offset += 5; | |
1456 } | |
1457 } | |
1458 | |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1459 inline void refresh_inputline(void) |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1460 { |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1461 mvwprintw(inputWnd, 0,0, "%s", inputLine + inputline_offset); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1462 wclrtoeol(inputWnd); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1463 if (*ptr_inputline) |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1464 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
|
1465 } |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1466 |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1467 void scr_handle_sigint(void) |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1468 { |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1469 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
|
1470 // Same as Ctrl-g, now |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1471 scr_cancel_current_completion(); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1472 scr_end_current_completion(); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1473 check_offset(-1); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1474 refresh_inputline(); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1475 } |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1476 |
44 | 1477 // process_key(key) |
1478 // Handle the pressed key, in the command line (bottom). | |
29 | 1479 int process_key(int key) |
24 | 1480 { |
1481 if (isprint(key)) { | |
1482 char tmpLine[INPUTLINE_LENGTH+1]; | |
1483 | |
1484 // Check the line isn't too long | |
1485 if (strlen(inputLine) >= INPUTLINE_LENGTH) | |
1486 return 0; | |
1487 | |
1488 // Insert char | |
1489 strcpy(tmpLine, ptr_inputline); | |
1490 *ptr_inputline++ = key; | |
1491 strcpy(ptr_inputline, tmpLine); | |
1492 check_offset(1); | |
1493 } else { | |
1494 switch(key) { | |
232 | 1495 case 8: // Ctrl-h |
1496 case 127: // Backspace too | |
24 | 1497 case KEY_BACKSPACE: |
1498 if (ptr_inputline != (char*)&inputLine) { | |
42 | 1499 char *c = --ptr_inputline; |
1500 for ( ; *c ; c++) | |
1501 *c = *(c+1); | |
24 | 1502 check_offset(-1); |
1503 } | |
1504 break; | |
238 | 1505 case KEY_DC:// Del |
24 | 1506 if (*ptr_inputline) |
1507 strcpy(ptr_inputline, ptr_inputline+1); | |
1508 break; | |
1509 case KEY_LEFT: | |
1510 if (ptr_inputline != (char*)&inputLine) { | |
1511 ptr_inputline--; | |
1512 check_offset(-1); | |
1513 } | |
1514 break; | |
1515 case KEY_RIGHT: | |
1516 if (*ptr_inputline) | |
1517 ptr_inputline++; | |
1518 check_offset(1); | |
1519 break; | |
98 | 1520 case 7: // Ctrl-g |
1521 scr_cancel_current_completion(); | |
1522 scr_end_current_completion(); | |
1523 check_offset(-1); | |
1524 break; | |
24 | 1525 case 9: // Tab |
98 | 1526 scr_handle_tab(); |
1527 check_offset(0); | |
24 | 1528 break; |
1529 case '\n': // Enter | |
263 | 1530 case 15: // Ctrl-o ("accept-line-and-down-history") |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1531 scr_CheckAutoAway(TRUE); |
29 | 1532 if (process_line(inputLine)) |
24 | 1533 return 255; |
173 | 1534 // Add line to history |
1535 scr_cmdhisto_addline(inputLine); | |
1536 // Reset the line | |
24 | 1537 ptr_inputline = inputLine; |
1538 *ptr_inputline = 0; | |
1539 inputline_offset = 0; | |
263 | 1540 |
1541 if (key == '\n') // Enter | |
1542 { | |
1543 // Reset history line pointer | |
1544 cmdhisto_cur = NULL; | |
1545 } else { // down-history | |
1546 // Use next history line instead of a blank line | |
1547 const char *l = scr_cmdhisto_next("", 0); | |
1548 if (l) | |
1549 strcpy(inputLine, l); | |
1550 // Reset backup history line | |
1551 cmdhisto_backup[0] = 0; | |
1552 } | |
24 | 1553 break; |
1554 case KEY_UP: | |
175 | 1555 { |
1556 const char *l = scr_cmdhisto_prev(inputLine, | |
1557 ptr_inputline-inputLine); | |
1558 if (l) { | |
1559 strcpy(inputLine, l); | |
1560 } | |
1561 } | |
24 | 1562 break; |
1563 case KEY_DOWN: | |
175 | 1564 { |
1565 const char *l = scr_cmdhisto_next(inputLine, | |
1566 ptr_inputline-inputLine); | |
1567 if (l) { | |
1568 strcpy(inputLine, l); | |
1569 } | |
1570 } | |
24 | 1571 break; |
1572 case KEY_PPAGE: | |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1573 scr_CheckAutoAway(TRUE); |
175 | 1574 scr_RosterUp(); |
24 | 1575 break; |
1576 case KEY_NPAGE: | |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1577 scr_CheckAutoAway(TRUE); |
175 | 1578 scr_RosterDown(); |
24 | 1579 break; |
1580 case KEY_HOME: | |
1581 case 1: | |
1582 ptr_inputline = inputLine; | |
1583 inputline_offset = 0; | |
1584 break; | |
1585 case KEY_END: | |
1586 case 5: | |
1587 for (; *ptr_inputline; ptr_inputline++) ; | |
1588 check_offset(1); | |
1589 break; | |
1590 case 21: // Ctrl-u | |
1591 strcpy(inputLine, ptr_inputline); | |
1592 ptr_inputline = inputLine; | |
1593 inputline_offset = 0; | |
1594 break; | |
1595 case KEY_EOL: | |
1596 case 11: // Ctrl-k | |
1597 *ptr_inputline = 0; | |
1598 break; | |
1599 case 16: // Ctrl-p | |
175 | 1600 scr_ScrollUp(); |
24 | 1601 break; |
1602 case 14: // Ctrl-n | |
175 | 1603 scr_ScrollDown(); |
24 | 1604 break; |
196 | 1605 case 17: // Ctrl-q |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1606 scr_CheckAutoAway(TRUE); |
236 | 1607 scr_RosterUnreadMessage(1); // next unread message |
196 | 1608 break; |
195 | 1609 case 20: // Ctrl-t |
1610 readline_transpose_chars(); | |
1611 break; | |
194 | 1612 case 23: // Ctrl-w |
195 | 1613 readline_backward_kill_word(); |
194 | 1614 break; |
24 | 1615 case 27: // ESC |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1616 scr_CheckAutoAway(TRUE); |
24 | 1617 currentWindow = NULL; |
1618 chatmode = FALSE; | |
119 | 1619 if (current_buddy) |
1620 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); | |
24 | 1621 top_panel(chatPanel); |
1622 top_panel(inputPanel); | |
157 | 1623 update_panels(); |
24 | 1624 break; |
151 | 1625 case 12: // Ctrl-l |
1626 case KEY_RESIZE: | |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1627 scr_CheckAutoAway(TRUE); |
151 | 1628 scr_Resize(); |
1629 break; | |
24 | 1630 default: |
288 | 1631 { |
1632 const gchar *boundcmd = isbound(key); | |
1633 if (boundcmd) { | |
1634 gchar *cmd = g_strdup_printf("/%s", boundcmd); | |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1635 scr_CheckAutoAway(TRUE); |
288 | 1636 if (process_command(cmd)) |
1637 return 255; | |
1638 g_free(cmd); | |
1639 } else { | |
1640 scr_LogPrint("Unknown key=%d", key); | |
1641 if (utf8_mode) | |
1642 scr_LogPrint("WARNING: UTF-8 not yet supported!"); | |
1643 } | |
1644 } | |
24 | 1645 } |
1646 } | |
157 | 1647 if (completion_started && key != 9 && key != KEY_RESIZE) |
98 | 1648 scr_end_current_completion(); |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1649 refresh_inputline(); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1650 if (!update_roster) |
157 | 1651 doupdate(); |
24 | 1652 return 0; |
1653 } |