1 /* $Id$ */
2 /* Copyright (c) 2015 Pierre Pronchery <khorben@defora.org> */
3 /* This file is part of DeforaOS Desktop Browser */
4 /* Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the authors nor the names of the contributors may be
16 * used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY ITS AUTHORS AND CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29
30
31
32 #include <sys/stat.h>
33 #include <unistd.h>
34 #include <stdio.h>
35 #include <string.h>
36 #include <gtk/gtk.h>
37 #include <Desktop/mime.h>
38 #include "Browser/vfs.h"
39
40 #ifndef PROGNAME
41 # define PROGNAME "vfs"
42 #endif
43
44
45 /* vfs */
_vfs(void)46 static int _vfs(void)
47 {
48 int ret = 0;
49 Mime * mime;
50 char const downloads[] = "/home/user/Downloads";
51 char const * type;
52 GdkPixbuf * icon;
53
54 if((mime = mime_new(NULL)) == NULL)
55 return -1;
56 if((type = browser_vfs_mime_type(mime, downloads, S_IFDIR)) == NULL
57 || strcmp(type, "inode/directory") != 0)
58 ret = -1;
59 else
60 printf("%s\n", type);
61 if((icon = browser_vfs_mime_icon(mime, downloads, type, NULL, NULL, 48))
62 != NULL)
63 g_object_unref(icon);
64 mime_delete(mime);
65 return ret;
66 }
67
68
69 /* usage */
_usage(void)70 static int _usage(void)
71 {
72 fputs("Usage: " PROGNAME "\n", stderr);
73 return 1;
74 }
75
76
77 /* main */
main(int argc,char * argv[])78 int main(int argc, char * argv[])
79 {
80 int o;
81
82 gtk_init(&argc, &argv);
83 while((o = getopt(argc, argv, "")) != -1)
84 switch(o)
85 {
86 default:
87 return _usage();
88 }
89 if(optind != argc)
90 return _usage();
91 return (_vfs() == 0) ? 0 : 2;
92 }
93