Update Friulian translation
[glib.git] / gio / gio-tool-open.c
blobfc74186f76bb8bf1494d18ed0aa644eaec9c1557
1 /*
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.1 of the License, 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>
20 #include "config.h"
22 #include <gio/gio.h>
23 #include <gi18n.h>
25 #include "gio-tool.h"
28 static const GOptionEntry entries[] = {
29 { NULL }
32 int
33 handle_open (int argc, char *argv[], gboolean do_help)
35 GOptionContext *context;
36 gchar *param;
37 GError *error = NULL;
38 int i;
39 gboolean success;
40 gboolean res;
42 g_set_prgname ("gio open");
44 /* Translators: commandline placeholder */
45 param = g_strdup_printf ("%s...", _("LOCATION"));
46 context = g_option_context_new (param);
47 g_free (param);
48 g_option_context_set_help_enabled (context, FALSE);
49 g_option_context_set_summary (context,
50 _("Open files with the default application that\n"
51 "is registered to handle files of this type."));
52 g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
54 if (do_help)
56 show_help (context, NULL);
57 g_option_context_free (context);
58 return 0;
61 if (!g_option_context_parse (context, &argc, &argv, &error))
63 show_help (context, error->message);
64 g_error_free (error);
65 g_option_context_free (context);
66 return 1;
69 if (argc < 2)
71 show_help (context, _("No locations given"));
72 g_option_context_free (context);
73 return 1;
76 g_option_context_free (context);
78 success = TRUE;
79 for (i = 1; i < argc; i++)
81 GFile *file;
82 char *uri;
84 file = g_file_new_for_commandline_arg (argv[i]);
85 uri = g_file_get_uri (file);
86 res = g_app_info_launch_default_for_uri (uri, NULL, &error);
88 if (!res)
90 print_file_error (file, error->message);
91 g_clear_error (&error);
92 success = FALSE;
95 g_object_unref (file);
96 g_free (uri);
99 return success ? 0 : 2;