~ubuntu-branches/ubuntu/trusty/weechat/trusty-proposed

« back to all changes in this revision

Viewing changes to src/plugins/xfer/xfer-upgrade.c

  • Committer: Bazaar Package Importer
  • Author(s): Emmanuel Bouthenot
  • Date: 2009-09-15 20:58:07 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090915205807-nd2nx3kof2aldqbt
Tags: 0.3.0-1
* New (final) upstream release.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2003-2009 by FlashCode <flashcode@flashtux.org>
 
3
 * See README for License detail, AUTHORS for developers list.
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 3 of the License, or
 
8
 * (at your option) any later version.
 
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
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
/* xfer-upgrade.c: save/restore xfer plugin data */
 
20
 
 
21
 
 
22
#include <stdlib.h>
 
23
 
 
24
#include "../weechat-plugin.h"
 
25
#include "xfer.h"
 
26
#include "xfer-upgrade.h"
 
27
#include "xfer-buffer.h"
 
28
 
 
29
 
 
30
 
 
31
/*
 
32
 * xfer_upgrade_save_xfers: save xfers info to upgrade file
 
33
 */
 
34
 
 
35
int
 
36
xfer_upgrade_save_xfers (struct t_upgrade_file *upgrade_file)
 
37
{
 
38
    /* TODO: save xfer data */
 
39
    (void) upgrade_file;
 
40
    return 1;
 
41
}
 
42
 
 
43
/*
 
44
 * xfer_upgrade_save: save upgrade file
 
45
 *                    return 1 if ok, 0 if error
 
46
 */
 
47
 
 
48
int
 
49
xfer_upgrade_save ()
 
50
{
 
51
    int rc;
 
52
    struct t_upgrade_file *upgrade_file;
 
53
    
 
54
    upgrade_file = weechat_upgrade_new (XFER_UPGRADE_FILENAME, 1);
 
55
    if (!upgrade_file)
 
56
        return 0;
 
57
    
 
58
    rc = xfer_upgrade_save_xfers (upgrade_file);
 
59
    
 
60
    weechat_upgrade_close (upgrade_file);
 
61
    
 
62
    return rc;
 
63
}
 
64
 
 
65
/*
 
66
 * xfer_upgrade_set_buffer_callbacks: restore buffers callbacks (input and
 
67
 *                                    close) for buffers created by xfer plugin
 
68
 */
 
69
 
 
70
void
 
71
xfer_upgrade_set_buffer_callbacks ()
 
72
{
 
73
    struct t_infolist *infolist;
 
74
    struct t_gui_buffer *ptr_buffer;
 
75
    
 
76
    infolist = weechat_infolist_get ("buffer", NULL, NULL);
 
77
    if (infolist)
 
78
    {
 
79
        while (weechat_infolist_next (infolist))
 
80
        {
 
81
            if (weechat_infolist_pointer (infolist, "plugin") == weechat_xfer_plugin)
 
82
            {
 
83
                ptr_buffer = weechat_infolist_pointer (infolist, "pointer");
 
84
                weechat_buffer_set_pointer (ptr_buffer, "close_callback", &xfer_buffer_close_cb);
 
85
                weechat_buffer_set_pointer (ptr_buffer, "input_callback", &xfer_buffer_input_cb);
 
86
            }
 
87
        }
 
88
    }
 
89
}
 
90
 
 
91
/*
 
92
 * xfer_upgrade_read_cb: read callback for xfer upgrade file
 
93
 */
 
94
 
 
95
int
 
96
xfer_upgrade_read_cb (void *data,
 
97
                      struct t_upgrade_file *upgrade_file,
 
98
                      int object_id,
 
99
                      struct t_infolist *infolist)
 
100
{
 
101
    /* TODO: write xfer read cb */
 
102
    (void) data;
 
103
    (void) upgrade_file;
 
104
    (void) object_id;
 
105
    (void) infolist;
 
106
    
 
107
    return WEECHAT_RC_OK;
 
108
}
 
109
 
 
110
/*
 
111
 * xfer_upgrade_load: load upgrade file
 
112
 *                    return 1 if ok, 0 if error
 
113
 */
 
114
 
 
115
int
 
116
xfer_upgrade_load ()
 
117
{
 
118
    int rc;
 
119
    struct t_upgrade_file *upgrade_file;
 
120
    
 
121
    xfer_upgrade_set_buffer_callbacks ();
 
122
    
 
123
    upgrade_file = weechat_upgrade_new (XFER_UPGRADE_FILENAME, 0);
 
124
    rc = weechat_upgrade_read (upgrade_file, &xfer_upgrade_read_cb, NULL);
 
125
    
 
126
    return rc;
 
127
}