Example #1
0
void
gtr_open_uri( const char * uri )
{
    if( uri )
    {
        gboolean opened = FALSE;

#if GTK_CHECK_VERSION(2,14,0)
        if( !opened )
            opened = gtk_show_uri( NULL, uri, GDK_CURRENT_TIME, NULL );
#endif

#ifdef HAVE_GIO
        if( !opened )
            opened = g_app_info_launch_default_for_uri( uri, NULL, NULL );
#endif

        if( !opened ) {
            char * argv[] = { (char*)"xdg-open", (char*)uri, NULL };
            opened = g_spawn_async( NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
                                    NULL, NULL, NULL, NULL );
        }

        if( !opened )
            g_message( "Unable to open \"%s\"", uri );
    }
}
Example #2
0
File: UgUtils.c Project: Endz0/uget
gboolean	ug_launch_default_app (const gchar* folder, const gchar* file)
{
	GError* error = NULL;
	GFile*	gfile;
	gchar*	uri;
	gchar*	path;
	gchar*	path_wcs;

	path = g_build_filename (folder, file, NULL);
	path_wcs = g_filename_from_utf8 (path, -1, NULL, NULL, NULL);
	g_free (path);
	if (g_file_test (path_wcs, G_FILE_TEST_EXISTS) == FALSE) {
		g_free (path_wcs);
		return FALSE;
	}

	gfile = g_file_new_for_path (path_wcs);
	g_free (path_wcs);
	uri = g_file_get_uri (gfile);
	g_object_unref (gfile);
	g_app_info_launch_default_for_uri (uri, NULL, &error);
	g_free (uri);

	if (error) {
#ifndef NDEBUG
		g_print ("%s", error->message);
#endif
		g_error_free (error);
	}

	return TRUE;
}
Example #3
0
/**
 * seahorse_widget_show_help
 * @swidget: The #SeahorseWidget.
 * 
 * Show help appropriate for the top level widget.
 */
void
seahorse_widget_show_help (SeahorseWidget *swidget)
{
    GError *error = NULL;
    gchar *document = NULL;
    GtkWidget *dialog = NULL;

    if (g_str_equal (swidget->name, "key-manager") || 
        g_str_equal (swidget->name, "keyserver-results")) {
        document = g_strdup ("ghelp:" PACKAGE "?introduction");
    } else {
        document = g_strdup_printf ("ghelp:" PACKAGE "?%s", swidget->name);
    }

    if (!g_app_info_launch_default_for_uri (document, NULL, &error)) {
        dialog = gtk_message_dialog_new (GTK_WINDOW (seahorse_widget_get_toplevel (swidget)),
                                         GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
                                         _("Could not display help: %s"), error->message);
        g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (gtk_widget_destroy), NULL);
        gtk_widget_show (dialog);
    }

    g_free (document);

    if (error)
        g_error_free (error);
}
Example #4
0
static void open_dir(GtkTreeView       *tree_view,
		     GtkTreePath       *path,
		     GtkTreeViewColumn *column,
		     gpointer	       user_data)
{
	GtkTreeIter iter;
	GtkTreeModel *model;
	char *dir, *url;

	model = gtk_tree_view_get_model(tree_view);

	if (!gtk_tree_model_get_iter(model, &iter, path)) {
		char *p;
		p = gtk_tree_path_to_string(path);
		g_warning("Cannot get iter for path '%s'\n", p);
		g_free(p);
		return;
	}

	gtk_tree_model_get(model, &iter, DISK_DIR, &dir, -1);

	url = g_strdup_printf("file://%s", dir);

	GError* error = 0;
	if (!g_app_info_launch_default_for_uri(url, NULL, &error)) {
		g_warning("Cannot open '%s' : %s\n", url, error->message);
		g_error_free(error);
	}

	g_free(url);
	g_free(dir);
}
Example #5
0
static void
bluefish_url_show(const gchar * url)
{
#ifdef WIN32
	if ((int) ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL) <= 32) {
		g_warning("Failed trying to launch URL in about dialog");
	}
#else
#ifdef PLATFORM_DARWIN
	GString *string;
	string = g_string_new("open \"");
	string = g_string_append(string, url);
	string = g_string_append(string, "\"");
	g_print("bluefish_url_show, launching uri=%s\n", string->str);
	system(string->str);
	g_string_free(string, TRUE);
#else
	GError *error = NULL;

	g_app_info_launch_default_for_uri(url, NULL, &error);
	if (error) {
		g_warning("bluefish_url_show, %s", error->message);
		g_error_free(error);
	}
#endif
#endif
}
Example #6
0
/**
 * fm_app_info_launch_default_for_uri
 * @uri: the uri to show
 * @launch_context: (allow-none): a launch context
 * @error: (out) (allow-none): location to store error
 *
 * Utility function that launches the default application
 * registered to handle the specified uri. Synchronous I/O
 * is done on the uri to detect the type of the file if
 * required.
 *
 * Returns: %TRUE if application was launched.
 *
 * Since: 0.1.15
 */
gboolean fm_app_info_launch_default_for_uri(const char *uri,
                                            GAppLaunchContext *launch_context,
                                            GError **error)
{
    /* FIXME: implement this */
    return g_app_info_launch_default_for_uri(uri, launch_context, error);
}
Example #7
0
File: mailme.c Project: jku/mailme
static void
on_get_inbox (GObject      *source,
              GAsyncResult *result,
              gpointer      user_data)
{
  MailmeInboxOpenFormat format;
  gchar *value;
  GError *error = NULL;

  value = mailme_telepathy_account_get_inbox_finish (
                                        MAILME_TELEPATHY_ACCOUNT (source),
                                        result,
                                        &format,
                                        &error);

  if (error)
  {
    g_warning ("Failed to get inbox information: %s", error->message);
    g_error_free (error);
    return;
  }

  switch (format) {
    case MAILME_INBOX_URI:
      if (!g_app_info_launch_default_for_uri (value, NULL, NULL))
        g_warning ("Failed to launch default handler for uri %s", value);
      break;
    default:
      g_warning ("Only inbox uri handling has been implemented");
      break;
  }

  g_free (value);
}
Example #8
0
static void browse_python_scripts_dir(GtkAction *action, gpointer data)
{
  gchar *uri;
  GdkAppLaunchContext *launch_context;
  GError *error = NULL;
  MainWindow *mainwin;

  mainwin =  mainwindow_get_mainwindow();
  if(!mainwin) {
      debug_print("Browse Python scripts: Problems getting the mainwindow\n");
      return;
  }
  launch_context = gdk_app_launch_context_new();
  gdk_app_launch_context_set_screen(launch_context, gtk_widget_get_screen(mainwin->window));
  uri = g_strconcat("file://", get_rc_dir(), G_DIR_SEPARATOR_S, PYTHON_SCRIPTS_BASE_DIR, G_DIR_SEPARATOR_S, NULL);
  g_app_info_launch_default_for_uri(uri, G_APP_LAUNCH_CONTEXT(launch_context), &error);

  if(error) {
      debug_print("Could not open scripts dir browser: '%s'\n", error->message);
      g_error_free(error);
  }

  g_object_unref(launch_context);
  g_free(uri);
}
Example #9
0
static void
about_dialog_activate_link_cb (GtkAboutDialog *about,
							   const gchar    *link,
							   gpointer        data)
{
	if (g_app_info_launch_default_for_uri (link, NULL, NULL) == FALSE) {
		g_warning ("Couldn't show URL: '%s'", link);
	}
}
Example #10
0
void
cb_help_contents (GtkAction *action, gpointer data)
{
    GError* error = 0;
    if (!g_app_info_launch_default_for_uri("help:mate-system-monitor", NULL, &error)) {
        g_warning("Could not display help : %s", error->message);
        g_error_free(error);
    }
}
Example #11
0
gboolean
gtk_show_uri (GdkScreen*   screen,
              const gchar* uri,
              guint32      timestamp,
              GError**     error)
{
    g_return_val_if_fail (uri != NULL, FALSE);

    return g_app_info_launch_default_for_uri (uri, NULL, NULL);
}
Example #12
0
File: UgUtils.c Project: Endz0/uget
gboolean	ug_launch_uri (const gchar* uri)
{
	GError* error = NULL;

	g_app_info_launch_default_for_uri (uri, NULL, &error);
	if (error) {
		g_error_free (error);
		return FALSE;
	}
	return TRUE;
}
Example #13
0
static gboolean
shell_utils_manage_quick_reference (EShell *shell,
                                    gboolean only_test)
{
    const gchar * const *language_names;
    gboolean app_launched = FALSE;
    gboolean found_any = FALSE;

    language_names = g_get_language_names ();
    while (*language_names != NULL && !app_launched) {
        const gchar *language = *language_names++;
        gchar *filename;

        /* This must be a valid language AND a language with
         * no encoding suffix.  The next language should have
         * no encoding suffix. */
        if (language == NULL || strchr (language, '.') != NULL)
            continue;

        filename = g_build_filename (
                       EVOLUTION_HELPDIR, "quickref",
                       language, "quickref.pdf", NULL);

        if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
            found_any = TRUE;

            if (!only_test) {
                GFile *file;
                gchar *uri;
                GError *error = NULL;

                file = g_file_new_for_path (filename);
                uri = g_file_get_uri (file);

                app_launched = g_app_info_launch_default_for_uri (
                                   uri, NULL, &error);

                if (error != NULL) {
                    /* FIXME Show an error dialog. */
                    g_warning ("%s", error->message);
                    g_error_free (error);
                }

                g_object_unref (file);
                g_free (uri);
            }
        }

        g_free (filename);
    }

    return found_any;
}
Example #14
0
NS_IMETHODIMP
nsGIOService::ShowURI(nsIURI* aURI)
{
  nsCAutoString spec;
  aURI->GetSpec(spec);
  GError *error = NULL;
  if (!g_app_info_launch_default_for_uri(spec.get(), NULL, &error)) {
    g_warning("Could not launch default application for URI: %s" ,error->message);
    g_error_free(error);
    return NS_ERROR_FAILURE;
  }
  return NS_OK;
}
Example #15
0
static VALUE
appinfo_launch_default_for_uri(int argc, VALUE *argv, VALUE self)
{
        VALUE uri, launch_context;
        GError *error;

        rb_scan_args(argc, argv, "11", &uri, &launch_context);
        if (!g_app_info_launch_default_for_uri(RVAL2CSTR(uri),
                                               RVAL2GAPPLAUNCHCONTEXT(launch_context),
                                               &error))
                rbgio_raise_error(error);

        return self;
}
Example #16
0
static void
help_cb (GtkAction *action, SeahorseApplet *sapplet)
{
	gchar const *document = "ghelp:seahorse-applet";
	GtkWidget *dialog;
	GError *error = NULL;
    
	if (!g_app_info_launch_default_for_uri (document, NULL, &error)) {
		dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, 
		                                 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, 
		                                 _("Could not display URL: %s"),
		                                 error && error->message ? error->message : "");
		g_signal_connect (G_OBJECT (dialog), "response",
		                  G_CALLBACK (gtk_widget_destroy), NULL);
		gtk_widget_show (dialog);
	}
}
Example #17
0
/**
 * mate_url_show_on_screen:
 * @url: The url to display. Should begin with the protocol to use (e.g.
 * "http:", "ghelp:", etc)
 * @screen: a #GdkScreen.
 * @error: Used to store any errors that result from trying to display the @url.
 *
 * Description: Like mate_url_show(), but ensures that the viewer application
 * appears on @screen.
 *
 * Returns: %TRUE if everything went fine, %FALSE otherwise (in which case
 * @error will contain the actual error).
 * 
 * Since: 2.6
 **/
gboolean
mate_url_show_on_screen (const char  *url,
			  GdkScreen   *screen,
			  GError     **error)
{
	gboolean   retval;
	GdkAppLaunchContext *context;

	context = gdk_app_launch_context_new ();
	gdk_app_launch_context_set_screen (context, screen);

	retval = g_app_info_launch_default_for_uri (url, context, error);

	g_object_unref (context);

	return retval;
}
static void
prefs_dialog_button_pressed (GtkDialog *dialog, gint id, gpointer data)
{
    if (id == GTK_RESPONSE_HELP)
    {
        GError* error = 0;
        if (!g_app_info_launch_default_for_uri("help:mate-system-monitor/mate-system-monitor-prefs", NULL, &error))
        {
            g_warning("Could not display preferences help : %s", error->message);
            g_error_free(error);
        }
    }
    else
    {
        gtk_widget_destroy (GTK_WIDGET (dialog));
        prefs_dialog = NULL;
    }
}
static void
command_quick_reference (BonoboUIComponent *uih,
                         EShellWindow *window,
                         const char *path)
{
    char *quickref;
    const gchar * const *language_names;

    language_names = g_get_language_names ();
    while (*language_names != NULL) {
        const gchar *lang = *language_names++;

        /* This has to be a valid language AND a language with
         * no encoding postfix.  The language will come up without
         * encoding next */
        if (lang == NULL || strchr (lang, '.') != NULL)
            continue;

        quickref = g_build_filename (EVOLUTION_HELPDIR, "quickref", lang, "quickref.pdf", NULL);
        if (g_file_test (quickref, G_FILE_TEST_EXISTS)) {
            GFile *file = g_file_new_for_path (quickref);

            if (file) {
                GError *error = NULL;
                char *uri = g_file_get_uri (file);

                g_app_info_launch_default_for_uri (uri, NULL, &error);

                if (error) {
                    g_warning ("%s", error->message);
                    g_error_free (error);
                }

                g_object_unref (file);
                g_free (uri);
            }

            g_free (quickref);
            return;
        }

        g_free (quickref);
    }
}
void
nemo_connect_server_dialog_display_location_async (NemoConnectServerDialog *self,
						       GFile *location,
						       GAsyncReadyCallback callback,
						       gpointer user_data)
{
	GError *error;
	GdkAppLaunchContext *launch_context;
	gchar *uri;

	display_location_res = g_simple_async_result_new (G_OBJECT (self),
							  callback, user_data,
							  nemo_connect_server_dialog_display_location_async);

	error = NULL;
	uri = g_file_get_uri (location);

	if (just_print_uri) {
		g_print ("%s\n", uri);
	}
	else {
		launch_context = gdk_display_get_app_launch_context (gtk_widget_get_display (GTK_WIDGET (self)));
		gdk_app_launch_context_set_screen (launch_context,
						   gtk_widget_get_screen (GTK_WIDGET (self)));

		g_app_info_launch_default_for_uri (uri,
						   G_APP_LAUNCH_CONTEXT (launch_context),
						   &error);

		g_object_unref (launch_context);
	}

	if (error != NULL) {
		g_simple_async_result_set_from_error (display_location_res, error);
		g_error_free (error);
	}

	g_simple_async_result_complete_in_idle (display_location_res);

	g_free (uri);
	g_object_unref (display_location_res);
	display_location_res = NULL;
}
gboolean
open_file_with_application (GtkWidget * window,
                            const gchar * file,
                            GAppInfo * app)
{
	GdkAppLaunchContext * context;
	GdkScreen * screen;
	gboolean result;

	if (g_file_test (file, G_FILE_TEST_IS_DIR) == TRUE) {
		return FALSE;
	}

	context = gdk_app_launch_context_new ();
	screen = gtk_widget_get_screen (window);
	gdk_app_launch_context_set_screen (context, screen);

	if (app == NULL) {
		gchar * uri;

		uri = g_filename_to_uri (file, NULL, NULL);
		result = g_app_info_launch_default_for_uri (uri, (GAppLaunchContext *) context, NULL);
		g_free (uri);
	}
	else {
		GList * g_file_list = NULL;
		GFile * g_file = NULL;

		g_file = g_file_new_for_path (file);

		if (g_file == NULL) {
			result = FALSE;
		}
		else {
			g_file_list = g_list_prepend (g_file_list, g_file);

			result = g_app_info_launch (app, g_file_list, (GAppLaunchContext *) context, NULL);
			g_list_free (g_file_list);
			g_object_unref (g_file);
		}
	}
	return result;
}
void vfs_backend_launch_uri (const gchar *cURI)
{
	g_return_if_fail (cURI != NULL);
	GError *erreur = NULL;
	gchar *cFullURI = (*cURI == '/' ? g_strconcat ("file://", cURI, NULL) : g_strdup (cURI));
	cd_message ("%s (%s)", __func__, cFullURI);
	
	gchar *cTargetURI = _cd_find_target_uri (cFullURI);
	gboolean bSuccess = g_app_info_launch_default_for_uri (cTargetURI != NULL ? cTargetURI : cFullURI,
		NULL,
		&erreur);
	g_free (cFullURI);
	g_free (cTargetURI);
	if (erreur != NULL)
	{
		cd_warning ("gnome_integration : couldn't launch '%s' [%s]", cURI, erreur->message);
		g_error_free (erreur);
	}
}
Example #23
0
NS_IMETHODIMP
nsGIOService::ShowURIForInput(const nsACString& aUri)
{
  GFile *file = g_file_new_for_commandline_arg(PromiseFlatCString(aUri).get());
  char* spec = g_file_get_uri(file);
  nsresult rv = NS_ERROR_FAILURE;
  GError *error = NULL;

  g_app_info_launch_default_for_uri(spec, NULL, &error);
  if (error) {
    g_warning("Cannot launch default application: %s", error->message);
    g_error_free(error);
  } else {
    rv = NS_OK;
  }
  g_object_unref(file);
  g_free(spec);

  return rv;
}
int main(int argc, char* argv[])
{
    GError* err = NULL;
    GFile* file;
    char* uri;

    if (argc < 2)
    {
        fprintf(stderr, "Usage: %s <url>\n", argv[0]);
        return 1;
    }

    mate_program_init("mate-url-show", VERSION, LIBMATE_MODULE, argc, argv, NULL);

    file = g_file_new_for_commandline_arg(argv[1]);

    if (g_file_is_native(file) && !is_file_uri_with_anchor(argv[1]))
    {
        uri = g_file_get_uri(file);
    }
    else
    {
        /* For uris, use the original string, as it might be
        modified by passing throught GFile (e.g. mailto: links) */
        uri = g_strdup(argv[1]);
    }

    g_object_unref(file);

    if (g_app_info_launch_default_for_uri(uri, NULL, &err))
    {
        return 0;
    }

    fprintf(stderr, _("Error showing url: %s\n"), err->message);
    g_error_free(err);

    return 1;
}
Example #25
0
JS_EXPORT_API
gboolean dcore_open_browser(char const* origin_uri)
{
    if (origin_uri == NULL || origin_uri[0] == '\0') {
        return FALSE;
    }

    char* uri = g_uri_unescape_string(origin_uri,
                                      G_URI_RESERVED_CHARS_ALLOWED_IN_PATH);
    char* scheme = g_uri_parse_scheme(uri);
    if (scheme == NULL) {
        char* uri_without_scheme = uri;
        uri = g_strconcat("http://", uri_without_scheme, NULL);
        g_free(uri_without_scheme);
    }
    g_free(scheme);

    gboolean launch_result = g_app_info_launch_default_for_uri(uri, NULL,
                                                               NULL);
    g_free(uri);

    return launch_result;
}
Example #26
0
static gboolean
policy_cb (WebKitWebView *v, WebKitPolicyDecision *pd, WebKitPolicyDecisionType pt, gpointer d)
{
  if (is_loaded && !options.html_data.browser)
    {
      WebKitNavigationAction *act = webkit_navigation_policy_decision_get_navigation_action (WEBKIT_NAVIGATION_POLICY_DECISION (pd));
      webkit_policy_decision_ignore (pd);
      if (webkit_navigation_action_get_navigation_type (act) == WEBKIT_NAVIGATION_TYPE_LINK_CLICKED)
        {
          WebKitURIRequest *r = webkit_navigation_action_get_request (act);
          gchar *uri = (gchar *) webkit_uri_request_get_uri (r);

          if (options.html_data.print_uri)
            g_printf ("%s\n", uri);
          else
            g_app_info_launch_default_for_uri (uri, NULL, NULL);
        }
    }
  else
    return FALSE;

  return TRUE;
}
static void
CappletResponse (GtkDialog * dialog, gint response)
{
	if (response == GTK_RESPONSE_HELP) {
		GError *error = NULL;
		GdkAppLaunchContext *ctx = gdk_app_launch_context_new ();

		g_app_info_launch_default_for_uri
		    ("ghelp:matekbd?gkb-indicator-applet-plugins",
		     G_APP_LAUNCH_CONTEXT (ctx), &error);

		if (error) {
			GtkWidget *d = NULL;

			d = gtk_message_dialog_new (GTK_WINDOW (dialog),
						    GTK_DIALOG_MODAL |
						    GTK_DIALOG_DESTROY_WITH_PARENT,
						    GTK_MESSAGE_ERROR,
						    GTK_BUTTONS_CLOSE,
						    "%s", _
						    ("Unable to open help file"));
			gtk_message_dialog_format_secondary_text
			    (GTK_MESSAGE_DIALOG (d), "%s", error->message);
			g_signal_connect (d, "response",
					  G_CALLBACK (gtk_widget_destroy),
					  NULL);
			gtk_window_present (GTK_WINDOW (d));

			g_error_free (error);
		}

		return;
	}

	g_main_loop_quit (loop);
}
Example #28
0
static void remmina_main_action_help_wiki(GtkAction *action, RemminaMain *remminamain)
{
	g_app_info_launch_default_for_uri("http://sourceforge.net/apps/mediawiki/remmina/", NULL, NULL);
}
Example #29
0
int
main (int argc, char *argv[])
{
    gboolean kill_shell;
    gboolean no_default_window;
    gboolean browser_window;
    gboolean no_desktop;
    gboolean version;
    gboolean autostart_mode;
    const char *autostart_id;
    gchar *geometry;
    gchar **remaining;
    gboolean perform_self_check;
    CajaApplication *application;
    GOptionContext *context;
    GFile *file = NULL;
    GFileInfo *fileinfo = NULL;
    GAppInfo *appinfo = NULL;
    char *uri = NULL;
    char **uris = NULL;
    GPtrArray *uris_array;
    GError *error;
    int i;

    const GOptionEntry options[] =
    {
#ifndef CAJA_OMIT_SELF_CHECK
        {
            "check", 'c', 0, G_OPTION_ARG_NONE, &perform_self_check,
            N_("Perform a quick set of self-check tests."), NULL
        },
#endif
        {
            "version", '\0', 0, G_OPTION_ARG_NONE, &version,
            N_("Show the version of the program."), NULL
        },
        {
            "geometry", 'g', 0, G_OPTION_ARG_STRING, &geometry,
            N_("Create the initial window with the given geometry."), N_("GEOMETRY")
        },
        {
            "no-default-window", 'n', 0, G_OPTION_ARG_NONE, &no_default_window,
            N_("Only create windows for explicitly specified URIs."), NULL
        },
        {
            "no-desktop", '\0', 0, G_OPTION_ARG_NONE, &no_desktop,
            N_("Do not manage the desktop (ignore the preference set in the preferences dialog)."), NULL
        },
        {
            "browser", '\0', 0, G_OPTION_ARG_NONE, &browser_window,
            N_("open a browser window."), NULL
        },
        {
            "quit", 'q', 0, G_OPTION_ARG_NONE, &kill_shell,
            N_("Quit Caja."), NULL
        },
        { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining, NULL,  N_("[URI...]") },

        { NULL }
    };

#if defined (HAVE_MALLOPT) && defined(M_MMAP_THRESHOLD)
    /* Caja uses lots and lots of small and medium size allocations,
     * and then a few large ones for the desktop background. By default
     * glibc uses a dynamic treshold for how large allocations should
     * be mmaped. Unfortunately this triggers quickly for caja when
     * it does the desktop background allocations, raising the limit
     * such that a lot of temporary large allocations end up on the
     * heap and are thus not returned to the OS. To fix this we set
     * a hardcoded limit. I don't know what a good value is, but 128K
     * was the old glibc static limit, lets use that.
     */
    mallopt (M_MMAP_THRESHOLD, 128 *1024);
#endif

    g_thread_init (NULL);

    /* This will be done by gtk+ later, but for now, force it to MATE */
    g_desktop_app_info_set_desktop_env ("MATE");

    if (g_getenv ("CAJA_DEBUG") != NULL)
    {
        eel_make_warnings_and_criticals_stop_in_debugger ();
    }

    /* Initialize gettext support */
    bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
    textdomain (GETTEXT_PACKAGE);

    autostart_mode = FALSE;

    autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID");
    if (autostart_id != NULL && *autostart_id != '\0')
    {
        autostart_mode = TRUE;
    }

    /* Get parameters. */
    remaining = NULL;
    geometry = NULL;
    version = FALSE;
    kill_shell = FALSE;
    no_default_window = FALSE;
    no_desktop = FALSE;
    perform_self_check = FALSE;
    browser_window = FALSE;

    g_set_prgname ("caja");

    if (g_file_test (DATADIR "/applications/caja.desktop", G_FILE_TEST_EXISTS))
    {
        egg_set_desktop_file (DATADIR "/applications/caja.desktop");
    }

    context = g_option_context_new (_("\n\nBrowse the file system with the file manager"));
    g_option_context_add_main_entries (context, options, NULL);

    g_option_context_add_group (context, gtk_get_option_group (TRUE));
    g_option_context_add_group (context, egg_sm_client_get_option_group ());

    error = NULL;
    if (!g_option_context_parse (context, &argc, &argv, &error))
    {
        g_printerr ("Could not parse arguments: %s\n", error->message);
        g_error_free (error);
        return 1;
    }

    g_option_context_free (context);

    if (version)
    {
        g_print ("MATE caja " PACKAGE_VERSION "\n");
        return 0;
    }

#ifdef HAVE_EXEMPI
    xmp_init();
#endif

    setup_debug_log ();

    /* If in autostart mode (aka started by mate-session), we need to ensure
         * caja starts with the correct options.
         */
    if (autostart_mode)
    {
        no_default_window = TRUE;
        no_desktop = FALSE;
    }

    if (perform_self_check && remaining != NULL)
    {
        /* translators: %s is an option (e.g. --check) */
        fprintf (stderr, _("caja: %s cannot be used with URIs.\n"),
                 "--check");
        return EXIT_FAILURE;
    }
    if (perform_self_check && kill_shell)
    {
        fprintf (stderr, _("caja: --check cannot be used with other options.\n"));
        return EXIT_FAILURE;
    }
    if (kill_shell && remaining != NULL)
    {
        fprintf (stderr, _("caja: %s cannot be used with URIs.\n"),
                 "--quit");
        return EXIT_FAILURE;
    }
    if (geometry != NULL && remaining != NULL && remaining[0] != NULL && remaining[1] != NULL)
    {
        fprintf (stderr, _("caja: --geometry cannot be used with more than one URI.\n"));
        return EXIT_FAILURE;
    }

    /* Initialize the services that we use. */
    LIBXML_TEST_VERSION

    /* Initialize preferences. This is needed so that proper
     * defaults are available before any preference peeking
     * happens.
     */
    caja_global_preferences_init ();

    /* exit_with_last_window being FALSE, caja can run without window. */
    exit_with_last_window = g_settings_get_boolean (caja_preferences, CAJA_PREFERENCES_EXIT_WITH_LAST_WINDOW);

    application = NULL;

    /* Do either the self-check or the real work. */
    if (perform_self_check)
    {
		#ifndef CAJA_OMIT_SELF_CHECK
			/* Run the checks (each twice) for caja and libcaja-private. */

			caja_run_self_checks ();
			caja_run_lib_self_checks ();
			eel_exit_if_self_checks_failed ();

			caja_run_self_checks ();
			caja_run_lib_self_checks ();
			eel_exit_if_self_checks_failed ();
		#endif
    }
    else
    {
        /* Convert args to URIs */
        if (remaining != NULL)
        {
            uris_array = g_ptr_array_new ();
            for (i = 0; remaining[i] != NULL; i++)
            {
                file = g_file_new_for_commandline_arg (remaining[i]);
                if (file != NULL)
                {
                    uri = g_file_get_uri (file);
                    if (uri)
                    {
                        fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL);
                        if (fileinfo && g_file_info_get_file_type(fileinfo) == G_FILE_TYPE_DIRECTORY)
                        {
                            g_ptr_array_add (uris_array, uri);
                        }
                        else
                        {
                            if (fileinfo)
                                g_object_unref (fileinfo);
                            fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL);
                            if (fileinfo)
                            {
                                appinfo = g_app_info_get_default_for_type (g_file_info_get_content_type (fileinfo), TRUE);
                                if (appinfo)
                                {
                                    if (g_strcmp0 (g_app_info_get_executable (appinfo), "caja") != 0)
                                    {
                                        g_app_info_launch_default_for_uri (uri, NULL, NULL);
                                    }
                                    else
                                    {
                                        fprintf (stderr, _("caja: set erroneously as default application for '%s' content type.\n"),
                                                 g_file_info_get_content_type (fileinfo));
                                    }
                                    g_object_unref (appinfo);
                                }
                                g_free (uri);
                            }
                            else
                            {
                                g_ptr_array_add (uris_array, uri);
                            }
                        }
                        if (fileinfo)
                            g_object_unref (fileinfo);
                    }
                    if (file)
                        g_object_unref (file);
                }
            }
            if (uris_array->len == 0)
            {
                /* Caja is being used only to open files (not directories), so closing */
                g_strfreev (remaining);
                return EXIT_SUCCESS;
            }
            g_ptr_array_add (uris_array, NULL);
            uris = (char**) g_ptr_array_free (uris_array, FALSE);
            g_strfreev (remaining);
        }


        /* Run the caja application. */
        application = caja_application_new ();

        if (egg_sm_client_is_resumed (application->smclient))
        {
            no_default_window = TRUE;
        }

        caja_application_startup
        (application,
         kill_shell, no_default_window, no_desktop,
         browser_window,
         geometry,
         uris);
        g_strfreev (uris);

        if (unique_app_is_running (application->unique_app) ||
                kill_shell)
        {
            exit_with_last_window = TRUE;
        }

        if (is_event_loop_needed ())
        {
            gtk_main ();
        }
    }

    caja_icon_info_clear_caches ();

    if (application != NULL)
    {
        g_object_unref (application);
    }

    eel_debug_shut_down ();

    caja_application_save_accel_map (NULL);

    return EXIT_SUCCESS;
}
Example #30
0
static void remmina_main_action_help_homepage(GtkAction *action, RemminaMain *remminamain)
{
	g_app_info_launch_default_for_uri("http://remmina.sourceforge.net", NULL, NULL);
}