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