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