Commit | Line | Data |
---|---|---|
0d04e87e FT |
1 | /* |
2 | * Dolda Connect - Modular multiuser Direct Connect-style client | |
302a2600 | 3 | * Copyright (C) 2007 Fredrik Tolf <fredrik@dolda2000.com> |
0d04e87e FT |
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 2 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, write to the Free Software | |
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | */ | |
19 | ||
20 | #include <stdlib.h> | |
21 | #include <string.h> | |
22 | #include <gtk/gtk.h> | |
23 | #include <doldaconnect/utils.h> | |
24 | ||
25 | #ifdef HAVE_CONFIG_H | |
26 | #include <config.h> | |
27 | #endif | |
28 | #include "dolcon.h" | |
29 | #include "hublist.h" | |
30 | ||
31 | int pubhuboldhandler(int op, char *buf, size_t len) | |
32 | { | |
33 | static GtkListStore *model = NULL; | |
34 | int i; | |
35 | char *p, *p2; | |
36 | wchar_t *wbuf; | |
37 | char *fields[4], *names[3]; | |
38 | int cols[3]; | |
39 | GtkTreeIter iter; | |
40 | ||
41 | switch(op) | |
42 | { | |
43 | case PHO_INIT: | |
44 | model = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT); | |
45 | break; | |
46 | case PHO_DATA: | |
47 | p = buf; | |
ef4a9a10 | 48 | while((p = memchr((p2 = p), '\n', len - (p - buf))) != NULL) |
0d04e87e FT |
49 | { |
50 | *(p++) = 0; | |
ef4a9a10 | 51 | for(i = 0; i < 4; i++) { |
0d04e87e FT |
52 | fields[i] = p2; |
53 | if((p2 = strchr(p2, '|')) == NULL) | |
54 | break; | |
55 | *(p2++) = 0; | |
56 | } | |
57 | if(i == 4) { | |
58 | for(i = 0; i < 4; i++) { | |
59 | if((wbuf = icsmbstowcs(fields[i], DCCHARSET, NULL)) == NULL) { | |
60 | fields[i] = sstrdup(_("(Invalid character)")); | |
61 | } else { | |
62 | if((fields[i] = icwcstombs(wbuf, "UTF-8")) == NULL) | |
63 | break; | |
64 | } | |
65 | } | |
66 | if(i == 4) { | |
67 | if(validhub(fields[0], fields[2], NULL)) { | |
68 | gtk_list_store_append(model, &iter); | |
69 | gtk_list_store_set(model, &iter, 0, fields[1], 1, fields[0], 2, fields[2], 3, atoi(fields[3]), -1); | |
70 | } | |
71 | } | |
72 | for(i--; i >= 0; i--) | |
73 | free(fields[i]); | |
74 | } | |
75 | } | |
ef4a9a10 | 76 | return(p2 - buf); |
0d04e87e FT |
77 | break; |
78 | case PHO_EOF: | |
79 | cols[0] = 3; names[0] = _("# users"); | |
80 | cols[1] = 1; names[1] = _("Name"); | |
81 | cols[2] = 2; names[2] = _("Description"); | |
82 | setpubhubmodel(GTK_TREE_MODEL(model), 3, 3, cols, names); | |
83 | break; | |
84 | case PHO_FINI: | |
85 | if(model != NULL) | |
86 | g_object_unref(model); | |
87 | model = NULL; | |
88 | break; | |
89 | } | |
90 | return(0); | |
91 | } |