1 |
root |
1.1 |
#define _GNU_SOURCE |
2 |
|
|
|
3 |
|
|
#include <dlfcn.h> |
4 |
|
|
#include <glib.h> |
5 |
|
|
#include <gtk/gtk.h> |
6 |
|
|
#include <stdlib.h> |
7 |
|
|
|
8 |
|
|
static char *helper = "/etc/gtkbfc-helper"; |
9 |
|
|
|
10 |
|
|
static GObject *(*old_constructor) (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties); |
11 |
|
|
|
12 |
|
|
static gboolean activate_cb (gpointer data) |
13 |
|
|
{ |
14 |
|
|
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (data), FALSE); |
15 |
|
|
g_signal_emit_by_name (GTK_FILE_CHOOSER (data), "file-activated"); |
16 |
|
|
return FALSE; |
17 |
|
|
} |
18 |
|
|
|
19 |
|
|
static gboolean show_cb (GtkWidget *widget, GdkEvent *event, gpointer user_data) |
20 |
|
|
{ |
21 |
|
|
gchar *argv[3]; |
22 |
|
|
gchar *output; |
23 |
|
|
|
24 |
|
|
argv [0] = helper; |
25 |
|
|
argv [1] = "hulla"; |
26 |
|
|
argv [2] = 0; |
27 |
|
|
|
28 |
|
|
if (g_spawn_sync (0, argv, 0, 0, 0, 0, &output, 0, 0, 0)) |
29 |
|
|
{ |
30 |
|
|
fprintf (stderr, "out<%s>\n", output); |
31 |
root |
1.2 |
|
32 |
|
|
if (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (widget)) == GTK_FILE_CHOOSER_ACTION_SAVE |
33 |
|
|
|| gtk_file_chooser_get_action (GTK_FILE_CHOOSER (widget)) == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER) |
34 |
|
|
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (widget), output); |
35 |
|
|
else |
36 |
|
|
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), output); |
37 |
root |
1.1 |
|
38 |
|
|
g_free (output); |
39 |
|
|
|
40 |
|
|
//gtk_widget_hide (widget); |
41 |
root |
1.2 |
g_timeout_add (1000, activate_cb, widget); |
42 |
root |
1.1 |
} |
43 |
|
|
else |
44 |
|
|
;//gtk_widget_show (widget); |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
static GObject *new_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) |
48 |
|
|
{ |
49 |
|
|
GObject *ob = old_constructor (type, n_construct_properties, construct_properties); |
50 |
|
|
g_signal_connect_after (ob, "map", G_CALLBACK (show_cb), 0); |
51 |
|
|
return ob; |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
__attribute__ ((constructor)) |
55 |
|
|
static void init () |
56 |
|
|
{ |
57 |
|
|
//helper = getenv ("GTKBFC_HELPER"); |
58 |
|
|
|
59 |
|
|
if (helper) |
60 |
|
|
{ |
61 |
|
|
g_type_init (); |
62 |
|
|
|
63 |
|
|
GType type = GTK_TYPE_FILE_CHOOSER_WIDGET; |
64 |
|
|
GObjectClass *klass = g_type_class_ref (type); |
65 |
|
|
|
66 |
|
|
old_constructor = klass->constructor; |
67 |
|
|
klass->constructor = new_constructor; |
68 |
|
|
} |
69 |
|
|
} |
70 |
|
|
|