Skip to content

Commit

Permalink
Added glib ver. check < 2.40 and manual write of key_file.
Browse files Browse the repository at this point in the history
  • Loading branch information
David C. Rankin committed Mar 10, 2017
1 parent c71fe39 commit 2ed5d73
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
36 changes: 36 additions & 0 deletions gtk_appdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,27 @@ static void context_read_keyfile (kwinst *app)

}

#ifndef HAVEKEYFILE
/** general use err_dialog, just pass errmsg. */
static void err_dialog (const gchar *errmsg)
{
GtkWidget *dialog;

g_warning (errmsg); /* log to terminal window */

/* create an error dialog and display modally to the user */
dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
errmsg);

gtk_window_set_title (GTK_WINDOW (dialog), "Error!");
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
#endif

/** write settings to key_file, key_file created if it doesn't exist.
* (default location $HOME/.config/gtkwrite/gtkwrite.cfg)
*/
Expand Down Expand Up @@ -265,8 +286,23 @@ static void context_write_keyfile (kwinst *app)
g_key_file_set_double (app->keyfile, "print", "marginleft", app->marginleft);
g_key_file_set_double (app->keyfile, "print", "marginright", app->marginright);

#ifdef HAVEKEYFILE
if (!g_key_file_save_to_file (app->keyfile, app->cfgfile, NULL))
g_print ("error: saving keyfile failed '%s'\n", app->cfgfile);
#else
GError *err=NULL;
gchar *kfd;
gsize len;

kfd = g_key_file_to_data (app->keyfile, &len, NULL);

if (!g_file_set_contents (app->cfgfile, kfd, -1, &err)) {
err_dialog (err->message);
g_error_free (err);
}

if (kfd) g_free (kfd);
#endif

}

Expand Down
4 changes: 4 additions & 0 deletions gtk_appdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include <glib.h>
#include <gtk/gtk.h>

#if GLIB_MAJOR_VERSION >= 2 && GLIB_MINOR_VERSION >= 40
#define HAVEKEYFILE
#endif

#ifdef WGTKSOURCEVIEW2
#include <gtksourceview/gtksourceview.h>
#include <gtksourceview/gtksourcelanguagemanager.h>
Expand Down

0 comments on commit 2ed5d73

Please sign in to comment.