From 1b23b615b3b37a3b8526e282e6ffec76dbd5d1e5 Mon Sep 17 00:00:00 2001 From: Frederic Crozat Date: Thu, 4 May 2006 16:19:04 +0000 Subject: - Add applications-mdk.menu file for XDG menu system - Add xdg_menu script from SUSE to support old WM - Don't ship defaultlayout.menu anymore, it is merged into main menu - Fix typo in old menu file --- desktop-common-data.spec | 21 +- menu/applications-mdk.menu | 1117 ++++++++++++++++++++++ menu/menu | 2 +- menu/update-menus | 40 + menu/xdg_menu | 2210 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 3387 insertions(+), 3 deletions(-) create mode 100644 menu/applications-mdk.menu create mode 100755 menu/update-menus create mode 100755 menu/xdg_menu diff --git a/desktop-common-data.spec b/desktop-common-data.spec index 528b673..c08d0ad 100644 --- a/desktop-common-data.spec +++ b/desktop-common-data.spec @@ -1,7 +1,7 @@ Summary: Desktop common files Name: desktop-common-data Version: 2006 -Release: 2mdk +Release: %mkrel 3 License: GPL URL: http://www.mandrivalinux.com/ Group: System/Configuration/Other @@ -97,9 +97,17 @@ install -m 0644 menu/icons/*.png %buildroot/%_iconsdir install -m 0644 menu/icons/large/*.png %buildroot/%_liconsdir install -m 0644 menu/icons/mini/*.png %buildroot/%_miconsdir install -d -m 0755 %buildroot/%_localstatedir/menu-xdg/menus/applications-mdk-merged %buildroot/%_localstatedir/menu-xdg/menus/applications-simplified-merged -install -m 0644 menu/defaultlayout.menu %buildroot/%_localstatedir/menu-xdg/menus/applications-mdk-merged +#install -m 0644 menu/defaultlayout.menu %buildroot/%_localstatedir/menu-xdg/menus/applications-mdk-merged install -m 0644 menu/defaultlayout-simplified.menu %buildroot/%_localstatedir/menu-xdg/menus/applications-simplified-merged +# XDG menus +install -d -m 0755 %buildroot/%_sysconfdir/xdg/menus/applications-merged +install -d -m 0755 %buildroot/%_sysconfdir/menu.d +install -m 0644 menu/applications-mdk.menu %buildroot/%_sysconfdir/xdg/ +install -m 0755 menu/xdg_menu %buildroot/%_bindir +#temporary name +install -m 0755 menu/update-menus %buildroot/%_bindir/update-menus-xdg + #install theme for GDM/KDM install -d -m 0755 %buildroot/%_datadir/mdk/dm @@ -139,6 +147,9 @@ rm -fr %buildroot %_sbindir/* %_sysconfdir/X11/xinit.d/* +%dir %_sysconfdir/menu.d +%_sysconfdir/xdg + # %dir %_datadir/faces/ %dir %_datadir/mdk/ @@ -171,6 +182,12 @@ rm -fr %buildroot %changelog +* Thu May 04 2006 Frederic Crozat 2006-3mdk +- Add applications-mdk.menu file for XDG menu system +- Add xdg_menu script from SUSE to support old WM +- Don't ship defaultlayout.menu anymore, it is merged into main menu +- Fix typo in old menu file + * Mon Sep 26 2005 Frederic Crozat 2006-2mdk - Fix desktop-directory script (UTF encoded URL, hidden .directory file) Mdk bug #18853 diff --git a/menu/applications-mdk.menu b/menu/applications-mdk.menu new file mode 100644 index 0000000..f74e954 --- /dev/null +++ b/menu/applications-mdk.menu @@ -0,0 +1,1117 @@ + + + + Mandriva Linux + + Office + Internet + Multimedia + System + More Applications + Other + + + + + + + + + + /var/lib/menu-xdg/applications + /var/lib/menu-xdg/desktop-directories + + + + mandrakelinux.directory + + X-Mandrakelinux + + + Office + + Wordprocessors + Spreadsheets + Presentations + Drawing + Graphs + Publishing + Tasks Management + Time Management + Address Books + Communications + Accessories + Other + + + + mandrakelinux$2doffice.directory + + + X-Mandrakelinux-Office + + + + Accessories + + + Mandrakelinux-Office-Accessories-kcalc.desktop + Mandrakelinux-Office-Accessories-oooqs.desktop + + + mandrakelinux$2doffice$2daccessories.directory + + + X-Mandrakelinux-Office-Accessories + Calculator + + + + + Address Books + + + Mandrakelinux-Office-AddressBooks-kaddressbook.desktop + + + mandrakelinux$2doffice$2daddressbooks.directory + + + X-Mandrakelinux-Office-AddressBooks + ContactManagement + + + + + Communications + + Fax + Phone + PDA + Other + + + + mandrakelinux$2doffice$2dcommunications.directory + + + X-Mandrakelinux-Office-Communications + + + + Fax + mandrakelinux$2doffice$2dcommunications$2dfax.directory + + X-Mandrakelinux-Office-Communications-Fax + + + + PDA + + + Mandrakelinux-Office-Communications-PDA-kpilot.desktop + + + mandrakelinux$2doffice$2dcommunications$2dpda.directory + + X-Mandrakelinux-Office-Communications-PDA + + + + Phone + mandrakelinux$2doffice$2dcommunications$2dphone.directory + + X-Mandrakelinux-Office-Communications-Phone + + + + Other + mandrakelinux$2doffice$2dcommunications$2dother.directory + + X-Mandrakelinux-Office-Communications-Other + + + + + Drawing + + + Mandrakelinux-Office-Drawing-OpenOffice.org Draw.desktop + + + mandrakelinux$2doffice$2ddrawing.directory + + X-Mandrakelinux-Office-Drawing + + + + Graphs + + + Mandrakelinux-Office-Graphs-Dia.desktop + + + mandrakelinux$2doffice$2dgraphs.directory + + X-Mandrakelinux-Office-Graphs + + + + Presentations + + + Mandrakelinux-Office-Presentations-OpenOffice.org Impress.desktop + + + mandrakelinux$2doffice$2dpresentations.directory + + X-Mandrakelinux-Office-Presentations + + + + Publishing + + + Mandrakelinux-Office-Publishing-Xpdf.desktop + Mandrakelinux-Office-Publishing-GhostView.desktop + + + mandrakelinux$2doffice$2dpublishing.directory + + X-Mandrakelinux-Office-Publishing + + + + Spreadsheets + + + Mandrakelinux-Office-Spreadsheets-OpenOffice.org Calc.desktop + + + mandrakelinux$2doffice$2dspreadsheets.directory + + X-Mandrakelinux-Office-Spreadsheets + + + + Tasks Management + + + Mandrakelinux-Office-TasksManagement-Planner.desktop + + + mandrakelinux$2doffice$2dtasksmanagement.directory + + X-Mandrakelinux-Office-TasksManagement + + + + Time Management + + + Mandrakelinux-Office-TimeManagement-korganizer.desktop + + + mandrakelinux$2doffice$2dtimemanagement.directory + + X-Mandrakelinux-Office-TimeManagement + + + + Other + mandrakelinux$2doffice$2dother.directory + + + X-Mandrakelinux-Office-Other + + + + + Wordprocessors + + + Mandrakelinux-Office-Wordprocessors-OpenOffice.org Writer.desktop + Mandrakelinux-Office-Wordprocessors-OpenOffice.org Math.desktop + + + mandrakelinux$2doffice$2dwordprocessors.directory + + + X-Mandrakelinux-Office-Wordprocessors + Wordprocessor + + + + + + Internet + + Web Browsers + Mail + Instant Messaging + Chat + News + File Transfer + Video Conference + Web Editors + Remote Access + Other + + + + mandrakelinux$2dinternet.directory + + X-Mandrakelinux-Internet + + + Chat + + + Mandrakelinux-Internet-Chat-ksirc.desktop + + + mandrakelinux$2dinternet$2dchat.directory + + + X-Mandrakelinux-Internet-Chat + IRCClient + + + + + File Transfer + + + Mandrakelinux-Internet-FileTransfer-kbear.desktop + Mandrakelinux-Internet-FileTransfer-Gtm.desktop + + + mandrakelinux$2dinternet$2dfiletransfert.directory + + + X-Mandrakelinux-FileTransfer + + + + + + Instant Messaging + + + Mandrakelinux-Internet-InstantMessaging-kopete.desktop + Mandrakelinux-Internet-InstantMessaging-Gaim.desktop + + + mandrakelinux$2dinternet$2dinstantmessaging.directory + + + X-Mandrakelinux-Internet-InstantMessaging + InstantMessaging + + + + + Mail + + + Mandrakelinux-Internet-Mail-Kontact.desktop + Mandrakelinux-Internet-Mail-Evolution.desktop + Mandrakelinux-Internet-Mail-Mozilla Thunderbird.desktop + + + mandrakelinux$2dinternet$2dmail.directory + + X-Mandrakelinux-Internet-Mail + + + + News + + + Mandrakelinux-Internet-News-KNode.desktop + + + mandrakelinux$2dinternet$2dnews.directory + + X-Mandrakelinux-Internet-News + + + + Video Conference + mandrakelinux$2dinternet$2dkppp.directory + + X-Mandrakelinux-Internet-VideoConference + + + + Other + mandrakelinux$2dinternet$2dother.directory + + X-Mandrakelinux-Internet-Other + + + + Remote Access + + + Mandrakelinux-Internet-RemoteAccess-Kppp.desktop + + + mandrakelinux$2dinternet$2dremoteaccess.directory + + X-Mandrakelinux-Internet-RemoteAccess + + + + Web Browsers + + + Mandrakelinux-Internet-WebBrowsers-konqbrowser.desktop + Mandrakelinux-Internet-WebBrowsers-Mozilla.desktop + Mandrakelinux-Internet-WebBrowsers-Mozilla Firefox.desktop + Mandrakelinux-Internet-WebBrowsers-Epiphany Web Browser.desktop + Mandrakelinux-Internet-WebBrowsers-Epiphany Bookmarks Editor.desktop + + + mandrakelinux$2dinternet$2dwebbrowsers.directory + + X-Mandrakelinux-Internet-WebBrowsers + + + + Web Editors + mandrakelinux$2dinternet$2dwebeditors.directory + + X-Mandrakelinux-Internet-WebEditors + + + + + More Applications + + Accessibility + Development + Editors + Emulators + Finances + Databases + Education + Sciences + Communications + Games + Documentation + Other + + + + mandrakelinux$2dmoreapplications.directory + + X-Mandrakelinux-MoreApplications + + + Accessibility + + + Mandrakelinux-MoreApplications-Accessibility-kmag.desktop + + + mandrakelinux$2dmoreapplications$2daccessibility.directory + + X-Mandrakelinux-MoreApplications-Accessibility + + + + Communications + mandrakelinux$2dmoreapplications$2dcommunications.directory + + X-Mandrakelinux-MoreApplications-Communications + + + + Databases + mandrakelinux$2dmoreapplications$2ddatabases.directory + + X-Mandrakelinux-MoreApplications-Databases + + + + Development + + Development Environment + Interpreters + Tools + Code Generators + + + + mandrakelinux$2dmoreapplications$2ddevelopment.directory + + X-Mandrakelinux-MoreApplications-Development + + + Development Environments + + + Mandrakelinux-MoreApplications-Development-DevelopmentEnvironments-kdevelop.desktop + + + mandrakelinux$2dmoreapplications$2ddevelopment$2ddevelopmentenvironments.directory + + X-Mandrakelinux-MoreApplications-Development-DevelopmentEnvironments + + + + Interpreters + + + Mandrakelinux-MoreApplications-Development-Interpreters-GNU Prolog.desktop + + + mandrakelinux$2dmoreapplications$2ddevelopment$2dinterpreters.directory + + X-Mandrakelinux-MoreApplications-Development-Interpreters + + + + Tools + + + Mandrakelinux-MoreApplications-Development-Tools-Gdb.desktop + + + mandrakelinux$2dmoreapplications$2ddevelopment$2dtools.directory + + X-Mandrakelinux-MoreApplications-Development-Tools + + + + Other + mandrakelinux$2dmoreapplications$2ddevelopment$2dother.directory + + X-Mandrakelinux-MoreApplications-Development-Other + + + + + Documentation + mandrakelinux$2dmoreapplications$2ddocumentation.directory + + X-Mandrakelinux-MoreApplications-Documentation + + + + Other + mandrakelinux$2dmoreapplications$2dother.directory + + X-Mandrakelinux-MoreApplications-Other + + + + Editors + + + Mandrakelinux-MoreApplications-Editors-Emacs.desktop + Mandrakelinux-MoreApplications-Editors-XEmacs.desktop + Mandrakelinux-MoreApplications-Editors-VI editor.desktop + + + mandrakelinux$2dmoreapplications$2deditors.directory + + X-Mandrakelinux-MoreApplications-Editors + + + + Education + + Economy + Geography + History + Languages + Literature + Sciences + Sports + Other + + + + mandrakelinux$2dmoreapplications$2deducation.directory + + X-Mandrakelinux-MoreApplications-Education + + + Economy + mandrakelinux$2dmoreapplications$2deducation$2deconomy.directory + + X-Mandrakelinux-MoreApplications-Education-Economy + + + + Geography + mandrakelinux$2dmoreapplications$2deducatino$2dgeography.directory + + X-Mandrakelinux-MoreApplications-Education-Geography + + + + History + mandrakelinux$2dmoreapplications$2deducation$2dhistory.directory + + X-Mandrakelinux-MoreApplications-Education-History + + + + Languages + mandrakelinux$2dmoreapplications$2deducation$2dlanguages.directory + + X-Mandrakelinux-MoreApplications-Education-Languages + + + + Literature + mandrakelinux$2dmoreapplications$2deducation$2dliterature.directory + + X-Mandrakelinux-MoreApplications-Education-Literature + + + + Sciences + mandrakelinux$2dmoreapplications$2deducation$2dsciences.directory + + X-Mandrakelinux-MoreApplications-Education-Sciences + + + + Sports + mandrakelinux$2dmoreapplications$2deducation$2dsports.directory + + X-Mandrakelinux-MoreApplications-Education-Sports + + + + Other + mandrakelinux$2dmoreapplications$2deducation$2dother.directory + + X-Mandrakelinux-MoreApplications-Education-Other + + + + + + Games + + Adventure + Arcade + Boards + Cards + Puzzles + Sports + Strategy + Toys + + + + mandrakelinux$2dmoreapplications$2dgames.directory + + X-Mandrakelinux-MoreApplications-Games + + + Adventure + mandrakelinux$2dmoreapplications$2dgames$2dadventure.directory + + X-Mandrakelinux-MoreApplications-Games-Adventure + + + + Arcade + mandrakelinux$2dmoreapplications$2dgames$2darcade.directory + + X-Mandrakelinux-MoreApplications-Games-Arcade + + + + Boards + mandrakelinux$2dmoreapplications$2dgames$2dboards.directory + + X-Mandrakelinux-MoreApplications-Games-Boards + + + + Cards + mandrakelinux$2dmoreapplications$2dgames$2dcards.directory + + X-Mandrakelinux-MoreApplications-Games-Cards + + + + Puzzles + mandrakelinux$2dmoreapplications$2dgames$2dpuzzles.directory + + X-Mandrakelinux-MoreApplications-Games-Puzzles + + + + Sports + mandrakelinux$2dmoreapplications$2dgames$2dsports.directory + + X-Mandrakelinux-MoreApplications-Games-Sports + + + + Strategy + mandrakelinux$2dmoreapplications$2dgames$2dstrategy.directory + + X-Mandrakelinux-MoreApplications-Games-Strategy + + + + Other + mandrakelinux$2dmoreapplications$2dgames$2dother.directory + + X-Mandrakelinux-MoreApplications-Games-Other + + + + Toys + mandrakelinux$2dmoreapplications$2dgames$2dtoys.directory + + X-Mandrakelinux-MoreApplications-Games-Toys + + + + + Sciences + + Artificial Intelligence + Astronomy + Biology + Chemistry + Computer Science + Data Visualization + Electricity + Geosciences + Image Processing + Mathematics + Numeric analysis + Parallel Computing + Physics + Robotics + Other + + + + mandrakelinux$2dmoreapplications$2dsciences.directory + + X-Mandrakelinux-MoreApplications-Sciences + + + Artificial Intelligence + mandrakelinux$2dmoreapplications$2dsciences$2dartificialintelligence.directory + + X-Mandrakelinux-MoreApplications-Sciences-ArtificialIntelligence + + + + Astronomy + mandrakelinux$2dmoreapplications$2dsciences$2dastronomy.directory + + X-Mandrakelinux-MoreApplications-Sciences-Astronomy + + + + Biology + mandrakelinux$2dmoreapplications$2dsciences$2dbiology.directory + + X-Mandrakelinux-MoreApplications-Sciences-Biology + + + + Chemistry + mandrakelinux$2dmoreapplications$2dsciences$2dchemistry.directory + + X-Mandrakelinux-MoreApplications-Sciences-Chemistry + + + + Computer Science + mandrakelinux$2dmoreapplications$2dsciences$2dcomputerscience.directory + + X-Mandrakelinux-MoreApplications-Sciences-ComputerScience + + + + Data Visualization + mandrakelinux$2dmoreapplications$2dsciences$2ddatavisualization.directory + + X-Mandrakelinux-MoreApplications-Sciences-DataVisualization + + + + Electricity + mandrakelinux$2dmoreapplications$2dsciences$2delectricity.directory + + X-Mandrakelinux-MoreApplications-Sciences-Electricity + + + + Geosciences + mandrakelinux$2dmoreapplications$2dsciences$2dgeosciences.directory + + X-Mandrakelinux-MoreApplications-Sciences-Geosciences + + + + Image Processing + mandrakelinux$2dmoreapplications$2dsciences$2dimageprocessing.directory + + X-Mandrakelinux-MoreApplications-Sciences-ImageProcessing + + + + Mathematics + mandrakelinux$2dmoreapplications$2dsciences$2dmathematics.directory + + X-Mandrakelinux-MoreApplications-Sciences-Mathematics + + + + Numeric Analysis + mandrakelinux$2dmoreapplications$2dsciences$2dnumericanalysis.directory + + X-Mandrakelinux-MoreApplications-Sciences-NumericAnalysis + + + + Parallel Computing + mandrakelinux$2dmoreapplications$2dsciences$2dparallelcomputing.directory + + X-Mandrakelinux-MoreApplications-Sciences-ParallelComptuting + + + + Physics + mandrakelinux$2dmoreapplications$2dsciences$2dphysics.directory + + X-Mandrakelinux-MoreApplications-Sciences-Physics + + + + Robotics + mandrakelinux$2dmoreapplications$2dsciences$2drobotics.directory + + X-Mandrakelinux-MoreApplications-Sciences-Robotics + + + + Other + mandrakelinux$2dmoreapplications$2dsciences$2dother.directory + + X-Mandrakelinux-MoreApplications-Sciences-Other + + + + + + Multimedia + + Sound + Video + Graphics + Other + + + + mandrakelinux$2dmultimedia.directory + + X-Mandrakelinux-Multimedia + + + Graphics + + + Mandrakelinux-Multimedia-Graphics-The GIMP.desktop + Mandrakelinux-Multimedia-Graphics-kooka.desktop + + + mandrakelinux$2dmultimedia$2dgraphics.directory + + X-Mandrakelinux-Multimedia-Graphics + + + + Sound + + + Mandrakelinux-Multimedia-Sound-kscd.desktop + Mandrakelinux-Multimedia-Sound-Totem Media Player.desktop + + + mandrakelinux$2dmultimedia$2dsound.directory + + X-Mandrakelinux-Multimedia-Sound + + + + Video + + + Mandrakelinux-Multimedia-Video-Totem Movie Player.desktop + + + mandrakelinux$2dmultimedia$2dvideo.directory + + X-Mandrakelinux-Multimedia-Video + + + + Other + mandrakelinux$2dmultimedia$2dother.directory + + X-Mandrakelinux-Multimedia-Other + + + + + System + + Terminals + Text Tools + Configuration + Archiving + File Tools + Monitoring + Session + + + + mandrakelinux$2dsystem.directory + + X-Mandrakelinux-System + + + Archiving + + Backup + CD Burning + Compression + Other + + + + mandrakelinux$2dsystem$2darchiving.directory + + X-Mandrakelinux-System-Archiving + + + Backup + + + Mandrakelinux-System-Archiving-Backup-DrakSync.desktop + + + mandrakelinux$2dsystem$2darchiving$2dbackup.directory + + X-Mandrakelinux-System-Archiving-Backup + + + + CD Burning + + + Mandrakelinux-System-Archiving-CDBurning-k3b.desktop + + + mandrakelinux$2dsystem$2darchiving$2dcdburning.directory + + X-Mandrakelinux-System-Archiving-CDBurning + + + + Compression + mandrakelinux$2dsystem$2darchiving$2dcompression.directory + + X-Mandrakelinux-System-Archiving-Compression + + + + Other + mandrakelinux$2dsystem$2darchiving$2dother.directory + + X-Mandrakelinux-System-Archiving-Other + + + + + Configuration + + Mandrakelinux-System-Configuration-KControl.desktop + Mandrakelinux-System-Configuration-Configure Your Computer.desktop + Boot and Init + KDE + GNOME + Hardware + Networking + Packaging + Printing + + + + mandrakelinux$2dsystem$2dconfiguration.directory + + X-Mandrakelinux-System-Configuration + + + Boot and Init + mandrakelinux$2dsystem$2dconfiguration$2dbootandinit.directory + + X-Mandrakelinux-System-Configuration-BootandInit + + + + GNOME + mandrakelinux$2dsystem$2dconfiguration$2dgnome.directory + + X-Mandrakelinux-System-Configuration-GNOME + + + Advanced + mandrakelinux$2dsystem$2dconfiguration$2dgnome$2dadvanced.directory + + X-Mandrakelinux-System-Configuration-GNOME-Advanced + + + + + KDE + mandrakelinux$2dsystem$2dconfiguration$2dkde.directory + + X-Mandrakelinux-System-Configuration-KDE + + + Components + mandrakelinux$2dsystem$2dconfiguration$2dkde$2dcomponents.directory + + X-Mandrakelinux-System-Configuration-KDE-Components + + + + System + mandrakelinux$2dsystem$2dconfiguration$2dkde$2dsystem.directory + + X-Mandrakelinux-System-Configuration-KDE-System + + + + + Networking + mandrakelinux$2dsystem$2dconfiguration$2dnetworking.directory + + X-Mandrakelinux-System-Configuration-Networking + + + + Packaging + mandrakelinux$2dsystem$2dconfiguration$2dpackaging.directory + + X-Mandrakelinux-System-Configuration-Packaging + + + + Printing + mandrakelinux$2dsystem$2dconfiguration$2dprinting.directory + + X-Mandrakelinux-System-Configuration-Printing + + + + Users + mandrakelinux$2dsystem$2dconfiguration$2dusers.directory + + X-Mandrakelinux-System-Configuration-Users + + + + Other + mandrakelinux$2dsystem$2dconfiguration$2dother.directory + + X-Mandrakelinux-System-Configuration-Other + + + + + File Tools + + + Mandrakelinux-System-FileTools-Kfind.desktop + + + mandrakelinux$2dsystem$2dfiletools.directory + + X-Mandrakelinux-System-FileTools + + + + Monitoring + + + Mandrakelinux-System-Monitoring-ksysguard.desktop + + + mandrakelinux$2dsystem$2dmonitoring.directory + + X-Mandrakelinux-System-Monitoring + + + + Session + mandrakelinux$2dsystem$2dsession.directory + + X-Mandrakelinux-System-Session + + + Windowmanagers + mandrakelinux$2dsystem$2dsession$2dwindowmanagers.directory + + X-Mandrakelinux-System-Session-Windowmanagers + + + + + Terminals + + + Mandrakelinux-System-Terminals-konsole.desktop + + + mandrakelinux$2dsystem$2dterminals.directory + + X-Mandrakelinux-System-Terminals + + + + Text Tools + + + Mandrakelinux-System-TextTools-kdict.desktop + + + mandrakelinux$2dsystem$2dtexttools.directory + + X-Mandrakelinux-System-TextTools + + + + + Other + mandrakelinux$2d$2eother.directory + + X-Mandrakelinux-Other + + + + .hidden + mandrakelinux$2d$2ehidden.directory + + X-Mandrakelinux-.hidden + + + diff --git a/menu/menu b/menu/menu index 6ed4fe7..fb69b89 100644 --- a/menu/menu +++ b/menu/menu @@ -69,7 +69,7 @@ ?package(menu): needs=x11 section="More Applications" title="Communications" icon="communications_section.png" ?package(menu): needs=x11 section="More Applications" title="Databases" icon="databases_section.png" # -?package(menu): needs=x11 section="More Applications" title="Development" icon="development_section.png" order="Development Environment,Interpreter,Tools,Code Generators,_mergemenu_,_mergefile_" +?package(menu): needs=x11 section="More Applications" title="Development" icon="development_section.png" order="Development Environment,Interpreters,Tools,Code Generators,_mergemenu_,_mergefile_" ?package(menu): needs=x11 section="More Applications/Development" title="Code Generators" icon="code_generator_section.png" ?package(menu): needs=x11 section="More Applications/Development" title="Development Environments" icon="development_environment_section.png" order="_mergemenu_,kdevelop,_mergefile_" ?package(menu): needs=x11 section="More Applications/Development" title="Interpreters" icon="interpreters_section.png" order="_mergemenu_,GNU Prolog,_mergefile_" diff --git a/menu/update-menus b/menu/update-menus new file mode 100755 index 0000000..c03fde5 --- /dev/null +++ b/menu/update-menus @@ -0,0 +1,40 @@ +#!/bin/sh + +usage() { +echo "Usage: update-menus [options]" +echo " -v Be verbose about what is going on." +echo " -u generate only user menu (useful for root user)" +echo " -h, --help This message." + +exit 0 +} + + +VERBOSE=0 + +if [ "$UID" == "0" ]; then + USER_MENU=0 +else + USER_MENU=1 +fi + +if [ $# != 0 ]; then + +while getopts ":vunh" option +do + case $option in + v ) VERBOSE=1 ; RUN_PARTS_ARG="--verbose" ;; + u ) USER_MENU=1 ;; + h ) usage ;; + esac +done +fi + +export VERBOSE +export USER_MENU + +if [ -d /etc/menu.d ]; then + run-parts $RUN_PARTS_ARG /etc/menu.d + echo +fi + diff --git a/menu/xdg_menu b/menu/xdg_menu new file mode 100755 index 0000000..b39575b --- /dev/null +++ b/menu/xdg_menu @@ -0,0 +1,2210 @@ +#!/usr/bin/perl + +# Copyright (c) 2003 SuSE Linux AG, Nuernberg, Germany. All rights reserved. +# +# Author: nadvornik@suse.cz +# +# + +use strict; +use Locale::gettext; +use Getopt::Long; +use Encode; +use I18N::Langinfo qw(langinfo CODESET); +use POSIX qw(locale_h); + +my $Version = "0.2"; + +my $DefaultAppDirs; +my $DefaultDirectoryDirs; +my @KDELegacyDirs; + +my $format = 'WindowMaker'; +my $desktop_name; +my $language = ''; +my $charset = 'iso-8859-1'; +my $root_cmd = 'xdg_menu_su'; + +my $die_on_error = 0; +my $verbose = 0; +my $fullmenu = 0; + +my @language_keys; + +my @accessed_files; +my @save_ARGV = @ARGV; + + +my %Desktop_entries; +my %Directory_entries; + +sub check_file ($) +{ + my ($file) =@_; + + unless (-e $file) { + push @accessed_files, "X $file"; + return ''; + } + + if (-d $file) { + push @accessed_files, "D $file"; + return 'D'; + } else { + push @accessed_files, "F $file"; + return 'F'; + } +} + +sub scan_AppDir ($$;$) +{ + my ($pool, $dir, $topdir) = @_; + + check_file($dir); + $topdir = $dir unless defined $topdir; + + opendir(DIR, $dir) or return; + + foreach my $entry (readdir(DIR)) { + + if ( -f "$dir/$entry" && $entry =~ /\.desktop$/ ) { + read_desktop_entry($pool, "$dir/$entry", $topdir); + } + elsif ( -d "$dir/$entry" && $entry ne '.' && $entry ne '..' && $entry ne '.hidden') { + scan_AppDir ($pool, "$dir/$entry", $topdir); + } + } + closedir DIR; +} + +sub scan_DirectoryDir ($$;$) +{ + my ($pool, $dir, $topdir) = @_; + + check_file($dir); + $topdir = $dir unless defined $topdir; + + opendir(DIR, $dir) or return; + + foreach my $entry (readdir(DIR)) { + + if ( -f "$dir/$entry" && $entry =~ /\.directory$/ ) { + read_directory_entry($pool, "$dir/$entry", $topdir); + } + elsif ( -d "$dir/$entry" && $entry ne '.' && $entry ne '..' && $entry ne '.hidden') { + scan_DirectoryDir ($pool, "$dir/$entry", $topdir); + } + } + + closedir DIR; +} + +sub read_directory_entry +{ + my ($pool, $file, $topdir) = @_; + + + unless (defined $Directory_entries{$file}) { + + check_file($file); + + open(FILE, "<$file") or return; + + my $in_desktop_entry = 0; + my %entry; + while () { + if (/^\[/) { + if (/^\[Desktop Entry\]/) { + $in_desktop_entry = 1; + } + elsif (/^\[.*\]/) { + $in_desktop_entry = 0; + } + } + elsif ($in_desktop_entry && /^([^=]*)=([^[:cntrl:]]*)/) { + $entry{$1} = $2; + } + } + close(FILE); + + my $id = $file; + $id =~ s/^$topdir//; + $id =~ s/^\/*//; + $id =~ s/\//-/g; + $entry{'id'} = $id; + + $Directory_entries{$file} = \%entry; + } + + my $entry = $Directory_entries{$file}; + + $pool->{'Directory_entries'}{$entry->{'id'}} = $entry; +} + +sub check_show_in ($) +{ + my ($entry) = @_; + + return 1 unless defined $entry; + + my %OnlyShowIn; + my %NotShowIn; + + if (defined $entry->{'OnlyShowIn'}) { + foreach my $showin (split /;/, $entry->{'OnlyShowIn'}) { + $OnlyShowIn{$showin} = 1; + } + return 0 unless defined $OnlyShowIn{$desktop_name}; + } + if (defined $entry->{'NotShowIn'}) { + foreach my $showin (split /;/, $entry->{'NotShowIn'}) { + $NotShowIn{$showin} = 1; + } + return 0 if defined $NotShowIn{$desktop_name} ; + } + + return 1; +} + +sub read_desktop_entry +{ + my ($pool, $file, $topdir) = @_; + + + unless (defined $Desktop_entries{$file}) { + + check_file($file); + + open(FILE, "<$file") or return; + + my $in_desktop_entry = 0; + my %entry; + while () { + if (/^\[/) { + if (/^\[Desktop Entry\]/) { + $in_desktop_entry = 1; + } + elsif (/^\[.*\]/) { + $in_desktop_entry = 0; + } + } + elsif ($in_desktop_entry && /^([^=]*)=([^[:cntrl:]]*)/) { + $entry{$1} = $2; + } + } + close(FILE); + + my $id = $file; + $id =~ s/^$topdir//; + $id =~ s/^\/*//; + $id =~ s/\//-/g; + $entry{'id'} = $id; + + $entry{'refcount'} = 0; + + $Desktop_entries{$file} = \%entry; + } + + my $entry = $Desktop_entries{$file}; + + return unless defined $entry->{'Name'}; + return unless defined $entry->{'Exec'}; + return if $entry->{'Hidden'} eq 'true'; + return if $entry->{'NoDisplay'} eq 'true'; + + return unless check_show_in($entry); + + return if defined $entry->{'NotShowIn'} && $entry->{'NotShowIn'} eq $desktop_name; + + + if (defined $pool) { + + foreach my $category (split /;/, $entry->{'Categories'}) { + $pool->{'Categories'}{$category} = [] unless defined $pool->{'Categories'}{$category}; + push @{$pool->{'Categories'}{$category}}, $entry; + } + + $pool->{'Desktop_entries'}{$entry->{'id'}} = $entry; + } + + return $entry; +} + +my $cached_pool; + +sub read_desktop_entries ($$) +{ + my ($directory_paths, $desktop_paths) = @_; + + if ($cached_pool->{'Directory_paths'} eq $directory_paths && + $cached_pool->{'Desktop_paths'} eq $desktop_paths) { + + return $cached_pool; + } + + + my $pool = {'Desktop_entries' => {}, + 'Categories' => {}, + 'Directory_entries' => {}, + 'Directory_paths' => $directory_paths, + 'Desktop_paths' => $desktop_paths + }; + + foreach my $dir (split /:/, $directory_paths) { + next if $dir =~ /^\s*$/; + scan_DirectoryDir($pool, $dir); + } + + foreach my $dir (split /:/, $desktop_paths) { + next if $dir =~ /^\s*$/; + scan_AppDir($pool, $dir); + } + + $cached_pool = $pool; + + return $pool; +} + +sub dump_entry_list ($) +{ + my ($list) = @_; + + print "list: "; + foreach my $entry (@$list) { + print "$entry->{id} "; + } + print "\n"; + +} + +sub get_directory_entry ($$) +{ + my ($entry, $pool) = @_; + + return $pool->{'Directory_entries'}{$entry}; +} + +sub interpret_Include +{ + my ($tree, $entries, $pool) = @_; + my %exist; + + my $i = 0; + + + my @list = interpret_entry_node($tree, 'Or', $pool); + + foreach my $e (@$entries) { + if ($e->{type} eq 'desktop') { + $exist{$e->{desktop}} = 1; + } + } + + +# dump_entry_list(\@list); + + foreach my $entry (@list) { + + next if $exist{$entry}; + + push @$entries, {type => 'desktop', desktop => $entry}; + $entry->{'refcount'}++; + + $exist{$entry} = 1; + + } +} + +sub interpret_Exclude +{ + my ($tree, $entries, $pool) = @_; + + my $i = 0; + + my @list = interpret_entry_node($tree, 'Or', $pool); + + + foreach my $entry (@list) { + + my $i = 0; + while (defined $entries->[$i]) { + my $exist = $entries->[$i]; + if ($exist->{type} eq 'desktop' && + $exist->{desktop} eq $entry) { + splice @$entries, $i, 1; + $entry->{'refcount'}--; + } + else { + $i++; + } + } + } +} + + +sub interpret_entry_node ($$$) +{ + my ($tree, $node, $pool) = @_; + + my $i = 0; + $i++ if (ref($tree->[$i]) eq 'HASH'); + + my @subtree; + + while (defined $tree->[$i]) { + if ($tree->[$i] eq 'Filename') { + $i++; + if (ref($tree->[$i][0]) eq 'HASH' and $tree->[$i][1] eq '0') { + my $entry = $tree->[$i][2]; + if (defined $pool->{'Desktop_entries'}{$entry}) { + push @subtree, [$pool->{'Desktop_entries'}{$entry}]; + } + else { + push @subtree, []; + } + } + else { + print STDERR "Filename\n"; + exit 1 if $die_on_error; + } + $i++; + } + elsif ($tree->[$i] eq 'Category') { + $i++; + if (ref($tree->[$i][0]) eq 'HASH' and $tree->[$i][1] eq '0') { + my $category = $tree->[$i][2]; + if (defined $pool->{'Categories'}{$category}) { + push @subtree, $pool->{'Categories'}{$category}; + } + else { + push @subtree, []; + } + } + else { + print STDERR "Category\n"; + exit 1 if $die_on_error; + } + $i++; + } + elsif ($tree->[$i] eq 'All') { + $i++; + if (values %{$pool->{'Desktop_entries'}} > 0) { + push @subtree, [values %{$pool->{'Desktop_entries'}}]; + } + else { + push @subtree, []; + } + $i++; + } + elsif ($tree->[$i] eq '0') { + $i++; + $i++; + } + else { + my @res = interpret_entry_node($tree->[$i+1], $tree->[$i], $pool); + push @subtree, \@res; + $i++; $i++; + } + } + + if ($node eq 'Or') + { +# print "or - \n"; + + my %used; + my @res; + foreach my $st (@subtree) { +# print " st: "; +# dump_entry_list($st); + foreach my $entry (@$st) { + if (! defined $used{$entry}) { + push @res, $entry; + $used{$entry} = 1; + } + } + } +# print " res: "; +# dump_entry_list(\@res); + return @res; + } elsif ($node eq 'And') + { + my %used; + my @res; +# print "and - \n"; + my $cnt = @subtree; + my $min = @{$subtree[0]}; + my $min_idx = 0; + my $idx = 0; + + foreach my $st (@subtree) { +# print " st: "; +# dump_entry_list($st); + + my $num = @$st; + if ($num < $min) { + $min = $num; + $min_idx = $idx; + } + + my %dupes; + foreach my $entry (@$st) { + next if $dupes{$entry}; + $dupes{$entry} = 1; + + if (! defined $used{$entry}) { + $used{$entry} = 1; + } + else { + $used{$entry} ++ + } + } + + $idx ++; + } + return () if $cnt == 0; + foreach my $entry (@{$subtree[$min_idx]}) { + push @res, $entry if $used{$entry} == $cnt; + } + +# print " res: "; +# dump_entry_list(\@res); + return @res; + } elsif ($node eq 'Not') + { + my %used; + my @res; +# print "not - \n"; + my $cnt = @subtree; + foreach my $st (@subtree) { +# print " st: "; +# dump_entry_list($st); + foreach my $entry (@$st) { + $used{$entry} = 1; + } + } + return if $cnt == 0; + foreach my $entry (values %{$pool->{'Desktop_entries'}}) { + push @res, $entry if !defined $used{$entry}; + } + +# print " res: "; +# dump_entry_list(\@res); + return @res; + } else { + print STDERR "Can't use '$node' inside or \n"; + exit 1 if $die_on_error; + return (); + } +} + +sub interpret_root ($$) +{ + my ($tree, $topdir) = @_; + if ($tree->[0] eq 'Menu') { + return interpret_menu($tree->[1]); + } + else { + print STDERR "No toplevel Menu\n"; + exit 1 if $die_on_error; + return; + } +} + + +sub interpret_menu ($;$$) +{ + my ($tree, $directory_paths, $desktop_paths) = @_; + + $directory_paths = '' unless defined $directory_paths; + $desktop_paths = '' unless defined $desktop_paths; + + my %menu = ('entries' => [], + 'OnlyUnallocated' => 0, + 'DontShowIfEmpty' => 0, + 'Deleted' => 0); + + my $i = 0; + + $i++ if (ref($tree->[$i]) eq 'HASH'); + + while (defined $tree->[$i]) { + if ($tree->[$i] eq 'AppDir') { + if (ref($tree->[$i + 1][0]) eq 'HASH' and $tree->[$i + 1][1] eq '0') { + $desktop_paths .= ':' . $tree->[$i + 1][2]; + splice @$tree, $i, 2; + } + else { + print STDERR "wrong AppDir\n"; + exit 1 if $die_on_error; + $i++; + $i++; + } + } + elsif ($tree->[$i] eq 'DefaultAppDirs') { + $desktop_paths .= ':' . $DefaultAppDirs; + splice @$tree, $i, 2; + } + elsif ($tree->[$i] eq 'DirectoryDir') { + if (ref($tree->[$i + 1][0]) eq 'HASH' and $tree->[$i + 1][1] eq '0') { + $directory_paths .= ':' . $tree->[$i + 1][2]; + splice @$tree, $i, 2; + } + else { + print STDERR "wrong DirectoryDir\n"; + exit 1 if $die_on_error; + $i++; + $i++; + } + } + elsif ($tree->[$i] eq 'DefaultDirectoryDirs') { + $directory_paths .= ':' . $DefaultDirectoryDirs; + splice @$tree, $i, 2; + } + else { + $i++; + $i++; + } + } + + + $menu{directory_paths} = $directory_paths; + $menu{desktop_paths} = $desktop_paths; + + my $pool = read_desktop_entries($directory_paths, $desktop_paths); + + + $i = 0; + + $i++ if (ref($tree->[$i]) eq 'HASH'); + + while (defined $tree->[$i]) { + if ($tree->[$i] eq 'Menu') { + $i++; + my $submenu = interpret_menu($tree->[$i], $directory_paths, $desktop_paths); + push @{$menu{'entries'}}, {type => 'menu', menu => $submenu}; + $i++; + } + elsif ($tree->[$i] eq 'Name') { + $i++; + if (ref($tree->[$i][0]) eq 'HASH' and $tree->[$i][1] eq '0') { + $menu{'Name'} = $tree->[$i][2]; + } + else { + print STDERR "wrong Name\n"; + exit 1 if $die_on_error; + } + $i++; + } + elsif ($tree->[$i] eq 'Directory') { + $i++; + if (ref($tree->[$i][0]) eq 'HASH' and $tree->[$i][1] eq '0') { + $menu{'Directory'} = get_directory_entry($tree->[$i][2], $pool); +# print "Directory " . $tree->[$i][2] . "\n"; + } + else { + print STDERR "wrong Directory\n"; + exit 1 if $die_on_error; + } + $i++; + } + elsif ($tree->[$i] eq 'OnlyUnallocated') { + $menu{'OnlyUnallocated'} = 1; + $i++; + $i++; + } + elsif ($tree->[$i] eq 'DontShowIfEmpty') { + $menu{'DontShowIfEmpty'} = 1; + $i++; + $i++; + } + elsif ($tree->[$i] eq 'Deleted') { + $menu{'Deleted'} = 1; + $i++; + $i++; + } + elsif ($tree->[$i] eq 'NotDeleted') { + $menu{'Deleted'} = 0; + $i++; + $i++; + } + elsif ($tree->[$i] eq 'Include') { + $i++; + interpret_Include($tree->[$i], $menu{'entries'}, $pool); + $i++; + } + elsif ($tree->[$i] eq 'Exclude') { + $i++; + interpret_Exclude($tree->[$i], $menu{'entries'}, $pool); + $i++; + } + elsif ($tree->[$i] eq '0') { + $i++; + if ($tree->[$i] !~ /^\s*$/) { + print STDERR "skip '$tree->[$i]'\n" ; + exit 1 if $die_on_error; + } + $i++; + } + else { + print STDERR "Unknown '$tree->[$i]':\n"; + $i++; + print STDERR " '@{$tree->[$i]}'\n"; + $i++; + exit 1 if $die_on_error; + } + } + + return \%menu; +} + + +sub read_menu ($;$) +{ + my ($file, $basedir) = @_; + + + if ($file !~ /^\// && defined $basedir) { + $file = "$basedir/$file"; + } + + unless (defined $basedir) { + $basedir = $file; + $basedir =~ s/\/[^\/]*$//; + } + + unless (check_file($file)) { + print STDERR "WARNING: '$file' does not exist\n"; + return ['Menu', [{}]]; + } + + print STDERR "reading '$file'\n" if $verbose; + + my $parser = new XML::Parser(Style => 'Tree'); + my $tree = $parser->parsefile($file); + + my $DefaultMergeDir = $file; + $DefaultMergeDir =~ s/^.*\///; + $DefaultMergeDir =~ s/\.menu$/-merged/; + + read_includes($tree, $basedir, $DefaultMergeDir); + + return $tree +} + +sub read_menu_dir ($;$) +{ + my ($dir, $basedir) = @_; + + my @out; + + if ($dir !~ /^\// && defined $basedir) { + $dir = "$basedir/$dir"; + } + + + check_file($dir); + + opendir(DIR, $dir); + + foreach my $entry (readdir(DIR)) { + + if ( -f "$dir/$entry" && $entry =~ /\.menu$/ ) { + my $menu = read_menu("$dir/$entry"); + $menu = remove_toplevel_Menu($menu); + push @out, @$menu; + } + } + closedir DIR; + + return \@out; +} + +sub quote_xml ($) +{ + my ($txt) = @_; + + $txt =~ s/&/&/g; + $txt =~ s//>/g; + return $txt; +} + +sub read_legacy_dir ($;$) +{ + my ($dir,$basedir) = @_; + my $out; + + $dir =~ s/\/*$//; + + $basedir = $dir unless defined $basedir; + + return "" if check_file($dir) ne 'D'; + + $out = "\n"; + + if ($dir eq $basedir) { + my $xmldir = quote_xml($dir); + + $out .= "$xmldir\n"; + $out .= "$xmldir\n"; + } + else { + my $name = $dir; + $name =~ s/\/*$//; + $name =~ s/^.*\///; + + $name = quote_xml($name); + + $out .= "$name\n"; + } + + + if (-f "$dir/.directory") { + + my $dir_id = "$dir/.directory"; + $dir_id =~ s/^$basedir//; + $dir_id =~ s/^\///; + $dir_id = quote_xml($dir_id); + + $out .= "$dir_id\n"; + } + + opendir(DIR, $dir); + + foreach my $entry (readdir(DIR)) { + + if ( -f "$dir/$entry" && $entry =~ /\.desktop$/ ) { + my $id = "$dir/$entry"; + $id =~ s/^$basedir//; + $id =~ s/^\///; + $id =~ s/\//-/g; + $id = quote_xml($id); + + my $desktop = read_desktop_entry(undef, "$dir/$entry", $basedir); + $out .= "$id\n" unless defined $desktop->{'Categories'} + } + elsif ( -d "$dir/$entry" && $entry ne '.' && $entry ne '..' && $entry ne '.hidden') { + $out .= read_legacy_dir("$dir/$entry", $basedir); + } + } + closedir DIR; + $out .= "\n"; + return $out; +} + +sub remove_toplevel_Menu ($) +{ + my ($tree) = @_; + if ($tree->[0] eq 'Menu') { + shift @{$tree->[1]} if (ref($tree->[1][0]) eq 'HASH'); + return $tree->[1]; + } + else { + print STDERR "No toplevel Menu\n"; + exit 1 if $die_on_error; + return; + } +} + +sub read_includes ($$$) +{ + my ($tree, $basedir, $DefaultMergeDir) = @_; + + my $i = 0; + + $i++ if (ref($tree->[$i]) eq 'HASH'); + + while (defined $tree->[$i]) { + if ($tree->[$i] eq 'MergeFile') { + if (ref($tree->[$i + 1][0]) eq 'HASH' and $tree->[$i + 1][1] eq '0') { + my $add_tree = read_menu($tree->[$i + 1][2], $basedir); + $add_tree = remove_toplevel_Menu($add_tree); + + splice @$tree, $i, 2, @$add_tree; + + } + else { + print STDERR "wrong MergeFile\n"; + exit 1 if $die_on_error; + $i++; + $i++; + } + + } + elsif ($tree->[$i] eq 'MergeDir') { + if (ref($tree->[$i + 1][0]) eq 'HASH' and $tree->[$i + 1][1] eq '0') { + + my $add_tree = read_menu_dir($tree->[$i + 1][2], $basedir); + + splice @$tree, $i, 2, @$add_tree; + + } + else { + print STDERR "wrong MergeFile\n"; + exit 1 if $die_on_error; + $i++; + $i++; + } + + } + elsif ($tree->[$i] eq 'DefaultMergeDirs') { + my $add_tree = read_menu_dir($DefaultMergeDir, $basedir); + splice @$tree, $i, 2, @$add_tree; + } + elsif ($tree->[$i] eq 'LegacyDir') { + if (ref($tree->[$i + 1][0]) eq 'HASH' and $tree->[$i + 1][1] eq '0') { + + my $xml = read_legacy_dir($tree->[$i + 1][2]); + print STDERR "reading legacy directory '" . $tree->[$i + 1][2] . "'\n" if $verbose; + + my $parser = new XML::Parser(Style => 'Tree'); + my $add_tree = $parser->parse($xml); + $add_tree = remove_toplevel_Menu($add_tree); + splice @$tree, $i, 2, @$add_tree; + + } + else { + print STDERR "wrong LegacyDir\n"; + exit 1 if $die_on_error; + $i++; + $i++; + } + + } + elsif ($tree->[$i] eq 'KDELegacyDirs') { + my @out; + foreach my $dir (@KDELegacyDirs) { + my $xml = read_legacy_dir($dir); + print STDERR "reading legacy directory '$dir'\n" if $verbose; + + my $parser = new XML::Parser(Style => 'Tree'); + my $add_tree = $parser->parse($xml); + $add_tree = remove_toplevel_Menu($add_tree); + push @out, @$add_tree + } + splice @$tree, $i, 2, @out; + } + elsif ($tree->[$i] eq 'Menu') { + $i++; + read_includes($tree->[$i], $basedir, $DefaultMergeDir); + $i++; + } + else { + $i++; + $i++; + } + } +} + +sub get_menu_name ($) +{ + my ($tree) = @_; + my $name; + + my $i = 0; + + $i++ if (ref($tree->[$i]) eq 'HASH'); + + while (defined $tree->[$i]) { + if ($tree->[$i] eq 'Name') { + $i++; + if (ref($tree->[$i][0]) eq 'HASH' and $tree->[$i][1] eq '0') { + $name = $tree->[$i][2]; + last; + } + else { + print STDERR "wrong Name\n"; + } + $i++; + } + else { + $i++; + $i++; + } + } + + unless (defined $name) { + print STDERR "Menu has no name element\n"; + } + return $name; +} + + +sub append_menu ($$) +{ + my ($target, $source) = @_; + + my $i = 0; + + $i++ if (ref($source->[$i]) eq 'HASH'); + + while (defined $source->[$i]) { + if ($source->[$i] ne 'Name') { + push @$target, $source->[$i]; + push @$target, $source->[$i + 1]; + } + + $i++; + $i++; + } +} + + +sub merge_menus ($) +{ + my ($tree) = @_; + + my %used; #menu name already used + + my $i = 0; + + $i++ if (ref($tree->[$i]) eq 'HASH'); + + while (defined $tree->[$i]) { + if ($tree->[$i] eq 'Menu') { + my $name = get_menu_name($tree->[$i + 1]); + if (defined $used{$name}) { #second menu with the same name + my $target = $used{$name}; + + append_menu($tree->[$target], $tree->[$i + 1]); + + splice @$tree, $i, 2; + } + else { # first appearance + $used{$name} = $i + 1; + $i++; + $i++; + } + } + else { + $i++; + $i++; + } + } + + + $i = 0; + $i++ if (ref($tree->[$i]) eq 'HASH'); + + while (defined $tree->[$i]) { + if ($tree->[$i] eq 'Menu') { + merge_menus($tree->[$i + 1]); + } + $i++; + $i++; + } +} + +sub read_Move ($$) +{ + my ($tree, $hash) = @_; + + my $i = 0; + + my $old = ''; + + + $i++ if (ref($tree->[$i]) eq 'HASH'); + + while (defined $tree->[$i]) { + if ($tree->[$i] eq 'Old') { + $i++; + if (ref($tree->[$i][0]) eq 'HASH' and $tree->[$i][1] eq '0') { + $old = $tree->[$i][2]; + } + else { + print STDERR "wrong Old\n"; + exit 1 if $die_on_error; + } + $i++; + } + if ($tree->[$i] eq 'New') { + $i++; + if (ref($tree->[$i][0]) eq 'HASH' and $tree->[$i][1] eq '0') { + $hash->{$old} = $tree->[$i][2]; + } + else { + print STDERR "wrong New\n"; + exit 1 if $die_on_error; + } + $i++; + } + else { + $i++; + $i++; + } + } +} + +sub find_menu_in_tree ($$) +{ + my ($path, $tree) = @_; + + my $root = $path; + $root =~ s/\/.*$//; + + my $subpath = $path; + $subpath =~ s/^[^\/]*\/*//; + + my $i = 0; + + $i++ if (ref($tree->[$i]) eq 'HASH'); + + while (defined $tree->[$i]) { + if ($tree->[$i] eq 'Menu') { + if ($root eq get_menu_name($tree->[$i + 1])) { + + if ($subpath eq '') { + return { 'parent' => $tree, 'index' => $i, 'menu' => $tree->[$i + 1]}; + } + return find_menu_in_tree($subpath, $tree->[$i + 1]); + } + } + + $i++; + $i++; + } + + return undef; +} + +sub copy_menu ($$) +{ + my ($path, $tree) = @_; + + my $tail; + my $child; + + foreach my $elem (reverse split(/\//, $path)) { + next if $elem eq ''; + + my $menu = [{}, 'Name', [{}, 0, $elem]]; + push @$menu, ('Menu', $child) if defined $child; + + $tail = $menu unless defined $tail; + $child = $menu; + } + + append_menu($tail, $tree); + + return $child; +} + +sub move_menus ($) +{ + my ($tree) = @_; + +# print "@$tree\n"; + my %move; + + my $i = 0; + + $i++ if (ref($tree->[$i]) eq 'HASH'); + + while (defined $tree->[$i]) { + if ($tree->[$i] eq 'Move') { + + read_Move($tree->[$i + 1], \%move); + splice @$tree, $i, 2; + } + else { + $i++; + $i++; + } + } + + foreach my $source (keys %move) { + my $sourceinfo = find_menu_in_tree($source, $tree); + + if (defined $sourceinfo) { + my $target = copy_menu($move{$source}, $sourceinfo->{'menu'}); + splice @{$sourceinfo->{'parent'}}, $sourceinfo->{'index'}, 2; + push @$tree, ('Menu', $target); + merge_menus($tree); + } + } + + $i = 0; + $i++ if (ref($tree->[$i]) eq 'HASH'); + + while (defined $tree->[$i]) { + if ($tree->[$i] eq 'Menu') { + move_menus($tree->[$i + 1]); + } + $i++; + $i++; + } +} + +sub remove_allocated ($) +{ + my ($menu) = @_; + + + my $i = 0; + while ($i < @{$menu->{'entries'}}) { + my $entry = $menu->{'entries'}[$i]; + + if ($entry->{type} eq 'menu') { + remove_allocated($entry->{menu}); + $i++; + } + elsif ($entry->{type} eq 'desktop' && + $menu->{'OnlyUnallocated'} && + $entry->{desktop}{'refcount'} > 1) { + + $entry->{desktop}{'refcount'}--; + splice @{$menu->{'entries'}}, $i, 1; + } + else { + $i++; + } + + + } + return 0; +} + + +sub remove_empty_menus ($) +{ + my ($menu) = @_; + + + my $i = 0; + while ($i < @{$menu->{'entries'}}) { + my $entry = $menu->{'entries'}[$i]; + + if ($entry->{type} eq 'menu' && remove_empty_menus($entry->{menu})) { + splice @{$menu->{'entries'}}, $i, 1; + } + else { + $i++; + } + + + } + + return 1 if @{$menu->{'entries'}} == 0; # && $menu->{'DontShowIfEmpty'}; #menu is empty + + return 0; +} + + +sub prepare_exec ($$) +{ + my ($exec, $desktop) = @_; + + $exec =~ s/%f//g; + $exec =~ s/%F//g; + $exec =~ s/%u//g; + $exec =~ s/%U//g; + $exec =~ s/%d//g; + $exec =~ s/%D//g; + $exec =~ s/%n//g; + $exec =~ s/%N//g; + $exec =~ s/%i//g; + $exec =~ s/%k//g; + $exec =~ s/%v//g; + $exec =~ s/%m//g; + + my $caption = $desktop->{Name}; + + $exec =~ s/%c/$caption/g; + + $exec =~ s/%%/%/g; + + $exec = "xterm -e $exec" if $desktop->{Terminal} eq '1' || $desktop->{Terminal} eq 'true'; + + $exec = "$root_cmd $exec" if $desktop->{'X-KDE-SubstituteUID'} eq '1' || $desktop->{'X-KDE-SubstituteUID'} eq 'true'; + return $exec; +} + +sub get_loc_entry ($$) +{ + my ($desktop, $entry) = @_; + + foreach my $key (@language_keys) { + my $loc_entry = $entry . "[$key]"; + return $desktop->{$loc_entry} if defined $desktop->{$loc_entry} && $desktop->{$loc_entry} !~ /^\s*$/; + } + + return $desktop->{$entry}; +} + +sub preprocess_menu ($) +{ + # localize, sort, prepare_exec + my ($menu) = @_; + + return 0 if $menu->{'Deleted'}; + return 0 unless check_show_in($menu->{'Directory'}); + return 0 if defined $menu->{'Directory'} && $menu->{'Directory'}->{'NoDisplay'} eq 'true'; + + my $menu_name = $menu->{'Name'}; + my $menu_icon = ""; + + if (defined $menu->{'Directory'}) { + my $directory = $menu->{'Directory'}; + $menu_icon = $menu->{'Directory'}{'Icon'}; + my $directory_name = get_loc_entry($directory, 'Name'); + + if (defined $directory_name) { + Encode::from_to($directory_name, "utf8", $charset) + if !defined $directory->{"Encoding"} || $directory->{"Encoding"} eq 'UTF-8'; + + $menu_name = $directory_name; + } + } + + $menu->{'PrepName'} = $menu_name; + $menu->{'PrepIcon'} = $menu_icon; + + my $i = 0; + while (defined $menu->{'entries'}[$i]) { + my $entry = $menu->{'entries'}[$i]; + if ($entry->{'type'} eq 'desktop') { + my $desktop = $entry->{desktop}; + + my $name = $desktop->{'id'}; + + my $desktop_name = get_loc_entry($desktop, 'Name'); + + if (defined $desktop_name) { + Encode::from_to($desktop_name, "utf8", $charset) + if !defined $desktop->{"Encoding"} || $desktop->{"Encoding"} eq 'UTF-8'; + + $name = $desktop_name; + } + + $desktop->{'PrepName'} = $name; + $entry->{'Name'} = $name; + $entry->{'PrepName'} = $name; + + $desktop->{'PrepExec'} = prepare_exec($desktop->{Exec}, $desktop); + $i++; + } + elsif ($entry->{type} eq 'menu') { + if (preprocess_menu ($entry->{'menu'})) { + $entry->{'Name'} = $entry->{'menu'}{'Name'}; + $entry->{'PrepName'} = $entry->{'menu'}{'PrepName'}; + $i++; + } + else { + splice @{$menu->{'entries'}}, $i, 1; + } + } + else { + print STDERR "wrong menu entry type: $entry->{type}"; + exit 1 if $die_on_error; + splice @{$menu->{'entries'}}, $i, 1; + } + } + + $menu->{'entries'} = [ sort {$b->{'type'} cmp $a->{'type'} || $a->{'PrepName'} cmp $b->{'PrepName'}} @{$menu->{'entries'}} ]; + + my $i = 0; + my $prev_entry; + while (defined $menu->{'entries'}[$i]) { + my $entry = $menu->{'entries'}[$i]; + if (defined $prev_entry && + $entry->{'type'} eq 'desktop' && + $prev_entry->{'type'} eq 'desktop' && + $prev_entry->{'PrepName'} eq $entry->{'PrepName'} && + $prev_entry->{'desktop'}->{'PrepExec'} eq $entry->{'desktop'}->{'PrepExec'}) { + splice @{$menu->{'entries'}}, $i, 1; + } + else { + $prev_entry = $entry; + $i++; + } + } + + return 1; +} + +sub output_twm_menu ($;$$) +{ + my ($menu, $toplevel, $path) = @_; + + my $output = ''; + + $path = '' unless defined $path; + + $toplevel = 1 unless defined $toplevel; + + my $menu_name = $menu->{'PrepName'}; + my $menu_id = "$path-" . $menu->{'Name'}; + $menu_id =~ s/\s/_/g; + + $menu_id = 'xdg_menu' if $toplevel; + + foreach my $entry (@{$menu->{'entries'}}) { + if ($entry->{type} eq 'menu') { + $output .= output_twm_menu($entry->{'menu'}, 0, $menu_id); + } + } + + $output .= "menu \"$menu_id\" {\n"; + $output .= "\"$menu_name\" f.title\n"; + + foreach my $entry (@{$menu->{'entries'}}) { + if ($entry->{type} eq 'desktop') { + my $desktop = $entry->{desktop}; + + my $name = $desktop->{'PrepName'}; + my $exec = $desktop->{'PrepExec'}; + my $color = ''; + + $exec =~ s/"/\\"/g; + + $color = ' ("red":"grey")' if $desktop->{'X-KDE-SubstituteUID'} eq '1' || $desktop->{'X-KDE-SubstituteUID'} eq 'true'; + + $output .= "\"$name\"$color f.exec \"$exec&\"\n"; + } + elsif ($entry->{type} eq 'menu') { + my $name = $entry->{'menu'}{'PrepName'}; + my $id = "$menu_id-" . $entry->{'menu'}{'Name'}; + + $id =~ s/\s/_/g; + + $output .= "\"$name\" f.menu \"$id\"\n"; + } + else { + print STDERR "wrong menu entry type: $entry->{type}"; + } + + } + $output .= "}\n"; + + return $output; +} + +sub output_wmaker_menu ($;$) +{ + my ($menu, $indent) = @_; + + my $output = ''; + + $indent = 0 unless defined $indent; + + my $menu_name = $menu->{'PrepName'}; + + $output .= ' ' x $indent; + $output .= "\"$menu_name\" MENU\n"; + + if ($indent == 0) { + $output .= "\n#include \"user.menu\"\n\n"; + } + + + foreach my $entry (@{$menu->{'entries'}}) { + if ($entry->{type} eq 'desktop') { + my $desktop = $entry->{desktop}; + + my $name = $desktop->{'PrepName'}; + my $exec = $desktop->{'PrepExec'}; + + $output .= ' ' x $indent; + $output .= " \"$name\" EXEC $exec\n"; + } + elsif ($entry->{type} eq 'menu') { + $output .= output_wmaker_menu ($entry->{'menu'}, $indent + 1); + } + else { + print STDERR "wrong menu entry type: $entry->{type}"; + } + + } + + if ($indent == 0) { + textdomain("menu-messages"); + + my $exit_msg = gettext("Exit"); + my $restart_msg = gettext("Restart"); + if (langinfo(CODESET) ne 'UTF-8') { + $exit_msg = Encode::encode_utf8($exit_msg); + $restart_msg = Encode::encode_utf8($restart_msg); + } + $output .= "\t\"$exit_msg\" MENU\n\t\t\"$restart_msg\" RESTART\n\t\t\"$exit_msg\" EXIT\n\"$exit_msg\" END\n"; + } + + $output .= ' ' x $indent; + $output .= "\"$menu_name\" END\n"; + + return $output; +} + +sub output_fvwm2_menu ($;$$) +{ + my ($menu, $toplevel, $path) = @_; + + my $output = ''; + + $path = '' unless defined $path; + + $toplevel = 1 unless defined $toplevel; + + my $menu_name = $menu->{'PrepName'}; + my $menu_id = "$path-" . $menu->{'Name'}; + $menu_id =~ s/\s/_/g; + + $menu_id = 'xdg_menu' if $toplevel; + + foreach my $entry (@{$menu->{'entries'}}) { + if ($entry->{type} eq 'menu') { + $output .= output_fvwm2_menu($entry->{'menu'}, 0, $menu_id); + } + } + + $output .= "DestroyMenu \"$menu_id\"\n"; + $output .= "AddToMenu \"$menu_id\" \"$menu_name\" Title\n"; + + foreach my $entry (@{$menu->{'entries'}}) { + if ($entry->{type} eq 'desktop') { + my $desktop = $entry->{desktop}; + + my $name = $desktop->{'PrepName'}; + my $exec = $desktop->{'PrepExec'}; + + $output .= "+ \"$name\" Exec $exec\n"; + } + elsif ($entry->{type} eq 'menu') { + my $name = $entry->{'menu'}{'PrepName'}; + my $id = "$menu_id-" . $entry->{'menu'}{'Name'}; + $id =~ s/\s/_/g; + + $output .= "+ \"$name\" Popup \"$id\"\n"; + } + else { + print STDERR "wrong menu entry type: $entry->{type}"; + } + + } + $output .= "\n"; + + return $output; +} + +sub output_blackbox_menu ($;$) +{ + my ($menu, $indent) = @_; + + my $output = ''; + + $output .= "[begin] (Menu)\n"; + $output .= "[exec] (xterm) {xterm}\n[separator]\n"; + $output .= output_blackbox_inner_menu ($menu, $indent); + $output .= "[separator]\n"; + $output .= '[config] (Configuration) + [workspaces] (Workspace) + [submenu] (System Styles) {Choose a style...} + [stylesdir] (/usr/share/blackbox/styles) + [stylesdir] (/usr/share/fluxbox/styles) + [stylesdir] (/usr/share/openbox/styles) + [end] + [submenu] (User Styles) {Choose a style...} + [stylesdir] (~/.blackbox/styles) + [stylesdir] (~/.fluxbox/styles) + [stylesdir] (~/.openbox/styles) + [end] + [separator] + [exec] (Run Command) {bbrun -a -w} + [exec] (Lock Screen) {xlock} + [restart] (Restart) {} + [exit] (Logout) +[end] +'; + $output .= "[end]\n"; + return $output; +} + + +sub output_blackbox_inner_menu ($;$) +{ + my ($menu, $indent) = @_; + + my $output = ''; + + $indent = 0 unless defined $indent; + + my $menu_name = $menu->{'PrepName'}; + + $output .= ' ' x $indent; + $output .= "[submenu] ($menu_name)\n"; + + foreach my $entry (@{$menu->{'entries'}}) { + if ($entry->{type} eq 'desktop') { + my $desktop = $entry->{desktop}; + + my $name = $desktop->{'PrepName'}; + my $exec = $desktop->{'PrepExec'}; + + $output .= ' ' x $indent; + $output .= " [exec] ($name) {$exec}\n"; + } + elsif ($entry->{type} eq 'menu') { + $output .= output_blackbox_inner_menu ($entry->{'menu'}, $indent + 1); + } + else { + print STDERR "wrong menu entry type: $entry->{type}"; + } + + } + $output .= ' ' x $indent; + $output .= "[end] # ($menu_name)\n"; + + return $output; +} + +sub output_icewm_menu ($;$) +{ + my ($menu, $indent) = @_; + + my $output = ''; + + $indent = 0 unless defined $indent; + + my $menu_name = $menu->{'PrepName'}; + my $menu_icon = $menu->{'PrepIcon'} || "folder" ; + + $output .= ' ' x $indent; + $output .= "menu \"$menu_name\" $menu_icon {\n"; + + foreach my $entry (@{$menu->{'entries'}}) { + if ($entry->{type} eq 'desktop') { + my $desktop = $entry->{desktop}; + + my $name = $desktop->{'PrepName'}; + my $exec = $desktop->{'PrepExec'}; + my $icon = $desktop->{'Icon'}; + + $output .= ' ' x $indent; + $output .= " prog \"$name\" $icon $exec\n"; + } + elsif ($entry->{type} eq 'menu') { + $output .= output_icewm_menu ($entry->{'menu'}, $indent + 1); + } + else { + print STDERR "wrong menu entry type: $entry->{type}"; + } + + } + $output .= ' ' x $indent; + $output .= "}\n"; + + return $output; +} + +sub prepare_exec_xfce4 ($$) +{ + my ($exec, $desktop) = @_; + + $exec =~ s/%f//g; + $exec =~ s/%F//g; + $exec =~ s/%u//g; + $exec =~ s/%U//g; + $exec =~ s/%d//g; + $exec =~ s/%D//g; + $exec =~ s/%n//g; + $exec =~ s/%N//g; + $exec =~ s/%i//g; + $exec =~ s/%k//g; + $exec =~ s/%v//g; + $exec =~ s/%m//g; + + my $caption = $desktop->{Name}; + + $exec =~ s/%c/$caption/g; + + $exec =~ s/%%/%/g; + + $exec =~ s/\"/"/g; + + $exec = "$root_cmd $exec" if $desktop->{'X-KDE-SubstituteUID'} eq '1' || $desktop->{'X-KDE-SubstituteUID'} eq 'true'; + return $exec; +} + + + +sub output_xfce4_menu ($;$) +{ + my ($menu, $indent) = @_; + + my $output = ''; + + $indent = 0 unless defined $indent; + + if ($indent == 0) { + $output .= '' . "\n"; + $output .= '' . "\n"; + $output .= ']>' . "\n\n"; + } + + my $menu_name = $menu->{'PrepName'}; + my $menu_ico = $menu->{'PrepIcon'}; + $output .= ' ' x $indent; + + if ($indent == 0) { + $output .= "\n" + } + else { + $output .= "\n"; + } + + foreach my $entry (@{$menu->{'entries'}}) { + if ($entry->{type} eq 'desktop') { + my $desktop = $entry->{desktop}; + + my $name = $desktop->{'PrepName'}; + my $exec = prepare_exec_xfce4($desktop->{Exec}, $desktop); + my $term = ($desktop->{Terminal} eq '1' || $desktop->{Terminal} eq 'true') ? "yes" : "no"; + my $ico = $desktop->{'Icon'}; + $output .= ' ' x $indent; + $output .= " \n"; + } + elsif ($entry->{type} eq 'menu') { + $output .= output_xfce4_menu ($entry->{'menu'}, $indent + 1); + } + else { + print STDERR "wrong menu entry type: $entry->{type}"; + } + + } + $output .= ' ' x $indent; + + if ($indent == 0) { + $output .= "\n"; + } + else { + $output .= "\n"; + } + + return $output; +} + +sub output_openbox3_menu ($;$) +{ + my ($menu, $indent) = @_; + + my $output = ''; + + $output .= ' + +'; + $output .= "\n"; + $output .= output_openbox3_inner_menu ($menu, $indent); + $output .= "\n"; + $output .= ' + + xterm + + + + + + + obconf + + + + xlock -remote -nice 19 -mode blank -geometry 1x1 -enablesaver + + + '; + $output .= "\n"; + return $output; +} + +sub output_openbox3_pipe_menu ($;$) +{ + my ($menu, $indent) = @_; + + my $output = ''; + + $output .= "\n"; + $output .= output_openbox3_inner_menu ($menu, $indent); + $output .= "\n"; + return $output; +} + +sub output_openbox3_inner_menu ($;$) +{ + my ($menu, $indent) = @_; + + my $output = ''; + + $indent = 0 unless defined $indent; + my $menu_name = $menu->{'PrepName'}; + + $output .= ' ' x $indent; + $output .= "\n"; +# $output .= "\n"; + + foreach my $entry (@{$menu->{'entries'}}) { + if ($entry->{type} eq 'desktop') { + my $desktop = $entry->{desktop}; + + my $name = $desktop->{'PrepName'}; + my $exec = $desktop->{'PrepExec'}; + + $output .= ' ' x $indent; + $output .= " \n"; + $output .= " $exec\n"; + $output .= " \n"; + } + elsif ($entry->{type} eq 'menu') { + $output .= output_openbox3_inner_menu ($entry->{'menu'}, $indent + 1); + } + else { + print STDERR "wrong menu entry type: $entry->{type}"; + } + + } + $output .= ' ' x $indent; + $output .= " \n"; + + return $output; +} + + +sub output_readable ($;$) +{ + my ($menu, $indent) = @_; + + my $output = ''; + + $indent = 0 unless defined $indent; + + my $menu_name = $menu->{'Name'}; + + $output .= "\t" x $indent; + $output .= "\"$menu_name\" MENU\n"; + + + foreach my $entry (@{$menu->{'entries'}}) { + if ($entry->{type} eq 'desktop') { + my $desktop = $entry->{desktop}; + + my $name = $desktop->{Name}; + + $output .= "\t" x $indent; + $output .= "\t\"$name\"\n"; + + + my @v = %$desktop; + $output .= "@v\n" if $name eq ''; + } + elsif ($entry->{type} eq 'menu') { + $output .= output_readable ($entry->{menu}, $indent + 1); + } + else { + print STDERR "wrong menu entry type: $entry->{type}"; + } + + } + + return $output; +} + +sub get_root_menu +{ + foreach my $dir (split(/:/, $ENV{XDG_CONFIG_DIRS}), "/etc/xdg") { + check_file("$dir/menus/applications.menu"); + return "$dir/menus/applications.menu" if -f "$dir/menus/applications.menu"; + } + return ""; +} + +sub get_app_dirs +{ + my %used; + my $ret = ''; + my @kde_xdgdata = split(/:/, `kde-config --path xdgdata-apps`); + + foreach $_ (@kde_xdgdata) { + s/\/applications\/*\s*$//; + }; + + foreach my $d (split(/:/, $ENV{XDG_DATA_DIRS}), @kde_xdgdata, "/usr/share", "/opt/gnome/share") { + my $dir = $d; + $dir =~ s/\/*$//; + next if defined $used{$dir}; + next if check_file("$dir/applications") ne 'D'; + $ret .= ':' if $ret ne ''; + $ret .= "$dir/applications"; + $used{$dir} = 1; + } + return $ret; +} + +sub get_desktop_dirs +{ + my %used; + my $ret = ''; + foreach my $dir (split(/:/, $ENV{XDG_DATA_DIRS}), "/usr/share", "/opt/kde3/share", "/opt/gnome/share") { + next if defined $used{$dir}; + next if check_file("$dir/desktop-directories") ne 'D'; + $ret .= ':' if $ret ne ''; + $ret .= "$dir/desktop-directories"; + $used{$dir} = 1; + } + return $ret; +} + +sub get_KDE_legacy_dirs +{ + my %used; + my @ret; + foreach my $d ("/etc/opt/kde3/share/applnk", "/opt/kde3/share/applnk", reverse(split(/:/, `kde-config --path apps`))) { + my $dir = $d; + chomp $dir; + $dir =~ s/\/*$//; + next if defined $used{$dir}; + next if check_file("$dir") ne 'D'; + $used{$dir} = 1; + push @ret, $dir; + } + return @ret; +} + +sub prepare_language_keys ($) +{ + my ($language) = @_; + + my @keys; + + $language =~ s/\.[^@]*//; # remove .ENCODING + + if ($language =~ /^([^_]*)_([^@]*)@(.*)$/) { # LANG_COUNTRY@MODIFIER + push @keys, $1 . '_' . $2 . '@' . $3; + push @keys, $1 . '_' . $2; + push @keys, $1 . '@' . $3; + push @keys, $1; + } + elsif ($language =~ /^([^_]*)_([^@]*)$/) { # LANG_COUNTRY + push @keys, $1 . '_' . $2; + push @keys, $1; + } + elsif ($language =~ /^([^_]*)@(.*)$/) { # LANG@MODIFIER + push @keys, $1 . '@' . $2; + push @keys, $1; + } + elsif ($language =~ /^([^_@]*)$/) { # LANG + push @keys, $1; + } + + return @keys; +} + +sub check_cache +{ + my $cachedir = $ENV{HOME}; + + return unless -d $cachedir; + + $cachedir .= "/.xdg_menu_cache"; + + return unless -f "$cachedir/inputs" && -f "$cachedir/output"; + + my @st = stat "$cachedir/output"; + my $ref_time = $st[10]; #ctime + + open(FILE, "<$cachedir/inputs"); + + my $num_opts = 0; + + while () { + chomp; + next if /^\s*$/; + next if /^#/; + + if (/^[FD] (.*)$/) { + my $file = $1; + my @st = stat $file; + my $time = $st[10]; #ctime + + if (!defined $time || $time >= $ref_time) { +# print STDERR "$file: is newer\n"; + return; + } + } + elsif (/^X (.*)$/) { + my $file = $1; + + if (-e $file) { +# print STDERR "$file: exists\n"; + return; + } + } + elsif (/^ENV ([^ ]+) (.*)$/) { + my $var = $1; + my $val = $2; + + if ($ENV{$var} ne $val) { +# print STDERR "$var: differs\n"; + return; + } + } + elsif (/^OPT ([0-9]+) (.*)$/) { + my $optidx = $1; + my $val = $2; + + $num_opts ++; + if ($save_ARGV[$optidx] ne $val) { +# print STDERR "$optidx: differs\n"; + return; + } + } + elsif (/^CHARSET (.*)$/) { + my $charset = $1; + + if ($charset ne langinfo(CODESET)) { +# print STDERR "charset $charset differs\n"; + return; + } + } + elsif (/^LANGUAGE (.*)$/) { + my $language = $1; + + if ($language ne setlocale(LC_MESSAGES)) { +# print STDERR "language $language differs\n"; + return; + } + } + elsif (/^VERSION (.*)$/) { + my $v = $1; + + if ($v ne $Version) { +# print STDERR "Version differs\n"; + return; + } + } + else { + print STDERR "Wrong cache inputs list\n"; + return; + } + + + } + + return if $num_opts != @save_ARGV; + + open(FILE, "<$cachedir/output") or return; + + print STDERR "Using cached output\n" if $verbose; + + my $buf; + while(read(FILE, $buf, 4096)) { + print $buf; + } + close(FILE); + + exit 0; +} + +sub write_cache ($) +{ + my ($output) = @_; + + my $cachedir = $ENV{HOME}; + + return unless -d $cachedir; + + $cachedir .= "/.xdg_menu_cache"; + + mkdir $cachedir; + unlink "$cachedir/output"; + + open(FILE, ">$cachedir/inputs") or return; + print FILE "# this file contains list of inputs xdg_menu\n"; + print FILE "VERSION $Version\n"; + print FILE "\n\n"; + print FILE join("\n", @accessed_files); + print FILE "\n\n"; + + for (my $i = 0; $i < @save_ARGV; $i++) { + print FILE "OPT $i $save_ARGV[$i]\n"; + } + + print FILE "ENV XDG_CONFIG_DIRS $ENV{XDG_CONFIG_DIRS}\n"; + print FILE "ENV XDG_DATA_DIRS $ENV{XDG_DATA_DIRS}\n"; + + print FILE "CHARSET " . langinfo(CODESET) . "\n"; + print FILE "LANGUAGE " . setlocale(LC_MESSAGES) . "\n"; + + close(FILE); + open(FILE, ">$cachedir/output") or return; + print FILE $output; + close(FILE); +} + + +check_cache(); + +use XML::Parser; + +$DefaultAppDirs = get_app_dirs(); +$DefaultDirectoryDirs = get_desktop_dirs(); + +my $root_menu = get_root_menu(); + +@KDELegacyDirs = get_KDE_legacy_dirs(); + +$charset = langinfo(CODESET); +$language = setlocale(LC_MESSAGES); + +$root_cmd = "/opt/gnome/bin/gnomesu" if -x '/opt/gnome/bin/gnomesu'; +$root_cmd = "/opt/kde3/bin/kdesu" if -x '/opt/kde3/bin/kdesu'; + +my $help; + +GetOptions("format=s" => \$format, + "fullmenu" => \$fullmenu, + "desktop=s" => \$desktop_name, + "charset=s" => \$charset, + "language=s" => \$language, + "root-menu=s" => \$root_menu, + "die-on-error" => \$die_on_error, + "verbose" => \$verbose, + "help" => \$help + ); + +@language_keys = prepare_language_keys($language); + +$desktop_name = $format unless defined $desktop_name; + +if ($help) { + print <<"EOF"; + +xdg-menu - XDG menus for WindowMaker and other window managers + http://freedesktop.org/Standards/menu-spec + + +Usage: + xdg_menu [--format ] [--desktop ] + [--charset ] [--language ] + [--root-menu ] [--die-on-error] + [--fullmenu] [--help] + + format - output format + possible formats: WindowMaker, fvwm2, icewm, + blackbox, fluxbox, openbox, + xfce4, openbox3, openbox3-pipe, + mwm, readable + default: WindowMaker + + fullmenu - output a full menu and not only a submenu + + desktop - desktop name for NotShowIn and OnlyShowIn + default: the same as format + + charset - output charset + default: $charset + + language - output language + default: $language + + root-menu - location of root menu file + default: $root_menu + + die-on-error - abort execution on any error, + default: try to continue + + verbose - print debugging information + + help - print this text + +EOF + exit 0; +} + + +unless ( -f $root_menu) { + print STDERR "Can't find root menu file.\n"; + exit 1; +} + +my $tree = read_menu($root_menu); + +merge_menus($tree); +move_menus($tree); + +my $menu = interpret_root($tree, ''); + +remove_allocated($menu); +preprocess_menu($menu); +remove_empty_menus($menu); + +my $output; + +if ($format eq 'WindowMaker') { + + $output = output_wmaker_menu($menu) +} +elsif ($format eq 'fvwm2') { + + $output = output_fvwm2_menu($menu) +} +elsif ($format eq 'icewm') { + foreach my $entry (@{$menu->{'entries'}}) { + + if ($entry->{type} eq 'menu') { + $output .= output_icewm_menu ($entry->{'menu'}); + } + } +} +elsif ($format eq 'xfce4') { + + $output = output_xfce4_menu($menu) +} +elsif ($format eq 'blackbox' || ($format eq 'openbox') || ($format eq 'fluxbox') ) { + if ($fullmenu) { + $output = output_blackbox_menu($menu) + } + else + { + $output = output_blackbox_inner_menu($menu) + } +} +elsif ($format eq 'openbox3') { + if ($fullmenu) { + $output = output_openbox3_menu($menu) + } + else + { + $output = output_openbox3_inner_menu($menu) + } +} +elsif ($format eq 'openbox3-pipe') { + + $output = output_openbox3_pipe_menu($menu) +} +elsif ($format eq 'twm') { + + print STDERR "WARNING: twm does not support umlauts. Parameter --language '' to output plain ASCII.\n" unless $language eq ''; + $output = output_twm_menu($menu) +} +elsif ($format eq 'mwm') { + + $output = output_twm_menu($menu) +} +elsif ($format eq 'readable') { + + $output = output_readable($menu) +} +else +{ + print STDERR "Unknown format $format\n"; + exit 1; +} + +print $output; +write_cache($output); + +exit 0; + -- cgit v1.2.1