static void save_settings(void) { GKeyFile *config = g_key_file_new(); gchar *data; gchar *config_dir = g_path_get_dirname(config_file); g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL); g_key_file_set_boolean(config, "geanyprj", "display_sidebar", display_sidebar); if (! g_file_test(config_dir, G_FILE_TEST_IS_DIR) && utils_mkdir(config_dir, TRUE) != 0) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Plugin configuration directory could not be created.")); } else { /* write config to file */ data = g_key_file_to_data(config, NULL, NULL); utils_write_file(config_file, data); g_free(data); } g_free(config_dir); g_key_file_free(config); }
static gchar *backup_create_dir_parts(const gchar *filename) { gchar *parts = NULL; gchar *dirname = NULL; dirname = g_path_get_dirname(filename); if ( !dirname ) return g_strdup ( "" ); // if the file is in the project space already, skip the if ( strncmp ( dirname, project_dir, strlen(project_dir) ) != 0 ) { parts = g_strdup ( "__non_project__" ); } else { parts = g_strdup ( dirname+24 ); } gchar *target_dir = g_strconcat ( backupcopy_backup_dir, G_DIR_SEPARATOR_S, parts, G_DIR_SEPARATOR_S, NULL ); utils_mkdir(target_dir, TRUE); g_free ( target_dir ); g_free ( dirname ); return parts; }
static void save_settings(void) { GKeyFile *config = g_key_file_new(); gchar *data; gchar *config_dir = g_path_get_dirname(config_file); g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL); g_key_file_set_integer(config, "geniuspaste", "website", website_selected); g_key_file_set_boolean(config, "geniuspaste", "open_browser", check_button_is_checked); g_key_file_set_string(config, "geniuspaste", "author_name", author_name); if (! g_file_test(config_dir, G_FILE_TEST_IS_DIR) && utils_mkdir(config_dir, TRUE) != 0) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Plugin configuration directory could not be created.")); } else { data = g_key_file_to_data(config, NULL, NULL); utils_write_file(config_file, data); g_free(data); } g_free(config_dir); g_key_file_free(config); }
static void on_configure_response(G_GNUC_UNUSED GtkDialog *dialog, gint response, G_GNUC_UNUSED gpointer user_data) { if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY) { GKeyFile *config = g_key_file_new(); gchar *config_dir = g_path_get_dirname(config_file); gboolean configure_toogle_status; g_free(mailer); mailer = g_strdup(gtk_entry_get_text(GTK_ENTRY(pref_widgets.entry))); configure_toogle_status = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pref_widgets.checkbox_icon_to_toolbar)); if (icon_in_toolbar ^ configure_toogle_status) /* Only do anything if a status change is needed */ { if (icon_in_toolbar == TRUE) { /* We need to remove the toolbar icon */ cleanup_icon(); } else { /* We need to show the toolbar icon */ show_icon(); } } if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pref_widgets.checkbox_use_addressdialog)) == TRUE) use_address_dialog = TRUE; else use_address_dialog = FALSE; g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL); g_key_file_set_string(config, "tools", "mailer", mailer); g_key_file_set_boolean(config, "tools", "address_usage", use_address_dialog); g_key_file_set_boolean(config, "icon", "show_icon", icon_in_toolbar); if (! g_file_test(config_dir, G_FILE_TEST_IS_DIR) && utils_mkdir(config_dir, TRUE) != 0) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Plugin configuration directory could not be created.")); } else { /* write config to file */ gchar *data = g_key_file_to_data(config, NULL, NULL); utils_write_file(config_file, data); g_free(data); } g_key_file_free(config); g_free(config_dir); } }
static gchar *backupcopy_create_dir_parts(const gchar *filename) { gint cnt_dir_parts = 0; gchar *cp; gchar *dirname; gchar last_char = 0; gint error; gchar *result; gchar *target_dir; if (backupcopy_dir_levels == 0) return g_strdup(""); dirname = g_path_get_dirname(filename); cp = dirname; /* walk to the end of the string */ while (*cp != '\0') cp++; /* walk backwards to find directory parts */ while (cp > dirname) { if (*cp == G_DIR_SEPARATOR && last_char != G_DIR_SEPARATOR) cnt_dir_parts++; if (cnt_dir_parts == backupcopy_dir_levels) break; last_char = *cp; cp--; } result = backupcopy_skip_root(cp); /* skip leading slash/backslash and c:\ */ target_dir = g_build_filename(backupcopy_backup_dir, result, NULL); error = utils_mkdir(target_dir, TRUE); if (error != 0) { ui_set_statusbar(FALSE, _("Backup Copy: Directory could not be created (%s)."), g_strerror(error)); result = g_strdup(""); /* return an empty string in case of an error */ } else result = g_strdup(result); g_free(dirname); g_free(target_dir); return result; }
static void save_config (void) { gchar *path; gchar *dirname; GError *err = NULL; path = get_config_filename (); dirname = g_path_get_dirname (path); utils_mkdir (dirname, TRUE); g_free (dirname); if (! gwh_settings_save_to_file (G_settings, path, &err)) { g_warning ("Failed to save configuration: %s", err->message); g_error_free (err); } g_free (path); g_object_unref (G_settings); G_settings = NULL; }
static void on_configure_response(G_GNUC_UNUSED GtkDialog *dialog, gint response, G_GNUC_UNUSED gpointer user_data) { if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY) { GKeyFile *config = g_key_file_new(); gchar *data; gchar *config_dir = g_path_get_dirname(config_file); config_file = g_strconcat(geany->app->configdir, G_DIR_SEPARATOR_S, "plugins", G_DIR_SEPARATOR_S, "updatechecker", G_DIR_SEPARATOR_S, "general.conf", NULL); /* Crabbing options that has been set */ check_on_startup = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(config_widgets.run_on_startup)); /* write stuff to file */ g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL); g_key_file_set_boolean(config, "general", "check_for_updates_on_startup", check_on_startup); if (!g_file_test(config_dir, G_FILE_TEST_IS_DIR) && utils_mkdir(config_dir, TRUE) != 0) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Plugin configuration directory could not be created.")); } else { /* write config to file */ data = g_key_file_to_data(config, NULL, NULL); utils_write_file(config_file, data); g_free(data); } g_free(config_dir); g_key_file_free(config); } }
static void save_config(void) { GKeyFile *kf = g_key_file_new(); gchar *filename = get_config_filename(); gchar *dirname = g_path_get_dirname(filename); gchar *data; gsize length; g_key_file_set_boolean(kf, CONF_GROUP, CONF_ENABLE_VIM, vi_get_enabled()); g_key_file_set_boolean(kf, CONF_GROUP, CONF_INSERT_FOR_DUMMIES, vi_get_insert_for_dummies()); g_key_file_set_boolean(kf, CONF_GROUP, CONF_START_IN_INSERT, start_in_insert); utils_mkdir(dirname, TRUE); data = g_key_file_to_data(kf, &length, NULL); g_file_set_contents(filename, data, length, NULL); g_free(data); g_key_file_free(kf); g_free(filename); g_free(dirname); }
/* Callback for sending file as attachment */ static void send_as_attachment(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata) { GeanyDocument *doc; gchar *locale_filename = NULL; gchar *command = NULL; GError *error = NULL; GString *cmd_str = NULL; gchar *data; doc = document_get_current(); if (doc->file_name == NULL) { dialogs_show_save_as(); } else { document_save_file(doc, FALSE); } if (doc->file_name != NULL) { if (mailer) { locale_filename = utils_get_locale_from_utf8(doc->file_name); cmd_str = g_string_new(mailer); if ((use_address_dialog == TRUE) && (g_strrstr(mailer, "%r") != NULL)) { GKeyFile *config = NULL; gchar *config_dir = NULL; gchar *input = dialogs_show_input(_("Recipient's Address"), GTK_WINDOW(geany->main_widgets->window), _("Enter the recipient's e-mail address:"), address); if (input) { config = g_key_file_new(); g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL); g_free(address); address = input; g_key_file_set_string(config, "tools", "address", address); } else { g_string_free(cmd_str, TRUE); g_free(locale_filename); return; } config_dir = g_path_get_dirname(config_file); if (! g_file_test(config_dir, G_FILE_TEST_IS_DIR) && utils_mkdir(config_dir, TRUE) != 0) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Plugin configuration directory could not be created.")); } else { /* write config to file */ data = g_key_file_to_data(config, NULL, NULL); utils_write_file(config_file, data); g_free(data); } g_key_file_free(config); g_free(config_dir); } if (! utils_string_replace_all(cmd_str, "%f", locale_filename)) ui_set_statusbar(FALSE, _("Filename placeholder not found. The executed command might have failed.")); if (use_address_dialog == TRUE && address != NULL) { if (! utils_string_replace_all(cmd_str, "%r", address)) ui_set_statusbar(FALSE, _("Recipient address placeholder not found. The executed command might have failed.")); } else { /* Removes %r if option was not activ but was included into command */ utils_string_replace_all(cmd_str, "%r", ""); } utils_string_replace_all(cmd_str, "%b", g_path_get_basename(locale_filename)); command = g_string_free(cmd_str, FALSE); g_spawn_command_line_async(command, &error); if (error != NULL) { ui_set_statusbar(FALSE, _("Could not execute mailer. Please check your configuration.")); g_error_free(error); } g_free(locale_filename); g_free(command); } else { ui_set_statusbar(FALSE, _("Please define a mail client first.")); } } else { ui_set_statusbar(FALSE, _("File has to be saved before sending.")); } }
void prefs_init(void) { guint i; MarkerStyle *style = pref_marker_styles; StashGroup *group; char *configdir = g_build_filename(geany->app->configdir, "plugins", "scope", NULL); char *configfile = prefs_file_name(); GKeyFile *config = g_key_file_new(); gchar *tmp_string; group = stash_group_new("scope"); stash_group_add_string(group, &pref_gdb_executable, "gdb_executable", "gdb"); stash_group_add_boolean(group, &pref_gdb_async_mode, "gdb_async_mode", FALSE); stash_group_add_integer(group, &pref_gdb_buffer_length, "gdb_buffer_length", 16383); stash_group_add_integer(group, &pref_gdb_wait_death, "gdb_wait_death", 20); #ifndef G_OS_UNIX stash_group_add_integer(group, &pref_gdb_send_interval, "gdb_send_interval", 5); stash_group_add_boolean(group, &pref_async_break_bugs, "async_break_bugs", TRUE); #endif stash_group_add_boolean(group, &pref_auto_view_source, "auto_view_source", FALSE); stash_group_add_boolean(group, &pref_keep_exec_point, "keep_exec_point", FALSE); stash_group_add_integer(group, &pref_visual_beep_length, "visual_beep_length", 25); #ifdef G_OS_UNIX stash_group_add_boolean(group, &pref_debug_console_vte, "debug_console_vte", TRUE); #endif stash_group_add_integer(group, &pref_sci_marker_1st, "sci_marker_first", 17); stash_group_add_integer(group, &pref_sci_caret_policy, "sci_caret_policy", CARET_SLOP | CARET_JUMPS | CARET_EVEN); stash_group_add_integer(group, &pref_sci_caret_slop, "sci_caret_slop", 3); stash_group_add_boolean(group, &pref_unmark_current_line, "unmark_current_line", FALSE); stash_group_add_boolean(group, &pref_scope_goto_cursor, "scope_run_to_cursor", FALSE); stash_group_add_boolean(group, &pref_seek_with_navqueue, "seek_with_navqueue", FALSE); stash_group_add_integer(group, &pref_panel_tab_pos, "panel_tab_pos", GTK_POS_TOP); stash_group_add_integer(group, &pref_show_recent_items, "show_recent_items", 10); stash_group_add_integer(group, &pref_show_toolbar_items, "show_toolbar_items", 0xFF); stash_group_add_integer(group, &pref_tooltips_fail_action, "tooltips_fail_action", 0); stash_group_add_integer(group, &pref_tooltips_send_delay, "tooltips_send_delay", 25); stash_group_add_integer(group, &pref_tooltips_length, "tooltips_length", 2048); stash_group_add_integer(group, &pref_memory_bytes_per_line, "memory_line_bytes", 16); stash_group_add_string(group, &pref_memory_font, "memory_font", ""); scope_group = group; config_item = ui_add_config_file_menu_item(configfile, NULL, NULL); plugin_signal_connect(geany_plugin, NULL, "document-save", FALSE, G_CALLBACK(on_document_save), NULL); group = stash_group_new("terminal"); #ifdef G_OS_UNIX stash_group_add_boolean(group, &pref_terminal_save_pos, "save_pos", TRUE); stash_group_add_boolean(group, &pref_terminal_padding, "padding", TRUE); stash_group_add_integer(group, &pref_terminal_window_x, "window_x", 70); stash_group_add_integer(group, &pref_terminal_window_y, "window_y", 50); stash_group_add_integer(group, &pref_terminal_width, "width", 640); stash_group_add_integer(group, &pref_terminal_height, "height", 480); #endif /* G_OS_UNIX */ terminal_group = group; for (i = 0; i < MARKER_COUNT; i++, style++) { group = stash_group_new(style->name); stash_group_add_integer(group, &style->mark, "mark", style->default_mark); stash_group_add_integer(group, &style->alpha, "alpha", style->default_alpha); marker_group[i] = group; } g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL); load_scope_prefs(config); pref_sci_marker_first = pref_sci_marker_1st; prefs_configure(); program_load_config(config); if (pref_panel_tab_pos == GTK_POS_LEFT || pref_panel_tab_pos == GTK_POS_RIGHT) { gtk_label_set_label(GTK_LABEL(get_widget("program_terminal_label")), _("Program")); gtk_label_set_label(GTK_LABEL(get_widget("break_view_label")), _("Breaks")); gtk_label_set_label(GTK_LABEL(get_widget("debug_console_label")), _("Console")); } if (!g_file_test(configfile, G_FILE_TEST_IS_REGULAR)) { gint error = utils_mkdir(configdir, TRUE); if (error) msgwin_status_add(_("Scope: %s: %s."), configdir, g_strerror(error)); else { save_scope_prefs(config); if (utils_key_file_write_to_file(config, configfile)) msgwin_status_add(_("Scope: created configuration file.")); } } g_key_file_free(config); g_free(configfile); g_free(configdir); configfile = g_build_filename(geany_data->app->configdir, "geany.conf", NULL); config = g_key_file_new(); g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL); pref_vte_blinken = utils_get_setting_boolean(config, "VTE", "cursor_blinks", FALSE); pref_vte_emulation = utils_get_setting_string(config, "VTE", "emulation", "xterm"); pref_vte_font = utils_get_setting_string(config, "VTE", "font", "Monospace 10"); pref_vte_scrollback = utils_get_setting_integer(config, "VTE", "scrollback_lines", 500); tmp_string = utils_get_setting_string(config, "VTE", "colour_fore", "#ffffff"); gdk_color_parse(tmp_string, &pref_vte_colour_fore); g_free(tmp_string); tmp_string = utils_get_setting_string(config, "VTE", "colour_back", "#000000"); gdk_color_parse(tmp_string, &pref_vte_colour_back); g_free(tmp_string); g_key_file_free(config); g_free(configfile); }
/* * Create the index file associated with a trace file. * * Return allocated struct lttng_index_file, NULL on error. */ struct lttng_index_file *lttng_index_file_create(char *path_name, char *stream_name, int uid, int gid, uint64_t size, uint64_t count, uint32_t major, uint32_t minor) { struct lttng_index_file *index_file; int ret, fd = -1; ssize_t size_ret; struct ctf_packet_index_file_hdr hdr; char fullpath[PATH_MAX]; uint32_t element_len = ctf_packet_index_len(major, minor); index_file = zmalloc(sizeof(*index_file)); if (!index_file) { PERROR("allocating lttng_index_file"); goto error; } ret = snprintf(fullpath, sizeof(fullpath), "%s/" DEFAULT_INDEX_DIR, path_name); if (ret < 0) { PERROR("snprintf index path"); goto error; } /* Create index directory if necessary. */ ret = utils_mkdir(fullpath, S_IRWXU | S_IRWXG, uid, gid); if (ret < 0) { if (errno != EEXIST) { PERROR("Index trace directory creation error"); goto error; } } /* * For tracefile rotation. We need to unlink the old * file if present to synchronize with the tail of the * live viewer which could be working on this same file. * By doing so, any reference to the old index file * stays valid even if we re-create a new file with the * same name afterwards. */ ret = utils_unlink_stream_file(fullpath, stream_name, size, count, uid, gid, DEFAULT_INDEX_FILE_SUFFIX); if (ret < 0 && errno != ENOENT) { goto error; } ret = utils_create_stream_file(fullpath, stream_name, size, count, uid, gid, DEFAULT_INDEX_FILE_SUFFIX); if (ret < 0) { goto error; } fd = ret; hdr.magic = htobe32(CTF_INDEX_MAGIC); hdr.index_major = htobe32(major); hdr.index_minor = htobe32(minor); hdr.packet_index_len = htobe32(element_len); size_ret = lttng_write(fd, &hdr, sizeof(hdr)); if (size_ret < sizeof(hdr)) { PERROR("write index header"); ret = -1; goto error; } index_file->fd = fd; index_file->major = major; index_file->minor = minor; index_file->element_len = element_len; urcu_ref_init(&index_file->ref); return index_file; error: if (fd >= 0) { int close_ret; close_ret = close(fd); if (close_ret < 0) { PERROR("close index fd"); } } free(index_file); return NULL; }
static void configure_response_cb(GtkDialog *dialog, gint response, G_GNUC_UNUSED gpointer data) { if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY) { GKeyFile *config = g_key_file_new(); gchar *str; const gchar *text_dir, *text_time; gchar *config_dir = g_path_get_dirname(config_file); enable_autosave = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(pref_widgets.checkbox_enable_autosave)); enable_autosave_losing_focus = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(pref_widgets.checkbox_enable_autosave_losing_focus)); enable_instantsave = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(pref_widgets.checkbox_enable_instantsave)); enable_backupcopy = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(pref_widgets.checkbox_enable_backupcopy)); autosave_interval = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(pref_widgets.autosave_interval_spin)); autosave_print_msg = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(pref_widgets.autosave_print_msg_checkbox)); autosave_save_all = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(pref_widgets.autosave_save_all_radio2)); g_free(instantsave_default_ft); instantsave_default_ft = gtk_combo_box_text_get_active_text( GTK_COMBO_BOX_TEXT(pref_widgets.instantsave_ft_combo)); text_dir = gtk_entry_get_text(GTK_ENTRY(pref_widgets.backupcopy_entry_dir)); text_time = gtk_entry_get_text(GTK_ENTRY(pref_widgets.backupcopy_entry_time)); backupcopy_dir_levels = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(pref_widgets.backupcopy_spin_dir_levels)); g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL); g_key_file_set_boolean(config, "saveactions", "enable_autosave", enable_autosave); g_key_file_set_boolean(config, "saveactions", "enable_autosave_losing_focus", enable_autosave_losing_focus); g_key_file_set_boolean(config, "saveactions", "enable_instantsave", enable_instantsave); g_key_file_set_boolean(config, "saveactions", "enable_backupcopy", enable_backupcopy); g_key_file_set_boolean(config, "autosave", "print_messages", autosave_print_msg); g_key_file_set_boolean(config, "autosave", "save_all", autosave_save_all); g_key_file_set_integer(config, "autosave", "interval", autosave_interval); if (instantsave_default_ft != NULL) g_key_file_set_string(config, "instantsave", "default_ft", instantsave_default_ft); g_key_file_set_integer(config, "backupcopy", "dir_levels", backupcopy_dir_levels); g_key_file_set_string(config, "backupcopy", "time_fmt", text_time); SETPTR(backupcopy_time_fmt, g_strdup(text_time)); if (enable_backupcopy) { if (!EMPTY(text_dir) && backupcopy_set_backup_dir(text_dir)) { g_key_file_set_string(config, "backupcopy", "backup_dir", text_dir); } else { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Backup directory does not exist or is not writable.")); } } if (! g_file_test(config_dir, G_FILE_TEST_IS_DIR) && utils_mkdir(config_dir, TRUE) != 0) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Plugin configuration directory could not be created.")); } else { /* write config to file */ str = g_key_file_to_data(config, NULL, NULL); utils_write_file(config_file, str); g_free(str); } if (enable_autosave) autosave_set_timeout(); /* apply the changes */ g_free(config_dir); g_key_file_free(config); } }
void plugin_init(GeanyData * data) { GKeyFile *kf = g_key_file_new(); GError *err = NULL; gchar *glob_file; gchar *user_file; gchar *old_config_dir; main_locale_init(LOCALEDIR, GETTEXT_PACKAGE); gdbui_setup.main_window = geany->main_widgets->window; gdbio_setup.temp_dir = g_build_filename(geany->app->configdir, "plugins", UNIX_NAME, NULL); old_config_dir = g_build_filename(geany->app->configdir, "plugins", UNIX_NAME_OLD, NULL); if (g_file_test(old_config_dir, G_FILE_TEST_IS_DIR) && !g_file_test(gdbio_setup.temp_dir, G_FILE_TEST_EXISTS)) g_rename(old_config_dir, gdbio_setup.temp_dir); /* * the tty helper binary is either in the user's config dir or globally * installed in $LIBDIR/geany/ */ glob_file = g_build_filename(TTYHELPERDIR, "ttyhelper", NULL); user_file = g_build_filename(geany->app->configdir, "plugins", UNIX_NAME, "ttyhelper", NULL); gdbio_setup.tty_helper = NULL; if (utils_mkdir(gdbio_setup.temp_dir, TRUE) != 0) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Plugin configuration directory (%s) could not be created."), gdbio_setup.temp_dir); } /* the global ttyhelper has higher priority */ if (!g_file_test(glob_file, G_FILE_TEST_IS_REGULAR)) { if (g_file_test(user_file, G_FILE_TEST_IS_REGULAR) && g_file_test(user_file, G_FILE_TEST_IS_EXECUTABLE)) { gdbio_setup.tty_helper = g_strdup(user_file); } } else if (g_file_test(glob_file, G_FILE_TEST_IS_EXECUTABLE)) gdbio_setup.tty_helper = g_strdup(glob_file); if (NULL == gdbio_setup.tty_helper) dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("geanygdb: ttyhelper program not found.")); config_file = g_build_filename(gdbio_setup.temp_dir,"debugger.cfg", NULL); gdbui_opts_init(); if (g_key_file_load_from_file(kf, config_file, G_KEY_FILE_NONE, NULL)) { GET_KEY_STR(mono_font); GET_KEY_STR(term_cmd); GET_KEY_BOOL(show_tooltips); GET_KEY_BOOL(show_icons); } g_key_file_free(kf); gdbui_setup.warn_func = warn_message_cb; gdbui_setup.info_func = info_message_cb; gdbui_setup.opts_func = update_settings_cb; gdbui_setup.location_query = location_query_cb; gdbui_setup.line_func = goto_file_line_cb; g_free(old_config_dir); g_free(glob_file); g_free(user_file); msgbook = GTK_NOTEBOOK(ui_lookup_widget(geany->main_widgets->window, "notebook_info")); compwin = gtk_widget_get_parent(ui_lookup_widget(geany->main_widgets->window, "treeview5")); frame = gtk_frame_new(NULL); gtk_notebook_append_page(GTK_NOTEBOOK(geany->main_widgets->sidebar_notebook), frame, gtk_label_new("Debug")); menudbg = gtk_menu_item_new_with_mnemonic (_("Debu_g")); gtk_widget_show (menudbg); gtk_menu_insert ( GTK_CONTAINER ( ui_lookup_widget(geany->main_widgets->window, "menubar1")) , menudbg, 7); btmframe = gtk_frame_new(NULL); gtk_widget_show_all(btmframe); gtk_notebook_append_page( GTK_NOTEBOOK(ui_lookup_widget(geany->main_widgets->window, "notebook_info")), btmframe, gtk_label_new(_("Debug"))); gdbui_create_menu(menudbg); gdbui_create_widgets(frame); gtk_widget_show_all(frame); }
/** * @brief Callback called when validating the configuration of the plug-in * @param dialog the parent dialog, not very interesting here * @param response OK/Cancel/Apply user action * @param user_data NULL * * @return void * */ static void on_configure_response(GtkDialog* dialog, gint response, gpointer user_data) { gsize i=0; GKeyFile *config = NULL; gchar *config_filename = NULL; gchar *config_dir = NULL; gchar *data; gsize list_len, empty_lines; gchar** head_list = NULL; gchar** impl_list = NULL; GtkTreeIter iter; log_func(); if(response != GTK_RESPONSE_OK && response != GTK_RESPONSE_APPLY) return; /* Write the settings into a file, using GLib's GKeyFile API. * File name : * geany->app->configdir G_DIR_SEPARATOR_S "plugins" G_DIR_SEPARATOR_S * "codenav" G_DIR_SEPARATOR_S "codenav.conf" * e.g. this could be: ~/.config/geany/plugins/codenav/codenav.conf */ /* Open the GKeyFile */ config = g_key_file_new(); config_filename = g_strconcat(geany->app->configdir, G_DIR_SEPARATOR_S, "plugins", G_DIR_SEPARATOR_S, "codenav", G_DIR_SEPARATOR_S, "codenav.conf", NULL); config_dir = g_path_get_dirname(config_filename); /* Allocate the list */ list_len = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(list_store), NULL); impl_list = g_malloc0( sizeof(gchar**) * list_len); head_list = g_malloc0( sizeof(gchar**) * list_len); empty_lines = 0; if ( list_len > 0 ) { // Get the first item gtk_tree_model_iter_children (GTK_TREE_MODEL(list_store),&iter,NULL); do { /* forall elements in list... */ gtk_tree_model_get (GTK_TREE_MODEL(list_store),&iter, COLUMN_IMPL,&impl_list[i], -1); gtk_tree_model_get (GTK_TREE_MODEL(list_store),&iter, COLUMN_HEAD,&head_list[i], -1); /* If one field is empty, ignore this line (it will be replaces at next execution) */ if ( strlen(impl_list[i])==0 || strlen(head_list[i])==0 ) empty_lines++; else i++; } while ( gtk_tree_model_iter_next(GTK_TREE_MODEL(list_store), &iter) ); } /* write lists */ g_key_file_set_string_list(config, "switch_head_impl", "implementations_list", (const gchar * const*)impl_list, list_len - empty_lines); g_key_file_set_string_list(config, "switch_head_impl", "headers_list", (const gchar * const*)head_list, list_len - empty_lines); /* Try to create directory if not exists */ if (! g_file_test(config_dir, G_FILE_TEST_IS_DIR) && utils_mkdir(config_dir, TRUE) != 0) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Plugin configuration directory could not be created.")); } else { /* write config to file */ data = g_key_file_to_data(config, NULL, NULL); utils_write_file(config_filename, data); g_free(data); } /* Replace the current (runtime) languages list */ fill_languages_list((const gchar**)impl_list, (const gchar**)head_list, list_len - empty_lines); /* Freeing memory */ for ( i=0; i < list_len; i++ ) { g_free(impl_list[i]); g_free(head_list[i]); } g_free(impl_list); g_free(head_list); g_free(config_dir); g_free(config_filename); g_key_file_free(config); }
/* Verifies data for New & Properties dialogs. * Returns: FALSE if the user needs to change any data. */ static gboolean update_config(const PropertyDialogElements *e, gboolean new_project) { const gchar *name, *file_name, *base_path; gchar *locale_filename; gsize name_len; gint err_code = 0; GeanyProject *p; g_return_val_if_fail(e != NULL, TRUE); name = gtk_entry_get_text(GTK_ENTRY(e->name)); name_len = strlen(name); if (name_len == 0) { SHOW_ERR(_("The specified project name is too short.")); gtk_widget_grab_focus(e->name); return FALSE; } else if (name_len > MAX_NAME_LEN) { SHOW_ERR1(_("The specified project name is too long (max. %d characters)."), MAX_NAME_LEN); gtk_widget_grab_focus(e->name); return FALSE; } if (new_project) file_name = gtk_entry_get_text(GTK_ENTRY(e->file_name)); else file_name = gtk_label_get_text(GTK_LABEL(e->file_name)); if (G_UNLIKELY(! NZV(file_name))) { SHOW_ERR(_("You have specified an invalid project filename.")); gtk_widget_grab_focus(e->file_name); return FALSE; } locale_filename = utils_get_locale_from_utf8(file_name); base_path = gtk_entry_get_text(GTK_ENTRY(e->base_path)); if (NZV(base_path)) { /* check whether the given directory actually exists */ gchar *locale_path = utils_get_locale_from_utf8(base_path); if (! g_path_is_absolute(locale_path)) { /* relative base path, so add base dir of project file name */ gchar *dir = g_path_get_dirname(locale_filename); SETPTR(locale_path, g_strconcat(dir, G_DIR_SEPARATOR_S, locale_path, NULL)); g_free(dir); } if (! g_file_test(locale_path, G_FILE_TEST_IS_DIR)) { gboolean create_dir; create_dir = dialogs_show_question_full(NULL, GTK_STOCK_OK, GTK_STOCK_CANCEL, _("Create the project's base path directory?"), _("The path \"%s\" does not exist."), base_path); if (create_dir) err_code = utils_mkdir(locale_path, TRUE); if (! create_dir || err_code != 0) { if (err_code != 0) SHOW_ERR1(_("Project base directory could not be created (%s)."), g_strerror(err_code)); gtk_widget_grab_focus(e->base_path); utils_free_pointers(2, locale_path, locale_filename, NULL); return FALSE; } } g_free(locale_path); } /* finally test whether the given project file can be written */ if ((err_code = utils_is_file_writable(locale_filename)) != 0 || (err_code = g_file_test(locale_filename, G_FILE_TEST_IS_DIR) ? EISDIR : 0) != 0) { SHOW_ERR1(_("Project file could not be written (%s)."), g_strerror(err_code)); gtk_widget_grab_focus(e->file_name); g_free(locale_filename); return FALSE; } g_free(locale_filename); if (app->project == NULL) { create_project(); new_project = TRUE; } p = app->project; SETPTR(p->name, g_strdup(name)); SETPTR(p->file_name, g_strdup(file_name)); /* use "." if base_path is empty */ SETPTR(p->base_path, g_strdup(NZV(base_path) ? base_path : "./")); if (! new_project) /* save properties specific fields */ { GtkTextIter start, end; GtkTextBuffer *buffer; GeanyDocument *doc = document_get_current(); GeanyBuildCommand *oldvalue; GeanyFiletype *ft = doc ? doc->file_type : NULL; GtkWidget *widget; gchar *tmp; GString *str; GSList *node; /* get and set the project description */ buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e->description)); gtk_text_buffer_get_start_iter(buffer, &start); gtk_text_buffer_get_end_iter(buffer, &end); SETPTR(p->description, g_strdup(gtk_text_buffer_get_text(buffer, &start, &end, FALSE))); foreach_slist(node, stash_groups) stash_group_update(node->data, e->dialog); /* read the project build menu */ oldvalue = ft ? ft->projfilecmds : NULL; build_read_project(ft, e->build_properties); if (ft != NULL && ft->projfilecmds != oldvalue && ft->project_list_entry < 0) { if (p->build_filetypes_list == NULL) p->build_filetypes_list = g_ptr_array_new(); ft->project_list_entry = p->build_filetypes_list->len; g_ptr_array_add(p->build_filetypes_list, ft); } build_menu_update(doc); widget = ui_lookup_widget(e->dialog, "radio_long_line_disabled_project"); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) p->long_line_behaviour = 0; else { widget = ui_lookup_widget(e->dialog, "radio_long_line_default_project"); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) p->long_line_behaviour = 1; else /* "Custom" radio button must be checked */ p->long_line_behaviour = 2; } widget = ui_lookup_widget(e->dialog, "spin_long_line_project"); p->long_line_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); apply_editor_prefs(); /* get and set the project file patterns */ tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(e->patterns))); g_strfreev(p->file_patterns); g_strstrip(tmp); str = g_string_new(tmp); do {} while (utils_string_replace_all(str, " ", " ")); p->file_patterns = g_strsplit(str->str, " ", -1); g_string_free(str, TRUE); g_free(tmp); } update_ui(); return TRUE; }
static void configure_response_cb(GtkDialog *dialog, gint response, gpointer user_data) { if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY) { GKeyFile *config = g_key_file_new(); gchar *data; gchar *config_dir = g_path_get_dirname(sc_info->config_file); GtkComboBox *combo = GTK_COMBO_BOX(g_object_get_data(G_OBJECT(dialog), "combo")); setptr(sc_info->default_language, gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combo))); #ifdef HAVE_ENCHANT_1_5 setptr(sc_info->dictionary_dir, g_strdup(gtk_entry_get_text(GTK_ENTRY( g_object_get_data(G_OBJECT(dialog), "dict_dir"))))); #endif sc_speller_reinit_enchant_dict(); sc_info->check_while_typing = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( g_object_get_data(G_OBJECT(dialog), "check_type")))); sc_info->use_msgwin = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( g_object_get_data(G_OBJECT(dialog), "check_msgwin")))); sc_info->show_toolbar_item = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( g_object_get_data(G_OBJECT(dialog), "check_toolbar")))); sc_info->show_editor_menu_item = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( g_object_get_data(G_OBJECT(dialog), "check_editor_menu")))); g_key_file_load_from_file(config, sc_info->config_file, G_KEY_FILE_NONE, NULL); if (sc_info->default_language != NULL) /* lang may be NULL */ g_key_file_set_string(config, "spellcheck", "language", sc_info->default_language); g_key_file_set_boolean(config, "spellcheck", "check_while_typing", sc_info->check_while_typing); g_key_file_set_boolean(config, "spellcheck", "use_msgwin", sc_info->use_msgwin); g_key_file_set_boolean(config, "spellcheck", "show_toolbar_item", sc_info->show_toolbar_item); g_key_file_set_boolean(config, "spellcheck", "show_editor_menu_item", sc_info->show_editor_menu_item); if (sc_info->dictionary_dir != NULL) g_key_file_set_string(config, "spellcheck", "dictionary_dir", sc_info->dictionary_dir); sc_gui_update_toolbar(); sc_gui_update_menu(); populate_dict_combo(combo); if (! g_file_test(config_dir, G_FILE_TEST_IS_DIR) && utils_mkdir(config_dir, TRUE) != 0) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Plugin configuration directory could not be created.")); } else { /* write config to file */ data = g_key_file_to_data(config, NULL, NULL); utils_write_file(sc_info->config_file, data); g_free(data); } g_free(config_dir); g_key_file_free(config); } }
static void ao_configure_response_cb(GtkDialog *dialog, gint response, gpointer user_data) { if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY) { GKeyFile *config = g_key_file_new(); gchar *data; gchar *config_dir = g_path_get_dirname(ao_info->config_file); ao_info->enable_doclist = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( g_object_get_data(G_OBJECT(dialog), "check_doclist")))); if (gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(g_object_get_data(G_OBJECT(dialog), "radio_doclist_name")))) ao_info->doclist_sort_mode = DOCLIST_SORT_BY_NAME; else ao_info->doclist_sort_mode = DOCLIST_SORT_BY_OCCURRENCE; ao_info->enable_openuri = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( g_object_get_data(G_OBJECT(dialog), "check_openuri")))); ao_info->enable_tasks = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( g_object_get_data(G_OBJECT(dialog), "check_tasks")))); ao_info->tasks_scan_all_documents = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( g_object_get_data(G_OBJECT(dialog), "check_tasks_scan_mode")))); g_free(ao_info->tasks_token_list); ao_info->tasks_token_list = g_strdup(gtk_entry_get_text(GTK_ENTRY( g_object_get_data(G_OBJECT(dialog), "entry_tasks_tokens")))); ao_info->enable_systray = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( g_object_get_data(G_OBJECT(dialog), "check_systray")))); ao_info->enable_bookmarklist = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( g_object_get_data(G_OBJECT(dialog), "check_bookmarklist")))); ao_info->enable_markword = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( g_object_get_data(G_OBJECT(dialog), "check_markword")))); ao_info->strip_trailing_blank_lines = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( g_object_get_data(G_OBJECT(dialog), "check_blanklines")))); ao_info->enable_xmltagging = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( g_object_get_data(G_OBJECT(dialog), "check_xmltagging")))); g_key_file_load_from_file(config, ao_info->config_file, G_KEY_FILE_NONE, NULL); g_key_file_set_boolean(config, "addons", "show_toolbar_doclist_item", ao_info->enable_doclist); g_key_file_set_integer(config, "addons", "doclist_sort_mode", ao_info->doclist_sort_mode); g_key_file_set_boolean(config, "addons", "enable_openuri", ao_info->enable_openuri); g_key_file_set_boolean(config, "addons", "enable_tasks", ao_info->enable_tasks); g_key_file_set_string(config, "addons", "tasks_token_list", ao_info->tasks_token_list); g_key_file_set_boolean(config, "addons", "tasks_scan_all_documents", ao_info->tasks_scan_all_documents); g_key_file_set_boolean(config, "addons", "enable_systray", ao_info->enable_systray); g_key_file_set_boolean(config, "addons", "enable_bookmarklist", ao_info->enable_bookmarklist); g_key_file_set_boolean(config, "addons", "enable_markword", ao_info->enable_markword); g_key_file_set_boolean(config, "addons", "strip_trailing_blank_lines", ao_info->strip_trailing_blank_lines); g_key_file_set_boolean(config, "addons", "enable_xmltagging", ao_info->enable_xmltagging); g_object_set(ao_info->doclist, "enable-doclist", ao_info->enable_doclist, NULL); g_object_set(ao_info->doclist, "sort-mode", ao_info->doclist_sort_mode, NULL); g_object_set(ao_info->openuri, "enable-openuri", ao_info->enable_openuri, NULL); g_object_set(ao_info->systray, "enable-systray", ao_info->enable_systray, NULL); g_object_set(ao_info->bookmarklist, "enable-bookmarklist", ao_info->enable_bookmarklist, NULL); g_object_set(ao_info->markword, "enable-markword", ao_info->enable_markword, NULL); g_object_set(ao_info->tasks, "enable-tasks", ao_info->enable_tasks, "scan-all-documents", ao_info->tasks_scan_all_documents, "tokens", ao_info->tasks_token_list, NULL); ao_blanklines_set_enable(ao_info->strip_trailing_blank_lines); if (! g_file_test(config_dir, G_FILE_TEST_IS_DIR) && utils_mkdir(config_dir, TRUE) != 0) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Plugin configuration directory could not be created.")); } else { /* write config to file */ data = g_key_file_to_data(config, NULL, NULL); utils_write_file(ao_info->config_file, data); g_free(data); } g_free(config_dir); g_key_file_free(config); } }