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