#!/bin/sh

if [ -z "$XDG_DATA_HOME" ]; then
    export XDG_DATA_HOME="$HOME/.local/share"
fi

if [ -z "$XDG_CONFIG_HOME" ]; then
	export XDG_CONFIG_HOME="$HOME/.config"
fi

if [ -z "$XDG_DATA_DIRS" ]; then
	export XDG_DATA_DIRS="$XDG_DATA_HOME:/usr/local/share/:/usr/share/"
fi

# ensure the existance of default pcmanfm-qt config file
PCMANFM_CONF_DIR="$XDG_CONFIG_HOME/pcmanfm-qt/default"
if [ ! -f "$PCMANFM_CONF_DIR/settings.conf" ]; then
	mkdir -p "$PCMANFM_CONF_DIR"
	cp /etc/pcmanfm-qt/lxqt/settings.conf "$PCMANFM_CONF_DIR/"
fi

# ensure the existance of default LXQt config files
LXQT_CONF_DIR="$XDG_CONFIG_HOME/lxqt"
for config in lxqt panel session windowmanagers;
do
  if [ ! -f "$LXQT_CONF_DIR/${config}.conf" ]; then
	mkdir -p "$LXQT_CONF_DIR"
	cp /etc/lxqt/${config}.conf "$LXQT_CONF_DIR/"
  fi
done

# ensure existence of default openbox config file
OPENBOX_CONF_DIR="$XDG_CONFIG_HOME/openbox"
if [ ! -f "$OPENBOX_CONF_DIR/rc.xml" ]; then
	mkdir -p "$OPENBOX_CONF_DIR"
	cp /etc/xdg/openbox/rc.xml "$OPENBOX_CONF_DIR/"
fi

# Ensure the existance of the 'Desktop' folder
if [ -e "$XDG_CONFIG_HOME/user-dirs.dirs" ]; then
	. "$XDG_CONFIG_HOME/user-dirs.dirs"
else
	XDG_DESKTOP_DIR="$HOME/Desktop"
fi
mkdir -p "$XDG_DESKTOP_DIR"

# Clean up after GDM (GDM sets the number of desktops to one)
xprop -root -remove _NET_NUMBER_OF_DESKTOPS -remove _NET_DESKTOP_NAMES -remove _NET_CURRENT_DESKTOP 2> /dev/null

# Enable Qt integration for OpenOffice.org, if available.
export SAL_USE_VCLPLUGIN=kde

# Launch DBus if needed
if which dbus-launch >/dev/null && test -z "$DBUS_SESSION_BUS_ADDRESS"; then
	eval "$(dbus-launch --sh-syntax --exit-with-session)"
fi

# Qt4 platform plugin
export QT_PLATFORM_PLUGIN=lxqt

# Qt5 platform plugin
export QT_QPA_PLATFORMTHEME=lxqt

# use lxqt-applications.menu for main app menu
export XDG_MENU_PREFIX="lxqt-"

export XDG_CURRENT_DESKTOP="LXQt"

# Start the LXQt session
exec lxqt-session
