annotate mcabber/src/screen.c @ 332:a1901741890e

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