#!/bin/bash

# Copyright (C) 2004-2007 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This program 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 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.

# This is the file that is included by everyone. It should cointain all the
# variables that are common to every function.

MDM_VERSION='0.0.3'

MDM_PREFIX=/

MDM_LOGS=$MDM_PREFIX/var/log/mdm/
MDM_RUN=$MDM_PREFIX/var/run/mdm/
MDM_ETC=$MDM_PREFIX/etc/mdm/
MDM_SHARE=$MDM_PREFIX/usr/share/mdm/
MDM_SCRIPTS=$MDM_PREFIX/usr/sbin/

CONFIG_FILE=$MDM_ETC/mdm.conf

MDM_DEVICES=$MDM_ETC/devices/
MDM_MODES=$MDM_SHARE/modes/
MDM_PIDS=$MDM_RUN/

MDM_XORG_CONF=$MDM_ETC/xorg.conf.mdm
DISCOVER_DEVICES=$MDM_SCRIPTS/discover-devices
XRANDR_FUNCTIONS=$MDM_SCRIPTS/xrandr-functions

source $XRANDR_FUNCTIONS

function log() {
    # Whoever calls this must set the $MY_LOG variable!
    ME=`basename $0`

    #echo "MY_LOG = $MY_LOG $1 $2"
    if [ "$1" == '--log-file-only' ]; then
        echo "$ME: $2" >> $MY_LOG
    else
        echo "$ME: $1" >> $MY_LOG
        echo "$ME: $1"
    fi
}

function debug() {
    if [[ "$DEBUG" -eq "1" ]]; then
	echo "$1"
    fi
}

function load_config() {
    # TODO: we should check for the file integrity and for missing variables
    source $CONFIG_FILE
}

function rotate_log () {
    # Whoever calls this must set the $MY_LOG variable
    if [ -f $1 ]; then
        mv $1 $1.old
    fi
}

function select_display_manager () {
    source $MDM_MODES/$MULTISEAT_MODE
}

#####

load_config
select_display_manager
