Bug Summary

File:fe-common/core/window-items.c
Location:line 102, column 2
Description:Value stored to 'window' is never read

Annotated Source Code

1/*
2 window-items.c : irssi
3
4 Copyright (C) 2000 Timo Sirainen
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19*/
20
21#include "module.h"
22#include "module-formats.h"
23#include "modules.h"
24#include "signals.h"
25#include "servers.h"
26#include "channels.h"
27#include "settings.h"
28
29#include "levels.h"
30
31#include "fe-windows.h"
32#include "window-items.h"
33#include "printtext.h"
34
35static void window_item_add_signal(WINDOW_REC *window, WI_ITEM_REC *item, int automatic, int send_signal)
36{
37 g_return_if_fail(window != NULL)do{ if (window != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "window != NULL"); return
; }; }while (0)
;
38 g_return_if_fail(item != NULL)do{ if (item != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "item != NULL"); return;
}; }while (0)
;
39 g_return_if_fail(item->window == NULL)do{ if (item->window == ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "item->window == NULL"
); return; }; }while (0)
;
40
41 item->window = window;
42
43 if (window->items == NULL((void *)0)) {
44 window->active = item;
45 window->active_server = item->server;
46 }
47
48 if (!automatic || settings_get_bool("window_auto_change")) {
49 if (automatic)
50 signal_emit("window changed automatic", 1, window);
51 window_set_active(window);
52 }
53
54 window->items = g_slist_append(window->items, item);
55 if (send_signal)
56 signal_emit("window item new", 2, window, item);
57
58 if (g_slist_length(window->items) == 1 ||
59 (!automatic && settings_get_bool("autofocus_new_items"))) {
60 window->active = NULL((void *)0);
61 window_item_set_active(window, item);
62 }
63}
64
65void window_item_add(WINDOW_REC *window, WI_ITEM_REC *item, int automatic)
66{
67 window_item_add_signal(window, item, automatic, TRUE(!(0)));
68}
69
70static void window_item_remove_signal(WI_ITEM_REC *item, int emit_signal)
71{
72 WINDOW_REC *window;
73
74 g_return_if_fail(item != NULL)do{ if (item != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "item != NULL"); return;
}; }while (0)
;
75
76 window = window_item_window(item)((WINDOW_REC *) ((WI_ITEM_REC *) (item))->window);
77
78 if (window == NULL((void *)0))
79 return;
80
81 item->window = NULL((void *)0);
82 window->items = g_slist_remove(window->items, item);
83
84 if (window->active == item) {
85 window_item_set_active(window, window->items == NULL((void *)0) ? NULL((void *)0) :
86 window->items->data);
87 }
88
89 if (emit_signal)
90 signal_emit("window item remove", 2, window, item);
91}
92
93void window_item_remove(WI_ITEM_REC *item)
94{
95 window_item_remove_signal(item, TRUE(!(0)));
96}
97
98void window_item_destroy(WI_ITEM_REC *item)
99{
100 WINDOW_REC *window;
101
102 window = window_item_window(item)((WINDOW_REC *) ((WI_ITEM_REC *) (item))->window);
Value stored to 'window' is never read
103 window_item_remove(item);
104 item->destroy(item);
105}
106
107void window_item_change_server(WI_ITEM_REC *item, void *server)
108{
109 WINDOW_REC *window;
110
111 g_return_if_fail(item != NULL)do{ if (item != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "item != NULL"); return;
}; }while (0)
;
112
113 window = window_item_window(item)((WINDOW_REC *) ((WI_ITEM_REC *) (item))->window);
114 item->server = server;
115
116 signal_emit("window item server changed", 2, window, item);
117 if (window->active == item) window_change_server(window, item->server);
118}
119
120void window_item_set_active(WINDOW_REC *window, WI_ITEM_REC *item)
121{
122 WINDOW_REC *old_window;
123
124 g_return_if_fail(window != NULL)do{ if (window != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "window != NULL"); return
; }; }while (0)
;
125
126 if (item != NULL((void *)0)) {
127 old_window = window_item_window(item)((WINDOW_REC *) ((WI_ITEM_REC *) (item))->window);
128 if (old_window != window) {
129 /* move item to different window */
130 window_item_remove_signal(item, FALSE(0));
131 window_item_add_signal(window, item, FALSE(0), FALSE(0));
132 signal_emit("window item moved", 3, window, item, old_window);
133 }
134 }
135
136 if (window->active != item) {
137 window->active = item;
138 if (item != NULL((void *)0) && window->active_server != item->server)
139 window_change_server(window, item->server);
140 signal_emit("window item changed", 2, window, item);
141 }
142}
143
144/* Return TRUE if `item' is the active window item in the window.
145 `item' can be NULL. */
146int window_item_is_active(WI_ITEM_REC *item)
147{
148 WINDOW_REC *window;
149
150 if (item == NULL((void *)0))
151 return FALSE(0);
152
153 window = window_item_window(item)((WINDOW_REC *) ((WI_ITEM_REC *) (item))->window);
154 if (window == NULL((void *)0))
155 return FALSE(0);
156
157 return window->active == item;
158}
159
160void window_item_prev(WINDOW_REC *window)
161{
162 WI_ITEM_REC *last;
163 GSList *tmp;
164
165 g_return_if_fail(window != NULL)do{ if (window != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "window != NULL"); return
; }; }while (0)
;
166
167 last = NULL((void *)0);
168 for (tmp = window->items; tmp != NULL((void *)0); tmp = tmp->next) {
169 WI_ITEM_REC *rec = tmp->data;
170
171 if (rec != window->active)
172 last = rec;
173 else {
174 /* current channel. did we find anything?
175 if not, go to the last channel */
176 if (last != NULL((void *)0)) break;
177 }
178 }
179
180 if (last != NULL((void *)0))
181 window_item_set_active(window, last);
182}
183
184void window_item_next(WINDOW_REC *window)
185{
186 WI_ITEM_REC *next;
187 GSList *tmp;
188 int gone;
189
190 g_return_if_fail(window != NULL)do{ if (window != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "window != NULL"); return
; }; }while (0)
;
191
192 next = NULL((void *)0); gone = FALSE(0);
193 for (tmp = window->items; tmp != NULL((void *)0); tmp = tmp->next) {
194 WI_ITEM_REC *rec = tmp->data;
195
196 if (rec == window->active)
197 gone = TRUE(!(0));
198 else {
199 if (gone) {
200 /* found the next channel */
201 next = rec;
202 break;
203 }
204
205 if (next == NULL((void *)0))
206 next = rec; /* fallback to first channel */
207 }
208 }
209
210 if (next != NULL((void *)0))
211 window_item_set_active(window, next);
212}
213
214WI_ITEM_REC *window_item_find_window(WINDOW_REC *window,
215 void *server, const char *name)
216{
217 CHANNEL_REC *channel;
218 GSList *tmp;
219
220 for (tmp = window->items; tmp != NULL((void *)0); tmp = tmp->next) {
221 WI_ITEM_REC *rec = tmp->data;
222
223 if ((server == NULL((void *)0) || rec->server == server) &&
224 g_strcasecmp(name, rec->visible_name) == 0)
225 return rec;
226 }
227
228 /* try with channel name too, it's not necessarily
229 same as visible_name (!channels) */
230 channel = channel_find(server, name);
231 if (channel != NULL((void *)0) && window_item_window(channel)((WINDOW_REC *) ((WI_ITEM_REC *) (channel))->window) == window)
232 return (WI_ITEM_REC *) channel;
233
234 return NULL((void *)0);
235}
236
237/* Find wanted window item by name. `server' can be NULL. */
238WI_ITEM_REC *window_item_find(void *server, const char *name)
239{
240 WI_ITEM_REC *item;
241 GSList *tmp;
242
243 g_return_val_if_fail(name != NULL, NULL)do{ if (name != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "name != NULL"); return (
((void *)0)); }; }while (0)
;
244
245 for (tmp = windows; tmp != NULL((void *)0); tmp = tmp->next) {
246 WINDOW_REC *rec = tmp->data;
247
248 item = window_item_find_window(rec, server, name);
249 if (item != NULL((void *)0)) return item;
250 }
251
252 return NULL((void *)0);
253}
254
255static int window_bind_has_sticky(WINDOW_REC *window)
256{
257 GSList *tmp;
258
259 for (tmp = window->bound_items; tmp != NULL((void *)0); tmp = tmp->next) {
260 WINDOW_BIND_REC *rec = tmp->data;
261
262 if (rec->sticky)
263 return TRUE(!(0));
264 }
265
266 return FALSE(0);
267}
268
269void window_item_create(WI_ITEM_REC *item, int automatic)
270{
271 WINDOW_REC *window;
272 WINDOW_BIND_REC *bind;
273 GSList *tmp, *sorted;
274 int clear_waiting, reuse_unused_windows;
275
276 g_return_if_fail(item != NULL)do{ if (item != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "item != NULL"); return;
}; }while (0)
;
277
278 reuse_unused_windows = settings_get_bool("reuse_unused_windows");
279
280 clear_waiting = TRUE(!(0));
281 window = NULL((void *)0);
282 sorted = windows_get_sorted();
283 for (tmp = sorted; tmp != NULL((void *)0); tmp = tmp->next) {
284 WINDOW_REC *rec = tmp->data;
285
286 /* is item bound to this window? */
287 if (item->server != NULL((void *)0)) {
288 bind = window_bind_find(rec, item->server->tag,
289 item->visible_name);
290 if (bind != NULL((void *)0)) {
291 if (!bind->sticky)
292 window_bind_destroy(rec, bind);
293 window = rec;
294 clear_waiting = FALSE(0);
295 break;
296 }
297 }
298
299 /* use this window IF:
300 - reuse_unused_windows is ON
301 - window has no existing items
302 - window has no name
303 - window has no sticky binds (/LAYOUT SAVEd)
304 - we already haven't found "good enough" window,
305 except if
306 - this is the active window
307 - old window had some temporary bounds and this
308 one doesn't
309 */
310 if (reuse_unused_windows && rec->items == NULL((void *)0) &&
311 rec->name == NULL((void *)0) && !window_bind_has_sticky(rec) &&
312 (window == NULL((void *)0) || rec == active_win ||
313 window->bound_items != NULL((void *)0)))
314 window = rec;
315 }
316 g_slist_free(sorted);
317
318 if (window == NULL((void *)0) && !settings_get_bool("autocreate_windows")) {
319 /* never create new windows automatically */
320 window = active_win;
321 }
322
323 if (window == NULL((void *)0)) {
324 /* create new window to use */
325 if (settings_get_bool("autocreate_split_windows")) {
326 signal_emit("gui window create override", 1,
327 GINT_TO_POINTER(0)((gpointer) (0)));
328 }
329 window = window_create(item, automatic);
330 } else {
331 /* use existing window */
332 window_item_add(window, item, automatic);
333 }
334
335 if (clear_waiting)
336 window_bind_remove_unsticky(window);
337}
338
339static void signal_window_item_changed(WINDOW_REC *window, WI_ITEM_REC *item)
340{
341 g_return_if_fail(window != NULL)do{ if (window != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "window != NULL"); return
; }; }while (0)
;
342
343 if (g_slist_length(window->items) > 1) {
344 /* default to printing "talking with ...",
345 you can override it it you wish */
346 printformat(item->server, item->visible_name,printformat_module("fe-common/core", item->server, item->
visible_name, MSGLEVEL_CLIENTNOTICE, TXT_TALKING_WITH, item->
visible_name)
347 MSGLEVEL_CLIENTNOTICE,printformat_module("fe-common/core", item->server, item->
visible_name, MSGLEVEL_CLIENTNOTICE, TXT_TALKING_WITH, item->
visible_name)
348 TXT_TALKING_WITH, item->visible_name)printformat_module("fe-common/core", item->server, item->
visible_name, MSGLEVEL_CLIENTNOTICE, TXT_TALKING_WITH, item->
visible_name)
;
349 }
350}
351
352void window_items_init(void)
353{
354 settings_add_bool("lookandfeel", "reuse_unused_windows", FALSE)settings_add_bool_module("fe-common/core", "lookandfeel", "reuse_unused_windows"
, (0))
;
355 settings_add_bool("lookandfeel", "autocreate_windows", TRUE)settings_add_bool_module("fe-common/core", "lookandfeel", "autocreate_windows"
, (!(0)))
;
356 settings_add_bool("lookandfeel", "autocreate_split_windows", FALSE)settings_add_bool_module("fe-common/core", "lookandfeel", "autocreate_split_windows"
, (0))
;
357 settings_add_bool("lookandfeel", "autofocus_new_items", TRUE)settings_add_bool_module("fe-common/core", "lookandfeel", "autofocus_new_items"
, (!(0)))
;
358
359 signal_add_last("window item changed", (SIGNAL_FUNC) signal_window_item_changed)signal_add_full("fe-common/core", 100, ("window item changed"
), (SIGNAL_FUNC) ((SIGNAL_FUNC) signal_window_item_changed), (
(void *)0))
;
360}
361
362void window_items_deinit(void)
363{
364 signal_remove("window item changed", (SIGNAL_FUNC) signal_window_item_changed)signal_remove_full(("window item changed"), (SIGNAL_FUNC) ((SIGNAL_FUNC
) signal_window_item_changed), ((void *)0))
;
365}