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