1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 
3 /* caja-connect-server-main.c - Start the "Connect to Server" dialog.
4  * Caja
5  *
6  * Copyright (C) 2005 Vincent Untz
7  *
8  * Caja is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) any later version.
12  *
13  * Caja is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public
19  * License along with this program; see the file COPYING.  If not,
20  * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  * Authors:
24  *   Vincent Untz <vincent@vuntz.net>
25  *   Cosimo Cecchi <cosimoc@gnome.org>
26  */
27 
28 #include <config.h>
29 #include <stdlib.h>
30 
31 #include <glib/gi18n.h>
32 #include <gtk/gtk.h>
33 #include <gdk/gdk.h>
34 
35 #include <eel/eel-stock-dialogs.h>
36 
37 #include <libcaja-private/caja-icon-names.h>
38 #include <libcaja-private/caja-global-preferences.h>
39 
40 #include "caja-connect-server-dialog.h"
41 
42 static GSimpleAsyncResult *display_location_res = NULL;
43 
44 static void
main_dialog_destroyed(GtkWidget * widget,gpointer user_data)45 main_dialog_destroyed (GtkWidget *widget,
46                        gpointer   user_data)
47 {
48     /* this only happens when user clicks "cancel"
49      * on the main dialog or when we are all done.
50      */
51     gtk_main_quit ();
52 }
53 
54 gboolean
caja_connect_server_dialog_display_location_finish(CajaConnectServerDialog * self,GAsyncResult * res,GError ** error)55 caja_connect_server_dialog_display_location_finish (CajaConnectServerDialog *self,
56 						    GAsyncResult *res,
57 						    GError **error)
58 {
59     if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) {
60     	return FALSE;
61     }
62 
63     return TRUE;
64 }
65 
66 void
caja_connect_server_dialog_display_location_async(CajaConnectServerDialog * self,CajaApplication * application,GFile * location,GAsyncReadyCallback callback,gpointer user_data)67 caja_connect_server_dialog_display_location_async (CajaConnectServerDialog *self,
68 						   CajaApplication *application,
69 						   GFile *location,
70 						   GAsyncReadyCallback callback,
71 						   gpointer user_data)
72 {
73     GError *error;
74     GdkAppLaunchContext *launch_context;
75     gchar *uri;
76 
77     display_location_res = g_simple_async_result_new (G_OBJECT (self),
78     			    callback, user_data,
79     			    caja_connect_server_dialog_display_location_async);
80 
81     error = NULL;
82     uri = g_file_get_uri (location);
83 
84     launch_context = gdk_display_get_app_launch_context (gtk_widget_get_display (GTK_WIDGET (self)));
85 
86     gdk_app_launch_context_set_screen (launch_context,
87                                        gtk_widget_get_screen (GTK_WIDGET (self)));
88 
89     g_app_info_launch_default_for_uri (uri,
90                                        G_APP_LAUNCH_CONTEXT (launch_context),
91                                        &error);
92 
93     g_object_unref (launch_context);
94 
95     if (error != NULL) {
96     	g_simple_async_result_set_from_error (display_location_res, error);
97         g_error_free (error);
98     }
99     g_simple_async_result_complete_in_idle (display_location_res);
100 
101     g_object_unref (display_location_res);
102     display_location_res = NULL;
103 }
104 
105 int
main(int argc,char * argv[])106 main (int argc, char *argv[])
107 {
108     GtkWidget *dialog;
109     GOptionContext *context;
110     GError *error;
111 
112 #ifdef ENABLE_NLS
113     bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
114     bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
115     textdomain (GETTEXT_PACKAGE);
116 #endif /* ENABLE_NLS */
117 
118     error = NULL;
119     /* Translators: This is the --help description for the connect to server app,
120        the initial newlines are between the command line arg and the description */
121     context = g_option_context_new (N_("\n\nAdd connect to server mount"));
122 #ifdef ENABLE_NLS
123     g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
124 #endif /* ENABLE_NLS */
125     g_option_context_add_group (context, gtk_get_option_group (TRUE));
126 
127     if (!g_option_context_parse (context, &argc, &argv, &error))
128     {
129         g_critical ("Failed to parse arguments: %s", error->message);
130         g_error_free (error);
131         g_option_context_free (context);
132         exit (1);
133     }
134 
135     g_option_context_free (context);
136 
137     caja_global_preferences_init ();
138 
139     gtk_window_set_default_icon_name (CAJA_ICON_FOLDER);
140 
141     dialog = caja_connect_server_dialog_new (NULL);
142 
143     g_signal_connect (dialog, "destroy",
144                       G_CALLBACK (main_dialog_destroyed), NULL);
145 
146     gtk_widget_show (dialog);
147 
148     gtk_main ();
149 
150     return 0;
151 }
152