Beispiel #1
0
static VALUE
rg_s_can_be_executable_p(G_GNUC_UNUSED VALUE type)
{
        return CBOOL2RVAL(g_content_type_can_be_executable(RVAL2CSTR(type)));
}
Beispiel #2
0
static gboolean exec_filter_func(const GtkFileFilterInfo *filter_info, gpointer data)
{
	if(g_content_type_can_be_executable(filter_info->mime_type))
		return TRUE;
	return FALSE;
}
gboolean
activate_file (GFile* file, const char* content_type,
               gboolean is_executable, GFile* _file_arg)
{
    char* file_name = g_file_get_basename (file);
    gboolean is_bin = g_str_has_suffix(file_name, ".bin");
    gboolean result = TRUE;

    g_debug ("activate_file: %s", file_name);
    g_free (file_name);
    g_debug ("content_type: %s", content_type);

    if (is_executable &&
        (g_content_type_can_be_executable (content_type) || is_bin))
    {
        g_debug("is_executable && g_content_type_can_be_executable || is_bin");
        //1. an executable text file. or an shell script
        if (g_content_type_is_a (content_type, "text/plain"))
        {
            g_debug("g_content_type_is_a");
            GtkWidget* dialog;
            int response;
            char* file_name;
            char* prompt;
            char* detail;

            file_name = g_file_get_basename (file);
            prompt = g_strdup_printf (_("Do you want to run \"%s\", or display its contents?"), file_name);
            detail = g_strdup_printf (_("\"%s\" is an executable text file."), file_name);
            g_free (file_name);
            //create prompt dialog
            dialog = gtk_message_dialog_new (NULL,
                                             GTK_DIALOG_MODAL,
                                             GTK_MESSAGE_QUESTION,
                                             GTK_BUTTONS_NONE,
                                             NULL);
            g_object_set (dialog, "text", prompt, "secondary-text", detail, NULL);
            g_free (prompt);
            g_free (detail);
            gtk_dialog_add_button (GTK_DIALOG(dialog), _("Run in _Terminal"), RESPONSE_RUN_IN_TERMINAL);
            gtk_dialog_add_button (GTK_DIALOG(dialog), _("_Display"), RESPONSE_DISPLAY);
            gtk_dialog_add_button (GTK_DIALOG(dialog), "_Cancel", GTK_RESPONSE_CANCEL);
            gtk_dialog_add_button (GTK_DIALOG(dialog), _("_Run"), RESPONSE_RUN);
            gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);

            gtk_widget_show (GTK_WIDGET (dialog));

            response = gtk_dialog_run (GTK_DIALOG(dialog));
            gtk_widget_destroy (GTK_WIDGET (dialog));

            g_message("response:%d",response);
            switch (response)
            {
            case RESPONSE_RUN_IN_TERMINAL:
                run_file_in_terminal (file);
                break;
            case RESPONSE_DISPLAY:
                result = display_file (file, content_type);
                break;
            case RESPONSE_RUN:
                run_file (file, NULL);
                break;
            case GTK_RESPONSE_CANCEL:
                break;
            default:
                break;
            }
        }
        //2. an executable binary file
        else
        {
            g_debug("run_file");
            run_file (file, _file_arg);
        }
    }
    //for non-executables just open it.
    else
    {
        g_debug("for non-executables just open it.");
        result = display_file (file, content_type);
    }

    return result;
}
int content_type_can_be_executable(char* type)
{
    return g_content_type_can_be_executable(type);
}