2 * Copyright 2015 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the licence, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 * Author: Matthias Clasen <mclasen@redhat.com>
34 print_file_error (GFile
*file
, const char *message
)
36 g_printerr ("gio: %s: %s\n", g_file_get_uri (file
), message
);
40 show_help (GOptionContext
*context
, const char *message
)
45 g_printerr ("gio: %s\n\n", message
);
47 help
= g_option_context_get_help (context
, TRUE
, NULL
);
48 g_printerr ("%s", help
);
53 file_type_to_string (GFileType type
)
57 case G_FILE_TYPE_UNKNOWN
:
59 case G_FILE_TYPE_REGULAR
:
61 case G_FILE_TYPE_DIRECTORY
:
63 case G_FILE_TYPE_SYMBOLIC_LINK
:
65 case G_FILE_TYPE_SPECIAL
:
67 case G_FILE_TYPE_SHORTCUT
:
69 case G_FILE_TYPE_MOUNTABLE
:
72 return "invalid type";
77 attribute_type_to_string (GFileAttributeType type
)
81 case G_FILE_ATTRIBUTE_TYPE_INVALID
:
83 case G_FILE_ATTRIBUTE_TYPE_STRING
:
85 case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING
:
87 case G_FILE_ATTRIBUTE_TYPE_BOOLEAN
:
89 case G_FILE_ATTRIBUTE_TYPE_UINT32
:
91 case G_FILE_ATTRIBUTE_TYPE_INT32
:
93 case G_FILE_ATTRIBUTE_TYPE_UINT64
:
95 case G_FILE_ATTRIBUTE_TYPE_INT64
:
97 case G_FILE_ATTRIBUTE_TYPE_OBJECT
:
100 return "uknown type";
105 attribute_type_from_string (const char *str
)
107 if (strcmp (str
, "string") == 0)
108 return G_FILE_ATTRIBUTE_TYPE_STRING
;
109 if (strcmp (str
, "stringv") == 0)
110 return G_FILE_ATTRIBUTE_TYPE_STRINGV
;
111 if (strcmp (str
, "bytestring") == 0)
112 return G_FILE_ATTRIBUTE_TYPE_BYTE_STRING
;
113 if (strcmp (str
, "boolean") == 0)
114 return G_FILE_ATTRIBUTE_TYPE_BOOLEAN
;
115 if (strcmp (str
, "uint32") == 0)
116 return G_FILE_ATTRIBUTE_TYPE_UINT32
;
117 if (strcmp (str
, "int32") == 0)
118 return G_FILE_ATTRIBUTE_TYPE_INT32
;
119 if (strcmp (str
, "uint64") == 0)
120 return G_FILE_ATTRIBUTE_TYPE_UINT64
;
121 if (strcmp (str
, "int64") == 0)
122 return G_FILE_ATTRIBUTE_TYPE_INT64
;
123 if (strcmp (str
, "object") == 0)
124 return G_FILE_ATTRIBUTE_TYPE_OBJECT
;
125 if (strcmp (str
, "unset") == 0)
126 return G_FILE_ATTRIBUTE_TYPE_INVALID
;
131 attribute_flags_to_string (GFileAttributeInfoFlags flags
)
141 G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE
,
145 G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED
,
146 N_("Keep with file when moved")
152 s
= g_string_new ("");
153 for (i
= 0; i
< G_N_ELEMENTS (flag_descr
); i
++)
155 if (flags
& flag_descr
[i
].mask
)
158 g_string_append (s
, ", ");
159 g_string_append (s
, gettext (flag_descr
[i
].descr
));
164 return g_string_free (s
, FALSE
);
168 file_is_dir (GFile
*file
)
173 info
= g_file_query_info (file
, G_FILE_ATTRIBUTE_STANDARD_TYPE
, 0, NULL
, NULL
);
174 res
= info
&& g_file_info_get_file_type (info
) == G_FILE_TYPE_DIRECTORY
;
176 g_object_unref (info
);
182 handle_version (int argc
, char *argv
[], gboolean do_help
)
184 if (do_help
|| argc
> 1)
187 g_printerr ("gio: %s\n\n", _("“version” takes no arguments"));
189 g_printerr ("%s\n", _("Usage:"));
190 g_printerr (" gio version\n");
192 g_printerr ("%s\n", _("Print version information and exit."));
194 return do_help
? 0 : 2;
197 g_print ("%d.%d.%d\n", glib_major_version
, glib_minor_version
, glib_micro_version
);
205 g_printerr ("%s\n", _("Usage:"));
206 g_printerr (" gio %s %s\n", _("COMMAND"), _("[ARGS...]"));
208 g_printerr ("%s\n", _("Commands:"));
209 g_printerr (" help %s\n", _("Print help"));
210 g_printerr (" version %s\n", _("Print version"));
211 g_printerr (" cat %s\n", _("Concatenate files to standard output"));
212 g_printerr (" copy %s\n", _("Copy one or more files"));
213 g_printerr (" info %s\n", _("Show information about locations"));
214 g_printerr (" list %s\n", _("List the contents of locations"));
215 g_printerr (" mime %s\n", _("Get or set the handler for a mimetype"));
216 g_printerr (" mkdir %s\n", _("Create directories"));
217 g_printerr (" monitor %s\n", _("Monitor files and directories for changes"));
218 g_printerr (" mount %s\n", _("Mount or unmount the locations"));
219 g_printerr (" move %s\n", _("Move one or more files"));
220 g_printerr (" open %s\n", _("Open files with the default application"));
221 g_printerr (" rename %s\n", _("Rename a file"));
222 g_printerr (" remove %s\n", _("Delete one or more files"));
223 g_printerr (" save %s\n", _("Read from standard input and save"));
224 g_printerr (" set %s\n", _("Set a file attribute"));
225 g_printerr (" trash %s\n", _("Move files or directories to the trash"));
226 g_printerr (" tree %s\n", _("Lists the contents of locations in a tree"));
228 g_printerr (_("Use %s to get detailed help.\n"), "“gio help COMMAND”");
233 main (int argc
, char **argv
)
238 setlocale (LC_ALL
, "");
239 textdomain (GETTEXT_PACKAGE
);
240 bindtextdomain (GETTEXT_PACKAGE
, GLIB_LOCALE_DIR
);
242 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
243 bind_textdomain_codeset (GETTEXT_PACKAGE
, "UTF-8");
257 if (g_str_equal (command
, "help"))
270 else if (g_str_equal (command
, "--help"))
275 else if (g_str_equal (command
, "--version"))
278 if (g_str_equal (command
, "version"))
279 return handle_version (argc
, argv
, do_help
);
280 else if (g_str_equal (command
, "cat"))
281 return handle_cat (argc
, argv
, do_help
);
282 else if (g_str_equal (command
, "copy"))
283 return handle_copy (argc
, argv
, do_help
);
284 else if (g_str_equal (command
, "info"))
285 return handle_info (argc
, argv
, do_help
);
286 else if (g_str_equal (command
, "list"))
287 return handle_list (argc
, argv
, do_help
);
288 else if (g_str_equal (command
, "mime"))
289 return handle_mime (argc
, argv
, do_help
);
290 else if (g_str_equal (command
, "mkdir"))
291 return handle_mkdir (argc
, argv
, do_help
);
292 else if (g_str_equal (command
, "monitor"))
293 return handle_monitor (argc
, argv
, do_help
);
294 else if (g_str_equal (command
, "mount"))
295 return handle_mount (argc
, argv
, do_help
);
296 else if (g_str_equal (command
, "move"))
297 return handle_move (argc
, argv
, do_help
);
298 else if (g_str_equal (command
, "open"))
299 return handle_open (argc
, argv
, do_help
);
300 else if (g_str_equal (command
, "rename"))
301 return handle_rename (argc
, argv
, do_help
);
302 else if (g_str_equal (command
, "remove"))
303 return handle_remove (argc
, argv
, do_help
);
304 else if (g_str_equal (command
, "save"))
305 return handle_save (argc
, argv
, do_help
);
306 else if (g_str_equal (command
, "set"))
307 return handle_set (argc
, argv
, do_help
);
308 else if (g_str_equal (command
, "trash"))
309 return handle_trash (argc
, argv
, do_help
);
310 else if (g_str_equal (command
, "tree"))
311 return handle_tree (argc
, argv
, do_help
);