1/*
2 * vala-panel-appmenu
3 * Copyright (C) 2015 Konstantin Pugin <ria.freelander@gmail.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser 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 Lesser General Public License
16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19using GLib;
20using Gtk;
21using Appmenu;
22using Xfce;
23
24public class AppmenuPlugin : Xfce.PanelPlugin {
25
26    public override void @construct() {
27        GLib.Intl.setlocale(LocaleCategory.CTYPE,"");
28        GLib.Intl.bindtextdomain(Config.GETTEXT_PACKAGE,Config.LOCALE_DIR);
29        GLib.Intl.bind_textdomain_codeset(Config.GETTEXT_PACKAGE,"UTF-8");
30        GLib.Intl.textdomain(Config.GETTEXT_PACKAGE);
31        var layout = new MenuWidget();
32        widget = layout;
33        add(widget);
34        add_action_widget(widget);
35        this.width_request = -1;
36        try{
37            Xfconf.init();
38            channel = this.get_channel();
39            Xfconf.Property.bind(channel,this.get_property_base()+"/"+Key.COMPACT_MODE,typeof(bool),widget,Key.COMPACT_MODE);
40            Xfconf.Property.bind(channel,this.get_property_base()+"/"+Key.BOLD_APPLICATION_NAME,typeof(bool),widget,Key.BOLD_APPLICATION_NAME);
41            Xfconf.Property.bind(channel,this.get_property_base()+"/expand",typeof(bool),widget,"hexpand");
42            this.menu_show_configure();
43        } catch (Xfconf.Error e) {
44            stderr.printf("Xfconf init failed. Configuration will not be saved.\n");
45        }
46        this.shrink = true;
47        this.set_expand(true);
48        widget.show();
49    }
50    public override void configure_plugin()
51    {
52        var dlg = new Gtk.Dialog.with_buttons( _("Configure AppMenu"), this.get_toplevel() as Window,
53                                              DialogFlags.DESTROY_WITH_PARENT,
54                                              null );
55        Gtk.Box dlg_vbox = dlg.get_content_area() as Gtk.Box;
56        var entry = new CheckButton.with_label(_("Use Compact mode (all menus in application menu)"));
57        entry.bind_property("active",widget,Key.COMPACT_MODE,BindingFlags.SYNC_CREATE);
58        dlg_vbox.pack_start(entry,false,false,2);
59        entry.show();
60        entry = new CheckButton.with_label(_("Use bold application name"));
61        entry.bind_property("active",widget,Key.BOLD_APPLICATION_NAME,BindingFlags.SYNC_CREATE);
62        dlg_vbox.pack_start(entry,false,false,2);
63        entry.show();
64        entry = new CheckButton.with_label(_("Expand plugin on panel"));
65        entry.bind_property("active",widget,"hexpand",BindingFlags.SYNC_CREATE);
66        dlg_vbox.pack_start(entry,false,false,2);
67        entry.show();
68        dlg.show();
69        dlg.present();
70        dlg.unmap.connect(()=>{
71            dlg.destroy();
72        });
73    }
74    private Xfconf.Channel channel;
75    private unowned MenuWidget widget;
76}
77
78[ModuleInit]
79public Type xfce_panel_module_init (TypeModule module) {
80    return typeof (AppmenuPlugin);
81}
82
83public bool xfce_panel_module_preinit (string[] args) {
84    Gdk.disable_multidevice();
85    return true;
86}
87