r38: Rescanning a directory only shrinks the item width at the end rather than the
[rox-filer.git] / ROX-Filer / src / type.c
blob3aa6974eccb0f7d8f85394cbb905835032ebd8e2
1 /* vi: set cindent:
2 * $Id$
4 * ROX-Filer, filer for the ROX desktop project
5 * By Thomas Leonard, <tal197@ecs.soton.ac.uk>.
6 */
8 /* type.c - code for dealing with filetypes */
10 #include <glib.h>
11 #include <sys/stat.h>
12 #include <unistd.h>
13 #include <errno.h>
15 #include "filer.h"
16 #include "pixmaps.h"
17 #include "apps.h"
18 #include "gui_support.h"
19 #include "choices.h"
20 #include "type.h"
21 #include "support.h"
23 /* Static prototypes */
25 /* XXX: Just for testing... */
26 static MIME_type text_plain = {"text/plain"};
28 void type_init()
32 char *basetype_name(FileItem *item)
34 if (item->flags & ITEM_FLAG_SYMLINK)
35 return "Sym link";
36 else if (item->flags & ITEM_FLAG_MOUNT_POINT)
37 return "Mount point";
38 else if (item->flags & ITEM_FLAG_APPDIR)
39 return "App dir";
41 switch (item->base_type)
43 case TYPE_FILE:
44 return "File";
45 case TYPE_DIRECTORY:
46 return "Dir";
47 case TYPE_CHAR_DEVICE:
48 return "Char dev";
49 case TYPE_BLOCK_DEVICE:
50 return "Block dev";
51 case TYPE_PIPE:
52 return "Pipe";
53 case TYPE_SOCKET:
54 return "Socket";
57 return "Unknown";
60 /* MIME-type guessing */
62 /* Returns a pointer to the MIME-type string, or NULL if we have
63 * no opinion.
65 MIME_type *type_from_path(char *path)
67 return &text_plain;
70 /* Actions for types */
72 gboolean type_open(char *path, MIME_type *type)
74 char *argv[] = {NULL, path, NULL};
75 GString *type_path;
76 char *open;
77 struct stat info;
78 gboolean needs_free = FALSE;
80 type_path = g_string_new(type->name);
81 g_string_append(type_path, "/open");
82 open = choices_find_path_load_shared(type_path->str, "MIME-types");
83 g_string_free(type_path, TRUE);
85 if (!open)
86 return FALSE;
88 if (stat(open, &info))
90 report_error("ROX-Filer", g_strerror(errno));
91 return FALSE;
94 if (S_ISDIR(info.st_mode))
96 argv[0] = g_strconcat(open, "/AppRun");
97 needs_free = TRUE;
99 else
100 argv[0] = open;
102 if (!spawn(argv))
103 report_error("ROX-Filer",
104 "Failed to fork() child process");
106 if (needs_free)
107 g_free(argv[0]);
109 return TRUE;