From 7f49d7c2602ccb2ef01c64067e2abcc6b5715200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 3 Feb 2011 16:22:06 +0100 Subject: Adding vala bindings and example Adding proper support for vala bindings, fixing the include path Now they are built in the bindings subfolder and they include a *.deps file. and I've also added a small example. --- bindings/Makefile.am | 7 +++-- bindings/vala/Makefile.am | 32 +++++++++++++++++++ bindings/vala/examples/Makefile.am | 14 +++++++++ bindings/vala/examples/indicator-example.vala | 45 +++++++++++++++++++++++++++ configure.ac | 9 ++++++ src/AppIndicator-0.1.metadata | 2 ++ src/Makefile.am | 29 +++-------------- 7 files changed, 111 insertions(+), 27 deletions(-) create mode 100644 bindings/vala/Makefile.am create mode 100644 bindings/vala/examples/Makefile.am create mode 100644 bindings/vala/examples/indicator-example.vala diff --git a/bindings/Makefile.am b/bindings/Makefile.am index f74dec5..8e621e4 100644 --- a/bindings/Makefile.am +++ b/bindings/Makefile.am @@ -1,7 +1,10 @@ if USE_GTK3 -SUBDIRS = mono +SUBDIRS = \ + mono \ + vala else SUBDIRS = \ mono \ - python + python \ + vala endif diff --git a/bindings/vala/Makefile.am b/bindings/vala/Makefile.am new file mode 100644 index 0000000..c4627f5 --- /dev/null +++ b/bindings/vala/Makefile.am @@ -0,0 +1,32 @@ +SUBDIRS = . examples + + +######################### +# VAPI Files +######################### + +if HAVE_INTROSPECTION + +if USE_GTK3 +GTKVAPI = gtk+-3.0 +else +GTKVAPI = gtk+-2.0 +endif + +vapidir = $(datadir)/vala/vapi +vapiprefix = appindicator$(VER)-0.1 +vapi_DATA = $(vapiprefix).vapi $(vapiprefix).deps +DEPS = $(GTKVAPI) + +$(vapiprefix).deps: + echo $(DEPS) > $@ + +$(vapiprefix).vapi: $(top_builddir)/src/AppIndicator$(VER)-0.1.gir $(vapiprefix).deps + $(VALA_API_GEN) --library=$(vapiprefix) \ + --pkg $(GTKVAPI) \ + $< + + +CLEANFILES = $(vapi_DATA) + +endif diff --git a/bindings/vala/examples/Makefile.am b/bindings/vala/examples/Makefile.am new file mode 100644 index 0000000..6c3bd3c --- /dev/null +++ b/bindings/vala/examples/Makefile.am @@ -0,0 +1,14 @@ + +TESTS = indicator-example +VALAFILES = indicator-example.vala +CLEANFILES = $(TESTS) *.c +EXTRA_DIST = $(VALAFILES) + +VALAFLAGS = --pkg appindicator-0.1 --vapidir=$(top_builddir)/bindings/vala --save-temps + +if HAVE_VALAC +$(TESTS): $(VALAFILES) Makefile.am + $(VALAC) $(VALAFLAGS) $(srcdir)/$(VALAFILES) + +all: $(TESTS) +endif diff --git a/bindings/vala/examples/indicator-example.vala b/bindings/vala/examples/indicator-example.vala new file mode 100644 index 0000000..908913a --- /dev/null +++ b/bindings/vala/examples/indicator-example.vala @@ -0,0 +1,45 @@ +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); + + indicator.set_status(IndicatorStatus.ACTIVE); + indicator.set_attention_icon("indicator-messages-new"); + + var menu = new Menu(); + var item = new MenuItem.with_label("Foo"); + item.activate.connect(() => { + indicator.set_status(IndicatorStatus.ATTENTION); + }); + item.show(); + menu.append(item); + + + item = new MenuItem.with_label("Bar"); + item.show(); + item.activate.connect(() => { + indicator.set_status(IndicatorStatus.ATTENTION); + }); + menu.append(item); + + indicator.set_menu(menu); + + win.show_all(); + + Gtk.main(); + return 0; + } +} diff --git a/configure.ac b/configure.ac index 6f78786..f689003 100644 --- a/configure.ac +++ b/configure.ac @@ -95,6 +95,13 @@ AM_CONDITIONAL(INTROSPECTION_TEN, [test "x$introspection_ten" = "xyes"]) AC_PATH_PROG([VALA_API_GEN], [vapigen]) +########################### +# Vala Compiler support +########################### + +AM_PROG_VALAC([0.11.0]) +AM_CONDITIONAL(HAVE_VALAC, [test "x$VALAC" != "x"]) + ########################### # Check for Mono support ########################### @@ -205,6 +212,8 @@ bindings/mono/appindicator-sharp-0.1.pc bindings/mono/examples/Makefile bindings/mono/examples/indicator-example bindings/python/Makefile +bindings/vala/Makefile +bindings/vala/examples/Makefile tests/Makefile example/Makefile docs/Makefile diff --git a/src/AppIndicator-0.1.metadata b/src/AppIndicator-0.1.metadata index e4d068e..5790ddb 100644 --- a/src/AppIndicator-0.1.metadata +++ b/src/AppIndicator-0.1.metadata @@ -1 +1,3 @@ AppIndicator name="AppIndicator" +Indicator.priv hidden="1" +IndicatorPrivate hidden="1" diff --git a/src/Makefile.am b/src/Makefile.am index b9ee3e1..b9696c5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,12 +2,10 @@ if USE_GTK3 VER=3 lib_LTLIBRARIES = libappindicator3.la GTKGIR = Gtk-3.0 -GTKVAPI = gtk+-3.0 else VER= lib_LTLIBRARIES = libappindicator.la GTKGIR = Gtk-2.0 -GTKVAPI = gtk+-2.0 endif CLEANFILES = @@ -45,7 +43,8 @@ glib_enum_headers = $(addprefix $(srcdir)/, $(libappindicator_headers)) DISTCLEANFILES += app-indicator-enum-types.c -libappindicatorincludedir=$(includedir)/libappindicator-0.1/libappindicator +libappindicatorincludefolder=libappindicator +libappindicatorincludedir=$(includedir)/libappindicator-0.1/$(libappindicatorincludefolder) libappindicator_headers = \ app-indicator.h @@ -133,13 +132,13 @@ INTROSPECTION_GIRS = if INTROSPECTION_TEN INTROSPECTION_SCANNER_ARGS = \ --add-include-path=$(srcdir) \ - $(addprefix --c-include=src/, $(introspection_sources)) \ + $(addprefix --c-include=$(libappindicatorincludefolder)/, $(libappindicator_headers)) \ --symbol-prefix=app \ --identifier-prefix=App else INTROSPECTION_SCANNER_ARGS = \ --add-include-path=$(srcdir) \ - $(addprefix --c-include=src/, $(introspection_sources)) + $(addprefix --c-include=$(libappindicatorincludefolder)/, $(libappindicator_headers)) endif INTROSPECTION_COMPILER_ARGS = --includedir=$(builddir) @@ -174,23 +173,3 @@ typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib) CLEANFILES += $(gir_DATA) $(typelib_DATA) endif - -######################### -# VAPI Files -######################### - -if HAVE_INTROSPECTION - -vapidir = $(datadir)/vala/vapi -vapi_DATA = AppIndicator$(VER)-0.1.vapi - -AppIndicator$(VER)-0.1.vapi: AppIndicator$(VER)-0.1.gir Makefile.am - $(VALA_API_GEN) --library=AppIndicator$(VER)-0.1 \ - --pkg $(GTKVAPI) \ - --vapidir=$(top_builddir)/src \ - $< - -CLEANFILES += $(vapi_DATA) - -endif - -- cgit v1.2.3 From bcbd870a2f3c304aa81133aa4635ee913c9af779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 3 Feb 2011 17:26:35 +0100 Subject: Vala example: adding copyright message. --- bindings/vala/examples/indicator-example.vala | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bindings/vala/examples/indicator-example.vala b/bindings/vala/examples/indicator-example.vala index 908913a..40226df 100644 --- a/bindings/vala/examples/indicator-example.vala +++ b/bindings/vala/examples/indicator-example.vala @@ -1,3 +1,22 @@ +/* + * Copyright 2009 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 . + * + * Authors: + * Marco Trevisan (TreviƱo) + */ + using Gtk; using AppIndicator; -- cgit v1.2.3 From 99ffe8877703c2d4e7ffe0bacb2a0cc0afd70d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 3 Feb 2011 17:30:27 +0100 Subject: Vala example: indentation fixes --- bindings/vala/examples/indicator-example.vala | 52 +++++++++++++-------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/bindings/vala/examples/indicator-example.vala b/bindings/vala/examples/indicator-example.vala index 40226df..60f62ea 100644 --- a/bindings/vala/examples/indicator-example.vala +++ b/bindings/vala/examples/indicator-example.vala @@ -21,44 +21,44 @@ using Gtk; using AppIndicator; public class IndicatorExample { - public static int main(string[] args) { + 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 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 label = new Label("Hello, world!"); + win.add(label); - var indicator = new Indicator(win.title, "indicator-messages", - IndicatorCategory.APPLICATION_STATUS); + var indicator = new Indicator(win.title, "indicator-messages", + IndicatorCategory.APPLICATION_STATUS); indicator.set_status(IndicatorStatus.ACTIVE); - indicator.set_attention_icon("indicator-messages-new"); + indicator.set_attention_icon("indicator-messages-new"); - var menu = new Menu(); - var item = new MenuItem.with_label("Foo"); - item.activate.connect(() => { - indicator.set_status(IndicatorStatus.ATTENTION); - }); - item.show(); - menu.append(item); + var menu = new Menu(); + var item = new MenuItem.with_label("Foo"); + item.activate.connect(() => { + indicator.set_status(IndicatorStatus.ATTENTION); + }); + item.show(); + menu.append(item); - item = new MenuItem.with_label("Bar"); - item.show(); - item.activate.connect(() => { - indicator.set_status(IndicatorStatus.ATTENTION); - }); - menu.append(item); + item = new MenuItem.with_label("Bar"); + item.show(); + item.activate.connect(() => { + indicator.set_status(IndicatorStatus.ATTENTION); + }); + menu.append(item); - indicator.set_menu(menu); + indicator.set_menu(menu); - win.show_all(); + win.show_all(); Gtk.main(); return 0; - } + } } -- cgit v1.2.3 From 2fea2064d1da2d2653009ba5f553829e67fc0d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 3 Feb 2011 17:59:57 +0100 Subject: Vala example, changed copyright year --- bindings/vala/examples/indicator-example.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/vala/examples/indicator-example.vala b/bindings/vala/examples/indicator-example.vala index 60f62ea..c91dfae 100644 --- a/bindings/vala/examples/indicator-example.vala +++ b/bindings/vala/examples/indicator-example.vala @@ -1,5 +1,5 @@ /* - * Copyright 2009 Canonical Ltd. + * 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 -- cgit v1.2.3 From 3f2a4ba6563e8d5ba35e65710dc70e81214baaf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 3 Feb 2011 18:54:18 +0100 Subject: vala bindings makefile: just use deps file for dependencies --- bindings/vala/Makefile.am | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bindings/vala/Makefile.am b/bindings/vala/Makefile.am index c4627f5..5a923a5 100644 --- a/bindings/vala/Makefile.am +++ b/bindings/vala/Makefile.am @@ -23,8 +23,7 @@ $(vapiprefix).deps: $(vapiprefix).vapi: $(top_builddir)/src/AppIndicator$(VER)-0.1.gir $(vapiprefix).deps $(VALA_API_GEN) --library=$(vapiprefix) \ - --pkg $(GTKVAPI) \ - $< + $< CLEANFILES = $(vapi_DATA) -- cgit v1.2.3 From 692281a6d91151306cc8cac72c22d451c17438a1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 3 Feb 2011 12:37:57 -0600 Subject: Changing the build to be the check instead of running it as we might not be interactive. --- bindings/vala/examples/Makefile.am | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bindings/vala/examples/Makefile.am b/bindings/vala/examples/Makefile.am index 6c3bd3c..32a695b 100644 --- a/bindings/vala/examples/Makefile.am +++ b/bindings/vala/examples/Makefile.am @@ -1,5 +1,4 @@ -TESTS = indicator-example VALAFILES = indicator-example.vala CLEANFILES = $(TESTS) *.c EXTRA_DIST = $(VALAFILES) @@ -7,8 +6,8 @@ EXTRA_DIST = $(VALAFILES) VALAFLAGS = --pkg appindicator-0.1 --vapidir=$(top_builddir)/bindings/vala --save-temps if HAVE_VALAC -$(TESTS): $(VALAFILES) Makefile.am +indicator-example: $(VALAFILES) Makefile.am $(VALAC) $(VALAFLAGS) $(srcdir)/$(VALAFILES) -all: $(TESTS) +check: indicator-example endif -- cgit v1.2.3 From c58fd3faa5fa27bd1500377caa2ae4908798b0fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 4 Feb 2011 01:32:52 +0100 Subject: Include gir metadata file in built_sources Now make distcheck will work ;) --- src/AppIndicator-0.1.metadata | 3 --- src/AppIndicator-0.1.metadata.in | 3 +++ src/AppIndicator3-0.1.metadata.in | 3 +++ src/Makefile.am | 8 +++++++- 4 files changed, 13 insertions(+), 4 deletions(-) delete mode 100644 src/AppIndicator-0.1.metadata create mode 100644 src/AppIndicator-0.1.metadata.in create mode 100644 src/AppIndicator3-0.1.metadata.in diff --git a/src/AppIndicator-0.1.metadata b/src/AppIndicator-0.1.metadata deleted file mode 100644 index 5790ddb..0000000 --- a/src/AppIndicator-0.1.metadata +++ /dev/null @@ -1,3 +0,0 @@ -AppIndicator name="AppIndicator" -Indicator.priv hidden="1" -IndicatorPrivate hidden="1" diff --git a/src/AppIndicator-0.1.metadata.in b/src/AppIndicator-0.1.metadata.in new file mode 100644 index 0000000..5790ddb --- /dev/null +++ b/src/AppIndicator-0.1.metadata.in @@ -0,0 +1,3 @@ +AppIndicator name="AppIndicator" +Indicator.priv hidden="1" +IndicatorPrivate hidden="1" diff --git a/src/AppIndicator3-0.1.metadata.in b/src/AppIndicator3-0.1.metadata.in new file mode 100644 index 0000000..5790ddb --- /dev/null +++ b/src/AppIndicator3-0.1.metadata.in @@ -0,0 +1,3 @@ +AppIndicator name="AppIndicator" +Indicator.priv hidden="1" +IndicatorPrivate hidden="1" diff --git a/src/Makefile.am b/src/Makefile.am index b9696c5..f83a6c4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,7 +14,7 @@ BUILT_SOURCES = EXTRA_DIST = \ appindicator-0.1.pc.in \ appindicator3-0.1.pc.in \ - AppIndicator-0.1.metadata + AppIndicator$(VER)-0.1.metadata.in include $(top_srcdir)/Makefile.am.enum include $(top_srcdir)/Makefile.am.marshal @@ -164,6 +164,12 @@ AppIndicator3_0_1_gir_FILES = $(AppIndicator_0_1_gir_FILES) INTROSPECTION_GIRS += AppIndicator$(VER)-0.1.gir +AppIndicator$(VER)-0.1.metadata: AppIndicator$(VER)-0.1.gir + cp -f $(srcdir)/$@.in $@ + +BUILT_SOURCES += AppIndicator$(VER)-0.1.metadata +CLEANFILES += AppIndicator$(VER)-0.1.metadata + girdir = $(datadir)/gir-1.0 gir_DATA = $(INTROSPECTION_GIRS) -- cgit v1.2.3 From 6cc0ff8c6f108324dd2310569b870b8586930712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 4 Feb 2011 01:33:35 +0100 Subject: Vala bindings: add metadata as build dependencies, support for gtk3 --- bindings/vala/Makefile.am | 9 ++++++--- bindings/vala/examples/indicator-example.vala | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bindings/vala/Makefile.am b/bindings/vala/Makefile.am index 5a923a5..3c17075 100644 --- a/bindings/vala/Makefile.am +++ b/bindings/vala/Makefile.am @@ -1,6 +1,5 @@ SUBDIRS = . examples - ######################### # VAPI Files ######################### @@ -9,8 +8,10 @@ if HAVE_INTROSPECTION if USE_GTK3 GTKVAPI = gtk+-3.0 +VER=3 else GTKVAPI = gtk+-2.0 +VER= endif vapidir = $(datadir)/vala/vapi @@ -21,8 +22,10 @@ DEPS = $(GTKVAPI) $(vapiprefix).deps: echo $(DEPS) > $@ -$(vapiprefix).vapi: $(top_builddir)/src/AppIndicator$(VER)-0.1.gir $(vapiprefix).deps - $(VALA_API_GEN) --library=$(vapiprefix) \ +$(vapiprefix).vapi: $(top_builddir)/src/AppIndicator$(VER)-0.1.gir \ + $(top_builddir)/src/AppIndicator$(VER)-0.1.metadata \ + $(vapiprefix).deps + $(VALA_API_GEN) --library=$(vapiprefix) --girdir=$(srcdir)/src \ $< diff --git a/bindings/vala/examples/indicator-example.vala b/bindings/vala/examples/indicator-example.vala index c91dfae..621c962 100644 --- a/bindings/vala/examples/indicator-example.vala +++ b/bindings/vala/examples/indicator-example.vala @@ -23,7 +23,7 @@ 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); -- cgit v1.2.3 From 32a1bf9cbb537a759c5fd8484c9eb37d5fa17d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 4 Feb 2011 01:48:02 +0100 Subject: Always check if vapigen is available when building VAPI --- bindings/vala/Makefile.am | 6 ++++-- configure.ac | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bindings/vala/Makefile.am b/bindings/vala/Makefile.am index 3c17075..f80b48c 100644 --- a/bindings/vala/Makefile.am +++ b/bindings/vala/Makefile.am @@ -1,11 +1,12 @@ +if HAVE_INTROSPECTION +if HAVE_VAPIGEN + SUBDIRS = . examples ######################### # VAPI Files ######################### -if HAVE_INTROSPECTION - if USE_GTK3 GTKVAPI = gtk+-3.0 VER=3 @@ -32,3 +33,4 @@ $(vapiprefix).vapi: $(top_builddir)/src/AppIndicator$(VER)-0.1.gir \ CLEANFILES = $(vapi_DATA) endif +endif diff --git a/configure.ac b/configure.ac index f689003..758914b 100644 --- a/configure.ac +++ b/configure.ac @@ -94,6 +94,7 @@ AM_CONDITIONAL(INTROSPECTION_TEN, [test "x$introspection_ten" = "xyes"]) ########################### AC_PATH_PROG([VALA_API_GEN], [vapigen]) +AM_CONDITIONAL(HAVE_VAPIGEN, [test "x$VALA_API_GEN" != "x"]) ########################### # Vala Compiler support -- cgit v1.2.3 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 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(-) 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(-) 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(+) 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(+) 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(-) 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 From 43c1ba2998088bb4e5dd74acc8637da2f867831b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Feb 2011 14:07:37 -0600 Subject: Being more specific about the types of the signal --- src/app-indicator.c | 2 ++ src/app-indicator.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app-indicator.c b/src/app-indicator.c index 7bee341..f4e9173 100644 --- a/src/app-indicator.c +++ b/src/app-indicator.c @@ -476,6 +476,8 @@ app_indicator_class_init (AppIndicatorClass *klass) /** AppIndicator::scroll-event: @arg0: The #AppIndicator object + @arg1: How many steps the scroll wheel has taken + @arg2: (type Gdk.ScrollDirection) Which direction the wheel went in Signaled when there is a new icon set for the object. diff --git a/src/app-indicator.h b/src/app-indicator.h index abd6699..2a30b22 100644 --- a/src/app-indicator.h +++ b/src/app-indicator.h @@ -212,7 +212,7 @@ struct _AppIndicatorClass { void (* scroll_event) (AppIndicator * indicator, gint delta, - guint direction, + GdkScrollDirection direction, gpointer user_data); void (*app_indicator_reserved_ats)(void); -- cgit v1.2.3 From 409fc00a5a2f60dad3c1adb62d82c896cdfb2a2a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Feb 2011 14:10:12 -0600 Subject: Ignoring new Vala stuff --- .bzrignore | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.bzrignore b/.bzrignore index e120c11..56f006e 100644 --- a/.bzrignore +++ b/.bzrignore @@ -129,3 +129,10 @@ src/gen-notification-watcher.xml.c src/gen-notification-watcher.xml.h src/libappindicator_la-gen-notification-item.xml.lo src/libappindicator_la-gen-notification-watcher.xml.lo +bindings/vala/appindicator-0.1.deps +bindings/vala/appindicator-0.1.vapi +bindings/vala/examples/indicator-example +bindings/vala/examples/indicator-example.c +example/simple-client-vala +example/simple-client-vala.c +src/AppIndicator-0.1.metadata -- cgit v1.2.3