Search
lxdream.org :: lxdream/src/guiutil.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/guiutil.c
changeset 1036:af7b0c5905dd
next1038:f220d18c0615
author nkeynes
date Wed Jun 24 06:06:40 2009 +0000 (14 years ago)
permissions -rw-r--r--
last change Support shell substitutions in config paths
Keep track of last folder in file dialogs
Fix out-of-dateness in GTK path dialog
file annotate diff log raw
nkeynes@1036
     1
/**
nkeynes@1036
     2
 * $Id$
nkeynes@1036
     3
 *
nkeynes@1036
     4
 * GUI helper functions that aren't specific to any particular implementation.
nkeynes@1036
     5
 *
nkeynes@1036
     6
 * Copyright (c) 2009 Nathan Keynes.
nkeynes@1036
     7
 *
nkeynes@1036
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@1036
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@1036
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@1036
    11
 * (at your option) any later version.
nkeynes@1036
    12
 *
nkeynes@1036
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@1036
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@1036
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@1036
    16
 * GNU General Public License for more details.
nkeynes@1036
    17
 */
nkeynes@1036
    18
nkeynes@1036
    19
#include <glib/gstrfuncs.h>
nkeynes@1036
    20
#include <glib/gutils.h>
nkeynes@1036
    21
nkeynes@1036
    22
#include "gui.h"
nkeynes@1036
    23
#include "config.h"
nkeynes@1036
    24
nkeynes@1036
    25
static gchar *gui_paths[CONFIG_KEY_MAX];
nkeynes@1036
    26
nkeynes@1036
    27
gchar *get_absolute_path( const gchar *in_path )
nkeynes@1036
    28
{
nkeynes@1036
    29
    char tmp[PATH_MAX];
nkeynes@1036
    30
    if( in_path == NULL ) {
nkeynes@1036
    31
        return NULL;
nkeynes@1036
    32
    }
nkeynes@1036
    33
    if( in_path[0] == '/' || in_path[0] == 0 ) {
nkeynes@1036
    34
        return g_strdup(in_path);
nkeynes@1036
    35
    } else {
nkeynes@1036
    36
        getcwd(tmp, sizeof(tmp));
nkeynes@1036
    37
        return g_strdup_printf("%s%c%s", tmp, G_DIR_SEPARATOR, in_path);
nkeynes@1036
    38
    }
nkeynes@1036
    39
}
nkeynes@1036
    40
nkeynes@1036
    41
const gchar *gui_get_configurable_path( int key )
nkeynes@1036
    42
{
nkeynes@1036
    43
    if( gui_paths[key] == NULL ) {
nkeynes@1036
    44
        gui_paths[key] = lxdream_get_global_config_path_value(key);
nkeynes@1036
    45
        /* If no path defined, go with the current working directory */
nkeynes@1036
    46
        if( gui_paths[key] == NULL ) {
nkeynes@1036
    47
            gui_paths[key] = get_absolute_path(".");
nkeynes@1036
    48
        }
nkeynes@1036
    49
    }
nkeynes@1036
    50
    return gui_paths[key];
nkeynes@1036
    51
}
nkeynes@1036
    52
nkeynes@1036
    53
void gui_set_configurable_path( int key, const gchar *path )
nkeynes@1036
    54
{
nkeynes@1036
    55
    g_free(gui_paths[key]);
nkeynes@1036
    56
    gui_paths[key] = g_strdup(path);
nkeynes@1036
    57
}
nkeynes@1036
    58
nkeynes@1036
    59
void gui_config_paths_changed()
nkeynes@1036
    60
{
nkeynes@1036
    61
    int i;
nkeynes@1036
    62
    for( i=0; i < CONFIG_KEY_MAX; i++ ) {
nkeynes@1036
    63
        g_free(gui_paths[i]);
nkeynes@1036
    64
        gui_paths[i] = NULL;
nkeynes@1036
    65
    }
nkeynes@1036
    66
}
.