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