1 /* vi:set et ai sw=2 sts=2 ts=2: */
2 /*-
3  * Copyright (c) 2005-2006 Benedikt Meurer <benny@xfce.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24 
25 #ifdef HAVE_MEMORY_H
26 #include <memory.h>
27 #endif
28 #ifdef HAVE_STRING_H
29 #include <string.h>
30 #endif
31 
32 #include <thunar-apr/thunar-apr-desktop-page.h>
33 #include <thunar-apr/thunar-apr-image-page.h>
34 #include <thunar-apr/thunar-apr-provider.h>
35 
36 
37 
38 static void   thunar_apr_provider_property_page_provider_init (ThunarxPropertyPageProviderIface *iface);
39 static GList *thunar_apr_provider_get_pages                   (ThunarxPropertyPageProvider      *property_page_provider,
40                                                                GList                            *files);
41 
42 
43 
44 struct _ThunarAprProviderClass
45 {
46   GObjectClass __parent__;
47 };
48 
49 struct _ThunarAprProvider
50 {
51   GObject __parent__;
52 };
53 
54 
55 
56 THUNARX_DEFINE_TYPE_WITH_CODE (ThunarAprProvider,
57                                thunar_apr_provider,
58                                G_TYPE_OBJECT,
59                                THUNARX_IMPLEMENT_INTERFACE (THUNARX_TYPE_PROPERTY_PAGE_PROVIDER,
60                                                             thunar_apr_provider_property_page_provider_init));
61 
62 
63 
64 static void
thunar_apr_provider_class_init(ThunarAprProviderClass * klass)65 thunar_apr_provider_class_init (ThunarAprProviderClass *klass)
66 {
67 }
68 
69 
70 
71 static void
thunar_apr_provider_property_page_provider_init(ThunarxPropertyPageProviderIface * iface)72 thunar_apr_provider_property_page_provider_init (ThunarxPropertyPageProviderIface *iface)
73 {
74   iface->get_pages = thunar_apr_provider_get_pages;
75 }
76 
77 
78 
79 static void
thunar_apr_provider_init(ThunarAprProvider * apr_provider)80 thunar_apr_provider_init (ThunarAprProvider *apr_provider)
81 {
82 }
83 
84 
85 
86 static GList*
thunar_apr_provider_get_pages(ThunarxPropertyPageProvider * property_page_provider,GList * files)87 thunar_apr_provider_get_pages (ThunarxPropertyPageProvider *property_page_provider,
88                                GList                       *files)
89 {
90   GSList *formats;
91   GSList *lp;
92   gchar **mime_types;
93   gchar  *scheme;
94   GList  *pages = NULL;
95   gint    n;
96 
97   /* we can handle only property pages for a single file */
98   if (G_UNLIKELY (files == NULL || files->next != NULL))
99     return NULL;
100 
101   /* determine the URI scheme of the file (works only for local files) */
102   scheme = thunarx_file_info_get_uri_scheme (files->data);
103   if (G_LIKELY (strcmp (scheme, "file") == 0))
104     {
105       /* ThunarAprDesktopPage case */
106       if (G_LIKELY (pages == NULL))
107         {
108           /* check if we have a .desktop file here */
109           if (thunarx_file_info_has_mime_type (files->data, "application/x-desktop"))
110             pages = g_list_append (pages, g_object_new (THUNAR_APR_TYPE_DESKTOP_PAGE, "file", files->data, NULL));
111         }
112 
113       /* ThunarAprImagePage case */
114       if (G_LIKELY (pages == NULL))
115         {
116           /* determine the supported GdkPixbuf formats */
117           formats = gdk_pixbuf_get_formats ();
118           for (lp = formats; lp != NULL && pages == NULL; lp = lp->next)
119             {
120               /* check if any of the mime types of this format matches */
121               mime_types = gdk_pixbuf_format_get_mime_types (lp->data);
122               for (n = 0; mime_types[n] != NULL && pages == NULL; ++n)
123                 if (thunarx_file_info_has_mime_type (files->data, mime_types[n]))
124                   pages = g_list_append (pages, g_object_new (THUNAR_APR_TYPE_IMAGE_PAGE, "file", files->data, NULL));
125               g_strfreev (mime_types);
126             }
127           g_slist_free (formats);
128         }
129     }
130   g_free (scheme);
131 
132   return pages;
133 }
134 
135