Search
lxdream.org :: lxdream/src/guiutil.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/guiutil.c
changeset 1038:f220d18c0615
prev1036:af7b0c5905dd
author nkeynes
date Thu Jun 25 01:15:25 2009 +0000 (13 years ago)
permissions -rw-r--r--
last change Move configuration to .lxdream/lxdreamrc on *nix, Library/Application Support/Lxdream on OS X
Create standard directories on first run
Add current quick state to config file
Refactor quick-state handling into dreamcast.c, and use the save directory
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@1038
    19
#include <unistd.h>
nkeynes@1036
    20
#include <glib/gstrfuncs.h>
nkeynes@1036
    21
#include <glib/gutils.h>
nkeynes@1036
    22
nkeynes@1036
    23
#include "gui.h"
nkeynes@1036
    24
#include "config.h"
nkeynes@1036
    25
nkeynes@1036
    26
static gchar *gui_paths[CONFIG_KEY_MAX];
nkeynes@1036
    27
nkeynes@1036
    28
gchar *get_absolute_path( const gchar *in_path )
nkeynes@1036
    29
{
nkeynes@1036
    30
    char tmp[PATH_MAX];
nkeynes@1036
    31
    if( in_path == NULL ) {
nkeynes@1036
    32
        return NULL;
nkeynes@1036
    33
    }
nkeynes@1036
    34
    if( in_path[0] == '/' || in_path[0] == 0 ) {
nkeynes@1036
    35
        return g_strdup(in_path);
nkeynes@1036
    36
    } else {
nkeynes@1036
    37
        getcwd(tmp, sizeof(tmp));
nkeynes@1036
    38
        return g_strdup_printf("%s%c%s", tmp, G_DIR_SEPARATOR, in_path);
nkeynes@1036
    39
    }
nkeynes@1036
    40
}
nkeynes@1036
    41
nkeynes@1036
    42
const gchar *gui_get_configurable_path( int key )
nkeynes@1036
    43
{
nkeynes@1036
    44
    if( gui_paths[key] == NULL ) {
nkeynes@1036
    45
        gui_paths[key] = lxdream_get_global_config_path_value(key);
nkeynes@1036
    46
        /* If no path defined, go with the current working directory */
nkeynes@1036
    47
        if( gui_paths[key] == NULL ) {
nkeynes@1036
    48
            gui_paths[key] = get_absolute_path(".");
nkeynes@1036
    49
        }
nkeynes@1036
    50
    }
nkeynes@1036
    51
    return gui_paths[key];
nkeynes@1036
    52
}
nkeynes@1036
    53
nkeynes@1036
    54
void gui_set_configurable_path( int key, const gchar *path )
nkeynes@1036
    55
{
nkeynes@1036
    56
    g_free(gui_paths[key]);
nkeynes@1036
    57
    gui_paths[key] = g_strdup(path);
nkeynes@1036
    58
}
nkeynes@1036
    59
nkeynes@1036
    60
void gui_config_paths_changed()
nkeynes@1036
    61
{
nkeynes@1036
    62
    int i;
nkeynes@1036
    63
    for( i=0; i < CONFIG_KEY_MAX; i++ ) {
nkeynes@1036
    64
        g_free(gui_paths[i]);
nkeynes@1036
    65
        gui_paths[i] = NULL;
nkeynes@1036
    66
    }
nkeynes@1036
    67
}
.