annotate src/desktopitem.c @ 12213:4e7ba55a1db2

[gaim-migrate @ 14515] Someone was in #gaim the other day having problems with the http method and a proxy server that was mangling the response headers (which is annoying, but legitimate). This should make that work a bit better, although I think that particular user had other problems with that proxy server too. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Thu, 24 Nov 2005 16:04:45 +0000
parents 0f7452b1f777
children f3768fab10bd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /**
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 * @file gaim-desktop-item.c Functions for managing .desktop files
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 * @ingroup core
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4 *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5 * Gaim is the legal property of its developers, whose names are too numerous
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 * source distribution.
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
8 *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 * (at your option) any later version.
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 * GNU General Public License for more details.
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25 /*
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 * The following code has been adapted from gnome-desktop-item.[ch],
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 * as found on gnome-desktop-2.8.1.
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28 *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 * Copyright (C) 2004 by Alceste Scalas <alceste.scalas@gmx.net>.
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 * Original copyright notice:
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 * Copyright (C) 1999, 2000 Red Hat Inc.
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 * Copyright (C) 2001 Sid Vicious
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35 * All rights reserved.
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 * This file is part of the Gnome Library.
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 * The Gnome Library is free software; you can redistribute it and/or
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 * modify it under the terms of the GNU Library General Public License as
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 * published by the Free Software Foundation; either version 2 of the
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 * License, or (at your option) any later version.
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43 *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44 * The Gnome Library is distributed in the hope that it will be useful,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 * Library General Public License for more details.
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 * You should have received a copy of the GNU Library General Public
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 * License along with the Gnome Library; see the file COPYING.LIB. If not,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52 * Boston, MA 02111-1307, USA.
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 #include <errno.h>
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 #include <stdio.h>
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 #include <string.h>
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 #include <time.h>
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 #include "desktopitem.h"
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 #include "internal.h"
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62 struct _GaimDesktopItem {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 int refcount;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 /* all languages used */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 GList *languages;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68 GaimDesktopItemType type;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 /* `modified' means that the ditem has been
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71 * modified since the last save. */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72 gboolean modified;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74 /* Keys of the main section only */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75 GList *keys;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
76
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77 GList *sections;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
79 /* This includes ALL keys, including
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80 * other sections, separated by '/' */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
81 GHashTable *main_hash;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
83 char *location;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
84
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85 time_t mtime;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
86 };
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
88 typedef struct {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
89 char *name;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90 GList *keys;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
91 } Section;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93 typedef enum {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
94 ENCODING_UNKNOWN,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
95 ENCODING_UTF8,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
96 ENCODING_LEGACY_MIXED
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
97 } Encoding;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
99 /**************************************************************************
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
100 * Private utility functions
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
101 **************************************************************************/
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102 static GaimDesktopItemType
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
103 type_from_string (const char *type)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
104 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105 if (!type)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
106 return GAIM_DESKTOP_ITEM_TYPE_NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108 switch (type [0]) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109 case 'A':
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
110 if (!strcmp (type, "Application"))
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111 return GAIM_DESKTOP_ITEM_TYPE_APPLICATION;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 case 'L':
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114 if (!strcmp (type, "Link"))
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115 return GAIM_DESKTOP_ITEM_TYPE_LINK;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 case 'F':
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118 if (!strcmp (type, "FSDevice"))
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 return GAIM_DESKTOP_ITEM_TYPE_FSDEVICE;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121 case 'M':
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122 if (!strcmp (type, "MimeType"))
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 return GAIM_DESKTOP_ITEM_TYPE_MIME_TYPE;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125 case 'D':
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126 if (!strcmp (type, "Directory"))
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
127 return GAIM_DESKTOP_ITEM_TYPE_DIRECTORY;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
129 case 'S':
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130 if (!strcmp (type, "Service"))
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
131 return GAIM_DESKTOP_ITEM_TYPE_SERVICE;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133 else if (!strcmp (type, "ServiceType"))
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134 return GAIM_DESKTOP_ITEM_TYPE_SERVICE_TYPE;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
135 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 default:
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
137 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
139
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 return GAIM_DESKTOP_ITEM_TYPE_OTHER;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143 static Section *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144 find_section (GaimDesktopItem *item, const char *section)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146 GList *li;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
147 Section *sec;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
148
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
149 if (section == NULL)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
150 return NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
151 if (strcmp (section, "Desktop Entry") == 0)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152 return NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154 for (li = item->sections; li != NULL; li = li->next) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
155 sec = li->data;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
156 if (strcmp (sec->name, section) == 0)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157 return sec;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160 sec = g_new0 (Section, 1);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
161 sec->name = g_strdup (section);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
162 sec->keys = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
164 item->sections = g_list_append (item->sections, sec);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
165
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
166 /* Don't mark the item modified, this is just an empty section,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
167 * it won't be saved even */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
168
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
169 return sec;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
170 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
171
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
172 static Section *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
173 section_from_key (GaimDesktopItem *item, const char *key)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175 char *p;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
176 char *name;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177 Section *sec;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
179 if (key == NULL)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
180 return NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
181
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
182 p = strchr (key, '/');
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
183 if (p == NULL)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
184 return NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
185
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
186 name = g_strndup (key, p - key);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
187
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
188 sec = find_section (item, name);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
189
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
190 g_free (name);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
191
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
192 return sec;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
193 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
194
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
195 static const char *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
196 key_basename (const char *key)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
197 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
198 char *p = strrchr (key, '/');
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
199 if (p != NULL)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
200 return p+1;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
201 else
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
202 return key;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
203 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
204
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
205 static void
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
206 set (GaimDesktopItem *item, const char *key, const char *value)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
207 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
208 Section *sec = section_from_key (item, key);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
209
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
210 if (sec != NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
211 if (value != NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
212 if (g_hash_table_lookup (item->main_hash, key) == NULL)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
213 sec->keys = g_list_append
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
214 (sec->keys,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
215 g_strdup (key_basename (key)));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
216
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
217 g_hash_table_replace (item->main_hash,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
218 g_strdup (key),
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
219 g_strdup (value));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
220 } else {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
221 GList *list = g_list_find_custom
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
222 (sec->keys, key_basename (key),
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
223 (GCompareFunc)strcmp);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
224 if (list != NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
225 g_free (list->data);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
226 sec->keys =
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
227 g_list_delete_link (sec->keys, list);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
228 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
229 g_hash_table_remove (item->main_hash, key);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
230 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
231 } else {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
232 if (value != NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
233 if (g_hash_table_lookup (item->main_hash, key) == NULL)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
234 item->keys = g_list_append (item->keys,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
235 g_strdup (key));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
236
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
237 g_hash_table_replace (item->main_hash,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
238 g_strdup (key),
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
239 g_strdup (value));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
240 } else {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
241 GList *list = g_list_find_custom
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
242 (item->keys, key, (GCompareFunc)strcmp);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
243 if (list != NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
244 g_free (list->data);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
245 item->keys =
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
246 g_list_delete_link (item->keys, list);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
247 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
248 g_hash_table_remove (item->main_hash, key);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
249 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
250 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
251 item->modified = TRUE;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
252 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
253
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
254
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
255 static void
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
256 _gaim_desktop_item_set_string (GaimDesktopItem *item,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
257 const char *attr,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
258 const char *value)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
259 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
260 g_return_if_fail (item != NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
261 g_return_if_fail (item->refcount > 0);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
262 g_return_if_fail (attr != NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
263
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
264 set (item, attr, value);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
265
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
266 if (strcmp (attr, GAIM_DESKTOP_ITEM_TYPE) == 0)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
267 item->type = type_from_string (value);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
268 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
269
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
270 static GaimDesktopItem *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
271 _gaim_desktop_item_new (void)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
272 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
273 GaimDesktopItem *retval;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
274
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
275 retval = g_new0 (GaimDesktopItem, 1);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
276
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
277 retval->refcount++;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
278
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
279 retval->main_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
280 (GDestroyNotify) g_free,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
281 (GDestroyNotify) g_free);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
282
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
283 /* These are guaranteed to be set */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
284 _gaim_desktop_item_set_string (retval,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
285 GAIM_DESKTOP_ITEM_NAME,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
286 _("No name"));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
287 _gaim_desktop_item_set_string (retval,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
288 GAIM_DESKTOP_ITEM_ENCODING,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
289 "UTF-8");
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
290 _gaim_desktop_item_set_string (retval,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
291 GAIM_DESKTOP_ITEM_VERSION,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
292 "1.0");
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
293
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
294 return retval;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
295 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
296
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
297 static gpointer
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
298 _gaim_desktop_item_copy (gpointer boxed)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
299 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
300 return gaim_desktop_item_copy (boxed);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
301 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
302
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
303 static void
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
304 _gaim_desktop_item_free (gpointer boxed)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
305 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
306 gaim_desktop_item_unref (boxed);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
307 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
308
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
309 /* Note, does not include the trailing \n */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
310 static char *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
311 my_fgets (char *buf, gsize bufsize, FILE *df)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
312 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
313 int c;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
314 gsize pos;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
315
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
316 g_return_val_if_fail (buf != NULL, NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
317 g_return_val_if_fail (df != NULL, NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
318
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
319 pos = 0;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
320 buf[0] = '\0';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
321
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
322 do {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
323 c = getc (df);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
324 if (c == EOF || c == '\n')
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
325 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
326 buf[pos++] = c;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
327 } while (pos < bufsize-1);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
328
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
329 if (c == EOF && pos == 0)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
330 return NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
331
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
332 buf[pos++] = '\0';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
333
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
334 return buf;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
335 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
336
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
337 static Encoding
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
338 get_encoding (FILE *df)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
339 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
340 gboolean old_kde = FALSE;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
341 char buf [BUFSIZ];
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
342 gboolean all_valid_utf8 = TRUE;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
343
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
344 while (my_fgets (buf, sizeof (buf), df) != NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
345 if (strncmp (GAIM_DESKTOP_ITEM_ENCODING,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
346 buf,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
347 strlen (GAIM_DESKTOP_ITEM_ENCODING)) == 0) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
348 char *p = &buf[strlen (GAIM_DESKTOP_ITEM_ENCODING)];
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
349 if (*p == ' ')
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
350 p++;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
351 if (*p != '=')
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
352 continue;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
353 p++;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
354 if (*p == ' ')
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
355 p++;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
356 if (strcmp (p, "UTF-8") == 0) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
357 return ENCODING_UTF8;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
358 } else if (strcmp (p, "Legacy-Mixed") == 0) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
359 return ENCODING_LEGACY_MIXED;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
360 } else {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
361 /* According to the spec we're not supposed
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
362 * to read a file like this */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
363 return ENCODING_UNKNOWN;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
364 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
365 } else if (strcmp ("[KDE Desktop Entry]", buf) == 0) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
366 old_kde = TRUE;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
367 /* don't break yet, we still want to support
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
368 * Encoding even here */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
369 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
370 if (all_valid_utf8 && ! g_utf8_validate (buf, -1, NULL))
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
371 all_valid_utf8 = FALSE;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
372 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
373
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
374 if (old_kde)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
375 return ENCODING_LEGACY_MIXED;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
376
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
377 /* A dilemma, new KDE files are in UTF-8 but have no Encoding
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
378 * info, at this time we really can't tell. The best thing to
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
379 * do right now is to just assume UTF-8 if the whole file
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
380 * validates as utf8 I suppose */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
381
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
382 if (all_valid_utf8)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
383 return ENCODING_UTF8;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
384 else
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
385 return ENCODING_LEGACY_MIXED;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
386 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
387
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
388 static char *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
389 snarf_locale_from_key (const char *key)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
390 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
391 const char *brace;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
392 char *locale, *p;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
393
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
394 brace = strchr (key, '[');
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
395 if (brace == NULL)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
396 return NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
397
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
398 locale = g_strdup (brace + 1);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
399 if (*locale == '\0') {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
400 g_free (locale);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
401 return NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
402 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
403 p = strchr (locale, ']');
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
404 if (p == NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
405 g_free (locale);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
406 return NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
407 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
408 *p = '\0';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
409 return locale;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
410 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
411
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
412 static gboolean
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
413 check_locale (const char *locale)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
414 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
415 GIConv cd = g_iconv_open ("UTF-8", locale);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
416 if ((GIConv)-1 == cd)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
417 return FALSE;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
418 g_iconv_close (cd);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
419 return TRUE;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
420 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
421
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
422 static void
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
423 insert_locales (GHashTable *encodings, char *enc, ...)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
424 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
425 va_list args;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
426 char *s;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
427
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
428 va_start (args, enc);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
429 for (;;) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
430 s = va_arg (args, char *);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
431 if (s == NULL)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
432 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
433 g_hash_table_insert (encodings, s, enc);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
434 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
435 va_end (args);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
436 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
437
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
438 /* make a standard conversion table from the desktop standard spec */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
439 static GHashTable *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
440 init_encodings (void)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
441 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
442 GHashTable *encodings = g_hash_table_new (g_str_hash, g_str_equal);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
443
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
444 /* "C" is plain ascii */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
445 insert_locales (encodings, "ASCII", "C", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
446
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
447 insert_locales (encodings, "ARMSCII-8", "by", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
448 insert_locales (encodings, "BIG5", "zh_TW", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
449 insert_locales (encodings, "CP1251", "be", "bg", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
450 if (check_locale ("EUC-CN")) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
451 insert_locales (encodings, "EUC-CN", "zh_CN", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
452 } else {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
453 insert_locales (encodings, "GB2312", "zh_CN", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
454 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
455 insert_locales (encodings, "EUC-JP", "ja", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
456 insert_locales (encodings, "EUC-KR", "ko", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
457 /*insert_locales (encodings, "GEORGIAN-ACADEMY", NULL);*/
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
458 insert_locales (encodings, "GEORGIAN-PS", "ka", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
459 insert_locales (encodings, "ISO-8859-1", "br", "ca", "da", "de", "en", "es", "eu", "fi", "fr", "gl", "it", "nl", "wa", "no", "pt", "pt", "sv", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
460 insert_locales (encodings, "ISO-8859-2", "cs", "hr", "hu", "pl", "ro", "sk", "sl", "sq", "sr", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
461 insert_locales (encodings, "ISO-8859-3", "eo", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
462 insert_locales (encodings, "ISO-8859-5", "mk", "sp", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
463 insert_locales (encodings, "ISO-8859-7", "el", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
464 insert_locales (encodings, "ISO-8859-9", "tr", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
465 insert_locales (encodings, "ISO-8859-13", "lt", "lv", "mi", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
466 insert_locales (encodings, "ISO-8859-14", "ga", "cy", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
467 insert_locales (encodings, "ISO-8859-15", "et", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
468 insert_locales (encodings, "KOI8-R", "ru", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
469 insert_locales (encodings, "KOI8-U", "uk", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
470 if (check_locale ("TCVN-5712")) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
471 insert_locales (encodings, "TCVN-5712", "vi", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
472 } else {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
473 insert_locales (encodings, "TCVN", "vi", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
474 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
475 insert_locales (encodings, "TIS-620", "th", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
476 /*insert_locales (encodings, "VISCII", NULL);*/
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
477
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
478 return encodings;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
479 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
480
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
481 static const char *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
482 get_encoding_from_locale (const char *locale)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
483 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
484 char lang[3];
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
485 const char *encoding;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
486 static GHashTable *encodings = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
487
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
488 if (locale == NULL)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
489 return NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
490
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
491 /* if locale includes encoding, use it */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
492 encoding = strchr (locale, '.');
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
493 if (encoding != NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
494 return encoding+1;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
495 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
496
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
497 if (encodings == NULL)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
498 encodings = init_encodings ();
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
499
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
500 /* first try the entire locale (at this point ll_CC) */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
501 encoding = g_hash_table_lookup (encodings, locale);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
502 if (encoding != NULL)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
503 return encoding;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
504
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
505 /* Try just the language */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
506 strncpy (lang, locale, 2);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
507 lang[2] = '\0';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
508 return g_hash_table_lookup (encodings, lang);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
509 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
510
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
511 static char *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
512 decode_string_and_dup (const char *s)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
513 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
514 char *p = g_malloc (strlen (s) + 1);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
515 char *q = p;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
516
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
517 do {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
518 if (*s == '\\'){
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
519 switch (*(++s)){
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
520 case 's':
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
521 *p++ = ' ';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
522 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
523 case 't':
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
524 *p++ = '\t';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
525 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
526 case 'n':
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
527 *p++ = '\n';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
528 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
529 case '\\':
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
530 *p++ = '\\';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
531 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
532 case 'r':
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
533 *p++ = '\r';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
534 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
535 default:
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
536 *p++ = '\\';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
537 *p++ = *s;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
538 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
539 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
540 } else {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
541 *p++ = *s;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
542 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
543 } while (*s++);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
544
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
545 return q;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
546 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
547
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
548 static char *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
549 decode_string (const char *value, Encoding encoding, const char *locale)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
550 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
551 char *retval = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
552
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
553 /* if legacy mixed, then convert */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
554 if (locale != NULL && encoding == ENCODING_LEGACY_MIXED) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
555 const char *char_encoding = get_encoding_from_locale (locale);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
556 char *utf8_string;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
557 if (char_encoding == NULL)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
558 return NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
559 if (strcmp (char_encoding, "ASCII") == 0) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
560 return decode_string_and_dup (value);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
561 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
562 utf8_string = g_convert (value, -1, "UTF-8", char_encoding,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
563 NULL, NULL, NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
564 if (utf8_string == NULL)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
565 return NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
566 retval = decode_string_and_dup (utf8_string);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
567 g_free (utf8_string);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
568 return retval;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
569 /* if utf8, then validate */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
570 } else if (locale != NULL && encoding == ENCODING_UTF8) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
571 if ( ! g_utf8_validate (value, -1, NULL))
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
572 /* invalid utf8, ignore this key */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
573 return NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
574 return decode_string_and_dup (value);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
575 } else {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
576 /* Meaning this is not a localized string */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
577 return decode_string_and_dup (value);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
578 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
579 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
580
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
581 /************************************************************
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
582 * Parser: *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
583 ************************************************************/
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
584
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
585 static gboolean G_GNUC_CONST
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
586 standard_is_boolean (const char * key)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
587 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
588 static GHashTable *bools = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
589
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
590 if (bools == NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
591 bools = g_hash_table_new (g_str_hash, g_str_equal);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
592 g_hash_table_insert (bools,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
593 GAIM_DESKTOP_ITEM_NO_DISPLAY,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
594 GAIM_DESKTOP_ITEM_NO_DISPLAY);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
595 g_hash_table_insert (bools,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
596 GAIM_DESKTOP_ITEM_HIDDEN,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
597 GAIM_DESKTOP_ITEM_HIDDEN);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
598 g_hash_table_insert (bools,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
599 GAIM_DESKTOP_ITEM_TERMINAL,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
600 GAIM_DESKTOP_ITEM_TERMINAL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
601 g_hash_table_insert (bools,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
602 GAIM_DESKTOP_ITEM_READ_ONLY,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
603 GAIM_DESKTOP_ITEM_READ_ONLY);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
604 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
605
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
606 return g_hash_table_lookup (bools, key) != NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
607 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
608
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
609 static gboolean G_GNUC_CONST
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
610 standard_is_strings (const char *key)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
611 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
612 static GHashTable *strings = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
613
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
614 if (strings == NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
615 strings = g_hash_table_new (g_str_hash, g_str_equal);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
616 g_hash_table_insert (strings,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
617 GAIM_DESKTOP_ITEM_FILE_PATTERN,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
618 GAIM_DESKTOP_ITEM_FILE_PATTERN);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
619 g_hash_table_insert (strings,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
620 GAIM_DESKTOP_ITEM_ACTIONS,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
621 GAIM_DESKTOP_ITEM_ACTIONS);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
622 g_hash_table_insert (strings,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
623 GAIM_DESKTOP_ITEM_MIME_TYPE,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
624 GAIM_DESKTOP_ITEM_MIME_TYPE);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
625 g_hash_table_insert (strings,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
626 GAIM_DESKTOP_ITEM_PATTERNS,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
627 GAIM_DESKTOP_ITEM_PATTERNS);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
628 g_hash_table_insert (strings,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
629 GAIM_DESKTOP_ITEM_SORT_ORDER,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
630 GAIM_DESKTOP_ITEM_SORT_ORDER);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
631 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
632
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
633 return g_hash_table_lookup (strings, key) != NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
634 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
635
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
636 /* If no need to cannonize, returns NULL */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
637 static char *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
638 cannonize (const char *key, const char *value)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
639 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
640 if (standard_is_boolean (key)) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
641 if (value[0] == 'T' ||
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
642 value[0] == 't' ||
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
643 value[0] == 'Y' ||
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
644 value[0] == 'y' ||
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
645 atoi (value) != 0) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
646 return g_strdup ("true");
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
647 } else {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
648 return g_strdup ("false");
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
649 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
650 } else if (standard_is_strings (key)) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
651 int len = strlen (value);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
652 if (len == 0 || value[len-1] != ';') {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
653 return g_strconcat (value, ";", NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
654 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
655 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
656 /* XXX: Perhaps we should canonize numeric values as well, but this
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
657 * has caused some subtle problems before so it needs to be done
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
658 * carefully if at all */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
659 return NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
660 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
661
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
662 static void
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
663 insert_key (GaimDesktopItem *item,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
664 Section *cur_section,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
665 Encoding encoding,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
666 const char *key,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
667 const char *value,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
668 gboolean old_kde,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
669 gboolean no_translations)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
670 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
671 char *k;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
672 char *val;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
673 /* we always store everything in UTF-8 */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
674 if (cur_section == NULL &&
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
675 strcmp (key, GAIM_DESKTOP_ITEM_ENCODING) == 0) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
676 k = g_strdup (key);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
677 val = g_strdup ("UTF-8");
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
678 } else {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
679 char *locale = snarf_locale_from_key (key);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
680 /* If we're ignoring translations */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
681 if (no_translations && locale != NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
682 g_free (locale);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
683 return;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
684 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
685 val = decode_string (value, encoding, locale);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
686
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
687 /* Ignore this key, it's whacked */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
688 if (val == NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
689 g_free (locale);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
690 return;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
691 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
692
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
693 g_strchomp (val);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
694
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
695 /* For old KDE entries, we can also split by a comma
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
696 * on sort order, so convert to semicolons */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
697 if (old_kde &&
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
698 cur_section == NULL &&
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
699 strcmp (key, GAIM_DESKTOP_ITEM_SORT_ORDER) == 0 &&
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
700 strchr (val, ';') == NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
701 int i;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
702 for (i = 0; val[i] != '\0'; i++) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
703 if (val[i] == ',')
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
704 val[i] = ';';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
705 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
706 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
707
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
708 /* Check some types, not perfect, but catches a lot
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
709 * of things */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
710 if (cur_section == NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
711 char *cannon = cannonize (key, val);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
712 if (cannon != NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
713 g_free (val);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
714 val = cannon;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
715 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
716 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
717
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
718 k = g_strdup (key);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
719
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
720 /* Take care of the language part */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
721 if (locale != NULL &&
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
722 strcmp (locale, "C") == 0) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
723 char *p;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
724 /* Whack C locale */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
725 p = strchr (k, '[');
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
726 *p = '\0';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
727 g_free (locale);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
728 } else if (locale != NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
729 char *p, *brace;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
730
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
731 /* Whack the encoding part */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
732 p = strchr (locale, '.');
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
733 if (p != NULL)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
734 *p = '\0';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
735
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
736 if (g_list_find_custom (item->languages, locale,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
737 (GCompareFunc)strcmp) == NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
738 item->languages = g_list_prepend
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
739 (item->languages, locale);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
740 } else {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
741 g_free (locale);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
742 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
743
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
744 /* Whack encoding from encoding in the key */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
745 brace = strchr (k, '[');
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
746 p = strchr (brace, '.');
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
747 if (p != NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
748 *p = ']';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
749 *(p+1) = '\0';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
750 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
751 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
752 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
753
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
754
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
755 if (cur_section == NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
756 /* only add to list if we haven't seen it before */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
757 if (g_hash_table_lookup (item->main_hash, k) == NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
758 item->keys = g_list_prepend (item->keys,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
759 g_strdup (k));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
760 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
761 /* later duplicates override earlier ones */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
762 g_hash_table_replace (item->main_hash, k, val);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
763 } else {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
764 char *full = g_strdup_printf
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
765 ("%s/%s",
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
766 cur_section->name, k);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
767 /* only add to list if we haven't seen it before */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
768 if (g_hash_table_lookup (item->main_hash, full) == NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
769 cur_section->keys =
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
770 g_list_prepend (cur_section->keys, k);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
771 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
772 /* later duplicates override earlier ones */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
773 g_hash_table_replace (item->main_hash,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
774 full, val);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
775 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
776 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
777
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
778 static const char *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
779 lookup (const GaimDesktopItem *item, const char *key)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
780 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
781 return g_hash_table_lookup (item->main_hash, key);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
782 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
783
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
784 static void
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
785 setup_type (GaimDesktopItem *item, const char *uri)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
786 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
787 const char *type = g_hash_table_lookup (item->main_hash,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
788 GAIM_DESKTOP_ITEM_TYPE);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
789 if (type == NULL && uri != NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
790 char *base = g_path_get_basename (uri);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
791 if (base != NULL &&
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
792 strcmp (base, ".directory") == 0) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
793 /* This gotta be a directory */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
794 g_hash_table_replace (item->main_hash,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
795 g_strdup (GAIM_DESKTOP_ITEM_TYPE),
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
796 g_strdup ("Directory"));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
797 item->keys = g_list_prepend
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
798 (item->keys, g_strdup (GAIM_DESKTOP_ITEM_TYPE));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
799 item->type = GAIM_DESKTOP_ITEM_TYPE_DIRECTORY;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
800 } else {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
801 item->type = GAIM_DESKTOP_ITEM_TYPE_NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
802 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
803 g_free (base);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
804 } else {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
805 item->type = type_from_string (type);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
806 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
807 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
808
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
809 static const char *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
810 lookup_locale (const GaimDesktopItem *item, const char *key, const char *locale)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
811 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
812 if (locale == NULL ||
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
813 strcmp (locale, "C") == 0) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
814 return lookup (item, key);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
815 } else {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
816 const char *ret;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
817 char *full = g_strdup_printf ("%s[%s]", key, locale);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
818 ret = lookup (item, full);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
819 g_free (full);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
820 return ret;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
821 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
822 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
823
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
824 /* fallback to find something suitable for C locale */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
825 static char *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
826 try_english_key (GaimDesktopItem *item, const char *key)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
827 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
828 char *str;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
829 char *locales[] = { "en_US", "en_GB", "en_AU", "en", NULL };
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
830 int i;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
831
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
832 str = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
833 for (i = 0; locales[i] != NULL && str == NULL; i++) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
834 str = g_strdup (lookup_locale (item, key, locales[i]));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
835 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
836 if (str != NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
837 /* We need a 7-bit ascii string, so whack all
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
838 * above 127 chars */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
839 guchar *p;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
840 for (p = (guchar *)str; *p != '\0'; p++) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
841 if (*p > 127)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
842 *p = '?';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
843 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
844 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
845 return str;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
846 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
847
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
848
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
849 static void
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
850 sanitize (GaimDesktopItem *item, const char *uri)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
851 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
852 const char *type;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
853
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
854 type = lookup (item, GAIM_DESKTOP_ITEM_TYPE);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
855
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
856 /* understand old gnome style url exec thingies */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
857 if (type != NULL && strcmp (type, "URL") == 0) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
858 const char *exec = lookup (item, GAIM_DESKTOP_ITEM_EXEC);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
859 set (item, GAIM_DESKTOP_ITEM_TYPE, "Link");
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
860 if (exec != NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
861 /* Note, this must be in this order */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
862 set (item, GAIM_DESKTOP_ITEM_URL, exec);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
863 set (item, GAIM_DESKTOP_ITEM_EXEC, NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
864 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
865 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
866
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
867 /* we make sure we have Name, Encoding and Version */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
868 if (lookup (item, GAIM_DESKTOP_ITEM_NAME) == NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
869 char *name = try_english_key (item, GAIM_DESKTOP_ITEM_NAME);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
870 /* If no name, use the basename */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
871 if (name == NULL && uri != NULL)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
872 name = g_path_get_basename (uri);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
873 /* If no uri either, use same default as gnome_desktop_item_new */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
874 if (name == NULL)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
875 name = g_strdup (_("No name"));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
876 g_hash_table_replace (item->main_hash,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
877 g_strdup (GAIM_DESKTOP_ITEM_NAME),
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
878 name);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
879 item->keys = g_list_prepend
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
880 (item->keys, g_strdup (GAIM_DESKTOP_ITEM_NAME));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
881 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
882 if (lookup (item, GAIM_DESKTOP_ITEM_ENCODING) == NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
883 /* We store everything in UTF-8 so write that down */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
884 g_hash_table_replace (item->main_hash,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
885 g_strdup (GAIM_DESKTOP_ITEM_ENCODING),
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
886 g_strdup ("UTF-8"));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
887 item->keys = g_list_prepend
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
888 (item->keys, g_strdup (GAIM_DESKTOP_ITEM_ENCODING));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
889 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
890 if (lookup (item, GAIM_DESKTOP_ITEM_VERSION) == NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
891 /* this is the version that we follow, so write it down */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
892 g_hash_table_replace (item->main_hash,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
893 g_strdup (GAIM_DESKTOP_ITEM_VERSION),
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
894 g_strdup ("1.0"));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
895 item->keys = g_list_prepend
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
896 (item->keys, g_strdup (GAIM_DESKTOP_ITEM_VERSION));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
897 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
898 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
899
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
900 enum {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
901 FirstBrace,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
902 OnSecHeader,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
903 IgnoreToEOL,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
904 IgnoreToEOLFirst,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
905 KeyDef,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
906 KeyDefOnKey,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
907 KeyValue
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
908 };
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
909
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
910 static GaimDesktopItem *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
911 ditem_load (FILE *df,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
912 gboolean no_translations,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
913 const char *uri)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
914 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
915 int state;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
916 char CharBuffer [1024];
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
917 char *next = CharBuffer;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
918 int c;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
919 Encoding encoding;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
920 GaimDesktopItem *item;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
921 Section *cur_section = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
922 char *key = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
923 gboolean old_kde = FALSE;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
924
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
925 encoding = get_encoding (df);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
926 if (encoding == ENCODING_UNKNOWN) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
927 fclose(df);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
928 /* spec says, don't read this file */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
929 printf ("Unknown encoding of .desktop file");
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
930
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
931 return NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
932 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
933
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
934 /* Rewind since get_encoding goes through the file */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
935 if (fseek(df, 0L, SEEK_SET)) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
936 fclose(df);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
937 /* spec says, don't read this file */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
938 printf ("fseek() error on .desktop file");
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
939 return NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
940 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
941
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
942 item = _gaim_desktop_item_new ();
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
943 item->modified = FALSE;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
944
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
945 /* Note: location and mtime are filled in by the new_from_file
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
946 * function since it has those values */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
947
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
948 #define GAIM_DESKTOP_ITEM_OVERFLOW (next == &CharBuffer [sizeof(CharBuffer)-1])
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
949
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
950 state = FirstBrace;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
951 while ((c = getc (df)) != EOF) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
952 if (c == '\r') /* Ignore Carriage Return */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
953 continue;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
954
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
955 switch (state) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
956
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
957 case OnSecHeader:
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
958 if (c == ']' || GAIM_DESKTOP_ITEM_OVERFLOW) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
959 *next = '\0';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
960 next = CharBuffer;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
961
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
962 /* keys were inserted in reverse */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
963 if (cur_section != NULL &&
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
964 cur_section->keys != NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
965 cur_section->keys = g_list_reverse
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
966 (cur_section->keys);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
967 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
968 if (strcmp (CharBuffer,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
969 "KDE Desktop Entry") == 0) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
970 /* Main section */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
971 cur_section = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
972 old_kde = TRUE;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
973 } else if (strcmp (CharBuffer,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
974 "Desktop Entry") == 0) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
975 /* Main section */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
976 cur_section = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
977 } else {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
978 cur_section = g_new0 (Section, 1);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
979 cur_section->name =
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
980 g_strdup (CharBuffer);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
981 cur_section->keys = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
982 item->sections = g_list_prepend
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
983 (item->sections, cur_section);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
984 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
985 state = IgnoreToEOL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
986 } else if (c == '[') {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
987 /* FIXME: probably error out instead of ignoring this */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
988 } else {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
989 *next++ = c;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
990 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
991 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
992
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
993 case IgnoreToEOL:
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
994 case IgnoreToEOLFirst:
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
995 if (c == '\n'){
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
996 if (state == IgnoreToEOLFirst)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
997 state = FirstBrace;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
998 else
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
999 state = KeyDef;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1000 next = CharBuffer;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1001 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1002 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1003
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1004 case FirstBrace:
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1005 case KeyDef:
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1006 case KeyDefOnKey:
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1007 if (c == '#') {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1008 if (state == FirstBrace)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1009 state = IgnoreToEOLFirst;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1010 else
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1011 state = IgnoreToEOL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1012 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1013 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1014
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1015 if (c == '[' && state != KeyDefOnKey){
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1016 state = OnSecHeader;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1017 next = CharBuffer;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1018 g_free (key);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1019 key = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1020 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1021 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1022 /* On first pass, don't allow dangling keys */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1023 if (state == FirstBrace)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1024 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1025
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1026 if ((c == ' ' && state != KeyDefOnKey) || c == '\t')
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1027 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1028
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1029 if (c == '\n' || GAIM_DESKTOP_ITEM_OVERFLOW) { /* Abort Definition */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1030 next = CharBuffer;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1031 state = KeyDef;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1032 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1033 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1034
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1035 if (c == '=' || GAIM_DESKTOP_ITEM_OVERFLOW){
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1036 *next = '\0';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1037
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1038 g_free (key);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1039 key = g_strdup (CharBuffer);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1040 state = KeyValue;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1041 next = CharBuffer;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1042 } else {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1043 *next++ = c;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1044 state = KeyDefOnKey;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1045 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1046 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1047
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1048 case KeyValue:
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1049 if (GAIM_DESKTOP_ITEM_OVERFLOW || c == '\n'){
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1050 *next = '\0';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1051
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1052 insert_key (item, cur_section, encoding,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1053 key, CharBuffer, old_kde,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1054 no_translations);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1055
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1056 g_free (key);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1057 key = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1058
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1059 state = (c == '\n') ? KeyDef : IgnoreToEOL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1060 next = CharBuffer;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1061 } else {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1062 *next++ = c;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1063 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1064 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1065
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1066 } /* switch */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1067
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1068 } /* while ((c = getc_unlocked (f)) != EOF) */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1069 if (c == EOF && state == KeyValue) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1070 *next = '\0';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1071
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1072 insert_key (item, cur_section, encoding,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1073 key, CharBuffer, old_kde,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1074 no_translations);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1075
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1076 g_free (key);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1077 key = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1078 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1079
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1080 #undef GAIM_DESKTOP_ITEM_OVERFLOW
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1081
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1082 /* keys were inserted in reverse */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1083 if (cur_section != NULL &&
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1084 cur_section->keys != NULL) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1085 cur_section->keys = g_list_reverse (cur_section->keys);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1086 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1087 /* keys were inserted in reverse */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1088 item->keys = g_list_reverse (item->keys);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1089 /* sections were inserted in reverse */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1090 item->sections = g_list_reverse (item->sections);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1091
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1092 /* sanitize some things */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1093 sanitize (item, uri);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1094
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1095 /* make sure that we set up the type */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1096 setup_type (item, uri);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1097
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1098 fclose (df);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1099
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1100 return item;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1101 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1102
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1103 static void
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1104 copy_string_hash (gpointer key, gpointer value, gpointer user_data)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1105 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1106 GHashTable *copy = user_data;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1107 g_hash_table_replace (copy,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1108 g_strdup (key),
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1109 g_strdup (value));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1110 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1111
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1112 static void
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1113 free_section (gpointer data, gpointer user_data)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1114 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1115 Section *section = data;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1116
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1117 g_free (section->name);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1118 section->name = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1119
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1120 g_list_foreach (section->keys, (GFunc)g_free, NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1121 g_list_free (section->keys);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1122 section->keys = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1123
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1124 g_free (section);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1125 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1126
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1127 static Section *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1128 dup_section (Section *sec)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1129 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1130 GList *li;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1131 Section *retval = g_new0 (Section, 1);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1132
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1133 retval->name = g_strdup (sec->name);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1134
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1135 retval->keys = g_list_copy (sec->keys);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1136 for (li = retval->keys; li != NULL; li = li->next)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1137 li->data = g_strdup (li->data);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1138
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1139 return retval;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1140 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1141
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1142 /**************************************************************************
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1143 * Public functions
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1144 **************************************************************************/
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1145 GaimDesktopItem *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1146 gaim_desktop_item_new_from_file (const char *filename)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1147 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1148 GaimDesktopItem *retval;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1149 FILE *dfile;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1150
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1151 g_return_val_if_fail (filename != NULL, NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1152
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10229
diff changeset
1153 dfile = g_fopen(filename, "r");
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1154 if (!dfile) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1155 printf ("Can't open %s: %s", filename, strerror(errno));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1156 return NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1157 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1158
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1159 retval = ditem_load(dfile, FALSE, filename);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1160
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1161 return retval;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1162 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1163
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1164 GaimDesktopItemType
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1165 gaim_desktop_item_get_entry_type (const GaimDesktopItem *item)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1166 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1167 g_return_val_if_fail (item != NULL, 0);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1168 g_return_val_if_fail (item->refcount > 0, 0);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1169
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1170 return item->type;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1171 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1172
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1173 const char *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1174 gaim_desktop_item_get_string (const GaimDesktopItem *item,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1175 const char *attr)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1176 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1177 g_return_val_if_fail (item != NULL, NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1178 g_return_val_if_fail (item->refcount > 0, NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1179 g_return_val_if_fail (attr != NULL, NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1180
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1181 return lookup (item, attr);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1182 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1183
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1184 GaimDesktopItem *
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1185 gaim_desktop_item_copy (const GaimDesktopItem *item)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1186 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1187 GList *li;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1188 GaimDesktopItem *retval;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1189
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1190 g_return_val_if_fail (item != NULL, NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1191 g_return_val_if_fail (item->refcount > 0, NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1192
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1193 retval = _gaim_desktop_item_new ();
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1194
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1195 retval->type = item->type;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1196 retval->modified = item->modified;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1197 retval->location = g_strdup (item->location);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1198 retval->mtime = item->mtime;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1199
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1200 /* Languages */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1201 retval->languages = g_list_copy (item->languages);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1202 for (li = retval->languages; li != NULL; li = li->next)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1203 li->data = g_strdup (li->data);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1204
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1205 /* Keys */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1206 retval->keys = g_list_copy (item->keys);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1207 for (li = retval->keys; li != NULL; li = li->next)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1208 li->data = g_strdup (li->data);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1209
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1210 /* Sections */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1211 retval->sections = g_list_copy (item->sections);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1212 for (li = retval->sections; li != NULL; li = li->next)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1213 li->data = dup_section (li->data);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1214
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1215 retval->main_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1216 (GDestroyNotify) g_free,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1217 (GDestroyNotify) g_free);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1218
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1219 g_hash_table_foreach (item->main_hash,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1220 copy_string_hash,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1221 retval->main_hash);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1222
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1223 return retval;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1224 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1225
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1226 void
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1227 gaim_desktop_item_unref (GaimDesktopItem *item)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1228 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1229 g_return_if_fail (item != NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1230 g_return_if_fail (item->refcount > 0);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1231
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1232 item->refcount--;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1233
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1234 if(item->refcount != 0)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1235 return;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1236
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1237 g_list_foreach (item->languages, (GFunc)g_free, NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1238 g_list_free (item->languages);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1239 item->languages = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1240
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1241 g_list_foreach (item->keys, (GFunc)g_free, NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1242 g_list_free (item->keys);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1243 item->keys = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1244
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1245 g_list_foreach (item->sections, free_section, NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1246 g_list_free (item->sections);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1247 item->sections = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1248
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1249 g_hash_table_destroy (item->main_hash);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1250 item->main_hash = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1251
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1252 g_free (item->location);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1253 item->location = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1254
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1255 g_free (item);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1256 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1257
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1258 GType
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1259 gaim_desktop_item_get_type (void)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1260 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1261 static GType type = 0;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1262
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1263 if (type == 0) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1264 type = g_boxed_type_register_static ("GaimDesktopItem",
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1265 _gaim_desktop_item_copy,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1266 _gaim_desktop_item_free);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1267 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1268
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1269 return type;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1270 }