about summary refs log tree commit diff stats
path: root/src/config
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-07-24 16:22:15 +0100
committerJames Booth <boothj5@gmail.com>2016-07-24 16:22:15 +0100
commitef942bd27a759b3016c473abba8066a8ddcb6ffe (patch)
treeb4964a5d9fd2920c1195a98d08f82c44a7ef0dc4 /src/config
parente7bfaa643fd8f57c50390194b0c804cacd5a0de4 (diff)
downloadprofani-tty-ef942bd27a759b3016c473abba8066a8ddcb6ffe.tar.gz
Add config/files.c
Diffstat (limited to 'src/config')
-rw-r--r--src/config/accounts.c1
-rw-r--r--src/config/files.c124
-rw-r--r--src/config/files.h44
-rw-r--r--src/config/preferences.c1
-rw-r--r--src/config/scripts.c1
-rw-r--r--src/config/theme.c5
-rw-r--r--src/config/tlscerts.c1
7 files changed, 175 insertions, 2 deletions
diff --git a/src/config/accounts.c b/src/config/accounts.c
index 7f852e6f..84671b74 100644
--- a/src/config/accounts.c
+++ b/src/config/accounts.c
@@ -42,6 +42,7 @@
 
 #include "common.h"
 #include "log.h"
+#include "config/files.h"
 #include "config/account.h"
 #include "config/conflists.h"
 #include "tools/autocomplete.h"
diff --git a/src/config/files.c b/src/config/files.c
new file mode 100644
index 00000000..5f57f691
--- /dev/null
+++ b/src/config/files.c
@@ -0,0 +1,124 @@
+/*
+ * files.c
+ *
+ * Copyright (C) 2012 - 2016 James Booth <boothj5@gmail.com>
+ *
+ * This file is part of Profanity.
+ *
+ * Profanity is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Profanity is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Profanity.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ * In addition, as a special exception, the copyright holders give permission to
+ * link the code of portions of this program with the OpenSSL library under
+ * certain conditions as described in each individual source file, and
+ * distribute linked combinations including the two.
+ *
+ * You must obey the GNU General Public License in all respects for all of the
+ * code used other than OpenSSL. If you modify file(s) with this exception, you
+ * may extend this exception to your version of the file(s), but you are not
+ * obligated to do so. If you do not wish to do so, delete this exception
+ * statement from your version. If you delete this exception statement from all
+ * source files in the program, then also delete it here.
+ *
+ */
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <glib.h>
+
+#include "common.h"
+#include "log.h"
+#include "config/files.h"
+
+void
+files_create_directories(void)
+{
+    gchar *xdg_config = xdg_get_config_home();
+    gchar *xdg_data = xdg_get_data_home();
+
+    GString *themes_dir = g_string_new(xdg_config);
+    g_string_append(themes_dir, "/profanity/themes");
+    GString *icons_dir = g_string_new(xdg_config);
+    g_string_append(icons_dir, "/profanity/icons");
+    GString *chatlogs_dir = g_string_new(xdg_data);
+    g_string_append(chatlogs_dir, "/profanity/chatlogs");
+    GString *logs_dir = g_string_new(xdg_data);
+    g_string_append(logs_dir, "/profanity/logs");
+    GString *plugins_dir = g_string_new(xdg_data);
+    g_string_append(plugins_dir, "/profanity/plugins");
+
+    if (!mkdir_recursive(themes_dir->str)) {
+        log_error("Error while creating directory %s", themes_dir->str);
+    }
+    if (!mkdir_recursive(icons_dir->str)) {
+        log_error("Error while creating directory %s", icons_dir->str);
+    }
+    if (!mkdir_recursive(chatlogs_dir->str)) {
+        log_error("Error while creating directory %s", chatlogs_dir->str);
+    }
+    if (!mkdir_recursive(logs_dir->str)) {
+        log_error("Error while creating directory %s", logs_dir->str);
+    }
+    if (!mkdir_recursive(plugins_dir->str)) {
+        log_error("Error while creating directory %s", plugins_dir->str);
+    }
+
+    g_string_free(themes_dir, TRUE);
+    g_string_free(icons_dir, TRUE);
+    g_string_free(chatlogs_dir, TRUE);
+    g_string_free(logs_dir, TRUE);
+    g_string_free(plugins_dir, TRUE);
+
+    g_free(xdg_config);
+    g_free(xdg_data);
+}
+
+gchar*
+xdg_get_config_home(void)
+{
+    gchar *xdg_config_home = getenv("XDG_CONFIG_HOME");
+    if (xdg_config_home)
+        g_strstrip(xdg_config_home);
+
+    if (xdg_config_home && (strcmp(xdg_config_home, "") != 0)) {
+        return strdup(xdg_config_home);
+    } else {
+        GString *default_path = g_string_new(getenv("HOME"));
+        g_string_append(default_path, "/.config");
+        gchar *result = strdup(default_path->str);
+        g_string_free(default_path, TRUE);
+
+        return result;
+    }
+}
+
+gchar*
+xdg_get_data_home(void)
+{
+    gchar *xdg_data_home = getenv("XDG_DATA_HOME");
+    if (xdg_data_home)
+        g_strstrip(xdg_data_home);
+
+    if (xdg_data_home && (strcmp(xdg_data_home, "") != 0)) {
+        return strdup(xdg_data_home);
+    } else {
+        GString *default_path = g_string_new(getenv("HOME"));
+        g_string_append(default_path, "/.local/share");
+        gchar *result = strdup(default_path->str);
+        g_string_free(default_path, TRUE);
+
+        return result;
+    }
+}
diff --git a/src/config/files.h b/src/config/files.h
new file mode 100644
index 00000000..431229f7
--- /dev/null
+++ b/src/config/files.h
@@ -0,0 +1,44 @@
+/*
+ * files.h
+ *
+ * Copyright (C) 2012 - 2016 James Booth <boothj5@gmail.com>
+ *
+ * This file is part of Profanity.
+ *
+ * Profanity is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Profanity is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Profanity.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ * In addition, as a special exception, the copyright holders give permission to
+ * link the code of portions of this program with the OpenSSL library under
+ * certain conditions as described in each individual source file, and
+ * distribute linked combinations including the two.
+ *
+ * You must obey the GNU General Public License in all respects for all of the
+ * code used other than OpenSSL. If you modify file(s) with this exception, you
+ * may extend this exception to your version of the file(s), but you are not
+ * obligated to do so. If you do not wish to do so, delete this exception
+ * statement from your version. If you delete this exception statement from all
+ * source files in the program, then also delete it here.
+ *
+ */
+
+#ifndef CONFIG_FILES_H
+#define CONFIG_FILES_H
+
+#include <glib.h>
+
+gchar* xdg_get_config_home(void);
+gchar* xdg_get_data_home(void);
+void files_create_directories(void);
+
+#endif
diff --git a/src/config/preferences.c b/src/config/preferences.c
index 4377cdfc..3fd32586 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -45,6 +45,7 @@
 #include "log.h"
 #include "preferences.h"
 #include "tools/autocomplete.h"
+#include "config/files.h"
 #include "config/conflists.h"
 
 // preference groups refer to the sections in .profrc, for example [ui]
diff --git a/src/config/scripts.c b/src/config/scripts.c
index 14f05f29..91dbe4df 100644
--- a/src/config/scripts.c
+++ b/src/config/scripts.c
@@ -42,6 +42,7 @@
 
 #include "common.h"
 #include "log.h"
+#include "config/files.h"
 #include "command/cmd_defs.h"
 #include "ui/ui.h"
 #include "ui/window_list.h"
diff --git a/src/config/theme.c b/src/config/theme.c
index 0ba9c786..fb208279 100644
--- a/src/config/theme.c
+++ b/src/config/theme.c
@@ -47,8 +47,9 @@
 
 #include "common.h"
 #include "log.h"
-#include "theme.h"
-#include "preferences.h"
+#include "config/files.h"
+#include "config/theme.h"
+#include "config/preferences.h"
 
 static GString *theme_loc;
 static GKeyFile *theme;
diff --git a/src/config/tlscerts.c b/src/config/tlscerts.c
index b51f5ff9..03a8bd97 100644
--- a/src/config/tlscerts.c
+++ b/src/config/tlscerts.c
@@ -40,6 +40,7 @@
 
 #include "log.h"
 #include "common.h"
+#include "config/files.h"
 #include "config/tlscerts.h"
 #include "tools/autocomplete.h"