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