Imported Upstream version 0.4.2
YunQiang Su
12 years ago
75 | 75 | |
76 | 76 | void begin_key_grab(KeyGrabButton* self, gpointer v) |
77 | 77 | { |
78 | gtk_widget_add_events(GTK_WIDGET(self), GDK_KEY_PRESS_MASK); | |
79 | 78 | KeyGrabButton* b = KEYGRAB_BUTTON(self); |
80 | 79 | b->popup = popup_new(GTK_WIDGET(self), _("Please press the new key combination"), FALSE); |
80 | gtk_widget_add_events(GTK_WIDGET(b->popup), GDK_KEY_PRESS_MASK); | |
81 | 81 | gtk_widget_show_all(b->popup); |
82 | 82 | b->handler = g_signal_connect(G_OBJECT(b->popup), "key-press-event", (GCallback)on_key_press_event, b); |
83 | 83 | |
127 | 127 | |
128 | 128 | void keygrab_button_set_key(KeyGrabButton* self, guint key, GdkModifierType mods) |
129 | 129 | { |
130 | if (mods & GDK_SUPER_MASK) { | |
131 | mods &= ~GDK_SUPER_MASK; | |
132 | mods |= FcitxKeyState_Super; | |
133 | } | |
130 | 134 | KeyGrabButton* b = KEYGRAB_BUTTON(self); |
131 | 135 | gchar *label; |
132 | 136 | b->key = key; |
31 | 31 | #include "sub_config_parser.h" |
32 | 32 | |
33 | 33 | static void sub_config_pattern_free(void* pattern); |
34 | static GList* sub_config_pattern_get_filelist(FcitxSubConfigPattern* pattern); | |
34 | static GHashTable* sub_config_pattern_get_filelist(FcitxSubConfigPattern* pattern); | |
35 | 35 | static GList* get_files_by_pattern(const gchar* dirpath, FcitxSubConfigPattern* pattern, int index); |
36 | 36 | static void sub_file_list_free(gpointer data, gpointer user_data); |
37 | 37 | |
184 | 184 | g_free(subconfig->configdesc); |
185 | 185 | g_free(subconfig->nativepath); |
186 | 186 | g_free(subconfig->name); |
187 | g_list_foreach(subconfig->filelist, sub_file_list_free, NULL); | |
188 | g_list_free(subconfig->filelist); | |
187 | g_hash_table_unref(subconfig->filelist); | |
189 | 188 | g_free(subconfig); |
190 | 189 | } |
191 | 190 | |
192 | GList* sub_config_pattern_get_filelist(FcitxSubConfigPattern* pattern) | |
191 | GHashTable* sub_config_pattern_get_filelist(FcitxSubConfigPattern* pattern) | |
193 | 192 | { |
194 | 193 | size_t size, i; |
195 | GList* result = NULL; | |
194 | GHashTable* result = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); | |
196 | 195 | #if FCITX_CHECK_VERSION(4,2,1) |
197 | 196 | char** xdgpath = FcitxXDGGetPathWithPrefix(&size, ""); |
198 | 197 | #else |
212 | 211 | l = l->next) { |
213 | 212 | if (strncmp(dirpath, (gchar*) l->data, strlen(dirpath)) == 0) { |
214 | 213 | gchar* filename = (gchar*) l->data; |
214 | ||
215 | FcitxLog(INFO, "%s", filename); | |
215 | 216 | gchar* name = filename + strlen(dirpath); |
216 | 217 | while (name[0] == '/') |
217 | 218 | name ++; |
218 | result = g_list_append(result, g_strdup(name)); | |
219 | if (!g_hash_table_lookup_extended(result, name, NULL, NULL)) { | |
220 | g_hash_table_insert(result, g_strdup(name), NULL); | |
221 | } | |
219 | 222 | } |
220 | 223 | } |
221 | 224 | g_list_foreach(list, sub_file_list_free, NULL); |
36 | 36 | typedef struct { |
37 | 37 | gchar* name; |
38 | 38 | SubConfigType type; |
39 | GList* filelist; | |
39 | GHashTable* filelist; | |
40 | 40 | gchar* nativepath; |
41 | 41 | gchar* configdesc; |
42 | 42 | } FcitxSubConfig; |
24 | 24 | #include "configdesc.h" |
25 | 25 | #include "config_widget.h" |
26 | 26 | |
27 | G_DEFINE_TYPE(FcitxSubConfigWidget, fcitx_sub_config_widget, GTK_TYPE_VBOX) | |
27 | G_DEFINE_TYPE(FcitxSubConfigWidget, fcitx_sub_config_widget, GTK_TYPE_BOX) | |
28 | 28 | |
29 | 29 | static void open_subconfig_file(GtkButton *button, gpointer user_data); |
30 | 30 | static void open_native_file(GtkButton *button, gpointer user_data); |
31 | static void push_into_store_cb(gpointer data, gpointer user_data); | |
31 | static void push_into_store_cb(gpointer data, gpointer value, gpointer user_data); | |
32 | 32 | |
33 | 33 | static void |
34 | 34 | fcitx_sub_config_widget_get_property(GObject *object, guint property_id, |
96 | 96 | gtk_tree_view_set_model(GTK_TREE_VIEW(view), |
97 | 97 | GTK_TREE_MODEL(store)); |
98 | 98 | |
99 | g_list_foreach(widget->subconfig->filelist, push_into_store_cb, store); | |
99 | g_hash_table_foreach(widget->subconfig->filelist, push_into_store_cb, store); | |
100 | 100 | |
101 | 101 | GtkWidget* button = gtk_button_new(); |
102 | 102 | gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_stock(GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_BUTTON)); |
162 | 162 | { |
163 | 163 | FcitxSubConfigWidget* widget = (FcitxSubConfigWidget*) user_data; |
164 | 164 | char *newpath = NULL; |
165 | if (g_list_length(widget->subconfig->filelist) > 0) { | |
166 | FILE* fp = FcitxXDGGetFileWithPrefix("", widget->subconfig->filelist->data, "r", &newpath); | |
167 | if (fp) | |
168 | fclose(fp); | |
165 | if (g_hash_table_size(widget->subconfig->filelist) > 0) { | |
166 | GHashTableIter iter; | |
167 | g_hash_table_iter_init(&iter, widget->subconfig->filelist); | |
168 | gpointer key; | |
169 | if (g_hash_table_iter_next(&iter, &key, NULL)) { | |
170 | FILE* fp = FcitxXDGGetFileWithPrefix("", key, "r", &newpath); | |
171 | if (fp) | |
172 | fclose(fp); | |
173 | } | |
169 | 174 | } else { |
170 | 175 | FILE* fp = FcitxXDGGetFileUserWithPrefix("", widget->subconfig->nativepath, "w", &newpath); |
171 | 176 | if (fp) { |
172 | widget->subconfig->filelist = g_list_append(widget->subconfig->filelist, widget->subconfig->nativepath); | |
177 | g_hash_table_insert(widget->subconfig->filelist, widget->subconfig->nativepath, NULL); | |
173 | 178 | fclose(fp); |
174 | 179 | } |
175 | 180 | } |
188 | 193 | |
189 | 194 | |
190 | 195 | void push_into_store_cb(gpointer data, |
196 | gpointer value, | |
191 | 197 | gpointer user_data) |
192 | 198 | { |
193 | 199 | GtkListStore* store = user_data; |
426 | 426 | #else |
427 | 427 | gtk_color_button_get_rgba(GTK_COLOR_BUTTON(arg), &color); |
428 | 428 | #endif |
429 | r = color.red / 256; | |
430 | g = color.green / 256; | |
431 | b = color.blue / 256; | |
429 | r = color.red * 256; | |
430 | g = color.green * 256; | |
431 | b = color.blue * 256; | |
432 | 432 | r = RoundColor(r); |
433 | 433 | g = RoundColor(g); |
434 | 434 | b = RoundColor(b); |
75 | 75 | |
76 | 76 | void begin_key_grab(KeyGrabButton* self, gpointer v) |
77 | 77 | { |
78 | gtk_widget_add_events(GTK_WIDGET(self), GDK_KEY_PRESS_MASK); | |
79 | 78 | KeyGrabButton* b = KEYGRAB_BUTTON(self); |
80 | 79 | b->popup = popup_new(GTK_WIDGET(self), _("Please press the new key combination"), FALSE); |
80 | gtk_widget_add_events(GTK_WIDGET(b->popup), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK); | |
81 | 81 | gtk_widget_show_all(b->popup); |
82 | 82 | b->handler = g_signal_connect(G_OBJECT(b->popup), "key-press-event", (GCallback)on_key_press_event, b); |
83 | ||
83 | ||
84 | 84 | GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(b->popup)); |
85 | 85 | GdkDisplay* display = gdk_window_get_display (window); |
86 | 86 | GdkDeviceManager* device_manager = gdk_display_get_device_manager (display); |
90 | 90 | while (gdk_device_grab( |
91 | 91 | keyboard, |
92 | 92 | window, |
93 | GDK_OWNERSHIP_NONE, FALSE, | |
93 | GDK_OWNERSHIP_WINDOW, TRUE, | |
94 | 94 | GDK_KEY_PRESS | GDK_KEY_RELEASE, |
95 | 95 | NULL, |
96 | 96 | GDK_CURRENT_TIME) != GDK_GRAB_SUCCESS) |
144 | 144 | |
145 | 145 | void keygrab_button_set_key(KeyGrabButton* self, guint key, GdkModifierType mods) |
146 | 146 | { |
147 | if (mods & GDK_SUPER_MASK) { | |
148 | mods &= ~GDK_SUPER_MASK; | |
149 | mods |= FcitxKeyState_Super; | |
150 | } | |
147 | 151 | KeyGrabButton* b = KEYGRAB_BUTTON(self); |
148 | 152 | gchar *label; |
149 | 153 | b->key = key; |
31 | 31 | #include "sub_config_parser.h" |
32 | 32 | |
33 | 33 | static void sub_config_pattern_free(void* pattern); |
34 | static GList* sub_config_pattern_get_filelist(FcitxSubConfigPattern* pattern); | |
34 | static GHashTable* sub_config_pattern_get_filelist(FcitxSubConfigPattern* pattern); | |
35 | 35 | static GList* get_files_by_pattern(const gchar* dirpath, FcitxSubConfigPattern* pattern, int index); |
36 | 36 | static void sub_file_list_free(gpointer data, gpointer user_data); |
37 | 37 | |
184 | 184 | g_free(subconfig->configdesc); |
185 | 185 | g_free(subconfig->nativepath); |
186 | 186 | g_free(subconfig->name); |
187 | g_list_foreach(subconfig->filelist, sub_file_list_free, NULL); | |
188 | g_list_free(subconfig->filelist); | |
187 | g_hash_table_unref(subconfig->filelist); | |
189 | 188 | g_free(subconfig); |
190 | 189 | } |
191 | 190 | |
192 | GList* sub_config_pattern_get_filelist(FcitxSubConfigPattern* pattern) | |
191 | GHashTable* sub_config_pattern_get_filelist(FcitxSubConfigPattern* pattern) | |
193 | 192 | { |
194 | 193 | size_t size, i; |
195 | GList* result = NULL; | |
194 | GHashTable* result = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); | |
196 | 195 | #if FCITX_CHECK_VERSION(4,2,1) |
197 | 196 | char** xdgpath = FcitxXDGGetPathWithPrefix(&size, ""); |
198 | 197 | #else |
212 | 211 | l = l->next) { |
213 | 212 | if (strncmp(dirpath, (gchar*) l->data, strlen(dirpath)) == 0) { |
214 | 213 | gchar* filename = (gchar*) l->data; |
214 | ||
215 | FcitxLog(INFO, "%s", filename); | |
215 | 216 | gchar* name = filename + strlen(dirpath); |
216 | 217 | while (name[0] == '/') |
217 | 218 | name ++; |
218 | result = g_list_append(result, g_strdup(name)); | |
219 | if (!g_hash_table_lookup_extended(result, name, NULL, NULL)) { | |
220 | g_hash_table_insert(result, g_strdup(name), NULL); | |
221 | } | |
219 | 222 | } |
220 | 223 | } |
221 | 224 | g_list_foreach(list, sub_file_list_free, NULL); |
36 | 36 | typedef struct { |
37 | 37 | gchar* name; |
38 | 38 | SubConfigType type; |
39 | GList* filelist; | |
39 | GHashTable* filelist; | |
40 | 40 | gchar* nativepath; |
41 | 41 | gchar* configdesc; |
42 | 42 | } FcitxSubConfig; |
28 | 28 | |
29 | 29 | static void open_subconfig_file(GtkButton *button, gpointer user_data); |
30 | 30 | static void open_native_file(GtkButton *button, gpointer user_data); |
31 | static void push_into_store_cb(gpointer data, gpointer user_data); | |
31 | static void push_into_store_cb(gpointer data, gpointer value, gpointer user_data); | |
32 | 32 | |
33 | 33 | static void |
34 | 34 | fcitx_sub_config_widget_get_property(GObject *object, guint property_id, |
96 | 96 | gtk_tree_view_set_model(GTK_TREE_VIEW(view), |
97 | 97 | GTK_TREE_MODEL(store)); |
98 | 98 | |
99 | g_list_foreach(widget->subconfig->filelist, push_into_store_cb, store); | |
99 | g_hash_table_foreach(widget->subconfig->filelist, push_into_store_cb, store); | |
100 | 100 | |
101 | 101 | GtkWidget* button = gtk_button_new(); |
102 | 102 | gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_stock(GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_BUTTON)); |
162 | 162 | { |
163 | 163 | FcitxSubConfigWidget* widget = (FcitxSubConfigWidget*) user_data; |
164 | 164 | char *newpath = NULL; |
165 | if (g_list_length(widget->subconfig->filelist) > 0) { | |
166 | FILE* fp = FcitxXDGGetFileWithPrefix("", widget->subconfig->filelist->data, "r", &newpath); | |
167 | if (fp) | |
168 | fclose(fp); | |
165 | if (g_hash_table_size(widget->subconfig->filelist) > 0) { | |
166 | GHashTableIter iter; | |
167 | g_hash_table_iter_init(&iter, widget->subconfig->filelist); | |
168 | gpointer key; | |
169 | if (g_hash_table_iter_next(&iter, &key, NULL)) { | |
170 | FILE* fp = FcitxXDGGetFileWithPrefix("", key, "r", &newpath); | |
171 | if (fp) | |
172 | fclose(fp); | |
173 | } | |
169 | 174 | } else { |
170 | 175 | FILE* fp = FcitxXDGGetFileUserWithPrefix("", widget->subconfig->nativepath, "w", &newpath); |
171 | 176 | if (fp) { |
172 | widget->subconfig->filelist = g_list_append(widget->subconfig->filelist, widget->subconfig->nativepath); | |
177 | g_hash_table_insert(widget->subconfig->filelist, widget->subconfig->nativepath, NULL); | |
173 | 178 | fclose(fp); |
174 | 179 | } |
175 | 180 | } |
188 | 193 | |
189 | 194 | |
190 | 195 | void push_into_store_cb(gpointer data, |
196 | gpointer value, | |
191 | 197 | gpointer user_data) |
192 | 198 | { |
193 | 199 | GtkListStore* store = user_data; |