summaryrefslogtreecommitdiffstats
path: root/kexi/tools/delete_column/kexi_delete_column_gui
blob: 73cd1d40a736d34cd21f1dcc11835f1173c2da82 (plain)
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
#!/bin/sh
#
#   Copyright (C) 2006-2007 Jaroslaw Staniek <js@iidea.pl>
#
#   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; see the file COPYING.  If not, write to
#   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
#   Boston, MA 02110-1301, USA.
#

basedir=`dirname "$0"`

setup_messages {
	lang=`grep Language= ~/.trinity/share/config/kdeglobals | head -n 1 | \
		sed -e 's/Language=\(.*\):.*/\1/'`
	if [ -z "$lang" ] ; then lang="en" ; fi
	
	IFS=:
	for dir in `tde-config --expandvars --path locale` ; do
		transl_file="$dir"$lang"/LC_MESSAGES/kexi_delete_column_gui_transl_$lang.sh";
		if [ -f "$transl_file" ] ; then
			source "$transl_file"
			break
		else
			transl_file=;
		fi
	done
	IFS=" "
	if [ -z "$transl_file" ] ; then
		transl_file="$basedir/kexi_delete_column_gui_transl_$lang.sh";
		if [ -f "$transl_file" ] ; then	source "$transl_file"; else transl_file=; fi
	fi
echo 	$transl_file
	if  [ -z "$transl_file" ] ; then
	# default: english messages:
		msg_filters="*.kexi|Kexi Project stored in a file
*.*|All files"
		msg_select_db_file="Select database file"
		msg_enter_table_name="Table name (not caption):"
		msg_enter_column_name="Column name (not caption):"
	fi
} # /setup_messages

setup_messages

ksqlite="ksqlite -noheader"

database_name=`kdialog --title "$msg_select_db_file" --getopenfilename . "$msg_filters"` || exit 1

table_name=`kdialog --inputbox "$msg_enter_table_name"` || exit 1

# show list of columns and ask for one

msg=`$ksqlite "$database_name" "SELECT f_name FROM kexi__objects o, kexi__fields f WHERE o.o_id=f.t_id AND o.o_name='$table_name' AND o_type=1 ORDER BY f_order;" || exit 1`

command_file=`mktemp "$database_name"XXXXXXXX`".sh"
echo -n "kdialog --radiolist \"$msg_enter_column_name\"" > $command_file
echo $msg | while read f ; do
	echo -n " $f $f off" >> $command_file
done

column_name=`. $command_file || exit 1`
rm -f $command_file

# call the command line tool

msg=`sh kexi_delete_column "$database_name" "$table_name" "$column_name" 2>&1`

[ -z "$msg" ] && exit 0

kdialog --error "$msg"
exit 1