11 " |
11 " |
12 "{ Package: 'stx:libbasic' }" |
12 "{ Package: 'stx:libbasic' }" |
13 |
13 |
14 UnixDesktop subclass:#XDGDesktop |
14 UnixDesktop subclass:#XDGDesktop |
15 instanceVariableNames:'' |
15 instanceVariableNames:'' |
16 classVariableNames:'XDG_USERCONFIG_DIR XDG_DESKTOP_DIR XDG_DOWNLOAD_DIR |
16 classVariableNames:'' |
17 XDG_TEMPLATES_DIR XDG_PUBLICSHARE_DIR XDG_DOCUMENTS_DIR |
|
18 XDG_MUSIC_DIR XDG_PICTURES_DIR XDG_VIDEOS_DIR' |
|
19 poolDictionaries:'' |
17 poolDictionaries:'' |
20 category:'System-Desktop' |
18 category:'System-Desktop' |
21 ! |
19 ! |
22 |
20 |
23 !XDGDesktop class methodsFor:'documentation'! |
21 !XDGDesktop class methodsFor:'documentation'! |
32 inclusion of the above copyright notice. This software may not |
30 inclusion of the above copyright notice. This software may not |
33 be provided or otherwise made available to, or used by, any |
31 be provided or otherwise made available to, or used by, any |
34 other person. No title to or ownership of the software is |
32 other person. No title to or ownership of the software is |
35 hereby transferred. |
33 hereby transferred. |
36 " |
34 " |
37 ! ! |
|
38 |
|
39 !XDGDesktop class methodsFor:'initialization'! |
|
40 |
|
41 initialize |
|
42 |
|
43 self initializeDirectories |
|
44 |
|
45 "Created: / 09-05-2012 / 11:11:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
46 ! |
|
47 |
|
48 initializeDirectories |
|
49 "Read XDG config file, if exist" |
|
50 |
|
51 | cfg | |
|
52 |
|
53 XDG_USERCONFIG_DIR := Filename homeDirectory / '.config'. |
|
54 |
|
55 cfg := XDG_USERCONFIG_DIR / 'user-dirs.dirs'. |
|
56 cfg exists ifFalse:[ ^ self ]. |
|
57 |
|
58 cfg readingFileDo:[:s| |
|
59 [ s atEnd ] whileFalse:[ |
|
60 | l i name value eqpos q1pos q2pos | |
|
61 |
|
62 l := s nextLine. |
|
63 (i := l indexOfNonSeparator) ~~ 0 ifTrue:[ |
|
64 (l at: i) ~~ $# ifTrue:[ |
|
65 ((eqpos := l indexOf: $= startingAt: i) ~~ 0 |
|
66 and:[(q1pos := l indexOf: $" startingAt: eqpos + 1) ~~ 0 |
|
67 and:[(q2pos := l indexOf: $" startingAt: q1pos + 1) ~~ 0]]) ifTrue:[ |
|
68 name := l copyFrom: i to: eqpos - 1. |
|
69 value := l copyFrom: q1pos + 1 to: q2pos - 1. |
|
70 (value startsWith: '$HOME/') ifTrue:[ |
|
71 value := Filename homeDirectory pathName , (value copyFrom:6). |
|
72 ]. |
|
73 self classVarAt: name asSymbol put: value asFilename. |
|
74 ] |
|
75 ] |
|
76 ] |
|
77 ] |
|
78 ] |
|
79 |
|
80 "Created: / 09-05-2012 / 11:11:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
81 ! |
|
82 |
|
83 reinitialize |
|
84 |
|
85 self initialize |
|
86 |
|
87 "Created: / 09-05-2012 / 11:11:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
88 ! ! |
35 ! ! |
89 |
36 |
90 !XDGDesktop class methodsFor:'accessing'! |
37 !XDGDesktop class methodsFor:'accessing'! |
91 |
38 |
92 priority |
39 priority |
105 ! ! |
52 ! ! |
106 |
53 |
107 !XDGDesktop class methodsFor:'testing'! |
54 !XDGDesktop class methodsFor:'testing'! |
108 |
55 |
109 isAvailable |
56 isAvailable |
110 ^ super isAvailable and: [ |
57 ^ super isAvailable |
111 (OperatingSystem getEnvironment: 'XDG_CONFIG_DIRS') notNil |
58 and: [ (OperatingSystem pathOfCommand: |
112 or:[(OperatingSystem getEnvironment: 'XDG_SESSION_PATH') notNil |
59 (self defaultEditorCommand upTo: |
113 ] |
60 Character space)) notNil ] |
114 ] |
|
115 |
|
116 " |
|
117 XDGDesktop isAvailable |
|
118 " |
|
119 |
61 |
120 "Created: / 11-08-2009 / 16:44:34 / Jan Vrany <vranyj1@fel.cvut.cz>" |
62 "Created: / 11-08-2009 / 16:44:34 / Jan Vrany <vranyj1@fel.cvut.cz>" |
121 "Modified: / 09-05-2012 / 11:44:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
122 ! ! |
|
123 |
|
124 !XDGDesktop methodsFor:'accessing-directories'! |
|
125 |
|
126 desktopDirectory |
|
127 ^XDG_DESKTOP_DIR notNil ifTrue:[ |
|
128 XDG_DESKTOP_DIR |
|
129 ] ifFalse:[ |
|
130 Filename homeDirectory |
|
131 ] |
|
132 |
|
133 "Created: / 09-05-2012 / 11:53:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
134 ! |
|
135 |
|
136 documentsDirectory |
|
137 |
|
138 ^XDG_DOCUMENTS_DIR isNil ifTrue:[Filename homeDirectory] |
|
139 |
|
140 "Created: / 09-05-2012 / 11:52:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
141 ! ! |
63 ! ! |
142 |
64 |
143 !XDGDesktop class methodsFor:'documentation'! |
65 !XDGDesktop class methodsFor:'documentation'! |
144 |
66 |
145 version |
67 version_CVS |
146 ^'$Id: XDGDesktop.st 10839 2012-08-21 10:46:45Z vranyj1 $' |
68 ^ '$Header: /cvs/stx/stx/libbasic/XDGDesktop.st,v 1.1 2011-06-28 10:09:48 vrany Exp $' |
147 ! |
69 ! |
148 |
70 |
149 version_SVN |
71 version_SVN |
150 ^ '$Id: XDGDesktop.st 10839 2012-08-21 10:46:45Z vranyj1 $' |
72 ^ ' Id: XDGDesktop.st 10517 2010-04-26 18:26:38Z vranyj1 ' |
151 ! ! |
73 ! ! |
152 |
|
153 XDGDesktop initialize! |
|