/*
This source file is part of Scol
For the latest info, see http://www.scolring.org

Copyright (c) 2010 Stephane Bisaro, aka Iri <iri@irizone.net>

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program 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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt

For others informations, please contact us from http://www.scolring.org/
*/


#include "../include/scol_glib_misc.h"


/**
 * \brief Returns the name of the executable Scol. The filename should NOT be freed
 * It should return "scol.exe" (or "unsmwin.exe" on the old Scol version) on MS Windows
 * On GNU/ Linux, it should return "scol" or "usmunix"
 * \return gchar * : this filename
 */
const gchar * scol_glib_name_scolexe ()
{
    return g_get_application_name ();
}

/**
 * \brief Returns the filename of the current Scol. The filename should be freed with g_free
 * \return gchar * : this filename
 */
gchar * scol_glib_filename_scol ()
{
    return g_find_program_in_path (scol_glib_name_scolexe ());
}

/**
 * \brief Returns the directory of the current Scol. The filename should be freed with g_free
 * \return gchar * : this filename
 */
gchar * scol_glib_dirname_scol ()
{
    gchar * f = scol_glib_filename_scol ();
    gchar * p;

    p = g_path_get_dirname (f);
    g_free (f);
    return p;
}

/**
 * \brief Returns the basename of any filename. The result should be freed with g_free
 * \param : const gchar * : any filename
 * \return gchar * : this base name
 */
gchar * scol_glib_basename (const gchar *f)
{
    return g_path_get_basename (f);
}

/**
 * \brief Returns the value of any environment variable or NULL if not found
 * \param  const gchar * : an environment variable, without "$" on Linux and without "%" on Windows
 * \return const gchar * : the value or NULL if not ound
 * This is an alias of g_getenv ()
 * The result should not be freed
 */
const gchar * scol_glib_get_env (const gchar *v)
{
    return g_getenv (v);
}

/**
 * \brief Returns the name ofthe current user
 * \return const gchar * : the name
 * This is an alias of g_get_user_name ()
 */
const gchar * scol_glib_get_username ()
{
   return g_get_user_name ();
}

/**
 * \brief Returns the host name. Don't free !
 * \return const gchar * : the result.
 */
const gchar * scol_glib_get_hostname ()
{
    return g_get_host_name ();
}

/**
 * \brief Returns TRUE if the given path is an absolute path, otherwise FALSE
 * \param const gchar * : any path
 * \return gboolean
 */
gboolean scol_glib_isabsolutepath (const gchar * p)
{
    return g_path_is_absolute (p);
}

/**
 * \brief Returns a string with an easy sizenumber (from bytes to KB, MO, ..)
 * \param int : an integer (by example a Scol value)
 * \return char *
 * The result should be freed with g_free
 */
char * scol_glib_get_sizefordisplay (int v)
{
    return g_format_size_for_display ((goffset) v);
}



