panelvalaappindicator

Simple AppIndicator with Vala application under Elementary OS


Yesterday I've been stuck on some hard things. Something that looks simple at first but who's not thrust me :/

Here is what i'm trying to have : An appindicator (statusicon ?) with a custom icon for my application.

Unfortunately, there is nothing I found inside valadoc, except this but it's deprecated and it says we should use Notifications which is really not the same thing I've heard about .vapi Appindicator files, but this is no real documentation about how to use it

If someone can post code about integrating AppIndicator inside vala code, I would be thankful !

Thanks


Solution

  • Have you tried the Vala example included in libappindicator?

    http://bazaar.launchpad.net/~indicator-applet-developers/libappindicator/trunk.15.10/view/head:/bindings/vala/examples/indicator-example.vala

    /*
     * Copyright 2011 Canonical Ltd.
     *
     * This program is free software: you can redistribute it and/or modify it
     * under the terms of the GNU General Public License version 3, as published
     * by the Free Software Foundation.
     *
     * This program is distributed in the hope that it will be useful, but
     * WITHOUT ANY WARRANTY; without even the implied warranties of
     * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
     * PURPOSE.  See the GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License along
     * with this program.  If not, see <http://www.gnu.org/licenses/>.
     *
     * Authors:
     *   Marco Trevisan (Treviño) <mail@3v1n0.net>
     */
    
    using Gtk;
    using AppIndicator;
    
    public class IndicatorExample {
        public static int main(string[] args) {
            Gtk.init(ref args);
    
            var win = new Window();
            win.title = "Indicator Test";
            win.resize(200, 200);
            win.destroy.connect(Gtk.main_quit);
    
            var label = new Label("Hello, world!");
            win.add(label);
    
            var indicator = new Indicator(win.title, "indicator-messages",
                                          IndicatorCategory.APPLICATION_STATUS);
            if (!(indicator is Indicator)) return -1;
    
            indicator.set_status(IndicatorStatus.ACTIVE);
            indicator.set_attention_icon("indicator-messages-new");
    
            var menu = new Gtk.Menu();
    
            var item = new Gtk.MenuItem.with_label("Foo");
            item.activate.connect(() => {
                indicator.set_status(IndicatorStatus.ATTENTION);
            });
            item.show();
            menu.append(item);
    
            var bar = item = new Gtk.MenuItem.with_label("Bar");
            item.show();
            item.activate.connect(() => {
                indicator.set_status(IndicatorStatus.ACTIVE);
            });
            menu.append(item);
    
            indicator.set_menu(menu);
            indicator.set_secondary_activate_target(bar);
    
            win.show_all();
    
            Gtk.main();
            return 0;
        }
    }