...and the attachment ;)
the patch is to be applied in the main efreet directory.

Dave

----- "Dave Andreoli" <[EMAIL PROTECTED]> ha scritto:

> Hi all
> This is a relly small patch that add 2 functions to Efreet_Mime.
> 
> EAPI const char*
> efreet_mime_default_application_get(const char *mime)
> 
> EAPI void
> efreet_mime_default_application_set(const char *mime, const char
> *desktop)
> 
> The _get function take a mime-type (as 'text/html') and return the 
> name of the desktop file (as 'Firefox.desktop') that should be 
> used to open the given mime-type. The information is readed from
> the $XDG_DATA_DIRS/applications/defaults.list file, first the 
> user preference file is checked than the system wide.
> The second one set the preference in the user defaults.list file.
> 
> With this functions all the applications that use efreet can know
> witch
> is the default program to use to open a given mime-type.
> 
> Hope you like it
> Dave
> 
> 
> 
> 
> 
> 
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the
> world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> enlightenment-devel mailing list
> enlightenment-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/enlightenment-devel
Index: src/lib/efreet_mime.c
===================================================================
--- src/lib/efreet_mime.c	(revisione 37249)
+++ src/lib/efreet_mime.c	(copia locale)
@@ -86,6 +86,7 @@
 static int efreet_mime_glob_match(const char *str, const char *glob);
 static int efreet_mime_glob_case_match(char *str, const char *glob);
 static int efreet_mime_endian_check(void);
+static const char*efreet_mime_default_get(const char *file, const char *mime);
 
 static void efreet_mime_monitor_add(const char *file);
 static void efreet_mime_cb_update_file(void *data,
@@ -317,6 +318,69 @@
 }
 
 /**
+ * @param mime: The mime type to check (ex. 'text/html' or 'x-directory/normal')
+ * @return Returns The name of the .desktop file to use to open the given mime type. Remember to free the value with eina_strinshare_del()
+ * @brief Retreive the application to use to open a give mime type
+ */
+EAPI const char*
+efreet_mime_default_application_get(const char *mime)
+{
+    Ecore_List *dirs;
+    char *dir;
+    char buf[PATH_MAX];
+    const char *ret = NULL;
+
+    if (!mime) return NULL;
+
+    //Search user defaults.list file
+    snprintf(buf, sizeof(buf), "%s/applications/defaults.list", efreet_data_home_get());
+    if ((ret = efreet_mime_default_get(buf, mime)))
+        return ret;
+
+    //Search system defaults.list file
+    dirs = efreet_data_dirs_get();
+    if (dirs)
+    {
+        ecore_list_first_goto(dirs);
+        while ((dir = ecore_list_next(dirs)))
+        {
+            snprintf(buf, sizeof(buf), "%sapplications/defaults.list", dir);
+            ret = efreet_mime_default_get(buf, mime);
+            if (ret)
+                break;
+        }
+    }
+
+   return ret;
+}
+
+/**
+ * @param mime: The mime type to set (ex. 'text/html' or 'x-directory/normal')
+ * @param desktop: The name of the desktop file to use as default (ex. 'Thunar.desktop')
+ * @brief Set the default application to use to open a give mime type
+ */
+EAPI void
+efreet_mime_default_application_set(const char *mime, const char *desktop)
+{
+    Efreet_Ini  *ini = NULL;
+    char buf[PATH_MAX];
+
+    if (!mime || !desktop)
+        return;
+
+    //Always use the user defaults.list file
+    snprintf(buf, sizeof(buf), "%s/applications/defaults.list", efreet_data_home_get());
+    ini = efreet_ini_new(buf);
+    if (!ini)
+        return;
+
+    efreet_ini_section_set(ini, "Default Applications");
+    efreet_ini_string_set(ini, mime, desktop);
+    efreet_ini_save(ini, buf);
+    efreet_ini_free(ini);
+}
+
+/**
  * @internal
  * @return Returns the endianess
  * @brief Retreive the endianess of the machine
@@ -1227,3 +1291,29 @@
     if (!fnmatch(str, tglob, 0)) return 1;
     return 0;
 }
+/**
+ * @internal
+ * @param file: The full path to a defaults.list file
+ * @param mime: The mime type to search for
+ * @return Returns a newly allocated string with the name of the .desktop file
+ * @brief Search the given defaults.desktop file for mime
+ */
+static const char*
+efreet_mime_default_get(const char *file, const char *mime)
+{
+    Efreet_Ini  *ini = NULL;
+    const char *str, *ret = NULL;
+
+    if (! file || !mime || !ecore_file_can_read(file))
+        return NULL;
+
+    ini = efreet_ini_new(file);
+    if (!ini) return NULL;
+
+    efreet_ini_section_set(ini, "Default Applications");   
+    if ((str = efreet_ini_string_get(ini, mime)))
+        ret = eina_stringshare_add(str);
+
+    efreet_ini_free(ini);
+    return ret;
+}
Index: src/lib/Efreet_Mime.h
===================================================================
--- src/lib/Efreet_Mime.h	(revisione 37249)
+++ src/lib/Efreet_Mime.h	(copia locale)
@@ -52,6 +52,7 @@
 EAPI char *efreet_mime_type_icon_get(const char *mime, const char *theme,
                                                           unsigned int size);
 
+EAPI const char* efreet_mime_default_application_get(const char *mime);
 /**
  * @}
  */
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to