summaryrefslogtreecommitdiff
path: root/src/plugins/relay/relay-upgrade.c
blob: 3fcb0e332069730161b2ecd3f3c8e80db1c426b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 * Copyright (c) 2003-2009 by FlashCode <flashcode@flashtux.org>
 * See README for License detail, AUTHORS for developers list.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/* relay-upgrade.c: save/restore relay plugin data */


#include <stdlib.h>

#include "../weechat-plugin.h"
#include "relay.h"
#include "relay-upgrade.h"
#include "relay-buffer.h"


/*
 * relay_upgrade_save_clients: save clients info to upgrade file
 */

int
relay_upgrade_save_clients (struct t_upgrade_file *upgrade_file)
{
    /* TODO: save relay data */
    (void) upgrade_file;
    return 1;
}

/*
 * relay_upgrade_save: save upgrade file
 *                     return 1 if ok, 0 if error
 */

int
relay_upgrade_save ()
{
    int rc;
    struct t_upgrade_file *upgrade_file;
    
    upgrade_file = weechat_upgrade_create (RELAY_UPGRADE_FILENAME, 1);
    if (!upgrade_file)
        return 0;
    
    rc = relay_upgrade_save_clients (upgrade_file);
    
    weechat_upgrade_close (upgrade_file);
    
    return rc;
}

/*
 * relay_upgrade_set_buffer_callbacks: restore buffers callbacks (input and
 *                                     close) for buffers created by relay plugin
 */

void
relay_upgrade_set_buffer_callbacks ()
{
    struct t_infolist *infolist;
    struct t_gui_buffer *ptr_buffer;
    
    infolist = weechat_infolist_get ("buffer", NULL, NULL);
    if (infolist)
    {
        while (weechat_infolist_next (infolist))
        {
            if (weechat_infolist_pointer (infolist, "plugin") == weechat_relay_plugin)
            {
                ptr_buffer = weechat_infolist_pointer (infolist, "pointer");
                weechat_buffer_set_pointer (ptr_buffer, "close_callback", &relay_buffer_close_cb);
                weechat_buffer_set_pointer (ptr_buffer, "input_callback", &relay_buffer_input_cb);
            }
        }
    }
}

/*
 * relay_upgrade_read_cb: read callback for relay upgrade file
 */

int
relay_upgrade_read_cb (int object_id,
                      struct t_infolist *infolist)
{
    /* TODO: write relay read cb */
    (void) object_id;
    (void) infolist;
    return WEECHAT_RC_OK;
}

/*
 * relay_upgrade_load: load upgrade file
 *                    return 1 if ok, 0 if error
 */

int
relay_upgrade_load ()
{
    int rc;
    struct t_upgrade_file *upgrade_file;
    
    relay_upgrade_set_buffer_callbacks ();
    
    upgrade_file = weechat_upgrade_create (RELAY_UPGRADE_FILENAME, 0);
    rc = weechat_upgrade_read (upgrade_file, &relay_upgrade_read_cb);
    
    return rc;
}