[Xfce4-commits] <orage:master> 4.8.0.6: Fixed bug 7192: Orage does not support the xdg dirs spec
Juha Kautto
noreply at xfce.org
Mon Jan 31 14:28:01 CET 2011
Updating branch refs/heads/master
to c7372febc25d071659b8d29821956b41938fa7bc (commit)
from 4786eb856190934bf7a5aeac8bf1a1c95db969a3 (commit)
commit c7372febc25d071659b8d29821956b41938fa7bc
Author: Juha Kautto <juha at xfce.org>
Date: Mon Jan 31 15:24:00 2011 +0200
4.8.0.6: Fixed bug 7192: Orage does not support the xdg dirs spec
Added support for xdg config and data specification, so that default settings
can now be utilized.
configure.in.in | 2 +-
src/functions.c | 119 +++++++++++++++++++++++++++++++++++++++++++++----------
src/interface.c | 17 +++++---
3 files changed, 110 insertions(+), 28 deletions(-)
diff --git a/configure.in.in b/configure.in.in
index fac4e9a..fa565fa 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -9,7 +9,7 @@ dnl Written for Xfce by Juha Kautto <juha at xfce.org>
dnl
dnl Version information
-m4_define([orage_version], [4.8.0.5-git])
+m4_define([orage_version], [4.8.0.6-git])
m4_define([gtk_minimum_version], [2.10.0])
m4_define([xfce_minimum_version], [4.6.0])
diff --git a/src/functions.c b/src/functions.c
index ad10f78..fd7e637 100644
--- a/src/functions.c
+++ b/src/functions.c
@@ -58,6 +58,7 @@ int g_log_level=0;
* grep MARK /tmp/logfile.strace
* grep MARK /tmp/logfile.strace|sed s/", F_OK) = -1 ENOENT (No such file or directory)"/\)/
* */
+/*
void program_log (const char *format, ...)
{
va_list args;
@@ -73,6 +74,7 @@ void program_log (const char *format, ...)
access (str, F_OK);
g_free (str);
}
+*/
/* Print message at various level:
* < 0 = Debug (Use only in special debug code which should not be in
@@ -749,47 +751,122 @@ void orage_select_today(GtkCalendar *cal)
* data and config file locations
*******************************************************/
+gboolean orage_copy_file(gchar *source, gchar *target)
+{
+ gchar *text;
+ gsize text_len;
+ GError *error = NULL;
+ gboolean ok = TRUE;
+
+ /* read file */
+ if (!g_file_get_contents(source, &text, &text_len, &error)) {
+ orage_message(150, "orage_copy_file: Could not open file (%s) error:%s"
+ , source, error->message);
+ g_error_free(error);
+ ok = FALSE;
+ }
+ /* write file */
+ if (!g_file_set_contents(target, text, -1, &error)) {
+ orage_message(150, "orage_copy_file: Could not write file (%s) error:%s"
+ , target, error->message);
+ g_error_free(error);
+ ok = FALSE;
+ }
+ g_free(text);
+ return(ok);
+}
+
+gchar *orage_xdg_system_data_file_location(char *name)
+{
+ char *file_name;
+ const gchar * const *base_dirs;
+ int i;
+
+ base_dirs = g_get_system_data_dirs();
+ for (i = 0; base_dirs[i] != NULL; i++) {
+ file_name = g_build_filename(base_dirs[i], name, NULL);
+ if (g_file_test(file_name, G_FILE_TEST_IS_REGULAR)) {
+ return(file_name);
+ }
+ g_free(file_name);
+ }
+
+ /* no system wide data file */
+ return(NULL);
+}
+
+/* Returns valid xdg local data file name.
+ If the file did not exist, it checks if there are system defaults
+ and creates it from those */
gchar *orage_data_file_location(char *name)
{
- char *file_name, *dir_name;
+ char *file_name, *dir_name, *sys_name;
const char *base_dir;
int mode = 0700;
- /*
- file_name = xfce_resource_save_location(XFCE_RESOURCE_DATA, name, TRUE);
- g_print("orage_data_file_location (%s) (%s)\n", file_name, g_get_user_data_dir());
- */
-
base_dir = g_get_user_data_dir();
file_name = g_build_filename(base_dir, name, NULL);
- dir_name = g_path_get_dirname((const gchar *)file_name);
- if (g_mkdir_with_parents(dir_name, mode)) {
- g_print("orage_data_file_location: (%s) (%s) directory creation failed.\n", base_dir, file_name);
+ if (!g_file_test(file_name, G_FILE_TEST_IS_REGULAR)) {
+ /* it does not exist, let's try to create it */
+ dir_name = g_path_get_dirname((const gchar *)file_name);
+ if (g_mkdir_with_parents(dir_name, mode)) {
+ orage_message(150, "orage_data_file_location: (%s) (%s) directory creation failed.\n", base_dir, file_name);
+ }
+ g_free(dir_name);
+ /* now we have the directories ready, let's check for system default */
+ sys_name = orage_xdg_system_data_file_location(name);
+ if (sys_name) { /* we found it, we need to copy it */
+ orage_copy_file(sys_name, file_name);
+ }
}
- g_free(dir_name);
return(file_name);
}
+/* these are default files and must only be read */
+gchar *orage_xdg_system_config_file_location(char *name)
+{
+ char *file_name;
+ const gchar * const *base_dirs;
+ int i;
+
+ base_dirs = g_get_system_config_dirs();
+ for (i = 0; base_dirs[i] != NULL; i++) {
+ file_name = g_build_filename(base_dirs[i], name, NULL);
+ if (g_file_test(file_name, G_FILE_TEST_IS_REGULAR)) {
+ return(file_name);
+ }
+ g_free(file_name);
+ }
+
+ /* no system wide config file */
+ return(NULL);
+}
+
+/* Returns valid xdg local config file name.
+ If the file did not exist, it checks if there are system defaults
+ and creates it from those */
gchar *orage_config_file_location(char *name)
{
- char *file_name, *dir_name;
+ char *file_name, *dir_name, *sys_name;
const char *base_dir;
int mode = 0700;
- /*
- file_name = xfce_resource_save_location(XFCE_RESOURCE_CONFIG, name
- , TRUE);
- g_print("orage_config_file_location (%s) (%s)\n", file_name, g_get_user_config_dir());
- */
-
base_dir = g_get_user_config_dir();
file_name = g_build_filename(base_dir, name, NULL);
- dir_name = g_path_get_dirname((const gchar *)file_name);
- if (g_mkdir_with_parents(dir_name, mode)) {
- g_print("orage_config_file_location: (%s) (%s) directory creation failed.\n", base_dir, file_name);
+ if (!g_file_test(file_name, G_FILE_TEST_IS_REGULAR)) {
+ /* it does not exist, let's try to create it */
+ dir_name = g_path_get_dirname((const gchar *)file_name);
+ if (g_mkdir_with_parents(dir_name, mode)) {
+ orage_message(150, "orage_config_file_location: (%s) (%s) directory creation failed.\n", base_dir, file_name);
+ }
+ g_free(dir_name);
+ /* now we have the directories ready, let's check for system default */
+ sys_name = orage_xdg_system_config_file_location(name);
+ if (sys_name) { /* we found it, we need to copy it */
+ orage_copy_file(sys_name, file_name);
+ }
}
- g_free(dir_name);
return(file_name);
}
diff --git a/src/interface.c b/src/interface.c
index ada12a2..312e86e 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -119,6 +119,7 @@ static void orage_file_entry_changed(GtkWidget *dialog, gpointer user_data)
}
}
+/* FIXME: This is now available in functions.c as orage_copy_file */
static gboolean copy_file(gchar *source, gchar *target)
{
gchar *text;
@@ -317,12 +318,14 @@ static void orage_file_open_button_clicked(GtkButton *button
{
intf_win *intf_w = (intf_win *)user_data;
GtkWidget *f_chooser;
- gchar *rcfile;
+ gchar *rcfile, *rcdir;
gchar *s;
- rcfile = orage_data_file_location(ORAGE_DIR);
+ rcdir = g_path_get_dirname((const gchar *)g_par.orage_file);
+ rcfile = g_path_get_basename((const gchar *)g_par.orage_file);
f_chooser = orage_file_chooser(intf_w->main_window, TRUE
- , g_par.orage_file, rcfile, ORAGE_APP_FILE);
+ , g_par.orage_file, rcdir, rcfile);
+ g_free(rcdir);
g_free(rcfile);
if (gtk_dialog_run(GTK_DIALOG(f_chooser)) == GTK_RESPONSE_ACCEPT) {
@@ -344,12 +347,14 @@ static void archive_file_open_button_clicked(GtkButton *button
{
intf_win *intf_w = (intf_win *)user_data;
GtkWidget *f_chooser;
- gchar *rcfile;
+ gchar *rcfile, *rcdir;
gchar *s;
- rcfile = orage_data_file_location(ORAGE_DIR);
+ rcdir = g_path_get_dirname((const gchar *)g_par.archive_file);
+ rcfile = g_path_get_basename((const gchar *)g_par.archive_file);
f_chooser = orage_file_chooser(intf_w->main_window, TRUE
- , g_par.archive_file, rcfile, ORAGE_ARC_FILE);
+ , g_par.archive_file, rcdir, rcfile);
+ g_free(rcdir);
g_free(rcfile);
if (gtk_dialog_run(GTK_DIALOG(f_chooser)) == GTK_RESPONSE_ACCEPT) {
More information about the Xfce4-commits
mailing list