Class: Yast::DesktopClass
- Inherits:
-
Module
- Object
- Module
- Yast::DesktopClass
- Defined in:
- library/desktop/src/modules/Desktop.rb
Instance Method Summary collapse
- #CreateList(m) ⇒ Object
- #GroupList ⇒ Object
- #main ⇒ Object
- #MakeAutostartMap(exec, args) ⇒ Object
- #ModuleList(group) ⇒ Object
-
#ParseSingleDesktopFile(file) ⇒ Hash
Parses the a .desktop file it gets as a parameter without trying to use already cached information or agent to access all desktop files.
-
#Read(values_to_parse) ⇒ Object
Read module and group data from desktop files.
-
#ReadLanguage ⇒ Object
Internal function: set up the language variables.
- #ReadLocalizedKey(fname, keypath, key) ⇒ Object
-
#RunViaDesktop(exec, args) ⇒ Object
Runs a program by writing a special desktop file.
- #Translate(key) ⇒ Object
Instance Method Details
#CreateList(m) ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'library/desktop/src/modules/Desktop.rb', line 222 def CreateList(m) m = deep_copy(m) keys = Map.Keys(m) keys = Builtins.sort(keys) do |x, y| Ops.less_than( Ops.get_string(m, [x, "SortKey"], ""), Ops.get_string(m, [y, "SortKey"], "") ) end keys = Builtins.filter(keys) do |key| Ops.get_string(m, [key, "Hidden"], "false") != "true" end Builtins.y2debug("keys=%1", keys) Builtins.maplist(keys) do |name| Item(Id(name), Translate(Ops.get_string(m, [name, "Name"], "???"))) end end |
#GroupList ⇒ Object
243 244 245 |
# File 'library/desktop/src/modules/Desktop.rb', line 243 def GroupList CreateList(@Groups) end |
#main ⇒ Object
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 |
# File 'library/desktop/src/modules/Desktop.rb', line 34 def main Yast.import "UI" textdomain "base" Yast.import "Map" Yast.import "Directory" # YaST configuration modules @Modules = {} # * YaST configuration groups # * # * <PRE> # Groups=$[ # "Hardware":$[ # "Icon":"hardware56.png", # "Name":"_(\"Hardware\")", # "SortKey":"20", # "Textdomain":"base", # "modules":["cdrom", "hwinfo", ...] # ], # ... # ]; # * </PRE> @Groups = {} # Optional agent path to the desktop files @AgentPath = path(".yast2.desktop") # Optional language for reading translated entries @Language = "" @LanguageFull = "" end |
#MakeAutostartMap(exec, args) ⇒ Object
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'library/desktop/src/modules/Desktop.rb', line 281 def MakeAutostartMap(exec, args) args = deep_copy(args) { "Encoding" => "UTF-8", "Name" => exec, "Exec" => exec, "X-SuSE-Autostart" => Ops.add( Ops.add(exec, " "), Builtins.mergestring(args, " ") ), "Hidden" => "true", "Icon" => exec, "Type" => "Application" } end |
#ModuleList(group) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'library/desktop/src/modules/Desktop.rb', line 247 def ModuleList(group) mods = Ops.get_list(@Groups, [group, "modules"], []) l = [] # support sort keys: #36466 mods = Builtins.sort(mods) do |x, y| Ops.less_than( Ops.get_string( @Modules, [x, "X-SuSE-YaST-SortKey"], Ops.get_string(@Modules, [x, "Name"], "") ), Ops.get_string( @Modules, [y, "X-SuSE-YaST-SortKey"], Ops.get_string(@Modules, [y, "Name"], "") ) ) end Builtins.foreach(mods) do |m| if Builtins.haskey(@Modules, m) && Ops.get_string(@Modules, [m, "Hidden"], "false") != "true" l = Builtins.add( l, Item(Id(m), Ops.get_string(@Modules, [m, "Name"], "???")) ) end end # y2debug too costly: y2debug("%1", m); deep_copy(l) end |
#ParseSingleDesktopFile(file) ⇒ Hash
Parses the a .desktop file it gets as a parameter without trying to use already cached information or agent to access all desktop files. This is optimized version to be used for rapid start of modules. Desktop file is placed in a special directory (/usr/share/applications/YaST2). Parameter file is relative to that directory without “.desktop” suffix. Warning: There are no desktop files in inst-sys.
// Opens /usr/share/applications/YaST2/lan.desktop map<string,string> description = Desktop::ParseSingleDesktopFile (“lan”); Wizard::SetDialogTitle (description:_(“None));
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'library/desktop/src/modules/Desktop.rb', line 331 def ParseSingleDesktopFile(file) filename = Builtins.sformat("%1/%2.desktop", Directory.desktopdir, file) # Do not use .yast2.desktop.v.$filename, because ini-agent reads # all the desktop files anyway which is wasteful for setting one icon. # The config is adapted from .yast2.desktop. SCR.RegisterAgent( path(".yast2.desktop1"), term( :ag_ini, term( :IniAgent, filename, "options" => ["read_only"], # rw works but not needed "comments" => ["^[ \t]*[;#].*", ";.*", "\\{[^}]*\\}", "^[ \t]*$"], "sections" => [ { "begin" => [ "^[ \t]*\\[[ \t]*(.*[^ \t])[ \t]*\\][ \t]*", "[%s]" ] } ], "params" => [ { "match" => [ "^[ \t]*([^=]*[^ \t=])[ \t]*=[ \t]*(.*[^ \t]|)[ \t]*$", "%s=%s" ] } ] ) ) ) # non-existent file requested if SCR.Dir(path(".yast2.desktop1.v.\"Desktop Entry\"")).nil? Builtins.y2error("Unknown desktop file: %1", file) SCR.UnregisterAgent(path(".yast2.desktop1")) return nil end # we need localized keys ReadLanguage() result = { "Icon" => Convert.to_string( SCR.Read(path(".yast2.desktop1.v.\"Desktop Entry\".Icon")) ), "Name" => ReadLocalizedKey( Ops.add(file, ".desktop"), path(".yast2.desktop1.v.\"Desktop Entry\""), "Name" ), "GenericName" => ReadLocalizedKey( Ops.add(file, ".desktop"), path(".yast2.desktop1.v.\"Desktop Entry\""), "GenericName" ) } SCR.UnregisterAgent(path(".yast2.desktop1")) deep_copy(result) end |
#Read(values_to_parse) ⇒ Object
Read module and group data from desktop files
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'library/desktop/src/modules/Desktop.rb', line 123 def Read(values_to_parse) values_to_parse = deep_copy(values_to_parse) extract_desktop_filename = lambda do |fullpath| path_components = Builtins.splitstring(fullpath, "/") filename = Ops.get( path_components, Ops.subtract(Builtins.size(path_components), 1), "" ) filename end # read modules filemap = {} filepath = nil ReadLanguage() ps = Builtins.add(@AgentPath, "s") files = SCR.Dir(ps) # read groups groups = SCR.Dir(path(".yast2.groups.s")) Builtins.y2debug("groups=%1", groups) Builtins.foreach(groups) do |group| filemap = {} filepath = Ops.add( Ops.add(path(".yast2.groups.v"), group), "Desktop Entry" ) filename = extract_desktop_filename.call(group) Ops.set(filemap, "Icon", SCR.Read(Ops.add(filepath, "Icon"))) Ops.set( filemap, "SortKey", SCR.Read(Ops.add(filepath, "X-SuSE-YaST-SortKey")) ) Ops.set(filemap, "Hidden", SCR.Read(Ops.add(filepath, "Hidden"))) Ops.set(filemap, "Name", ReadLocalizedKey(filename, filepath, "Name")) Ops.set(filemap, "modules", []) Ops.set( filemap, "X-SuSE-DocTeamID", SCR.Read(Ops.add(filepath, "X-SuSE-DocTeamID")) ) name2 = Convert.to_string( SCR.Read(Ops.add(filepath, "X-SuSE-YaST-Group")) ) Ops.set(@Groups, name2, filemap) end Builtins.y2debug("Groups=%1", @Groups) # read modules Builtins.foreach(files) do |file| filemap = {} filepath = Ops.add( Ops.add(Ops.add(@AgentPath, path(".v")), file), path(".\"Desktop Entry\"") ) values = SCR.Dir(filepath) filename = extract_desktop_filename.call(file) values = deep_copy(values_to_parse) if !values_to_parse.nil? && values_to_parse != [] Builtins.foreach(values) do |value| ret = ReadLocalizedKey(filename, filepath, value) Ops.set(filemap, value, ret) if !ret.nil? && ret != "" end name2 = Builtins.regexpsub(file, "^.*/(.*).desktop", "\\1") if name2 != "" && !name2.nil? Ops.set(@Modules, name2, filemap) group = Ops.get_string(filemap, "X-SuSE-YaST-Group", "") if group != "" Ops.set( @Groups, [ group, "modules", Builtins.size(Ops.get_list(@Groups, [group, "modules"], [])) ], name2 ) end end end Builtins.y2debug("Groups=%1", @Groups) Builtins.y2debug("Modules=%1", @Modules) nil end |
#ReadLanguage ⇒ Object
Internal function: set up the language variables.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'library/desktop/src/modules/Desktop.rb', line 105 def ReadLanguage # read language @LanguageFull = "" @Language = UI.GetLanguage(true) if Builtins.regexpmatch(@Language, "(.*_[^.]*)\\.?.*") # matches: ll_TT ll_TT.UTF-8 @LanguageFull = Builtins.regexpsub(@Language, "(.*_[^.]*)\\.?.*", "\\1") end if Builtins.regexpmatch(@Language, "(.*)_") @Language = Builtins.regexpsub(@Language, "(.*)_", "\\1") end Builtins.y2debug("LanguageFull=%1", @LanguageFull) Builtins.y2debug("Language=%1", @Language) nil end |
#ReadLocalizedKey(fname, keypath, key) ⇒ Object
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 |
# File 'library/desktop/src/modules/Desktop.rb', line 67 def ReadLocalizedKey(fname, keypath, key) if key != "Name" && key != "GenericName" return Convert.to_string(SCR.Read(Builtins.add(keypath, key))) end ret = "" fallback = Convert.to_string(SCR.Read(Builtins.add(keypath, key))) # check if there are any translation in .desktop file # that is - Name[$lang_code] if !@LanguageFull.nil? || @LanguageFull != "" newkey = Builtins.sformat("%1[%2]", key, @LanguageFull) ret = Convert.to_string(SCR.Read(Builtins.add(keypath, newkey))) return ret if !ret.nil? && ret != "" end if !@Language.nil? || @Language != "" newkey = Builtins.sformat("%1[%2]", key, @Language) ret = Convert.to_string(SCR.Read(Builtins.add(keypath, newkey))) return ret if !ret.nil? && ret != "" end # no translations in .desktop, check desktop_translations.mo then msgid = Builtins.sformat("%1(%2): %3", key, fname, fallback) Builtins.y2debug("Looking for key: %1", msgid) ret = Builtins.dpgettext( "desktop_translations", "/usr/share/locale", msgid ) # probably untranslated - return english name return fallback if ret == msgid ret end |
#RunViaDesktop(exec, args) ⇒ Object
Runs a program by writing a special desktop file. Works with KDE and GNOME. Useful for kinternet, see bug 37864#c17
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'library/desktop/src/modules/Desktop.rb', line 301 def RunViaDesktop(exec, args) args = deep_copy(args) content = "[KDE Desktop Entry]\n" Builtins.foreach(MakeAutostartMap(exec, args)) do |key, value| content = Ops.add(content, Builtins.sformat("%1=%2\n", key, value)) end dir = "/var/lib/Desktop" SCR.Write( path(".target.string"), Builtins.sformat("%1/yast2-run-%2.desktop", dir, exec), content ) nil end |
#Translate(key) ⇒ Object
213 214 215 216 217 218 219 220 |
# File 'library/desktop/src/modules/Desktop.rb', line 213 def Translate(key) if Builtins.regexpmatch(key, "_\\(\"(.*)\"\\)") == true ke = Builtins.regexpsub(key, "_\\(\"(.*)\"\\)", "\\1") key = Builtins.eval(ke) Builtins.y2milestone("%1 -> %2", ke, key) end key end |