comparison libpurple/desktopitem.c @ 25918:bc8d1607f9b8

propagate from branch 'im.pidgin.pidgin' (head 566d2e86bfd45c806aba1b32d6f85a9a409ff9ea) to branch 'im.pidgin.pidgin.next.minor' (head ffd76856f93610f7cd6178e943d0b61e4220b549)
author Richard Laager <rlaager@wiktel.com>
date Mon, 26 Jan 2009 02:39:55 +0000
parents a6e3cb32cdd2
children 584063555949
comparison
equal deleted inserted replaced
25372:a8db457c421a 25918:bc8d1607f9b8
106 if (!type) 106 if (!type)
107 return PURPLE_DESKTOP_ITEM_TYPE_NULL; 107 return PURPLE_DESKTOP_ITEM_TYPE_NULL;
108 108
109 switch (type [0]) { 109 switch (type [0]) {
110 case 'A': 110 case 'A':
111 if (!strcmp (type, "Application")) 111 if (purple_strequal (type, "Application"))
112 return PURPLE_DESKTOP_ITEM_TYPE_APPLICATION; 112 return PURPLE_DESKTOP_ITEM_TYPE_APPLICATION;
113 break; 113 break;
114 case 'L': 114 case 'L':
115 if (!strcmp (type, "Link")) 115 if (purple_strequal (type, "Link"))
116 return PURPLE_DESKTOP_ITEM_TYPE_LINK; 116 return PURPLE_DESKTOP_ITEM_TYPE_LINK;
117 break; 117 break;
118 case 'F': 118 case 'F':
119 if (!strcmp (type, "FSDevice")) 119 if (purple_strequal (type, "FSDevice"))
120 return PURPLE_DESKTOP_ITEM_TYPE_FSDEVICE; 120 return PURPLE_DESKTOP_ITEM_TYPE_FSDEVICE;
121 break; 121 break;
122 case 'M': 122 case 'M':
123 if (!strcmp (type, "MimeType")) 123 if (purple_strequal (type, "MimeType"))
124 return PURPLE_DESKTOP_ITEM_TYPE_MIME_TYPE; 124 return PURPLE_DESKTOP_ITEM_TYPE_MIME_TYPE;
125 break; 125 break;
126 case 'D': 126 case 'D':
127 if (!strcmp (type, "Directory")) 127 if (purple_strequal (type, "Directory"))
128 return PURPLE_DESKTOP_ITEM_TYPE_DIRECTORY; 128 return PURPLE_DESKTOP_ITEM_TYPE_DIRECTORY;
129 break; 129 break;
130 case 'S': 130 case 'S':
131 if (!strcmp (type, "Service")) 131 if (purple_strequal (type, "Service"))
132 return PURPLE_DESKTOP_ITEM_TYPE_SERVICE; 132 return PURPLE_DESKTOP_ITEM_TYPE_SERVICE;
133 133
134 else if (!strcmp (type, "ServiceType")) 134 else if (purple_strequal (type, "ServiceType"))
135 return PURPLE_DESKTOP_ITEM_TYPE_SERVICE_TYPE; 135 return PURPLE_DESKTOP_ITEM_TYPE_SERVICE_TYPE;
136 break; 136 break;
137 default: 137 default:
138 break; 138 break;
139 } 139 }
147 GList *li; 147 GList *li;
148 Section *sec; 148 Section *sec;
149 149
150 if (section == NULL) 150 if (section == NULL)
151 return NULL; 151 return NULL;
152 if (strcmp (section, "Desktop Entry") == 0) 152 if (purple_strequal (section, "Desktop Entry"))
153 return NULL; 153 return NULL;
154 154
155 for (li = item->sections; li != NULL; li = li->next) { 155 for (li = item->sections; li != NULL; li = li->next) {
156 sec = li->data; 156 sec = li->data;
157 if (strcmp (sec->name, section) == 0) 157 if (purple_strequal (sec->name, section))
158 return sec; 158 return sec;
159 } 159 }
160 160
161 sec = g_new0 (Section, 1); 161 sec = g_new0 (Section, 1);
162 sec->name = g_strdup (section); 162 sec->name = g_strdup (section);
262 g_return_if_fail (item->refcount > 0); 262 g_return_if_fail (item->refcount > 0);
263 g_return_if_fail (attr != NULL); 263 g_return_if_fail (attr != NULL);
264 264
265 set (item, attr, value); 265 set (item, attr, value);
266 266
267 if (strcmp (attr, PURPLE_DESKTOP_ITEM_TYPE) == 0) 267 if (purple_strequal (attr, PURPLE_DESKTOP_ITEM_TYPE))
268 item->type = type_from_string (value); 268 item->type = type_from_string (value);
269 } 269 }
270 270
271 static PurpleDesktopItem * 271 static PurpleDesktopItem *
272 _purple_desktop_item_new (void) 272 _purple_desktop_item_new (void)
352 if (*p != '=') 352 if (*p != '=')
353 continue; 353 continue;
354 p++; 354 p++;
355 if (*p == ' ') 355 if (*p == ' ')
356 p++; 356 p++;
357 if (strcmp (p, "UTF-8") == 0) { 357 if (purple_strequal (p, "UTF-8")) {
358 return ENCODING_UTF8; 358 return ENCODING_UTF8;
359 } else if (strcmp (p, "Legacy-Mixed") == 0) { 359 } else if (purple_strequal (p, "Legacy-Mixed")) {
360 return ENCODING_LEGACY_MIXED; 360 return ENCODING_LEGACY_MIXED;
361 } else { 361 } else {
362 /* According to the spec we're not supposed 362 /* According to the spec we're not supposed
363 * to read a file like this */ 363 * to read a file like this */
364 return ENCODING_UNKNOWN; 364 return ENCODING_UNKNOWN;
365 } 365 }
366 } else if (strcmp ("[KDE Desktop Entry]", buf) == 0) { 366 } else if (purple_strequal ("[KDE Desktop Entry]", buf)) {
367 old_kde = TRUE; 367 old_kde = TRUE;
368 /* don't break yet, we still want to support 368 /* don't break yet, we still want to support
369 * Encoding even here */ 369 * Encoding even here */
370 } 370 }
371 if (all_valid_utf8 && ! g_utf8_validate (buf, -1, NULL)) 371 if (all_valid_utf8 && ! g_utf8_validate (buf, -1, NULL))
555 if (locale != NULL && encoding == ENCODING_LEGACY_MIXED) { 555 if (locale != NULL && encoding == ENCODING_LEGACY_MIXED) {
556 const char *char_encoding = get_encoding_from_locale (locale); 556 const char *char_encoding = get_encoding_from_locale (locale);
557 char *utf8_string; 557 char *utf8_string;
558 if (char_encoding == NULL) 558 if (char_encoding == NULL)
559 return NULL; 559 return NULL;
560 if (strcmp (char_encoding, "ASCII") == 0) { 560 if (purple_strequal (char_encoding, "ASCII")) {
561 return decode_string_and_dup (value); 561 return decode_string_and_dup (value);
562 } 562 }
563 utf8_string = g_convert (value, -1, "UTF-8", char_encoding, 563 utf8_string = g_convert (value, -1, "UTF-8", char_encoding,
564 NULL, NULL, NULL); 564 NULL, NULL, NULL);
565 if (utf8_string == NULL) 565 if (utf8_string == NULL)
671 { 671 {
672 char *k; 672 char *k;
673 char *val; 673 char *val;
674 /* we always store everything in UTF-8 */ 674 /* we always store everything in UTF-8 */
675 if (cur_section == NULL && 675 if (cur_section == NULL &&
676 strcmp (key, PURPLE_DESKTOP_ITEM_ENCODING) == 0) { 676 purple_strequal (key, PURPLE_DESKTOP_ITEM_ENCODING)) {
677 k = g_strdup (key); 677 k = g_strdup (key);
678 val = g_strdup ("UTF-8"); 678 val = g_strdup ("UTF-8");
679 } else { 679 } else {
680 char *locale = snarf_locale_from_key (key); 680 char *locale = snarf_locale_from_key (key);
681 /* If we're ignoring translations */ 681 /* If we're ignoring translations */
695 695
696 /* For old KDE entries, we can also split by a comma 696 /* For old KDE entries, we can also split by a comma
697 * on sort order, so convert to semicolons */ 697 * on sort order, so convert to semicolons */
698 if (old_kde && 698 if (old_kde &&
699 cur_section == NULL && 699 cur_section == NULL &&
700 strcmp (key, PURPLE_DESKTOP_ITEM_SORT_ORDER) == 0 && 700 purple_strequal (key, PURPLE_DESKTOP_ITEM_SORT_ORDER) &&
701 strchr (val, ';') == NULL) { 701 strchr (val, ';') == NULL) {
702 int i; 702 int i;
703 for (i = 0; val[i] != '\0'; i++) { 703 for (i = 0; val[i] != '\0'; i++) {
704 if (val[i] == ',') 704 if (val[i] == ',')
705 val[i] = ';'; 705 val[i] = ';';
718 718
719 k = g_strdup (key); 719 k = g_strdup (key);
720 720
721 /* Take care of the language part */ 721 /* Take care of the language part */
722 if (locale != NULL && 722 if (locale != NULL &&
723 strcmp (locale, "C") == 0) { 723 purple_strequal (locale, "C")) {
724 char *p; 724 char *p;
725 /* Whack C locale */ 725 /* Whack C locale */
726 p = strchr (k, '['); 726 p = strchr (k, '[');
727 if(p) *p = '\0'; 727 if(p) *p = '\0';
728 g_free (locale); 728 g_free (locale);
789 { 789 {
790 const char *type = g_hash_table_lookup (item->main_hash, 790 const char *type = g_hash_table_lookup (item->main_hash,
791 PURPLE_DESKTOP_ITEM_TYPE); 791 PURPLE_DESKTOP_ITEM_TYPE);
792 if (type == NULL && uri != NULL) { 792 if (type == NULL && uri != NULL) {
793 char *base = g_path_get_basename (uri); 793 char *base = g_path_get_basename (uri);
794 if (base != NULL && 794 if (purple_strequal(base, ".directory")) {
795 strcmp (base, ".directory") == 0) {
796 /* This gotta be a directory */ 795 /* This gotta be a directory */
797 g_hash_table_replace (item->main_hash, 796 g_hash_table_replace (item->main_hash,
798 g_strdup (PURPLE_DESKTOP_ITEM_TYPE), 797 g_strdup (PURPLE_DESKTOP_ITEM_TYPE),
799 g_strdup ("Directory")); 798 g_strdup ("Directory"));
800 item->keys = g_list_prepend 799 item->keys = g_list_prepend
811 810
812 static const char * 811 static const char *
813 lookup_locale (const PurpleDesktopItem *item, const char *key, const char *locale) 812 lookup_locale (const PurpleDesktopItem *item, const char *key, const char *locale)
814 { 813 {
815 if (locale == NULL || 814 if (locale == NULL ||
816 strcmp (locale, "C") == 0) { 815 purple_strequal (locale, "C")) {
817 return lookup (item, key); 816 return lookup (item, key);
818 } else { 817 } else {
819 const char *ret; 818 const char *ret;
820 char *full = g_strdup_printf ("%s[%s]", key, locale); 819 char *full = g_strdup_printf ("%s[%s]", key, locale);
821 ret = lookup (item, full); 820 ret = lookup (item, full);
855 const char *type; 854 const char *type;
856 855
857 type = lookup (item, PURPLE_DESKTOP_ITEM_TYPE); 856 type = lookup (item, PURPLE_DESKTOP_ITEM_TYPE);
858 857
859 /* understand old gnome style url exec thingies */ 858 /* understand old gnome style url exec thingies */
860 if (type != NULL && strcmp (type, "URL") == 0) { 859 if (purple_strequal(type, "URL")) {
861 const char *exec = lookup (item, PURPLE_DESKTOP_ITEM_EXEC); 860 const char *exec = lookup (item, PURPLE_DESKTOP_ITEM_EXEC);
862 set (item, PURPLE_DESKTOP_ITEM_TYPE, "Link"); 861 set (item, PURPLE_DESKTOP_ITEM_TYPE, "Link");
863 if (exec != NULL) { 862 if (exec != NULL) {
864 /* Note, this must be in this order */ 863 /* Note, this must be in this order */
865 set (item, PURPLE_DESKTOP_ITEM_URL, exec); 864 set (item, PURPLE_DESKTOP_ITEM_URL, exec);
966 if (cur_section != NULL && 965 if (cur_section != NULL &&
967 cur_section->keys != NULL) { 966 cur_section->keys != NULL) {
968 cur_section->keys = g_list_reverse 967 cur_section->keys = g_list_reverse
969 (cur_section->keys); 968 (cur_section->keys);
970 } 969 }
971 if (strcmp (CharBuffer, 970 if (purple_strequal (CharBuffer, "KDE Desktop Entry")) {
972 "KDE Desktop Entry") == 0) {
973 /* Main section */ 971 /* Main section */
974 cur_section = NULL; 972 cur_section = NULL;
975 old_kde = TRUE; 973 old_kde = TRUE;
976 } else if (strcmp (CharBuffer, 974 } else if (purple_strequal(CharBuffer, "Desktop Entry")) {
977 "Desktop Entry") == 0) {
978 /* Main section */ 975 /* Main section */
979 cur_section = NULL; 976 cur_section = NULL;
980 } else { 977 } else {
981 cur_section = g_new0 (Section, 1); 978 cur_section = g_new0 (Section, 1);
982 cur_section->name = 979 cur_section->name =