~danielholm/gsixaxis/0.4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash

# SixA is a manager for your GNU/Linux-supported gamepad/joystick.
# SixA is distributed under the terms of GPL v2 - for more info about the license, read the LICENSE file.
# This file is the main script of SixA - Gamepad manager: http://www.launchpad/gsixaxis/

# Variables:
# Define what file this script always needs for settings.
FILE="$HOME/.sixa.conf"

# What language the users has set is always set in the variable #LANG, which we'll use.
# This checks if the user has a manual set language. If not use $LANG.
if [ "cat $FILE | grep LANG=" ]; then
	cat $FILE | grep LANG=
	source lang/$LANG.po
	echo $YOURLANG

else
	if [ -f lang/$LANG.po ]; then
		source lang/$LANG.po
		echo $YOURLANG

	# If the users desktop language isn't yet supported, it uses English.
	else
		source lang/en_GB.UTF-8.po
		echo "Your language doesn't seem to be supported in SixA. Using English as default."
	#	LANG=en_GB.UTF-8.po >> $FILE
	fi
fi

# Runs GNOME, KDE or teminal
if [ x"$KDE_FULL_SESSION" = x"true" ]; then 
	DESKTOP="sixa --gui-qt"
	SUDO_TOOL="kdesudo"
	NOTIFY_TOOL="notify-send"
	ENVIROMENT="qt"
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then
	DESKTOP="sixa --gui-gtk"
	SUDO_TOOL="gksu"
	NOTIFY_TOOL="notify-send"
	ENVIROMENT="gtk"
elif [ x"$DISPLAY" != x"" ]; then
	DESKTOP="sixa --gui-gtk"
	SUDO_TOOL="gksu"
	NOTIFY_TOOL="notify-send"
	ENVIROMENT="gtk"
else 
	DESKTOP="sixa --terminal"
	SUDO_TOOL="sudo"
	NOTIFY_TOOL="echo"
fi

# Make sure that there are not varibles if you want to run SixA by the settingsfile.
if [ $1 ]; then
	echo "$SKIP_SET"
else

# Check if settingsfile exists, if not, then show the setup-window.
	if [ -f $FILE ]; then
		echo "$SETFILEEX"
	else
		if [ x"$DISPLAY" != x"" ]; then
			echo "$SETFILENEX"	
			touch $FILE	
			python /usr/share/sixa/gui/$ENVIROMENT/setup.py
		else 			
			touch $FILE
			echo -e "TRAY=false" | sudo tee -a $FILE
			echo -e "PS3=true" | sudo tee -a $FILE

		fi		
	fi
fi

# If there isnt a parameter, skip all of the else-ifs.
if [ $1 ]; then

# Some parameters.
# Shows the helptext.

if [ $1 == -h ]; then
		echo "$HELP"
elif [ $1 == --help ]; then
		echo "$HELP"

# Shows the current version.
elif [ $1 == -v ]; then
		echo "$SIXA_VER"
elif [ $1 == --version ]; then
		echo "$SIXA_VER"

# No tray - only the GUI.
elif [ $1 == --no-tray ]; then 
		cd /usr/share/sixa
		python ./sixa.py

# No GUI - only tray icon.
elif [ $1 == --no-gui ]; then
		python /usr/share/sixa/sixatray.py

# Shows the graphical setup-guide ONLY - removes current settingsfile, but backs it up.
elif [ $1 == --setup ]; then
	if [ x"$DISPLAY" != x"" ]; then
		cp $HOME/.sixa.conf $HOME/.sixa.conf.backup
		rm $HOME/.sixa.conf		
		touch $FILE
		python /usr/share/sixa/gui/gtk/setup.py
	else 			
		cp $HOME/.sixa.conf $HOME/.sixa.conf.backup
		rm $HOME/.sixa.conf
		touch $FILE
		echo -e "TRAY=true" | sudo tee -a $FILE
		echo -e "PS3=false" | sudo tee -a $FILE
	fi		

# Profiles
elif [ $1 == --profile ]; then
	# Changes profile.
	if [ $2 ]; then
		echo $2
		# These aren't enabled untill the code is finished.
		# $SUDO_TOOL rm /etc/hal/fdi/policy/sixa*.fdi
		# $SUDO_TOOL cp /usr/share/sixa/profiles/$2.fdi /etc/hal/fdi/policy/$2.fdi
		$NOTIFY_TOOL "SixA" "$PROFILE_CHANGE '$2'" -i sixa 
	else
		echo $PROFILE_SUPPORT
		cat /usr/share/sixa/profiles/sixa_*.fdi | grep SixA | awk '{ print $5 }'
	fi

# Set som advanced settings.
elif [ $1 == --set ]; then
		echo "$SET_SET"

	# Set support for PS3 gamepad to true or false.
	if [ $2 == ps3 ]; then
		if [ $3 == true ]; then
			echo PS3 plugin enabled.
			sed -i 's/^PS3=false/PS3=true/g' $FILE
		elif [ $3 == false ]; then
			echo PS3 plugin disabled.
			sed -i 's/^PS3=true/PS3=false/g' $FILE
		else
			echo $SET_TRUEFALSE.
		fi

	# Set tray to active or inactive.
	elif [ $2 == tray ]; then
		if [ $3 == true ]; then
			echo Trayicon enabled.
			sed -i 's/^TRAY=false/TRAY=true/g' $FILE
			$SUDO_TOOL cp /usr/share/sixa/plugins/ps3/ps3-gamepad /usr/share/bin/sixa-ps3-plugin
		elif [ $3 == false ]; then
			echo Trayicon disabled.
			sed -i 's/^TRAY=true/TRAY=false/g' $FILE
			$SUDO_TOOL rm /usr/share/bin/sixa-ps3-plugin
		else
			echo $SET_TRUEFALSE.
		fi
			
	else
		echo $SET_ADVANCED

	fi

# The different interfaces:
elif [ $1 == --gui-gtk ]; then
	python /usr/share/sixa/gtk/sixa.py

elif [ $1 == --gui-qt ]; then
	# The QT-interface has a lower priority at the moment.
	if [ -f /usr/share/sixa/qt/sixa.py ]; then
		echo "The QT-interface isn't done yet, runing GTK instead"
		python /usr/share/sixa/gtk/sixa.py
	else
		python /usr/share/sixa/qt/sixa.py
	fi
fi

# If nothing else is run, the user will get here, and now SixA will run from the settingsfile and depends on the desktop-enviroment.
else
	$DESKTOP
	echo "Test"
fi


exit 0