#!/bin/sh
#
# 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 Library 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#-------------------------------------------------------
export TEXTDOMAIN=lxdecc
export TEXTDOMAINDIR="/usr/share/locale"
#
# check of running lxdecc
RUN=`ps -e | grep -c lxdecc`
#echo $RUN
if [ $RUN -gt 2 ];then
exit 0
fi
# create icons folder in users home 
if [ ! -d $HOME/.local/share/icons ]; then
mkdir mkdir $HOME/.local/share/icons
fi
##########################################################################
# Check for available applications and load them into the control center #
##########################################################################
{
#PCManFM and LXDE applications
if [ -f /usr/bin/pcmanfm ]; then
WALLP='<hbox tooltip-text="'$"Set Wallpaper"'"><button image-position="top" >
<label>Wallpaper</label><input file>"/usr/share/icons/Adwaita/32x32/legacy/preferences-desktop-wallpaper.png"</input>
<action>/usr/bin/pcmanfm --desktop-pref --set-wallpaper= &</action></button></hbox>'
#
PCMAN='<hbox tooltip-text="'$"Configure PCManFM"'"><button image-position="top">
<label>Show-Pref</label><input file>"/usr/share/icons/Adwaita/32x32/legacy/preferences-desktop-accessibility.png"</input>
<action>pcmanfm --show-pref=1 &</action></button></hbox>'
#
PCMANS='<hbox tooltip-text="'$"File Manager Superuser Mode"'"><button image-position="top">
<label>Superuser</label><input file>"/usr/share/icons/Adwaita/32x32/legacy/system-file-manager.png"</input>
<action>gksu -l /usr/bin/pcmanfm &</action></button></hbox>'
fi
if [ -f /usr/bin/libfm-pref-apps ]; then
LIBFM='<hbox tooltip-text="'$"Set Preferred Applications"'"><button image-position="top"><label>Pref-Apps</label>
<input file>"/usr/share/icons/Adwaita/32x32/legacy/web-browser.png"</input>
<action>libfm-pref-apps &</action></button></hbox>'
fi
if [ -f /usr/bin/lxpanel ]; then
LXPAN='<hbox tooltip-text="'$"Refresh Panel"'"><button image-position="top">
<label>Panel</label><input file>"/usr/share/icons/Adwaita/32x32/legacy/view-refresh.png"</input>
<action>killall lxdecc && lxpanelctl restart</action></button></hbox>'
fi
if [ -f /usr/bin/lxinput ]; then
LXINPUT='<hbox tooltip-text="'$"Configure Mouse and Keyboard"'"><button image-position="top"><label>LXInput</label>
<input file>"/usr/share/icons/Adwaita/32x32/legacy/preferences-desktop-keyboard.png"</input><action>lxinput &</action>
</button></hbox>'
fi
if [ -f /usr/bin/lxrandr ]; then
LXRANDR='<hbox tooltip-text="'$"Configure Monitor"'"><button image-position="top"><label>LXRandr</label>
<input file>"/usr/share/icons/Adwaita/32x32/legacy/preferences-desktop-display.png"</input>
<action>lxrandr &</action></button></hbox>'
fi
if [ -f /usr/bin/lxsession ]; then
LXPREF='<hbox tooltip-text="'$"Default Applications"'"><button image-position="top"><label>LX-Apps</label>
<input file>"/usr/share/icons/Adwaita/32x32/legacy/preferences-desktop.png"</input>
<action>lxsession-default-apps &</action></button></hbox>'
#
LXEDIT='<hbox tooltip-text="'$"Configure Session"'"><button image-position="top"><label>LXSession</label>
<input file>"/usr/share/icons/Adwaita/32x32/legacy/preferences-desktop-personal.png"</input>
<action>lxsession-edit &</action></button></hbox>'
#
LXOUT='<hbox tooltip-text="'$"Logout Session"'"><button image-position="top"><label>Logout</label>
<input file>"/usr/share/icons/Adwaita/32x32/legacy/edit-delete.png"</input>
<action>lxsession-logout &</action></button></hbox>'
fi
if [ -f /usr/bin/lxcursor ]; then
MOUSE='<hbox tooltip-text="'$"Configure Your Cursor Theme"'"><button image-position="top"><label>Cursor</label>
<input file>"/usr/share/icons/cursor_ring_icon.png"</input><action>lxcursor &</action></button></hbox>'
fi

if [ -f /usr/bin/lxmed ]; then
	if [ ! -f $HOME/.local/share/icons/lxmed.png ]; then
	convert /opt/lxmed/lxmed.png -resize 32x32 $HOME/.local/share/icons/lxmed.png
	fi
LXMED='<hbox tooltip-text="'$"Main Menu Editor"'"><button image-position="top"><label>Main Menu</label>
<input file>"'$HOME'/.local/share/icons/lxmed.png"</input><action>lxmed &</action></button></hbox>'
fi
if [ -f /usr/bin/lxrotator ]; then
LXRT='<hbox tooltip-text="'$"LXDesktop Background Diashow"'"><button image-position="top"><label>Diashow</label>
<input file>"//usr/share/icons/hicolor/32x32/apps/lxrotator.png"</input><action>gksu /usr/bin/lxrotator &</action>
</button></hbox>'
fi
if  [ -f /usr/bin/lxautostart.sh ]; then
LXTSRT='<hbox --tooltip-text="'$"Autostart Settings"'"><button image-position="top"><label>Autostart</label>
<input file>"/usr/share/icons/lxautostart_32.png"</input><action>lxautostart.sh &</action></button></hbox>'
fi
if [ -f /usr/bin/lxterminal ]; then
TERMINAL='<hbox tooltip-text="'$"Open Terminal"'"><button image-position="top"><label>Terminal</label>
<input file>"/usr/share/icons/terminals_section.png"</input><action>lxterminal &</action></button></hbox>'
fi
# end PCManFM and LXDE applications
# begin appearance tools
if [ `ps -e | grep -c openbox ` -gt 0 ]; then 
	if [ -f /usr/bin/obconf ]; then
	OBCONF='<hbox tooltip-text="'$"Configure Openbox"'"><button image-position="top"><label>Openbox</label>
<input file>"/usr/share/icons/Adwaita/32x32/legacy/preferences-system-windows.png"</input>
<action>obconf &</action></button></hbox>'
	fi
fi
if [ -f /usr/bin/lxappearance ]; then
LXAPPE='<hbox tooltip-text="'$"Configure GTK and Icon Theme"'"><button image-position="top">
<label>GTK-Style</label><input file>"/usr/share/icons/Adwaita/32x32/legacy/preferences-desktop-theme.png"</input>
<action>lxappearance &</action></button></hbox>'
fi
if [ `ps -e | grep -c xfwm4` -gt 0 ]; then
	if [ -f /usr/bin/xfwm4-settings ]; then
	XFWM_SET='<hbox tooltip-text="'$"Configure xfwm4"'"><button image-position="top"><label>4-Settings</label>
<input file>"/usr/share/icons/nuoveXT2/32x32/apps/xfwm4.png"</input><action>xfwm4-settings &</action></button></hbox>'
	fi
	if [ -f /usr/bin/xfwm4-tweaks-settings ]; then
	XFWMTWEAKS='<hbox tooltip-text="'$"Configure xfwm4-tweaks"'"><button image-position="top"><label>4-Tweaks</label>
<input file>"/usr/share/icons/nuoveXT2/32x32/categories/xfce4-settings.png"</input><action>xfwm4-tweaks-settings &</action>
</button></hbox>'
	fi
	if [ -f /usr/bin/xfwm4-workspace-settings ]; then
	XFWM_WORK='<hbox tooltip-text="'$"Configure xfwm4-workspace"'"><button image-position="top"><label>4-Workspace</label>
<input file>"/usr/share/icons/nuoveXT2/32x32/places/desktop.png"</input><action>xfwm4-workspace-settings &</action>
</button></hbox>'
	fi
	if [ -f /usr/bin/xfce4-power-manager-settings ]; then
	XFWM_POWER='<hbox tooltip-text="'$"Configure xfce4-power-manager"'"><button image-position="top"><label>4-Power</label>
<input file>"/usr/share/icons/Adwaita/32x32/legacy/battery.png"</input><action>xfce4-power-manager-settings &</action>
</button></hbox>'
	fi
fi
if [ -f /usr/bin/qt6ct ]; then
QT6CT='<hbox tooltip-text="'$"Configure QT6 Theme"'"><button image-position="top">
<label>QT6-Style</label><input file>"/usr/share/icons/Adwaita/32x32/legacy/preferences-desktop-theme.png"</input>
<action>qt6ct &</action></button></hbox>'
fi
if [ -f /usr/bin/kvantummanager ]; then
	if [ ! -f $HOME/.local/share/icons/kvantum.png ]; then
	convert /usr/share/icons/hicolor/scalable/apps/kvantum.svg -resize 32x32 $HOME/.local/share/icons/kvantum.png
	fi
KVANT='<hbox tooltip-text="'$"Open Kvantum"'"><button image-position="top">
<label>Kvantum</label><input file>"'$HOME'/.local/share/icons/kvantum.png"</input>
<action>kvantummanager &</action></button></hbox>'
fi
# end appearance tools
# Systems tools
if [ -f /usr/bin/xscreensaver ]; then
XSCREEN='<hbox tooltip-text="'$"Configure XScreensaver"'"><button image-position="top">
<label>XScreens</label><input file>"/usr/share/icons/Adwaita/32x32/legacy/preferences-desktop-screensaver.png"</input>
<action>xscreensaver-demo &</action></button></hbox>'
fi
if [ -f /usr/bin/xglock ]; then
XLOCK='<hbox tooltip-text="'$"Configure XLock"'"><button image-position="top">
<label>XLock</label><input file>"/usr/share/icons/Adwaita/32x32/legacy/preferences-desktop-screensaver.png"</input>
<action>xglock &</action></button></hbox>'
fi
if [ -f /usr/bin/xbindkeys-config ]; then
XBINDKEYS='<hbox tooltip-text="'$"Configure Xbindkeys"'"><button image-position="top"><label>Xbindkeys</label>
<input file>"/usr/share/icons/Adwaita/32x32/legacy/preferences-desktop-keyboard-shortcuts.png"</input><action>
xbindkeys-config &</action></button></hbox>'
fi
if [ -f /usr/bin/pcc ]; then
PCC='<hbox tooltip-text="'$"PCLinuxOS Control Center"'"><button image-position="top"><label>PCC</label>
<input file>"/usr/share/icons/drakconf.png"</input><action>gksu drakconf &</action></button></hbox>'
fi
if [ -f /usr/bin/mynvidia ]; then
NVDIA='<hbox tooltip-text="'$"Install Nvidia driver"'"><button image-position="top"><label>Nvidia</label>
<input file>"/usr/share/icons/applications_section.png"</input><action>mynvidia &</action></button></hbox>'
fi
if [ -f /usr/bin/mygrub-editor ]; then
GRUB2='<hbox tooltip-text="'$"Configure the default Grub2 config file"'"><button image-position="top"><label>Grub2</label>
<input file>"/usr/share/icons/hicolor/32x32/apps/mygrub-editor.png"</input><action>mygrub-editor &</action></button></hbox>'
fi
if [ -f /usr/bin/t_solutions ]; then
TOUCH='<hbox tooltip-text="'$"Configure Touchpad"'"><button image-position="top"><label>Touchpad</label>
<input file>"/usr/share/icons/Adwaita/32x32/legacy/input-touchpad.png"</input><action>t_solutions &</action>
</button></hbox>'
fi
if [ -f /usr/bin/edit_hostname.sh ]; then
HNAME='<hbox tooltip-text="'$"Configure Hostname"'"><button image-position="top"><label>Hostname</label>
<input file>"/usr/share/icons/Adwaita/32x32/legacy/preferences-system-network.png"</input>
<action>edit_hostname.sh &</action></button></hbox>'
fi
if [ -f /usr/bin/gparted ]; then
GPARTED='<hbox tooltip-text="'$"Open GParted"'"><button image-position="top"><label>GParted</label>
<input file>"/usr/share/icons/hicolor/32x32/apps/gparted.png"</input><action>gparted &</action></button></hbox>'
fi
if [ -f /usr/bin/cpupowerset ]; then
POWERSET='<hbox tooltip-text="'$"Open CPUPowerSet"'"><button image-position="top"><label>Powerset</label>
<input file>"/usr/share/icons/Adwaita/32x32/legacy/battery.png"</input><action>cpupowerset &</action></button></hbox>'
fi
if [ -f /usr/bin/gsmartcontrol-root ]; then
GSMART='<hbox tooltip-text="'$"Open GSmartControl"'"><button image-position="top"><label>GSmart</label>
<input file>"/usr/share/icons/hicolor/32x32/apps/gsmartcontrol.png"</input><action>gsmartcontrol-root &</action></button></hbox>'
fi
if [ -f /usr/bin/sicusys ]; then
SICUSYS='<hbox tooltip-text="'$"Basic information about your system"'"><button image-position="top"><label>Sicusys</label>
<input file>"/usr/share/icons/hicolor/32x32/apps/sicusys.png"</input><action>sicusys &</action></button></hbox>'
fi
#if [ -f /usr/bin/ntfs-config-root ]; then
#NTFS='<hbox tooltip-text="'$"Open NTFS-Config Tool"'"><button image-position="top"><label>NTFS</label>
#<input file>"/usr/share/icons/Adwaita/32x32/legacy/drive-optical.png"</input><action>ntfs-config-root &</action></button></hbox>'
#fi
if [ -f /usr/bin/myrtcwake ]; then
	if [ ! -f $HOME/.local/share/icons/myrtcwake.png ]; then
	convert /usr/share/icons/hicolor/128x128/apps/myrtcwake.png -resize 32x32 $HOME/.local/share/icons/myrtcwake.png
	fi
MYRTC='<hbox tooltip-text="'$"Open MyRTCWake"'"><button image-position="top"><label>RTCWake</label>
<input file>"'$HOME'/.local/share/icons/myrtcwake.png"</input><action>myrtcwake &</action></button></hbox>'
fi
# end systems tools
# software manager
if [ -f /usr/bin/synaptic ]; then
	if [ ! -f $HOME/.local/share/icons/synaptic.png ]; then
	convert /usr/share/pixmaps/synaptic.png -resize 32x32 $HOME/.local/share/icons/synaptic.png
	fi
SYNAPTIC='<hbox tooltip-text="'$"Install Software with Synaptic"'"><button image-position="top"><label>Synaptic</label>
<input file>"'$HOME'/.local/share/icons/synaptic.png"</input>
<action>gksu -l /usr/bin/synaptic &</action></button></hbox>'
fi
if [ -f /usr/bin/dnf5_launcher ]; then
	if [ ! -f $HOME/.local/share/icons/dnf-package-manager.png ]; then
	convert /usr/share/pixmaps/dnf-package-manager.png -resize 32x32 $HOME/.local/share/icons/dnf-package-manager.png
	fi
DNF5L='<hbox tooltip-text="'$"Install Software with DNF Paket Manager"'"><button image-position="top"><label>DNF-Man</label>
<input file>"'$HOME'/.local/share/icons/dnf-package-manager.png"</input>
<action>gksu -l /usr/bin/dnf5_launcher &</action></button></hbox>'
fi
if [ -f /usr/bin/myrlyn ]; then
	if [ ! -f $HOME/.local/share/icons/Myrlyn.png ]; then
	convert /usr/share/pixmaps/Myrlyn.png -resize 32x32 $HOME/.local/share/icons/Myrlyn.png
	fi
MYRLYN='<hbox tooltip-text="'$"Install Software with Myrlyn"'"><button image-position="top"><label>Myrlyn</label>
<input file>"'$HOME'/.local/share/icons/Myrlyn.png"</input>
<action>gksu -l /usr/bin/myrlyn &</action></button></hbox>'
fi
if [ -f /usr/bin/easyflatpak ]; then
	if [ ! -f $HOME/.local/share/icons/easyflatpak.png ]; then
	convert /usr/share/icons/hicolor/48x48/apps/easyflatpak.png -resize 32x32 $HOME/.local/share/icons/easyflatpak.png
	fi
FLATPAK='<hbox tooltip-text="'$"Install Software with EasyFlatpak"'"><button image-position="top"><label>Flatpak</label>
<input file>"'$HOME'/.local/share/icons/easyflatpak.png"</input>
<action>/usr/bin/easyflatpak &</action></button></hbox>'
fi
# end software manager
# Display manager
if [ -f /usr/bin/lxdm-config ]; then
LXDM='<hbox tooltip-text="'$"Configure LXDM"'"><button image-position="top"><label>LXDM</label>
<input file>"/usr/share/icons/userdrake.png"</input><action>gksu /usr/bin/lxdm-config &</action></button></hbox>'
fi
if [ -f /usr/bin/gdmsetup  ]; then
GDM='<hbox tooltip-text="'$"Configure GDM"'"><button image-position="top"><label>GDM</label>
<input file>"/usr/share/icons/hicolor/32x32/apps/gdmsetup.png"</input>
<action>gksu /usr/bin/gdmsetup &</action></button></hbox>'
fi
if [ -f /usr/bin/gdmphotosetup ];then
GDMPH='<hbox tooltip-text="'$"Login Face"'"><button image-position="top"><label>Login</label>
<input file>"/usr/share/icons/Adwaita/32x32/legacy/system-users.png"</input><action>gdmphotosetup &</action>
</button></hbox>'
fi
if [ -f /usr/bin/sddm-gtk ]; then
SDDM='<hbox tooltip-text="'$"Configure SDDM"'"><button image-position="top"><label>SDDM</label>
<input file>"/usr/share/icons//hicolor/32x32/apps/sddm-gtk.png"</input><action>sddm-gtk &</action></button></hbox>'
fi
# end Display manager
#######################################################
# end Check for available applications 				  #
#######################################################
}
#######################################################
# changelog											  #
#######################################################
{
export CHANGELOG='
<window window_position="1" width-request="500" height-request="400" allow-shrink="true" title="LXDE Control Center" icon-name="preferences-system">
	<vbox>
		<vbox scrollable="true"  width="600" >
			<text use-markup="false">
				<input file>/usr/share/doc/lxdecc/Changelog</input>
			</text>
		</vbox>			
		<hbox><vbox>	 
			<button>
				<label>OK</label>
					<variable>CHANGELOG</variable>
					<action type="closewindow">CHANGELOG</action>
			</button>
		</vbox></hbox>		
	</vbox>
</window>
'	
}
#####################################################
# info display										#
#####################################################
{
export INFO='
<window window_position="1"  width-request="500" height-request="400"  title="LXDE Control Center" icon-name="preferences-system">
	<vbox>
		<vbox scrollable="true"  width="600" >
			<text use-markup="false">
				<input file>/usr/share/doc/lxdecc/readme</input>
			</text>
		</vbox>	
		<vbox><hbox>  
			<button>
				<label>OK</label>
				<variable>INFO</variable>
				<action type="closewindow">INFO</action>
			</button>
		</hbox></vbox>
	</vbox>		
</window>
'
}
###################################################
# Start main program							  #
###################################################

export lxdecc='
<window title="LXDE Control Center" icon-name="preferences-system" window-position="1" width-request="800"  homogeneous="true" space-expand="true">
	<vbox> 
		<menubar>
			<menu use-underline="true">
				<menuitem stock-id="gtk-quit" accel-key="0x51" accel-mods="4">
					<action>exit:Quit</action>
				</menuitem>
				<label>'$"_File"'</label>
			</menu>
			<menu>
				<menuitem>
					<label>'$"Info"'</label>
					<action type="launch">INFO</action>
				</menuitem>
				<menuitem>
					<label>'$"Changelog"'</label>
					<action type="launch">CHANGELOG</action>
				</menuitem>
					<label>'$"Help"'</label>
			</menu>
		</menubar>	
			<vbox  homogeneous="true" space-expand="true" space-fill="true">
				<frame '$"Appearance Settings"'>
					<vbox homogeneous="true" allow-shrink="true" resizable="true" scrollable="true" space-expand="false" space-fill="false">
						<hbox>
							'$PCMAN'
							'$WALLP'
							'$XSCREEN'
							'$XLOCK'
							'$XBINDKEYS'
							'$OBCONF'
							'$LXAPPE'
							'$QT6CT'
							'$KVANT'
							'$XFWM_SET'
							'$XFWMTWEAKS'
							'$XFWM_WORK'
							'$MOUSE'
							'$LXRT'
							'$LXPAN'
						</hbox>
					</vbox>
				</frame>
			</vbox>
			
			<vbox homogeneous="true" space-expand="true" space-fill="true">
				<frame '$"System"'>
					<vbox homogeneous="true" allow-shrink="true" resizable="true" scrollable="true" space-expand="false" space-fill="false">
						<hbox>
							'$LXDM'	
							'$GDM'
						 	'$SDDM'
							'$NVDIA'							
							'$LXMED'
							'$PCMANS'
							'$SYNAPTIC'
							'$DNF5L'
							'$MYRLYN'
							'$FLATPAK'
							'$PCC'
							'$LXINPUT'
							'$LXRANDR'
							'$LXPREF'
							'$LXEDIT'
							'$LXOUT'
						</hbox>
					</vbox>

					<vbox homogeneous="true" allow-shrink="true" resizable="true" scrollable="true" space-expand="false" space-fill="false">
						<hbox>
							'$SICUSYS'
							'$TERMINAL'
							'$GDMPH'
							'$LIBFM'
							'$GRUB2'
							'$TOUCH'
							'$HNAME'
							'$XFWM_POWER'
							'$GPARTED'
							'$POWERSET'
							'$GSMART'
							'$MYRTC'
							'$NTFS'
						</hbox>
					</vbox>
				</frame>
			</vbox>
	</vbox>
</window>
'

gtkdialog --program=lxdecc
unset lxdecc
