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