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