Example #1
0
static void
save_data( HWND hwndDlg, LONG user_data )
{
  struct binary_info *info = ( struct binary_info * ) user_data;

  long start, length; size_t i;
  libspectrum_byte *buffer;

  TCHAR *temp_buffer;
  size_t temp_buffer_len;

  int error;

  errno = 0;
  temp_buffer_len = SendDlgItemMessage( hwndDlg, IDC_BINARY_EDIT_LENGTH,
                                        WM_GETTEXTLENGTH, 0, 0 );
  temp_buffer = malloc( sizeof( TCHAR ) * ( temp_buffer_len + 1 ) );
  SendDlgItemMessage( hwndDlg, IDC_BINARY_EDIT_LENGTH, WM_GETTEXT,
                      temp_buffer_len + 1, ( LPARAM ) temp_buffer );
  length = _tcstol( temp_buffer, NULL, 10 );
  free( temp_buffer );
  if( errno || length < 1 || length > 0x10000 ) {
    ui_error( UI_ERROR_ERROR, "Length must be between 1 and 65536" );
    return;
  }

  buffer = malloc( length * sizeof( libspectrum_byte ) );
  if( !buffer ) {
    ui_error( UI_ERROR_ERROR, "out of memory at %s:%d", __FILE__, __LINE__ );
    return;
  }

  errno = 0;
  temp_buffer_len = SendDlgItemMessage( hwndDlg, IDC_BINARY_EDIT_START,
                                        WM_GETTEXTLENGTH, 0, 0 );
  temp_buffer = malloc( sizeof( TCHAR ) * ( temp_buffer_len + 1 ) );
  SendDlgItemMessage( hwndDlg, IDC_BINARY_EDIT_START, WM_GETTEXT,
                      temp_buffer_len + 1, ( LPARAM ) temp_buffer );
  start = _tcstol( temp_buffer, NULL, 10 );
  free( temp_buffer );
  if( errno || start < 0 || start > 0xffff ) {
    ui_error( UI_ERROR_ERROR, "Start must be between 0 and 65535" );
    return;
  }

  if( start + length > 0x10000 ) {
    ui_error( UI_ERROR_ERROR, "Block ends after address 65535" );
    return;
  }

  for( i = 0; i < length; i++ )
    buffer[ i ] = readbyte( start + i );

  error = utils_write_file( info->filename, buffer, length );
  if( error ) { free( buffer ); return; }

  free( buffer );

  EndDialog( hwndDlg, 0 );
}
Example #2
0
/* Write the current in-memory tape file out to disk */
int tape_write( const char* filename )
{
  libspectrum_id_t type;
  libspectrum_class_t class;
  libspectrum_byte *buffer; size_t length;

  int error;

  /* Work out what sort of file we want from the filename; default to
     .tzx if we couldn't guess */
  error = libspectrum_identify_file_with_class( &type, &class, filename, NULL,
						0 );
  if( error ) return error;

  if( class != LIBSPECTRUM_CLASS_TAPE || type == LIBSPECTRUM_ID_UNKNOWN )
    type = LIBSPECTRUM_ID_TAPE_TZX;

  length = 0;

  error = libspectrum_tape_write( &buffer, &length, tape, type );
  if( error != LIBSPECTRUM_ERROR_NONE ) return error;

  error = utils_write_file( filename, buffer, length );
  if( error ) { libspectrum_free( buffer ); return error; }

  tape_modified = 0;
  ui_tape_browser_update( UI_TAPE_BROWSER_MODIFIED, NULL );

  libspectrum_free( buffer );

  return 0;
}
Example #3
0
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);
}
Example #4
0
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);
}
Example #5
0
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);
	}
}
Example #6
0
int messages_push(char *msgid, zmsg_t *arguments)
{
	int ret;
  char filename[MAX_STRING_LEN];
	zframe_t *param = NULL;
  uint8_t *data = NULL;
  int size = 0;

  assert(msgid);
	assert(arguments);

  param = zmsg_pop(arguments);
  if (param == NULL) goto s_msg_push_parseerror;
  data = zframe_data(param);
  size = zframe_size(param);

  if (zmsg_size(arguments) > 0) {
    char *file = zmsg_popstr(arguments);
    ret = utils_write_file(file,(char*)data,size);
    free(file);
  } else {
    sprintf(filename, "/tmp/%s", msgid);
    ret = utils_write_file(filename,(char*)data,size);
  }

  if (ret != STATUS_OK) goto s_msg_push_execerror;

	ret = MSG_ANSWER_COMPLETED;

s_msg_push_end:
	if (param)
		free(param);
	return ret;

s_msg_push_execerror:
	ret = MSG_ANSWER_EXECERROR;
	goto s_msg_push_end;

s_msg_push_parseerror:
	ret = MSG_ANSWER_PARSEERROR;
	goto s_msg_push_end;
}
Example #7
0
int snapshot_write( const char *filename )
{
  libspectrum_id_t type;
  libspectrum_class_t class;
  libspectrum_snap *snap;
  unsigned char *buffer; size_t length;
  int flags;

  int error;

  /* Work out what sort of file we want from the filename; default to
     .szx if we couldn't guess */
  error = libspectrum_identify_file_with_class( &type, &class, filename, NULL,
						0 );
  if( error ) return error;

  if( class != LIBSPECTRUM_CLASS_SNAPSHOT || type == LIBSPECTRUM_ID_UNKNOWN )
    type = LIBSPECTRUM_ID_SNAPSHOT_SZX;

  snap = libspectrum_snap_alloc();

  error = snapshot_copy_to( snap );
  if( error ) { libspectrum_snap_free( snap ); return error; }

  flags = 0;
  length = 0;
  buffer = NULL;
  error = libspectrum_snap_write( &buffer, &length, &flags, snap, type,
				  fuse_creator, 0 );
  if( error ) { libspectrum_snap_free( snap ); return error; }

  if( flags & LIBSPECTRUM_FLAG_SNAPSHOT_MAJOR_INFO_LOSS ) {
    ui_error(
      UI_ERROR_WARNING,
      "A large amount of information has been lost in conversion; the snapshot probably won't work"
    );
  } else if( flags & LIBSPECTRUM_FLAG_SNAPSHOT_MINOR_INFO_LOSS ) {
    ui_error(
      UI_ERROR_WARNING,
      "Some information has been lost in conversion; the snapshot may not work"
    );
  }

  error = libspectrum_snap_free( snap );
  if( error ) { libspectrum_free( buffer ); return 1; }

  error = utils_write_file( filename, buffer, length );
  if( error ) { libspectrum_free( buffer ); return error; }

  libspectrum_free( buffer );

  return 0;

}
Example #8
0
int
rzx_finalise_recording( const char *filename )
{
  libspectrum_byte *buffer; size_t length;
  libspectrum_error libspec_error; int error;
  utils_file file;

  if( rzx_recording || rzx_playback ) return 1;

  error = utils_read_file( filename, &file );
  if( error ) return error;

  rzx = libspectrum_rzx_alloc();

  libspec_error = libspectrum_rzx_read( rzx, file.buffer, file.length );
  if( libspec_error != LIBSPECTRUM_ERROR_NONE ) {
    utils_close_file( &file );
    libspectrum_rzx_free( rzx );
    return libspec_error;
  }

  utils_close_file( &file );

  libspec_error = libspectrum_rzx_finalise( rzx );
  if( libspec_error != LIBSPECTRUM_ERROR_NONE ) {
    libspectrum_rzx_free( rzx );
    return libspec_error;
  }

  /* Write the file */
  length = 0;
  buffer = NULL;
  libspec_error = libspectrum_rzx_write(
    &buffer, &length, rzx, LIBSPECTRUM_ID_UNKNOWN, fuse_creator,
    settings_current.rzx_compression, rzx_competition_mode ? &rzx_key : NULL
  );
  if( libspec_error != LIBSPECTRUM_ERROR_NONE ) {
    libspectrum_rzx_free( rzx );
    return libspec_error;
  }

  error = utils_write_file( filename, buffer, length );
  if( error ) {
    libspectrum_free( buffer );
    libspectrum_rzx_free( rzx );
    return error;
  }

  libspectrum_free( buffer );
  libspectrum_rzx_free( rzx );

  return 0;
}
Example #9
0
int rzx_stop_recording( void )
{
  libspectrum_byte *buffer; size_t length;
  libspectrum_error libspec_error; int error;

  if( !rzx_recording ) return 0;

  /* Stop recording data */
  rzx_recording = 0;
  if( settings_current.movie_stop_after_rzx ) movie_stop();

  /* Embed final snapshot */
  if( !rzx_competition_mode ) rzx_add_snap( rzx, 0 );

  libspectrum_free( rzx_in_bytes );
  rzx_in_bytes = NULL;
  rzx_in_allocated = 0;

  ui_menu_activate( UI_MENU_ITEM_RECORDING, 0 );
  ui_menu_activate( UI_MENU_ITEM_RECORDING_ROLLBACK, 0 );

  libspectrum_creator_set_competition_code(
    fuse_creator, settings_current.competition_code
  );

  length = 0;
  buffer = NULL;
  libspec_error = libspectrum_rzx_write(
    &buffer, &length, rzx, LIBSPECTRUM_ID_UNKNOWN, fuse_creator,
    settings_current.rzx_compression, rzx_competition_mode ? &rzx_key : NULL
  );
  if( libspec_error != LIBSPECTRUM_ERROR_NONE ) {
    libspectrum_free( rzx_filename );
    libspectrum_rzx_free( rzx );
    return libspec_error;
  }

  error = utils_write_file( rzx_filename, buffer, length );
  libspectrum_free( rzx_filename );
  if( error ) {
    libspectrum_free( buffer );
    libspectrum_rzx_free( rzx );
    return error;
  }

  libspectrum_free( buffer );

  libspec_error = libspectrum_rzx_free( rzx );
  if( libspec_error != LIBSPECTRUM_ERROR_NONE ) return libspec_error;

  return 0;
}
Example #10
0
static void write_data(const gchar *filename, const gchar *data)
{
	gint error_nr = utils_write_file(filename, data);
	gchar *utf8_filename = utils_get_utf8_from_locale(filename);

	if (error_nr == 0)
		ui_set_statusbar(TRUE, _("Document successfully exported as '%s'."), utf8_filename);
	else
		ui_set_statusbar(TRUE, _("File '%s' could not be written (%s)."),
			utf8_filename, g_strerror(error_nr));

	g_free(utf8_filename);
}
Example #11
0
/* Write the project settings as well as the project session files into its configuration files.
 * emit_signal defines whether the project-save signal should be emitted. When write_config()
 * is called while closing a project, this is used to skip emitting the signal because
 * project-close will be emitted afterwards.
 * Returns: TRUE if project file was written successfully. */
static gboolean write_config(gboolean emit_signal)
{
	GeanyProject *p;
	GKeyFile *config;
	gchar *filename;
	gchar *data;
	gboolean ret = FALSE;
	GSList *node;

	g_return_val_if_fail(app->project != NULL, FALSE);

	p = app->project;

	config = g_key_file_new();
	/* try to load an existing config to keep manually added comments */
	filename = utils_get_locale_from_utf8(p->file_name);
	g_key_file_load_from_file(config, filename, G_KEY_FILE_NONE, NULL);

	foreach_slist(node, stash_groups)
		stash_group_save_to_key_file(node->data, config);

	g_key_file_set_string(config, "project", "name", p->name);
	g_key_file_set_string(config, "project", "base_path", p->base_path);

	if (p->description)
		g_key_file_set_string(config, "project", "description", p->description);
	if (p->file_patterns)
		g_key_file_set_string_list(config, "project", "file_patterns",
			(const gchar**) p->file_patterns, g_strv_length(p->file_patterns));

	g_key_file_set_integer(config, "long line marker", "long_line_behaviour", p->long_line_behaviour);
	g_key_file_set_integer(config, "long line marker", "long_line_column", p->long_line_column);

	/* store the session files into the project too */
	if (project_prefs.project_session)
		configuration_save_session_files(config);
	build_save_menu(config, (gpointer)p, GEANY_BCS_PROJ);
	if (emit_signal)
	{
		g_signal_emit_by_name(geany_object, "project-save", config);
	}
	/* write the file */
	data = g_key_file_to_data(config, NULL, NULL);
	ret = (utils_write_file(filename, data) == 0);

	g_free(data);
	g_free(filename);
	g_key_file_free(config);

	return ret;
}
Example #12
0
void plugin_cleanup(void)
{
	gchar *data = g_key_file_to_data(config, NULL, NULL);
	utils_write_file(conf, data);
	g_free(data);
	g_key_file_free(config);

	gtk_notebook_remove_page(
		GTK_NOTEBOOK(geany->main_widgets->sidebar_notebook),
		gtk_notebook_page_num(GTK_NOTEBOOK(geany->main_widgets->sidebar_notebook), panel)
	);
	g_regex_unref(trim_file);
	g_regex_unref(trim_regex);
}
Example #13
0
void plugin_cleanup(void)
{
	gchar *data = g_key_file_to_data(config, NULL, NULL);
	utils_write_file(conf, data);
	g_free(data);
	g_key_file_free(config);

	g_free(pathRegexSetting.text);
	g_free(nameRegexSetting.text);
	g_regex_unref(pathRegexSetting.regex);
	g_regex_unref(nameRegexSetting.regex);

	gtk_widget_destroy(quick_open_project_menu);
	gtk_widget_destroy(quick_open_menu);
}
Example #14
0
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);
    }
}
Example #15
0
static void
update_settings_cb()
{
	GKeyFile *kf = g_key_file_new();
	gchar *data;

	g_key_file_set_string(kf, UNIX_NAME, "mono_font", gdbui_setup.options.mono_font);
	g_key_file_set_string(kf, UNIX_NAME, "term_cmd", gdbui_setup.options.term_cmd);
	g_key_file_set_boolean(kf, UNIX_NAME, "show_tooltips", gdbui_setup.options.show_tooltips);
	g_key_file_set_boolean(kf, UNIX_NAME, "show_icons", gdbui_setup.options.show_icons);

	data = g_key_file_to_data(kf, NULL, NULL);
	utils_write_file(config_file, data);
	g_free(data);

	g_key_file_free(kf);
	gtk_widget_destroy(GTK_BIN(frame)->child);
	gdbui_create_widgets(frame);
	gtk_widget_show_all(frame);
}
Example #16
0
void configure_response (GtkDialog *dialog, gint response, gpointer char_tree_view)
{
	GtkTreeIter char_iter;
	GKeyFile *config;
	gchar *config_data = NULL;
	gchar key_name[] = "Enclose_x";
	gint i;

	if (response != GTK_RESPONSE_OK && response != GTK_RESPONSE_ACCEPT)
		return;

	gtk_tree_model_get_iter_first (GTK_TREE_MODEL(chars_list), &char_iter);

	config = g_key_file_new();
	g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL);

	for (i = 0; i < 8; i++)
	{
		gchar *prior_char_str, *end_char_str;

		key_name [8] = (gchar) (i + '0');

		gtk_tree_model_get (GTK_TREE_MODEL(chars_list), &char_iter,
			COLUMN_PRIOR_CHAR, &prior_char_str, COLUMN_END_CHAR, &end_char_str, -1);
		*enclose_chars [i] = prior_char_str [0];
		*(enclose_chars [i] + 1) = end_char_str [0];
		gtk_tree_model_iter_next (GTK_TREE_MODEL(chars_list), &char_iter);

		g_key_file_set_string (config, "addons", key_name, enclose_chars [i]);

		g_free (prior_char_str);
		g_free (end_char_str);
	}

	config_data = g_key_file_to_data (config, NULL, NULL);
	utils_write_file (config_file, config_data);

	g_free (config_data);
	g_key_file_free(config);
}
int
screenshot_scr_write( const char *filename )
{
  libspectrum_byte scr_data[HIRES_SCR_SIZE];
  int scr_length;

  memset( scr_data, 0, HIRES_SCR_SIZE );

  if( scld_last_dec.name.hires ) {
    memcpy( scr_data,
            &RAM[ memory_current_screen ][display_get_addr(0,0)],
            MONO_BITMAP_SIZE );
    memcpy( scr_data + MONO_BITMAP_SIZE,
            &RAM[ memory_current_screen ][display_get_addr(0,0) +
            ALTDFILE_OFFSET], MONO_BITMAP_SIZE );
    scr_data[HIRES_ATTR] = ( scld_last_dec.byte & HIRESCOLMASK ) |
                           scld_last_dec.mask.scrnmode;
    scr_length = HIRES_SCR_SIZE;
  }
  else if( scld_last_dec.name.b1 ) {
    memcpy( scr_data,
            &RAM[ memory_current_screen ][display_get_addr(0,0)],
            MONO_BITMAP_SIZE );
    memcpy( scr_data + MONO_BITMAP_SIZE,
            &RAM[ memory_current_screen ][display_get_addr(0,0) +
            ALTDFILE_OFFSET], MONO_BITMAP_SIZE );
    scr_length = HICOLOUR_SCR_SIZE;
  }
  else { /* ALTDFILE and default */
    memcpy( scr_data, 
            &RAM[ memory_current_screen ][display_get_addr(0,0)],
            STANDARD_SCR_SIZE );
    scr_length = STANDARD_SCR_SIZE;
  }

  return utils_write_file( filename, scr_data, scr_length );
}
Example #18
0
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);
	}
}
Example #19
0
/* 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."));
	}
}
Example #20
0
/**
 * @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);

}
/* save settings (preferences, file data such as fold states, marker positions) */
static void SaveSettings(gchar *filename)
{
	GKeyFile *config=NULL;
	gchar *config_file=NULL,*config_dir=NULL;
	gchar *data;
	FileData* fdTemp=fdKnownFilesSettings;
	gint i=0;

	/* create new config from default settings */
	config=g_key_file_new();

	/* now set settings */
	g_key_file_set_boolean(config,"Settings","Center_When_Goto_Bookmark",bCenterWhenGotoBookmark);
	g_key_file_set_boolean(config,"Settings","Remember_Folds",bRememberFolds);
	g_key_file_set_integer(config,"Settings","Position_In_Line",PositionInLine);
	g_key_file_set_integer(config,"Settings","Where_To_Save_File_Details",WhereToSaveFileDetails);
	g_key_file_set_boolean(config,"Settings","Remember_Bookmarks",bRememberBookmarks);
	if(FileDetailsSuffix!=NULL)
		g_key_file_set_string(config,"Settings","File_Details_Suffix",FileDetailsSuffix);

	/* now save file data */
	while(fdTemp!=NULL)
	{
		/* if this entry has data needing saveing then save it and increment the counter */
		if(SaveIndividualSetting(config,fdTemp,i,fdTemp->pcFileName))
			i++;

		fdTemp=fdTemp->NextNode;
	}

	/* turn config into data */
	data=g_key_file_to_data(config,NULL,NULL);

	/* calculate setting directory name */
	config_dir=g_build_filename(geany->app->configdir,"plugins","Geany_Numbered_Bookmarks",NULL);
	/* ensure directory exists */
	g_mkdir_with_parents(config_dir,0755);

	/* make config_file hold name of settings file */
	config_file=g_build_filename(config_dir,"settings.conf",NULL);

	/* write data */
	utils_write_file(config_file,data);

	/* free memory */
	g_free(config_dir);
	g_free(config_file);
	g_key_file_free(config);
	g_free(data);

	/* now consider if not purely saving file settings to main settings file */
	/* return if not saving data with file */
	if(filename==NULL || WhereToSaveFileDetails==0)
		return;

	/* setup keyfile to hold values */
	config=g_key_file_new();

	/* get pointer to data we're saving */
	fdTemp=GetFileData(filename);

	/* calculate settings filename */
	config_file=g_strdup_printf("%s%s",filename,FileDetailsSuffix);

	/* if nothing to save then delete any old data */
	if(SaveIndividualSetting(config,fdTemp,-1,NULL)==FALSE)
		g_remove(config_file);
	/* otherwise save the data */
	else
	{
		/* turn config into data */
		data=g_key_file_to_data(config,NULL,NULL);
		/* write data */
		utils_write_file(config_file,data);

		g_free(data);
	}

	/* free memory */
	g_free(config_file);
	g_key_file_free(config);
}
Example #22
0
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);
	}
}
Example #23
0
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);
	}
}