Codebase list fcitx-configtool / da81983
Imported Upstream version 0.4.2 YunQiang Su 12 years ago
9 changed file(s) with 62 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
7575
7676 void begin_key_grab(KeyGrabButton* self, gpointer v)
7777 {
78 gtk_widget_add_events(GTK_WIDGET(self), GDK_KEY_PRESS_MASK);
7978 KeyGrabButton* b = KEYGRAB_BUTTON(self);
8079 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);
8181 gtk_widget_show_all(b->popup);
8282 b->handler = g_signal_connect(G_OBJECT(b->popup), "key-press-event", (GCallback)on_key_press_event, b);
8383
127127
128128 void keygrab_button_set_key(KeyGrabButton* self, guint key, GdkModifierType mods)
129129 {
130 if (mods & GDK_SUPER_MASK) {
131 mods &= ~GDK_SUPER_MASK;
132 mods |= FcitxKeyState_Super;
133 }
130134 KeyGrabButton* b = KEYGRAB_BUTTON(self);
131135 gchar *label;
132136 b->key = key;
3131 #include "sub_config_parser.h"
3232
3333 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);
3535 static GList* get_files_by_pattern(const gchar* dirpath, FcitxSubConfigPattern* pattern, int index);
3636 static void sub_file_list_free(gpointer data, gpointer user_data);
3737
184184 g_free(subconfig->configdesc);
185185 g_free(subconfig->nativepath);
186186 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);
189188 g_free(subconfig);
190189 }
191190
192 GList* sub_config_pattern_get_filelist(FcitxSubConfigPattern* pattern)
191 GHashTable* sub_config_pattern_get_filelist(FcitxSubConfigPattern* pattern)
193192 {
194193 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);
196195 #if FCITX_CHECK_VERSION(4,2,1)
197196 char** xdgpath = FcitxXDGGetPathWithPrefix(&size, "");
198197 #else
212211 l = l->next) {
213212 if (strncmp(dirpath, (gchar*) l->data, strlen(dirpath)) == 0) {
214213 gchar* filename = (gchar*) l->data;
214
215 FcitxLog(INFO, "%s", filename);
215216 gchar* name = filename + strlen(dirpath);
216217 while (name[0] == '/')
217218 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 }
219222 }
220223 }
221224 g_list_foreach(list, sub_file_list_free, NULL);
3636 typedef struct {
3737 gchar* name;
3838 SubConfigType type;
39 GList* filelist;
39 GHashTable* filelist;
4040 gchar* nativepath;
4141 gchar* configdesc;
4242 } FcitxSubConfig;
2424 #include "configdesc.h"
2525 #include "config_widget.h"
2626
27 G_DEFINE_TYPE(FcitxSubConfigWidget, fcitx_sub_config_widget, GTK_TYPE_VBOX)
27 G_DEFINE_TYPE(FcitxSubConfigWidget, fcitx_sub_config_widget, GTK_TYPE_BOX)
2828
2929 static void open_subconfig_file(GtkButton *button, gpointer user_data);
3030 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);
3232
3333 static void
3434 fcitx_sub_config_widget_get_property(GObject *object, guint property_id,
9696 gtk_tree_view_set_model(GTK_TREE_VIEW(view),
9797 GTK_TREE_MODEL(store));
9898
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);
100100
101101 GtkWidget* button = gtk_button_new();
102102 gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_stock(GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_BUTTON));
162162 {
163163 FcitxSubConfigWidget* widget = (FcitxSubConfigWidget*) user_data;
164164 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 }
169174 } else {
170175 FILE* fp = FcitxXDGGetFileUserWithPrefix("", widget->subconfig->nativepath, "w", &newpath);
171176 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);
173178 fclose(fp);
174179 }
175180 }
188193
189194
190195 void push_into_store_cb(gpointer data,
196 gpointer value,
191197 gpointer user_data)
192198 {
193199 GtkListStore* store = user_data;
426426 #else
427427 gtk_color_button_get_rgba(GTK_COLOR_BUTTON(arg), &color);
428428 #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;
432432 r = RoundColor(r);
433433 g = RoundColor(g);
434434 b = RoundColor(b);
7575
7676 void begin_key_grab(KeyGrabButton* self, gpointer v)
7777 {
78 gtk_widget_add_events(GTK_WIDGET(self), GDK_KEY_PRESS_MASK);
7978 KeyGrabButton* b = KEYGRAB_BUTTON(self);
8079 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);
8181 gtk_widget_show_all(b->popup);
8282 b->handler = g_signal_connect(G_OBJECT(b->popup), "key-press-event", (GCallback)on_key_press_event, b);
83
83
8484 GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(b->popup));
8585 GdkDisplay* display = gdk_window_get_display (window);
8686 GdkDeviceManager* device_manager = gdk_display_get_device_manager (display);
9090 while (gdk_device_grab(
9191 keyboard,
9292 window,
93 GDK_OWNERSHIP_NONE, FALSE,
93 GDK_OWNERSHIP_WINDOW, TRUE,
9494 GDK_KEY_PRESS | GDK_KEY_RELEASE,
9595 NULL,
9696 GDK_CURRENT_TIME) != GDK_GRAB_SUCCESS)
144144
145145 void keygrab_button_set_key(KeyGrabButton* self, guint key, GdkModifierType mods)
146146 {
147 if (mods & GDK_SUPER_MASK) {
148 mods &= ~GDK_SUPER_MASK;
149 mods |= FcitxKeyState_Super;
150 }
147151 KeyGrabButton* b = KEYGRAB_BUTTON(self);
148152 gchar *label;
149153 b->key = key;
3131 #include "sub_config_parser.h"
3232
3333 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);
3535 static GList* get_files_by_pattern(const gchar* dirpath, FcitxSubConfigPattern* pattern, int index);
3636 static void sub_file_list_free(gpointer data, gpointer user_data);
3737
184184 g_free(subconfig->configdesc);
185185 g_free(subconfig->nativepath);
186186 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);
189188 g_free(subconfig);
190189 }
191190
192 GList* sub_config_pattern_get_filelist(FcitxSubConfigPattern* pattern)
191 GHashTable* sub_config_pattern_get_filelist(FcitxSubConfigPattern* pattern)
193192 {
194193 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);
196195 #if FCITX_CHECK_VERSION(4,2,1)
197196 char** xdgpath = FcitxXDGGetPathWithPrefix(&size, "");
198197 #else
212211 l = l->next) {
213212 if (strncmp(dirpath, (gchar*) l->data, strlen(dirpath)) == 0) {
214213 gchar* filename = (gchar*) l->data;
214
215 FcitxLog(INFO, "%s", filename);
215216 gchar* name = filename + strlen(dirpath);
216217 while (name[0] == '/')
217218 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 }
219222 }
220223 }
221224 g_list_foreach(list, sub_file_list_free, NULL);
3636 typedef struct {
3737 gchar* name;
3838 SubConfigType type;
39 GList* filelist;
39 GHashTable* filelist;
4040 gchar* nativepath;
4141 gchar* configdesc;
4242 } FcitxSubConfig;
2828
2929 static void open_subconfig_file(GtkButton *button, gpointer user_data);
3030 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);
3232
3333 static void
3434 fcitx_sub_config_widget_get_property(GObject *object, guint property_id,
9696 gtk_tree_view_set_model(GTK_TREE_VIEW(view),
9797 GTK_TREE_MODEL(store));
9898
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);
100100
101101 GtkWidget* button = gtk_button_new();
102102 gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_stock(GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_BUTTON));
162162 {
163163 FcitxSubConfigWidget* widget = (FcitxSubConfigWidget*) user_data;
164164 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 }
169174 } else {
170175 FILE* fp = FcitxXDGGetFileUserWithPrefix("", widget->subconfig->nativepath, "w", &newpath);
171176 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);
173178 fclose(fp);
174179 }
175180 }
188193
189194
190195 void push_into_store_cb(gpointer data,
196 gpointer value,
191197 gpointer user_data)
192198 {
193199 GtkListStore* store = user_data;