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