Mercurial > hg
annotate mcabber/src/screen.c @ 1168:eb05f960613f
Fix UTF-8 group names in the roster (Myhailo Danylenko)
Long names were truncated by snprintf, possibly at a wrong position.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Thu, 22 Feb 2007 22:10:19 +0100 |
parents | 14f5876b5555 |
children | 29f805d8412f |
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 <time.h> | |
27 #include <ctype.h> | |
28 #include <locale.h> | |
232 | 29 #include <langinfo.h> |
929 | 30 #include <config.h> |
31 | |
24 | 32 #include "screen.h" |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
33 #include "utf8.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 |
739
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
42 #define get_color(col) (COLOR_PAIR(col)|COLOR_ATTRIB[col]) |
24 | 43 |
515
180f0a6e4ac9
Log window's height can be set by the user
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
44 #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
|
45 #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
|
46 #define CHAT_WIN_HEIGHT (maxY-1-Log_Win_Height) |
180f0a6e4ac9
Log window's height can be set by the user
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
47 |
592
67a332121aea
Try UTF8 -> locale conversion with fallback
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
48 char *LocaleCharSet = "C"; |
67a332121aea
Try UTF8 -> locale conversion with fallback
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
49 |
515
180f0a6e4ac9
Log window's height can be set by the user
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
50 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
|
51 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
|
52 |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
53 static inline void check_offset(int); |
151 | 54 |
1078
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
55 static GHashTable *winbufhash; |
24 | 56 |
822 | 57 typedef struct { |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
58 GList *hbuf; |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
59 GList *top; // If top is NULL, we'll display the last lines |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
60 char cleared; // For ex, user has issued a /clear command... |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
61 char lock; |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
62 } buffdata; |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
63 |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
64 typedef struct { |
24 | 65 WINDOW *win; |
108 | 66 PANEL *panel; |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
67 buffdata *bd; |
822 | 68 } winbuf; |
24 | 69 |
1078
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
70 struct dimensions { |
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
71 int l; |
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
72 int c; |
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
73 }; |
24 | 74 |
1133
9dd28a56128f
Do not create one panel per contact
Mikael Berthe <mikael@lilotux.net>
parents:
1131
diff
changeset
|
75 static WINDOW *rosterWnd, *chatWnd, *activechatWnd, *inputWnd, *logWnd; |
711 | 76 static WINDOW *mainstatusWnd, *chatstatusWnd; |
1133
9dd28a56128f
Do not create one panel per contact
Mikael Berthe <mikael@lilotux.net>
parents:
1131
diff
changeset
|
77 static PANEL *rosterPanel, *chatPanel, *activechatPanel, *inputPanel; |
711 | 78 static PANEL *mainstatusPanel, *chatstatusPanel; |
79 static PANEL *logPanel; | |
24 | 80 static int maxY, maxX; |
1093
6ca9a65df21f
Do not rewrap buffer lines when the chat window width doesn't change
Mikael Berthe <mikael@lilotux.net>
parents:
1089
diff
changeset
|
81 static int prev_chatwidth; |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
82 static winbuf *statusWindow; |
822 | 83 static winbuf *currentWindow; |
851
da03534e46c7
Add startup log messages to the status buffer
Mikael Berthe <mikael@lilotux.net>
parents:
850
diff
changeset
|
84 static GList *statushbuf; |
24 | 85 |
707
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
86 static int roster_hidden; |
24 | 87 static int chatmode; |
238 | 88 static int multimode; |
807
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
89 static char *multiline, *multimode_subj; |
30 | 90 int update_roster; |
232 | 91 int utf8_mode = 0; |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
92 static bool Autoaway; |
332
a1901741890e
scr_LogPrint() can be called before ncurses initialization
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
93 static bool Curses; |
972
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
94 static bool log_win_on_top; |
973
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
95 static bool roster_win_on_right; |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
936
diff
changeset
|
96 static time_t LastActivity; |
24 | 97 |
174 | 98 static char inputLine[INPUTLINE_LENGTH+1]; |
99 static char *ptr_inputline; | |
100 static short int inputline_offset; | |
101 static int completion_started; | |
173 | 102 static GList *cmdhisto; |
103 static GList *cmdhisto_cur; | |
1127
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
104 static guint cmdhisto_nblines; |
174 | 105 static char cmdhisto_backup[INPUTLINE_LENGTH+1]; |
24 | 106 |
991
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
107 static int chatstate; /* (0=active, 1=composing, 2=paused) */ |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
108 static bool lock_chatstate; |
991
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
109 static time_t chatstate_timestamp; |
993
0759f4c7da68
Add option 'disable_chatstates'
Mikael Berthe <mikael@lilotux.net>
parents:
992
diff
changeset
|
110 int chatstates_disabled; |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
111 |
761
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
112 #define MAX_KEYSEQ_LENGTH 8 |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
113 |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
114 typedef struct { |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
115 char *seqstr; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
116 guint mkeycode; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
117 gint value; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
118 } keyseq; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
119 |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
120 GSList *keyseqlist; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
121 static void add_keyseq(char *seqstr, guint mkeycode, gint value); |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
122 |
850
d0781ca2dd08
Use new status buffer window
Mikael Berthe <mikael@lilotux.net>
parents:
849
diff
changeset
|
123 void scr_WriteInWindow(const char *winId, const char *text, time_t timestamp, |
d0781ca2dd08
Use new status buffer window
Mikael Berthe <mikael@lilotux.net>
parents:
849
diff
changeset
|
124 unsigned int prefix_flags, int force_show); |
d0781ca2dd08
Use new status buffer window
Mikael Berthe <mikael@lilotux.net>
parents:
849
diff
changeset
|
125 |
24 | 126 |
99 | 127 /* Functions */ |
24 | 128 |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
129 static int FindColor(const char *name) |
24 | 130 { |
131 if (!strcmp(name, "default")) | |
132 return -1; | |
133 if (!strcmp(name, "black")) | |
134 return COLOR_BLACK; | |
135 if (!strcmp(name, "red")) | |
136 return COLOR_RED; | |
137 if (!strcmp(name, "green")) | |
138 return COLOR_GREEN; | |
139 if (!strcmp(name, "yellow")) | |
140 return COLOR_YELLOW; | |
141 if (!strcmp(name, "blue")) | |
142 return COLOR_BLUE; | |
143 if (!strcmp(name, "magenta")) | |
144 return COLOR_MAGENTA; | |
145 if (!strcmp(name, "cyan")) | |
146 return COLOR_CYAN; | |
147 if (!strcmp(name, "white")) | |
148 return COLOR_WHITE; | |
149 | |
739
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
150 scr_LogPrint(LPRINT_LOGNORM, "ERROR: Wrong color: %s", name); |
24 | 151 return -1; |
152 } | |
153 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
154 static void ParseColors(void) |
24 | 155 { |
739
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
156 const char *colors[] = { |
24 | 157 "", "", |
267 | 158 "general", |
785
7e0562e3bc83
Replace color_highlight with color_msgout
Mikael Berthe <mikael@lilotux.net>
parents:
779
diff
changeset
|
159 "msgout", |
711 | 160 "status", |
712 | 161 "roster", |
162 "rostersel", | |
723
23068490d063
Add text color when the selected buddy has an unread message
Mikael Berthe <mikael@lilotux.net>
parents:
721
diff
changeset
|
163 "rosterselmsg", |
712 | 164 "rosternewmsg", |
24 | 165 NULL |
166 }; | |
167 | |
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
168 const char *color; |
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
169 const char *background = settings_opt_get("color_background"); |
712 | 170 const char *backselected = settings_opt_get("color_bgrostersel"); |
171 const char *backstatus = settings_opt_get("color_bgstatus"); | |
739
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
172 char *tmp; |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
173 int i; |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
174 |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
175 // Initialize color attributes |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
176 memset(COLOR_ATTRIB, 0, sizeof(COLOR_ATTRIB)); |
24 | 177 |
267 | 178 // Default values |
711 | 179 if (!background) background = "black"; |
267 | 180 if (!backselected) backselected = "cyan"; |
711 | 181 if (!backstatus) backstatus = "blue"; |
267 | 182 |
739
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
183 for (i=0; colors[i]; i++) { |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
184 tmp = g_strdup_printf("color_%s", colors[i]); |
279
f5dd437c057b
Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
276
diff
changeset
|
185 color = settings_opt_get(tmp); |
739
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
186 g_free(tmp); |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
187 |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
188 if (color) { |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
189 if (!strncmp(color, "bright", 6)) { |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
190 COLOR_ATTRIB[i+1] = A_BOLD; |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
191 color += 6; |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
192 } |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
193 } |
24 | 194 |
195 switch (i + 1) { | |
739
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
196 case 1: |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
197 init_pair(1, COLOR_BLACK, COLOR_WHITE); |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
198 break; |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
199 case 2: |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
200 init_pair(2, COLOR_WHITE, COLOR_BLACK); |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
201 break; |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
202 case COLOR_GENERAL: |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
203 init_pair(i+1, ((color) ? FindColor(color) : COLOR_WHITE), |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
204 FindColor(background)); |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
205 break; |
785
7e0562e3bc83
Replace color_highlight with color_msgout
Mikael Berthe <mikael@lilotux.net>
parents:
779
diff
changeset
|
206 case COLOR_MSGOUT: |
739
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
207 init_pair(i+1, ((color) ? FindColor(color) : COLOR_CYAN), |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
208 FindColor(background)); |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
209 break; |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
210 case COLOR_STATUS: |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
211 init_pair(i+1, ((color) ? FindColor(color) : COLOR_WHITE), |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
212 FindColor(backstatus)); |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
213 break; |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
214 case COLOR_ROSTER: |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
215 init_pair(i+1, ((color) ? FindColor(color) : COLOR_GREEN), |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
216 FindColor(background)); |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
217 break; |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
218 case COLOR_ROSTERSEL: |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
219 init_pair(i+1, ((color) ? FindColor(color) : COLOR_BLUE), |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
220 FindColor(backselected)); |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
221 break; |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
222 case COLOR_ROSTERSELNMSG: |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
223 init_pair(i+1, ((color) ? FindColor(color) : COLOR_RED), |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
224 FindColor(backselected)); |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
225 break; |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
226 case COLOR_ROSTERNMSG: |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
227 init_pair(i+1, ((color) ? FindColor(color) : COLOR_RED), |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
228 FindColor(background)); |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
229 break; |
24 | 230 } |
231 } | |
232 } | |
233 | |
765
72626e9d60bd
Create init_keycodes(), add 2 screen escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
764
diff
changeset
|
234 static void init_keycodes(void) |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
235 { |
761
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
236 add_keyseq("O5A", MKEY_EQUIV, 521); // Ctrl-Up |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
237 add_keyseq("O5B", MKEY_EQUIV, 514); // Ctrl-Down |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
238 add_keyseq("O5C", MKEY_EQUIV, 518); // Ctrl-Right |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
239 add_keyseq("O5D", MKEY_EQUIV, 516); // Ctrl-Left |
763 | 240 add_keyseq("O6A", MKEY_EQUIV, 520); // Shift-Up |
241 add_keyseq("O6B", MKEY_EQUIV, 513); // Shift-Down | |
242 add_keyseq("O6C", MKEY_EQUIV, 402); // Shift-Right | |
243 add_keyseq("O6D", MKEY_EQUIV, 393); // Shift-Left | |
244 add_keyseq("O2A", MKEY_EQUIV, 520); // Shift-Up | |
245 add_keyseq("O2B", MKEY_EQUIV, 513); // Shift-Down | |
246 add_keyseq("O2C", MKEY_EQUIV, 402); // Shift-Right | |
247 add_keyseq("O2D", MKEY_EQUIV, 393); // Shift-Left | |
248 add_keyseq("[5^", MKEY_CTRL_PGUP, 0); // Ctrl-PageUp | |
249 add_keyseq("[6^", MKEY_CTRL_PGDOWN, 0); // Ctrl-PageDown | |
250 add_keyseq("[5@", MKEY_CTRL_SHIFT_PGUP, 0); // Ctrl-Shift-PageUp | |
251 add_keyseq("[6@", MKEY_CTRL_SHIFT_PGDOWN, 0); // Ctrl-Shift-PageDown | |
826
3a3c7a017904
Add Ctrl-Shift-{Home,End} key code sequences
Mikael Berthe <mikael@lilotux.net>
parents:
825
diff
changeset
|
252 add_keyseq("[7@", MKEY_CTRL_SHIFT_HOME, 0); // Ctrl-Shift-Home |
3a3c7a017904
Add Ctrl-Shift-{Home,End} key code sequences
Mikael Berthe <mikael@lilotux.net>
parents:
825
diff
changeset
|
253 add_keyseq("[8@", MKEY_CTRL_SHIFT_END, 0); // Ctrl-Shift-End |
794
32d5298f9f8d
Add a few keycode sequences
Mikael Berthe <mikael@lilotux.net>
parents:
790
diff
changeset
|
254 add_keyseq("[8^", MKEY_CTRL_END, 0); // Ctrl-End |
32d5298f9f8d
Add a few keycode sequences
Mikael Berthe <mikael@lilotux.net>
parents:
790
diff
changeset
|
255 add_keyseq("[7^", MKEY_CTRL_HOME, 0); // Ctrl-Home |
32d5298f9f8d
Add a few keycode sequences
Mikael Berthe <mikael@lilotux.net>
parents:
790
diff
changeset
|
256 add_keyseq("[2^", MKEY_CTRL_INS, 0); // Ctrl-Insert |
32d5298f9f8d
Add a few keycode sequences
Mikael Berthe <mikael@lilotux.net>
parents:
790
diff
changeset
|
257 add_keyseq("[3^", MKEY_CTRL_DEL, 0); // Ctrl-Delete |
761
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
258 |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
259 // Xterm |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
260 add_keyseq("[1;5A", MKEY_EQUIV, 521); // Ctrl-Up |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
261 add_keyseq("[1;5B", MKEY_EQUIV, 514); // Ctrl-Down |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
262 add_keyseq("[1;5C", MKEY_EQUIV, 518); // Ctrl-Right |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
263 add_keyseq("[1;5D", MKEY_EQUIV, 516); // Ctrl-Left |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
264 add_keyseq("[1;6A", MKEY_EQUIV, 520); // Ctrl-Shift-Up |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
265 add_keyseq("[1;6B", MKEY_EQUIV, 513); // Ctrl-Shift-Down |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
266 add_keyseq("[1;6C", MKEY_EQUIV, 402); // Ctrl-Shift-Right |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
267 add_keyseq("[1;6D", MKEY_EQUIV, 393); // Ctrl-Shift-Left |
826
3a3c7a017904
Add Ctrl-Shift-{Home,End} key code sequences
Mikael Berthe <mikael@lilotux.net>
parents:
825
diff
changeset
|
268 add_keyseq("[1;6H", MKEY_CTRL_SHIFT_HOME, 0); // Ctrl-Shift-Home |
3a3c7a017904
Add Ctrl-Shift-{Home,End} key code sequences
Mikael Berthe <mikael@lilotux.net>
parents:
825
diff
changeset
|
269 add_keyseq("[1;6F", MKEY_CTRL_SHIFT_END, 0); // Ctrl-Shift-End |
763 | 270 add_keyseq("[1;2A", MKEY_EQUIV, 521); // Shift-Up |
271 add_keyseq("[1;2B", MKEY_EQUIV, 514); // Shift-Down | |
272 add_keyseq("[5;5~", MKEY_CTRL_PGUP, 0); // Ctrl-PageUp | |
273 add_keyseq("[6;5~", MKEY_CTRL_PGDOWN, 0); // Ctrl-PageDown | |
794
32d5298f9f8d
Add a few keycode sequences
Mikael Berthe <mikael@lilotux.net>
parents:
790
diff
changeset
|
274 add_keyseq("[1;5F", MKEY_CTRL_END, 0); // Ctrl-End |
32d5298f9f8d
Add a few keycode sequences
Mikael Berthe <mikael@lilotux.net>
parents:
790
diff
changeset
|
275 add_keyseq("[1;5H", MKEY_CTRL_HOME, 0); // Ctrl-Home |
32d5298f9f8d
Add a few keycode sequences
Mikael Berthe <mikael@lilotux.net>
parents:
790
diff
changeset
|
276 add_keyseq("[2;5~", MKEY_CTRL_INS, 0); // Ctrl-Insert |
32d5298f9f8d
Add a few keycode sequences
Mikael Berthe <mikael@lilotux.net>
parents:
790
diff
changeset
|
277 add_keyseq("[3;5~", MKEY_CTRL_DEL, 0); // Ctrl-Delete |
761
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
278 |
768
0f6d25a02450
Add PuTTY escape keys for Ctrl-arrows
Mikael Berthe <mikael@lilotux.net>
parents:
766
diff
changeset
|
279 // PuTTY |
0f6d25a02450
Add PuTTY escape keys for Ctrl-arrows
Mikael Berthe <mikael@lilotux.net>
parents:
766
diff
changeset
|
280 add_keyseq("[A", MKEY_EQUIV, 521); // Ctrl-Up |
0f6d25a02450
Add PuTTY escape keys for Ctrl-arrows
Mikael Berthe <mikael@lilotux.net>
parents:
766
diff
changeset
|
281 add_keyseq("[B", MKEY_EQUIV, 514); // Ctrl-Down |
0f6d25a02450
Add PuTTY escape keys for Ctrl-arrows
Mikael Berthe <mikael@lilotux.net>
parents:
766
diff
changeset
|
282 add_keyseq("[C", MKEY_EQUIV, 518); // Ctrl-Right |
0f6d25a02450
Add PuTTY escape keys for Ctrl-arrows
Mikael Berthe <mikael@lilotux.net>
parents:
766
diff
changeset
|
283 add_keyseq("[D", MKEY_EQUIV, 516); // Ctrl-Left |
0f6d25a02450
Add PuTTY escape keys for Ctrl-arrows
Mikael Berthe <mikael@lilotux.net>
parents:
766
diff
changeset
|
284 |
762
96d46e00524a
Add some key escape sequences for screen
Mikael Berthe <mikael@lilotux.net>
parents:
761
diff
changeset
|
285 // screen |
96d46e00524a
Add some key escape sequences for screen
Mikael Berthe <mikael@lilotux.net>
parents:
761
diff
changeset
|
286 add_keyseq("Oa", MKEY_EQUIV, 521); // Ctrl-Up |
96d46e00524a
Add some key escape sequences for screen
Mikael Berthe <mikael@lilotux.net>
parents:
761
diff
changeset
|
287 add_keyseq("Ob", MKEY_EQUIV, 514); // Ctrl-Down |
96d46e00524a
Add some key escape sequences for screen
Mikael Berthe <mikael@lilotux.net>
parents:
761
diff
changeset
|
288 add_keyseq("Oc", MKEY_EQUIV, 518); // Ctrl-Right |
96d46e00524a
Add some key escape sequences for screen
Mikael Berthe <mikael@lilotux.net>
parents:
761
diff
changeset
|
289 add_keyseq("Od", MKEY_EQUIV, 516); // Ctrl-Left |
763 | 290 add_keyseq("[a", MKEY_EQUIV, 520); // Shift-Up |
291 add_keyseq("[b", MKEY_EQUIV, 513); // Shift-Down | |
292 add_keyseq("[c", MKEY_EQUIV, 402); // Shift-Right | |
293 add_keyseq("[d", MKEY_EQUIV, 393); // Shift-Left | |
765
72626e9d60bd
Create init_keycodes(), add 2 screen escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
764
diff
changeset
|
294 add_keyseq("[5$", MKEY_SHIFT_PGUP, 0); // Shift-PageUp |
72626e9d60bd
Create init_keycodes(), add 2 screen escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
764
diff
changeset
|
295 add_keyseq("[6$", MKEY_SHIFT_PGDOWN, 0); // Shift-PageDown |
72626e9d60bd
Create init_keycodes(), add 2 screen escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
764
diff
changeset
|
296 } |
72626e9d60bd
Create init_keycodes(), add 2 screen escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
764
diff
changeset
|
297 |
779
057ffe7c43dc
Initialize locale charset earlier
Mikael Berthe <mikael@lilotux.net>
parents:
773
diff
changeset
|
298 void scr_InitLocaleCharSet(void) |
057ffe7c43dc
Initialize locale charset earlier
Mikael Berthe <mikael@lilotux.net>
parents:
773
diff
changeset
|
299 { |
057ffe7c43dc
Initialize locale charset earlier
Mikael Berthe <mikael@lilotux.net>
parents:
773
diff
changeset
|
300 setlocale(LC_CTYPE, ""); |
057ffe7c43dc
Initialize locale charset earlier
Mikael Berthe <mikael@lilotux.net>
parents:
773
diff
changeset
|
301 LocaleCharSet = nl_langinfo(CODESET); |
057ffe7c43dc
Initialize locale charset earlier
Mikael Berthe <mikael@lilotux.net>
parents:
773
diff
changeset
|
302 utf8_mode = (strcmp(LocaleCharSet, "UTF-8") == 0); |
057ffe7c43dc
Initialize locale charset earlier
Mikael Berthe <mikael@lilotux.net>
parents:
773
diff
changeset
|
303 } |
057ffe7c43dc
Initialize locale charset earlier
Mikael Berthe <mikael@lilotux.net>
parents:
773
diff
changeset
|
304 |
765
72626e9d60bd
Create init_keycodes(), add 2 screen escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
764
diff
changeset
|
305 void scr_InitCurses(void) |
72626e9d60bd
Create init_keycodes(), add 2 screen escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
764
diff
changeset
|
306 { |
72626e9d60bd
Create init_keycodes(), add 2 screen escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
764
diff
changeset
|
307 /* Key sequences initialization */ |
72626e9d60bd
Create init_keycodes(), add 2 screen escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
764
diff
changeset
|
308 init_keycodes(); |
762
96d46e00524a
Add some key escape sequences for screen
Mikael Berthe <mikael@lilotux.net>
parents:
761
diff
changeset
|
309 |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
310 initscr(); |
382
4c6e8392e465
Use nodelay() instead of halfdelay()
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
311 raw(); |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
312 noecho(); |
389
6e895f397474
Ncurses changes + Ctrl-C does not send a signal anylore
Mikael Berthe <mikael@lilotux.net>
parents:
388
diff
changeset
|
313 nonl(); |
6e895f397474
Ncurses changes + Ctrl-C does not send a signal anylore
Mikael Berthe <mikael@lilotux.net>
parents:
388
diff
changeset
|
314 intrflush(stdscr, FALSE); |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
315 start_color(); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
316 use_default_colors(); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
317 |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
318 ParseColors(); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
319 |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
320 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
|
321 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
|
322 // 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
|
323 // 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
|
324 |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
325 inputLine[0] = 0; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
326 ptr_inputline = inputLine; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
327 |
966
d9acb7f2a3d1
Do not set Curses variable too early
Mikael Berthe <mikael@lilotux.net>
parents:
961
diff
changeset
|
328 Curses = TRUE; |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
329 return; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
330 } |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
331 |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
332 void scr_TerminateCurses(void) |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
333 { |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
334 if (!Curses) return; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
335 clear(); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
336 refresh(); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
337 endwin(); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
338 Curses = FALSE; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
339 return; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
340 } |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
341 |
675
ae7016aae014
New "beep_on_message" option
Mikael Berthe <mikael@lilotux.net>
parents:
667
diff
changeset
|
342 inline void scr_Beep(void) |
ae7016aae014
New "beep_on_message" option
Mikael Berthe <mikael@lilotux.net>
parents:
667
diff
changeset
|
343 { |
ae7016aae014
New "beep_on_message" option
Mikael Berthe <mikael@lilotux.net>
parents:
667
diff
changeset
|
344 beep(); |
ae7016aae014
New "beep_on_message" option
Mikael Berthe <mikael@lilotux.net>
parents:
667
diff
changeset
|
345 } |
ae7016aae014
New "beep_on_message" option
Mikael Berthe <mikael@lilotux.net>
parents:
667
diff
changeset
|
346 |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
347 // scr_LogPrint(...) |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
348 // Display a message in the log window. |
771
ce4f8a2129a4
scr_LogPrint() can display UTF-8 strings
Mikael Berthe <mikael@lilotux.net>
parents:
770
diff
changeset
|
349 // This function will convert from UTF-8 unless the LPRINT_NOTUTF8 flag is set. |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
350 void scr_LogPrint(unsigned int flag, const char *fmt, ...) |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
351 { |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
352 time_t timestamp; |
857
ef35a2bb40d7
scr_LogPrint(): do not use static buffer size
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
353 char strtimestamp[64]; |
858
2683ad5d1003
Improve scr_LogPrint() for log/debug messages
Mikael Berthe <mikael@lilotux.net>
parents:
857
diff
changeset
|
354 char *buffer, *btext; |
1075
03bc225ad763
Improve scr_LogPrint() readability
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
355 char *convbuf1 = NULL, *convbuf2 = NULL; |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
356 va_list ap; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
357 |
771
ce4f8a2129a4
scr_LogPrint() can display UTF-8 strings
Mikael Berthe <mikael@lilotux.net>
parents:
770
diff
changeset
|
358 if (!(flag & ~LPRINT_NOTUTF8)) return; // Shouldn't happen |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
359 |
857
ef35a2bb40d7
scr_LogPrint(): do not use static buffer size
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
360 timestamp = time(NULL); |
ef35a2bb40d7
scr_LogPrint(): do not use static buffer size
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
361 strftime(strtimestamp, 48, "[%H:%M:%S]", localtime(×tamp)); |
ef35a2bb40d7
scr_LogPrint(): do not use static buffer size
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
362 va_start(ap, fmt); |
858
2683ad5d1003
Improve scr_LogPrint() for log/debug messages
Mikael Berthe <mikael@lilotux.net>
parents:
857
diff
changeset
|
363 btext = g_strdup_vprintf(fmt, ap); |
857
ef35a2bb40d7
scr_LogPrint(): do not use static buffer size
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
364 va_end(ap); |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
365 |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
366 if (flag & LPRINT_NORMAL) { |
771
ce4f8a2129a4
scr_LogPrint() can display UTF-8 strings
Mikael Berthe <mikael@lilotux.net>
parents:
770
diff
changeset
|
367 char *buffer_locale; |
851
da03534e46c7
Add startup log messages to the status buffer
Mikael Berthe <mikael@lilotux.net>
parents:
850
diff
changeset
|
368 char *buf_specialwindow; |
da03534e46c7
Add startup log messages to the status buffer
Mikael Berthe <mikael@lilotux.net>
parents:
850
diff
changeset
|
369 |
858
2683ad5d1003
Improve scr_LogPrint() for log/debug messages
Mikael Berthe <mikael@lilotux.net>
parents:
857
diff
changeset
|
370 buffer = g_strdup_printf("%s %s", strtimestamp, btext); |
2683ad5d1003
Improve scr_LogPrint() for log/debug messages
Mikael Berthe <mikael@lilotux.net>
parents:
857
diff
changeset
|
371 |
851
da03534e46c7
Add startup log messages to the status buffer
Mikael Berthe <mikael@lilotux.net>
parents:
850
diff
changeset
|
372 // Convert buffer to current locale for wprintw() |
771
ce4f8a2129a4
scr_LogPrint() can display UTF-8 strings
Mikael Berthe <mikael@lilotux.net>
parents:
770
diff
changeset
|
373 if (!(flag & LPRINT_NOTUTF8)) |
1075
03bc225ad763
Improve scr_LogPrint() readability
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
374 buffer_locale = convbuf1 = from_utf8(buffer); |
771
ce4f8a2129a4
scr_LogPrint() can display UTF-8 strings
Mikael Berthe <mikael@lilotux.net>
parents:
770
diff
changeset
|
375 else |
ce4f8a2129a4
scr_LogPrint() can display UTF-8 strings
Mikael Berthe <mikael@lilotux.net>
parents:
770
diff
changeset
|
376 buffer_locale = buffer; |
851
da03534e46c7
Add startup log messages to the status buffer
Mikael Berthe <mikael@lilotux.net>
parents:
850
diff
changeset
|
377 |
884
9e6d9f0cf9eb
scr_LogPrint(): Add a warning for UTF-8 -> locale conversion failures
Mikael Berthe <mikael@lilotux.net>
parents:
880
diff
changeset
|
378 if (!buffer_locale) { |
9e6d9f0cf9eb
scr_LogPrint(): Add a warning for UTF-8 -> locale conversion failures
Mikael Berthe <mikael@lilotux.net>
parents:
880
diff
changeset
|
379 wprintw(logWnd, |
9e6d9f0cf9eb
scr_LogPrint(): Add a warning for UTF-8 -> locale conversion failures
Mikael Berthe <mikael@lilotux.net>
parents:
880
diff
changeset
|
380 "\n%s*Error: cannot convert string to locale.", strtimestamp); |
9e6d9f0cf9eb
scr_LogPrint(): Add a warning for UTF-8 -> locale conversion failures
Mikael Berthe <mikael@lilotux.net>
parents:
880
diff
changeset
|
381 update_panels(); |
9e6d9f0cf9eb
scr_LogPrint(): Add a warning for UTF-8 -> locale conversion failures
Mikael Berthe <mikael@lilotux.net>
parents:
880
diff
changeset
|
382 g_free(buffer); |
897
a05b5a16a06a
Fix memory leak in scr_LogPrint()
Mikael Berthe <mikael@lilotux.net>
parents:
891
diff
changeset
|
383 g_free(btext); |
884
9e6d9f0cf9eb
scr_LogPrint(): Add a warning for UTF-8 -> locale conversion failures
Mikael Berthe <mikael@lilotux.net>
parents:
880
diff
changeset
|
384 return; |
9e6d9f0cf9eb
scr_LogPrint(): Add a warning for UTF-8 -> locale conversion failures
Mikael Berthe <mikael@lilotux.net>
parents:
880
diff
changeset
|
385 } |
9e6d9f0cf9eb
scr_LogPrint(): Add a warning for UTF-8 -> locale conversion failures
Mikael Berthe <mikael@lilotux.net>
parents:
880
diff
changeset
|
386 |
851
da03534e46c7
Add startup log messages to the status buffer
Mikael Berthe <mikael@lilotux.net>
parents:
850
diff
changeset
|
387 // For the special status buffer, we need utf-8, but without the timestamp |
da03534e46c7
Add startup log messages to the status buffer
Mikael Berthe <mikael@lilotux.net>
parents:
850
diff
changeset
|
388 if (flag & LPRINT_NOTUTF8) |
1075
03bc225ad763
Improve scr_LogPrint() readability
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
389 buf_specialwindow = convbuf2 = to_utf8(btext); |
851
da03534e46c7
Add startup log messages to the status buffer
Mikael Berthe <mikael@lilotux.net>
parents:
850
diff
changeset
|
390 else |
858
2683ad5d1003
Improve scr_LogPrint() for log/debug messages
Mikael Berthe <mikael@lilotux.net>
parents:
857
diff
changeset
|
391 buf_specialwindow = btext; |
851
da03534e46c7
Add startup log messages to the status buffer
Mikael Berthe <mikael@lilotux.net>
parents:
850
diff
changeset
|
392 |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
393 if (Curses) { |
771
ce4f8a2129a4
scr_LogPrint() can display UTF-8 strings
Mikael Berthe <mikael@lilotux.net>
parents:
770
diff
changeset
|
394 wprintw(logWnd, "\n%s", buffer_locale); |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
395 update_panels(); |
850
d0781ca2dd08
Use new status buffer window
Mikael Berthe <mikael@lilotux.net>
parents:
849
diff
changeset
|
396 scr_WriteInWindow(NULL, buf_specialwindow, timestamp, |
d0781ca2dd08
Use new status buffer window
Mikael Berthe <mikael@lilotux.net>
parents:
849
diff
changeset
|
397 HBB_PREFIX_SPECIAL, FALSE); |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
398 } else { |
771
ce4f8a2129a4
scr_LogPrint() can display UTF-8 strings
Mikael Berthe <mikael@lilotux.net>
parents:
770
diff
changeset
|
399 printf("%s\n", buffer_locale); |
851
da03534e46c7
Add startup log messages to the status buffer
Mikael Berthe <mikael@lilotux.net>
parents:
850
diff
changeset
|
400 // ncurses are not initialized yet, so we call directly hbuf routine |
da03534e46c7
Add startup log messages to the status buffer
Mikael Berthe <mikael@lilotux.net>
parents:
850
diff
changeset
|
401 hbuf_add_line(&statushbuf, buf_specialwindow, timestamp, |
1141
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1139
diff
changeset
|
402 HBB_PREFIX_SPECIAL, 0, 0); |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
403 } |
851
da03534e46c7
Add startup log messages to the status buffer
Mikael Berthe <mikael@lilotux.net>
parents:
850
diff
changeset
|
404 |
1075
03bc225ad763
Improve scr_LogPrint() readability
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
405 g_free(convbuf1); |
03bc225ad763
Improve scr_LogPrint() readability
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
406 g_free(convbuf2); |
858
2683ad5d1003
Improve scr_LogPrint() for log/debug messages
Mikael Berthe <mikael@lilotux.net>
parents:
857
diff
changeset
|
407 g_free(buffer); |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
408 } |
412
9c640ee3bae3
Display full date in the log file
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
409 |
857
ef35a2bb40d7
scr_LogPrint(): do not use static buffer size
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
410 if (flag & (LPRINT_LOG|LPRINT_DEBUG)) { |
ef35a2bb40d7
scr_LogPrint(): do not use static buffer size
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
411 strftime(strtimestamp, 23, "[%Y-%m-%d %H:%M:%S]", localtime(×tamp)); |
858
2683ad5d1003
Improve scr_LogPrint() for log/debug messages
Mikael Berthe <mikael@lilotux.net>
parents:
857
diff
changeset
|
412 buffer = g_strdup_printf("%s %s\n", strtimestamp, btext); |
857
ef35a2bb40d7
scr_LogPrint(): do not use static buffer size
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
413 ut_WriteLog(flag, buffer); |
ef35a2bb40d7
scr_LogPrint(): do not use static buffer size
Mikael Berthe <mikael@lilotux.net>
parents:
851
diff
changeset
|
414 g_free(buffer); |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
415 } |
897
a05b5a16a06a
Fix memory leak in scr_LogPrint()
Mikael Berthe <mikael@lilotux.net>
parents:
891
diff
changeset
|
416 g_free(btext); |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
417 } |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
418 |
1156
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
419 static winbuf *scr_SearchWindow(const char *winId, int special) |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
420 { |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
421 char *id; |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
422 winbuf *wbp; |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
423 |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
424 if (special) |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
425 return statusWindow; // Only one special window atm. |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
426 |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
427 if (!winId) |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
428 return NULL; |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
429 |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
430 id = g_strdup(winId); |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
431 mc_strtolower(id); |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
432 wbp = g_hash_table_lookup(winbufhash, id); |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
433 g_free(id); |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
434 return wbp; |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
435 } |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
436 |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
437 int scr_BuddyBufferExists(const char *bjid) |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
438 { |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
439 return (scr_SearchWindow(bjid, FALSE) != NULL); |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
440 } |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
441 |
1133
9dd28a56128f
Do not create one panel per contact
Mikael Berthe <mikael@lilotux.net>
parents:
1131
diff
changeset
|
442 // scr_new_buddy(title, dontshow) |
1139 | 443 // Note: title (aka winId/jid) can be NULL for special buffers |
1133
9dd28a56128f
Do not create one panel per contact
Mikael Berthe <mikael@lilotux.net>
parents:
1131
diff
changeset
|
444 static winbuf *scr_new_buddy(const char *title, int dont_show) |
24 | 445 { |
822 | 446 winbuf *tmp; |
393 | 447 |
822 | 448 tmp = g_new0(winbuf, 1); |
24 | 449 |
1133
9dd28a56128f
Do not create one panel per contact
Mikael Berthe <mikael@lilotux.net>
parents:
1131
diff
changeset
|
450 tmp->win = activechatWnd; |
9dd28a56128f
Do not create one panel per contact
Mikael Berthe <mikael@lilotux.net>
parents:
1131
diff
changeset
|
451 tmp->panel = activechatPanel; |
24 | 452 |
143 | 453 if (!dont_show) { |
24 | 454 currentWindow = tmp; |
455 } else { | |
456 if (currentWindow) | |
457 top_panel(currentWindow->panel); | |
458 else | |
459 top_panel(chatPanel); | |
460 } | |
143 | 461 update_panels(); |
24 | 462 |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
463 // If title is NULL, this is a special buffer |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
464 if (title) { |
1078
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
465 char *id; |
1156
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
466 id = hlog_get_log_jid(title); |
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
467 if (id) { |
1160
14f5876b5555
Slight optimization + line wrapping
Mikael Berthe <mikael@lilotux.net>
parents:
1159
diff
changeset
|
468 winbuf *wb = scr_SearchWindow(id, FALSE); |
14f5876b5555
Slight optimization + line wrapping
Mikael Berthe <mikael@lilotux.net>
parents:
1159
diff
changeset
|
469 if (!wb) |
14f5876b5555
Slight optimization + line wrapping
Mikael Berthe <mikael@lilotux.net>
parents:
1159
diff
changeset
|
470 wb = scr_new_buddy(id, TRUE); |
14f5876b5555
Slight optimization + line wrapping
Mikael Berthe <mikael@lilotux.net>
parents:
1159
diff
changeset
|
471 tmp->bd=wb->bd; |
1156
cae430fcd385
Mcabber will load symlinked histories only once, now.
Frank Zschockelt
parents:
1154
diff
changeset
|
472 g_free(id); |
1159
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1157
diff
changeset
|
473 } else { // Load buddy history from file (if enabled) |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
474 tmp->bd = g_new0(buffdata, 1); |
1159
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1157
diff
changeset
|
475 hlog_read_history(title, &tmp->bd->hbuf, |
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1157
diff
changeset
|
476 maxX - Roster_Width - PREFIX_WIDTH); |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
477 } |
181 | 478 |
1078
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
479 id = g_strdup(title); |
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
480 mc_strtolower(id); |
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
481 g_hash_table_insert(winbufhash, id, tmp); |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
482 } else { |
1159
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1157
diff
changeset
|
483 tmp->bd = g_new0(buffdata, 1); |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
484 } |
24 | 485 return tmp; |
486 } | |
487 | |
143 | 488 // scr_UpdateWindow() |
489 // (Re-)Display the given chat window. | |
822 | 490 static void scr_UpdateWindow(winbuf *win_entry) |
74 | 491 { |
492 int n; | |
493 int width; | |
184 | 494 hbb_line **lines, *line; |
74 | 495 GList *hbuf_head; |
850
d0781ca2dd08
Use new status buffer window
Mikael Berthe <mikael@lilotux.net>
parents:
849
diff
changeset
|
496 char date[64]; |
74 | 497 |
1077
c51ca5225516
Remove useless WindowWidth function
Mikael Berthe <mikael@lilotux.net>
parents:
1076
diff
changeset
|
498 width = getmaxx(win_entry->win); |
108 | 499 |
500 // Should the window be empty? | |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
501 if (win_entry->bd->cleared) { |
168 | 502 werase(win_entry->win); |
108 | 503 return; |
504 } | |
505 | |
1160
14f5876b5555
Slight optimization + line wrapping
Mikael Berthe <mikael@lilotux.net>
parents:
1159
diff
changeset
|
506 // win_entry->bd->top is the top message of the screen. If it set to NULL, |
14f5876b5555
Slight optimization + line wrapping
Mikael Berthe <mikael@lilotux.net>
parents:
1159
diff
changeset
|
507 // we are displaying the last messages. |
105 | 508 |
74 | 509 // We will show the last CHAT_WIN_HEIGHT lines. |
510 // Let's find out where it begins. | |
1160
14f5876b5555
Slight optimization + line wrapping
Mikael Berthe <mikael@lilotux.net>
parents:
1159
diff
changeset
|
511 if (!win_entry->bd->top || (g_list_position(g_list_first(win_entry->bd->hbuf), |
14f5876b5555
Slight optimization + line wrapping
Mikael Berthe <mikael@lilotux.net>
parents:
1159
diff
changeset
|
512 win_entry->bd->top) == -1)) { |
105 | 513 // Move up CHAT_WIN_HEIGHT lines |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
514 win_entry->bd->hbuf = g_list_last(win_entry->bd->hbuf); |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
515 hbuf_head = win_entry->bd->hbuf; |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
516 win_entry->bd->top = NULL; // (Just to make sure) |
105 | 517 n = 0; |
518 while (hbuf_head && (n < CHAT_WIN_HEIGHT-1) && g_list_previous(hbuf_head)) { | |
519 hbuf_head = g_list_previous(hbuf_head); | |
520 n++; | |
521 } | |
873
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
522 // If the buffer is locked, remember current "top" line for the next time. |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
523 if (win_entry->bd->lock) |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
524 win_entry->bd->top = hbuf_head; |
105 | 525 } else |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
526 hbuf_head = win_entry->bd->top; |
74 | 527 |
528 // Get the last CHAT_WIN_HEIGHT lines. | |
529 lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT); | |
530 | |
531 // Display these lines | |
532 for (n = 0; n < CHAT_WIN_HEIGHT; n++) { | |
168 | 533 wmove(win_entry->win, n, 0); |
184 | 534 line = *(lines+n); |
185 | 535 // NOTE: update PREFIX_WIDTH if you change the date format!! |
536 // You need to set it to the whole prefix length + 1 | |
184 | 537 if (line) { |
730
e46c680bdd3d
New color: color_highlight (for outgoing messages)
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
538 if (line->flags & HBB_PREFIX_HLIGHT) |
785
7e0562e3bc83
Replace color_highlight with color_msgout
Mikael Berthe <mikael@lilotux.net>
parents:
779
diff
changeset
|
539 wattrset(win_entry->win, get_color(COLOR_MSGOUT)); |
730
e46c680bdd3d
New color: color_highlight (for outgoing messages)
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
540 |
850
d0781ca2dd08
Use new status buffer window
Mikael Berthe <mikael@lilotux.net>
parents:
849
diff
changeset
|
541 if (line->timestamp && !(line->flags & HBB_PREFIX_SPECIAL)) { |
419 | 542 strftime(date, 30, "%m-%d %H:%M", localtime(&line->timestamp)); |
184 | 543 } else |
185 | 544 strcpy(date, " "); |
197 | 545 if (line->flags & HBB_PREFIX_INFO) { |
546 char dir = '*'; | |
547 if (line->flags & HBB_PREFIX_IN) | |
548 dir = '<'; | |
549 else if (line->flags & HBB_PREFIX_OUT) | |
550 dir = '>'; | |
551 wprintw(win_entry->win, "%.11s *%c* ", date, dir); | |
325
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
552 } else if (line->flags & HBB_PREFIX_ERR) { |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
553 char dir = '#'; |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
554 if (line->flags & HBB_PREFIX_IN) |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
555 dir = '<'; |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
556 else if (line->flags & HBB_PREFIX_OUT) |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
557 dir = '>'; |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
558 wprintw(win_entry->win, "%.11s #%c# ", date, dir); |
728
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
727
diff
changeset
|
559 } else if (line->flags & HBB_PREFIX_IN) { |
1058 | 560 char cryptflag = line->flags & HBB_PREFIX_PGPCRYPT ? '~' : '='; |
561 wprintw(win_entry->win, "%.11s <%c= ", date, cryptflag); | |
728
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
727
diff
changeset
|
562 } else if (line->flags & HBB_PREFIX_OUT) { |
1058 | 563 char cryptflag = line->flags & HBB_PREFIX_PGPCRYPT ? '~' : '-'; |
564 wprintw(win_entry->win, "%.11s -%c> ", date, cryptflag); | |
850
d0781ca2dd08
Use new status buffer window
Mikael Berthe <mikael@lilotux.net>
parents:
849
diff
changeset
|
565 } else if (line->flags & HBB_PREFIX_SPECIAL) { |
d0781ca2dd08
Use new status buffer window
Mikael Berthe <mikael@lilotux.net>
parents:
849
diff
changeset
|
566 strftime(date, 30, "%m-%d %H:%M:%S", localtime(&line->timestamp)); |
d0781ca2dd08
Use new status buffer window
Mikael Berthe <mikael@lilotux.net>
parents:
849
diff
changeset
|
567 wprintw(win_entry->win, "%.14s ", date); |
728
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
727
diff
changeset
|
568 } else { |
185 | 569 wprintw(win_entry->win, "%.11s ", date); |
75 | 570 } |
729
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
728
diff
changeset
|
571 |
730
e46c680bdd3d
New color: color_highlight (for outgoing messages)
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
572 wprintw(win_entry->win, "%s", line->text); // Display text line |
729
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
728
diff
changeset
|
573 |
730
e46c680bdd3d
New color: color_highlight (for outgoing messages)
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
574 if (line->flags & HBB_PREFIX_HLIGHT) |
739
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
575 wattrset(win_entry->win, get_color(COLOR_GENERAL)); |
168 | 576 wclrtoeol(win_entry->win); |
184 | 577 g_free(line->text); |
898
c65b71dcda94
Fix memory leak in scr_UpdateWindow()
Mikael Berthe <mikael@lilotux.net>
parents:
897
diff
changeset
|
578 g_free(line); |
168 | 579 } else { |
580 wclrtobot(win_entry->win); | |
581 break; | |
75 | 582 } |
74 | 583 } |
584 g_free(lines); | |
585 } | |
1159
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1157
diff
changeset
|
586 |
53c0c5be43fa
Small fixes, typos and cleanups
Mikael Berthe <mikael@lilotux.net>
parents:
1157
diff
changeset
|
587 static winbuf *scr_CreateWindow(const char *winId, int special, int dont_show) |
1154 | 588 { |
589 if (special) { | |
590 if (!statusWindow) { | |
591 statusWindow = scr_new_buddy(NULL, dont_show); | |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
592 statusWindow->bd->hbuf = statushbuf; |
1154 | 593 } |
594 return statusWindow; | |
595 } else { | |
596 return scr_new_buddy(winId, dont_show); | |
597 } | |
598 } | |
599 | |
143 | 600 // scr_ShowWindow() |
601 // Display the chat window with the given identifier. | |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
602 // "special" must be true if this is a special buffer window. |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
603 static void scr_ShowWindow(const char *winId, int special) |
24 | 604 { |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
605 winbuf *win_entry; |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
606 |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
607 win_entry = scr_SearchWindow(winId, special); |
74 | 608 |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
609 if (!win_entry) { |
1154 | 610 win_entry = scr_CreateWindow(winId, special, FALSE); |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
611 } |
74 | 612 |
180 | 613 top_panel(win_entry->panel); |
614 currentWindow = win_entry; | |
615 chatmode = TRUE; | |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
616 if (!win_entry->bd->lock) |
889
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
888
diff
changeset
|
617 roster_msg_setflag(winId, special, FALSE); |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
888
diff
changeset
|
618 if (!special) |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
619 roster_setflags(winId, ROSTER_FLAG_LOCK, TRUE); |
874
293e8955075c
Display a flag in the chat status line when the buffer is locked
Mikael Berthe <mikael@lilotux.net>
parents:
873
diff
changeset
|
620 update_roster = TRUE; |
74 | 621 |
180 | 622 // Refresh the window |
623 scr_UpdateWindow(win_entry); | |
624 | |
625 // Finished :) | |
626 update_panels(); | |
142 | 627 |
628 top_panel(inputPanel); | |
24 | 629 } |
630 | |
143 | 631 // scr_ShowBuddyWindow() |
632 // Display the chat window buffer for the current buddy. | |
24 | 633 void scr_ShowBuddyWindow(void) |
634 { | |
1058 | 635 const gchar *bjid; |
140 | 636 |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
637 if (!current_buddy) { |
1058 | 638 bjid = NULL; |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
639 } else { |
1058 | 640 bjid = CURRENT_JID; |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
641 if (buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_SPECIAL) { |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
642 scr_ShowWindow(buddy_getname(BUDDATA(current_buddy)), TRUE); |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
643 return; |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
644 } |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
645 } |
140 | 646 |
1058 | 647 if (!bjid) { |
140 | 648 top_panel(chatPanel); |
143 | 649 top_panel(inputPanel); |
140 | 650 currentWindow = NULL; |
105 | 651 return; |
140 | 652 } |
653 | |
1058 | 654 scr_ShowWindow(bjid, FALSE); |
24 | 655 } |
656 | |
865
cee8d6be04e1
Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents:
858
diff
changeset
|
657 // scr_UpdateBuddyWindow() |
cee8d6be04e1
Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents:
858
diff
changeset
|
658 // (Re)Display the current window. |
cee8d6be04e1
Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents:
858
diff
changeset
|
659 // If chatmode is enabled, call scr_ShowBuddyWindow(), |
cee8d6be04e1
Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents:
858
diff
changeset
|
660 // else display the chat window. |
cee8d6be04e1
Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents:
858
diff
changeset
|
661 inline void scr_UpdateBuddyWindow(void) |
cee8d6be04e1
Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents:
858
diff
changeset
|
662 { |
cee8d6be04e1
Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents:
858
diff
changeset
|
663 if (chatmode) { |
cee8d6be04e1
Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents:
858
diff
changeset
|
664 scr_ShowBuddyWindow(); |
cee8d6be04e1
Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents:
858
diff
changeset
|
665 return; |
cee8d6be04e1
Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents:
858
diff
changeset
|
666 } |
cee8d6be04e1
Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents:
858
diff
changeset
|
667 |
cee8d6be04e1
Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents:
858
diff
changeset
|
668 top_panel(chatPanel); |
cee8d6be04e1
Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents:
858
diff
changeset
|
669 top_panel(inputPanel); |
cee8d6be04e1
Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents:
858
diff
changeset
|
670 } |
cee8d6be04e1
Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents:
858
diff
changeset
|
671 |
143 | 672 // scr_WriteInWindow() |
673 // Write some text in the winId window (this usually is a jid). | |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
674 // Use winId == NULL for the special status buffer. |
143 | 675 // Lines are splitted when they are too long to fit in the chat window. |
676 // If this window doesn't exist, it is created. | |
184 | 677 void scr_WriteInWindow(const char *winId, const char *text, time_t timestamp, |
850
d0781ca2dd08
Use new status buffer window
Mikael Berthe <mikael@lilotux.net>
parents:
849
diff
changeset
|
678 unsigned int prefix_flags, int force_show) |
24 | 679 { |
822 | 680 winbuf *win_entry; |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
771
diff
changeset
|
681 char *text_locale; |
24 | 682 int dont_show = FALSE; |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
683 int special; |
1142
0e27177882c7
Small fix for the max_history_blocks option
Mikael Berthe <mikael@lilotux.net>
parents:
1141
diff
changeset
|
684 guint num_history_blocks; |
873
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
685 bool setmsgflg = FALSE; |
24 | 686 |
74 | 687 // Look for the window entry. |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
688 special = (winId == NULL); |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
689 win_entry = scr_SearchWindow(winId, special); |
74 | 690 |
691 // Do we have to really show the window? | |
24 | 692 if (!chatmode) |
693 dont_show = TRUE; | |
74 | 694 else if ((!force_show) && ((!currentWindow || (currentWindow != win_entry)))) |
24 | 695 dont_show = TRUE; |
696 | |
74 | 697 // If the window entry doesn't exist yet, let's create it. |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
698 if (!win_entry) { |
1154 | 699 win_entry = scr_CreateWindow(winId, special, dont_show); |
24 | 700 } |
701 | |
220 | 702 // The message must be displayed -> update top pointer |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
703 if (win_entry->bd->cleared) |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
704 win_entry->bd->top = g_list_last(win_entry->bd->hbuf); |
220 | 705 |
1142
0e27177882c7
Small fix for the max_history_blocks option
Mikael Berthe <mikael@lilotux.net>
parents:
1141
diff
changeset
|
706 // Make sure we do not free the buffer while it's locked or when |
0e27177882c7
Small fix for the max_history_blocks option
Mikael Berthe <mikael@lilotux.net>
parents:
1141
diff
changeset
|
707 // top is set. |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
708 if (win_entry->bd->lock || win_entry->bd->top) |
1142
0e27177882c7
Small fix for the max_history_blocks option
Mikael Berthe <mikael@lilotux.net>
parents:
1141
diff
changeset
|
709 num_history_blocks = 0U; |
0e27177882c7
Small fix for the max_history_blocks option
Mikael Berthe <mikael@lilotux.net>
parents:
1141
diff
changeset
|
710 else |
0e27177882c7
Small fix for the max_history_blocks option
Mikael Berthe <mikael@lilotux.net>
parents:
1141
diff
changeset
|
711 num_history_blocks = get_max_history_blocks(); |
0e27177882c7
Small fix for the max_history_blocks option
Mikael Berthe <mikael@lilotux.net>
parents:
1141
diff
changeset
|
712 |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
771
diff
changeset
|
713 text_locale = from_utf8(text); |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
714 hbuf_add_line(&win_entry->bd->hbuf, text_locale, timestamp, prefix_flags, |
1142
0e27177882c7
Small fix for the max_history_blocks option
Mikael Berthe <mikael@lilotux.net>
parents:
1141
diff
changeset
|
715 maxX - Roster_Width - PREFIX_WIDTH, num_history_blocks); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
771
diff
changeset
|
716 g_free(text_locale); |
74 | 717 |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
718 if (win_entry->bd->cleared) { |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
719 win_entry->bd->cleared = FALSE; |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
720 if (g_list_next(win_entry->bd->top)) |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
721 win_entry->bd->top = g_list_next(win_entry->bd->top); |
220 | 722 } |
723 | |
724 // Make sure the last line appears in the window; update top if necessary | |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
725 if (!win_entry->bd->lock && win_entry->bd->top) { |
220 | 726 int dist; |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
727 GList *first = g_list_first(win_entry->bd->hbuf); |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
728 dist = g_list_position(first, g_list_last(win_entry->bd->hbuf)) - |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
729 g_list_position(first, win_entry->bd->top); |
220 | 730 if (dist >= CHAT_WIN_HEIGHT) |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
731 win_entry->bd->top = NULL; |
108 | 732 } |
733 | |
24 | 734 if (!dont_show) { |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
735 if (win_entry->bd->lock) |
873
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
736 setmsgflg = TRUE; |
74 | 737 // Show and refresh the window |
738 top_panel(win_entry->panel); | |
739 scr_UpdateWindow(win_entry); | |
142 | 740 top_panel(inputPanel); |
24 | 741 update_panels(); |
873
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
742 } else if (!(prefix_flags & HBB_PREFIX_NOFLAG)) { |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
743 setmsgflg = TRUE; |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
744 } |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
745 if (setmsgflg && !special) { |
889
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
888
diff
changeset
|
746 if (special && !winId) |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
888
diff
changeset
|
747 winId = SPECIAL_BUFFER_STATUS_ID; |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
888
diff
changeset
|
748 roster_msg_setflag(winId, special, TRUE); |
30 | 749 update_roster = TRUE; |
24 | 750 } |
751 } | |
752 | |
713 | 753 // scr_UpdateMainStatus() |
754 // Redraw the main (bottom) status line. | |
724
264375fe7159
Fix a roster refresh issue
Mikael Berthe <mikael@lilotux.net>
parents:
723
diff
changeset
|
755 void scr_UpdateMainStatus(int forceupdate) |
713 | 756 { |
773
e25b8a348ebd
Screen updating functions use UTF-8
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
757 char *sm = from_utf8(jb_getstatusmsg()); |
713 | 758 |
759 werase(mainstatusWnd); | |
724
264375fe7159
Fix a roster refresh issue
Mikael Berthe <mikael@lilotux.net>
parents:
723
diff
changeset
|
760 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
|
761 (unread_msg(NULL) ? '#' : ' '), |
b41799901abd
Add a new_message flag (#) in the main status line
Mikael Berthe <mikael@lilotux.net>
parents:
717
diff
changeset
|
762 imstatus2char[jb_getstatus()], (sm ? sm : "")); |
724
264375fe7159
Fix a roster refresh issue
Mikael Berthe <mikael@lilotux.net>
parents:
723
diff
changeset
|
763 if (forceupdate) { |
264375fe7159
Fix a roster refresh issue
Mikael Berthe <mikael@lilotux.net>
parents:
723
diff
changeset
|
764 top_panel(inputPanel); |
264375fe7159
Fix a roster refresh issue
Mikael Berthe <mikael@lilotux.net>
parents:
723
diff
changeset
|
765 update_panels(); |
264375fe7159
Fix a roster refresh issue
Mikael Berthe <mikael@lilotux.net>
parents:
723
diff
changeset
|
766 } |
773
e25b8a348ebd
Screen updating functions use UTF-8
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
767 g_free(sm); |
713 | 768 } |
769 | |
151 | 770 // scr_DrawMainWindow() |
157 | 771 // Set fullinit to TRUE to also create panels. Set it to FALSE for a resize. |
151 | 772 // |
773 // I think it could be improved a _lot_ but I'm really not an ncurses | |
774 // expert... :-\ Mikael. | |
775 // | |
776 void scr_DrawMainWindow(unsigned int fullinit) | |
24 | 777 { |
701
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
778 int requested_size; |
961
95659cf9ea1a
Display mcabber version in the status window
Mikael Berthe <mikael@lilotux.net>
parents:
952
diff
changeset
|
779 gchar *ver, *message; |
972
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
780 int chat_y_pos, chatstatus_y_pos, log_y_pos; |
973
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
781 int roster_x_pos, chat_x_pos; |
518
9480a76471b6
Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents:
515
diff
changeset
|
782 |
9480a76471b6
Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents:
515
diff
changeset
|
783 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
|
784 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
|
785 if (requested_size > 0) { |
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
786 if (maxY > requested_size + 3) |
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
787 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
|
788 else |
9480a76471b6
Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents:
515
diff
changeset
|
789 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
|
790 } else if (requested_size < 0) { |
518
9480a76471b6
Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents:
515
diff
changeset
|
791 Log_Win_Height = 3; |
9480a76471b6
Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents:
515
diff
changeset
|
792 } |
9480a76471b6
Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents:
515
diff
changeset
|
793 |
9480a76471b6
Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents:
515
diff
changeset
|
794 if (maxY < Log_Win_Height+2) { |
9480a76471b6
Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents:
515
diff
changeset
|
795 if (maxY < 5) { |
9480a76471b6
Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents:
515
diff
changeset
|
796 Log_Win_Height = 3; |
9480a76471b6
Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents:
515
diff
changeset
|
797 maxY = Log_Win_Height+2; |
9480a76471b6
Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents:
515
diff
changeset
|
798 } else { |
9480a76471b6
Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents:
515
diff
changeset
|
799 Log_Win_Height = maxY - 2; |
9480a76471b6
Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents:
515
diff
changeset
|
800 } |
9480a76471b6
Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents:
515
diff
changeset
|
801 } |
9480a76471b6
Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents:
515
diff
changeset
|
802 |
707
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
803 if (roster_hidden) { |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
804 Roster_Width = 0; |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
805 } else { |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
806 requested_size = settings_opt_get_int("roster_width"); |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
807 if (requested_size > 1) |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
808 Roster_Width = requested_size; |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
809 else if (requested_size == 1) |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
810 Roster_Width = 2; |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
811 else |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
812 Roster_Width = DEFAULT_ROSTER_WIDTH; |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
813 } |
701
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
814 |
972
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
815 log_win_on_top = (settings_opt_get_int("log_win_on_top") == 1); |
973
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
816 roster_win_on_right = (settings_opt_get_int("roster_win_on_right") == 1); |
972
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
817 |
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
818 if (log_win_on_top) { |
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
819 chat_y_pos = Log_Win_Height-1; |
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
820 log_y_pos = 0; |
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
821 chatstatus_y_pos = Log_Win_Height-2; |
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
822 } else { |
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
823 chat_y_pos = 0; |
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
824 log_y_pos = CHAT_WIN_HEIGHT+1; |
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
825 chatstatus_y_pos = CHAT_WIN_HEIGHT; |
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
826 } |
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
827 |
973
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
828 if (roster_win_on_right) { |
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
829 roster_x_pos = maxX - Roster_Width; |
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
830 chat_x_pos = 0; |
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
831 } else { |
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
832 roster_x_pos = 0; |
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
833 chat_x_pos = Roster_Width; |
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
834 } |
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
835 |
157 | 836 if (fullinit) { |
1078
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
837 if (!winbufhash) |
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
838 winbufhash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); |
157 | 839 /* Create windows */ |
973
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
840 rosterWnd = newwin(CHAT_WIN_HEIGHT, Roster_Width, chat_y_pos, roster_x_pos); |
972
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
841 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - Roster_Width, chat_y_pos, |
973
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
842 chat_x_pos); |
1133
9dd28a56128f
Do not create one panel per contact
Mikael Berthe <mikael@lilotux.net>
parents:
1131
diff
changeset
|
843 activechatWnd = newwin(CHAT_WIN_HEIGHT, maxX - Roster_Width, chat_y_pos, |
9dd28a56128f
Do not create one panel per contact
Mikael Berthe <mikael@lilotux.net>
parents:
1131
diff
changeset
|
844 chat_x_pos); |
972
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
845 logWnd = newwin(Log_Win_Height-2, maxX, log_y_pos, 0); |
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
846 chatstatusWnd = newwin(1, maxX, chatstatus_y_pos, 0); |
711 | 847 mainstatusWnd = newwin(1, maxX, maxY-2, 0); |
157 | 848 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
|
849 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
|
850 scr_TerminateCurses(); |
6e4e667c5571
Fix a segfault when starting mcabber in a really small terminal
Mikael Berthe <mikael@lilotux.net>
parents:
339
diff
changeset
|
851 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
|
852 exit(EXIT_FAILURE); |
6e4e667c5571
Fix a segfault when starting mcabber in a really small terminal
Mikael Berthe <mikael@lilotux.net>
parents:
339
diff
changeset
|
853 } |
739
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
854 wbkgd(rosterWnd, get_color(COLOR_GENERAL)); |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
855 wbkgd(chatWnd, get_color(COLOR_GENERAL)); |
1133
9dd28a56128f
Do not create one panel per contact
Mikael Berthe <mikael@lilotux.net>
parents:
1131
diff
changeset
|
856 wbkgd(activechatWnd, get_color(COLOR_GENERAL)); |
739
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
857 wbkgd(logWnd, get_color(COLOR_GENERAL)); |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
858 wbkgd(chatstatusWnd, get_color(COLOR_STATUS)); |
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
859 wbkgd(mainstatusWnd, get_color(COLOR_STATUS)); |
157 | 860 } else { |
701
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
861 /* Resize/move windows */ |
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
862 wresize(rosterWnd, CHAT_WIN_HEIGHT, Roster_Width); |
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
863 wresize(chatWnd, CHAT_WIN_HEIGHT, maxX - Roster_Width); |
711 | 864 wresize(logWnd, Log_Win_Height-2, maxX); |
157 | 865 |
973
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
866 mvwin(chatWnd, chat_y_pos, chat_x_pos); |
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
867 mvwin(rosterWnd, chat_y_pos, roster_x_pos); |
972
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
868 mvwin(logWnd, log_y_pos, 0); |
157 | 869 |
711 | 870 // Resize & move chat status window |
871 wresize(chatstatusWnd, 1, maxX); | |
972
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
872 mvwin(chatstatusWnd, chatstatus_y_pos, 0); |
711 | 873 // Resize & move main status window |
874 wresize(mainstatusWnd, 1, maxX); | |
875 mvwin(mainstatusWnd, maxY-2, 0); | |
876 // Resize & move input line window | |
157 | 877 wresize(inputWnd, 1, maxX); |
878 mvwin(inputWnd, maxY-1, 0); | |
168 | 879 |
880 werase(chatWnd); | |
157 | 881 } |
151 | 882 |
883 /* Draw/init windows */ | |
884 | |
961
95659cf9ea1a
Display mcabber version in the status window
Mikael Berthe <mikael@lilotux.net>
parents:
952
diff
changeset
|
885 ver = mcabber_version(); |
95659cf9ea1a
Display mcabber version in the status window
Mikael Berthe <mikael@lilotux.net>
parents:
952
diff
changeset
|
886 message = g_strdup_printf("MCabber version %s.\n", ver); |
95659cf9ea1a
Display mcabber version in the status window
Mikael Berthe <mikael@lilotux.net>
parents:
952
diff
changeset
|
887 mvwprintw(chatWnd, 0, 0, message); |
679
5933a8036672
Remove "This is the status window" message
Mikael Berthe <mikael@lilotux.net>
parents:
675
diff
changeset
|
888 mvwprintw(chatWnd, 1, 0, "http://www.lilotux.net/~mikael/mcabber/"); |
961
95659cf9ea1a
Display mcabber version in the status window
Mikael Berthe <mikael@lilotux.net>
parents:
952
diff
changeset
|
889 g_free(ver); |
95659cf9ea1a
Display mcabber version in the status window
Mikael Berthe <mikael@lilotux.net>
parents:
952
diff
changeset
|
890 g_free(message); |
24 | 891 |
157 | 892 // Auto-scrolling in log window |
74 | 893 scrollok(logWnd, TRUE); |
24 | 894 |
895 | |
151 | 896 if (fullinit) { |
157 | 897 // Enable keypad (+ special keys) |
898 keypad(inputWnd, TRUE); | |
382
4c6e8392e465
Use nodelay() instead of halfdelay()
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
899 nodelay(inputWnd, TRUE); |
157 | 900 |
151 | 901 // Create panels |
902 rosterPanel = new_panel(rosterWnd); | |
903 chatPanel = new_panel(chatWnd); | |
1133
9dd28a56128f
Do not create one panel per contact
Mikael Berthe <mikael@lilotux.net>
parents:
1131
diff
changeset
|
904 activechatPanel = new_panel(activechatWnd); |
151 | 905 logPanel = new_panel(logWnd); |
711 | 906 chatstatusPanel = new_panel(chatstatusWnd); |
907 mainstatusPanel = new_panel(mainstatusWnd); | |
151 | 908 inputPanel = new_panel(inputWnd); |
232 | 909 |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
910 // Build the buddylist at least once, to make sure the special buffer |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
911 // is added |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
912 buddylist_build(); |
1093
6ca9a65df21f
Do not rewrap buffer lines when the chat window width doesn't change
Mikael Berthe <mikael@lilotux.net>
parents:
1089
diff
changeset
|
913 |
6ca9a65df21f
Do not rewrap buffer lines when the chat window width doesn't change
Mikael Berthe <mikael@lilotux.net>
parents:
1089
diff
changeset
|
914 // Init prev_chatwidth; this variable will be used to prevent us |
6ca9a65df21f
Do not rewrap buffer lines when the chat window width doesn't change
Mikael Berthe <mikael@lilotux.net>
parents:
1089
diff
changeset
|
915 // from rewrapping buffers when the width doesn't change. |
6ca9a65df21f
Do not rewrap buffer lines when the chat window width doesn't change
Mikael Berthe <mikael@lilotux.net>
parents:
1089
diff
changeset
|
916 prev_chatwidth = maxX - Roster_Width - PREFIX_WIDTH; |
851
da03534e46c7
Add startup log messages to the status buffer
Mikael Berthe <mikael@lilotux.net>
parents:
850
diff
changeset
|
917 // Wrap existing status buffer lines |
1093
6ca9a65df21f
Do not rewrap buffer lines when the chat window width doesn't change
Mikael Berthe <mikael@lilotux.net>
parents:
1089
diff
changeset
|
918 hbuf_rebuild(&statushbuf, prev_chatwidth); |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
919 |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
920 #ifndef UNICODE |
232 | 921 if (utf8_mode) |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
922 scr_LogPrint(LPRINT_NORMAL, |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
923 "WARNING: Compiled without full UTF-8 support!"); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
924 #endif |
157 | 925 } else { |
926 // Update panels | |
927 replace_panel(rosterPanel, rosterWnd); | |
928 replace_panel(chatPanel, chatWnd); | |
929 replace_panel(logPanel, logWnd); | |
711 | 930 replace_panel(chatstatusPanel, chatstatusWnd); |
931 replace_panel(mainstatusPanel, mainstatusWnd); | |
157 | 932 replace_panel(inputPanel, inputWnd); |
151 | 933 } |
934 | |
935 // We'll need to redraw the roster | |
149 | 936 update_roster = TRUE; |
24 | 937 return; |
938 } | |
939 | |
1078
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
940 static void resize_win_buffer(gpointer key, gpointer value, gpointer data) |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
941 { |
1078
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
942 winbuf *wbp = value; |
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
943 struct dimensions *dim = data; |
973
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
944 int chat_x_pos, chat_y_pos; |
1093
6ca9a65df21f
Do not rewrap buffer lines when the chat window width doesn't change
Mikael Berthe <mikael@lilotux.net>
parents:
1089
diff
changeset
|
945 int new_chatwidth; |
972
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
946 |
1078
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
947 if (!(wbp && wbp->win)) |
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
948 return; |
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
949 |
972
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
950 if (log_win_on_top) |
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
951 chat_y_pos = Log_Win_Height-1; |
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
952 else |
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
953 chat_y_pos = 0; |
11b632d824f6
Add option 'log_win_on_top'
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
954 |
973
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
955 if (roster_win_on_right) |
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
956 chat_x_pos = 0; |
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
957 else |
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
958 chat_x_pos = Roster_Width; |
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
959 |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
960 // Resize/move buddy window |
1078
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
961 wresize(wbp->win, dim->l, dim->c); |
973
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
962 mvwin(wbp->win, chat_y_pos, chat_x_pos); |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
963 werase(wbp->win); |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
964 // If a panel exists, replace the old window with the new |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
965 if (wbp->panel) |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
966 replace_panel(wbp->panel, wbp->win); |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
967 // Redo line wrapping |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
968 wbp->bd->top = hbuf_previous_persistent(wbp->bd->top); |
1093
6ca9a65df21f
Do not rewrap buffer lines when the chat window width doesn't change
Mikael Berthe <mikael@lilotux.net>
parents:
1089
diff
changeset
|
969 |
6ca9a65df21f
Do not rewrap buffer lines when the chat window width doesn't change
Mikael Berthe <mikael@lilotux.net>
parents:
1089
diff
changeset
|
970 new_chatwidth = maxX - Roster_Width - PREFIX_WIDTH; |
6ca9a65df21f
Do not rewrap buffer lines when the chat window width doesn't change
Mikael Berthe <mikael@lilotux.net>
parents:
1089
diff
changeset
|
971 if (new_chatwidth != prev_chatwidth) |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
972 hbuf_rebuild(&wbp->bd->hbuf, new_chatwidth); |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
973 } |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
974 |
151 | 975 // scr_Resize() |
976 // Function called when the window is resized. | |
157 | 977 // - Resize windows |
151 | 978 // - Rewrap lines in each buddy buffer |
1059 | 979 void scr_Resize(void) |
151 | 980 { |
1078
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
981 struct dimensions dim; |
151 | 982 |
983 // First, update the global variables | |
984 getmaxyx(stdscr, maxY, maxX); | |
518
9480a76471b6
Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents:
515
diff
changeset
|
985 // 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
|
986 |
151 | 987 // Make sure the cursor stays inside the window |
988 check_offset(0); | |
989 | |
157 | 990 // Resize windows and update panels |
151 | 991 scr_DrawMainWindow(FALSE); |
992 | |
993 // Resize all buddy windows | |
1078
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
994 dim.l = CHAT_WIN_HEIGHT; |
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
995 dim.c = maxX - Roster_Width; |
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
996 if (dim.c < 1) |
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
997 dim.c = 1; |
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
998 |
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
999 // Resize all buffers |
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
1000 g_hash_table_foreach(winbufhash, resize_win_buffer, &dim); |
151 | 1001 |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1002 // Resize/move special status buffer |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1003 if (statusWindow) |
1078
7866dbaf67a6
Use a hash for the list of win buffers
Mikael Berthe <mikael@lilotux.net>
parents:
1077
diff
changeset
|
1004 resize_win_buffer(NULL, statusWindow, &dim); |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1005 |
1093
6ca9a65df21f
Do not rewrap buffer lines when the chat window width doesn't change
Mikael Berthe <mikael@lilotux.net>
parents:
1089
diff
changeset
|
1006 // Update prev_chatwidth, now that all buffers have been resized |
6ca9a65df21f
Do not rewrap buffer lines when the chat window width doesn't change
Mikael Berthe <mikael@lilotux.net>
parents:
1089
diff
changeset
|
1007 prev_chatwidth = maxX - Roster_Width - PREFIX_WIDTH; |
6ca9a65df21f
Do not rewrap buffer lines when the chat window width doesn't change
Mikael Berthe <mikael@lilotux.net>
parents:
1089
diff
changeset
|
1008 |
151 | 1009 // Refresh current buddy window |
157 | 1010 if (chatmode) |
151 | 1011 scr_ShowBuddyWindow(); |
1012 } | |
1013 | |
721
9cf31c9b1dc4
Use room topic as a description in the chat status line
Mikael Berthe <mikael@lilotux.net>
parents:
720
diff
changeset
|
1014 // scr_UpdateChatStatus(forceupdate) |
713 | 1015 // Redraw the buddy status bar. |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
936
diff
changeset
|
1016 // Set forceupdate to TRUE if update_panels() 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
|
1017 void scr_UpdateChatStatus(int forceupdate) |
713 | 1018 { |
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1019 unsigned short btype, isgrp, ismuc, isspe; |
717
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1020 const char *fullname; |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1021 const char *msg = NULL; |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1022 char status; |
773
e25b8a348ebd
Screen updating functions use UTF-8
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
1023 char *buf, *buf_locale; |
713 | 1024 |
718
b41799901abd
Add a new_message flag (#) in the main status line
Mikael Berthe <mikael@lilotux.net>
parents:
717
diff
changeset
|
1025 // 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
|
1026 // at least to refresh the pending message flag. |
724
264375fe7159
Fix a roster refresh issue
Mikael Berthe <mikael@lilotux.net>
parents:
723
diff
changeset
|
1027 scr_UpdateMainStatus(FALSE); |
718
b41799901abd
Add a new_message flag (#) in the main status line
Mikael Berthe <mikael@lilotux.net>
parents:
717
diff
changeset
|
1028 |
806
3521e34f722a
Fix a segfault when not connected to a server
Mikael Berthe <mikael@lilotux.net>
parents:
797
diff
changeset
|
1029 // Clear the line |
3521e34f722a
Fix a segfault when not connected to a server
Mikael Berthe <mikael@lilotux.net>
parents:
797
diff
changeset
|
1030 werase(chatstatusWnd); |
3521e34f722a
Fix a segfault when not connected to a server
Mikael Berthe <mikael@lilotux.net>
parents:
797
diff
changeset
|
1031 |
3521e34f722a
Fix a segfault when not connected to a server
Mikael Berthe <mikael@lilotux.net>
parents:
797
diff
changeset
|
1032 if (chatmode) |
3521e34f722a
Fix a segfault when not connected to a server
Mikael Berthe <mikael@lilotux.net>
parents:
797
diff
changeset
|
1033 wprintw(chatstatusWnd, "~"); |
3521e34f722a
Fix a segfault when not connected to a server
Mikael Berthe <mikael@lilotux.net>
parents:
797
diff
changeset
|
1034 |
3521e34f722a
Fix a segfault when not connected to a server
Mikael Berthe <mikael@lilotux.net>
parents:
797
diff
changeset
|
1035 if (!current_buddy) { |
3521e34f722a
Fix a segfault when not connected to a server
Mikael Berthe <mikael@lilotux.net>
parents:
797
diff
changeset
|
1036 if (forceupdate) { |
3521e34f722a
Fix a segfault when not connected to a server
Mikael Berthe <mikael@lilotux.net>
parents:
797
diff
changeset
|
1037 update_panels(); |
3521e34f722a
Fix a segfault when not connected to a server
Mikael Berthe <mikael@lilotux.net>
parents:
797
diff
changeset
|
1038 } |
3521e34f722a
Fix a segfault when not connected to a server
Mikael Berthe <mikael@lilotux.net>
parents:
797
diff
changeset
|
1039 return; |
3521e34f722a
Fix a segfault when not connected to a server
Mikael Berthe <mikael@lilotux.net>
parents:
797
diff
changeset
|
1040 } |
3521e34f722a
Fix a segfault when not connected to a server
Mikael Berthe <mikael@lilotux.net>
parents:
797
diff
changeset
|
1041 |
717
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1042 fullname = buddy_getname(BUDDATA(current_buddy)); |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1043 btype = buddy_gettype(BUDDATA(current_buddy)); |
713 | 1044 |
717
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1045 isgrp = btype & ROSTER_TYPE_GROUP; |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1046 ismuc = btype & ROSTER_TYPE_ROOM; |
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1047 isspe = btype & ROSTER_TYPE_SPECIAL; |
713 | 1048 |
874
293e8955075c
Display a flag in the chat status line when the buffer is locked
Mikael Berthe <mikael@lilotux.net>
parents:
873
diff
changeset
|
1049 if (chatmode && !isgrp) { |
293e8955075c
Display a flag in the chat status line when the buffer is locked
Mikael Berthe <mikael@lilotux.net>
parents:
873
diff
changeset
|
1050 winbuf *win_entry; |
293e8955075c
Display a flag in the chat status line when the buffer is locked
Mikael Berthe <mikael@lilotux.net>
parents:
873
diff
changeset
|
1051 win_entry = scr_SearchWindow(buddy_getjid(BUDDATA(current_buddy)), isspe); |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1052 if (win_entry && win_entry->bd->lock) |
874
293e8955075c
Display a flag in the chat status line when the buffer is locked
Mikael Berthe <mikael@lilotux.net>
parents:
873
diff
changeset
|
1053 mvwprintw(chatstatusWnd, 0, 0, "*"); |
293e8955075c
Display a flag in the chat status line when the buffer is locked
Mikael Berthe <mikael@lilotux.net>
parents:
873
diff
changeset
|
1054 } |
293e8955075c
Display a flag in the chat status line when the buffer is locked
Mikael Berthe <mikael@lilotux.net>
parents:
873
diff
changeset
|
1055 |
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1056 if (isgrp || isspe) { |
773
e25b8a348ebd
Screen updating functions use UTF-8
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
1057 buf_locale = from_utf8(fullname); |
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1058 if (isgrp) |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1059 mvwprintw(chatstatusWnd, 0, 5, "Group: %s", buf_locale); |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1060 else |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1061 mvwprintw(chatstatusWnd, 0, 5, "Special buffer: %s", buf_locale); |
773
e25b8a348ebd
Screen updating functions use UTF-8
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
1062 g_free(buf_locale); |
716
ba1137a01078
Add a chatmode flag (©) in the chat status line
Mikael Berthe <mikael@lilotux.net>
parents:
715
diff
changeset
|
1063 if (forceupdate) { |
ba1137a01078
Add a chatmode flag (©) in the chat status line
Mikael Berthe <mikael@lilotux.net>
parents:
715
diff
changeset
|
1064 update_panels(); |
ba1137a01078
Add a chatmode flag (©) in the chat status line
Mikael Berthe <mikael@lilotux.net>
parents:
715
diff
changeset
|
1065 } |
717
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1066 return; |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1067 } |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1068 |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1069 status = '?'; |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1070 |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1071 if (ismuc) { |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1072 if (buddy_getinsideroom(BUDDATA(current_buddy))) |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1073 status = 'C'; |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1074 else |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1075 status = 'x'; |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1076 } else if (jb_getstatus() != offline) { |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1077 enum imstatus budstate; |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1078 budstate = buddy_getstatus(BUDDATA(current_buddy), NULL); |
790
5d4ad1d77da4
Kill a few gcc4 warnings
Mikael Berthe <mikael@lilotux.net>
parents:
785
diff
changeset
|
1079 if (budstate < imstatus_size) |
717
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1080 status = imstatus2char[budstate]; |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1081 } |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1082 |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1083 // No status message for groups & MUC rooms |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1084 if (!isgrp && !ismuc) { |
1072
2a3cfb98bd5e
Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents:
1059
diff
changeset
|
1085 GSList *resources, *p_res; |
2a3cfb98bd5e
Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents:
1059
diff
changeset
|
1086 resources = buddy_getresources(BUDDATA(current_buddy)); |
843
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
833
diff
changeset
|
1087 msg = buddy_getstatusmsg(BUDDATA(current_buddy), |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
833
diff
changeset
|
1088 resources ? resources->data : ""); |
1072
2a3cfb98bd5e
Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents:
1059
diff
changeset
|
1089 // Free the resources list data |
2a3cfb98bd5e
Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents:
1059
diff
changeset
|
1090 for (p_res = resources ; p_res ; p_res = g_slist_next(p_res)) |
2a3cfb98bd5e
Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents:
1059
diff
changeset
|
1091 g_free(p_res->data); |
2a3cfb98bd5e
Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents:
1059
diff
changeset
|
1092 g_slist_free(resources); |
721
9cf31c9b1dc4
Use room topic as a description in the chat status line
Mikael Berthe <mikael@lilotux.net>
parents:
720
diff
changeset
|
1093 } else if (ismuc) { |
9cf31c9b1dc4
Use room topic as a description in the chat status line
Mikael Berthe <mikael@lilotux.net>
parents:
720
diff
changeset
|
1094 msg = buddy_gettopic(BUDDATA(current_buddy)); |
717
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1095 } |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1096 if (!msg) |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1097 msg = ""; |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1098 |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1099 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
|
1100 replace_nl_with_dots(buf); |
773
e25b8a348ebd
Screen updating functions use UTF-8
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
1101 buf_locale = from_utf8(buf); |
e25b8a348ebd
Screen updating functions use UTF-8
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
1102 mvwprintw(chatstatusWnd, 0, 1, "%s", buf_locale); |
e25b8a348ebd
Screen updating functions use UTF-8
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
1103 g_free(buf_locale); |
717
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1104 g_free(buf); |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1105 |
996
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1106 // Display chatstates of the contact, if available. |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1107 if (btype & ROSTER_TYPE_USER) { |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1108 char eventchar = 0; |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1109 guint event; |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1110 |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1111 // We do not specify the resource here, so one of the resources with the |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1112 // highest priority will be used. |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1113 event = buddy_resource_getevents(BUDDATA(current_buddy), NULL); |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1114 |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1115 if (event == ROSTER_EVENT_ACTIVE) |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1116 eventchar = 'A'; |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1117 else if (event == ROSTER_EVENT_COMPOSING) |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1118 eventchar = 'C'; |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1119 else if (event == ROSTER_EVENT_PAUSED) |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1120 eventchar = 'P'; |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1121 else if (event == ROSTER_EVENT_INACTIVE) |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1122 eventchar = 'I'; |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1123 else if (event == ROSTER_EVENT_GONE) |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1124 eventchar = 'G'; |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1125 |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1126 if (eventchar) |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1127 mvwprintw(chatstatusWnd, 0, maxX-3, "[%c]", eventchar); |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1128 } |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1129 |
f4d6570e2628
Chatstates: display contact chatstate in the chat status bar
Mikael Berthe <mikael@lilotux.net>
parents:
993
diff
changeset
|
1130 |
717
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1131 if (forceupdate) { |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1132 update_panels(); |
8ce2bfdc4143
Reindent update_chat_status_window()
Mikael Berthe <mikael@lilotux.net>
parents:
716
diff
changeset
|
1133 } |
713 | 1134 } |
1135 | |
143 | 1136 // scr_DrawRoster() |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
1137 // Display the buddylist (not really the roster) on the screen |
81 | 1138 void scr_DrawRoster(void) |
24 | 1139 { |
735 | 1140 static int offset = 0; |
701
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1141 char *name, *rline; |
81 | 1142 int maxx, maxy; |
1143 GList *buddy; | |
1144 int i, n; | |
1145 int rOffset; | |
713 | 1146 int cursor_backup; |
1147 char status, pending; | |
164 | 1148 enum imstatus currentstatus = jb_getstatus(); |
973
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
1149 int x_pos; |
81 | 1150 |
123 | 1151 // We can reset update_roster |
1152 update_roster = FALSE; | |
1153 | |
81 | 1154 getmaxyx(rosterWnd, maxy, maxx); |
701
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1155 maxx--; // Last char is for vertical border |
81 | 1156 |
713 | 1157 cursor_backup = curs_set(0); |
1158 | |
724
264375fe7159
Fix a roster refresh issue
Mikael Berthe <mikael@lilotux.net>
parents:
723
diff
changeset
|
1159 if (!buddylist) |
264375fe7159
Fix a roster refresh issue
Mikael Berthe <mikael@lilotux.net>
parents:
723
diff
changeset
|
1160 offset = 0; |
264375fe7159
Fix a roster refresh issue
Mikael Berthe <mikael@lilotux.net>
parents:
723
diff
changeset
|
1161 else |
264375fe7159
Fix a roster refresh issue
Mikael Berthe <mikael@lilotux.net>
parents:
723
diff
changeset
|
1162 scr_UpdateChatStatus(FALSE); |
264375fe7159
Fix a roster refresh issue
Mikael Berthe <mikael@lilotux.net>
parents:
723
diff
changeset
|
1163 |
701
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1164 // Cleanup of roster window |
168 | 1165 werase(rosterWnd); |
81 | 1166 |
707
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1167 if (Roster_Width) { |
973
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
1168 int line_x_pos = roster_win_on_right ? 0 : Roster_Width-1; |
707
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1169 // Redraw the vertical line (not very good...) |
739
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
1170 wattrset(rosterWnd, get_color(COLOR_GENERAL)); |
707
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1171 for (i=0 ; i < CHAT_WIN_HEIGHT ; i++) |
973
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
1172 mvwaddch(rosterWnd, i, line_x_pos, ACS_VLINE); |
707
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1173 } |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1174 |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1175 // 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
|
1176 if (!buddylist || !Roster_Width) { |
123 | 1177 update_panels(); |
713 | 1178 curs_set(cursor_backup); |
81 | 1179 return; |
1180 } | |
1181 | |
84 | 1182 // Update offset if necessary |
680
1f8987e0e56c
Try to display as many buddylist items as possible
Mikael Berthe <mikael@lilotux.net>
parents:
679
diff
changeset
|
1183 // 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
|
1184 i = g_list_length(buddylist) - maxy; |
682
f3945593432e
Small fix in scr_DrawRoster()
Mikael Berthe <mikael@lilotux.net>
parents:
680
diff
changeset
|
1185 if (i < 0) |
f3945593432e
Small fix in scr_DrawRoster()
Mikael Berthe <mikael@lilotux.net>
parents:
680
diff
changeset
|
1186 i = 0; |
f3945593432e
Small fix in scr_DrawRoster()
Mikael Berthe <mikael@lilotux.net>
parents:
680
diff
changeset
|
1187 if (i < offset) |
680
1f8987e0e56c
Try to display as many buddylist items as possible
Mikael Berthe <mikael@lilotux.net>
parents:
679
diff
changeset
|
1188 offset = i; |
1f8987e0e56c
Try to display as many buddylist items as possible
Mikael Berthe <mikael@lilotux.net>
parents:
679
diff
changeset
|
1189 // b) Make sure the current_buddy is visible |
84 | 1190 i = g_list_position(buddylist, current_buddy); |
1191 if (i == -1) { // This is bad | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
1192 scr_LogPrint(LPRINT_NORMAL, "Doh! Can't find current selected buddy!!"); |
713 | 1193 curs_set(cursor_backup); |
84 | 1194 return; |
1195 } else if (i < offset) { | |
1196 offset = i; | |
1197 } else if (i+1 > offset + maxy) { | |
1198 offset = i + 1 - maxy; | |
1199 } | |
81 | 1200 |
973
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
1201 if (roster_win_on_right) |
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
1202 x_pos = 1; // 1 char offset (vertical line) |
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
1203 else |
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
1204 x_pos = 0; |
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
1205 |
1026
fc6060707022
[BP] Fixes truncating utf-8 buddy names (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
966
diff
changeset
|
1206 name = g_new0(char, 4*Roster_Width); |
fc6060707022
[BP] Fixes truncating utf-8 buddy names (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
966
diff
changeset
|
1207 rline = g_new0(char, 4*Roster_Width+1); |
701
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1208 |
81 | 1209 buddy = buddylist; |
1210 rOffset = offset; | |
1211 | |
84 | 1212 for (i=0; i<maxy && buddy; buddy = g_list_next(buddy)) { |
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1213 unsigned short bflags, btype, ismsg, isgrp, ismuc, ishid, isspe; |
773
e25b8a348ebd
Screen updating functions use UTF-8
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
1214 gchar *rline_locale; |
1072
2a3cfb98bd5e
Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents:
1059
diff
changeset
|
1215 GSList *resources, *p_res; |
713 | 1216 |
1217 bflags = buddy_getflags(BUDDATA(buddy)); | |
1218 btype = buddy_gettype(BUDDATA(buddy)); | |
1219 | |
1220 ismsg = bflags & ROSTER_FLAG_MSG; | |
1221 ishid = bflags & ROSTER_FLAG_HIDE; | |
1222 isgrp = btype & ROSTER_TYPE_GROUP; | |
1223 ismuc = btype & ROSTER_TYPE_ROOM; | |
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1224 isspe = btype & ROSTER_TYPE_SPECIAL; |
81 | 1225 |
1226 if (rOffset > 0) { | |
1227 rOffset--; | |
1228 continue; | |
1229 } | |
1230 | |
713 | 1231 status = '?'; |
1232 pending = ' '; | |
1233 | |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
981
diff
changeset
|
1234 resources = buddy_getresources(BUDDATA(buddy)); |
1072
2a3cfb98bd5e
Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents:
1059
diff
changeset
|
1235 for (p_res = resources ; p_res ; p_res = g_slist_next(p_res)) { |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
981
diff
changeset
|
1236 guint events = buddy_resource_getevents(BUDDATA(buddy), |
1072
2a3cfb98bd5e
Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents:
1059
diff
changeset
|
1237 p_res ? p_res->data : ""); |
2a3cfb98bd5e
Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents:
1059
diff
changeset
|
1238 if ((events & ROSTER_EVENT_PAUSED) && pending != '+') |
992
b37348c2aa79
Chatstates: display "paused" states in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
991
diff
changeset
|
1239 pending = '.'; |
1072
2a3cfb98bd5e
Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents:
1059
diff
changeset
|
1240 if (events & ROSTER_EVENT_COMPOSING) |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1241 pending = '+'; |
1072
2a3cfb98bd5e
Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents:
1059
diff
changeset
|
1242 g_free(p_res->data); |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
981
diff
changeset
|
1243 } |
1072
2a3cfb98bd5e
Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents:
1059
diff
changeset
|
1244 g_slist_free(resources); |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
981
diff
changeset
|
1245 |
149 | 1246 // Display message notice if there is a message flag, but not |
1247 // for unfolded groups. | |
1248 if (ismsg && (!isgrp || ishid)) { | |
81 | 1249 pending = '#'; |
1250 } | |
1251 | |
713 | 1252 if (ismuc) { |
1253 if (buddy_getinsideroom(BUDDATA(buddy))) | |
1254 status = 'C'; | |
1255 else | |
1256 status = 'x'; | |
1257 } else if (currentstatus != offline) { | |
1258 enum imstatus budstate; | |
1259 budstate = buddy_getstatus(BUDDATA(buddy), NULL); | |
790
5d4ad1d77da4
Kill a few gcc4 warnings
Mikael Berthe <mikael@lilotux.net>
parents:
785
diff
changeset
|
1260 if (budstate < imstatus_size) |
713 | 1261 status = imstatus2char[budstate]; |
1262 } | |
81 | 1263 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
|
1264 if (pending == '#') |
739
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
1265 wattrset(rosterWnd, get_color(COLOR_ROSTERSELNMSG)); |
723
23068490d063
Add text color when the selected buddy has an unread message
Mikael Berthe <mikael@lilotux.net>
parents:
721
diff
changeset
|
1266 else |
739
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
1267 wattrset(rosterWnd, get_color(COLOR_ROSTERSEL)); |
723
23068490d063
Add text color when the selected buddy has an unread message
Mikael Berthe <mikael@lilotux.net>
parents:
721
diff
changeset
|
1268 // The 3 following lines aim at coloring the whole line |
973
e693cbe33802
Add option 'roster_win_on_right'
Mikael Berthe <mikael@lilotux.net>
parents:
972
diff
changeset
|
1269 wmove(rosterWnd, i, x_pos); |
81 | 1270 for (n = 0; n < maxx; n++) |
1271 waddch(rosterWnd, ' '); | |
1272 } else { | |
149 | 1273 if (pending == '#') |
739
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
1274 wattrset(rosterWnd, get_color(COLOR_ROSTERNMSG)); |
139 | 1275 else |
739
0d5fb1d9077c
Allow "bright" text colors
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
1276 wattrset(rosterWnd, get_color(COLOR_ROSTER)); |
81 | 1277 } |
1278 | |
701
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1279 if (Roster_Width > 7) |
1026
fc6060707022
[BP] Fixes truncating utf-8 buddy names (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
966
diff
changeset
|
1280 g_utf8_strncpy(name, buddy_getname(BUDDATA(buddy)), Roster_Width-7); |
701
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1281 else |
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1282 name[0] = 0; |
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1283 |
149 | 1284 if (isgrp) { |
133 | 1285 char *sep; |
149 | 1286 if (ishid) |
133 | 1287 sep = "+++"; |
1288 else | |
1289 sep = "---"; | |
1168
eb05f960613f
Fix UTF-8 group names in the roster (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
1160
diff
changeset
|
1290 snprintf(rline, 4*Roster_Width, " %c%s %s", pending, sep, name); |
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1291 } else if (isspe) { |
1168
eb05f960613f
Fix UTF-8 group names in the roster (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
1160
diff
changeset
|
1292 snprintf(rline, 4*Roster_Width, " %c%s", pending, name); |
701
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1293 } else { |
824
37ef269330f0
Show incomplete subscriptions in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
822
diff
changeset
|
1294 char sepleft = '['; |
37ef269330f0
Show incomplete subscriptions in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
822
diff
changeset
|
1295 char sepright = ']'; |
37ef269330f0
Show incomplete subscriptions in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
822
diff
changeset
|
1296 if (btype & ROSTER_TYPE_USER) { |
37ef269330f0
Show incomplete subscriptions in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
822
diff
changeset
|
1297 guint subtype = buddy_getsubscription(BUDDATA(buddy)); |
832
7c210263c661
Small scr_DrawRoster() fix
Mikael Berthe <mikael@lilotux.net>
parents:
828
diff
changeset
|
1298 if (status == '_' && !(subtype & sub_to)) |
824
37ef269330f0
Show incomplete subscriptions in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
822
diff
changeset
|
1299 status = '?'; |
37ef269330f0
Show incomplete subscriptions in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
822
diff
changeset
|
1300 if (!(subtype & sub_from)) { |
37ef269330f0
Show incomplete subscriptions in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
822
diff
changeset
|
1301 sepleft = '{'; |
37ef269330f0
Show incomplete subscriptions in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
822
diff
changeset
|
1302 sepright = '}'; |
37ef269330f0
Show incomplete subscriptions in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
822
diff
changeset
|
1303 } |
37ef269330f0
Show incomplete subscriptions in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
822
diff
changeset
|
1304 } |
37ef269330f0
Show incomplete subscriptions in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
822
diff
changeset
|
1305 |
1026
fc6060707022
[BP] Fixes truncating utf-8 buddy names (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents:
966
diff
changeset
|
1306 snprintf(rline, 4*Roster_Width, |
824
37ef269330f0
Show incomplete subscriptions in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
822
diff
changeset
|
1307 " %c%c%c%c %s", pending, sepleft, status, sepright, name); |
133 | 1308 } |
84 | 1309 |
773
e25b8a348ebd
Screen updating functions use UTF-8
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
1310 rline_locale = from_utf8(rline); |
981
553b8ecf901f
Fixes truncating of utf-8 buddy names (again)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
980
diff
changeset
|
1311 mvwprintw(rosterWnd, i, x_pos, "%s", rline_locale); |
773
e25b8a348ebd
Screen updating functions use UTF-8
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
1312 g_free(rline_locale); |
84 | 1313 i++; |
81 | 1314 } |
1315 | |
701
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1316 g_free(rline); |
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1317 g_free(name); |
142 | 1318 top_panel(inputPanel); |
81 | 1319 update_panels(); |
713 | 1320 curs_set(cursor_backup); |
24 | 1321 } |
1322 | |
707
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1323 // scr_RosterVisibility(status) |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1324 // Set the roster visibility: |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1325 // status=1 Show roster |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1326 // status=0 Hide roster |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1327 // status=-1 Toggle roster status |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1328 void scr_RosterVisibility(int status) |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1329 { |
708
ed326697e4ed
scr_RosterVisibility(): do not refresh when it is not needed
Mikael Berthe <mikael@lilotux.net>
parents:
707
diff
changeset
|
1330 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
|
1331 |
707
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1332 if (status > 0) |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1333 roster_hidden = FALSE; |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1334 else if (status == 0) |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1335 roster_hidden = TRUE; |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1336 else |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1337 roster_hidden = !roster_hidden; |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1338 |
708
ed326697e4ed
scr_RosterVisibility(): do not refresh when it is not needed
Mikael Berthe <mikael@lilotux.net>
parents:
707
diff
changeset
|
1339 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
|
1340 if (roster_hidden) { |
5aa66101807b
Leave full-width mode automatically under some conditions
Mikael Berthe <mikael@lilotux.net>
parents:
708
diff
changeset
|
1341 // Enter chat mode |
5aa66101807b
Leave full-width mode automatically under some conditions
Mikael Berthe <mikael@lilotux.net>
parents:
708
diff
changeset
|
1342 scr_set_chatmode(TRUE); |
5aa66101807b
Leave full-width mode automatically under some conditions
Mikael Berthe <mikael@lilotux.net>
parents:
708
diff
changeset
|
1343 scr_ShowBuddyWindow(); |
5aa66101807b
Leave full-width mode automatically under some conditions
Mikael Berthe <mikael@lilotux.net>
parents:
708
diff
changeset
|
1344 } |
708
ed326697e4ed
scr_RosterVisibility(): do not refresh when it is not needed
Mikael Berthe <mikael@lilotux.net>
parents:
707
diff
changeset
|
1345 // 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
|
1346 scr_Resize(); |
ed326697e4ed
scr_RosterVisibility(): do not refresh when it is not needed
Mikael Berthe <mikael@lilotux.net>
parents:
707
diff
changeset
|
1347 redrawwin(stdscr); |
ed326697e4ed
scr_RosterVisibility(): do not refresh when it is not needed
Mikael Berthe <mikael@lilotux.net>
parents:
707
diff
changeset
|
1348 } |
707
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1349 } |
b26a0bde4cdb
Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents:
701
diff
changeset
|
1350 |
1058 | 1351 inline void scr_WriteMessage(const char *bjid, const char *text, |
480 | 1352 time_t timestamp, guint prefix_flags) |
24 | 1353 { |
727
1c3620668857
Expand tabs when reading history files
Mikael Berthe <mikael@lilotux.net>
parents:
726
diff
changeset
|
1354 char *xtext; |
725
1aff92625bdb
Expand tabs when receiving a message
Mikael Berthe <mikael@lilotux.net>
parents:
724
diff
changeset
|
1355 |
726 | 1356 if (!timestamp) timestamp = time(NULL); |
725
1aff92625bdb
Expand tabs when receiving a message
Mikael Berthe <mikael@lilotux.net>
parents:
724
diff
changeset
|
1357 |
1122
648fe6f715a6
Filter out ^M (0x0d) characters in incoming messages
Mikael Berthe <mikael@lilotux.net>
parents:
1115
diff
changeset
|
1358 xtext = ut_expand_tabs(text); // Expand tabs and filter out some chars |
726 | 1359 |
1058 | 1360 scr_WriteInWindow(bjid, xtext, timestamp, prefix_flags, FALSE); |
725
1aff92625bdb
Expand tabs when receiving a message
Mikael Berthe <mikael@lilotux.net>
parents:
724
diff
changeset
|
1361 |
1aff92625bdb
Expand tabs when receiving a message
Mikael Berthe <mikael@lilotux.net>
parents:
724
diff
changeset
|
1362 if (xtext != (char*)text) |
1aff92625bdb
Expand tabs when receiving a message
Mikael Berthe <mikael@lilotux.net>
parents:
724
diff
changeset
|
1363 g_free(xtext); |
24 | 1364 } |
1365 | |
726 | 1366 // If prefix is NULL, HBB_PREFIX_IN is supposed. |
1367 void scr_WriteIncomingMessage(const char *jidfrom, const char *text, | |
1368 time_t timestamp, guint prefix) | |
1369 { | |
1055
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1050
diff
changeset
|
1370 if (!(prefix & |
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1050
diff
changeset
|
1371 ~HBB_PREFIX_NOFLAG & ~HBB_PREFIX_HLIGHT & ~HBB_PREFIX_PGPCRYPT)) |
726 | 1372 prefix |= HBB_PREFIX_IN; |
1373 | |
1374 scr_WriteMessage(jidfrom, text, timestamp, prefix); | |
1375 } | |
1376 | |
1055
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1050
diff
changeset
|
1377 void scr_WriteOutgoingMessage(const char *jidto, const char *text, guint prefix) |
47 | 1378 { |
1115
922a9ae1a17e
Fix /say_to to a member of a folded group
Mikael Berthe <mikael@lilotux.net>
parents:
1093
diff
changeset
|
1379 GSList *roster_elt; |
922a9ae1a17e
Fix /say_to to a member of a folded group
Mikael Berthe <mikael@lilotux.net>
parents:
1093
diff
changeset
|
1380 roster_elt = roster_find(jidto, jidsearch, |
922a9ae1a17e
Fix /say_to to a member of a folded group
Mikael Berthe <mikael@lilotux.net>
parents:
1093
diff
changeset
|
1381 ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM); |
922a9ae1a17e
Fix /say_to to a member of a folded group
Mikael Berthe <mikael@lilotux.net>
parents:
1093
diff
changeset
|
1382 |
1055
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1050
diff
changeset
|
1383 scr_WriteMessage(jidto, text, 0, prefix|HBB_PREFIX_OUT|HBB_PREFIX_HLIGHT); |
1115
922a9ae1a17e
Fix /say_to to a member of a folded group
Mikael Berthe <mikael@lilotux.net>
parents:
1093
diff
changeset
|
1384 |
922a9ae1a17e
Fix /say_to to a member of a folded group
Mikael Berthe <mikael@lilotux.net>
parents:
1093
diff
changeset
|
1385 // Show jidto's buffer unless the buddy is not in the buddylist |
922a9ae1a17e
Fix /say_to to a member of a folded group
Mikael Berthe <mikael@lilotux.net>
parents:
1093
diff
changeset
|
1386 if (roster_elt && g_list_position(buddylist, roster_elt->data) != -1) |
922a9ae1a17e
Fix /say_to to a member of a folded group
Mikael Berthe <mikael@lilotux.net>
parents:
1093
diff
changeset
|
1387 scr_ShowWindow(jidto, FALSE); |
47 | 1388 } |
1389 | |
935
97e6a6da2b2c
Fix ncurses #include (again)
Mikael Berthe <mikael@lilotux.net>
parents:
933
diff
changeset
|
1390 static inline void set_autoaway(bool setaway) |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1391 { |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1392 static enum imstatus oldstatus; |
521 | 1393 static char *oldmsg; |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1394 Autoaway = setaway; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1395 |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1396 if (setaway) { |
521 | 1397 const char *msg, *prevmsg; |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1398 oldstatus = jb_getstatus(); |
521 | 1399 if (oldmsg) { |
1400 g_free(oldmsg); | |
1401 oldmsg = NULL; | |
1402 } | |
1403 prevmsg = jb_getstatusmsg(); | |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1404 msg = settings_opt_get("message_autoaway"); |
521 | 1405 if (!msg) |
1406 msg = prevmsg; | |
1407 if (prevmsg) | |
1408 oldmsg = g_strdup(prevmsg); | |
1056
5b3ecae91c95
PGP: sign auto-away presence too
Mikael Berthe <mikael@lilotux.net>
parents:
1055
diff
changeset
|
1409 jb_setstatus(away, NULL, msg, FALSE); |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1410 } else { |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1411 // Back |
1050
ea71d31a2607
PGP: Do not sign presence messages to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
1037
diff
changeset
|
1412 jb_setstatus(oldstatus, NULL, (oldmsg ? oldmsg : ""), FALSE); |
521 | 1413 if (oldmsg) { |
1414 g_free(oldmsg); | |
1415 oldmsg = NULL; | |
1416 } | |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1417 } |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1418 } |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1419 |
991
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1420 long int scr_GetAutoAwayTimeout(time_t now) |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
936
diff
changeset
|
1421 { |
940 | 1422 enum imstatus cur_st; |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
936
diff
changeset
|
1423 unsigned int autoaway_timeout = settings_opt_get_int("autoaway"); |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
936
diff
changeset
|
1424 |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
936
diff
changeset
|
1425 if (Autoaway || !autoaway_timeout) |
940 | 1426 return 86400; |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
936
diff
changeset
|
1427 |
940 | 1428 cur_st = jb_getstatus(); |
1429 // Auto-away is disabled for the following states | |
1430 if ((cur_st != available) && (cur_st != freeforchat)) | |
1431 return 86400; | |
1432 | |
1433 if (now >= LastActivity + (time_t)autoaway_timeout) | |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
936
diff
changeset
|
1434 return 0; |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
936
diff
changeset
|
1435 else |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
936
diff
changeset
|
1436 return LastActivity + (time_t)autoaway_timeout - now; |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
936
diff
changeset
|
1437 } |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
936
diff
changeset
|
1438 |
991
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1439 // set_chatstate(state) |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1440 // Set the current chat state (0=active, 1=composing, 2=paused) |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1441 // If the chat state has changed, call jb_send_chatstate() |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1442 static inline void set_chatstate(int state) |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1443 { |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1444 #if defined JEP0022 || defined JEP0085 |
993
0759f4c7da68
Add option 'disable_chatstates'
Mikael Berthe <mikael@lilotux.net>
parents:
992
diff
changeset
|
1445 if (chatstates_disabled) |
0759f4c7da68
Add option 'disable_chatstates'
Mikael Berthe <mikael@lilotux.net>
parents:
992
diff
changeset
|
1446 return; |
991
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1447 if (!chatmode) |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1448 state = 0; |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1449 if (state != chatstate) { |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1450 chatstate = state; |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1451 if (current_buddy && |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1452 buddy_gettype(BUDDATA(current_buddy)) == ROSTER_TYPE_USER) { |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1453 guint jep_state; |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1454 if (chatstate == 1) |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1455 jep_state = ROSTER_EVENT_COMPOSING; |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1456 else if (chatstate == 2) |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1457 jep_state = ROSTER_EVENT_PAUSED; |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1458 else |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1459 jep_state = ROSTER_EVENT_ACTIVE; |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1460 jb_send_chatstate(BUDDATA(current_buddy), jep_state); |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1461 } |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1462 if (!chatstate) |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1463 chatstate_timestamp = 0; |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1464 } |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1465 #endif |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1466 } |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1467 |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1468 #if defined JEP0022 || defined JEP0085 |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1469 inline long int scr_GetChatStatesTimeout(time_t now) |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1470 { |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1471 // Check if we're currently composing... |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1472 if (chatstate != 1 || !chatstate_timestamp) |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1473 return 86400; |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1474 |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1475 // If the timeout is reached, let's change the state right now. |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1476 if (now >= chatstate_timestamp + COMPOSING_TIMEOUT) { |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1477 chatstate_timestamp = now; |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1478 set_chatstate(2); |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1479 return 86400; |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1480 } |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1481 |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1482 return chatstate_timestamp + COMPOSING_TIMEOUT - now; |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1483 } |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1484 #endif |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
1485 |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1486 // Check if we should enter/leave automatic away status |
935
97e6a6da2b2c
Fix ncurses #include (again)
Mikael Berthe <mikael@lilotux.net>
parents:
933
diff
changeset
|
1487 void scr_CheckAutoAway(int activity) |
24 | 1488 { |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1489 enum imstatus cur_st; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1490 unsigned int autoaway_timeout = settings_opt_get_int("autoaway"); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1491 |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1492 if (Autoaway && activity) set_autoaway(FALSE); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1493 if (!autoaway_timeout) return; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1494 if (!LastActivity || activity) time(&LastActivity); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1495 |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1496 cur_st = jb_getstatus(); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1497 // Auto-away is disabled for the following states |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1498 if ((cur_st != available) && (cur_st != freeforchat)) |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1499 return; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1500 |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1501 if (!activity) { |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1502 time_t now; |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1503 time(&now); |
735 | 1504 if (!Autoaway && (now > LastActivity + (time_t)autoaway_timeout)) |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1505 set_autoaway(TRUE); |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
1506 } |
24 | 1507 } |
1508 | |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
1509 // set_current_buddy(newbuddy) |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
1510 // 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
|
1511 // 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
|
1512 static void set_current_buddy(GList *newbuddy) |
24 | 1513 { |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
1514 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
|
1515 /* 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
|
1516 * 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
|
1517 * buddy_getstatus() call. |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
1518 */ |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
1519 |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
1520 if (!current_buddy || !newbuddy) return; |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
1521 if (newbuddy == current_buddy) return; |
24 | 1522 |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
1523 // We're moving to another buddy. We're thus inactive wrt current_buddy. |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
1524 set_chatstate(0); |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
1525 // We don't want the chatstate to be changed again right now. |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
1526 lock_chatstate = true; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
1527 |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1528 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
|
1529 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); |
330 | 1530 if (chatmode) |
1531 alternate_buddy = current_buddy; | |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
1532 current_buddy = newbuddy; |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
1533 // 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
|
1534 if (chatmode) |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
1535 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
|
1536 // 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
|
1537 // 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
|
1538 // 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
|
1539 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
|
1540 buddylist_build(); |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
1541 update_roster = TRUE; |
24 | 1542 } |
1543 | |
143 | 1544 // scr_RosterTop() |
1545 // Go to the first buddy in the buddylist | |
105 | 1546 void scr_RosterTop(void) |
104 | 1547 { |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
1548 set_current_buddy(buddylist); |
104 | 1549 if (chatmode) |
1550 scr_ShowBuddyWindow(); | |
1551 } | |
1552 | |
143 | 1553 // scr_RosterBottom() |
1554 // Go to the last buddy in the buddylist | |
105 | 1555 void scr_RosterBottom(void) |
104 | 1556 { |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
1557 set_current_buddy(g_list_last(buddylist)); |
104 | 1558 if (chatmode) |
1559 scr_ShowBuddyWindow(); | |
1560 } | |
1561 | |
143 | 1562 // scr_RosterUp() |
1563 // Go to the previous buddy in the buddylist | |
105 | 1564 void scr_RosterUp(void) |
81 | 1565 { |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
1566 set_current_buddy(g_list_previous(current_buddy)); |
104 | 1567 if (chatmode) |
1568 scr_ShowBuddyWindow(); | |
81 | 1569 } |
1570 | |
143 | 1571 // scr_RosterDown() |
1572 // Go to the next buddy in the buddylist | |
105 | 1573 void scr_RosterDown(void) |
81 | 1574 { |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
1575 set_current_buddy(g_list_next(current_buddy)); |
104 | 1576 if (chatmode) |
1577 scr_ShowBuddyWindow(); | |
81 | 1578 } |
1579 | |
1086
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1580 // scr_RosterPrevGroup() |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1581 // Go to the previous group in the buddylist |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1582 void scr_RosterPrevGroup(void) |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1583 { |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1584 GList *bud; |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1585 |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1586 for (bud = current_buddy ; bud ; ) { |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1587 bud = g_list_previous(bud); |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1588 if (!bud) |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1589 break; |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1590 if (buddy_gettype(BUDDATA(bud)) & ROSTER_TYPE_GROUP) { |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1591 set_current_buddy(bud); |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1592 if (chatmode) |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1593 scr_ShowBuddyWindow(); |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1594 break; |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1595 } |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1596 } |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1597 } |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1598 |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1599 // scr_RosterNextGroup() |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1600 // Go to the next group in the buddylist |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1601 void scr_RosterNextGroup(void) |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1602 { |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1603 GList *bud; |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1604 |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1605 for (bud = current_buddy ; bud ; ) { |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1606 bud = g_list_next(bud); |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1607 if (!bud) |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1608 break; |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1609 if (buddy_gettype(BUDDATA(bud)) & ROSTER_TYPE_GROUP) { |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1610 set_current_buddy(bud); |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1611 if (chatmode) |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1612 scr_ShowBuddyWindow(); |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1613 break; |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1614 } |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1615 } |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1616 } |
5e2e647e781b
Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents:
1083
diff
changeset
|
1617 |
265 | 1618 // scr_RosterSearch(str) |
1619 // Look forward for a buddy with jid/name containing str. | |
1620 void scr_RosterSearch(char *str) | |
1621 { | |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
1622 set_current_buddy(buddy_search(str)); |
265 | 1623 if (chatmode) |
1624 scr_ShowBuddyWindow(); | |
1625 } | |
1626 | |
1058 | 1627 // scr_RosterJumpJid(bjid) |
1628 // Jump to buddy bjid. | |
480 | 1629 // NOTE: With this function, the buddy is added to the roster if doesn't exist. |
1630 void scr_RosterJumpJid(char *barejid) | |
1631 { | |
1632 GSList *roster_elt; | |
1633 // Look for an existing buddy | |
1634 roster_elt = roster_find(barejid, jidsearch, | |
1635 ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM); | |
1636 // Create it if necessary | |
1637 if (!roster_elt) | |
603 | 1638 roster_elt = roster_add_user(barejid, NULL, NULL, ROSTER_TYPE_USER, |
1639 sub_none); | |
480 | 1640 // Set a lock to see it in the buddylist |
1641 buddy_setflags(BUDDATA(roster_elt), ROSTER_FLAG_LOCK, TRUE); | |
1642 buddylist_build(); | |
1643 // Jump to the buddy | |
1644 set_current_buddy(buddy_search_jid(barejid)); | |
1645 if (chatmode) | |
1646 scr_ShowBuddyWindow(); | |
1647 } | |
1648 | |
236 | 1649 // scr_RosterUnreadMessage(next) |
1650 // Go to a new message. If next is not null, try to go to the next new | |
1651 // message. If it is not possible or if next is NULL, go to the first new | |
1652 // message from unread_list. | |
1653 void scr_RosterUnreadMessage(int next) | |
1654 { | |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
1655 gpointer unread_ptr; |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
1656 gpointer refbuddata; |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
1657 GList *nbuddy; |
236 | 1658 |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
1659 if (!current_buddy) return; |
236 | 1660 |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
1661 if (next) refbuddata = BUDDATA(current_buddy); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
1662 else refbuddata = NULL; |
236 | 1663 |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
1664 unread_ptr = unread_msg(refbuddata); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
1665 if (!unread_ptr) return; |
236 | 1666 |
889
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
888
diff
changeset
|
1667 if (!(buddy_gettype(unread_ptr) & ROSTER_TYPE_SPECIAL)) { |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
888
diff
changeset
|
1668 gpointer ngroup; |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
888
diff
changeset
|
1669 // If buddy is in a folded group, we need to expand it |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
888
diff
changeset
|
1670 ngroup = buddy_getgroup(unread_ptr); |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
888
diff
changeset
|
1671 if (buddy_getflags(ngroup) & ROSTER_FLAG_HIDE) { |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
888
diff
changeset
|
1672 buddy_setflags(ngroup, ROSTER_FLAG_HIDE, FALSE); |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
888
diff
changeset
|
1673 buddylist_build(); |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
888
diff
changeset
|
1674 } |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
1675 } |
236 | 1676 |
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
1677 nbuddy = g_list_find(buddylist, unread_ptr); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
1678 if (nbuddy) { |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
1679 set_current_buddy(nbuddy); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
1680 if (chatmode) scr_ShowBuddyWindow(); |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
1681 } else |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
1682 scr_LogPrint(LPRINT_LOGNORM, "Error: nbuddy == NULL"); // should not happen |
236 | 1683 } |
1684 | |
330 | 1685 // scr_RosterJumpAlternate() |
1686 // Try to jump to alternate (== previous) buddy | |
1687 void scr_RosterJumpAlternate(void) | |
105 | 1688 { |
330 | 1689 if (!alternate_buddy || g_list_position(buddylist, alternate_buddy) == -1) |
1690 return; | |
1691 set_current_buddy(alternate_buddy); | |
1692 if (chatmode) | |
1693 scr_ShowBuddyWindow(); | |
1694 } | |
1695 | |
369
499170ed71c9
Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents:
365
diff
changeset
|
1696 // scr_BufferScrollUpDown() |
508
5a2132ba2220
Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents:
503
diff
changeset
|
1697 // Scroll up/down the current buddy window, |
5a2132ba2220
Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents:
503
diff
changeset
|
1698 // - half a screen if nblines is 0, |
5a2132ba2220
Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents:
503
diff
changeset
|
1699 // - up if updown == -1, down if updown == 1 |
5a2132ba2220
Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents:
503
diff
changeset
|
1700 void scr_BufferScrollUpDown(int updown, unsigned int nblines) |
105 | 1701 { |
822 | 1702 winbuf *win_entry; |
508
5a2132ba2220
Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents:
503
diff
changeset
|
1703 int n, nbl; |
105 | 1704 GList *hbuf_top; |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1705 guint isspe; |
105 | 1706 |
1707 // Get win_entry | |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1708 if (!current_buddy) return; |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1709 |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1710 isspe = buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_SPECIAL; |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1711 win_entry = scr_SearchWindow(CURRENT_JID, isspe); |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1712 if (!win_entry) return; |
105 | 1713 |
508
5a2132ba2220
Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents:
503
diff
changeset
|
1714 if (!nblines) { |
5a2132ba2220
Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents:
503
diff
changeset
|
1715 // Scroll half a screen (or less) |
512 | 1716 nbl = CHAT_WIN_HEIGHT/2; |
508
5a2132ba2220
Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents:
503
diff
changeset
|
1717 } else { |
5a2132ba2220
Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents:
503
diff
changeset
|
1718 nbl = nblines; |
5a2132ba2220
Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents:
503
diff
changeset
|
1719 } |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1720 hbuf_top = win_entry->bd->top; |
105 | 1721 |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1722 if (updown == -1) { // UP |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1723 if (!hbuf_top) { |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1724 hbuf_top = g_list_last(win_entry->bd->hbuf); |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1725 if (!win_entry->bd->cleared) { |
512 | 1726 if (!nblines) nbl = nbl*3 - 1; |
1727 else nbl += CHAT_WIN_HEIGHT - 1; | |
1728 } else { | |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1729 win_entry->bd->cleared = FALSE; |
512 | 1730 } |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1731 } |
508
5a2132ba2220
Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents:
503
diff
changeset
|
1732 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
|
1733 hbuf_top = g_list_previous(hbuf_top); |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1734 win_entry->bd->top = hbuf_top; |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1735 } else { // DOWN |
508
5a2132ba2220
Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents:
503
diff
changeset
|
1736 for (n=0 ; hbuf_top && n < nbl ; n++) |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1737 hbuf_top = g_list_next(hbuf_top); |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1738 win_entry->bd->top = hbuf_top; |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1739 // Check if we are at the bottom |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1740 for (n=0 ; hbuf_top && n < CHAT_WIN_HEIGHT-1 ; n++) |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1741 hbuf_top = g_list_next(hbuf_top); |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1742 if (!hbuf_top) |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1743 win_entry->bd->top = NULL; // End reached |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1744 } |
105 | 1745 |
1746 // Refresh the window | |
1747 scr_UpdateWindow(win_entry); | |
1748 | |
1749 // Finished :) | |
1750 update_panels(); | |
1751 } | |
1752 | |
369
499170ed71c9
Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents:
365
diff
changeset
|
1753 // scr_BufferClear() |
143 | 1754 // 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
|
1755 void scr_BufferClear(void) |
108 | 1756 { |
822 | 1757 winbuf *win_entry; |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1758 guint isspe; |
108 | 1759 |
1760 // Get win_entry | |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1761 if (!current_buddy) return; |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1762 isspe = buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_SPECIAL; |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1763 win_entry = scr_SearchWindow(CURRENT_JID, isspe); |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1764 if (!win_entry) return; |
108 | 1765 |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1766 win_entry->bd->cleared = TRUE; |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1767 win_entry->bd->top = NULL; |
108 | 1768 |
1769 // Refresh the window | |
1770 scr_UpdateWindow(win_entry); | |
1771 | |
1772 // Finished :) | |
1773 update_panels(); | |
1774 } | |
1775 | |
1138
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1776 // buffer_purge() |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1777 // key: winId/jid |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1778 // value: winbuf structure |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1779 // data: int, set to 1 if the buffer should be closed. |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1780 // NOTE: does not work for special buffers. |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1781 static void buffer_purge(gpointer key, gpointer value, gpointer data) |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1782 { |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1783 int closebuf = (gint)data; // XXX GPOINTER_TO_INT? |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1784 winbuf *win_entry = value; |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1785 |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1786 // Delete the current hbuf |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1787 hbuf_free(&win_entry->bd->hbuf); |
1138
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1788 |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1789 if (closebuf) { |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1790 g_hash_table_remove(winbufhash, key); |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1791 } else { |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1792 win_entry->bd->cleared = FALSE; |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1793 win_entry->bd->top = NULL; |
1138
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1794 } |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1795 } |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1796 |
1135
5d7c05932b13
Add command /buffer close
Mikael Berthe <mikael@lilotux.net>
parents:
1133
diff
changeset
|
1797 // scr_BufferPurge(closebuf) |
866 | 1798 // Purge/Drop the current buddy buffer |
1135
5d7c05932b13
Add command /buffer close
Mikael Berthe <mikael@lilotux.net>
parents:
1133
diff
changeset
|
1799 // If closebuf is 1, close the buffer. |
5d7c05932b13
Add command /buffer close
Mikael Berthe <mikael@lilotux.net>
parents:
1133
diff
changeset
|
1800 void scr_BufferPurge(int closebuf) |
866 | 1801 { |
1802 winbuf *win_entry; | |
1803 guint isspe; | |
1804 | |
1805 // Get win_entry | |
1806 if (!current_buddy) return; | |
1807 isspe = buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_SPECIAL; | |
1808 win_entry = scr_SearchWindow(CURRENT_JID, isspe); | |
1809 if (!win_entry) return; | |
1810 | |
1138
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1811 if (!isspe) { |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1812 buffer_purge((gpointer)CURRENT_JID, win_entry, (gpointer)closebuf); |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1813 // XXX GINT_TO_POINTER? |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1814 if (closebuf) { |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1815 scr_set_chatmode(FALSE); |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1816 currentWindow = NULL; |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1817 } |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1818 } else { |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1819 // (Special buffer) |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1820 // Reset the current hbuf |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1821 hbuf_free(&win_entry->bd->hbuf); |
866 | 1822 // Currently it can only be the status buffer |
1823 statushbuf = NULL; | |
1138
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1824 |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1825 win_entry->bd->cleared = FALSE; |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1826 win_entry->bd->top = NULL; |
866 | 1827 } |
1828 | |
1138
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1829 // Refresh the window |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1830 scr_UpdateBuddyWindow(); |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1831 |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1832 // Finished :) |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1833 update_panels(); |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1834 } |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1835 |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1836 void scr_BufferPurgeAll(int closebuf) |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1837 { |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1838 g_hash_table_foreach(winbufhash, buffer_purge, (gpointer)closebuf); |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1839 // XXX GINT_TO_POINTER? |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1840 |
8ba4b1e8b42d
Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents:
1137
diff
changeset
|
1841 if (closebuf) { |
1135
5d7c05932b13
Add command /buffer close
Mikael Berthe <mikael@lilotux.net>
parents:
1133
diff
changeset
|
1842 scr_set_chatmode(FALSE); |
1137
5752017f6e2b
Fix a bug in /buffer close
Mikael Berthe <mikael@lilotux.net>
parents:
1135
diff
changeset
|
1843 currentWindow = NULL; |
1135
5d7c05932b13
Add command /buffer close
Mikael Berthe <mikael@lilotux.net>
parents:
1133
diff
changeset
|
1844 } |
5d7c05932b13
Add command /buffer close
Mikael Berthe <mikael@lilotux.net>
parents:
1133
diff
changeset
|
1845 |
866 | 1846 // Refresh the window |
1847 scr_UpdateBuddyWindow(); | |
1848 | |
1849 // Finished :) | |
1850 update_panels(); | |
1851 } | |
1852 | |
873
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1853 // scr_BufferScrollLock(lock) |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1854 // Lock/unlock the current buddy buffer |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1855 // lock = 1 : lock |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1856 // lock = 0 : unlock |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1857 // lock = -1: toggle lock status |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1858 void scr_BufferScrollLock(int lock) |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1859 { |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1860 winbuf *win_entry; |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1861 guint isspe; |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1862 |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1863 // Get win_entry |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1864 if (!current_buddy) return; |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1865 isspe = buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_SPECIAL; |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1866 win_entry = scr_SearchWindow(CURRENT_JID, isspe); |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1867 if (!win_entry) return; |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1868 |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1869 if (lock == -1) |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1870 lock = !win_entry->bd->lock; |
873
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1871 |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1872 if (lock) { |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1873 win_entry->bd->lock = TRUE; |
873
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1874 } else { |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1875 win_entry->bd->lock = FALSE; |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1876 //win_entry->bd->cleared = FALSE; |
880
ea983a945eba
/buffer scroll_unlock: Don't always jump to the end of the buffer
Mikael Berthe <mikael@lilotux.net>
parents:
878
diff
changeset
|
1877 if (isspe || (buddy_getflags(BUDDATA(current_buddy)) & ROSTER_FLAG_MSG)) |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1878 win_entry->bd->top = NULL; |
873
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1879 } |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1880 |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1881 // If chatmode is disabled and we're at the bottom of the buffer, |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1882 // we need to set the "top" line, so we need to call scr_ShowBuddyWindow() |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1883 // at least once. (Maybe it will cause a double refresh...) |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1884 if (!chatmode && !win_entry->bd->top) { |
873
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1885 chatmode = TRUE; |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1886 scr_ShowBuddyWindow(); |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1887 chatmode = FALSE; |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1888 } |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1889 |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1890 // Refresh the window |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1891 scr_UpdateBuddyWindow(); |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1892 |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1893 // Finished :) |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1894 update_panels(); |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1895 } |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
1896 |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1897 // scr_BufferTopBottom() |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1898 // Jump to the head/tail of the current buddy window |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1899 // (top if topbottom == -1, bottom topbottom == 1) |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1900 void scr_BufferTopBottom(int topbottom) |
187 | 1901 { |
822 | 1902 winbuf *win_entry; |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1903 guint isspe; |
187 | 1904 |
1905 // Get win_entry | |
1906 if (!current_buddy) return; | |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1907 isspe = buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_SPECIAL; |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1908 win_entry = scr_SearchWindow(CURRENT_JID, isspe); |
187 | 1909 if (!win_entry) return; |
1910 | |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1911 win_entry->bd->cleared = FALSE; |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1912 if (topbottom == 1) |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1913 win_entry->bd->top = NULL; |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
1914 else |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1915 win_entry->bd->top = g_list_first(win_entry->bd->hbuf); |
187 | 1916 |
1917 // Refresh the window | |
1918 scr_UpdateWindow(win_entry); | |
1919 | |
1920 // Finished :) | |
1921 update_panels(); | |
1922 } | |
1923 | |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1924 // scr_BufferSearch(direction, text) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1925 // Jump to the next line containing text |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1926 // (backward search if direction == -1, forward if topbottom == 1) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1927 void scr_BufferSearch(int direction, const char *text) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1928 { |
822 | 1929 winbuf *win_entry; |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1930 GList *current_line, *search_res; |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1931 guint isspe; |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1932 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1933 // Get win_entry |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1934 if (!current_buddy) return; |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1935 isspe = buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_SPECIAL; |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1936 win_entry = scr_SearchWindow(CURRENT_JID, isspe); |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1937 if (!win_entry) return; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1938 |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1939 if (win_entry->bd->top) |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1940 current_line = win_entry->bd->top; |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1941 else |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1942 current_line = g_list_last(win_entry->bd->hbuf); |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1943 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1944 search_res = hbuf_search(current_line, direction, text); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1945 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1946 if (search_res) { |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1947 win_entry->bd->cleared = FALSE; |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1948 win_entry->bd->top = search_res; |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1949 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1950 // Refresh the window |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1951 scr_UpdateWindow(win_entry); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1952 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1953 // Finished :) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1954 update_panels(); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1955 } else |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
1956 scr_LogPrint(LPRINT_NORMAL, "Search string not found"); |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1957 } |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1958 |
462 | 1959 // scr_BufferPercent(n) |
1960 // Jump to the specified position in the buffer, in % | |
1961 void scr_BufferPercent(int pc) | |
1962 { | |
822 | 1963 winbuf *win_entry; |
462 | 1964 GList *search_res; |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1965 guint isspe; |
462 | 1966 |
1967 // Get win_entry | |
1968 if (!current_buddy) return; | |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1969 isspe = buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_SPECIAL; |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1970 win_entry = scr_SearchWindow(CURRENT_JID, isspe); |
462 | 1971 if (!win_entry) return; |
1972 | |
1973 if (pc < 0 || pc > 100) { | |
1974 scr_LogPrint(LPRINT_NORMAL, "Bad % value"); | |
1975 return; | |
1976 } | |
1977 | |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1978 search_res = hbuf_jump_percent(win_entry->bd->hbuf, pc); |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1979 |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1980 win_entry->bd->cleared = FALSE; |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
1981 win_entry->bd->top = search_res; |
462 | 1982 |
1983 // Refresh the window | |
1984 scr_UpdateWindow(win_entry); | |
1985 | |
1986 // Finished :) | |
1987 update_panels(); | |
1988 } | |
1989 | |
464 | 1990 // scr_BufferDate(t) |
1991 // Jump to the first line after date t in the buffer | |
1992 // t is a date in seconds since `00:00:00 1970-01-01 UTC' | |
1993 void scr_BufferDate(time_t t) | |
1994 { | |
822 | 1995 winbuf *win_entry; |
464 | 1996 GList *search_res; |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
1997 guint isspe; |
464 | 1998 |
1999 // Get win_entry | |
2000 if (!current_buddy) return; | |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
2001 isspe = buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_SPECIAL; |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
2002 win_entry = scr_SearchWindow(CURRENT_JID, isspe); |
464 | 2003 if (!win_entry) return; |
2004 | |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
2005 search_res = hbuf_jump_date(win_entry->bd->hbuf, t); |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
2006 |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
2007 win_entry->bd->cleared = FALSE; |
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
2008 win_entry->bd->top = search_res; |
464 | 2009 |
2010 // Refresh the window | |
2011 scr_UpdateWindow(win_entry); | |
2012 | |
2013 // Finished :) | |
2014 update_panels(); | |
2015 } | |
2016 | |
143 | 2017 // scr_set_chatmode() |
261 | 2018 // Public function to (un)set chatmode... |
129 | 2019 inline void scr_set_chatmode(int enable) |
2020 { | |
2021 chatmode = enable; | |
721
9cf31c9b1dc4
Use room topic as a description in the chat status line
Mikael Berthe <mikael@lilotux.net>
parents:
720
diff
changeset
|
2022 scr_UpdateChatStatus(TRUE); |
129 | 2023 } |
2024 | |
1129
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1127
diff
changeset
|
2025 // scr_get_chatmode() |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1127
diff
changeset
|
2026 // Public function to get chatmode state. |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1127
diff
changeset
|
2027 inline int scr_get_chatmode(void) |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1127
diff
changeset
|
2028 { |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1127
diff
changeset
|
2029 return chatmode; |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1127
diff
changeset
|
2030 } |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1127
diff
changeset
|
2031 |
238 | 2032 // scr_get_multimode() |
261 | 2033 // Public function to get multimode status... |
1059 | 2034 inline int scr_get_multimode(void) |
238 | 2035 { |
2036 return multimode; | |
2037 } | |
2038 | |
654
d7fe7b88e4fc
MUC: Set the new_message flag when joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
2039 // 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
|
2040 // Set the message flag unless we're already in the jid buffer window |
1058 | 2041 void scr_setmsgflag_if_needed(const char *bjid, int special) |
654
d7fe7b88e4fc
MUC: Set the new_message flag when joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
2042 { |
891
78f4971578dd
Add a "special" parameter to scr_setmsgflag_if_needed()
Mikael Berthe <mikael@lilotux.net>
parents:
889
diff
changeset
|
2043 const char *current_id; |
873
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
2044 bool iscurrentlocked = FALSE; |
667
86bc3295a4db
Fix segfault in scr_setmsgflag_if_needed()
Mikael Berthe <mikael@lilotux.net>
parents:
658
diff
changeset
|
2045 |
1058 | 2046 if (!bjid) |
849
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
2047 return; |
42c43a88d823
Status buffer management
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
2048 |
873
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
2049 if (current_buddy) { |
891
78f4971578dd
Add a "special" parameter to scr_setmsgflag_if_needed()
Mikael Berthe <mikael@lilotux.net>
parents:
889
diff
changeset
|
2050 if (special) |
78f4971578dd
Add a "special" parameter to scr_setmsgflag_if_needed()
Mikael Berthe <mikael@lilotux.net>
parents:
889
diff
changeset
|
2051 current_id = buddy_getname(BUDDATA(current_buddy)); |
78f4971578dd
Add a "special" parameter to scr_setmsgflag_if_needed()
Mikael Berthe <mikael@lilotux.net>
parents:
889
diff
changeset
|
2052 else |
78f4971578dd
Add a "special" parameter to scr_setmsgflag_if_needed()
Mikael Berthe <mikael@lilotux.net>
parents:
889
diff
changeset
|
2053 current_id = buddy_getjid(BUDDATA(current_buddy)); |
78f4971578dd
Add a "special" parameter to scr_setmsgflag_if_needed()
Mikael Berthe <mikael@lilotux.net>
parents:
889
diff
changeset
|
2054 if (current_id) { |
78f4971578dd
Add a "special" parameter to scr_setmsgflag_if_needed()
Mikael Berthe <mikael@lilotux.net>
parents:
889
diff
changeset
|
2055 winbuf *win_entry = scr_SearchWindow(current_id, special); |
888
578d2034e971
scr_setmsgflag_if_needed(): Add a check after scr_SearchWindow()
Mikael Berthe <mikael@lilotux.net>
parents:
884
diff
changeset
|
2056 if (!win_entry) return; |
1157
5c857f0f0ab8
Moved all variables related to hbuf to an extra struct, bufdata
Frank Zschockelt
parents:
1156
diff
changeset
|
2057 iscurrentlocked = win_entry->bd->lock; |
873
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
2058 } |
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
2059 } else { |
891
78f4971578dd
Add a "special" parameter to scr_setmsgflag_if_needed()
Mikael Berthe <mikael@lilotux.net>
parents:
889
diff
changeset
|
2060 current_id = NULL; |
873
ee39f6d94d43
Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents:
866
diff
changeset
|
2061 } |
1058 | 2062 if (!chatmode || !current_id || strcmp(bjid, current_id) || iscurrentlocked) |
2063 roster_msg_setflag(bjid, special, TRUE); | |
654
d7fe7b88e4fc
MUC: Set the new_message flag when joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
2064 } |
d7fe7b88e4fc
MUC: Set the new_message flag when joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
2065 |
238 | 2066 // scr_set_multimode() |
261 | 2067 // Public function to (un)set multimode... |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
252
diff
changeset
|
2068 // Convention: |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
252
diff
changeset
|
2069 // 0 = disabled / 1 = multimode / 2 = multimode verbatim (commands disabled) |
807
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2070 inline void scr_set_multimode(int enable, char *subject) |
238 | 2071 { |
807
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2072 g_free(multiline); |
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2073 multiline = NULL; |
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2074 |
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2075 g_free(multimode_subj); |
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2076 if (enable && subject) |
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2077 multimode_subj = g_strdup(subject); |
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2078 else |
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2079 multimode_subj = NULL; |
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2080 |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
252
diff
changeset
|
2081 multimode = enable; |
238 | 2082 } |
2083 | |
2084 // scr_get_multiline() | |
261 | 2085 // Public function to get the current multi-line. |
807
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2086 inline const char *scr_get_multiline(void) |
238 | 2087 { |
2088 if (multimode && multiline) | |
2089 return multiline; | |
807
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2090 return NULL; |
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2091 } |
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2092 |
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2093 // scr_get_multimode_subj() |
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2094 // Public function to get the multi-line subject, if any. |
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2095 inline const char *scr_get_multimode_subj(void) |
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2096 { |
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2097 if (multimode) |
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2098 return multimode_subj; |
f6cda389db48
Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents:
806
diff
changeset
|
2099 return NULL; |
238 | 2100 } |
2101 | |
2102 // scr_append_multiline(line) | |
2103 // Public function to append a line to the current multi-line message. | |
2104 // Skip empty leading lines. | |
2105 void scr_append_multiline(const char *line) | |
2106 { | |
2107 static int num; | |
2108 | |
2109 if (!multimode) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
2110 scr_LogPrint(LPRINT_NORMAL, "Error: Not in multi-line message mode!"); |
238 | 2111 return; |
2112 } | |
2113 if (multiline) { | |
2114 int len = strlen(multiline)+strlen(line)+2; | |
252 | 2115 if (len >= HBB_BLOCKSIZE - 1) { |
238 | 2116 // We don't handle single messages with size > HBB_BLOCKSIZE |
2117 // (see hbuf) | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
2118 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
|
2119 "this line has not been added."); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
2120 scr_LogPrint(LPRINT_NORMAL, "Please send this part now..."); |
238 | 2121 return; |
2122 } | |
276
627925d885de
Limit the number of lines in multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
271
diff
changeset
|
2123 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
|
2124 // 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
|
2125 // (It should be < 1000 yet) |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
2126 scr_LogPrint(LPRINT_NORMAL, "Your message has too many lines, " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
2127 "this one has not been added."); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
2128 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
|
2129 return; |
627925d885de
Limit the number of lines in multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
271
diff
changeset
|
2130 } |
238 | 2131 multiline = g_renew(char, multiline, len); |
2132 strcat(multiline, "\n"); | |
2133 strcat(multiline, line); | |
2134 num++; | |
2135 } else { | |
2136 // First message line (we skip leading empty lines) | |
2137 num = 0; | |
2138 if (line[0]) { | |
419 | 2139 multiline = g_strdup(line); |
238 | 2140 num++; |
2141 } else | |
2142 return; | |
2143 } | |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
771
diff
changeset
|
2144 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8, |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
771
diff
changeset
|
2145 "Multi-line mode: line #%d added [%.25s...", num, line); |
238 | 2146 } |
2147 | |
173 | 2148 // scr_cmdhisto_addline() |
2149 // Add a line to the inputLine history | |
2150 inline void scr_cmdhisto_addline(char *line) | |
2151 { | |
1127
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
2152 int max_histo_lines; |
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
2153 |
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
2154 if (!line || !*line) |
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
2155 return; |
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
2156 |
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
2157 max_histo_lines = settings_opt_get_int("cmdhistory_lines"); |
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
2158 |
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
2159 if (max_histo_lines < 0) |
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
2160 max_histo_lines = 1; |
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
2161 |
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
2162 if (max_histo_lines) |
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
2163 while (cmdhisto_nblines >= (guint)max_histo_lines) { |
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
2164 if (cmdhisto_cur && cmdhisto_cur == cmdhisto) |
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
2165 break; |
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
2166 g_free(cmdhisto->data); |
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
2167 cmdhisto = g_list_delete_link(cmdhisto, cmdhisto); |
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
2168 cmdhisto_nblines--; |
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
2169 } |
173 | 2170 |
2171 cmdhisto = g_list_append(cmdhisto, g_strdup(line)); | |
1127
fddf2fef7b83
Add option "cmdhistory_lines"
Mikael Berthe <mikael@lilotux.net>
parents:
1122
diff
changeset
|
2172 cmdhisto_nblines++; |
173 | 2173 } |
2174 | |
2175 // scr_cmdhisto_prev() | |
2176 // Look for previous line beginning w/ the given mask in the inputLine history | |
175 | 2177 // Returns NULL if none found |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
2178 static const char *scr_cmdhisto_prev(char *mask, guint len) |
173 | 2179 { |
2180 GList *hl; | |
2181 if (!cmdhisto_cur) { | |
2182 hl = g_list_last(cmdhisto); | |
174 | 2183 if (hl) { // backup current line |
2184 strncpy(cmdhisto_backup, mask, INPUTLINE_LENGTH); | |
2185 } | |
173 | 2186 } else { |
2187 hl = g_list_previous(cmdhisto_cur); | |
2188 } | |
2189 while (hl) { | |
2190 if (!strncmp((char*)hl->data, mask, len)) { | |
2191 // Found a match | |
2192 cmdhisto_cur = hl; | |
2193 return (const char*)hl->data; | |
2194 } | |
2195 hl = g_list_previous(hl); | |
2196 } | |
2197 return NULL; | |
2198 } | |
2199 | |
2200 // scr_cmdhisto_next() | |
2201 // Look for next line beginning w/ the given mask in the inputLine history | |
175 | 2202 // Returns NULL if none found |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
2203 static const char *scr_cmdhisto_next(char *mask, guint len) |
173 | 2204 { |
2205 GList *hl; | |
2206 if (!cmdhisto_cur) return NULL; | |
2207 hl = cmdhisto_cur; | |
2208 while ((hl = g_list_next(hl)) != NULL) | |
2209 if (!strncmp((char*)hl->data, mask, len)) { | |
2210 // Found a match | |
2211 cmdhisto_cur = hl; | |
2212 return (const char*)hl->data; | |
2213 } | |
175 | 2214 // If the "backuped" line matches, we'll use it |
2215 if (strncmp(cmdhisto_backup, mask, len)) return NULL; // No match | |
174 | 2216 cmdhisto_cur = NULL; |
2217 return cmdhisto_backup; | |
173 | 2218 } |
2219 | |
195 | 2220 // readline_transpose_chars() |
2221 // Drag the character before point forward over the character at | |
2222 // point, moving point forward as well. If point is at the end of | |
2223 // the line, then this transposes the two characters before point. | |
1059 | 2224 void readline_transpose_chars(void) |
195 | 2225 { |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2226 char *c1, *c2; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2227 unsigned a, b; |
195 | 2228 |
2229 if (ptr_inputline == inputLine) return; | |
2230 | |
2231 if (!*ptr_inputline) { // We're at EOL | |
2232 // If line is only 1 char long, nothing to do... | |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2233 if (ptr_inputline == prev_char(ptr_inputline, inputLine)) return; |
195 | 2234 // Transpose the two previous characters |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2235 c2 = prev_char(ptr_inputline, inputLine); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2236 c1 = prev_char(c2, inputLine); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2237 a = get_char(c1); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2238 b = get_char(c2); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2239 put_char(put_char(c1, b), a); |
195 | 2240 } else { |
196 | 2241 // Swap the two characters before the cursor and move right. |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2242 c2 = ptr_inputline; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2243 c1 = prev_char(c2, inputLine); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2244 a = get_char(c1); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2245 b = get_char(c2); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2246 put_char(put_char(c1, b), a); |
195 | 2247 check_offset(1); |
2248 } | |
2249 } | |
2250 | |
2251 // readline_backward_kill_word() | |
194 | 2252 // Kill the word before the cursor, in input line |
1059 | 2253 void readline_backward_kill_word(void) |
194 | 2254 { |
2255 char *c, *old = ptr_inputline; | |
2256 int spaceallowed = 1; | |
2257 | |
2258 if (ptr_inputline == inputLine) return; | |
2259 | |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2260 c = prev_char(ptr_inputline, inputLine); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2261 for ( ; c > inputLine ; c = prev_char(c, inputLine)) { |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2262 if (!iswalnum(get_char(c))) { |
933
ede9260be93d
Input line: Improve word-related functions
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
2263 if (iswblank(get_char(c))) { |
194 | 2264 if (!spaceallowed) break; |
933
ede9260be93d
Input line: Improve word-related functions
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
2265 } else spaceallowed = 0; |
194 | 2266 } else spaceallowed = 0; |
759
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2267 } |
194 | 2268 |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2269 if (c != inputLine || iswblank(get_char(c))) |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2270 if ((c < prev_char(ptr_inputline, inputLine)) && (!iswalnum(get_char(c)))) |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2271 c = next_char(c); |
194 | 2272 |
2273 // Modify the line | |
2274 ptr_inputline = c; | |
2275 for (;;) { | |
2276 *c = *old++; | |
2277 if (!*c++) break; | |
2278 } | |
195 | 2279 check_offset(-1); |
194 | 2280 } |
2281 | |
759
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2282 // readline_backward_word() |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2283 // Move back to the start of the current or previous word |
1059 | 2284 void readline_backward_word(void) |
759
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2285 { |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2286 char *old_ptr_inputLine = ptr_inputline; |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2287 int spaceallowed = 1; |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2288 |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2289 if (ptr_inputline == inputLine) return; |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2290 |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2291 for (ptr_inputline = prev_char(ptr_inputline, inputLine) ; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2292 ptr_inputline > inputLine ; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2293 ptr_inputline = prev_char(ptr_inputline, inputLine)) { |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2294 if (!iswalnum(get_char(ptr_inputline))) { |
933
ede9260be93d
Input line: Improve word-related functions
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
2295 if (iswblank(get_char(ptr_inputline))) { |
759
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2296 if (!spaceallowed) break; |
933
ede9260be93d
Input line: Improve word-related functions
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
2297 } else spaceallowed = 0; |
759
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2298 } else spaceallowed = 0; |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2299 } |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2300 |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2301 if (ptr_inputline < prev_char(old_ptr_inputLine, inputLine) |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2302 && iswblank(get_char(ptr_inputline)) |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2303 && iswblank(get_char(next_char(ptr_inputline)))) |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2304 ptr_inputline = next_char(ptr_inputline); |
759
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2305 |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2306 check_offset(-1); |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2307 } |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2308 |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2309 // readline_forward_word() |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2310 // Move forward to the end of the next word |
1059 | 2311 void readline_forward_word(void) |
759
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2312 { |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2313 int spaceallowed = 1; |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2314 |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2315 while (*ptr_inputline) { |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2316 ptr_inputline = next_char(ptr_inputline); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2317 if (!iswalnum(get_char(ptr_inputline))) { |
933
ede9260be93d
Input line: Improve word-related functions
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
2318 if (iswblank(get_char(ptr_inputline))) { |
759
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2319 if (!spaceallowed) break; |
933
ede9260be93d
Input line: Improve word-related functions
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
2320 } else spaceallowed = 0; |
759
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2321 } else spaceallowed = 0; |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2322 } |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2323 |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2324 check_offset(1); |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2325 } |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2326 |
98 | 2327 // which_row() |
2328 // 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
|
2329 // -2 -> normal text |
ddec224c2318
MUC: nickname completion
Mikael Berthe <mikael@lilotux.net>
parents:
499
diff
changeset
|
2330 // -1 -> room: nickname completion |
98 | 2331 // 0 -> command |
2332 // 1 -> parameter 1 (etc.) | |
102 | 2333 // 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
|
2334 static int which_row(const char **p_row) |
98 | 2335 { |
2336 int row = -1; | |
2337 char *p; | |
2338 int quote = FALSE; | |
2339 | |
2340 // Not a command? | |
967 | 2341 if ((ptr_inputline == inputLine) || (inputLine[0] != COMMAND_CHAR)) { |
503
ddec224c2318
MUC: nickname completion
Mikael Berthe <mikael@lilotux.net>
parents:
499
diff
changeset
|
2342 if (!current_buddy) return -2; |
ddec224c2318
MUC: nickname completion
Mikael Berthe <mikael@lilotux.net>
parents:
499
diff
changeset
|
2343 if (buddy_gettype(BUDDATA(current_buddy)) == ROSTER_TYPE_ROOM) { |
ddec224c2318
MUC: nickname completion
Mikael Berthe <mikael@lilotux.net>
parents:
499
diff
changeset
|
2344 *p_row = inputLine; |
ddec224c2318
MUC: nickname completion
Mikael Berthe <mikael@lilotux.net>
parents:
499
diff
changeset
|
2345 return -1; |
ddec224c2318
MUC: nickname completion
Mikael Berthe <mikael@lilotux.net>
parents:
499
diff
changeset
|
2346 } |
ddec224c2318
MUC: nickname completion
Mikael Berthe <mikael@lilotux.net>
parents:
499
diff
changeset
|
2347 return -2; |
ddec224c2318
MUC: nickname completion
Mikael Berthe <mikael@lilotux.net>
parents:
499
diff
changeset
|
2348 } |
98 | 2349 |
2350 // This is a command | |
2351 row = 0; | |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2352 for (p = inputLine ; p < ptr_inputline ; p = next_char(p)) { |
98 | 2353 if (quote) { |
2354 if (*p == '"' && *(p-1) != '\\') | |
2355 quote = FALSE; | |
2356 continue; | |
2357 } | |
2358 if (*p == '"' && *(p-1) != '\\') { | |
2359 quote = TRUE; | |
121 | 2360 } else if (*p == ' ') { |
2361 if (*(p-1) != ' ') | |
2362 row++; | |
102 | 2363 *p_row = p+1; |
2364 } | |
98 | 2365 } |
2366 return row; | |
2367 } | |
2368 | |
143 | 2369 // scr_insert_text() |
2370 // Insert the given text at the current cursor position. | |
2371 // The cursor is moved. We don't check if the cursor still is in the screen | |
2372 // after, the caller should do that. | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
2373 static void scr_insert_text(const char *text) |
98 | 2374 { |
2375 char tmpLine[INPUTLINE_LENGTH+1]; | |
2376 int len = strlen(text); | |
2377 // Check the line isn't too long | |
2378 if (strlen(inputLine) + len >= INPUTLINE_LENGTH) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
2379 scr_LogPrint(LPRINT_LOGNORM, "Cannot insert text, line too long."); |
98 | 2380 return; |
2381 } | |
2382 | |
2383 strcpy(tmpLine, ptr_inputline); | |
419 | 2384 strcpy(ptr_inputline, text); |
2385 ptr_inputline += len; | |
98 | 2386 strcpy(ptr_inputline, tmpLine); |
2387 } | |
2388 | |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2389 static void scr_cancel_current_completion(void); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2390 |
143 | 2391 // scr_handle_tab() |
2392 // Function called when tab is pressed. | |
2393 // Initiate or continue a completion... | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
2394 static void scr_handle_tab(void) |
98 | 2395 { |
102 | 2396 int nrow; |
503
ddec224c2318
MUC: nickname completion
Mikael Berthe <mikael@lilotux.net>
parents:
499
diff
changeset
|
2397 const char *row; |
102 | 2398 const char *cchar; |
103 | 2399 guint compl_categ; |
98 | 2400 |
740 | 2401 row = inputLine; // (Kills a GCC warning) |
102 | 2402 nrow = which_row(&row); |
98 | 2403 |
503
ddec224c2318
MUC: nickname completion
Mikael Berthe <mikael@lilotux.net>
parents:
499
diff
changeset
|
2404 // a) No completion if no leading slash ('cause not a command), |
ddec224c2318
MUC: nickname completion
Mikael Berthe <mikael@lilotux.net>
parents:
499
diff
changeset
|
2405 // unless this is a room (then, it is a nickname completion) |
103 | 2406 // 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
|
2407 if ((nrow == -2) || (nrow == 3 && !completion_started) || nrow > 3) |
ddec224c2318
MUC: nickname completion
Mikael Berthe <mikael@lilotux.net>
parents:
499
diff
changeset
|
2408 return; |
102 | 2409 |
503
ddec224c2318
MUC: nickname completion
Mikael Berthe <mikael@lilotux.net>
parents:
499
diff
changeset
|
2410 if (nrow == 0) { // Command completion |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2411 row = next_char(inputLine); |
103 | 2412 compl_categ = COMPL_CMD; |
503
ddec224c2318
MUC: nickname completion
Mikael Berthe <mikael@lilotux.net>
parents:
499
diff
changeset
|
2413 } else if (nrow == -1) { // Nickname completion |
ddec224c2318
MUC: nickname completion
Mikael Berthe <mikael@lilotux.net>
parents:
499
diff
changeset
|
2414 compl_categ = COMPL_RESOURCE; |
ddec224c2318
MUC: nickname completion
Mikael Berthe <mikael@lilotux.net>
parents:
499
diff
changeset
|
2415 } else { // Other completion, depending on the command |
285 | 2416 int alias = FALSE; |
2417 cmd *com; | |
2418 char *xpline = expandalias(inputLine); | |
2419 com = cmd_get(xpline); | |
2420 if (xpline != inputLine) { | |
2421 // This is an alias, so we can't complete rows > 0 | |
2422 alias = TRUE; | |
2423 g_free(xpline); | |
2424 } | |
2425 if ((!com && (!alias || !completion_started)) || !row) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
373
diff
changeset
|
2426 scr_LogPrint(LPRINT_NORMAL, "I cannot complete that..."); |
103 | 2427 return; |
2428 } | |
285 | 2429 if (!alias) |
2430 compl_categ = com->completion_flags[nrow-1]; | |
2431 else | |
2432 compl_categ = 0; | |
103 | 2433 } |
2434 | |
2435 if (!completion_started) { | |
1076
b9698c89f46d
Fix memory leak in scr_handle_tab()
Mikael Berthe <mikael@lilotux.net>
parents:
1075
diff
changeset
|
2436 guint dynlist; |
b9698c89f46d
Fix memory leak in scr_handle_tab()
Mikael Berthe <mikael@lilotux.net>
parents:
1075
diff
changeset
|
2437 GSList *list = compl_get_category_list(compl_categ, &dynlist); |
103 | 2438 if (list) { |
2439 char *prefix = g_strndup(row, ptr_inputline-row); | |
2440 // Init completion | |
2441 new_completion(prefix, list); | |
2442 g_free(prefix); | |
1076
b9698c89f46d
Fix memory leak in scr_handle_tab()
Mikael Berthe <mikael@lilotux.net>
parents:
1075
diff
changeset
|
2443 // Free the list if it's a dynamic one |
b9698c89f46d
Fix memory leak in scr_handle_tab()
Mikael Berthe <mikael@lilotux.net>
parents:
1075
diff
changeset
|
2444 if (dynlist) { |
b9698c89f46d
Fix memory leak in scr_handle_tab()
Mikael Berthe <mikael@lilotux.net>
parents:
1075
diff
changeset
|
2445 GSList *slp; |
b9698c89f46d
Fix memory leak in scr_handle_tab()
Mikael Berthe <mikael@lilotux.net>
parents:
1075
diff
changeset
|
2446 for (slp = list; slp; slp = g_slist_next(slp)) |
b9698c89f46d
Fix memory leak in scr_handle_tab()
Mikael Berthe <mikael@lilotux.net>
parents:
1075
diff
changeset
|
2447 g_free(slp->data); |
b9698c89f46d
Fix memory leak in scr_handle_tab()
Mikael Berthe <mikael@lilotux.net>
parents:
1075
diff
changeset
|
2448 g_slist_free(list); |
b9698c89f46d
Fix memory leak in scr_handle_tab()
Mikael Berthe <mikael@lilotux.net>
parents:
1075
diff
changeset
|
2449 |
b9698c89f46d
Fix memory leak in scr_handle_tab()
Mikael Berthe <mikael@lilotux.net>
parents:
1075
diff
changeset
|
2450 } |
103 | 2451 // Now complete |
98 | 2452 cchar = complete(); |
2453 if (cchar) | |
2454 scr_insert_text(cchar); | |
103 | 2455 completion_started = TRUE; |
98 | 2456 } |
103 | 2457 } else { // Completion already initialized |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2458 scr_cancel_current_completion(); |
103 | 2459 // Now complete again |
2460 cchar = complete(); | |
2461 if (cchar) | |
2462 scr_insert_text(cchar); | |
102 | 2463 } |
98 | 2464 } |
2465 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
2466 static void scr_cancel_current_completion(void) |
98 | 2467 { |
2468 char *c; | |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2469 char *src = ptr_inputline; |
98 | 2470 guint back = cancel_completion(); |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2471 guint i; |
98 | 2472 // Remove $back chars |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2473 for (i = 0; i < back; i++) |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2474 ptr_inputline = prev_char(ptr_inputline, inputLine); |
98 | 2475 c = ptr_inputline; |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2476 for ( ; *src ; ) |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2477 *c++ = *src++; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2478 *c = 0; |
98 | 2479 } |
2480 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
2481 static void scr_end_current_completion(void) |
98 | 2482 { |
2483 done_completion(); | |
2484 completion_started = FALSE; | |
2485 } | |
2486 | |
24 | 2487 // check_offset(int direction) |
2488 // Check inputline_offset value, and make sure the cursor is inside the | |
2489 // screen. | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
2490 static inline void check_offset(int direction) |
24 | 2491 { |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2492 int i; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2493 char *c = &inputLine[inputline_offset]; |
24 | 2494 // Left side |
2495 if (inputline_offset && direction <= 0) { | |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2496 while (ptr_inputline <= c) { |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2497 for (i = 0; i < 5; i++) |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2498 c = prev_char(c, inputLine); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2499 if (c == inputLine) |
828
319fc55b9a2b
Fix a bug in check_offset()
Mikael Berthe <mikael@lilotux.net>
parents:
827
diff
changeset
|
2500 break; |
24 | 2501 } |
2502 } | |
2503 // Right side | |
2504 if (direction >= 0) { | |
932
fc6aaa223650
Fix a few problems with non-UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents:
931
diff
changeset
|
2505 int delta = get_char_width(c); |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2506 while (ptr_inputline > c) { |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2507 c = next_char(c); |
932
fc6aaa223650
Fix a few problems with non-UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents:
931
diff
changeset
|
2508 delta += get_char_width(c); |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2509 } |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2510 c = &inputLine[inputline_offset]; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2511 while (delta >= maxX) { |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2512 for (i = 0; i < 5; i++) { |
932
fc6aaa223650
Fix a few problems with non-UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents:
931
diff
changeset
|
2513 delta -= get_char_width(c); |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2514 c = next_char(c); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2515 } |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2516 } |
24 | 2517 } |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2518 inputline_offset = c - inputLine; |
24 | 2519 } |
2520 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
2521 static inline void refresh_inputline(void) |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
2522 { |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
2523 mvwprintw(inputWnd, 0,0, "%s", inputLine + inputline_offset); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
2524 wclrtoeol(inputWnd); |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2525 if (*ptr_inputline) { |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2526 // hack to set cursor pos. Characters can have different width, |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2527 // so I know of no better way. |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2528 char c = *ptr_inputline; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2529 *ptr_inputline = 0; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2530 mvwprintw(inputWnd, 0,0, "%s", inputLine + inputline_offset); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2531 *ptr_inputline = c; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2532 } |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
2533 } |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
2534 |
389
6e895f397474
Ncurses changes + Ctrl-C does not send a signal anylore
Mikael Berthe <mikael@lilotux.net>
parents:
388
diff
changeset
|
2535 void scr_handle_CtrlC(void) |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
2536 { |
365
ddb6593bedc9
Fix segfault when mcabber receives an INT signal (Ctrl-C) early
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
2537 if (!Curses) return; |
315
65aa05520556
First Ctrl-C now also leaves multi-line message mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
2538 // Leave multi-line mode |
967 | 2539 process_command(mkcmdstr("msay abort")); |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
2540 // Same as Ctrl-g, now |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
2541 scr_cancel_current_completion(); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
2542 scr_end_current_completion(); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
2543 check_offset(-1); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
2544 refresh_inputline(); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
2545 } |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
2546 |
1083
07941d7feee9
Ctrl-d sends a multi-line message
Mikael Berthe <mikael@lilotux.net>
parents:
1079
diff
changeset
|
2547 static void scr_handle_CtrlD(void) |
07941d7feee9
Ctrl-d sends a multi-line message
Mikael Berthe <mikael@lilotux.net>
parents:
1079
diff
changeset
|
2548 { |
07941d7feee9
Ctrl-d sends a multi-line message
Mikael Berthe <mikael@lilotux.net>
parents:
1079
diff
changeset
|
2549 // Validate current multi-line |
07941d7feee9
Ctrl-d sends a multi-line message
Mikael Berthe <mikael@lilotux.net>
parents:
1079
diff
changeset
|
2550 if (scr_get_multimode()) |
07941d7feee9
Ctrl-d sends a multi-line message
Mikael Berthe <mikael@lilotux.net>
parents:
1079
diff
changeset
|
2551 process_command(mkcmdstr("msay send")); |
07941d7feee9
Ctrl-d sends a multi-line message
Mikael Berthe <mikael@lilotux.net>
parents:
1079
diff
changeset
|
2552 } |
07941d7feee9
Ctrl-d sends a multi-line message
Mikael Berthe <mikael@lilotux.net>
parents:
1079
diff
changeset
|
2553 |
761
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2554 static void add_keyseq(char *seqstr, guint mkeycode, gint value) |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2555 { |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2556 keyseq *ks; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2557 |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2558 // Let's make sure the length is correct |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2559 if (strlen(seqstr) > MAX_KEYSEQ_LENGTH) { |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2560 scr_LogPrint(LPRINT_LOGNORM, "add_keyseq(): key sequence is too long!"); |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2561 return; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2562 } |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2563 |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2564 ks = g_new0(keyseq, 1); |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2565 ks->seqstr = g_strdup(seqstr); |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2566 ks->mkeycode = mkeycode; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2567 ks->value = value; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2568 keyseqlist = g_slist_append(keyseqlist, ks); |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2569 } |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2570 |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2571 // match_keyseq(iseq, &ret) |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2572 // Check if "iseq" is a known key escape sequence. |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2573 // Return value: |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2574 // -1 if "seq" matches no known sequence |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2575 // 0 if "seq" could match 1 or more known sequences |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2576 // >0 if "seq" matches a key sequence; the mkey code is returned |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2577 // and *ret is set to the matching keyseq structure. |
952 | 2578 static inline gint match_keyseq(int *iseq, keyseq **ret) |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
2579 { |
761
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2580 GSList *ksl; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2581 keyseq *ksp; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2582 char *p, c; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2583 int *i; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2584 int needmore = FALSE; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2585 |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2586 for (ksl = keyseqlist; ksl; ksl = g_slist_next(ksl)) { |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2587 ksp = ksl->data; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2588 p = ksp->seqstr; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2589 i = iseq; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2590 while (1) { |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2591 c = (unsigned char)*i; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2592 if (!*p && !c) { // Match |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2593 (*ret) = ksp; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2594 return ksp->mkeycode; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2595 } |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2596 if (!c) { |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2597 // iseq is too short |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2598 needmore = TRUE; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2599 break; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2600 } else if (!*p || c != *p) { |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2601 // This isn't a match |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2602 break; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2603 } |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2604 p++; i++; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2605 } |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2606 } |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2607 |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2608 if (needmore) |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2609 return 0; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2610 return -1; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2611 } |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2612 |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2613 static inline int match_utf8_keyseq(int *iseq) |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2614 { |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2615 int *strp = iseq; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2616 unsigned c = *strp++; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2617 unsigned mask = 0x80; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2618 int len = -1; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2619 while (c & mask) { |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2620 mask >>= 1; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2621 len++; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2622 } |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2623 if (len <= 0 || len > 4) |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2624 return -1; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2625 c &= mask - 1; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2626 while ((*strp & 0xc0) == 0x80) { |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2627 if (len-- <= 0) // can't happen |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2628 return -1; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2629 c = (c << 6) | (*strp++ & 0x3f); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2630 } |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2631 if (len) |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2632 return 0; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2633 return c; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2634 } |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2635 |
761
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2636 void scr_Getch(keycode *kcode) |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2637 { |
769 | 2638 keyseq *mks = NULL; |
761
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2639 int ks[MAX_KEYSEQ_LENGTH+1]; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2640 int i; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2641 |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2642 memset(kcode, 0, sizeof(keycode)); |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2643 memset(ks, 0, sizeof(ks)); |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2644 |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2645 kcode->value = wgetch(inputWnd); |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2646 if (utf8_mode) { |
1058 | 2647 bool ismeta = (kcode->value == 27); |
2648 | |
2649 if (ismeta) | |
944
aec71ebf98fa
Fix Meta + UTF-8 character
Mikael Berthe <mikael@lilotux.net>
parents:
940
diff
changeset
|
2650 ks[0] = wgetch(inputWnd); |
aec71ebf98fa
Fix Meta + UTF-8 character
Mikael Berthe <mikael@lilotux.net>
parents:
940
diff
changeset
|
2651 else |
aec71ebf98fa
Fix Meta + UTF-8 character
Mikael Berthe <mikael@lilotux.net>
parents:
940
diff
changeset
|
2652 ks[0] = kcode->value; |
aec71ebf98fa
Fix Meta + UTF-8 character
Mikael Berthe <mikael@lilotux.net>
parents:
940
diff
changeset
|
2653 |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2654 for (i = 0; i < MAX_KEYSEQ_LENGTH - 1; i++) { |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2655 int match = match_utf8_keyseq(ks); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2656 if (match == -1) |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2657 break; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2658 if (match > 0) { |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2659 kcode->value = match; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2660 kcode->utf8 = 1; |
1058 | 2661 if (ismeta) |
944
aec71ebf98fa
Fix Meta + UTF-8 character
Mikael Berthe <mikael@lilotux.net>
parents:
940
diff
changeset
|
2662 kcode->mcode = MKEY_META; |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2663 return; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2664 } |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2665 ks[i + 1] = wgetch(inputWnd); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2666 if (ks[i + 1] == ERR) |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2667 break; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2668 } |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2669 while (i > 0) |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2670 ungetch(ks[i--]); |
1058 | 2671 if (ismeta) |
944
aec71ebf98fa
Fix Meta + UTF-8 character
Mikael Berthe <mikael@lilotux.net>
parents:
940
diff
changeset
|
2672 ungetch(ks[0]); |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2673 memset(ks, 0, sizeof(ks)); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2674 } |
761
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2675 if (kcode->value != 27) |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2676 return; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2677 |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2678 // Check for escape key sequence |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2679 for (i=0; i < MAX_KEYSEQ_LENGTH; i++) { |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2680 int match; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2681 ks[i] = wgetch(inputWnd); |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2682 if (ks[i] == ERR) break; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2683 match = match_keyseq(ks, &mks); |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2684 if (match == -1) { |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2685 // No such key sequence. Let's increment i as it is a valid key. |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2686 i++; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2687 break; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2688 } |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2689 if (match > 0) { |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2690 // We have a matching sequence |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2691 kcode->mcode = mks->mkeycode; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2692 kcode->value = mks->value; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2693 return; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2694 } |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2695 } |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2696 |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2697 // No match. Let's return a meta-key. |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2698 if (i > 0) { |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2699 kcode->mcode = MKEY_META; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2700 kcode->value = ks[0]; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2701 } |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2702 if (i > 1) { |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2703 // We need to push some keys back to the keyboard buffer |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2704 while (i-- > 1) |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2705 ungetch(ks[i]); |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2706 } |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2707 return; |
373
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
2708 } |
af2f8ddf6a1b
Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
2709 |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
936
diff
changeset
|
2710 inline void scr_DoUpdate(void) |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
936
diff
changeset
|
2711 { |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
936
diff
changeset
|
2712 doupdate(); |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
936
diff
changeset
|
2713 } |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
936
diff
changeset
|
2714 |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2715 static int bindcommand(keycode kcode) |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2716 { |
945
17ef145f3326
Display and use UTF-8 key codes
Mikael Berthe <mikael@lilotux.net>
parents:
944
diff
changeset
|
2717 gchar asciikey[16], asciicode[16]; |
764
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2718 const gchar *boundcmd; |
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2719 |
945
17ef145f3326
Display and use UTF-8 key codes
Mikael Berthe <mikael@lilotux.net>
parents:
944
diff
changeset
|
2720 if (kcode.utf8) |
17ef145f3326
Display and use UTF-8 key codes
Mikael Berthe <mikael@lilotux.net>
parents:
944
diff
changeset
|
2721 g_snprintf(asciicode, 15, "U%d", kcode.value); |
17ef145f3326
Display and use UTF-8 key codes
Mikael Berthe <mikael@lilotux.net>
parents:
944
diff
changeset
|
2722 else |
17ef145f3326
Display and use UTF-8 key codes
Mikael Berthe <mikael@lilotux.net>
parents:
944
diff
changeset
|
2723 g_snprintf(asciicode, 15, "%d", kcode.value); |
17ef145f3326
Display and use UTF-8 key codes
Mikael Berthe <mikael@lilotux.net>
parents:
944
diff
changeset
|
2724 |
764
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2725 if (!kcode.mcode || kcode.mcode == MKEY_EQUIV) |
945
17ef145f3326
Display and use UTF-8 key codes
Mikael Berthe <mikael@lilotux.net>
parents:
944
diff
changeset
|
2726 g_snprintf(asciikey, 15, "%s", asciicode); |
764
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2727 else if (kcode.mcode == MKEY_META) |
945
17ef145f3326
Display and use UTF-8 key codes
Mikael Berthe <mikael@lilotux.net>
parents:
944
diff
changeset
|
2728 g_snprintf(asciikey, 15, "M%s", asciicode); |
764
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2729 else |
949
e3c49b2f8143
Fix bindings of special keys (MK*)
Mikael Berthe <mikael@lilotux.net>
parents:
945
diff
changeset
|
2730 g_snprintf(asciikey, 15, "MK%d", kcode.mcode); |
764
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2731 |
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2732 boundcmd = settings_get(SETTINGS_TYPE_BINDING, asciikey); |
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2733 |
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2734 if (boundcmd) { |
1058 | 2735 gchar *cmdline, *boundcmd_locale; |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
771
diff
changeset
|
2736 boundcmd_locale = from_utf8(boundcmd); |
1058 | 2737 cmdline = g_strdup_printf(mkcmdstr("%s"), boundcmd_locale); |
764
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2738 scr_CheckAutoAway(TRUE); |
1058 | 2739 if (process_command(cmdline)) |
764
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2740 return 255; // Quit |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
771
diff
changeset
|
2741 g_free(boundcmd_locale); |
1058 | 2742 g_free(cmdline); |
764
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2743 return 0; |
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2744 } |
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2745 |
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2746 scr_LogPrint(LPRINT_NORMAL, "Unknown key=%s", asciikey); |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2747 #ifndef UNICODE |
764
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2748 if (utf8_mode) |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2749 scr_LogPrint(LPRINT_NORMAL, |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2750 "WARNING: Compiled without full UTF-8 support!"); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2751 #endif |
764
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2752 return -1; |
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2753 } |
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2754 |
44 | 2755 // process_key(key) |
2756 // Handle the pressed key, in the command line (bottom). | |
761
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2757 int process_key(keycode kcode) |
24 | 2758 { |
761
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2759 int key = kcode.value; |
931
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2760 int display_char = FALSE; |
761
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2761 |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
2762 lock_chatstate = false; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
2763 |
761
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2764 switch (kcode.mcode) { |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2765 case 0: |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2766 break; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2767 case MKEY_EQUIV: |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2768 key = kcode.value; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2769 break; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2770 case MKEY_META: |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2771 key = ERR; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2772 switch (kcode.value) { |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2773 case 27: |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2774 key = 27; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2775 break; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2776 default: |
764
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2777 if (bindcommand(kcode) == 255) |
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2778 return 255; |
761
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2779 } |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2780 break; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2781 default: |
764
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2782 if (bindcommand(kcode) == 255) |
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2783 return 255; |
4e15322d315e
Allow binding of meta keys
Mikael Berthe <mikael@lilotux.net>
parents:
763
diff
changeset
|
2784 key = ERR; // Do not process any further |
758 | 2785 } |
761
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2786 |
931
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2787 if (kcode.utf8) { |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2788 if (key != ERR && !kcode.mcode) |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2789 display_char = TRUE; |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2790 goto display; |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2791 } |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2792 |
758 | 2793 switch (key) { |
761
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2794 case 0: |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2795 case ERR: |
758 | 2796 break; |
499
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2797 case 8: // Ctrl-h |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2798 case 127: // Backspace too |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2799 case KEY_BACKSPACE: |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2800 if (ptr_inputline != (char*)&inputLine) { |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2801 char *src = ptr_inputline; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2802 char *c = prev_char(ptr_inputline, inputLine); |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2803 ptr_inputline = c; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2804 for ( ; *src ; ) |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2805 *c++ = *src++; |
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2806 *c = 0; |
499
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2807 check_offset(-1); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2808 } |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2809 break; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2810 case KEY_DC:// Del |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2811 if (*ptr_inputline) |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2812 strcpy(ptr_inputline, next_char(ptr_inputline)); |
499
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2813 break; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2814 case KEY_LEFT: |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2815 if (ptr_inputline != (char*)&inputLine) { |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2816 ptr_inputline = prev_char(ptr_inputline, inputLine); |
499
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2817 check_offset(-1); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2818 } |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2819 break; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2820 case KEY_RIGHT: |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2821 if (*ptr_inputline) |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2822 ptr_inputline = next_char(ptr_inputline); |
499
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2823 check_offset(1); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2824 break; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2825 case 7: // Ctrl-g |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2826 scr_cancel_current_completion(); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2827 scr_end_current_completion(); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2828 check_offset(-1); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2829 break; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2830 case 9: // Tab |
827
04da822bc47c
Expand tabs in verbatim multi-line mode
Mikael Berthe <mikael@lilotux.net>
parents:
826
diff
changeset
|
2831 if (scr_get_multimode() != 2) { |
04da822bc47c
Expand tabs in verbatim multi-line mode
Mikael Berthe <mikael@lilotux.net>
parents:
826
diff
changeset
|
2832 // Not in verbatim multi-line mode |
04da822bc47c
Expand tabs in verbatim multi-line mode
Mikael Berthe <mikael@lilotux.net>
parents:
826
diff
changeset
|
2833 scr_handle_tab(); |
04da822bc47c
Expand tabs in verbatim multi-line mode
Mikael Berthe <mikael@lilotux.net>
parents:
826
diff
changeset
|
2834 } else { |
04da822bc47c
Expand tabs in verbatim multi-line mode
Mikael Berthe <mikael@lilotux.net>
parents:
826
diff
changeset
|
2835 // Verbatim multi-line mode: expand tab |
04da822bc47c
Expand tabs in verbatim multi-line mode
Mikael Berthe <mikael@lilotux.net>
parents:
826
diff
changeset
|
2836 char tabstr[9]; |
04da822bc47c
Expand tabs in verbatim multi-line mode
Mikael Berthe <mikael@lilotux.net>
parents:
826
diff
changeset
|
2837 int i, n; |
04da822bc47c
Expand tabs in verbatim multi-line mode
Mikael Berthe <mikael@lilotux.net>
parents:
826
diff
changeset
|
2838 n = 8 - (ptr_inputline - inputLine) % 8; |
04da822bc47c
Expand tabs in verbatim multi-line mode
Mikael Berthe <mikael@lilotux.net>
parents:
826
diff
changeset
|
2839 for (i = 0; i < n; i++) |
04da822bc47c
Expand tabs in verbatim multi-line mode
Mikael Berthe <mikael@lilotux.net>
parents:
826
diff
changeset
|
2840 tabstr[i] = ' '; |
04da822bc47c
Expand tabs in verbatim multi-line mode
Mikael Berthe <mikael@lilotux.net>
parents:
826
diff
changeset
|
2841 tabstr[i] = '\0'; |
04da822bc47c
Expand tabs in verbatim multi-line mode
Mikael Berthe <mikael@lilotux.net>
parents:
826
diff
changeset
|
2842 scr_insert_text(tabstr); |
04da822bc47c
Expand tabs in verbatim multi-line mode
Mikael Berthe <mikael@lilotux.net>
parents:
826
diff
changeset
|
2843 } |
499
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2844 check_offset(0); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2845 break; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2846 case 13: // Enter |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2847 case 15: // Ctrl-o ("accept-line-and-down-history") |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2848 scr_CheckAutoAway(TRUE); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2849 if (process_line(inputLine)) |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2850 return 255; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2851 // Add line to history |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2852 scr_cmdhisto_addline(inputLine); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2853 // Reset the line |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2854 ptr_inputline = inputLine; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2855 *ptr_inputline = 0; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2856 inputline_offset = 0; |
24 | 2857 |
499
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2858 if (key == 13) // Enter |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2859 { |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2860 // Reset history line pointer |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2861 cmdhisto_cur = NULL; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2862 } else { // down-history |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2863 // Use next history line instead of a blank line |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2864 const char *l = scr_cmdhisto_next("", 0); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2865 if (l) strcpy(inputLine, l); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2866 // Reset backup history line |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2867 cmdhisto_backup[0] = 0; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2868 } |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2869 break; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2870 case KEY_UP: |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2871 { |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2872 const char *l = scr_cmdhisto_prev(inputLine, |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2873 ptr_inputline-inputLine); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2874 if (l) strcpy(inputLine, l); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2875 } |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2876 break; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2877 case KEY_DOWN: |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2878 { |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2879 const char *l = scr_cmdhisto_next(inputLine, |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2880 ptr_inputline-inputLine); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2881 if (l) strcpy(inputLine, l); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2882 } |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2883 break; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2884 case KEY_PPAGE: |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2885 scr_CheckAutoAway(TRUE); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2886 scr_RosterUp(); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2887 break; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2888 case KEY_NPAGE: |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2889 scr_CheckAutoAway(TRUE); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2890 scr_RosterDown(); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2891 break; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2892 case KEY_HOME: |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2893 case 1: |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2894 ptr_inputline = inputLine; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2895 inputline_offset = 0; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2896 break; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2897 case 3: // Ctrl-C |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2898 scr_handle_CtrlC(); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2899 break; |
1083
07941d7feee9
Ctrl-d sends a multi-line message
Mikael Berthe <mikael@lilotux.net>
parents:
1079
diff
changeset
|
2900 case 4: // Ctrl-D |
07941d7feee9
Ctrl-d sends a multi-line message
Mikael Berthe <mikael@lilotux.net>
parents:
1079
diff
changeset
|
2901 scr_handle_CtrlD(); |
07941d7feee9
Ctrl-d sends a multi-line message
Mikael Berthe <mikael@lilotux.net>
parents:
1079
diff
changeset
|
2902 break; |
499
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2903 case KEY_END: |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2904 case 5: |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2905 for (; *ptr_inputline; ptr_inputline++) ; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2906 check_offset(1); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2907 break; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2908 case 21: // Ctrl-u |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2909 strcpy(inputLine, ptr_inputline); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2910 ptr_inputline = inputLine; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2911 inputline_offset = 0; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2912 break; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2913 case KEY_EOL: |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2914 case 11: // Ctrl-k |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2915 *ptr_inputline = 0; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2916 break; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2917 case 16: // Ctrl-p |
508
5a2132ba2220
Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents:
503
diff
changeset
|
2918 scr_BufferScrollUpDown(-1, 0); |
499
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2919 break; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2920 case 14: // Ctrl-n |
508
5a2132ba2220
Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents:
503
diff
changeset
|
2921 scr_BufferScrollUpDown(1, 0); |
499
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2922 break; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2923 case 20: // Ctrl-t |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2924 readline_transpose_chars(); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2925 break; |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2926 case 23: // Ctrl-w |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2927 readline_backward_kill_word(); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2928 break; |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2929 case 515: |
759
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2930 case 516: // Ctrl-Left |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2931 readline_backward_word(); |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2932 break; |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
929
diff
changeset
|
2933 case 517: |
759
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2934 case 518: // Ctrl-Right |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2935 readline_forward_word(); |
a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
Mikael Berthe <mikael@lilotux.net>
parents:
758
diff
changeset
|
2936 break; |
499
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2937 case 12: // Ctrl-l |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2938 scr_CheckAutoAway(TRUE); |
825
3ecfaa6111e2
Ctrl-l rereads color variables
Mikael Berthe <mikael@lilotux.net>
parents:
824
diff
changeset
|
2939 ParseColors(); |
701
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
2940 scr_Resize(); |
499
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2941 redrawwin(stdscr); |
701
6c100adfbfb6
Add setting "roster_width" (variable buddylist width)
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
2942 break; |
499
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2943 case KEY_RESIZE: |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2944 scr_Resize(); |
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2945 break; |
761
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2946 case 27: // ESC |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2947 scr_CheckAutoAway(TRUE); |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2948 currentWindow = NULL; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2949 chatmode = FALSE; |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2950 if (current_buddy) |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2951 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2952 scr_RosterVisibility(1); |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2953 scr_UpdateChatStatus(FALSE); |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2954 top_panel(chatPanel); |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2955 top_panel(inputPanel); |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2956 update_panels(); |
4532a9fe0e8c
Handle some keyboard escape sequences
Mikael Berthe <mikael@lilotux.net>
parents:
760
diff
changeset
|
2957 break; |
499
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2958 default: |
931
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2959 display_char = TRUE; |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2960 } // switch |
263 | 2961 |
931
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2962 display: |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2963 if (display_char) { |
932
fc6aaa223650
Fix a few problems with non-UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents:
931
diff
changeset
|
2964 if (kcode.utf8 ? iswprint(key) : isprint(key)) { |
931
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2965 char tmpLine[INPUTLINE_LENGTH+1]; |
499
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2966 |
931
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2967 // Check the line isn't too long |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2968 if (strlen(inputLine) + 4 > INPUTLINE_LENGTH) |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2969 return 0; |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2970 |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2971 // Insert char |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2972 strcpy(tmpLine, ptr_inputline); |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2973 ptr_inputline = put_char(ptr_inputline, key); |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2974 strcpy(ptr_inputline, tmpLine); |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2975 check_offset(1); |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2976 } else { |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2977 // Look for a key binding. |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2978 if (!kcode.utf8 && (bindcommand(kcode) == 255)) |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2979 return 255; |
1cd6d694ac3c
Fix display of some UTF-8 chars
Mikael Berthe <mikael@lilotux.net>
parents:
930
diff
changeset
|
2980 } |
24 | 2981 } |
499
baa812f04f24
Reorganise process_key()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
2982 |
157 | 2983 if (completion_started && key != 9 && key != KEY_RESIZE) |
98 | 2984 scr_end_current_completion(); |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
2985 refresh_inputline(); |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
2986 |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
2987 if (!lock_chatstate) { |
997 | 2988 // Set chat state to composing (1) if the user is currently composing, |
2989 // i.e. not an empty line and not a command line. | |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
2990 if (inputLine[0] == 0 || inputLine[0] == COMMAND_CHAR) |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
2991 set_chatstate(0); |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
2992 else |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
2993 set_chatstate(1); |
991
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
2994 if (chatstate) |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
2995 time(&chatstate_timestamp); |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
2996 } |
24 | 2997 return 0; |
2998 } | |
576 | 2999 |
580 | 3000 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |