From 89b31ab0083ef53a0372d5a3ab3b76a5f9d00d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 4 Feb 2011 04:45:35 +0100 Subject: Examples, added simple-client-vala A rewrite of the simple-client.c version in Vala as example. Added a workaround for compiling it. --- example/Makefile.am | 26 ++++++- example/simple-client-vala.vala | 165 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 example/simple-client-vala.vala (limited to 'example') diff --git a/example/Makefile.am b/example/Makefile.am index 0900baf..ae9ee94 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -4,9 +4,11 @@ else VER= endif +CLEANFILES = check_PROGRAMS = \ - simple-client + simple-client \ + simple-client-vala ######################################### ## simple-client @@ -27,3 +29,25 @@ simple_client_LDADD = \ EXTRA_DIST = \ simple-client-test-icon.png + +######################################### +## simple-client-vala +######################################### + +VALAFLAGS = \ + --pkg appindicator$(VER)-0.1 \ + --vapidir=$(top_builddir)/bindings/vala + +BUILT_SOURCES = simple-client-vala.c +simple-client-vala.c: $(srcdir)/simple-client-vala.vala + $(VALAC) $(VALAFLAGS) -C $< -o $@ + $(SED) -i "s|#include\s||g" $@ + +simple_client_vala_SOURCES = simple-client-vala.c +simple_client_vala_CFLAGS = \ + $(simple_client_CFLAGS) \ + -include $(top_srcdir)/src/app-indicator.h + +simple_client_vala_LDADD = $(simple_client_LDADD) + +CLEANFILES += *.stamp *-vala.c diff --git a/example/simple-client-vala.vala b/example/simple-client-vala.vala new file mode 100644 index 0000000..9b4ffb3 --- /dev/null +++ b/example/simple-client-vala.vala @@ -0,0 +1,165 @@ +/* +A small piece of sample code demonstrating a very simple application +with an indicator. + +Copyright 2011 Canonical Ltd. + +Authors: + Marco Trevisan + +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 . +*/ + +using Gtk; +using AppIndicator; + +static int main(string[] args) { + var sc = new SimpleClient(args); + sc.run(); + return 0; +} + +class SimpleClient { + Menu menu; + Indicator ci; + int percentage; + bool active; + bool can_haz_label; + + public SimpleClient(string[] args) { + Gtk.init(ref args); + + ci = new Indicator("example-simple-client", + "indicator-messages", + IndicatorCategory.APPLICATION_STATUS); + + ci.set_status(IndicatorStatus.ACTIVE); + ci.set_attention_icon("indicator-messages-new"); + ci.set_label("1%", "100%"); + + active = true; + can_haz_label = true; + } + + private void toggle_sensitivity(Widget widget) { + widget.set_sensitive(!widget.is_sensitive()); + } + + private void append_submenu(MenuItem item) { + var menu = new Menu(); + MenuItem mi; + + mi = new MenuItem.with_label("Sub 1"); + menu.append(mi); + mi.activate.connect(() => { print("Sub1\n"); }); + + MenuItem prev_mi = mi; + mi = new MenuItem.with_label("Sub 2"); + menu.append(mi); + mi.activate.connect(() => { toggle_sensitivity(prev_mi); }); + + mi = new MenuItem.with_label("Sub 3"); + menu.append(mi); + mi.activate.connect(() => { print("Sub3\n"); }); + + menu.show_all(); + item.set_submenu(menu); + } + + private void label_toggle(MenuItem item) { + can_haz_label = !can_haz_label; + + if (can_haz_label) { + item.set_label("Hide label"); + } else { + item.set_label("Show label"); + } + } + + public void run() { + Timeout.add_seconds(1, () => { + percentage = (percentage + 1) % 100; + if (can_haz_label) { + ci.set_label(@"$(percentage+1)%", ""); + } else { + ci.set_label("", ""); + } + return true; + }); + + menu = new Menu(); + var chk = new CheckMenuItem.with_label("1"); + chk.activate.connect(() => { print("1\n"); }); + menu.append(chk); + chk.show(); + + var radio = new RadioMenuItem.with_label(new SList(), "2"); + radio.activate.connect(() => { print("2\n"); }); + menu.append(radio); + radio.show(); + + var submenu = new MenuItem.with_label("3"); + menu.append(submenu); + append_submenu(submenu); + submenu.show(); + + var toggle_item = new MenuItem.with_label("Toggle 3"); + toggle_item.activate.connect(() => { toggle_sensitivity(submenu); }); + menu.append(toggle_item); + toggle_item.show(); + + var imgitem = new ImageMenuItem.from_stock(Stock.NEW, null); + imgitem.activate.connect(() => { + Image img = (Image) imgitem.get_image(); + img.set_from_stock(Stock.OPEN, IconSize.MENU); + }); + menu.append(imgitem); + imgitem.show(); + + var att = new MenuItem.with_label("Get Attention"); + att.activate.connect(() => { + if (active) { + ci.set_status(IndicatorStatus.ATTENTION); + att.set_label("I'm okay now"); + active = false; + } else { + ci.set_status(IndicatorStatus.ACTIVE); + att.set_label("Get Attention"); + active = false; + } + }); + menu.append(att); + att.show(); + + var show = new MenuItem.with_label("Show Label"); + label_toggle(show); + show.activate.connect(() => { label_toggle(show); }); + menu.append(show); + show.show(); + + var icon = new CheckMenuItem.with_label("Set Local Icon"); + icon.activate.connect(() => { + if (icon.get_active()) { + ci.set_icon("simple-client-test-icon.png"); + } else { + ci.set_icon("indicator-messages"); + } + }); + menu.append(icon); + icon.show(); + + ci.set_menu(menu); + + Gtk.main(); + } +} -- cgit v1.2.3 From b9efa8f945736d4fd134bbf8731cdbc18fd15eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 4 Feb 2011 04:55:34 +0100 Subject: simple-client-vala: indentation fixes --- example/simple-client-vala.vala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'example') diff --git a/example/simple-client-vala.vala b/example/simple-client-vala.vala index 9b4ffb3..18ece22 100644 --- a/example/simple-client-vala.vala +++ b/example/simple-client-vala.vala @@ -108,9 +108,9 @@ class SimpleClient { menu.append(radio); radio.show(); - var submenu = new MenuItem.with_label("3"); - menu.append(submenu); - append_submenu(submenu); + var submenu = new MenuItem.with_label("3"); + menu.append(submenu); + append_submenu(submenu); submenu.show(); var toggle_item = new MenuItem.with_label("Toggle 3"); -- cgit v1.2.3 From 1b85f7f0fbfa233db1f68792e0496dc6b9d43164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 4 Feb 2011 12:36:25 +0100 Subject: Vala simple client, compile workaround improved. --- example/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'example') diff --git a/example/Makefile.am b/example/Makefile.am index ae9ee94..62347d2 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -41,7 +41,7 @@ VALAFLAGS = \ BUILT_SOURCES = simple-client-vala.c simple-client-vala.c: $(srcdir)/simple-client-vala.vala $(VALAC) $(VALAFLAGS) -C $< -o $@ - $(SED) -i "s|#include\s||g" $@ + $(SED) -i "s|#include\s*<\s*libappindicator/app-indicator.h\s*>||g" $@ simple_client_vala_SOURCES = simple-client-vala.c simple_client_vala_CFLAGS = \ -- cgit v1.2.3 From d22edfa36b360724f433885656a821bcaf7f36cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 4 Feb 2011 12:48:16 +0100 Subject: examples, added scroll-event demo. --- example/simple-client-vala.vala | 5 +++++ example/simple-client.c | 9 +++++++++ 2 files changed, 14 insertions(+) (limited to 'example') diff --git a/example/simple-client-vala.vala b/example/simple-client-vala.vala index 18ece22..61e0c2f 100644 --- a/example/simple-client-vala.vala +++ b/example/simple-client-vala.vala @@ -87,6 +87,11 @@ class SimpleClient { } public void run() { + + ci.scroll_event.connect((delta, direction) => { + print(@"Got scroll event! delta: $delta, direction: $direction\n"); + }); + Timeout.add_seconds(1, () => { percentage = (percentage + 1) % 100; if (can_haz_label) { diff --git a/example/simple-client.c b/example/simple-client.c index ac8360f..1cf06dc 100644 --- a/example/simple-client.c +++ b/example/simple-client.c @@ -97,6 +97,12 @@ image_clicked_cb (GtkWidget *widget, gpointer data) GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU); } +static void +scroll_event_cb (AppIndicator * ci, gint delta, guint direction) +{ + g_print("Got scroll event! delta: %d, direction: %d\n", delta, direction); +} + static void append_submenu (GtkWidget *item) { @@ -162,6 +168,9 @@ main (int argc, char ** argv) app_indicator_set_attention_icon(ci, "indicator-messages-new"); app_indicator_set_label (ci, "1%", "100%"); + g_signal_connect (ci, "scroll-event", + G_CALLBACK (scroll_event_cb), NULL); + g_timeout_add_seconds(1, percent_change, ci); menu = gtk_menu_new (); -- cgit v1.2.3 From d268d2bd9de3cecc3c5cd69a048bc18e0b77b237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sat, 5 Feb 2011 18:30:38 +0100 Subject: examples, vala: check for valac --- example/Makefile.am | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'example') diff --git a/example/Makefile.am b/example/Makefile.am index 62347d2..a3eb906 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -30,6 +30,8 @@ simple_client_LDADD = \ EXTRA_DIST = \ simple-client-test-icon.png +if HAVE_VALAC + ######################################### ## simple-client-vala ######################################### @@ -51,3 +53,5 @@ simple_client_vala_CFLAGS = \ simple_client_vala_LDADD = $(simple_client_LDADD) CLEANFILES += *.stamp *-vala.c + +endif -- cgit v1.2.3 From b4f20fedc3d5e4549567c73e28cb22cff960eb79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sat, 5 Feb 2011 18:31:44 +0100 Subject: example makefile code cleanup --- example/Makefile.am | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'example') diff --git a/example/Makefile.am b/example/Makefile.am index a3eb906..606317c 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -30,11 +30,10 @@ simple_client_LDADD = \ EXTRA_DIST = \ simple-client-test-icon.png -if HAVE_VALAC - ######################################### ## simple-client-vala ######################################### +if HAVE_VALAC VALAFLAGS = \ --pkg appindicator$(VER)-0.1 \ -- cgit v1.2.3