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