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