summaryrefslogtreecommitdiffstats
path: root/blueman_open
diff options
context:
space:
mode:
authordrgr33n <root@drgr33n.example.net>2009-12-15 10:11:50 +0000
committerdrgr33n <root@drgr33n.example.net>2009-12-15 10:11:50 +0000
commitacc62cd1d26916096f4cc42fc65b80e8f75d0ba4 (patch)
tree14db212a9616a322c94025d704a79e6943b17944 /blueman_open
parent2624f9f5c4eb101a73a2edc18aef3947e746fed3 (diff)
downloadblueman-open-acc62cd1d26916096f4cc42fc65b80e8f75d0ba4.tar.xz
Added gtk progress bar, changed references to phone into device, Cleaned up my bad spelling and the device now mounts to /mnt.
Diffstat (limited to 'blueman_open')
-rwxr-xr-x[-rw-r--r--]blueman_open126
1 files changed, 84 insertions, 42 deletions
diff --git a/blueman_open b/blueman_open
index 50f05c3..a1982c4 100644..100755
--- a/blueman_open
+++ b/blueman_open
@@ -1,11 +1,19 @@
#!/bin/sh
+# varables
+
DEBUG=${DEBUG:-""}
+if [ ! -z $DEBUG ];then
+ dbg_msg="Check /var/log/messages for errors."
+else
+ dbg_msg="Enable *DEBUG* for error log."
+fi
-phone_addr=$1
+device_addr=$1
own_name=$(basename $0)
-dir=$(mktemp -d)/$phone_addr
+dir=$(mkdir)/mnt/$device_addr
browser=${browser:-"xdg-open"}
+count=0
# Check for kdialog
@@ -13,31 +21,27 @@ if which kdialog 1>/dev/null 2>/dev/null; then
messagetype="kdialog"
else
messagetype="gtkdialog"
+ export p_file="progress.tmp"
+ export m_file="message.tmp"
+ touch $p_file
+ touch $m_file
+ echo "0" > $p_file
fi
-# Abstract some stuff for gtkdialog
-gtkbox_passive() {
- export messagebox='
- <vbox>
- <frame Blueman Open Device.>
- <text>
- <label>"'$(printf $1)'"</label>
- </text>
- </frame>
- </vbox>
- '
-}
+#gtkdialog abstraction
+
gtkbox_interactive() {
export messagebox='
<vbox>
<frame Blueman Open Device.>
<text>
- <label>"'$(printf $1)'"</label>
+ <label>Mounting Bluetooth Devive ..</label>
</text>
- <hbox>
- <button ok></button>
- </hbox>
- </frame>
+ <progressbar>
+ <input>progress p_file</input>
+ <action type="exit">Done.</action>
+ </progressbar>
+ </frame>
</vbox>
'
}
@@ -48,56 +52,89 @@ gtkmessage() {
done
IFS=$I
}
+
+#gtkdialog progress counter
+
+if [ "$messagetype" = "gtkdialog" ]; then
+ progress(){
+ while :
+ do
+ sleep 0.3
+ percentage=$(cat $p_file)
+ text=$(cat $m_file)
+ echo $percentage
+ echo $text
+ if [ $percentage = 100 ]; then
+ rm *.tmp
+ exit 0
+ fi
+ done
+ }
+
+ message(){
+ echo $MSG_TXT > $m_file
+ }
+fi
+
+
+export -f progress
+
# End gtkdialog abstraction
# mount function
-mount_phone ()
+
+mount_device ()
{
i=0
LIMIT=5
while [ $i -lt $LIMIT ]
do
+ let count=$count+17
+ echo "$count" > $p_file
printf "$i "
- [ ! -z $DEBUG ] && logger -i -t $own_name "Perform $i try to mount phone $phone_addr to $dir using obexfs"
- [ ! -z $DEBUG ] && logger -i -t $own_name "Execute: obexfs -b $phone_addr -B 10 $dir"
- out=$(obexfs -b $phone_addr $dir 2>&1)
+ [ ! -z $DEBUG ] && logger -i -t $own_name "Perform $i try to mount device $device_addr to $dir using obexfs"
+ [ ! -z $DEBUG ] && logger -i -t $own_name "Execute: obexfs -b $device_addr -B 10 $dir"
+ out=$(obexfs -b $device_addr $dir 2>&1)
[ ! -z $DEBUG ] && logger -i -t $own_name "$out"
mounts=$(grep $dir /proc/mounts | wc -l)
[ ! -z $DEBUG ] && logger -i -t $own_name "Found $mounts mounted $dir inside /proc/mounts"
if [ $mounts -ne 0 ] ;then
- progress=99
- MSG_TXT="Successfully mounted $phone_addr to $dir"
+ MSG_TXT="Successfully mounted $device_addr to $dir"
if [ $messagetype == "kdialog" ]; then
kdialog --passivepopup "$MSG_TXT" 2
elif [ $messagetype == "gtkdialog" ]; then
- gtkbox_interactive $"$MSG_TXT"
- gtkmessage
+ message $"$MSG_TXT"
+ echo "99" > $p_file
+ sleep 2
+ echo "100" > $p_file
fi
[ ! -z $DEBUG ] && logger -i -t $own_name "Open $dir with $browser"
out=$($browser $dir 2>&1)
[ ! -z $DEBUG ] && logger -i -t $own_name "$out"
exit 0
else
- logger -i -t $own_name "Failed to mount $phone_addr to $dir from try $i "
+ logger -i -t $own_name "Failed to mount $device_addr to $dir from try $i "
fi
sleep 1
((i += 1))
done
if [ $mounts -eq 0 ] ;then
- MSG_TXT="Failed to mount $phone_addr to $dir.\nCheck /var/log/messages for errors."
+ MSG_TXT="Failed to mount $device_addr to $dir. $dbg_msg"
if [ $messagetype == "kdialog" ]; then
kdialog --passivepopup "$MSG_TXT" 4
elif [ $messagetype == "gtkdialog" ]; then
- gtkbox_interactive $"$MSG_TXT"
- gtkmessage
+ message $"$MSG_TXT"
+ echo "99" > $p_file
+ sleep 4
+ echo "100" > $p_file
fi
- killall gtkdialog
fi
}
# unmount function
-umount_phone ()
+
+umount_device ()
{
mounts=$(grep $dir /proc/mounts | wc -l)
if [ $mounts -ne 0 ] ;then
@@ -109,12 +146,14 @@ umount_phone ()
[ ! -z $DEBUG ] && logger -i -t $own_name "Successfully unmounted $dir."
else
logger -i -t $own_name "$dir is already mounted. Failed to umount $dir.$out. Please perform its umount manually."
- MSG_TXT="Failed to umount $dir - check /var/log/messages for errors"
+ MSG_TXT="Failed to umount $dir - $dbg_msg"
if [ $messagetype == "kdialog" ]; then
kdialog --passivepopup "$MSG_TXT" 4
elif [ $messagetype == "gtkdialog" ]; then
- gtkbox_interactive $"$MSG_TXT"
- gtkmessage
+ message $"$MSG_TXT"
+ echo "99" > $p_file
+ sleep 4
+ count=5
fi
exit
fi
@@ -124,23 +163,26 @@ umount_phone ()
}
# mkdir function
+
create_dir ()
{
- progress=1
- [ ! -z $DEBUG ] && logger -i -t $own_name "Create directory $dir to mount the phone by bluetooth..."
+ [ ! -z $DEBUG ] && logger -i -t $own_name "Create directory $dir to mount the device by bluetooth..."
out=$(mkdir -p $dir 2>&1)
[ ! -z $DEBUG ] && logger -i -t $own_name "$out"
}
-MSG_TXT="Mount phone is in progress... Please wait..."
+#main
+
+MSG_TXT="Mount device is in progress... Please wait..."
if [ $messagetype == "kdialog" ]; then
kdialog --passivepopup "$MSG_TXT" 4
elif [ $messagetype == "gtkdialog" ]; then
- gtkbox_passive $"$MSG_TXT"
+ message $"$MSG_TXT"
+ gtkbox_interactive
gtkmessage&
fi
create_dir
-umount_phone
-mount_phone
+umount_device
+mount_device