Mer/Documentation/Vala control panel
Mer is back : Please visit http://www.merproject.org to learn more about this news. |
Mer needs new control panels. But not everyone knows C, but they may be proficient in C#. Vala is a language with C#-like syntax, that compiles to C, which makes it perfect for writing CPAs which are (to my knowledge) C only. But, documentation on Vala is rather lacking.
An example can be found here:
/* * cpa.vala * * Copyright 2009 Faheem Pervez <qwerty12> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ using Osso; using Hildon; using Gtk; public Hildon.Program program; public Gtk.Widget dialog; Status execute(Context *osso, void* data, bool user_activated) { osso = new Osso.Context("vala-test-applet", "0.1", false, null); program = Hildon.Program.get_instance(); data = new Hildon.Window(); program.add_window((Hildon.Window)data); dialog = new Hildon.Note.information ((Hildon.Window)data, "Hey, I'ma CPA written in Vala.\n"+"The \"programmer\" who wrote me sucks; but he hopes \nthat this can be used for something."); ((Gtk.Window)dialog).set_modal(true); ((Gtk.Window)dialog).set_position(WindowPosition.CENTER_ALWAYS); ((Gtk.Dialog)dialog).run(); dialog.destroy(); delete osso; return Status.OK; } //valac -C --pkg libosso --pkg hildon-1 cpa.vala ; gcc `pkg-config --cflags libosso hildon-1` -fPIC -c cpa.c ; gcc -module -avoid-version -shared -Wl,-soname,cpa.so -o cpa.so cpa.o -lc
Save the above as "cpa.vala". Because valac seems to be more accustomed for making programs, you have to use valac's -C option which'll output the generated C code and gcc can then be used to make it into a library.
Improvements very much welcomed.
- This page was last modified on 9 March 2011, at 13:50.
- This page has been accessed 10,405 times.