LeandroNKZ

obmenu-generator modificado

May 25th, 2013
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 26.00 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. # Copyright (C) 2011-2012 Trizen <echo dHJpemVueEBnbWFpbC5jb20K | base64 -d>.
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. # Openbox Menu Generator
  19. # A fast pipe/static menu generator for the Openbox Window Manager.
  20. # It used to be even faster about a year ago, but now it's older and wiser :)
  21. #
  22. # License: GPLv3
  23. # Created on: 25 March 2011
  24. # Latest edit on: 25 May 2013
  25. # Website: http://trizen.googlecode.com
  26. # Modificado por Leandro Nkz <http://www.vivaolinux.com.br/~leandro>
  27.  
  28. #use strict;
  29. #use warnings;
  30.  
  31. require Linux::DesktopFiles;
  32.  
  33.  
  34. my $pkgname = 'obmenu-generator';
  35. our $VERSION = '0.54';
  36.  
  37. our ($CONFIG, $SCHEMA);
  38. my $output_h = *STDOUT;
  39.  
  40. my ($pipe, $static, $icons, $reconfigure, $stdout_config, $update_config);
  41.  
  42. my $home_dir =
  43.      $ENV{HOME}
  44.   || $ENV{LOGDIR}
  45.   || (getpwuid($<))[7]
  46.   || `echo -n ~`;
  47.  
  48. my $xdg_config_home = $ENV{XDG_CONFIG_HOME} || "$home_dir/.config";
  49.  
  50. my $config_dir   = "$xdg_config_home/obmenu-generator";
  51. my $schema_file  = "$config_dir/schema.pl";
  52. my $config_file  = "$config_dir/config.pl";
  53. my $openbox_conf = "$xdg_config_home/openbox";
  54. my $menufile     = "$openbox_conf/menu.xml";
  55. my $icons_db     = "$config_dir/icons.db";
  56.  
  57.  
  58. ##### Configurações personalizadas #####
  59. #Obs.: é recomendável deixar, ao menos 2 temas de ícones ativos
  60. #Assim, se não houver um determinado ícone em uma categoria, ele usará do próximo tema
  61. my $ICONS = "$home_dir/.icons/fs-icons-ubuntu-sky";
  62. my $ICONS2 = "$home_dir/.icons/Faenza";
  63. my $ICONS3 = "";
  64. my $FILEMANAGER = "thunar";
  65. my $TERMINAL = "lxterminal --geometry=100x30";
  66. my $EDITOR = "gvim";
  67. my $NAVEGADOR = "firefox";
  68. ##Adicione novas entradas no topo do menu:
  69. ##             USO: "{item => ['comando',     'Nome',  'ícone']},";
  70. my $CUSTOM_ITEM_1 = "{item => ['gmail --gui', 'Gmail', 'gmail']},";
  71. my $CUSTOM_ITEM_2 = "";
  72. my $CUSTOM_ITEM_3 = "";
  73. my $CUSTOM_ITEM_4 = "";
  74. ########################################
  75.  
  76.  
  77. sub usage {
  78.     print <<"HELP";
  79. usage: $0 [options]\n
  80. Options:
  81.     -p  : (re)generate a pipe menu
  82.     -s  : (re)generate a static menu
  83.     -d  : (re)generate icons.db (with -i)
  84.     -r  : (re)generate config file
  85.     -i  : use icons in menus
  86.     -u  : update the configuration file
  87.     -R  : reconfigure openbox
  88.  
  89. Others:
  90.     -h  : print this message
  91.     -S  : print the schema file to STDOUT
  92.     -H  : print help message for config files
  93.  
  94. Examples:
  95.    ** Static menu without icons:
  96.         $0 -s
  97.  
  98.    ** Pipe menu with icons:
  99.         $0 -p -i
  100.  
  101.     ** Reconfigure openbox:
  102.         $0 -R
  103.  
  104. NOTE: After a pipe menu is generated, '-p' it's not needed anymore.
  105.  
  106. ** Config file: $config_file
  107. ** Schema file: $schema_file
  108. HELP
  109.     exit 0;
  110. }
  111.  
  112. my $config_help = <<"HELP";
  113.  
  114. categories_case_sensitive => BOOL (default: 0)
  115. - True (1) to make the category names case sensitive;
  116. - By default, "XFCE-4" is equivalent with "xfce_4".
  117.  
  118. clean_command_name_re => REGEX
  119. - Remove from the command name anything matched by the regex.
  120.  
  121. skip_app_command_re => REGEX
  122. - Skip the application if its command name matches the regex.
  123.  
  124. skip_app_name_re => REGEX
  125. - Skip the application if its name matches the regex.
  126.  
  127. skip_file_content_re => REGEX
  128. - Skip the application if the content of the *.desktop
  129.   file matches the regex.
  130.  
  131. skip_file_name_re => REGEX
  132. - Skip the application if its file name matches the regex.
  133.   Name is from the last slash to the end. (example: file.desktop)
  134.  
  135. skip_svg_icons => BOOL
  136. - True (1) to skip the SVG icons.
  137.  
  138. desktop_files_paths => ARRAY REF
  139. - Paths which contains the desktop files.
  140.  
  141. wine_desktop_files_paths => ARRAY REF
  142. - Directories which contains desktop files generated by the wine app.
  143.  
  144. wine_skip_exec_re => REGEX
  145. - Skip the wine application if its command matches the regex.
  146.  
  147. wine_skip_name_re => REGEX
  148. - Skip the wine application if its name matches the regex.
  149.  
  150. editor => STRING
  151. - Text editor command.
  152.  
  153. terminal => STRING
  154. - Terminal command.
  155.  
  156. gtk_rc_filename => STRING - full path to file
  157. - GTK configuration file. (autodetected)
  158.  
  159. icon_dirs_first => ARRAY REF
  160. - When looking for full icon paths, look in this directories first,
  161.   before looking in the directories of the current icon theme.
  162.  
  163. icon_dirs_second => ARRAY REF
  164. - When looking for full icon paths, look in this directories as a
  165.   second icon theme. (Before /usr/share/pixmaps)
  166.  
  167. icon_dirs_last => ARRAY REF
  168. - Look in this directories at the very last, after looked in
  169.   /usr/share/pixmaps, /usr/share/icons/hicolor and some other
  170.   directories.
  171.  
  172. use_only_my_icon_dirs => BOOL
  173. - True (1) to look only in directories specified in the above ARRAY REF's.
  174. - False (0) to look in other directories. (example: /usr/share/pixmaps)
  175.  
  176. missing_icon => STRING
  177. - When an icon is not found, use this icon instead.
  178.  
  179. VERSION => NUMBER (default: $VERSION)
  180. - Version of obmenu-generator.
  181. HELP
  182.  
  183. my $schema_help = <<"HELP";
  184.  
  185. item: add an item into the menu
  186. {item => ["command", "label", "icon"]}
  187.  
  188. cat: add a category into the menu
  189. {cat => ["name", "label", "icon"]}
  190.  
  191. begin_cat: begin of a category
  192. {begin_cat => ["name", "icon"]}
  193.  
  194. end_cat: end of a category
  195. {end_cat => undef}
  196.  
  197. sep: menu line separator
  198. {sep => undef} or {sep => "label"}
  199.  
  200. exit: default "Exit" action
  201. {exit => ["label", "icon"]}
  202.  
  203. raw: any valid Openbox XML string
  204. {raw => q(xml string)},
  205.  
  206. obgenmenu: category provided by obmenu-generator
  207. {obgenmenu => "label"}
  208.  
  209. scripts: executable scripts from a directory
  210. {scripts => ["/my/dir", BOOL, "icon"]}
  211. BOOL - can be either true or false (1 or 0)
  212. 0 == open the script in background
  213. 1 == open the script in a new terminal
  214.  
  215. wine_apps: windows applications installed via wine
  216. {wine_apps => ["label", "icon"]}
  217. HELP
  218.  
  219. sub full_help {
  220.     print <<"HELP";
  221. =>> Schema file:
  222. $schema_help
  223. ====================================================
  224.  
  225. =>> Config file:
  226. $config_help
  227. HELP
  228.  
  229.     exit 0;
  230. }
  231.  
  232. if (@ARGV) {
  233.     foreach my $arg (@ARGV) {
  234.         if ($arg eq '-i') {
  235.             $icons = 1;
  236.         }
  237.         elsif ($arg eq '-S') {
  238.             $stdout_config = 1;
  239.         }
  240.         elsif ($arg eq '-p') {
  241.             $pipe = 1;
  242.         }
  243.         elsif ($arg eq '-r') {
  244.             $reconfigure = 1;
  245.         }
  246.         elsif ($arg eq '-s') {
  247.             $static = 1;
  248.         }
  249.         elsif ($arg eq '-d') {
  250.             unlink $icons_db;
  251.         }
  252.         elsif ($arg eq '-h') {
  253.             usage();
  254.         }
  255.         elsif ($arg eq '-H') {
  256.             full_help();
  257.         }
  258.         elsif ($arg eq '-u') {
  259.             $update_config = 1;
  260.         }
  261.         elsif ($arg eq '-v') {
  262.             print "$pkgname $VERSION\n";
  263.             exit 0;
  264.         }
  265.         elsif ($arg eq '-R') {
  266.             exec 'openbox', '--reconfigure';
  267.         }
  268.     }
  269. }
  270.  
  271. if (not -d $config_dir) {
  272.     require File::Path;
  273.     File::Path::make_path($config_dir)
  274.       or die "Can't create directory '${config_dir}': $!";
  275. }
  276.  
  277. my $config_documentation = <<"EOD";
  278. #!/usr/bin/perl
  279.  
  280. # $pkgname - configuration file
  281. # This file is updated automatically every time when is needed.
  282. # Any additional comment and/or indentation will be lost.
  283.  
  284. =for comment
  285. $config_help
  286. =cut
  287.  
  288. # For regular expressions
  289. #    * is better to use qr/REGEX/ instead of 'REGEX'
  290.  
  291. # NOTE: Once an icon is found, it will *NOT* be replaced by another.
  292.  
  293. EOD
  294.  
  295. my %CONFIG = (
  296.               desktop_files_paths       => ['/usr/share/applications'],
  297.               wine_desktop_files_paths  => ["$home_dir/.local/share/applications/wine"],
  298.               gtk_rc_filename           => undef,
  299.               skip_file_name_re         => undef,
  300.               skip_app_name_re          => undef,
  301.               skip_app_command_re       => undef,
  302.               skip_file_content_re      => undef,
  303.               clean_command_name_re     => undef,
  304.               wine_skip_name_re         => qr{^(?:Uninstall|Readme|Help|Visit|Register|Technical Support)\b}i,
  305.               wine_skip_exec_re         => undef,
  306.               icon_dirs_first           => [$ICONS],
  307.               icon_dirs_second          => [$ICONS2],
  308.               icon_dirs_last            => [$ICONS3],
  309.               missing_icon              => 'gtk-missing-image',
  310.               use_only_my_icon_dirs     => 0,
  311.               skip_svg_icons            => 1,
  312.               categories_case_sensitive => 0,
  313.               terminal                  => $TERMINAL,
  314.               editor                    => $EDITOR,
  315.               VERSION                   => $VERSION,
  316.              );
  317.  
  318. sub dump_configuration {
  319.     require Data::Dump;
  320.     open my $config_fh, '>', $config_file
  321.       or die "Can't open file '${config_file}' for write: $!";
  322.     my $dumped_config = q{our $CONFIG = } . Data::Dump::dump(\%CONFIG);
  323.     print $config_fh $config_documentation, $dumped_config;
  324.     close $config_fh;
  325. }
  326.  
  327.  
  328. if (not -e $config_file or $reconfigure) {
  329.     dump_configuration();
  330. }
  331.  
  332. if (not -e $schema_file or $reconfigure or $stdout_config) {
  333.  
  334.     my $schema_fh = $stdout_config ? \*STDOUT : do {
  335.         open my $fh, '>', $schema_file
  336.           or die "Can't open file '${schema_file}' for write: $!";
  337.         $fh;
  338.     };
  339.  
  340.     print $schema_fh <<"SCHEMA_FILE";
  341. #!/usr/bin/perl
  342.  
  343. # SCHEMA supports the following keys: item, cat, begin_cat, end_cat,
  344. #                                     exit, raw, sep, obgenmenu
  345.  
  346. =for comment
  347. $schema_help
  348. =cut
  349.  
  350. # NOTE:
  351. #    * Keys and values are case sensitive. Keep all keys lowercase.
  352. #    * ICON can be a either a direct path to a icon or a valid icon name
  353. #    * By default, category names are case insensitive. (e.g.: X-XFCE == x_xfce)
  354.  
  355. require '${config_file}';
  356.  
  357. our \$SCHEMA = [
  358.     #             COMMAND                 LABEL                ICON
  359.     {item => [$FILEMANAGER,        'Gerenciador de arquivos',    'file-manager']},
  360.     {item => [\$CONFIG->{terminal},     'Terminal',           'terminal']},
  361.     {item => [\$CONFIG->{editor},       'Editor de textos',   'text-editor']},
  362.     {item => [$NAVEGADOR,               'Navegador',           'web-browser']},
  363.     $CUSTOM_ITEM_1
  364.     $CUSTOM_ITEM_2
  365.     $CUSTOM_ITEM_3
  366.     $CUSTOM_ITEM_4
  367.     {sep => 'Aplicações'},
  368.  
  369.     #          NAME            LABEL                ICON
  370.     {cat => ['utility',     'Acessórios', 'applications-utilities']},
  371.     {cat => ['development', 'Desenvolvimento', 'applications-development']},
  372.     {cat => ['office',      'Escritório',      'applications-office']},
  373.     {cat => ['graphics',    'Gráficos',    'applications-graphics']},
  374.     {cat => ['education',   'Educação',   'applications-science']},
  375.     {cat => ['game',        'Jogos',       'applications-games']},
  376.     {cat => ['network',     'Internet',     'applications-internet']},
  377.     {cat => ['audiovideo',  'Multimídia',  'applications-multimedia']},
  378.     {cat => ['applications', 'Outros',     'applications-other']},
  379.     {cat => ['settings',    'Configurações',    'applications-accessories']},
  380.     {cat => ['system',      'Sistema',      'applications-system']},
  381.  
  382.     #{cat => ['qt',          'QT Applications',    'qtlogo']},
  383.     #{cat => ['gtk',         'GTK Applications',   'gnome-applications']},
  384.     #{cat => ['x_xfce',      'XFCE Applications',  'applications-other']},
  385.     #{cat => ['gnome',       'GNOME Applications', 'gnome-applications']},
  386.     #{cat => ['consoleonly', 'CLI Applications',   'applications-utilities']},
  387.  
  388.     #                  LABEL          ICON
  389.     #{begin_cat => ['My category',  'cat-icon']},
  390.     #             ... some items ...
  391.     #{end_cat   => undef},
  392.  
  393.     #                  LABEL             ICON
  394.     #{wine_apps => ['Wine apps', 'applications-other']},
  395.  
  396.     #                DIR     BOOL       ICON
  397.     #{scripts => ['/my/path', 1,  'text-x-script']},
  398.  
  399.     {obgenmenu => 'Configurações do Openbox'},
  400.     {sep       => undef},
  401.  
  402.     {item => ['xscreensaver-command -lock', 'Travar tela', 'lock']},
  403.  
  404.     # This options uses the default OpenBox action "Exit"
  405.     #{exit => ['Sair', 'exit']},
  406.     {exit => 'lock'},
  407. ]
  408. SCHEMA_FILE
  409.  
  410.     exit if $stdout_config;
  411.     close $schema_fh;
  412. }
  413.  
  414. require $schema_file;    # Load the configuration files
  415.  
  416. # Remove the user defined values
  417. #my @valid_keys = grep exists $CONFIG{$_}, keys %{$CONFIG};
  418. #@CONFIG{@valid_keys} = @{$CONFIG}{@valid_keys};
  419.  
  420. # Keep the user defined values
  421. @CONFIG{keys %{$CONFIG}} = values %{$CONFIG};
  422.  
  423. if ($CONFIG{VERSION} != $VERSION) {
  424.     $update_config = 1;
  425.     $CONFIG{VERSION} = $VERSION;
  426. }
  427.  
  428. my $desk_obj = Linux::DesktopFiles->new(
  429.  
  430.     home_dir         => $home_dir,
  431.     terminal         => $CONFIG{terminal},
  432.     gtk_rc_filename  => $CONFIG{gtk_rc_filename},
  433.     icon_db_filename => $icons_db,
  434.  
  435.     desktop_files_paths => $CONFIG{desktop_files_paths},
  436.  
  437.     with_icons            => $icons,
  438.     skip_svg_icons        => $CONFIG{skip_svg_icons},
  439.     full_icon_paths       => 1,
  440.     terminalize           => 1,
  441.     keep_empty_categories => 1,
  442.  
  443.     icon_dirs_first       => $CONFIG{icon_dirs_first},
  444.     icon_dirs_second      => $CONFIG{icon_dirs_second},
  445.     icon_dirs_last        => $CONFIG{icon_dirs_last},
  446.     use_only_my_icon_dirs => $CONFIG{use_only_my_icon_dirs},
  447.  
  448.     skip_file_name_re     => $CONFIG{skip_file_name_re},
  449.     skip_app_name_re      => $CONFIG{skip_app_name_re},
  450.     skip_app_command_re   => $CONFIG{skip_app_command_re},
  451.     skip_file_content_re  => $CONFIG{skip_file_content_re},
  452.     clean_command_name_re => $CONFIG{subst_command_name_re},
  453.  
  454.     categories                => [map $_->{cat}[0], grep exists $_->{cat}, @$SCHEMA],
  455.     categories_case_sensitive => $CONFIG{categories_case_sensitive},
  456. );
  457.  
  458. if ($pipe or $static) {
  459.     my $menu_backup = $menufile . '.bak';
  460.     if (not -e $menu_backup and -e $menufile) {
  461.         require File::Copy;
  462.         File::Copy::copy($menufile, $menu_backup);
  463.     }
  464.  
  465.     if ($static) {
  466.         open $output_h, '>', $menufile
  467.           or die "Can't open file '${menufile}' for write: $!";
  468.     }
  469.     elsif ($pipe) {
  470.         if (not -d $openbox_conf) {
  471.             require File::Path;
  472.             File::Path::make_path($openbox_conf)
  473.               or die "Can't create directory '${openbox_conf}': $!";
  474.         }
  475.  
  476.         require Cwd;
  477.         my $exec_name = Cwd::abs_path($0) . ($icons ? q{ -i} : q{});
  478.  
  479.         open my $fh, '>', $menufile
  480.           or die "Can't open file '${menufile}' for write: $!";
  481.         print $fh <<"PIPE_MENU_HEADER";
  482. <?xml version="1.0" encoding="utf-8"?>
  483. <openbox_menu xmlns="http://openbox.org/"
  484.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  485.   xsi:schemaLocation="http://openbox.org/">
  486.     <menu id="root-menu" label="obmenu-generator" execute="$exec_name" />
  487. </openbox_menu>
  488. PIPE_MENU_HEADER
  489.         close $fh;
  490.     }
  491. }
  492.  
  493. my $generated_menu = $static
  494.   ? <<'STATIC_MENU_HEADER'
  495. <?xml version="1.0" encoding="utf-8"?>
  496. <openbox_menu xmlns="http://openbox.org/"
  497.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  498.   xsi:schemaLocation="http://openbox.org/">
  499.   <menu id="root-menu" label="Applications">
  500. STATIC_MENU_HEADER
  501.   : "<openbox_pipe_menu>\n";
  502.  
  503. sub prepare_item {
  504.     $icons
  505.       ? <<"ITEM_WITH_ICON"
  506.     <item label="$_[1]" icon="${\($desk_obj->get_icon_path($_[2]) || $desk_obj->get_icon_path($CONFIG{missing_icon}))}"><action name="Execute"><execute>$_[0]</execute></action></item>
  507. ITEM_WITH_ICON
  508.       : <<"ITEM";
  509.     <item label="$_[1]"><action name="Execute"><execute>$_[0]</execute></action></item>
  510. ITEM
  511. }
  512.  
  513. sub begin_category {
  514.     $icons
  515.       ? <<"MENU_WITH_ICON"
  516.   <menu id="$_[0]" icon="${\$desk_obj->get_icon_path($_[1])}" label="$_[0]">
  517. MENU_WITH_ICON
  518.       : <<"MENU"
  519.   <menu id="$_[0]" label="$_[0]">
  520. MENU
  521. }
  522.  
  523. my $categories = $desk_obj->parse_desktop_files();
  524.  
  525. foreach my $schema (@$SCHEMA) {
  526.     if (exists $schema->{cat}) {
  527.         next unless defined $categories->{$schema->{cat}[0]};
  528.         $generated_menu .= begin_category($schema->{cat}[1], ($icons ? $schema->{cat}[2] : ())) . join(
  529.             q{},
  530.             (
  531.              map $_->[1],
  532.              sort { $a->[0] cmp $b->[0] }
  533.                map [lc($_) => $_],
  534.              map {
  535.                  if ($_->{Name} =~ tr/"&//) {
  536.                     $_->{Name} =~ s/&/&amp;/g;
  537.                     $_->{Name} =~ s/"/&quot;/g;
  538.                  }
  539.                  $icons
  540.                    ? <<"ITEM_WITH_ICON"
  541.     <item label="$_->{Name}" icon="$_->{Icon}"><action name="Execute"><execute>$_->{Exec}</execute></action></item>
  542. ITEM_WITH_ICON
  543.                    : <<"ITEM";
  544.     <item label="$_->{Name}"><action name="Execute"><execute>$_->{Exec}</execute></action></item>
  545. ITEM
  546.                } @{$categories->{$schema->{cat}[0]}}
  547.             )
  548.           )
  549.           . qq[  </menu>\n];
  550.     }
  551.     elsif (exists $schema->{item}) {
  552.         $generated_menu .= prepare_item(@{$schema->{item}});
  553.     }
  554.     elsif (exists $schema->{sep}) {
  555.         $generated_menu .=
  556.           defined $schema->{sep}
  557.           ? qq[  <separator label="$schema->{sep}"/>\n]
  558.           : qq[  <separator/>\n];
  559.     }
  560.     elsif (exists $schema->{wine_apps}) {
  561.  
  562.         my @output;
  563.         my @dirs = @{$CONFIG{wine_desktop_files_paths}};
  564.  
  565.         while (@dirs) {
  566.             my $dir = shift @dirs;
  567.             opendir(my $dir_h, $dir) or next;
  568.             while (defined(my $file = readdir $dir_h)) {
  569.  
  570.                 if (substr($file, -8) eq '.desktop') {
  571.  
  572.                     sysopen my $fh, "$dir/$file", 0 or next;
  573.                     sysread $fh, (my $_), -s "$dir/$file";
  574.                     close $fh;
  575.  
  576.                     my ($exec) = (/^Exec=(.+)/m ? $1 : next);
  577.                     my ($name) = (/^Name=(.+)/m ? $1 : "Unknown name");
  578.  
  579.                     if (defined $CONFIG{wine_skip_name_re}) {
  580.                         next if $name =~ $CONFIG{wine_skip_name_re};
  581.                     }
  582.                     if (defined $CONFIG{wine_skip_exec_re}) {
  583.                         next if $exec =~ $CONFIG{wine_skip_exec_re};
  584.                     }
  585.  
  586.                     $exec =~ s{\\(.)}{$1}g;
  587.  
  588.                     if ($name =~ tr/"&//) {
  589.                        $name =~ s{&}{&amp;}g;
  590.                        $name =~ s{"}{&quot;}g;
  591.                     }
  592.  
  593.                     push @output,
  594.                       scalar {item => [$exec, $name, ($icons ? (/^Icon=(.+)/m ? $1 : $CONFIG{missing_icon}) : ())]};
  595.                 }
  596.                 elsif ($file eq '.' or $file eq '..') {
  597.                     next;
  598.                 }
  599.                 elsif (-d "$dir/$file") {
  600.                     push @dirs, "$dir/$file";
  601.                 }
  602.             }
  603.             closedir $dir_h;
  604.         }
  605.  
  606.         $generated_menu .=
  607.             begin_category(@{$schema->{wine_apps}})
  608.           . join('', map prepare_item(@{$_->{item}}), sort { lc $a->{item}[1] cmp lc $b->{item}[1] } @output)
  609.           . qq[  </menu>\n];
  610.     }
  611.     elsif (exists $schema->{scripts}) {
  612.         my @scripts;
  613.         my $dir = $schema->{scripts}[0];
  614.  
  615.         opendir(my $dir_h, $dir) or next;
  616.         foreach my $file (sort readdir $dir_h) {
  617.             if (-f "$dir/$file" and -x _ and not -z _) {
  618.                 $generated_menu .=
  619.                   prepare_item(($schema->{scripts}[1] ? qq{$CONFIG{terminal} -e '$dir/$file'} : "$dir/$file"),
  620.                                $file, ($icons ? $schema->{scripts}[2] : ()));
  621.             }
  622.         }
  623.         closedir $dir_h;
  624.     }
  625.     elsif (exists $schema->{begin_cat}) {
  626.         $generated_menu .= begin_category(@{$schema->{begin_cat}});
  627.     }
  628.     elsif (exists $schema->{end_cat}) {
  629.         $generated_menu .= qq[  </menu>\n];
  630.     }
  631.     #   elsif (exists $schema->{exit}) {
  632.     #    $generated_menu .= $icons
  633.     #      ? <<"EXIT_WITH_ICON"
  634.     #<item label="Exit" icon="${\$desk_obj->get_icon_path($schema->{exit}[1])}"><action name="Exit" /></item>
  635. #EXIT_WITH_ICON
  636. #      : <<'EXIT';
  637. #<item label="Exit"><action name="Exit" /></item>
  638. #EXIT
  639.     #}
  640.     elsif (exists $schema->{raw}) {
  641.         $generated_menu .= qq[    $schema->{raw}\n];
  642.     }
  643.     elsif (exists $schema->{obgenmenu}) {
  644.         $generated_menu .= <<"CONFIG_MENU";
  645.   <separator />
  646.   <menu id="$schema->{obgenmenu}" label="$schema->{obgenmenu}">
  647.     <item label="Reconfigure Openbox"><action name="Reconfigure" /></item>
  648. CONFIG_MENU
  649.         if (-e '/usr/bin/obconf') {
  650.             $generated_menu .= <<'EOL';
  651.     <item label="Openbox Configuration Manager"><action name="Execute"><execute>obconf</execute></action></item>
  652. EOL
  653.         }
  654.         $generated_menu .= <<"CONFIG_MENU";
  655.     <item label="Aplicativos de inicialização"><action name="Execute"><execute>$CONFIG{editor} $openbox_conf/autostart</execute></action></item>
  656.     <item label="Editar rc.xml"><action name="Execute"><execute>$CONFIG{editor} $openbox_conf/rc.xml</execute></action></item>
  657.     <separator />
  658.     <item label="Gerar um pipe menu"><action name="Execute"><execute>$0 -p</execute></action></item>
  659.     <item label="Gerar um static menu"><action name="Execute"><execute>$0 -s</execute></action></item>
  660.     <item label="Gerar um pipe menu com ícones"><action name="Execute"><execute>$0 -p -i</execute></action></item>
  661.     <item label="Gerar um static menu com ícones"><action name="Execute"><execute>$0 -s -i</execute></action></item>
  662.     <separator />
  663.     <item label="Editar menu.xml"><action name="Execute"><execute>$CONFIG{editor} $menufile</execute></action></item>
  664.     <item label="Editar o arquivo de schema"><action name="Execute"><execute>$CONFIG{editor} $schema_file</execute></action></item>
  665.     <item label="Editar o arquivo de configuração"><action name="Execute"><execute>$CONFIG{editor} $config_file</execute></action></item>
  666.     <separator />
  667.     <item label="Atualizar arquivo de configuração"><action name="Execute"><execute>$0 -r</execute></action></item>
  668.     <item label="Atualizar cache"><action name="Execute"><execute>rm -r $config_dir</execute></action></item>
  669.   </menu>
  670. CONFIG_MENU
  671.     }
  672.  
  673.     #### Início menu sair ####
  674.        elsif (exists $schema->{exit}) {
  675.         $generated_menu .= $icons
  676.           ? <<"MENU_WITH_ICON"
  677.           <separator />
  678.           <menu id="$schema->{exit}" label="Sair" icon="${\$desk_obj->get_icon_path('exit')}">
  679.             <item label="Desligar" icon="${\$desk_obj->get_icon_path('system-shutdown')}">
  680.                 <action name="Execute">
  681.                     <execute>dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop</execute>
  682.                 </action>
  683.             </item>
  684.             <separator />
  685.             <item label="Reiniciar" icon="${\$desk_obj->get_icon_path('system-restart')}">
  686.                 <action name="Execute">
  687.                     <execute>dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart</execute>
  688.                 </action>
  689.             </item>
  690.             <separator />
  691.             <item label="Hibernar" icon="${\$desk_obj->get_icon_path('system-hibernate')}">
  692.                 <action name="Execute">
  693.                     <execute>dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Hibernate</execute>
  694.                 </action>
  695.             </item>
  696.             <separator />
  697.             <item label="Suspender" icon="${\$desk_obj->get_icon_path('system-suspend')}">
  698.                 <action name="Execute">
  699.                     <execute>dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend</execute>
  700.                 </action>
  701.             </item>
  702.             <separator />
  703.             <item label="Logoff" icon="${\$desk_obj->get_icon_path('system-log-out')}">
  704.                 <action name="Execute">
  705.                     <execute>openbox --exit</execute>
  706.                 </action>
  707.             </item>
  708.   </menu>
  709.  
  710. MENU_WITH_ICON
  711.       : <<'MENU';
  712.   <separator />
  713.   <menu id="$schema->{exit}" label="Sair">
  714.             <item label="Desligar">
  715.                 <action name="Execute">
  716.                     <execute>dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop</execute>
  717.                 </action>
  718.             </item>
  719.             <separator />
  720.             <item label="Reiniciar">
  721.                 <action name="Execute">
  722.                     <execute>dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart</execute>
  723.                 </action>
  724.             </item>
  725.             <separator />
  726.             <item label="Hibernar">
  727.                 <action name="Execute">
  728.                     <execute>dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Hibernate</execute>
  729.                 </action>
  730.             </item>
  731.             <separator />
  732.             <item label="Suspender">
  733.                 <action name="Execute">
  734.                     <execute>dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend</execute>
  735.                 </action>
  736.             </item>
  737.             <separator />
  738.             <item label="Logoff">
  739.                 <action name="Execute">
  740.                     <execute>openbox --exit</execute>
  741.                 </action>
  742.             </item>
  743.   </menu>
  744. MENU
  745.     }
  746.     ## FIM menu sair ###
  747.  
  748. }
  749.  
  750. print $output_h $generated_menu, $static
  751.   ? qq[  </menu>\n</openbox_menu>\n]
  752.   : qq[</openbox_pipe_menu>\n];
  753.  
  754. dump_configuration() if $update_config;
Add Comment
Please, Sign In to add comment