File: URIRegisterKDE.tcl

package info (click to toggle)
coccinella 0.96.20-9
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 13,184 kB
  • sloc: tcl: 124,744; xml: 206; makefile: 66; sh: 62
file content (131 lines) | stat: -rw-r--r-- 3,347 bytes parent folder | download | duplicates (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
# URIRegisterKDE.tcl --
#
#       At least Konqurer on my SUSE box understands this.
#       There is a dependency on ParseURI.
#       
#  Copyright (c) 2007 Mats Bengtsson
#  
#   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 3 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.  If not, see <http://www.gnu.org/licenses/>.
#  
# $Id: URIRegisterKDE.tcl,v 1.5 2007-11-17 07:40:52 matben Exp $

namespace eval URIRegisterKDE { 
    
    if {![string equal $::this(platform) "unix"]} {
	return
    }
    
    # Try to see if we've got KDE.
    set dir ~/.kde/share/services/
    if {![file isdirectory $dir]} {
	return
    }

    component::define URIRegisterKDE "Adds XMPP uri parsing support in KDE"
}

proc URIRegisterKDE::Init {} {

    Register
    
    component::register URIRegisterKDE
}

# ParseURI::RegisterKDE --
# 
#       At least Konqurer on my SUSE box understands this.

proc ::URIRegisterKDE::Register {} {
    global  this

    set prefsPath  [file nativename ~/.coccinella]
    set scriptFile [file join $prefsPath scripts handle_uri.tcl]

    # Not sure how any spaces should be handled; uri parsed?
    set protocolSpec {\
[Protocol]
exec=@T %u
protocol=xmpp
input=none
output=none
helper=true
listing=false
reading=false
writing=false
makedir=false
deleting=false
Icon="" 
}

    set protocolSpec [string map [list @T $scriptFile] $protocolSpec]

    # Write protocol file only if dir exists.
    set dst ~/.kde/share/services/xmpp.protocol
    if {[file isdirectory [file dirname $dst]]} {
	set fd [open $dst w]
	puts $fd $protocolSpec
	close $fd
    }

    # This is a script that either sends off a command to open the uri or
    # launches the app with -uri.

    # --- Begin script ---

    set script {#!/bin/sh
# the next line restarts using wish @B
	exec wish "$0" -visual best "$@"

    wm withdraw .
    set prefsPath [file nativename ~/.coccinella]
    set pidFile   [file join $prefsPath coccinella.pid]
    set execFile  [file join $prefsPath launchCmd]

    set runs 0
    if {[file exists $pidFile]} {
	set fd [open $pidFile r]
	set pid [read $fd]
	close $fd
	# BSD style:
	# set pids [exec ps -xa -o pid]
	# On unix BSD switches must not have dashes.
	set pids [exec ps xa o pid]
	set runs [expr {[lsearch $pids $pid] >= 0 ? 1 : 0}]
    }
    set uri [lindex $argv 0]
    
    if {$runs} {
	send -async coccinella [list ::ParseURI::TextCmd $uri]
    } else {
	set fd [open $execFile r]
	set exe [read $fd]
	close $fd
	eval exec $exe [list -uri $uri] &
    }
    exit
}
    # --- End script ---
        
    # Trick to get the ending \ in place.
    set script [string map {@B \\} $script]

    # Write the launch script  to our prefs dir.
    if {![file exists $scriptFile]} {
	set fd [open $scriptFile w]
	puts $fd $script
	close $fd
	file attributes $scriptFile -permissions "u+x"
    }     
}