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