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