[monkey-bubble: 316/753] wipe all the standard incomformat stuff, clean up a little bit and start



commit 37e785c457d9ecff1e202f30f455cb6ae67b1f37
Author: George Lebl <jirka 5z com>
Date:   Tue May 22 06:11:01 2001 +0000

    wipe all the standard incomformat stuff, clean up a little bit and start
    
    Mon May 21 23:12:04 2001  George Lebl <jirka 5z com>
    
    	* gnome-ditem.[ch]: wipe all the standard incomformat stuff, clean
    	  up a little bit and start on supporting the standard.  Currently
    	  compiles but doesn't all work, that is launching doesn't work.
    	  Also wipe all KDE vs. GNOME stuff, now the entry is converted to
    	  standard upon load, making life easier on the rest of the functions

 libgnome/ChangeLog     |    8 +
 libgnome/gnome-ditem.c |  512 +++++++++++++++++++++++-------------------------
 libgnome/gnome-ditem.h |   32 +---
 3 files changed, 260 insertions(+), 292 deletions(-)
---
diff --git a/libgnome/ChangeLog b/libgnome/ChangeLog
index cbdb061..e7300e5 100644
--- a/libgnome/ChangeLog
+++ b/libgnome/ChangeLog
@@ -1,3 +1,11 @@
+Mon May 21 23:12:04 2001  George Lebl <jirka 5z com>
+
+	* gnome-ditem.[ch]: wipe all the standard incomformat stuff, clean
+	  up a little bit and start on supporting the standard.  Currently
+	  compiles but doesn't all work, that is launching doesn't work.
+	  Also wipe all KDE vs. GNOME stuff, now the entry is converted to
+	  standard upon load, making life easier on the rest of the functions
+
 2001-05-21  Martin Baulig  <baulig suse de>
 
 	* gnome-selector-factory.c: Create a BonoboItemHandler so that
diff --git a/libgnome/gnome-ditem.c b/libgnome/gnome-ditem.c
index 6d8593f..5ef2a4a 100644
--- a/libgnome/gnome-ditem.c
+++ b/libgnome/gnome-ditem.c
@@ -54,6 +54,8 @@
 #include <libgnomevfs/gnome-vfs-uri.h>
 
 struct _GnomeDesktopItem {
+        int refcount;
+
         GHashTable *name; /* key is language, value is translated string */
         GHashTable *comment; /* key is language, value is translated string */
 
@@ -72,10 +74,7 @@ struct _GnomeDesktopItem {
 
         time_t mtime;
 
-        guchar refcount;
-
-        GnomeDesktopItemFormat item_format : 4;
-        GnomeDesktopItemFlags item_flags : 8;
+        GnomeDesktopItemFlags item_flags;
 };
 
 /**
@@ -117,125 +116,147 @@ gnome_desktop_item_copy (const GnomeDesktopItem *item)
         GnomeDesktopItem *retval;
 	GSList *li;
 
-        g_return_val_if_fail(item, NULL);
+        g_return_val_if_fail (item, NULL);
 
-        retval = gnome_desktop_item_new();
+        retval = gnome_desktop_item_new ();
 
-        retval->item_format = item->item_format;
         retval->item_flags = item->item_flags;
 
 	/* g_strdup handles NULLs correctly */
-        retval->icon_path = g_strdup(item->icon_path);
-        retval->location = g_strdup(item->location);
-        retval->exec = g_strdup(item->exec);
-        retval->type = g_strdup(item->type);
+        retval->icon_path = g_strdup (item->icon_path);
+        retval->location = g_strdup (item->location);
+        retval->exec = g_strdup (item->exec);
+        retval->type = g_strdup (item->type);
 
-        if(item->name
-           && g_hash_table_size(item->name) > 0) {
+        if (item->name != NULL
+	    && g_hash_table_size (item->name) > 0) {
                 retval->name = g_hash_table_new (g_str_hash, g_str_equal);
-                g_hash_table_foreach(item->name, ditem_copy_key_value, retval->name);      
+                g_hash_table_foreach (item->name, ditem_copy_key_value,
+				      retval->name);      
         }
 
-        if(item->comment
-           && g_hash_table_size(item->comment) > 0) {
+        if (item->comment != NULL
+	    && g_hash_table_size (item->comment) > 0) {
                 retval->comment = g_hash_table_new (g_str_hash, g_str_equal);
-                g_hash_table_foreach(item->comment, ditem_copy_key_value, retval->comment);
+                g_hash_table_foreach (item->comment, ditem_copy_key_value,
+				      retval->comment);
         }
 
-        if(item->other_attributes
-           && g_hash_table_size(item->other_attributes) > 0) {
-                retval->other_attributes = g_hash_table_new (g_str_hash, g_str_equal);
-                g_hash_table_foreach(item->other_attributes, ditem_copy_key_value, retval->other_attributes);
+        if (item->other_attributes != NULL
+	    && g_hash_table_size (item->other_attributes) > 0) {
+                retval->other_attributes = g_hash_table_new (g_str_hash,
+							     g_str_equal);
+                g_hash_table_foreach (item->other_attributes,
+				      ditem_copy_key_value,
+				      retval->other_attributes);
         }
 
-        retval->order = g_slist_copy(item->order);
-	for(li = retval->order; li; li = li->next)
-		li->data = g_strdup(li->data);
+        retval->order = g_slist_copy (item->order);
+	for (li = retval->order; li != NULL; li = li->next)
+		li->data = g_strdup (li->data);
 
         return retval;
 }
 
-/* If you find a bug here, odds are that it exists in ditem_gnome_load() too */
 static GnomeDesktopItem *
-ditem_kde_load (const char *data_file, GnomeDesktopItemLoadFlags flags,
-		GnomeDesktopItemFlags item_flags)
+ditem_load (const char *data_file,
+	    const char *main_entry_header,
+	    GnomeDesktopItemLoadFlags flags,
+	    GnomeDesktopItemFlags item_flags)
 {
-        GnomeDesktopItem *retval = gnome_desktop_item_new();
+        GnomeDesktopItem *retval = gnome_desktop_item_new ();
         char confpath[PATH_MAX];
         char *key, *value;
         void *iter;
 
-        g_snprintf(confpath, sizeof(confpath), "=%s=/KDE Desktop Entry", data_file);
+        g_snprintf (confpath, sizeof (confpath), "=%s=/%s",
+		    data_file, main_entry_header);
 
         retval->item_flags = item_flags;
-        retval->name = g_hash_table_new(g_str_hash, g_str_equal);
-        retval->comment = g_hash_table_new(g_str_hash, g_str_equal);
-        retval->other_attributes = g_hash_table_new(g_str_hash, g_str_equal);
+        retval->name = g_hash_table_new (g_str_hash, g_str_equal);
+        retval->comment = g_hash_table_new (g_str_hash, g_str_equal);
+        retval->other_attributes = g_hash_table_new (g_str_hash, g_str_equal);
 
-        iter = gnome_config_init_iterator(confpath);
-        while((iter = gnome_config_iterator_next(iter, &key, &value))) {
+        iter = gnome_config_init_iterator (confpath);
+        while ((iter = gnome_config_iterator_next (iter, &key, &value))) {
 		/* we need to keep things where the value is empty however */
-                if(!*key) {
-                        g_free(key);
-                        g_free(value);
+                if (*key == '\0') {
+                        g_free (key);
+                        g_free (value);
                         continue;
                 }
+                if ((flags & GNOME_DESKTOP_ITEM_LOAD_ONLY_IF_EXISTS) &&
+		    strcmp (key, "TryExec") == 0) {
+			if (*value != '\0') {
+				char *tryme = gnome_is_program_in_path (value);
+				if (tryme == NULL) {
+					g_free (key);
+					g_free (value);
+					g_free (iter);
+					goto errout;
+				}
+				g_free (tryme);
+			}
+		}
 
-                if(!strcmp(key, "Name")) {
-                        g_hash_table_insert(retval->name, g_strdup("C"), value);
-                } else if(!strncmp(key, "Name[", 5)) {
+                if (strcmp (key, "Name") == 0) {
+                        g_hash_table_insert (retval->name, g_strdup ("C"),
+					     value);
+			g_free (key);
+                } else if (strncmp (key, "Name[", strlen ("Name[")) == 0) {
                         char *mylang, *ctmp;
 
-                        mylang = key + 5;
-                        ctmp = strchr(mylang, ']');
-                        if(ctmp) *ctmp = '\0';
-
-                        g_hash_table_insert(retval->name, g_strdup(mylang), value);
-                        g_free(key);
-                } else if(!strcmp(key, "Comment")) {
-                        g_hash_table_insert(retval->comment, g_strdup("C"), value);
-                } else if(!strncmp(key, "Comment[", strlen("Comment["))) {
+                        mylang = key + strlen ("Name[");
+                        ctmp = strchr (mylang, ']');
+                        if (ctmp) *ctmp = '\0';
+
+                        g_hash_table_insert (retval->name,
+					     g_strdup (mylang), value);
+                        g_free (key);
+                } else if (strcmp (key, "Comment") == 0) {
+                        g_hash_table_insert (retval->comment, g_strdup ("C"),
+					     value);
+			g_free (key);
+                } else if (strncmp(key, "Comment[", strlen ("Comment[")) == 0) {
                         char *mylang, *ctmp;
 
-                        mylang = key + strlen("Comment[");
-                        ctmp = strchr(mylang, ']');
-                        if(ctmp) *ctmp = '\0';
+                        mylang = key + strlen ("Comment[");
+                        ctmp = strchr (mylang, ']');
+                        if (ctmp) *ctmp = '\0';
 
-                        g_hash_table_insert(retval->name, g_strdup(mylang), value);
-                        g_free(key);
-                } else if(!strcmp(key, "Icon")) {
+                        g_hash_table_insert (retval->name, g_strdup(mylang),
+					     value);
+                        g_free (key);
+                } else if (strcmp (key, "Icon") == 0) {
                         retval->icon_path = value;
-                        g_free(key);
-                } else if(!strcmp(key, "Terminal")) {
-                        if(tolower(*value) == 'y' || tolower(*value) == 't' || atoi(value))
+                        g_free (key);
+                } else if (strcmp (key, "Terminal") == 0) {
+                        if (*value == 'y' || *value == 'Y' ||
+			   *value == 't' || *value == 'T' ||
+			   atoi (value) != 0)
                                 retval->item_flags |= GNOME_DESKTOP_ITEM_RUN_IN_TERMINAL;
                         else
                                 retval->item_flags &= (~GNOME_DESKTOP_ITEM_RUN_IN_TERMINAL);
 
                         g_free(key);
                         g_free(value);
-                } else if(!strcmp(key, "Exec")) {
+                } else if (strcmp (key, "Exec") == 0) {
 			retval->exec = value;
-			if(strstr(value,"%f")) {
-				retval->item_flags |= GNOME_DESKTOP_ITEM_NO_URL_DROP;
-			} else if(strstr(value,"%F")) {
-				retval->item_flags |= GNOME_DESKTOP_ITEM_NO_URL_DROP |
-					GNOME_DESKTOP_ITEM_SINGLE_FILE_DROP_ONLY;
-			} else if(strstr(value,"%u")) {
-				/* everything is set just right :), don't touch it */
-			} else 
-				retval->item_flags |= GNOME_DESKTOP_ITEM_OLD_STYLE_DROP;
-                        g_free(key);
-                } else if(!strcmp(key, "Type")) {
+                        g_free (key);
+                } else if (strcmp (key, "Type") == 0) {
 			retval->type = value;
-			if(strcmp(value,"KonsoleApplication")==0)
+			if (strcmp (value, "KonsoleApplication")==0) {
 				retval->item_flags |=
 					GNOME_DESKTOP_ITEM_RUN_IN_TERMINAL;
-                        g_free(key);
-                } else if(!strcmp(key, "SortOrder")) {
+				/* convert to sanity */
+				g_free (retval->type);
+				retval->type = g_strdup ("Application");
+			}
+                        g_free (key);
+                } else if (strcmp (key, "SortOrder") == 0) {
 			char *p;
-                        g_free(key);
-			p = strtok(value,",");
+                        g_free (key);
+			p = strtok (value, ",");
 			while(p) {
 				retval->order = g_slist_prepend(retval->order,
 								g_strdup(p));
@@ -244,35 +265,20 @@ ditem_kde_load (const char *data_file, GnomeDesktopItemLoadFlags flags,
                         g_free(value);
 			retval->order = g_slist_reverse(retval->order);
                 } else {
-                        g_hash_table_insert(retval->other_attributes,
-					    key, value);
+                        g_hash_table_insert (retval->other_attributes,
+					     key, value);
                 }
         }
 
-        if ((flags & GNOME_DESKTOP_ITEM_LOAD_ONLY_IF_EXISTS)
-            && !(retval->item_flags & GNOME_DESKTOP_ITEM_IS_DIRECTORY)) {
-                char *tryme;
-                /* We don't use gnome_desktop_item_exists() here because it is more thorough than the TryExec stuff
-                   which GNOME_DESKTOP_ITEM_LOAD_ONLY_IF_EXISTS specifies */
-
-                if(!retval->exec)
-                        goto errout;
-
-                tryme = g_hash_table_lookup(retval->other_attributes, "TryExec");
-
-                if(tryme && !(tryme = gnome_is_program_in_path(tryme))) {
-			g_free(tryme);
-                        goto errout;
-		}
-        }
-
         return retval;
 
  errout:
-        gnome_desktop_item_unref(retval);
+        gnome_desktop_item_unref (retval);
         return NULL;
 }
 
+#if 0
+/* Not deleted because I may want to scavange bits later */
 /* There is entirely too much duplication between this function and ditem_kde_load() */
 static GnomeDesktopItem *
 ditem_gnome_load (const char *data_file, GnomeDesktopItemLoadFlags flags,
@@ -422,6 +428,7 @@ ditem_gnome_load (const char *data_file, GnomeDesktopItemLoadFlags flags,
         gnome_desktop_item_unref(retval);
         return NULL;
 }
+#endif
 
 /* load all the extra sections and store them as attributes in form of
    section/attribute */
@@ -457,6 +464,57 @@ ditem_load_other_sections(GnomeDesktopItem *item, const char *data_file,
         }
 }
 
+static const char *
+get_headers (const char *file, GSList **sections)
+{
+	void *iter;
+	char *section;
+	char confpath[PATH_MAX];
+	const char *main_entry_header = NULL;
+
+	g_snprintf (confpath, sizeof (confpath),
+		    "=%s=/", file);
+
+        iter = gnome_config_init_iterator_sections (confpath);
+        while ((iter = gnome_config_iterator_next (iter, &section, NULL))) {
+                if (*section == '\0') {
+                        g_free (section);
+                        continue;
+                }
+
+		if (main_entry_header == NULL &&
+		    strcmp (section, "Desktop Entry") == 0) {
+			main_entry_header = "Desktop Entry";
+			if (sections == NULL) {
+				g_free (section);
+				g_free (iter);
+				break;
+			}
+		} else if (main_entry_header == NULL &&
+			   strcmp (section, "KDE Desktop Entry") == 0) {
+			main_entry_header = "KDE Desktop Entry";
+			if (sections == NULL) {
+				g_free (section);
+				g_free (iter);
+				break;
+			}
+		}
+
+		if (sections == NULL) {
+			g_free (section);
+			continue;
+		}
+
+		/* store a list of other sections to read */
+		*sections = g_slist_prepend (*sections, section);
+	}
+
+	if (sections != NULL)
+		*sections = g_slist_reverse (*sections);
+
+	return main_entry_header;
+}
+
 /**
  * gnome_desktop_item_new_from_file:
  * @file: The filename or directory path to load the GnomeDesktopItem from
@@ -469,15 +527,15 @@ ditem_load_other_sections(GnomeDesktopItem *item, const char *data_file,
  * Returns: The newly loaded item.
  */
 GnomeDesktopItem *
-gnome_desktop_item_new_from_file (const char *file, GnomeDesktopItemLoadFlags flags)
+gnome_desktop_item_new_from_file (const char *file,
+				  GnomeDesktopItemLoadFlags flags)
 {
         GnomeDesktopItem *retval;
-        char subfn[PATH_MAX], headbuf[256], confpath[PATH_MAX];
-        FILE *fh;
+        char subfn[PATH_MAX], confpath[PATH_MAX];
         GnomeDesktopItemFlags item_flags;
-        GnomeDesktopItemFormat fmt;
         struct stat sbuf;
 	GSList *other_sections = NULL; /* names of other sections */
+	const char *main_entry_header = NULL;
 
         g_return_val_if_fail (file, NULL);
 
@@ -490,7 +548,6 @@ gnome_desktop_item_new_from_file (const char *file, GnomeDesktopItemLoadFlags fl
 
         /* Step one - figure out what type of file this is */
         flags = 0;
-        fmt = GNOME_DESKTOP_ITEM_UNKNOWN;
         item_flags = 0;
         if (S_ISDIR(sbuf.st_mode)) {
                 item_flags |= GNOME_DESKTOP_ITEM_IS_DIRECTORY;
@@ -509,75 +566,33 @@ gnome_desktop_item_new_from_file (const char *file, GnomeDesktopItemLoadFlags fl
                 strcpy(subfn, file);
         }
 
+	if (flags & GNOME_DESKTOP_ITEM_LOAD_NO_OTHER_SECTIONS) {
+		main_entry_header = get_headers (subfn, NULL);
+		other_sections = NULL;
+	} else {
+		other_sections = NULL;
+		main_entry_header = get_headers (subfn, &other_sections);
+	}
 
-        fh = fopen(subfn, "r");
-
-        if(!fh && (item_flags & GNOME_DESKTOP_ITEM_IS_DIRECTORY))
-                fmt = GNOME_DESKTOP_ITEM_GNOME; /* Empty dir becomes a GNOME thingie */
-        else if(fh) {
-		/* we go through the entire file looking for section headers,
-		   we do this as the right section header does not have to
-		   be at the top.  We however assume that it's either a
-		   GNOME desktop entry or a KDE one, and never both,
-		   perhaps we should us gnome_config_* for this already
-		   as it would probably speed things up, as gnome_config_*
-		   would already cache the file for later reading, we could
-		   also just do this from the file extention! */
-		while(fgets(headbuf, sizeof(headbuf), fh)) {
-			char *p;
-			g_strchug(headbuf);
-			if(headbuf[0] != '[')
-				continue;
-
-			if(!strncmp(headbuf, "[Desktop Entry]", strlen("[Desktop Entry]"))) {
-				fmt = GNOME_DESKTOP_ITEM_GNOME;
-				if(flags & GNOME_DESKTOP_ITEM_LOAD_NO_OTHER_SECTIONS)
-					break;
-			} else if(!strncmp(headbuf, "[KDE Desktop Entry]", strlen("[KDE Desktop Entry]"))) {
-				fmt = GNOME_DESKTOP_ITEM_KDE;
-				if(flags & GNOME_DESKTOP_ITEM_LOAD_NO_OTHER_SECTIONS)
-					break;
-			}
-
-			if(flags & GNOME_DESKTOP_ITEM_LOAD_NO_OTHER_SECTIONS)
-				continue;
-
-			p = strchr(headbuf,']');
-			if(!p) continue;
-			*p = '\0';
-			/* store a list of other sections to read */
-			other_sections =
-				g_slist_prepend(other_sections,
-						g_strdup(&headbuf[1]));
-		}
-
-                fclose(fh);
-        }
-
-        switch (fmt) {
-        case GNOME_DESKTOP_ITEM_KDE:
-                retval = ditem_kde_load(subfn, flags, item_flags);
-                break;
-        case GNOME_DESKTOP_ITEM_GNOME:
-                retval = ditem_gnome_load(subfn, flags, item_flags);
-                break;
-        default:
-                g_warning(_("Unknown desktop file format %d"), fmt);
+	if (main_entry_header == NULL) {
+		/*FIXME: use GError */
+                g_warning(_("Unknown desktop file"));
 		/* if we have names of other sections, free that list */
 		if(other_sections) {
 			g_slist_foreach(other_sections,(GFunc)g_free,NULL);
 			g_slist_free(other_sections);
 		}
                 return NULL;
-                break;
         }
 
-        if(!retval)
+	retval = ditem_load (subfn, main_entry_header, flags, item_flags);
+
+        if (retval == NULL)
                 goto out;
 
 	ditem_load_other_sections(retval, subfn, other_sections);
 
-	/* make the 'Type' sane */
+	/* make the 'Type' partly sane */
         if(item_flags & GNOME_DESKTOP_ITEM_IS_DIRECTORY) {
 		/* perhaps a little ineficent way to ensure this
 		   is the correct type */
@@ -599,7 +614,6 @@ gnome_desktop_item_new_from_file (const char *file, GnomeDesktopItemLoadFlags fl
 		retval->location = g_concat_dir_and_file(curdir,subfn);
 		g_free(curdir);
 	}
-        retval->item_format = fmt;
         retval->mtime = sbuf.st_mtime;
 
         if(!g_hash_table_size(retval->name)) {
@@ -617,13 +631,13 @@ gnome_desktop_item_new_from_file (const char *file, GnomeDesktopItemLoadFlags fl
 
  out:
 	/* if we have names of other sections, free that list */
-	if(other_sections) {
-		g_slist_foreach(other_sections,(GFunc)g_free,NULL);
-		g_slist_free(other_sections);
+	if (other_sections != NULL) {
+		g_slist_foreach (other_sections,(GFunc)g_free,NULL);
+		g_slist_free (other_sections);
 	}
-        if(!(flags & GNOME_DESKTOP_ITEM_LOAD_NO_SYNC)) {
-		g_snprintf(confpath, sizeof(confpath), "=%s=", subfn);
-                gnome_config_sync_file(confpath);
+        if ( ! (flags & GNOME_DESKTOP_ITEM_LOAD_NO_DROP)) {
+		g_snprintf (confpath, sizeof(confpath), "=%s=", subfn);
+                gnome_config_drop_file (confpath);
 	}
 
         return retval;
@@ -643,19 +657,9 @@ save_lang_val(gpointer key, gpointer value, gpointer user_data)
 }
 
 static void
-save_key_val(gpointer key, gpointer value, gpointer user_data)
+save_key_val (gpointer key, gpointer value, gpointer user_data)
 {
-	GnomeDesktopItem *item = user_data;
-	
-	/* in case the user set the OLD_STYLE_DROP flag on ignore
-	   the FileDropExec and URLDropExec so that next time we
-	   load we get the OLD_STYLE_DROP behaviour */
-	if(item->item_flags == GNOME_DESKTOP_ITEM_OLD_STYLE_DROP &&
-	   (strcmp(key,"FileDropExec")==0 ||
-	    strcmp(key,"URLDropExec")==0))
-		return;
-
-        gnome_config_set_string(key, value);
+        gnome_config_set_string (key, value);
 }
 
 /**
@@ -672,7 +676,7 @@ save_key_val(gpointer key, gpointer value, gpointer user_data)
 gboolean
 gnome_desktop_item_save (GnomeDesktopItem *item, const char *under)
 {
-        char fnbuf[PATH_MAX + sizeof("==/KDE Desktop Entry/")];
+        char fnbuf[PATH_MAX + sizeof("==/Desktop Entry/")];
 
         g_return_val_if_fail(item, FALSE);
         g_return_val_if_fail(under, FALSE);
@@ -688,6 +692,7 @@ gnome_desktop_item_save (GnomeDesktopItem *item, const char *under)
 		g_free(old_loc);
 	}
 
+#if 0
 	/* save the .order for gnome directory entries */
 	if(item->item_flags & GNOME_DESKTOP_ITEM_IS_DIRECTORY &&
 	   item->item_format == GNOME_DESKTOP_ITEM_GNOME) {
@@ -708,6 +713,7 @@ gnome_desktop_item_save (GnomeDesktopItem *item, const char *under)
 		} else
 			return FALSE;
 	}
+#endif
 
 	/* clean the file first, do not drop as if we dropped it the old
 	   stuff would be realoded on the next gnome_config_set_*, also
@@ -715,9 +721,8 @@ gnome_desktop_item_save (GnomeDesktopItem *item, const char *under)
 	g_snprintf(fnbuf, sizeof(fnbuf), "=%s=", item->location);
 	gnome_config_clean_file(fnbuf);
 
-	g_snprintf(fnbuf, sizeof(fnbuf), "=%s=/%sDesktop Entry/",
-		   item->location,
-		   (item->item_format==GNOME_DESKTOP_ITEM_KDE)?"KDE ":"");
+	g_snprintf (fnbuf, sizeof(fnbuf), "=%s=/Desktop Entry/",
+		    item->location);
 
         gnome_config_push_prefix(fnbuf);
 
@@ -758,15 +763,14 @@ gnome_desktop_item_save (GnomeDesktopItem *item, const char *under)
         if(item->item_flags & GNOME_DESKTOP_ITEM_RUN_IN_TERMINAL)
                 gnome_config_set_bool("Terminal", TRUE);
 
-        if(item->item_format == GNOME_DESKTOP_ITEM_KDE &&
-	   item->order) {
+        if (item->order != NULL) {
 		GString *gs;
 		GSList *li;
 
 		gs = g_string_new("");
 		for(li = item->order; li; li = li->next) {
 			if(li != item->order)
-				g_string_append_c(gs,',');
+				g_string_append_c(gs,';');
 			g_string_append(gs,li->data);
 		}
 
@@ -819,7 +823,7 @@ ditem_free_key_value(gpointer key, gpointer value, gpointer user_data)
 void
 gnome_desktop_item_unref (GnomeDesktopItem *item)
 {
-        g_return_if_fail(item);
+        g_return_if_fail (item != NULL);
 
         item->refcount--;
 
@@ -849,7 +853,10 @@ gnome_desktop_item_unref (GnomeDesktopItem *item)
         g_slist_foreach(item->order, (GFunc)g_free, NULL);
         g_slist_free(item->order);
 
-        g_free(item);
+	/* just for sanity */
+	memset (item, 0, sizeof (GnomeDesktopItem));
+
+        g_free (item);
 }
 
 /* replace %? (ps) with a string, the string can be NULL which is the same
@@ -908,28 +915,17 @@ ditem_execute(const GnomeDesktopItem *item, int appargc, const char *appargv[],
 
 	/* check the type, if there is one set */
 	if(item->type) {
-		if(item->item_format == GNOME_DESKTOP_ITEM_KDE) {
-			if(strcmp(item->type,"KonsoleApplication")!=0 &&
-			   strcmp(item->type,"Application")!=0) {
-				/* we are not an application so just exit
-				   with an error */
-				g_warning(_("Attempting to launch a non-application"));
-				return -1;
-			}
-		} else if(item->item_format == GNOME_DESKTOP_ITEM_GNOME) {
-			if(strcmp(item->type,"Application")!=0) {
-				/* we are not an application so just exit
-				   with an error */
-				g_warning(_("Attempting to launch a non-application"));
-				return -1;
-			}
-		} else {
-			g_warning(_("Unknown desktop file format %d"),
-				  item->item_format);
+		/* FIXME: ue GError */
+		if(strcmp(item->type,"Application")!=0) {
+			/* we are not an application so just exit
+			   with an error */
+			g_warning(_("Attempting to launch a non-application"));
+			return -1;
 		}
 	}
 
 	if(item->item_flags & GNOME_DESKTOP_ITEM_RUN_IN_TERMINAL) {
+		/* FIXME: add temrinal options from desktop file */
 		/* somewhat hackish I guess, we should use this in
 		 * the prepend mode rather then just getting a new
 		 * vector, but I didn't want to rewrite this whole
@@ -951,20 +947,19 @@ ditem_execute(const GnomeDesktopItem *item, int appargc, const char *appargv[],
         for(j = 0; j < argc; j++, i++)
                 real_argv[i] = (char *)argv[j];
 
-	/* if we are kde, replace the standard %? thingies */
-	if(item->item_format == GNOME_DESKTOP_ITEM_KDE) {
-		if(replacekdefiles) {
-			replace_percentsign(real_argc, real_argv, "%f", NULL, &tofree, TRUE);
-			replace_percentsign(real_argc, real_argv, "%F", NULL, &tofree, TRUE);
-			replace_percentsign(real_argc, real_argv, "%u", NULL, &tofree, TRUE);
-		}
-		replace_percentsign(real_argc, real_argv, "%d", g_getenv("PWD"), &tofree, FALSE);
-		replace_percentsign(real_argc, real_argv, "%i", item->icon_path, &tofree, FALSE);
-		replace_percentsign(real_argc, real_argv, "%m", 
-				    gnome_desktop_item_get_attribute(item,"MiniIcon"), &tofree, FALSE);
-		replace_percentsign(real_argc, real_argv, "%c", 
-				    gnome_desktop_item_get_local_comment(item), &tofree, FALSE);
+	/* FIXME: this ought to be standards compliant */
+	/* replace the standard %? thingies */
+	if(replacekdefiles) {
+		replace_percentsign(real_argc, real_argv, "%f", NULL, &tofree, TRUE);
+		replace_percentsign(real_argc, real_argv, "%F", NULL, &tofree, TRUE);
+		replace_percentsign(real_argc, real_argv, "%u", NULL, &tofree, TRUE);
 	}
+	replace_percentsign(real_argc, real_argv, "%d", g_getenv("PWD"), &tofree, FALSE);
+	replace_percentsign(real_argc, real_argv, "%i", item->icon_path, &tofree, FALSE);
+	replace_percentsign(real_argc, real_argv, "%m", 
+			    gnome_desktop_item_get_attribute(item,"MiniIcon"), &tofree, FALSE);
+	replace_percentsign(real_argc, real_argv, "%c", 
+			    gnome_desktop_item_get_local_comment(item), &tofree, FALSE);
 
         ret = gnome_execute_async(NULL, real_argc, real_argv);
 
@@ -1029,21 +1024,35 @@ gnome_desktop_item_launch (const GnomeDesktopItem *item, int argc, const char **
 
         g_return_val_if_fail(item, -1);
 
-	if(!item->exec) {
-		g_warning(_("Trying to execute an item with no 'Exec'"));
-		return -1;
-	}
-
 	/* This is a URL, so launch it as a url */
 	if (item->type != NULL &&
-	    item->item_format == GNOME_DESKTOP_ITEM_GNOME &&
 	    strcmp (item->type, "URL") == 0) {
-		if (gnome_url_show (item->exec))
-			return 0;
-		else
+		const char *url;
+		url = gnome_desktop_item_get_attribute (item, "URL");
+		if (url != NULL) {
+			if (gnome_url_show (item->exec))
+				return 0;
+			else
+				return -1;
+		/* Gnome panel used to put this in Exec */
+		} else if (item->exec != NULL) {
+			if (gnome_url_show (item->exec))
+				return 0;
+			else
+				return -1;
+		} else {
 			return -1;
+		}
+		/* FIXME: use GError */
+	}
+
+	if(!item->exec) {
+		/* FIXME: use GError */
+		g_warning(_("Trying to execute an item with no 'Exec'"));
+		return -1;
 	}
 
+
 	/* make a new copy and get rid of spaces */
 	the_exec = g_alloca(strlen(item->exec)+1);
 	strcpy(the_exec,item->exec);
@@ -1279,16 +1288,17 @@ gnome_desktop_item_drop_uri_list (const GnomeDesktopItem *item,
 	/* How could you drop something on a URL entry, that would
 	 * be bollocks */
 	if (item->type != NULL &&
-	    item->item_format == GNOME_DESKTOP_ITEM_GNOME &&
 	    strcmp (item->type, "URL") == 0) {
+		/*FIXME: use a GError */
 		return -1;
 	}
 
-	/* do we even allow drops? */
-	if(item->item_flags & GNOME_DESKTOP_ITEM_NO_FILE_DROP &&
-	   item->item_flags & GNOME_DESKTOP_ITEM_NO_URL_DROP)
-		return -1;
+	/* FIXME: we should really test if this was a compliant entry and there
+	 * were no %f %u or %F or whatnot, we shouldn't allow a drop!,
+	 * in that case I suppose, we should do that during load and add a
+	 * %F or something */
 
+#if 0
 	/* the simple case */
 	if(item->item_flags & GNOME_DESKTOP_ITEM_OLD_STYLE_DROP) {
 		int i;
@@ -1301,6 +1311,7 @@ gnome_desktop_item_drop_uri_list (const GnomeDesktopItem *item,
 		argv[i] = NULL;
 		return gnome_desktop_item_launch(item, argc, argv);
 	}
+#endif
 
 	/* figure out if we have any urls in the dropped files,
 	   this also builds a list of all the files */
@@ -1310,6 +1321,9 @@ gnome_desktop_item_drop_uri_list (const GnomeDesktopItem *item,
 	if(file_list)
 		file_list = g_list_reverse(file_list);
 
+	/* EEEEEEEEEK! */
+	/* FIXME: this is all non-standard bullshit! */
+#if 0
 	/* if there are any urls, or if the app didn't specify a command
 	   for files use the URL command */
 	if(any_urls || item->item_flags & GNOME_DESKTOP_ITEM_NO_FILE_DROP) {
@@ -1351,6 +1365,7 @@ gnome_desktop_item_drop_uri_list (const GnomeDesktopItem *item,
 			ret = ditem_exec_multiple_files(item, exec, file_list);
 		}
 	}
+#endif
 
 	if(file_list) {
 		g_list_foreach(file_list,(GFunc)g_free,NULL);
@@ -1785,20 +1800,6 @@ gnome_desktop_item_get_attributes(const GnomeDesktopItem *item)
 }
 
 /**
- * gnome_desktop_item_get_format:
- * @item: A desktop item
- *
- * Returns: The format that the specified 'item' is stored on disk with
- */
-GnomeDesktopItemFormat
-gnome_desktop_item_get_format (const GnomeDesktopItem *item)
-{
-        g_return_val_if_fail(item, GNOME_DESKTOP_ITEM_UNKNOWN);
-
-        return item->item_format;
-}
-
-/**
  * gnome_desktop_item_get_file_status:
  * @item: A desktop item
  *
@@ -2138,31 +2139,6 @@ gnome_desktop_item_set_flags (GnomeDesktopItem *item, GnomeDesktopItemFlags flag
 }
 
 /**
- * gnome_desktop_item_set_format:
- * @item: A desktop item
- * @fmt: The format to be set
- */
-void
-gnome_desktop_item_set_format (GnomeDesktopItem *item, GnomeDesktopItemFormat fmt)
-{
-        g_return_if_fail(item);
-
-	/* correctly convert from kde to gnome if the type is
-	   KonsoleApplication */
-	if(fmt == GNOME_DESKTOP_ITEM_GNOME &&
-	   item->item_format == GNOME_DESKTOP_ITEM_KDE &&
-	   item->type &&
-	   strcmp(item->type,"KonsoleApplication")==0) {
-		g_free(item->type);
-		item->type = g_strdup("Application");
-		item->item_flags |= GNOME_DESKTOP_ITEM_RUN_IN_TERMINAL;
-	}
-
-        item->item_format = fmt;
-
-}
-
-/**
  * gnome_desktop_item_set_location:
  * @item: A desktop item
  * @location: A string specifying the file location of this particular item.
diff --git a/libgnome/gnome-ditem.h b/libgnome/gnome-ditem.h
index 2f503f0..d376fa4 100644
--- a/libgnome/gnome-ditem.h
+++ b/libgnome/gnome-ditem.h
@@ -35,27 +35,10 @@ typedef enum {
 	/* Start a terminal to run this */
         GNOME_DESKTOP_ITEM_RUN_IN_TERMINAL = 1<<0,
 	/* Directory type */
-        GNOME_DESKTOP_ITEM_IS_DIRECTORY = 1<<1,
-	/* drop by appending arguments after Exec */
-        GNOME_DESKTOP_ITEM_OLD_STYLE_DROP = 1<<2,
-	/* never drop files (always off for OLD_STYLE_DROP items) */
- 	GNOME_DESKTOP_ITEM_NO_FILE_DROP = 1<<3,
-	/* never drop urls (always off for OLD_STYLE_DROP items) */
-        GNOME_DESKTOP_ITEM_NO_URL_DROP = 1<<4,
-	/* if multiple files are dropped start multiple instances */
-        GNOME_DESKTOP_ITEM_SINGLE_FILE_DROP_ONLY = 1<<5,
-	/* if multiple urls are dropped start multiple instances */
-        GNOME_DESKTOP_ITEM_SINGLE_URL_DROP_ONLY = 1<<6
+        GNOME_DESKTOP_ITEM_IS_DIRECTORY = 1<<1
 } GnomeDesktopItemFlags;
 
 typedef enum {
-        GNOME_DESKTOP_ITEM_UNKNOWN=0,
-        GNOME_DESKTOP_ITEM_GNOME=1,
-        GNOME_DESKTOP_ITEM_KDE=2
-        /* More types can be added here as needed */
-} GnomeDesktopItemFormat;
-
-typedef enum {
         GNOME_DESKTOP_ITEM_UNCHANGED = 0,
         GNOME_DESKTOP_ITEM_CHANGED = 1,
         GNOME_DESKTOP_ITEM_DISAPPEARED = 2
@@ -64,10 +47,13 @@ typedef enum {
 typedef struct _GnomeDesktopItem GnomeDesktopItem;
 
 typedef enum {
+	/* Use the TryExec field to determine if this shoul dbe loaded */
         GNOME_DESKTOP_ITEM_LOAD_ONLY_IF_EXISTS = 1<<0,
-        GNOME_DESKTOP_ITEM_LOAD_NO_SYNC = 1<<1,
-        GNOME_DESKTOP_ITEM_LOAD_NO_OTHER_SECTIONS = 1<<2 /* don't try to load
-							    other sections */
+	/* don't drop file from cache after loading */
+	GNOME_DESKTOP_ITEM_LOAD_NO_DROP = 1<<1,
+	/* don't try to load other sections, this is if you don't want to
+	 * save this file and don't need other sections, it saves memory */
+        GNOME_DESKTOP_ITEM_LOAD_NO_OTHER_SECTIONS = 1<<2
 } GnomeDesktopItemLoadFlags;
 
 /* Returned item from new*() and copy() methods have a refcount of 1 */
@@ -113,15 +99,13 @@ const char *           gnome_desktop_item_get_attribute   (const GnomeDesktopIte
 const char *           gnome_desktop_item_get_local_attribute (const GnomeDesktopItem *item,
 							       const char *attr_name);
 const GSList *         gnome_desktop_item_get_order    (const GnomeDesktopItem     *item);
-GnomeDesktopItemFormat gnome_desktop_item_get_format      (const GnomeDesktopItem     *item);
 GnomeDesktopItemStatus gnome_desktop_item_get_file_status (GnomeDesktopItem           *item);
 
 
 /* Free the return value but not the contained strings */
 GSList *               gnome_desktop_item_get_languages   (const GnomeDesktopItem     *item);
 GSList *               gnome_desktop_item_get_attributes  (const GnomeDesktopItem     *item);
-void                   gnome_desktop_item_set_format      (GnomeDesktopItem           *item,
-                                                           GnomeDesktopItemFormat      fmt);
+
 /* the _clear_name clears the name for all languages */
 void                   gnome_desktop_item_clear_name      (GnomeDesktopItem           *item);
 void                   gnome_desktop_item_set_name        (GnomeDesktopItem           *item,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]