Ejemplo n.º 1
0
static void
_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 *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");

    if (!mkdir_recursive(themes_dir->str)) {
        log_error("Error while creating directory %s", themes_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);
    }

    g_string_free(themes_dir, TRUE);
    g_string_free(chatlogs_dir, TRUE);
    g_string_free(logs_dir, TRUE);

    g_free(xdg_config);
    g_free(xdg_data);
}
Ejemplo n.º 2
0
static gchar *
_get_themes_dir(void)
{
    gchar *xdg_config = xdg_get_config_home();
    GString *themes_dir = g_string_new(xdg_config);
    g_free(xdg_config);
    g_string_append(themes_dir, "/profanity/themes");
    return g_string_free(themes_dir, FALSE);
}
Ejemplo n.º 3
0
static int xdg_for_each_config_found
  (
    const char * itempath, /* relative path of item to look for in each directory */
    xdg_item_path_action action,
    void * actionarg,
    bool forwards /* false to do in reverse */
  )
  {
    xdg_for_each_config_found_context context;
    int status = 0;
    const char * const home_path = xdg_get_config_home();
    const char * const search_path = xdg_config_search_path();
    context.itempath = itempath;
    context.action = action;
    context.actionarg = actionarg;
    do /*once*/
      {
        if (home_path != 0 && forwards)
          {
            status = xdg_for_each_config_found_try_component
              (
                (const unsigned char *)home_path,
                strlen(home_path),
                &context
              );
            if (status != 0)
                break;
          } /*if*/
        status = xdg_for_each_path_component
          (
            /*path =*/ (const unsigned char *)search_path,
            /*path_len =*/ strlen(search_path),
            /*action =*/ (xdg_path_component_action)xdg_for_each_config_found_try_component,
            /*actionarg =*/ (void *)&context,
            /*forwards =*/ forwards
          );
        if (status != 0)
            break;
        if (home_path != 0 && !forwards)
          {
            status = xdg_for_each_config_found_try_component
              (
                (const unsigned char *)home_path,
                strlen(home_path),
                &context
              );
            if (status != 0)
                break;
          } /*if*/
      }
    while (false);
    if (home_path != 0)
        free((void *)home_path);
    free((void *)search_path);
    return
        status;
  } /*xdg_for_each_config_found*/
Ejemplo n.º 4
0
static gchar *
_get_preferences_file(void)
{
    gchar *xdg_config = xdg_get_config_home();
    GString *prefs_file = g_string_new(xdg_config);
    g_string_append(prefs_file, "/profanity/profrc");
    gchar *result = strdup(prefs_file->str);
    g_free(xdg_config);
    g_string_free(prefs_file, TRUE);

    return result;
}
Ejemplo n.º 5
0
/*
 * Get icons from installation share folder or (if defined) .locale user's folder
 *
 * As implementation, looking through all the entries in the .locale folder is chosen.
 * While useless as now, it might be useful in case an association name-icon is created.
 * As now, with 2 icons only, this is pretty useless, but it is not harming ;)
 *
 */
static void _get_icons(void)
{
    GString *icons_dir =  NULL;

#ifdef ICONS_PATH

    icons_dir = g_string_new(ICONS_PATH);
    icon_filename = g_string_new(icons_dir->str);
    icon_msg_filename = g_string_new(icons_dir->str);
    g_string_append(icon_filename, "/proIcon.png");
    g_string_append(icon_msg_filename, "/proIconMsg.png");
    g_string_free(icons_dir, true);

#endif /* ICONS_PATH */

    gchar *xdg_config = xdg_get_config_home();
    icons_dir = g_string_new(xdg_config);
    g_free(xdg_config);
    g_string_append(icons_dir, "/profanity/icons");
    GError *err = NULL;
    if (!g_file_test(icons_dir->str, G_FILE_TEST_IS_DIR)) {
        return;
    }
    GDir *dir = g_dir_open(icons_dir->str, 0, &err);
    if (dir) {
        GString *name = g_string_new(g_dir_read_name(dir));
        while (name->len) {
            if (g_strcmp0("proIcon.png", name->str) == 0) {
                if (icon_filename) {
                    g_string_free(icon_filename, true);
                }
                icon_filename = g_string_new(icons_dir->str);
                g_string_append(icon_filename, "/proIcon.png");
            } else
            if (g_strcmp0("proIconMsg.png", name->str) == 0){
                if (icon_msg_filename) {
                    g_string_free(icon_msg_filename, true);
                }
                icon_msg_filename = g_string_new(icons_dir->str);
                g_string_append(icon_msg_filename, "/proIconMsg.png");
            }
            g_string_free(name, true);
            name = g_string_new(g_dir_read_name(dir));
        }
        g_string_free(name, true);
    } else {
        log_error("Unable to open dir: %s", err->message);
        g_error_free(err);
    }
    g_dir_close(dir);
    g_string_free(icons_dir, true);
}
Ejemplo n.º 6
0
void create_config_dir(void **state)
{
    setenv("XDG_CONFIG_HOME", "./tests/files/xdg_config_home", 1);
    gchar *xdg_config = xdg_get_config_home();

    GString *profanity_dir = g_string_new(xdg_config);
    g_string_append(profanity_dir, "/profanity");

    if (!mkdir_recursive(profanity_dir->str)) {
        assert_true(FALSE);
    }

    g_free(xdg_config);
    g_string_free(profanity_dir, TRUE);
}
Ejemplo n.º 7
0
static void
_save_prefs(void)
{
    gsize g_data_size;
    gchar *g_prefs_data = g_key_file_to_data(prefs, &g_data_size, NULL);
    gchar *xdg_config = xdg_get_config_home();
    GString *base_str = g_string_new(xdg_config);
    g_string_append(base_str, "/profanity/");
    gchar *true_loc = get_file_or_linked(prefs_loc, base_str->str);
    g_file_set_contents(true_loc, g_prefs_data, g_data_size, NULL);
    g_chmod(prefs_loc, S_IRUSR | S_IWUSR);
    g_free(xdg_config);
    free(true_loc);
    g_free(g_prefs_data);
    g_string_free(base_str, TRUE);
}
Ejemplo n.º 8
0
gchar*
prefs_get_inputrc(void)
{
    gchar *xdg_config = xdg_get_config_home();
    GString *inputrc_file = g_string_new(xdg_config);
    g_free(xdg_config);

    g_string_append(inputrc_file, "/profanity/inputrc");

    if (g_file_test(inputrc_file->str, G_FILE_TEST_IS_REGULAR)) {
        gchar *result = strdup(inputrc_file->str);
        g_string_free(inputrc_file, TRUE);

        return result;
    }

    return NULL;
}