annotate mcabber/src/screen.c @ 717:8ce2bfdc4143

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