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