annotate mcabber/src/screen.c @ 667:86bc3295a4db

Fix segfault in scr_setmsgflag_if_needed()
author Mikael Berthe <mikael@lilotux.net>
date Fri, 13 Jan 2006 22:05:38 +0100
parents 5d71d1f8887e
children ae7016aae014
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
307
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
1 /*
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
2 * screen.c -- UI stuff
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 389
diff changeset
3 *
307
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
4 * Copyright (C) 2005 Mikael Berthe <bmikael@lists.lilotux.net>
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
5 * Parts of this file come from the Cabber project <cabber@ajmacias.com>
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
6 *
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
7 * This program is free software; you can redistribute it and/or modify
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
8 * it under the terms of the GNU General Public License as published by
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or (at
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
10 * your option) any later version.
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
11 *
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
12 * This program is distributed in the hope that it will be useful, but
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
15 * General Public License for more details.
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
16 *
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
17 * You should have received a copy of the GNU General Public License
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
18 * along with this program; if not, write to the Free Software
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
20 * USA
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
21 */
566818afee1c Add headers to C files
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
22
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
23 #include <stdio.h>
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
24 #include <stdlib.h>
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
25 #include <string.h>
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
26 #include <ncurses.h>
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
27 #include <panel.h>
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
28 #include <time.h>
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
29 #include <ctype.h>
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
30 #include <locale.h>
232
9a6ba4b38e63 [/trunk] Changeset 245 by mikael
mikael
parents: 220
diff changeset
31 #include <langinfo.h>
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
32
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
33 #include "screen.h"
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
34 #include "hbuf.h"
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents: 44
diff changeset
35 #include "commands.h"
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 84
diff changeset
36 #include "compl.h"
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
37 #include "roster.h"
180
42a33611233b [/trunk] Changeset 192 by mikael
mikael
parents: 178
diff changeset
38 #include "histolog.h"
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents: 276
diff changeset
39 #include "settings.h"
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
40 #include "utils.h"
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
41 #include "list.h"
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
42
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
43 #define window_entry(n) list_entry(n, window_entry_t, list)
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
44
515
180f0a6e4ac9 Log window's height can be set by the user
Mikael Berthe <mikael@lilotux.net>
parents: 514
diff changeset
45 #define DEFAULT_LOG_WIN_HEIGHT (5+2)
180f0a6e4ac9 Log window's height can be set by the user
Mikael Berthe <mikael@lilotux.net>
parents: 514
diff changeset
46 #define CHAT_WIN_HEIGHT (maxY-1-Log_Win_Height)
180f0a6e4ac9 Log window's height can be set by the user
Mikael Berthe <mikael@lilotux.net>
parents: 514
diff changeset
47
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;
180f0a6e4ac9 Log window's height can be set by the user
Mikael Berthe <mikael@lilotux.net>
parents: 514
diff changeset
51
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 332
diff changeset
52 static inline void check_offset(int);
151
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
53
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
54 LIST_HEAD(window_list);
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
55
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
56 typedef struct _window_entry_t {
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
57 WINDOW *win;
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
58 PANEL *panel;
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
59 char *name;
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
60 GList *hbuf;
181
4a0bde661562 [/trunk] Changeset 193 by mikael
mikael
parents: 180
diff changeset
61 GList *top; // If top is NULL, we'll display the last lines
4a0bde661562 [/trunk] Changeset 193 by mikael
mikael
parents: 180
diff changeset
62 char cleared; // For ex, user has issued a /clear command...
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
63 struct list_head list;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
64 } window_entry_t;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
65
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
66
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
67 static WINDOW *rosterWnd, *chatWnd, *inputWnd;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
68 static WINDOW *logWnd, *logWnd_border;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
69 static PANEL *rosterPanel, *chatPanel, *inputPanel;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
70 static PANEL *logPanel, *logPanel_border;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
71 static int maxY, maxX;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
72 static window_entry_t *currentWindow;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
73
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
74 static int chatmode;
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
75 static int multimode;
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
76 static char *multiline;
30
4ea2df449381 [/trunk] Changeset 46 by mikael
mikael
parents: 29
diff changeset
77 int update_roster;
232
9a6ba4b38e63 [/trunk] Changeset 245 by mikael
mikael
parents: 220
diff changeset
78 int utf8_mode = 0;
322
da138cdebf04 Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents: 314
diff changeset
79 static bool Autoaway;
332
a1901741890e scr_LogPrint() can be called before ncurses initialization
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
80 static bool Curses;
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
81
174
6354625e8fb2 [/trunk] Changeset 186 by mikael
mikael
parents: 173
diff changeset
82 static char inputLine[INPUTLINE_LENGTH+1];
6354625e8fb2 [/trunk] Changeset 186 by mikael
mikael
parents: 173
diff changeset
83 static char *ptr_inputline;
6354625e8fb2 [/trunk] Changeset 186 by mikael
mikael
parents: 173
diff changeset
84 static short int inputline_offset;
6354625e8fb2 [/trunk] Changeset 186 by mikael
mikael
parents: 173
diff changeset
85 static int completion_started;
173
09e24917059d [/trunk] Changeset 185 by mikael
mikael
parents: 168
diff changeset
86 static GList *cmdhisto;
09e24917059d [/trunk] Changeset 185 by mikael
mikael
parents: 168
diff changeset
87 static GList *cmdhisto_cur;
174
6354625e8fb2 [/trunk] Changeset 186 by mikael
mikael
parents: 173
diff changeset
88 static char cmdhisto_backup[INPUTLINE_LENGTH+1];
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
89
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
90
99
7fffb8a6b229 [/trunk] Changeset 113 by mikael
mikael
parents: 98
diff changeset
91 /* Functions */
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
92
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 332
diff changeset
93 static int scr_WindowWidth(WINDOW * win)
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
94 {
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
95 int x, y;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
96 getmaxyx(win, y, x);
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
97 return x;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
98 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
99
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 332
diff changeset
100 static void scr_draw_box(WINDOW * win, int y, int x, int height, int width,
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 332
diff changeset
101 int Color, chtype box, chtype border)
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
102 {
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
103 int i, j;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
104
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
105 wattrset(win, COLOR_PAIR(Color));
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
106 for (i = 0; i < height; i++) {
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
107 wmove(win, y + i, x);
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
108 for (j = 0; j < width; j++)
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
109 if (!i && !j)
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
110 waddch(win, border | ACS_ULCORNER);
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
111 else if (i == height - 1 && !j)
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
112 waddch(win, border | ACS_LLCORNER);
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
113 else if (!i && j == width - 1)
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
114 waddch(win, box | ACS_URCORNER);
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
115 else if (i == height - 1 && j == width - 1)
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
116 waddch(win, box | ACS_LRCORNER);
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
117 else if (!i)
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
118 waddch(win, border | ACS_HLINE);
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
119 else if (i == height - 1)
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
120 waddch(win, box | ACS_HLINE);
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
121 else if (!j)
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
122 waddch(win, border | ACS_VLINE);
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
123 else if (j == width - 1)
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
124 waddch(win, box | ACS_VLINE);
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
125 else
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
126 waddch(win, box | ' ');
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
127 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
128 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
129
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 332
diff changeset
130 static int FindColor(const char *name)
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
131 {
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
132 if (!strcmp(name, "default"))
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
133 return -1;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
134 if (!strcmp(name, "black"))
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
135 return COLOR_BLACK;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
136 if (!strcmp(name, "red"))
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
137 return COLOR_RED;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
138 if (!strcmp(name, "green"))
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
139 return COLOR_GREEN;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
140 if (!strcmp(name, "yellow"))
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
141 return COLOR_YELLOW;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
142 if (!strcmp(name, "blue"))
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
143 return COLOR_BLUE;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
144 if (!strcmp(name, "magenta"))
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
145 return COLOR_MAGENTA;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
146 if (!strcmp(name, "cyan"))
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
147 return COLOR_CYAN;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
148 if (!strcmp(name, "white"))
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
149 return COLOR_WHITE;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
150
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
151 return -1;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
152 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
153
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 332
diff changeset
154 static void ParseColors(void)
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
155 {
281
f562b9af2de7 Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
156 const char *colors[8] = {
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
157 "", "",
267
8d3d5bd52da3 Improve color configuration
mikael@frmp8452
parents: 265
diff changeset
158 "general",
139
8d7e31d37bec [/trunk] Changeset 151 by mikael
mikael
parents: 135
diff changeset
159 "newmsg",
267
8d3d5bd52da3 Improve color configuration
mikael@frmp8452
parents: 265
diff changeset
160 "rosterselect",
8d3d5bd52da3 Improve color configuration
mikael@frmp8452
parents: 265
diff changeset
161 "rosternormal",
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
162 NULL
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
163 };
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
164
657
056dc9e65c25 Some memory allocation code cleaning
Mikael Berthe <mikael@lilotux.net>
parents: 654
diff changeset
165 char *tmp = g_new(char, 512);
281
f562b9af2de7 Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
166 const char *color;
f562b9af2de7 Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
167 const char *background = settings_opt_get("color_background");
f562b9af2de7 Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
168 const char *backselected = settings_opt_get("color_backselected");
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
169 int i = 0;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
170
267
8d3d5bd52da3 Improve color configuration
mikael@frmp8452
parents: 265
diff changeset
171 // Default values
8d3d5bd52da3 Improve color configuration
mikael@frmp8452
parents: 265
diff changeset
172 if (!background) background = "blue";
8d3d5bd52da3 Improve color configuration
mikael@frmp8452
parents: 265
diff changeset
173 if (!backselected) backselected = "cyan";
8d3d5bd52da3 Improve color configuration
mikael@frmp8452
parents: 265
diff changeset
174
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
175 while (colors[i]) {
657
056dc9e65c25 Some memory allocation code cleaning
Mikael Berthe <mikael@lilotux.net>
parents: 654
diff changeset
176 snprintf(tmp, 512, "color_%s", colors[i]);
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents: 276
diff changeset
177 color = settings_opt_get(tmp);
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
178
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
179 switch (i + 1) {
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
180 case 1:
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
181 init_pair(1, COLOR_BLACK, COLOR_WHITE);
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
182 break;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
183 case 2:
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
184 init_pair(2, COLOR_WHITE, COLOR_BLACK);
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
185 break;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
186 case 3:
267
8d3d5bd52da3 Improve color configuration
mikael@frmp8452
parents: 265
diff changeset
187 init_pair(3, ((color) ? FindColor(color) : COLOR_WHITE),
8d3d5bd52da3 Improve color configuration
mikael@frmp8452
parents: 265
diff changeset
188 FindColor(background));
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
189 break;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
190 case 4:
267
8d3d5bd52da3 Improve color configuration
mikael@frmp8452
parents: 265
diff changeset
191 init_pair(4, ((color) ? FindColor(color) : COLOR_RED),
8d3d5bd52da3 Improve color configuration
mikael@frmp8452
parents: 265
diff changeset
192 FindColor(background));
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
193 break;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
194 case 5:
267
8d3d5bd52da3 Improve color configuration
mikael@frmp8452
parents: 265
diff changeset
195 init_pair(5, ((color) ? FindColor(color) : COLOR_BLACK),
8d3d5bd52da3 Improve color configuration
mikael@frmp8452
parents: 265
diff changeset
196 FindColor(backselected));
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
197 break;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
198 case 6:
267
8d3d5bd52da3 Improve color configuration
mikael@frmp8452
parents: 265
diff changeset
199 init_pair(6, ((color) ? FindColor(color) : COLOR_MAGENTA),
8d3d5bd52da3 Improve color configuration
mikael@frmp8452
parents: 265
diff changeset
200 FindColor(background));
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
201 break;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
202 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
203 i++;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
204 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
205 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
206
373
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
207 void scr_InitCurses(void)
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
208 {
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
209 initscr();
382
4c6e8392e465 Use nodelay() instead of halfdelay()
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
210 raw();
373
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
211 noecho();
389
6e895f397474 Ncurses changes + Ctrl-C does not send a signal anylore
Mikael Berthe <mikael@lilotux.net>
parents: 388
diff changeset
212 nonl();
6e895f397474 Ncurses changes + Ctrl-C does not send a signal anylore
Mikael Berthe <mikael@lilotux.net>
parents: 388
diff changeset
213 intrflush(stdscr, FALSE);
373
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
214 start_color();
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
215 use_default_colors();
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
216 Curses = TRUE;
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
217
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
218 ParseColors();
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
219
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
220 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
221 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
222 // 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
223 // 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
224
373
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
225 inputLine[0] = 0;
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
226 ptr_inputline = inputLine;
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
227
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
228 setlocale(LC_CTYPE, "");
592
67a332121aea Try UTF8 -> locale conversion with fallback
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
229 LocaleCharSet = nl_langinfo(CODESET);
67a332121aea Try UTF8 -> locale conversion with fallback
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
230 utf8_mode = (strcmp(LocaleCharSet, "UTF-8") == 0);
373
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
231
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
232 return;
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
233 }
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
234
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
235 void scr_TerminateCurses(void)
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
236 {
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
237 if (!Curses) return;
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
238 clear();
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
239 refresh();
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
240 endwin();
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
241 Curses = FALSE;
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
242 return;
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
243 }
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
244
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
245 // scr_LogPrint(...)
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
246 // Display a message in the log window.
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
247 void scr_LogPrint(unsigned int flag, const char *fmt, ...)
373
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
248 {
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
249 time_t timestamp;
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
250 char *buffer, *b2;
373
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
251 va_list ap;
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
252
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
253 if (!flag) return;
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
254
602
7b20c27cae48 Increase scr_LogPrint() buffer size
Mikael Berthe <mikael@lilotux.net>
parents: 592
diff changeset
255 buffer = g_new(char, 5184);
373
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
256
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
257 timestamp = time(NULL);
602
7b20c27cae48 Increase scr_LogPrint() buffer size
Mikael Berthe <mikael@lilotux.net>
parents: 592
diff changeset
258 strftime(buffer, 48, "[%H:%M:%S] ", localtime(&timestamp));
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
259 for (b2 = buffer ; *b2 ; b2++)
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
260 ;
373
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
261 va_start(ap, fmt);
602
7b20c27cae48 Increase scr_LogPrint() buffer size
Mikael Berthe <mikael@lilotux.net>
parents: 592
diff changeset
262 vsnprintf(b2, 5120, fmt, ap);
373
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
263 va_end(ap);
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
264
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
265 if (flag & LPRINT_NORMAL) {
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
266 if (Curses) {
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
267 wprintw(logWnd, "\n%s", buffer);
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
268 update_panels();
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
269 doupdate();
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
270 } else {
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
271 printf("%s\n", buffer);
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
272 }
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
273 }
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
274 if (flag & (LPRINT_LOG|LPRINT_DEBUG)) {
658
5d71d1f8887e Avoid g_try_new()
Mikael Berthe <mikael@lilotux.net>
parents: 657
diff changeset
275 char *buffer2 = g_new(char, 5184);
412
9c640ee3bae3 Display full date in the log file
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
276
658
5d71d1f8887e Avoid g_try_new()
Mikael Berthe <mikael@lilotux.net>
parents: 657
diff changeset
277 strftime(buffer2, 23, "[%Y-%m-%d %H:%M:%S] ", localtime(&timestamp));
5d71d1f8887e Avoid g_try_new()
Mikael Berthe <mikael@lilotux.net>
parents: 657
diff changeset
278 strcat(buffer2, b2);
412
9c640ee3bae3 Display full date in the log file
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
279 strcat(buffer2, "\n");
9c640ee3bae3 Display full date in the log file
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
280 ut_WriteLog(flag, buffer2);
658
5d71d1f8887e Avoid g_try_new()
Mikael Berthe <mikael@lilotux.net>
parents: 657
diff changeset
281 g_free(buffer2);
373
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
282 }
602
7b20c27cae48 Increase scr_LogPrint() buffer size
Mikael Berthe <mikael@lilotux.net>
parents: 592
diff changeset
283 g_free(buffer);
373
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
284 }
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
285
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 332
diff changeset
286 static window_entry_t *scr_CreateBuddyPanel(const char *title, int dont_show)
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
287 {
151
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
288 int x;
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
289 int y;
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
290 int lines;
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
291 int cols;
153
ae0844311710 [/trunk] Changeset 165 by mikael
mikael
parents: 151
diff changeset
292 window_entry_t *tmp;
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 389
diff changeset
293
657
056dc9e65c25 Some memory allocation code cleaning
Mikael Berthe <mikael@lilotux.net>
parents: 654
diff changeset
294 tmp = g_new0(window_entry_t, 1);
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
295
151
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
296 // Dimensions
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
297 x = ROSTER_WIDTH;
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
298 y = 0;
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
299 lines = CHAT_WIN_HEIGHT;
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
300 cols = maxX - ROSTER_WIDTH;
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
301
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
302 tmp->win = newwin(lines, cols, y, x);
154
8630b7cae87b [/trunk] Changeset 166 by mikael
mikael
parents: 153
diff changeset
303 while (!tmp->win) {
419
2f9852610cf4 Small code review
Mikael Berthe <mikael@lilotux.net>
parents: 412
diff changeset
304 safe_usleep(250);
154
8630b7cae87b [/trunk] Changeset 166 by mikael
mikael
parents: 153
diff changeset
305 tmp->win = newwin(lines, cols, y, x);
8630b7cae87b [/trunk] Changeset 166 by mikael
mikael
parents: 153
diff changeset
306 }
168
6ad156673b19 [/trunk] Changeset 180 by mikael
mikael
parents: 167
diff changeset
307 wbkgd(tmp->win, COLOR_PAIR(COLOR_GENERAL));
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
308 tmp->panel = new_panel(tmp->win);
657
056dc9e65c25 Some memory allocation code cleaning
Mikael Berthe <mikael@lilotux.net>
parents: 654
diff changeset
309 tmp->name = g_strdup(title);
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
310
143
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
311 if (!dont_show) {
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
312 currentWindow = tmp;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
313 } else {
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
314 if (currentWindow)
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
315 top_panel(currentWindow->panel);
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
316 else
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
317 top_panel(chatPanel);
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
318 }
143
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
319 update_panels();
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
320
181
4a0bde661562 [/trunk] Changeset 193 by mikael
mikael
parents: 180
diff changeset
321 // Load buddy history from file (if enabled)
185
e8e447a07641 [/trunk] Changeset 197 by mikael
mikael
parents: 184
diff changeset
322 hlog_read_history(title, &tmp->hbuf, maxX - ROSTER_WIDTH - PREFIX_WIDTH);
181
4a0bde661562 [/trunk] Changeset 193 by mikael
mikael
parents: 180
diff changeset
323
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
324 list_add_tail(&tmp->list, &window_list);
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
325
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
326 return tmp;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
327 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
328
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 332
diff changeset
329 static window_entry_t *scr_SearchWindow(const char *winId)
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
330 {
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
331 struct list_head *pos, *n;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
332 window_entry_t *search_entry = NULL;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
333
361
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
334 if (!winId) return NULL;
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
335
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
336 list_for_each_safe(pos, n, &window_list) {
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
337 search_entry = window_entry(pos);
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
338 if (search_entry->name) {
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
339 if (!strcasecmp(search_entry->name, winId)) {
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
340 return search_entry;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
341 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
342 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
343 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
344 return NULL;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
345 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
346
514
979eb0fe2969 Show status changes in buddy window, if it is open
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
347 bool scr_BuddyBufferExists(const char *jid)
979eb0fe2969 Show status changes in buddy window, if it is open
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
348 {
979eb0fe2969 Show status changes in buddy window, if it is open
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
349 return (scr_SearchWindow(jid) != NULL);
979eb0fe2969 Show status changes in buddy window, if it is open
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
350 }
979eb0fe2969 Show status changes in buddy window, if it is open
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
351
143
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
352 // scr_UpdateWindow()
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
353 // (Re-)Display the given chat window.
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 332
diff changeset
354 static void scr_UpdateWindow(window_entry_t *win_entry)
74
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
355 {
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
356 int n;
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
357 int width;
184
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 181
diff changeset
358 hbb_line **lines, *line;
74
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
359 GList *hbuf_head;
184
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 181
diff changeset
360 char date[32];
74
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
361
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
362 width = scr_WindowWidth(win_entry->win);
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
363
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
364 // Should the window be empty?
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
365 if (win_entry->cleared) {
168
6ad156673b19 [/trunk] Changeset 180 by mikael
mikael
parents: 167
diff changeset
366 werase(win_entry->win);
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
367 return;
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
368 }
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
369
105
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
370 // win_entry->top is the top message of the screen. If it set to NULL, we
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
371 // are displaying the last messages.
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
372
74
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
373 // We will show the last CHAT_WIN_HEIGHT lines.
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
374 // Let's find out where it begins.
105
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
375 if (!win_entry->top ||
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
376 (g_list_position(g_list_first(win_entry->hbuf), win_entry->top) == -1)) {
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
377 // Move up CHAT_WIN_HEIGHT lines
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
378 win_entry->hbuf = g_list_last(win_entry->hbuf);
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
379 hbuf_head = win_entry->hbuf;
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
380 win_entry->top = NULL; // (Just to make sure)
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
381 n = 0;
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
382 while (hbuf_head && (n < CHAT_WIN_HEIGHT-1) && g_list_previous(hbuf_head)) {
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
383 hbuf_head = g_list_previous(hbuf_head);
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
384 n++;
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
385 }
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
386 } else
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
387 hbuf_head = win_entry->top;
74
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
388
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
389 // Get the last CHAT_WIN_HEIGHT lines.
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
390 lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT);
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
391
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
392 // Display these lines
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
393 for (n = 0; n < CHAT_WIN_HEIGHT; n++) {
168
6ad156673b19 [/trunk] Changeset 180 by mikael
mikael
parents: 167
diff changeset
394 wmove(win_entry->win, n, 0);
184
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 181
diff changeset
395 line = *(lines+n);
185
e8e447a07641 [/trunk] Changeset 197 by mikael
mikael
parents: 184
diff changeset
396 // NOTE: update PREFIX_WIDTH if you change the date format!!
e8e447a07641 [/trunk] Changeset 197 by mikael
mikael
parents: 184
diff changeset
397 // You need to set it to the whole prefix length + 1
184
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 181
diff changeset
398 if (line) {
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 181
diff changeset
399 if (line->timestamp) {
419
2f9852610cf4 Small code review
Mikael Berthe <mikael@lilotux.net>
parents: 412
diff changeset
400 strftime(date, 30, "%m-%d %H:%M", localtime(&line->timestamp));
184
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 181
diff changeset
401 } else
185
e8e447a07641 [/trunk] Changeset 197 by mikael
mikael
parents: 184
diff changeset
402 strcpy(date, " ");
197
c289e3c39c48 [/trunk] Changeset 209 by mikael
mikael
parents: 196
diff changeset
403 if (line->flags & HBB_PREFIX_INFO) {
c289e3c39c48 [/trunk] Changeset 209 by mikael
mikael
parents: 196
diff changeset
404 char dir = '*';
c289e3c39c48 [/trunk] Changeset 209 by mikael
mikael
parents: 196
diff changeset
405 if (line->flags & HBB_PREFIX_IN)
c289e3c39c48 [/trunk] Changeset 209 by mikael
mikael
parents: 196
diff changeset
406 dir = '<';
c289e3c39c48 [/trunk] Changeset 209 by mikael
mikael
parents: 196
diff changeset
407 else if (line->flags & HBB_PREFIX_OUT)
c289e3c39c48 [/trunk] Changeset 209 by mikael
mikael
parents: 196
diff changeset
408 dir = '>';
c289e3c39c48 [/trunk] Changeset 209 by mikael
mikael
parents: 196
diff changeset
409 wprintw(win_entry->win, "%.11s *%c* ", date, dir);
325
ff6fb51bfd78 Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents: 322
diff changeset
410 } else if (line->flags & HBB_PREFIX_ERR) {
ff6fb51bfd78 Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents: 322
diff changeset
411 char dir = '#';
ff6fb51bfd78 Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents: 322
diff changeset
412 if (line->flags & HBB_PREFIX_IN)
ff6fb51bfd78 Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents: 322
diff changeset
413 dir = '<';
ff6fb51bfd78 Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents: 322
diff changeset
414 else if (line->flags & HBB_PREFIX_OUT)
ff6fb51bfd78 Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents: 322
diff changeset
415 dir = '>';
ff6fb51bfd78 Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents: 322
diff changeset
416 wprintw(win_entry->win, "%.11s #%c# ", date, dir);
197
c289e3c39c48 [/trunk] Changeset 209 by mikael
mikael
parents: 196
diff changeset
417 } else if (line->flags & HBB_PREFIX_IN)
185
e8e447a07641 [/trunk] Changeset 197 by mikael
mikael
parents: 184
diff changeset
418 wprintw(win_entry->win, "%.11s <== ", date);
184
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 181
diff changeset
419 else if (line->flags & HBB_PREFIX_OUT)
185
e8e447a07641 [/trunk] Changeset 197 by mikael
mikael
parents: 184
diff changeset
420 wprintw(win_entry->win, "%.11s --> ", date);
75
ff119bb11563 [/trunk] Changeset 89 by mikael
mikael
parents: 74
diff changeset
421 else {
185
e8e447a07641 [/trunk] Changeset 197 by mikael
mikael
parents: 184
diff changeset
422 wprintw(win_entry->win, "%.11s ", date);
75
ff119bb11563 [/trunk] Changeset 89 by mikael
mikael
parents: 74
diff changeset
423 }
184
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 181
diff changeset
424 wprintw(win_entry->win, "%s", line->text); // line
168
6ad156673b19 [/trunk] Changeset 180 by mikael
mikael
parents: 167
diff changeset
425 wclrtoeol(win_entry->win);
184
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 181
diff changeset
426 g_free(line->text);
168
6ad156673b19 [/trunk] Changeset 180 by mikael
mikael
parents: 167
diff changeset
427 } else {
6ad156673b19 [/trunk] Changeset 180 by mikael
mikael
parents: 167
diff changeset
428 wclrtobot(win_entry->win);
6ad156673b19 [/trunk] Changeset 180 by mikael
mikael
parents: 167
diff changeset
429 break;
75
ff119bb11563 [/trunk] Changeset 89 by mikael
mikael
parents: 74
diff changeset
430 }
74
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
431 }
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
432 g_free(lines);
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
433 }
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
434
143
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
435 // scr_ShowWindow()
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
436 // Display the chat window with the given identifier.
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 332
diff changeset
437 static void scr_ShowWindow(const char *winId)
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
438 {
74
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
439 window_entry_t *win_entry = scr_SearchWindow(winId);
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
440
181
4a0bde661562 [/trunk] Changeset 193 by mikael
mikael
parents: 180
diff changeset
441 if (!win_entry)
180
42a33611233b [/trunk] Changeset 192 by mikael
mikael
parents: 178
diff changeset
442 win_entry = scr_CreateBuddyPanel(winId, FALSE);
74
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
443
180
42a33611233b [/trunk] Changeset 192 by mikael
mikael
parents: 178
diff changeset
444 top_panel(win_entry->panel);
42a33611233b [/trunk] Changeset 192 by mikael
mikael
parents: 178
diff changeset
445 currentWindow = win_entry;
42a33611233b [/trunk] Changeset 192 by mikael
mikael
parents: 178
diff changeset
446 chatmode = TRUE;
42a33611233b [/trunk] Changeset 192 by mikael
mikael
parents: 178
diff changeset
447 roster_msg_setflag(winId, FALSE);
42a33611233b [/trunk] Changeset 192 by mikael
mikael
parents: 178
diff changeset
448 roster_setflags(winId, ROSTER_FLAG_LOCK, TRUE);
42a33611233b [/trunk] Changeset 192 by mikael
mikael
parents: 178
diff changeset
449 update_roster = TRUE;
74
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
450
180
42a33611233b [/trunk] Changeset 192 by mikael
mikael
parents: 178
diff changeset
451 // Refresh the window
42a33611233b [/trunk] Changeset 192 by mikael
mikael
parents: 178
diff changeset
452 scr_UpdateWindow(win_entry);
42a33611233b [/trunk] Changeset 192 by mikael
mikael
parents: 178
diff changeset
453
42a33611233b [/trunk] Changeset 192 by mikael
mikael
parents: 178
diff changeset
454 // Finished :)
42a33611233b [/trunk] Changeset 192 by mikael
mikael
parents: 178
diff changeset
455 update_panels();
142
bb6fe91589b9 [/trunk] Changeset 154 by mikael
mikael
parents: 140
diff changeset
456
bb6fe91589b9 [/trunk] Changeset 154 by mikael
mikael
parents: 140
diff changeset
457 top_panel(inputPanel);
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
458 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
459
143
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
460 // scr_ShowBuddyWindow()
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
461 // Display the chat window buffer for the current buddy.
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
462 void scr_ShowBuddyWindow(void)
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
463 {
105
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
464 const gchar *jid;
140
3b480b73df19 [/trunk] Changeset 152 by mikael
mikael
parents: 139
diff changeset
465
105
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
466 if (!current_buddy)
140
3b480b73df19 [/trunk] Changeset 152 by mikael
mikael
parents: 139
diff changeset
467 jid = NULL;
3b480b73df19 [/trunk] Changeset 152 by mikael
mikael
parents: 139
diff changeset
468 else
3b480b73df19 [/trunk] Changeset 152 by mikael
mikael
parents: 139
diff changeset
469 jid = CURRENT_JID;
3b480b73df19 [/trunk] Changeset 152 by mikael
mikael
parents: 139
diff changeset
470
3b480b73df19 [/trunk] Changeset 152 by mikael
mikael
parents: 139
diff changeset
471 if (!jid) {
3b480b73df19 [/trunk] Changeset 152 by mikael
mikael
parents: 139
diff changeset
472 top_panel(chatPanel);
143
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
473 top_panel(inputPanel);
140
3b480b73df19 [/trunk] Changeset 152 by mikael
mikael
parents: 139
diff changeset
474 currentWindow = NULL;
105
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
475 return;
140
3b480b73df19 [/trunk] Changeset 152 by mikael
mikael
parents: 139
diff changeset
476 }
3b480b73df19 [/trunk] Changeset 152 by mikael
mikael
parents: 139
diff changeset
477
105
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
478 scr_ShowWindow(jid);
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
479 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
480
143
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
481 // scr_WriteInWindow()
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
482 // Write some text in the winId window (this usually is a jid).
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
483 // Lines are splitted when they are too long to fit in the chat window.
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
484 // If this window doesn't exist, it is created.
184
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 181
diff changeset
485 void scr_WriteInWindow(const char *winId, const char *text, time_t timestamp,
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 181
diff changeset
486 unsigned int prefix_flags, int force_show)
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
487 {
74
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
488 window_entry_t *win_entry;
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
489 int dont_show = FALSE;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
490
74
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
491 // Look for the window entry.
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
492 win_entry = scr_SearchWindow(winId);
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
493
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
494 // Do we have to really show the window?
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
495 if (!chatmode)
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
496 dont_show = TRUE;
74
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
497 else if ((!force_show) && ((!currentWindow || (currentWindow != win_entry))))
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
498 dont_show = TRUE;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
499
74
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
500 // If the window entry doesn't exist yet, let's create it.
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
501 if (win_entry == NULL) {
151
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
502 win_entry = scr_CreateBuddyPanel(winId, dont_show);
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
503 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
504
220
8dfdc6f1778e [/trunk] Changeset 232 by mikael
mikael
parents: 197
diff changeset
505 // The message must be displayed -> update top pointer
8dfdc6f1778e [/trunk] Changeset 232 by mikael
mikael
parents: 197
diff changeset
506 if (win_entry->cleared)
8dfdc6f1778e [/trunk] Changeset 232 by mikael
mikael
parents: 197
diff changeset
507 win_entry->top = g_list_last(win_entry->hbuf);
8dfdc6f1778e [/trunk] Changeset 232 by mikael
mikael
parents: 197
diff changeset
508
184
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 181
diff changeset
509 hbuf_add_line(&win_entry->hbuf, text, timestamp, prefix_flags,
185
e8e447a07641 [/trunk] Changeset 197 by mikael
mikael
parents: 184
diff changeset
510 maxX - ROSTER_WIDTH - PREFIX_WIDTH);
74
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
511
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
512 if (win_entry->cleared) {
220
8dfdc6f1778e [/trunk] Changeset 232 by mikael
mikael
parents: 197
diff changeset
513 win_entry->cleared = FALSE;
8dfdc6f1778e [/trunk] Changeset 232 by mikael
mikael
parents: 197
diff changeset
514 if (g_list_next(win_entry->top))
8dfdc6f1778e [/trunk] Changeset 232 by mikael
mikael
parents: 197
diff changeset
515 win_entry->top = g_list_next(win_entry->top);
8dfdc6f1778e [/trunk] Changeset 232 by mikael
mikael
parents: 197
diff changeset
516 }
8dfdc6f1778e [/trunk] Changeset 232 by mikael
mikael
parents: 197
diff changeset
517
8dfdc6f1778e [/trunk] Changeset 232 by mikael
mikael
parents: 197
diff changeset
518 // Make sure the last line appears in the window; update top if necessary
8dfdc6f1778e [/trunk] Changeset 232 by mikael
mikael
parents: 197
diff changeset
519 if (win_entry->top) {
8dfdc6f1778e [/trunk] Changeset 232 by mikael
mikael
parents: 197
diff changeset
520 int dist;
8dfdc6f1778e [/trunk] Changeset 232 by mikael
mikael
parents: 197
diff changeset
521 GList *first = g_list_first(win_entry->hbuf);
8dfdc6f1778e [/trunk] Changeset 232 by mikael
mikael
parents: 197
diff changeset
522 dist = g_list_position(first, g_list_last(win_entry->hbuf)) -
8dfdc6f1778e [/trunk] Changeset 232 by mikael
mikael
parents: 197
diff changeset
523 g_list_position(first, win_entry->top);
8dfdc6f1778e [/trunk] Changeset 232 by mikael
mikael
parents: 197
diff changeset
524 if (dist >= CHAT_WIN_HEIGHT)
8dfdc6f1778e [/trunk] Changeset 232 by mikael
mikael
parents: 197
diff changeset
525 win_entry->top = NULL;
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
526 }
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
527
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
528 if (!dont_show) {
74
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
529 // Show and refresh the window
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
530 top_panel(win_entry->panel);
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
531 scr_UpdateWindow(win_entry);
142
bb6fe91589b9 [/trunk] Changeset 154 by mikael
mikael
parents: 140
diff changeset
532 top_panel(inputPanel);
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
533 update_panels();
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
534 doupdate();
513
d40c434fff46 Add HBB_PREFIX_NOFLAG
Mikael Berthe <mikael@lilotux.net>
parents: 512
diff changeset
535 } else if (!(prefix_flags & HBB_PREFIX_NOFLAG)) {
148
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 143
diff changeset
536 roster_msg_setflag(winId, TRUE);
30
4ea2df449381 [/trunk] Changeset 46 by mikael
mikael
parents: 29
diff changeset
537 update_roster = TRUE;
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
538 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
539 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
540
151
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
541 // scr_DrawMainWindow()
157
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
542 // Set fullinit to TRUE to also create panels. Set it to FALSE for a resize.
151
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
543 //
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
544 // I think it could be improved a _lot_ but I'm really not an ncurses
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
545 // expert... :-\ Mikael.
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
546 //
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
547 void scr_DrawMainWindow(unsigned int fullinit)
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
548 {
518
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
549 int requested_lwh;
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
550
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
551 Log_Win_Height = DEFAULT_LOG_WIN_HEIGHT;
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
552 requested_lwh = settings_opt_get_int("log_win_height");
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
553 if (requested_lwh > 0) {
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
554 if (maxY > requested_lwh + 3)
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
555 Log_Win_Height = requested_lwh + 2;
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
556 else
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
557 Log_Win_Height = ((maxY > 5) ? (maxY - 2) : 3);
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
558 } else if (requested_lwh < 0) {
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
559 Log_Win_Height = 3;
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
560 }
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
561
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
562 if (maxY < Log_Win_Height+2) {
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
563 if (maxY < 5) {
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
564 Log_Win_Height = 3;
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
565 maxY = Log_Win_Height+2;
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
566 } else {
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
567 Log_Win_Height = maxY - 2;
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
568 }
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
569 }
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
570
157
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
571 if (fullinit) {
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
572 /* Create windows */
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
573 rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WIDTH, 0, 0);
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
574 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH, 0, ROSTER_WIDTH);
515
180f0a6e4ac9 Log window's height can be set by the user
Mikael Berthe <mikael@lilotux.net>
parents: 514
diff changeset
575 logWnd_border = newwin(Log_Win_Height, maxX, CHAT_WIN_HEIGHT, 0);
180f0a6e4ac9 Log window's height can be set by the user
Mikael Berthe <mikael@lilotux.net>
parents: 514
diff changeset
576 logWnd = newwin(Log_Win_Height-2, maxX-2, CHAT_WIN_HEIGHT+1, 1);
157
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
577 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
578 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
579 scr_TerminateCurses();
6e4e667c5571 Fix a segfault when starting mcabber in a really small terminal
Mikael Berthe <mikael@lilotux.net>
parents: 339
diff changeset
580 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
581 exit(EXIT_FAILURE);
6e4e667c5571 Fix a segfault when starting mcabber in a really small terminal
Mikael Berthe <mikael@lilotux.net>
parents: 339
diff changeset
582 }
168
6ad156673b19 [/trunk] Changeset 180 by mikael
mikael
parents: 167
diff changeset
583 wbkgd(rosterWnd, COLOR_PAIR(COLOR_GENERAL));
6ad156673b19 [/trunk] Changeset 180 by mikael
mikael
parents: 167
diff changeset
584 wbkgd(chatWnd, COLOR_PAIR(COLOR_GENERAL));
6ad156673b19 [/trunk] Changeset 180 by mikael
mikael
parents: 167
diff changeset
585 wbkgd(logWnd_border, COLOR_PAIR(COLOR_GENERAL));
6ad156673b19 [/trunk] Changeset 180 by mikael
mikael
parents: 167
diff changeset
586 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL));
157
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
587 } else {
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
588 /* Resize windows */
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
589 wresize(rosterWnd, CHAT_WIN_HEIGHT, ROSTER_WIDTH);
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
590 wresize(chatWnd, CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH);
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
591
515
180f0a6e4ac9 Log window's height can be set by the user
Mikael Berthe <mikael@lilotux.net>
parents: 514
diff changeset
592 wresize(logWnd_border, Log_Win_Height, maxX);
180f0a6e4ac9 Log window's height can be set by the user
Mikael Berthe <mikael@lilotux.net>
parents: 514
diff changeset
593 wresize(logWnd, Log_Win_Height-2, maxX-2);
157
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
594 mvwin(logWnd_border, CHAT_WIN_HEIGHT, 0);
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
595 mvwin(logWnd, CHAT_WIN_HEIGHT+1, 1);
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
596
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
597 wresize(inputWnd, 1, maxX);
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
598 mvwin(inputWnd, maxY-1, 0);
168
6ad156673b19 [/trunk] Changeset 180 by mikael
mikael
parents: 167
diff changeset
599
6ad156673b19 [/trunk] Changeset 180 by mikael
mikael
parents: 167
diff changeset
600 werase(chatWnd);
157
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
601 }
151
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
602
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
603 /* Draw/init windows */
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
604
74
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
605 mvwprintw(chatWnd, 0, 0, "This is the status window");
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
606
151
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
607 // - Draw/clear the log window
515
180f0a6e4ac9 Log window's height can be set by the user
Mikael Berthe <mikael@lilotux.net>
parents: 514
diff changeset
608 scr_draw_box(logWnd_border, 0, 0, Log_Win_Height, maxX, COLOR_GENERAL, 0, 0);
157
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
609 // Auto-scrolling in log window
74
b392112ab995 [/trunk] Changeset 88 by mikael
mikael
parents: 65
diff changeset
610 scrollok(logWnd, TRUE);
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
611
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
612
151
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
613 if (fullinit) {
157
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
614 // Enable keypad (+ special keys)
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
615 keypad(inputWnd, TRUE);
382
4c6e8392e465 Use nodelay() instead of halfdelay()
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
616 nodelay(inputWnd, TRUE);
157
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
617
151
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
618 // Create panels
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
619 rosterPanel = new_panel(rosterWnd);
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
620 chatPanel = new_panel(chatWnd);
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
621 logPanel_border = new_panel(logWnd_border);
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
622 logPanel = new_panel(logWnd);
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
623 inputPanel = new_panel(inputWnd);
232
9a6ba4b38e63 [/trunk] Changeset 245 by mikael
mikael
parents: 220
diff changeset
624
9a6ba4b38e63 [/trunk] Changeset 245 by mikael
mikael
parents: 220
diff changeset
625 if (utf8_mode)
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
626 scr_LogPrint(LPRINT_NORMAL, "WARNING: UTF-8 not yet supported!");
157
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
627 } else {
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
628 // Update panels
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
629 replace_panel(rosterPanel, rosterWnd);
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
630 replace_panel(chatPanel, chatWnd);
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
631 replace_panel(logPanel, logWnd);
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
632 replace_panel(logPanel_border, logWnd_border);
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
633 replace_panel(inputPanel, inputWnd);
151
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
634 }
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
635
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
636 // We'll need to redraw the roster
149
9f74832eb4f8 [/trunk] Changeset 161 by mikael
mikael
parents: 148
diff changeset
637 update_roster = TRUE;
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
638 return;
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
639 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
640
151
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
641 // scr_Resize()
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
642 // Function called when the window is resized.
157
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
643 // - Resize windows
151
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
644 // - Rewrap lines in each buddy buffer
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
645 void scr_Resize()
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
646 {
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
647 struct list_head *pos, *n;
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
648 window_entry_t *search_entry;
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
649 int x, y, lines, cols;
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
650
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
651 // First, update the global variables
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
652 getmaxyx(stdscr, maxY, maxX);
518
9480a76471b6 Update Log_Win_Height when refreshing the screen
Mikael Berthe <mikael@lilotux.net>
parents: 515
diff changeset
653 // 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
654
151
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
655 // Make sure the cursor stays inside the window
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
656 check_offset(0);
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
657
157
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
658 // Resize windows and update panels
151
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
659 scr_DrawMainWindow(FALSE);
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
660
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
661 // Resize all buddy windows
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
662 x = ROSTER_WIDTH;
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
663 y = 0;
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
664 lines = CHAT_WIN_HEIGHT;
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
665 cols = maxX - ROSTER_WIDTH;
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
666
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
667 list_for_each_safe(pos, n, &window_list) {
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
668 search_entry = window_entry(pos);
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
669 if (search_entry->win) {
189
4f3975f1b852 [/trunk] Changeset 201 by mikael
mikael
parents: 187
diff changeset
670 GList *rescue_top;
157
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
671 // Resize buddy window (no need to move it)
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
672 wresize(search_entry->win, lines, cols);
168
6ad156673b19 [/trunk] Changeset 180 by mikael
mikael
parents: 167
diff changeset
673 werase(search_entry->win);
151
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
674 // If a panel exists, replace the old window with the new
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
675 if (search_entry->panel) {
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
676 replace_panel(search_entry->panel, search_entry->win);
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
677 }
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
678 // Redo line wrapping
189
4f3975f1b852 [/trunk] Changeset 201 by mikael
mikael
parents: 187
diff changeset
679 rescue_top = hbuf_previous_persistent(search_entry->top);
151
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
680 hbuf_rebuild(&search_entry->hbuf,
185
e8e447a07641 [/trunk] Changeset 197 by mikael
mikael
parents: 184
diff changeset
681 maxX - ROSTER_WIDTH - PREFIX_WIDTH);
388
f211238d5812 Ctrl-l does a full refresh
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
682 if (g_list_position(g_list_first(search_entry->hbuf),
f211238d5812 Ctrl-l does a full refresh
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
683 search_entry->top) == -1) {
189
4f3975f1b852 [/trunk] Changeset 201 by mikael
mikael
parents: 187
diff changeset
684 search_entry->top = rescue_top;
388
f211238d5812 Ctrl-l does a full refresh
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
685 }
151
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
686 }
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
687 }
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
688
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
689 // Refresh current buddy window
157
409ff07d9fe2 [/trunk] Changeset 169 by mikael
mikael
parents: 154
diff changeset
690 if (chatmode)
151
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
691 scr_ShowBuddyWindow();
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
692 }
b69c0b7a23e3 [/trunk] Changeset 163 by mikael
mikael
parents: 149
diff changeset
693
143
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
694 // scr_DrawRoster()
328
83d129adde03 Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
695 // Display the buddylist (not really the roster) on the screen
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
696 void scr_DrawRoster(void)
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
697 {
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
698 static guint offset = 0;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
699 char name[ROSTER_WIDTH];
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
700 int maxx, maxy;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
701 GList *buddy;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
702 int i, n;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
703 int rOffset;
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
704 enum imstatus currentstatus = jb_getstatus();
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
705
123
1bdf882bed98 [/trunk] Changeset 136 by mikael
mikael
parents: 121
diff changeset
706 // We can reset update_roster
1bdf882bed98 [/trunk] Changeset 136 by mikael
mikael
parents: 121
diff changeset
707 update_roster = FALSE;
1bdf882bed98 [/trunk] Changeset 136 by mikael
mikael
parents: 121
diff changeset
708
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
709 getmaxyx(rosterWnd, maxy, maxx);
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
710 maxx --; // last char is for vertical border
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
711 name[ROSTER_WIDTH-7] = 0;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
712
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
713 // cleanup of roster window
168
6ad156673b19 [/trunk] Changeset 180 by mikael
mikael
parents: 167
diff changeset
714 werase(rosterWnd);
6ad156673b19 [/trunk] Changeset 180 by mikael
mikael
parents: 167
diff changeset
715 // Redraw the vertical line (not very good...)
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
716 wattrset(rosterWnd, COLOR_PAIR(COLOR_GENERAL));
168
6ad156673b19 [/trunk] Changeset 180 by mikael
mikael
parents: 167
diff changeset
717 for (i=0 ; i < CHAT_WIN_HEIGHT ; i++)
6ad156673b19 [/trunk] Changeset 180 by mikael
mikael
parents: 167
diff changeset
718 mvwaddch(rosterWnd, i, ROSTER_WIDTH-1, ACS_VLINE);
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
719
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
720 // Leave now if buddylist is empty
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
721 if (!buddylist) {
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
722 offset = 0;
123
1bdf882bed98 [/trunk] Changeset 136 by mikael
mikael
parents: 121
diff changeset
723 update_panels();
1bdf882bed98 [/trunk] Changeset 136 by mikael
mikael
parents: 121
diff changeset
724 doupdate();
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
725 return;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
726 }
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
727
84
134fe2567f07 [/trunk] Changeset 98 by mikael
mikael
parents: 81
diff changeset
728 // Update offset if necessary
134fe2567f07 [/trunk] Changeset 98 by mikael
mikael
parents: 81
diff changeset
729 i = g_list_position(buddylist, current_buddy);
134fe2567f07 [/trunk] Changeset 98 by mikael
mikael
parents: 81
diff changeset
730 if (i == -1) { // This is bad
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
731 scr_LogPrint(LPRINT_NORMAL, "Doh! Can't find current selected buddy!!");
84
134fe2567f07 [/trunk] Changeset 98 by mikael
mikael
parents: 81
diff changeset
732 return;
134fe2567f07 [/trunk] Changeset 98 by mikael
mikael
parents: 81
diff changeset
733 } else if (i < offset) {
134fe2567f07 [/trunk] Changeset 98 by mikael
mikael
parents: 81
diff changeset
734 offset = i;
134fe2567f07 [/trunk] Changeset 98 by mikael
mikael
parents: 81
diff changeset
735 } else if (i+1 > offset + maxy) {
134fe2567f07 [/trunk] Changeset 98 by mikael
mikael
parents: 81
diff changeset
736 offset = i + 1 - maxy;
134fe2567f07 [/trunk] Changeset 98 by mikael
mikael
parents: 81
diff changeset
737 }
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
738
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
739 buddy = buddylist;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
740 rOffset = offset;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
741
84
134fe2567f07 [/trunk] Changeset 98 by mikael
mikael
parents: 81
diff changeset
742 for (i=0; i<maxy && buddy; buddy = g_list_next(buddy)) {
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
743
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
744 char status = '?';
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
745 char pending = ' ';
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
746 enum imstatus budstate;
149
9f74832eb4f8 [/trunk] Changeset 161 by mikael
mikael
parents: 148
diff changeset
747 unsigned short ismsg = buddy_getflags(BUDDATA(buddy)) & ROSTER_FLAG_MSG;
9f74832eb4f8 [/trunk] Changeset 161 by mikael
mikael
parents: 148
diff changeset
748 unsigned short isgrp = buddy_gettype(BUDDATA(buddy)) & ROSTER_TYPE_GROUP;
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 445
diff changeset
749 unsigned short ismuc = buddy_gettype(BUDDATA(buddy)) & ROSTER_TYPE_ROOM;
149
9f74832eb4f8 [/trunk] Changeset 161 by mikael
mikael
parents: 148
diff changeset
750 unsigned short ishid = buddy_getflags(BUDDATA(buddy)) & ROSTER_FLAG_HIDE;
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
751
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
752 if (rOffset > 0) {
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
753 rOffset--;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
754 continue;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
755 }
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
756
149
9f74832eb4f8 [/trunk] Changeset 161 by mikael
mikael
parents: 148
diff changeset
757 // Display message notice if there is a message flag, but not
9f74832eb4f8 [/trunk] Changeset 161 by mikael
mikael
parents: 148
diff changeset
758 // for unfolded groups.
9f74832eb4f8 [/trunk] Changeset 161 by mikael
mikael
parents: 148
diff changeset
759 if (ismsg && (!isgrp || ishid)) {
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
760 pending = '#';
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
761 }
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
762
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
763 budstate = buddy_getstatus(BUDDATA(buddy), NULL);
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
764 if (budstate >= 0 && budstate < imstatus_size && currentstatus != offline)
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
765 status = imstatus2char[budstate];
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
766 if (buddy == current_buddy) {
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
767 wattrset(rosterWnd, COLOR_PAIR(COLOR_BD_DESSEL));
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
768 // The 3 following lines aim to color the whole line
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
769 wmove(rosterWnd, i, 0);
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
770 for (n = 0; n < maxx; n++)
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
771 waddch(rosterWnd, ' ');
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
772 } else {
149
9f74832eb4f8 [/trunk] Changeset 161 by mikael
mikael
parents: 148
diff changeset
773 if (pending == '#')
139
8d7e31d37bec [/trunk] Changeset 151 by mikael
mikael
parents: 135
diff changeset
774 wattrset(rosterWnd, COLOR_PAIR(COLOR_NMSG));
8d7e31d37bec [/trunk] Changeset 151 by mikael
mikael
parents: 135
diff changeset
775 else
8d7e31d37bec [/trunk] Changeset 151 by mikael
mikael
parents: 135
diff changeset
776 wattrset(rosterWnd, COLOR_PAIR(COLOR_BD_DES));
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
777 }
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
778
459
8827bbef84a1 Show if we are inside/outside a MUC room
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
779 if (ismuc) {
652
b243d3b3ff1b We do not need buddy_isresource() anymore
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
780 if (buddy_getinsideroom(BUDDATA(buddy)))
459
8827bbef84a1 Show if we are inside/outside a MUC room
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
781 status = 'C';
8827bbef84a1 Show if we are inside/outside a MUC room
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
782 else
8827bbef84a1 Show if we are inside/outside a MUC room
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
783 status = 'x';
8827bbef84a1 Show if we are inside/outside a MUC room
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
784 }
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 445
diff changeset
785
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
786 strncpy(name, buddy_getname(BUDDATA(buddy)), ROSTER_WIDTH-7);
149
9f74832eb4f8 [/trunk] Changeset 161 by mikael
mikael
parents: 148
diff changeset
787 if (isgrp) {
133
a27b22e3b3a1 [/trunk] Changeset 146 by mikael
mikael
parents: 129
diff changeset
788 char *sep;
149
9f74832eb4f8 [/trunk] Changeset 161 by mikael
mikael
parents: 148
diff changeset
789 if (ishid)
133
a27b22e3b3a1 [/trunk] Changeset 146 by mikael
mikael
parents: 129
diff changeset
790 sep = "+++";
a27b22e3b3a1 [/trunk] Changeset 146 by mikael
mikael
parents: 129
diff changeset
791 else
a27b22e3b3a1 [/trunk] Changeset 146 by mikael
mikael
parents: 129
diff changeset
792 sep = "---";
a27b22e3b3a1 [/trunk] Changeset 146 by mikael
mikael
parents: 129
diff changeset
793 mvwprintw(rosterWnd, i, 0, " %c%s %s", pending, sep, name);
a27b22e3b3a1 [/trunk] Changeset 146 by mikael
mikael
parents: 129
diff changeset
794 }
126
d3ee9abe9ca6 [/trunk] Changeset 139 by mikael
mikael
parents: 123
diff changeset
795 else
d3ee9abe9ca6 [/trunk] Changeset 139 by mikael
mikael
parents: 123
diff changeset
796 mvwprintw(rosterWnd, i, 0, " %c[%c] %s", pending, status, name);
84
134fe2567f07 [/trunk] Changeset 98 by mikael
mikael
parents: 81
diff changeset
797
134fe2567f07 [/trunk] Changeset 98 by mikael
mikael
parents: 81
diff changeset
798 i++;
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
799 }
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
800
142
bb6fe91589b9 [/trunk] Changeset 154 by mikael
mikael
parents: 140
diff changeset
801 top_panel(inputPanel);
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
802 update_panels();
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
803 doupdate();
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
804 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
805
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
806 inline void scr_WriteMessage(const char *jid, const char *text,
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
807 time_t timestamp, guint prefix_flags)
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
808 {
184
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 181
diff changeset
809 if (!timestamp) timestamp = time(NULL);
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 181
diff changeset
810
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 181
diff changeset
811 scr_WriteInWindow(jid, text, timestamp, prefix_flags, FALSE);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents: 44
diff changeset
812 }
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents: 44
diff changeset
813
190
9c2023d60986 [/trunk] Changeset 202 by mikael
mikael
parents: 189
diff changeset
814 // If prefix is NULL, HBB_PREFIX_IN is supposed.
184
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 181
diff changeset
815 void scr_WriteIncomingMessage(const char *jidfrom, const char *text,
190
9c2023d60986 [/trunk] Changeset 202 by mikael
mikael
parents: 189
diff changeset
816 time_t timestamp, guint prefix)
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents: 44
diff changeset
817 {
513
d40c434fff46 Add HBB_PREFIX_NOFLAG
Mikael Berthe <mikael@lilotux.net>
parents: 512
diff changeset
818 if (!(prefix & ~HBB_PREFIX_NOFLAG))
d40c434fff46 Add HBB_PREFIX_NOFLAG
Mikael Berthe <mikael@lilotux.net>
parents: 512
diff changeset
819 prefix |= HBB_PREFIX_IN;
75
ff119bb11563 [/trunk] Changeset 89 by mikael
mikael
parents: 74
diff changeset
820 // FIXME expand tabs / filter out special chars...
190
9c2023d60986 [/trunk] Changeset 202 by mikael
mikael
parents: 189
diff changeset
821 scr_WriteMessage(jidfrom, text, timestamp, prefix);
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
822 update_panels();
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
823 doupdate();
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
824 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
825
50
5425ee13dce6 [/trunk] Changeset 66 by mikael
mikael
parents: 47
diff changeset
826 void scr_WriteOutgoingMessage(const char *jidto, const char *text)
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents: 44
diff changeset
827 {
184
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 181
diff changeset
828 scr_WriteMessage(jidto, text, 0, HBB_PREFIX_OUT);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents: 44
diff changeset
829 scr_ShowWindow(jidto);
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents: 44
diff changeset
830 }
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents: 44
diff changeset
831
373
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
832 void inline set_autoaway(bool setaway)
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
833 {
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
834 static enum imstatus oldstatus;
521
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 518
diff changeset
835 static char *oldmsg;
373
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
836 Autoaway = setaway;
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
837
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
838 if (setaway) {
521
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 518
diff changeset
839 const char *msg, *prevmsg;
373
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
840 oldstatus = jb_getstatus();
521
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 518
diff changeset
841 if (oldmsg) {
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 518
diff changeset
842 g_free(oldmsg);
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 518
diff changeset
843 oldmsg = NULL;
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 518
diff changeset
844 }
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 518
diff changeset
845 prevmsg = jb_getstatusmsg();
373
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
846 msg = settings_opt_get("message_autoaway");
521
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 518
diff changeset
847 if (!msg)
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 518
diff changeset
848 msg = prevmsg;
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 518
diff changeset
849 if (prevmsg)
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 518
diff changeset
850 oldmsg = g_strdup(prevmsg);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
851 jb_setstatus(away, NULL, msg);
373
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
852 } else {
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
853 // Back
521
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 518
diff changeset
854 jb_setstatus(oldstatus, NULL, (oldmsg ? oldmsg : ""));
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 518
diff changeset
855 if (oldmsg) {
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 518
diff changeset
856 g_free(oldmsg);
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 518
diff changeset
857 oldmsg = NULL;
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 518
diff changeset
858 }
373
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
859 }
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
860 }
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
861
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
862 // Check if we should enter/leave automatic away status
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
863 void scr_CheckAutoAway(bool activity)
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
864 {
373
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
865 static time_t LastActivity;
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
866 enum imstatus cur_st;
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
867 unsigned int autoaway_timeout = settings_opt_get_int("autoaway");
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
868
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
869 if (Autoaway && activity) set_autoaway(FALSE);
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
870 if (!autoaway_timeout) return;
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
871 if (!LastActivity || activity) time(&LastActivity);
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
872
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
873 cur_st = jb_getstatus();
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
874 // Auto-away is disabled for the following states
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
875 if ((cur_st != available) && (cur_st != freeforchat))
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
876 return;
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
877
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
878 if (!activity) {
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
879 time_t now;
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
880 time(&now);
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
881 if (!Autoaway && (now > LastActivity + autoaway_timeout))
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
882 set_autoaway(TRUE);
af2f8ddf6a1b Move (reorganize) functions
Mikael Berthe <mikael@lilotux.net>
parents: 370
diff changeset
883 }
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
884 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
885
328
83d129adde03 Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
886 // set_current_buddy(newbuddy)
83d129adde03 Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
887 // 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
888 // 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
889 static void set_current_buddy(GList *newbuddy)
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
890 {
328
83d129adde03 Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
891 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
892 /* 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
893 * 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
894 * buddy_getstatus() call.
83d129adde03 Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
895 */
83d129adde03 Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
896
329
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
897 if (!current_buddy || !newbuddy) return;
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
898 if (newbuddy == current_buddy) return;
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
899
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
900 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
901 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE);
330
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 329
diff changeset
902 if (chatmode)
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 329
diff changeset
903 alternate_buddy = current_buddy;
328
83d129adde03 Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
904 current_buddy = newbuddy;
83d129adde03 Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
905 // 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
906 if (chatmode)
83d129adde03 Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
907 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
908 // 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
909 // 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
910 // 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
911 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
912 buddylist_build();
83d129adde03 Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
913 update_roster = TRUE;
24
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
914 }
e88b15cbf2de [/trunk] Changeset 40 by mikael
mikael
parents:
diff changeset
915
143
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
916 // scr_RosterTop()
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
917 // Go to the first buddy in the buddylist
105
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
918 void scr_RosterTop(void)
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
919 {
328
83d129adde03 Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
920 set_current_buddy(buddylist);
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
921 if (chatmode)
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
922 scr_ShowBuddyWindow();
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
923 }
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
924
143
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
925 // scr_RosterBottom()
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
926 // Go to the last buddy in the buddylist
105
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
927 void scr_RosterBottom(void)
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
928 {
328
83d129adde03 Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
929 set_current_buddy(g_list_last(buddylist));
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
930 if (chatmode)
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
931 scr_ShowBuddyWindow();
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
932 }
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
933
143
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
934 // scr_RosterUp()
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
935 // Go to the previous buddy in the buddylist
105
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
936 void scr_RosterUp(void)
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
937 {
328
83d129adde03 Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
938 set_current_buddy(g_list_previous(current_buddy));
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
939 if (chatmode)
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
940 scr_ShowBuddyWindow();
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
941 }
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
942
143
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
943 // scr_RosterDown()
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
944 // Go to the next buddy in the buddylist
105
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
945 void scr_RosterDown(void)
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
946 {
328
83d129adde03 Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
947 set_current_buddy(g_list_next(current_buddy));
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
948 if (chatmode)
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
949 scr_ShowBuddyWindow();
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
950 }
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 76
diff changeset
951
265
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 263
diff changeset
952 // scr_RosterSearch(str)
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 263
diff changeset
953 // Look forward for a buddy with jid/name containing str.
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 263
diff changeset
954 void scr_RosterSearch(char *str)
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 263
diff changeset
955 {
328
83d129adde03 Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
956 set_current_buddy(buddy_search(str));
265
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 263
diff changeset
957 if (chatmode)
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 263
diff changeset
958 scr_ShowBuddyWindow();
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 263
diff changeset
959 }
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 263
diff changeset
960
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
961 // scr_RosterJumpJid(jid)
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
962 // Jump to buddy jid.
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
963 // NOTE: With this function, the buddy is added to the roster if doesn't exist.
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
964 void scr_RosterJumpJid(char *barejid)
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
965 {
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
966 GSList *roster_elt;
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
967 // Look for an existing buddy
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
968 roster_elt = roster_find(barejid, jidsearch,
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
969 ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM);
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
970 // Create it if necessary
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
971 if (!roster_elt)
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 602
diff changeset
972 roster_elt = roster_add_user(barejid, NULL, NULL, ROSTER_TYPE_USER,
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 602
diff changeset
973 sub_none);
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
974 // Set a lock to see it in the buddylist
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
975 buddy_setflags(BUDDATA(roster_elt), ROSTER_FLAG_LOCK, TRUE);
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
976 buddylist_build();
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
977 // Jump to the buddy
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
978 set_current_buddy(buddy_search_jid(barejid));
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
979 if (chatmode)
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
980 scr_ShowBuddyWindow();
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
981 }
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 464
diff changeset
982
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
983 // scr_RosterUnreadMessage(next)
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
984 // Go to a new message. If next is not null, try to go to the next new
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
985 // message. If it is not possible or if next is NULL, go to the first new
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
986 // message from unread_list.
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
987 void scr_RosterUnreadMessage(int next)
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
988 {
329
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
989 gpointer unread_ptr;
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
990 gpointer refbuddata;
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
991 gpointer ngroup;
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
992 GList *nbuddy;
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
993
329
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
994 if (!current_buddy) return;
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
995
329
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
996 if (next) refbuddata = BUDDATA(current_buddy);
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
997 else refbuddata = NULL;
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
998
329
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
999 unread_ptr = unread_msg(refbuddata);
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
1000 if (!unread_ptr) return;
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
1001
329
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
1002 // If buddy is in a folded group, we need to expand it
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
1003 ngroup = buddy_getgroup(unread_ptr);
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
1004 if (buddy_getflags(ngroup) & ROSTER_FLAG_HIDE) {
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
1005 buddy_setflags(ngroup, ROSTER_FLAG_HIDE, FALSE);
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
1006 buddylist_build();
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
1007 }
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
1008
329
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
1009 nbuddy = g_list_find(buddylist, unread_ptr);
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
1010 if (nbuddy) {
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
1011 set_current_buddy(nbuddy);
7c53bf62a2a2 scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents: 328
diff changeset
1012 if (chatmode) scr_ShowBuddyWindow();
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
1013 } else
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
1014 scr_LogPrint(LPRINT_LOGNORM, "Error: nbuddy == NULL"); // should not happen
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
1015 }
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
1016
330
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 329
diff changeset
1017 // scr_RosterJumpAlternate()
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 329
diff changeset
1018 // Try to jump to alternate (== previous) buddy
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 329
diff changeset
1019 void scr_RosterJumpAlternate(void)
105
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
1020 {
330
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 329
diff changeset
1021 if (!alternate_buddy || g_list_position(buddylist, alternate_buddy) == -1)
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 329
diff changeset
1022 return;
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 329
diff changeset
1023 set_current_buddy(alternate_buddy);
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 329
diff changeset
1024 if (chatmode)
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 329
diff changeset
1025 scr_ShowBuddyWindow();
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 329
diff changeset
1026 }
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 329
diff changeset
1027
369
499170ed71c9 Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents: 365
diff changeset
1028 // scr_BufferScrollUpDown()
508
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 503
diff changeset
1029 // Scroll up/down the current buddy window,
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 503
diff changeset
1030 // - half a screen if nblines is 0,
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 503
diff changeset
1031 // - up if updown == -1, down if updown == 1
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 503
diff changeset
1032 void scr_BufferScrollUpDown(int updown, unsigned int nblines)
105
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
1033 {
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
1034 window_entry_t *win_entry;
508
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 503
diff changeset
1035 int n, nbl;
105
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
1036 GList *hbuf_top;
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
1037
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
1038 // Get win_entry
361
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1039 if (!current_buddy) return;
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1040 win_entry = scr_SearchWindow(CURRENT_JID);
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1041 if (!win_entry) return;
105
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
1042
508
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 503
diff changeset
1043 if (!nblines) {
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 503
diff changeset
1044 // Scroll half a screen (or less)
512
1744664332cd Fix "/buffer up"
Mikael Berthe <mikael@lilotux.net>
parents: 508
diff changeset
1045 nbl = CHAT_WIN_HEIGHT/2;
508
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 503
diff changeset
1046 } else {
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 503
diff changeset
1047 nbl = nblines;
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 503
diff changeset
1048 }
105
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
1049 hbuf_top = win_entry->top;
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
1050
361
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1051 if (updown == -1) { // UP
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1052 if (!hbuf_top) {
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1053 hbuf_top = g_list_last(win_entry->hbuf);
512
1744664332cd Fix "/buffer up"
Mikael Berthe <mikael@lilotux.net>
parents: 508
diff changeset
1054 if (!win_entry->cleared) {
1744664332cd Fix "/buffer up"
Mikael Berthe <mikael@lilotux.net>
parents: 508
diff changeset
1055 if (!nblines) nbl = nbl*3 - 1;
1744664332cd Fix "/buffer up"
Mikael Berthe <mikael@lilotux.net>
parents: 508
diff changeset
1056 else nbl += CHAT_WIN_HEIGHT - 1;
1744664332cd Fix "/buffer up"
Mikael Berthe <mikael@lilotux.net>
parents: 508
diff changeset
1057 } else {
361
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1058 win_entry->cleared = FALSE;
512
1744664332cd Fix "/buffer up"
Mikael Berthe <mikael@lilotux.net>
parents: 508
diff changeset
1059 }
361
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1060 }
508
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 503
diff changeset
1061 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
1062 hbuf_top = g_list_previous(hbuf_top);
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1063 win_entry->top = hbuf_top;
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1064 } else { // DOWN
508
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 503
diff changeset
1065 for (n=0 ; hbuf_top && n < nbl ; n++)
361
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1066 hbuf_top = g_list_next(hbuf_top);
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1067 win_entry->top = hbuf_top;
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1068 // Check if we are at the bottom
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1069 for (n=0 ; hbuf_top && n < CHAT_WIN_HEIGHT-1 ; n++)
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1070 hbuf_top = g_list_next(hbuf_top);
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1071 if (!hbuf_top)
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1072 win_entry->top = NULL; // End reached
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1073 }
105
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
1074
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
1075 // Refresh the window
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
1076 scr_UpdateWindow(win_entry);
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
1077
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
1078 // Finished :)
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
1079 update_panels();
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
1080 doupdate();
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
1081 }
91d3ec21c24e [/trunk] Changeset 119 by mikael
mikael
parents: 104
diff changeset
1082
369
499170ed71c9 Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents: 365
diff changeset
1083 // scr_BufferClear()
143
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
1084 // 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
1085 void scr_BufferClear(void)
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
1086 {
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
1087 window_entry_t *win_entry;
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
1088
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
1089 // Get win_entry
361
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1090 if (!current_buddy) return;
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1091 win_entry = scr_SearchWindow(CURRENT_JID);
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1092 if (!win_entry) return;
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
1093
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
1094 win_entry->cleared = TRUE;
109
96d239239c7a [/trunk] Changeset 123 by mikael
mikael
parents: 108
diff changeset
1095 win_entry->top = NULL;
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
1096
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
1097 // Refresh the window
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
1098 scr_UpdateWindow(win_entry);
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
1099
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
1100 // Finished :)
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
1101 update_panels();
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
1102 doupdate();
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
1103 }
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 105
diff changeset
1104
361
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1105 // scr_BufferTopBottom()
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1106 // Jump to the head/tail of the current buddy window
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1107 // (top if topbottom == -1, bottom topbottom == 1)
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1108 void scr_BufferTopBottom(int topbottom)
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 185
diff changeset
1109 {
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 185
diff changeset
1110 window_entry_t *win_entry;
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 185
diff changeset
1111
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 185
diff changeset
1112 // Get win_entry
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 185
diff changeset
1113 if (!current_buddy) return;
361
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1114 win_entry = scr_SearchWindow(CURRENT_JID);
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 185
diff changeset
1115 if (!win_entry) return;
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 185
diff changeset
1116
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 185
diff changeset
1117 win_entry->cleared = FALSE;
361
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1118 if (topbottom == 1)
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1119 win_entry->top = NULL;
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1120 else
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 358
diff changeset
1121 win_entry->top = g_list_first(win_entry->hbuf);
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 185
diff changeset
1122
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 185
diff changeset
1123 // Refresh the window
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 185
diff changeset
1124 scr_UpdateWindow(win_entry);
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 185
diff changeset
1125
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 185
diff changeset
1126 // Finished :)
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 185
diff changeset
1127 update_panels();
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 185
diff changeset
1128 doupdate();
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 185
diff changeset
1129 }
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 185
diff changeset
1130
370
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1131 // scr_BufferSearch(direction, text)
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1132 // Jump to the next line containing text
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1133 // (backward search if direction == -1, forward if topbottom == 1)
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1134 void scr_BufferSearch(int direction, const char *text)
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1135 {
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1136 window_entry_t *win_entry;
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1137 GList *current_line, *search_res;
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1138
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1139 // Get win_entry
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1140 if (!current_buddy) return;
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1141 win_entry = scr_SearchWindow(CURRENT_JID);
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1142 if (!win_entry) return;
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1143
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1144 if (win_entry->top)
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1145 current_line = win_entry->top;
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1146 else
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1147 current_line = g_list_last(win_entry->hbuf);
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1148
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1149 search_res = hbuf_search(current_line, direction, text);
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1150
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1151 if (search_res) {
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1152 win_entry->cleared = FALSE;
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1153 win_entry->top = search_res;
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1154
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1155 // Refresh the window
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1156 scr_UpdateWindow(win_entry);
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1157
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1158 // Finished :)
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1159 update_panels();
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1160 doupdate();
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1161 } else
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
1162 scr_LogPrint(LPRINT_NORMAL, "Search string not found");
370
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1163 }
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1164
462
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1165 // scr_BufferPercent(n)
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1166 // Jump to the specified position in the buffer, in %
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1167 void scr_BufferPercent(int pc)
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1168 {
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1169 window_entry_t *win_entry;
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1170 GList *search_res;
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1171
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1172 // Get win_entry
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1173 if (!current_buddy) return;
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1174 win_entry = scr_SearchWindow(CURRENT_JID);
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1175 if (!win_entry) return;
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1176
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1177 if (pc < 0 || pc > 100) {
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1178 scr_LogPrint(LPRINT_NORMAL, "Bad % value");
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1179 return;
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1180 }
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1181
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1182 search_res = hbuf_jump_percent(win_entry->hbuf, pc);
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1183
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1184 win_entry->cleared = FALSE;
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1185 win_entry->top = search_res;
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1186
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1187 // Refresh the window
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1188 scr_UpdateWindow(win_entry);
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1189
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1190 // Finished :)
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1191 update_panels();
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1192 doupdate();
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1193 }
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 459
diff changeset
1194
464
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1195 // scr_BufferDate(t)
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1196 // Jump to the first line after date t in the buffer
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1197 // t is a date in seconds since `00:00:00 1970-01-01 UTC'
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1198 void scr_BufferDate(time_t t)
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1199 {
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1200 window_entry_t *win_entry;
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1201 GList *search_res;
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1202
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1203 // Get win_entry
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1204 if (!current_buddy) return;
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1205 win_entry = scr_SearchWindow(CURRENT_JID);
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1206 if (!win_entry) return;
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1207
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1208 search_res = hbuf_jump_date(win_entry->hbuf, t);
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1209
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1210 win_entry->cleared = FALSE;
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1211 win_entry->top = search_res;
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1212
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1213 // Refresh the window
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1214 scr_UpdateWindow(win_entry);
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1215
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1216 // Finished :)
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1217 update_panels();
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1218 doupdate();
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1219 }
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
1220
143
300bb88f631f [/trunk] Changeset 155 by mikael
mikael
parents: 142
diff changeset
1221 // scr_set_chatmode()
261
259ed1de5bdc Fix spelling mistakes in comments
mikael@frmp8452
parents: 260
diff changeset
1222 // Public function to (un)set chatmode...
129
03be1cc94560 [/trunk] Changeset 142 by mikael
mikael
parents: 126
diff changeset
1223 inline void scr_set_chatmode(int enable)
03be1cc94560 [/trunk] Changeset 142 by mikael
mikael
parents: 126
diff changeset
1224 {
03be1cc94560 [/trunk] Changeset 142 by mikael
mikael
parents: 126
diff changeset
1225 chatmode = enable;
03be1cc94560 [/trunk] Changeset 142 by mikael
mikael
parents: 126
diff changeset
1226 }
03be1cc94560 [/trunk] Changeset 142 by mikael
mikael
parents: 126
diff changeset
1227
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1228 // scr_get_multimode()
261
259ed1de5bdc Fix spelling mistakes in comments
mikael@frmp8452
parents: 260
diff changeset
1229 // Public function to get multimode status...
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1230 inline int scr_get_multimode()
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1231 {
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1232 return multimode;
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1233 }
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1234
654
d7fe7b88e4fc MUC: Set the new_message flag when joining a room
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
1235 // 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
1236 // Set the message flag unless we're already in the jid buffer window
d7fe7b88e4fc MUC: Set the new_message flag when joining a room
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
1237 void scr_setmsgflag_if_needed(const char *jid)
d7fe7b88e4fc MUC: Set the new_message flag when joining a room
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
1238 {
667
86bc3295a4db Fix segfault in scr_setmsgflag_if_needed()
Mikael Berthe <mikael@lilotux.net>
parents: 658
diff changeset
1239 const char *current_jid;
86bc3295a4db Fix segfault in scr_setmsgflag_if_needed()
Mikael Berthe <mikael@lilotux.net>
parents: 658
diff changeset
1240
86bc3295a4db Fix segfault in scr_setmsgflag_if_needed()
Mikael Berthe <mikael@lilotux.net>
parents: 658
diff changeset
1241 if (current_buddy)
86bc3295a4db Fix segfault in scr_setmsgflag_if_needed()
Mikael Berthe <mikael@lilotux.net>
parents: 658
diff changeset
1242 current_jid = buddy_getjid(BUDDATA(current_buddy));
86bc3295a4db Fix segfault in scr_setmsgflag_if_needed()
Mikael Berthe <mikael@lilotux.net>
parents: 658
diff changeset
1243 else
86bc3295a4db Fix segfault in scr_setmsgflag_if_needed()
Mikael Berthe <mikael@lilotux.net>
parents: 658
diff changeset
1244 current_jid = NULL;
86bc3295a4db Fix segfault in scr_setmsgflag_if_needed()
Mikael Berthe <mikael@lilotux.net>
parents: 658
diff changeset
1245 if (!chatmode || !current_jid || strcmp(jid, current_jid))
654
d7fe7b88e4fc MUC: Set the new_message flag when joining a room
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
1246 roster_msg_setflag(jid, TRUE);
d7fe7b88e4fc MUC: Set the new_message flag when joining a room
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
1247 }
d7fe7b88e4fc MUC: Set the new_message flag when joining a room
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
1248
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1249 // scr_set_multimode()
261
259ed1de5bdc Fix spelling mistakes in comments
mikael@frmp8452
parents: 260
diff changeset
1250 // Public function to (un)set multimode...
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 252
diff changeset
1251 // Convention:
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 252
diff changeset
1252 // 0 = disabled / 1 = multimode / 2 = multimode verbatim (commands disabled)
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1253 inline void scr_set_multimode(int enable)
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1254 {
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1255 if (multiline) {
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1256 g_free(multiline);
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1257 multiline = NULL;
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1258 }
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 252
diff changeset
1259 multimode = enable;
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1260 }
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1261
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1262 // scr_get_multiline()
261
259ed1de5bdc Fix spelling mistakes in comments
mikael@frmp8452
parents: 260
diff changeset
1263 // Public function to get the current multi-line.
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1264 inline const char *scr_get_multiline()
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1265 {
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1266 if (multimode && multiline)
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1267 return multiline;
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1268 else
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1269 return "";
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1270 }
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1271
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1272 // scr_append_multiline(line)
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1273 // Public function to append a line to the current multi-line message.
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1274 // Skip empty leading lines.
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1275 void scr_append_multiline(const char *line)
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1276 {
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1277 static int num;
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1278
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1279 if (!multimode) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 373
diff changeset
1280 scr_LogPrint(LPRINT_NORMAL, "Error: Not in multi-line message mode!");
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1281 return</