File: galeon

package info (click to toggle)
hibernate 2.0%2B15%2Bg88d54a8-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch, wheezy
  • size: 740 kB
  • ctags: 114
  • sloc: sh: 1,223; makefile: 17
file content (97 lines) | stat: -rw-r--r-- 2,471 bytes parent folder | download | duplicates (3)
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
# -*- sh -*-
# vim:ft=sh:ts=8:sw=4:noet

# $Id$

gconftool=$(command -v gconftool)
galeon_gconf_offline_key='/apps/galeon/Browsing/General/offline'

AddConfigHandler GaleonOptions
AddConfigHelp "GaleonOffline <boolean>" "Changes all locally running Galeon's status to offline before suspending, and (optionally) change it back to the original state after resuming."
AddConfigHelp "GaleonRestoreStatus <boolean>" "Change status of Galeon back to the original state after resuming."

GaleonOffline()
{
    [ x"$GALEON_OFFLINE" != "x1" ] && return 0

    if [ -z "$gconftool" ] || [ ! -x "$gconftool" ]; then
	vecho 0 'Cannot change Galeon to offline: `gconftool` not found.'
	return 0
    fi

    local pid i=0
    for pid in `pidof galeon`; do
	local user galeon_status

	user=$(get_env_var_of_process $pid USER)

	vecho 2 "Saving status of $user's Galeon"
	galeon_status=$(su "$user" -c "$gconftool --get $galeon_gconf_offline_key")

	# using this eval-crap to be POSIX-compliant (arrays are nonstandard)
	eval "GALEON_OFFLINED_SESSIONS_USER_$i='$user'"
	eval "GALEON_OFFLINED_SESSIONS_STATUS_$i='$galeon_status'"
	i=`expr $i + 1`

	vecho 2 "Changing status of $user's Galeon to offline"
	su "$user" -c "$gconftool --type bool --set $galeon_gconf_offline_key true"
    done

    return 0
}

GaleonRestoreStatus()
{
    [ x"$GALEON_OFFLINE" != "x1" ] && return 0

    [ x"$GALEON_RESTORE_STATUS" != "x1" ] && return 0

    if [ -z "$gconftool" ] || [ ! -x "$gconftool" ]; then
	vecho 0 'Cannot change Galeon status back: `gconftool` not found.'
	return 0
    fi

    local i=0
    while :; do
	local user galeon_status

	user=`eval "echo \\\$GALEON_OFFLINED_SESSIONS_USER_$i"`
	galeon_status=`eval "echo \\\$GALEON_OFFLINED_SESSIONS_STATUS_$i"`
	i=`expr $i + 1`

	[ -z "$user" ] && break

	vecho 2 "Changing status of $user's Galeon back to original status (offline: $galeon_status)"
	su "$user" -c "$gconftool --type bool --set $galeon_gconf_offline_key $galeon_status"
    done

    return 0
}

GaleonOptions()
{
    case "$1" in
	galeonoffline)
	    if BoolIsOn "$1" "$2"; then
		GALEON_OFFLINE=1
		if [ -z "$GALEONOFFLINE_HOOKED" ]; then
		    AddSuspendHook 19 GaleonOffline
		    AddResumeHook 19 GaleonRestoreStatus
		    GALEONOFFLINE_HOOKED=1
		fi
	    else
		GALEON_OFFLINE=0
	    fi
	    ;;
	galeonrestorestatus)
	    if BoolIsOn "$1" "$2"; then
		GALEON_RESTORE_STATUS=1
	    else
		GALEON_RESTORE_STATUS=0
	    fi
	    ;;
	*)
	    return 1
	    ;;
    esac
}