Writing Gnome applets - setting up an eclipse environment

niedziela, 21 marca 2010 by Michał Jezierski
A few steps to create your own Gnome Applet.


Install Eclipse C/C++ IDE

You can download it from http://www.eclipse.org/downloads/.

Install libraries

sudo aptitude install libpanel-applet2-dev
sudo aptitude install libgtk2.0-dev

Create project

Run Eclipse. Create new C++ Project and call it "ExampleApplet". Copy and paste this code
#include <string.h>
#include <panel-2.0/panel-applet.h>
#include <gtk-2.0/gtk/gtklabel.h>
static gboolean myexample_applet_fill (PanelApplet *applet, const gchar *iid, gpointer data)
{
 GtkWidget *label;

 if (strcmp (iid, "OAFIID:ExampleApplet") != 0)
  return FALSE;

 label = gtk_label_new ("Hello World");
 gtk_container_add (GTK_CONTAINER (applet), label);

 gtk_widget_show_all (GTK_WIDGET (applet));

 return TRUE;
}

PANEL_APPLET_BONOBO_FACTORY ("OAFIID:ExampleApplet_Factory",PANEL_TYPE_APPLET,"The Hello World Applet","0",myexample_applet_fill,NULL);
into your ExampleApplet.cpp file.

Bonobo server file

Next to ExampleApplet.cpp create bonobo server file GNOME_HelloWorldApplet.server and fill it with below text



        
                
                
        
        
        




        
                
                
                
        
        
        
        
        


Build your applet

If you try to build your applet, you probably get an error like this
**** Build of configuration Debug for project hw ****

make all 
Building file: ../src/hw.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/hw.d" -MT"src/hw.d" -o"src/hw.o" "../src/hw.cpp"
In file included from ../src/hw.cpp:3:
/usr/include/panel-2.0/panel-applet.h:39: error: expected constructor, destructor, or type conversion before ‘typedef’
/usr/include/panel-2.0/panel-applet.h:71: error: typedef ‘gboolean’ is initialized (use __typeof__ instead)
/usr/include/panel-2.0/panel-applet.h:71: error: ‘PanelAppletFactoryCallback’ was not declared in this scope
/usr/include/panel-2.0/panel-applet.h:76: error: ‘GtkEventBox’ does not name a type
/usr/include/panel-2.0/panel-applet.h:82: error: ‘GtkEventBoxClass’ does not name a type
/usr/include/panel-2.0/panel-applet.h:85: error: ‘PanelAppletOrient’ has not been declared
/usr/include/panel-2.0/panel-applet.h:88: error: ‘guint’ has not been declared
/usr/include/panel-2.0/panel-applet.h:92: error: ‘GdkColor’ has not been declared
/usr/include/panel-2.0/panel-applet.h:93: error: ‘GdkPixmap’ has not been declared
/usr/include/panel-2.0/panel-applet.h:95: error: ‘GtkDirectionType’ has not been declared
/usr/include/panel-2.0/panel-applet.h:98: error: ‘GType’ does not name a type
/usr/include/panel-2.0/panel-applet.h:100: error: expected constructor, destructor, or type conversion before ‘*’ token
/usr/include/panel-2.0/panel-applet.h:102: error: ‘PanelAppletOrient’ does not name a type
/usr/include/panel-2.0/panel-applet.h:104: error: ‘guint’ does not name a type
/usr/include/panel-2.0/panel-applet.h:109: error: ‘GdkColor’ has not been declared
/usr/include/panel-2.0/panel-applet.h:110: error: ‘GdkPixmap’ has not been declared
...
Right click on project. Select Properties | C/C++ Build | Settings. Click on GCC C++ Compiler and add `pkg-config --cflags --libs libpanelapplet-2.0` after g++ command. Do the same for GCC C++ Linker. Now you can build your project.

Place files in right location

GNOME_HelloWorldApplet.server should be placed in /usr/lib/bonobo/servers/ directory, so lets create symbolic link
sudo ln -s /home/msn0/workspace/hw/src/GNOME_HelloWorldApplet.server /usr/lib/bonobo/servers/GNOME_HelloWorldApplet.server
(Remember to replace msn0 with your user name).

Our executable ExampleApplet should be placed in /usr/lib/gnome-panel/ so
sudo ln -s /home/msn0/workspace/ExampleApplet/Debug/ExampleApplet /usr/lib/gnome-panel/ExampleApplet

Our applet is represented by myicon.png file. Choose one and copy to /usr/share/pixmaps/

Run applet

Right-click on panel, click "Add to panel" and select "Example Applet" from the list.
Posted in | 0 Comments »

Brak komentarzy:

Prześlij komentarz