~ubuntu-branches/ubuntu/trusty/irssi-plugin-xmpp/trusty

« back to all changes in this revision

Viewing changes to src/fe-text/text-xmpp-nick.c

  • Committer: Bazaar Package Importer
  • Author(s): David Ammouial
  • Date: 2009-05-12 12:14:44 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (2.2.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20090512121444-eh5zfk5r24tmq1he
* New CVS snapshot, built against irssi-dev 0.8.13:
  - New features and bugfixes.
  - Fix segfault when successfully identified (Closes: #521227).
  - Fix build error (Closes: #527697)
* Depend on irssi >=0.8.13, build-depend on irssi-dev >=0.8.13.
* Bump Standards-Version to 3.8.1 (no changes needed).
* Add INTERNAL to documentation files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * $Id: text-xmpp-nick.c,v 1.6 2008/03/01 17:57:21 errtu Exp $
3
 
 *
4
 
 * Copyright (C) 2007 Colin DIDIER
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 version 2 as
8
 
 * published by the Free Software Foundation.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License along
16
 
 * with this program; if not, write to the Free Software Foundation, Inc.,
17
 
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
 
 */
19
 
 
20
 
#include "module.h"
21
 
#include "signals.h"
22
 
#include "window-items.h"
23
 
 
24
 
/* in include/irssi/src/fe-text */
25
 
#include "statusbar.h"
26
 
 
27
 
#include "xmpp-servers.h"
28
 
#include "xmpp-channels.h"
29
 
 
30
 
static void
31
 
update_nick_statusbar(XMPP_SERVER_REC *server, XMPP_CHANNEL_REC *channel,
32
 
    gboolean redraw)
33
 
{
34
 
        g_return_if_fail(server != NULL);
35
 
 
36
 
        if (!IS_XMPP_SERVER(server))
37
 
                return;
38
 
 
39
 
        g_free(server->nick);
40
 
        server->nick = g_strdup(IS_XMPP_CHANNEL(channel) ?
41
 
            channel->nick : server->nickname);
42
 
 
43
 
        if (redraw)
44
 
                statusbar_redraw(NULL, TRUE);
45
 
}
46
 
 
47
 
static void
48
 
sig_window_changed(WINDOW_REC *window, WINDOW_REC *oldwindow)
49
 
{
50
 
        XMPP_SERVER_REC *server;
51
 
        XMPP_CHANNEL_REC *channel;
52
 
 
53
 
        g_return_if_fail(window != NULL);
54
 
 
55
 
        server = XMPP_SERVER(window->active_server);
56
 
        if (server == NULL)
57
 
                return;
58
 
 
59
 
        channel = XMPP_CHANNEL(window->active);
60
 
        if (channel != NULL ||
61
 
            (oldwindow != NULL && IS_XMPP_CHANNEL(oldwindow->active)))
62
 
                update_nick_statusbar(server, channel, FALSE);
63
 
}
64
 
 
65
 
static void
66
 
sig_window_destroyed(WINDOW_REC *window)
67
 
{
68
 
        XMPP_SERVER_REC *server;
69
 
        XMPP_CHANNEL_REC *channel;
70
 
 
71
 
        g_return_if_fail(window != NULL);
72
 
 
73
 
        server = XMPP_SERVER(window->active_server);
74
 
        if (server == NULL)
75
 
                return;
76
 
 
77
 
        channel = XMPP_CHANNEL(window->active);
78
 
        if (channel != NULL || !IS_XMPP_CHANNEL(active_win->active))
79
 
                update_nick_statusbar(server, NULL, TRUE);
80
 
}
81
 
 
82
 
static void
83
 
sig_nick_changed(XMPP_SERVER_REC *server, XMPP_CHANNEL_REC *channel)
84
 
{
85
 
        if (!IS_XMPP_SERVER(server) || !IS_XMPP_CHANNEL(channel))
86
 
                return;
87
 
 
88
 
        if (XMPP_CHANNEL(active_win->active) == channel)
89
 
                update_nick_statusbar(server, channel, TRUE);
90
 
}
91
 
 
92
 
static void
93
 
sig_channel_joined(XMPP_CHANNEL_REC *channel)
94
 
{
95
 
        g_return_if_fail(channel != NULL);
96
 
 
97
 
        if (!IS_XMPP_CHANNEL(channel))
98
 
                return;
99
 
 
100
 
        if (XMPP_CHANNEL(active_win->active) == channel)
101
 
                update_nick_statusbar(channel->server, channel, TRUE);
102
 
}
103
 
 
104
 
static void
105
 
sig_channel_destroyed(XMPP_CHANNEL_REC *channel)
106
 
{
107
 
        g_return_if_fail(channel != NULL);
108
 
 
109
 
        if (!IS_XMPP_CHANNEL(channel))
110
 
                return;
111
 
 
112
 
        if (XMPP_CHANNEL(active_win->active) == channel)
113
 
                update_nick_statusbar(channel->server, NULL, TRUE);
114
 
}
115
 
 
116
 
void
117
 
text_xmpp_nick_init(void)
118
 
{
119
 
        signal_add("window changed", (SIGNAL_FUNC)sig_window_changed);
120
 
        signal_add("window destroyed", (SIGNAL_FUNC)sig_window_destroyed);
121
 
        signal_add("message xmpp channel own_nick",
122
 
            (SIGNAL_FUNC)sig_nick_changed);
123
 
        signal_add("channel joined",(SIGNAL_FUNC)sig_channel_joined);
124
 
        signal_add("channel destroyed",(SIGNAL_FUNC)sig_channel_destroyed);
125
 
}
126
 
 
127
 
void
128
 
text_xmpp_nick_deinit(void)
129
 
{
130
 
        signal_remove("window changed", (SIGNAL_FUNC)sig_window_changed);
131
 
        signal_remove("window destroyed", (SIGNAL_FUNC)sig_window_destroyed);
132
 
        signal_remove("message xmpp channel own_nick",
133
 
            (SIGNAL_FUNC)sig_nick_changed);
134
 
        signal_remove("channel joined",(SIGNAL_FUNC)sig_channel_joined);
135
 
        signal_remove("channel destroyed",(SIGNAL_FUNC)sig_channel_destroyed);
136
 
}