GNOME 3 Application Development Beginner's Guide

By Mohammad Anwari
  • Instant online access to over 7,500+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. Installing GNOME 3 and SDK

About this book

GNOME is a desktop environment and graphical user interface that runs on top of a computer operating system. GNOME 3 provides both modern desktops and development platforms with more than 50 supported languages of the world. Since 1999, it has been evolving into a very nice desktop to use and an interesting platform to develop on.

"GNOME 3 Application Development Beginner's Guide" is about developing GNOME 3 application with Vala and JavaScript programming languages. It guides the reader to build Gtk+, Clutter, and HTML5 applications on the GNOME 3 platform. It covers GNOME 3 specific subsystems such as data access, multimedia, networking, and filesystem. It also covers good software engineering practices such as localization and testing.

This book is full of step-by-step tutorials and ready to run codes. The examples are written in a simple and straightforward way  to make it easier for the reader to get a thorough understanding of the topics.

The book starts with the installation of GNOME 3 and ends with building two exciting projects, a web browser and a Twitter client. The book starts from the basics and gradually talks about more advanced topics.

It then guides the readers in using the development environment starts from Anjuta IDE, Glade, and DevHelp. The essential GNOME 3 subsystems like GStreamer, GLib, GIO, GSettings, Evolutions Data Server, WebKit, and GNOME desktop are then uncovered one by one. Then the internationalization, localization, and unit testing techniques are brought up.

"GNOME 3 Application Development Beginner's Guide" is really a guide that a novice GNOME 3 application developer must not miss.

Publication date:
February 2013
Publisher
Packt
Pages
366
ISBN
9781849519427

 

Chapter 1. Installing GNOME 3 and SDK

GNOME 3 is the latest and greatest version of GNOME since it was released for the first time in 1999. GNOME 3 delivers a breakthrough desktop user experience compared to its previous versions. While providing smooth user interface with fluid animations, it uses a different metaphor of how a modern desktop would work by introducing GNOME Shell as its new user experience (UX). However, the traditional user experience still persists as a fallback whenever the hardware configuration is not supported.

GNOME is known for its simplicity and has been chosen as the default desktop environment in many popular Linux distributions. It is also one of the first free types of software that has user interface guidelines, hence securing itself as usable and user friendly.

During its evolution, the architecture also changed and was extended, making it one of the most advanced freely available desktops in the world. With that, it requires more and more advanced technology to be available in the system to be able to maximize the usage of the hardware and at the same time give users an enjoyable time when using computers.

Before we go any further, a proper installation of GNOME as well as the development environment should be available in our computer. And as a starter, we will talk about the installation in a few popular Linux distributions. Specifically, we will cover these topics in this chapter:

  • Understanding the system requirements

  • The basic GNOME 3 architecture that we will cover in this book

  • Installing GNOME 3 and the SDK on various Linux distributions

So let's get started.

 

System requirements


GNOME 3 provides two sets of User Experience (UX) that target different types of installed hardware—GNOME Shell and GNOME Panel/Fallback. These two UX have different requirements, but they share the basic ones:

  • 800 MHz CPU power (at least 1 GHz for optimal performance)

  • 512 MB of RAM (at least 1 GB for optimal performance)

  • More than 2 GB of available hard drive storage (more, if you want to install more applications)

The GNOME Shell

This is the latest addition in GNOME 3, and provides slick user experience. This UX requires 3D acceleration through an OpenGL-capable video card properly installed in your system. On a safer note, most of the video cards from Intel, ATI, and nvidia brands would work nicely.

However, even though you know that you have a video card that is capable of doing OpenGL, make sure that your video card is really activated with the proper drivers, otherwise the system will not let you use this UX.

Note

You can check whether your video card would work with this UX by checking the h-node page at http://www.h-node.org/videocards/catalogue/en and check whether it has the works with 3D acceleration verdict stated there.

GNOME Panel/Fallback

This is the good old GNOME desktop, which provides a basic and less attractive user experience. The system will fall back into this UX whenever it cannot activate the OpenGL. This UX is similar to the older versions of GNOME, but the user interface is modified a bit so that it will look similar to a state of GNOME Shell user interface. For example, the main UI is totally different but the lock screen is pretty similar in both.

Fortunately, only a few parts of this book will make use of the GNOME Shell UX in great depth, so we can safely work with GNOME Panel/Fallback UX in order to follow this book.

Development requirements

As we are doing software development on top of these requirements, obviously we will need more computing power, RAM, and storage. Fulfilling at least the following requirements would make our development time enjoyable:

  • Multicore 2 GHz CPU

  • 4 GB of RAM

  • 500 GB of hard drive storage, preferably SSD

The good news is that we can easily develop GNOME 3 applications using virtualization. By installing the Linux distributions in virtual machines, we can switch between them and tackle the issues found there so that we can make sure that our applications will be built smoothly in GNOME 3 regardless of the distributions. In case of GNOME Shell, you need to make sure that you have enabled the 3D acceleration option in your favorite virtual machine program.

For example, in VirtualBox, we can go to the Settings dialog of a virtual machine, click on the Display option, and then tick on the Enable 3D Acceleration option. Remember, though, that you will not be able to activate this option if your host machine is not capable of doing 3D acceleration by itself.

 

GNOME 3 desktop architecture


When talking about GNOME 3, usually many people refer only to the GNOME Shell. This is incorrect. GNOME Shell is just a part of the whole GNOME desktop architecture. It can be replaced (as in the case of GNOME Panel/Fallback UX) or even removed.

In fact, GNOME is more than GNOME Shell. It provides the infrastructure of the applications so they can talk to the system, render text nicely, flow the animation, read data, and so on. We need to understand the architecture better before starting any development. This would help us to know which parts need to be installed, too. Let's start with looking at the following simplified GNOME architecture diagram:

As we can see from the diagram, the GNOME Shell, along with the applications, sits on top of the GNOME platform architecture stack. This book covers the platform architecture and will touch on some parts of the upper layer.

Note

The GNOME platform reference can be studied in more depth in the GNOME developer website, http://developer.gnome.org.

The following are the specific components of the GNOME platform that we will cover in this book:

  • Core libraries: These are the lowest interface in the architecture. It includes the following:

    • GObject: This is the object system in GNOME. It is the GNOME's object-oriented programming approach with the C language.

    • GLib: This is a general purpose library that contains the infrastructure used by all the parts in the architecture.

    • GIO: This is a virtual filesystem library that provides access to files, volumes, and drives in an abstracted manner.

  • User interface libraries: This is the toolkit for building graphical applications, and includes:

    • GTK+: Historically named as the GIMP toolkit, this is the default toolkit to build graphical applications in GNOME. It provides a set of widgets and tools.

    • Cairo: This is a library that helps us draw on the canvas. It is mainly used for creating new widgets or extending the existing ones.

    • Pango: This is a library that helps us to do text rendering.

    • ATK: This is the accessibility toolkit. It provides ways to offer a good experience for special users of GNOME that have different needs.

    • Clutter: This is a toolkit that is used for creating applications with rich and fluid animations. This requires OpenGL.

    • WebKit: This is the web toolkit. It provides full-featured engines capable of displaying HTML5 documents.

  • Multimedia libraries: Provides playing and authoring multimedia files, and includes:

    • GStreamer: This is a powerful multimedia library

  • Data storage: Provides libraries of accessing data:

    • Evolution Data Storage (EDS): This contains libebook and libecal , and provides access to the address book and the calendar managed in your Evolution.

We will also use several tools in this book; they are as follows:

  • seed: This is a JavaScript interpreter in the GNOME world. We will use this when we develop our GNOME application scripts. We will have seed automatically installed when installing the GNOME Shell, so we will not see this explicitly later when we do the installation.

  • vala: This is an emerging object-oriented programming language, mainly used for developing GNOME applications.

  • Anjuta: This is an integrated development environment software for GNOME.

  • Glade: This is a graphical application layout designer for GTK+.

  • Gtranslator: This is a tool for translating our application user interface to local languages.

  • Devhelp: This is a reference lookup tool; really handy when developing applications.

Note

Note that the actual package names of these parts are not standardized, so you will find that the package names are slightly different from the preceding list. These will be specifically covered in each section.

 

GNOME and the SDK


We will go through installing GNOME and the Software Development Kit (SDK) in our favorite Linux distribution. A few popular distributions are covered. However, we are not going to talk about installing any of these distributions, so it is expected that we already have it up and running. We just need to install several additional packages to get the GNOME and the SDK.

You can directly go ahead to the section discussing your distribution without bothering to read the other distribution's installation descriptions. And if your distribution is not listed here, no need to be worried, just pick the closest distribution variant and adjust the package names as we will use the search function in the distributions when we are installing. Now let's pull our sleeves up and jump right into the action.

 

Time for action – installing GNOME and SDK in Fedora 17


Fedora 17 uses GNOME 3 by default, so our focus here is to install the SDK. To install packages in Fedora 17, we are going to use the Add/Remove Software tool. This is how we do it:

  1. Click on the Activities button on upper-left corner of the screen.

  2. Click on the Applications button.

  3. Click on the Add/Remove Software button.

  4. The following tool shows up:

What just happened?

The Add/Remove Software tool shows the database of Fedora 17 packages that we can browse and select. The left-hand side of the screen displays a search textbox, and below it we can see the collection packages. The collection package is a group of packages that serve similar functionalities. On the upper-left corner we can see the place where the search results or the contents of a collection will be displayed, and below it we can see the description box of a selected package we choose in the above area.

The SDK comes in the form of so-called development packages. In Fedora, the development packages use -devel as its postfix on their names. The actual libraries are inside the package without the -devel postfix and they are by default installed when the devel packages are installed. For example, GLib is available inside the glib2 package and the supporting development package is available in the glib2-devel package. Whenever the glib2-devel package is installed, the glib2 package is automatically installed.

Note

The development package means that it contains header files and other files needed only when you do development, but not needed when you are only running it.

So let's start finding them.

Marking packages to be installed

Before a package can be installed with this tool, it must be marked for installation. Head on to the search box and type glib2-devel. Click on the Find button and we will see the search results. It should be a couple of lines with one of them showing the glib2-devel string followed by a long version number (glib2-devel-2.32.1-1.fc17, in my case). Tick on the checkbox to its left. We should see that the tool stamps the icon with a big plus sign, meaning that it is marked for installation. If you don't see a checkbox, it is already installed.

The following table provides a mapping between the package names in Fedora 17 and the GNOME components described in the architecture section earlier. We also want to install the documentation packages (the names are inconsistently postfixed with -doc or -docs). We also will install the tools and basic development packages that we are going to use throughout this book. So let's go ahead with marking these packages in the tool by searching and ticking the checkbox.

Subsystem

Package names

Core libraries

glib2-devel (GIO and GObject are already inside this package)

User interface libraries

gtk3-devel

gtk3-devel-docs

cairo-devel

pango-devel

atk-devel

clutter-devel

clutter-doc

webkitgtk3-devel

webkitgtk3-doc

Multimedia libraries

gstreamer-devel

gstreamer-devel-docs

Data storage

evolution-data-server-devel

evolution-data-server-doc

Tools and basic development packages

vala

vala-doc

vala-tools

anjuta

glade (don't mix up with glade3!)

glade-libs

gtranslator

devhelp

Ready to install the packages

After we mark the packages, we are ready to install them. Just click on the Apply button at the bottom of the screen. We will get a dialog popping up and asking whether we want to install additional packages required by the packages we selected previously. Make a nod gesture to agree by clicking on the Continue button. Then enter the root password and relax for a while as the tool will download and install all the packages into the system. After everything is installed, we will get a new window, as shown in the next screenshot, that displays that there are newly installed applications that we can run; let's keep this dialog for the next chapter.

 

Time for action – installing GNOME and SDK in openSUSE 12


openSUSE 12 ships GNOME by default, so we don't need to worry about it and can just concentrate on getting the SDK installed. To manage applications, openSUSE provides the Yet another Setup Tool (YaST) tool. Follow these steps to install the SDK in openSUSE 12:

  1. Click on the Activities button on the upper-left corner of the screen.

  2. Click on the Applications button.

  3. Click on YaST (or type YaST in the text field).

  4. YaST is now opened; to continue, click on the Software Management icon.

  5. After a while taken for contacting the servers and refreshing the package database, it is ready to use. This is how it will appear:

What just happened?

YaST is a collection of system management tools in openSUSE, and Software Manager is one of the tools. As the name suggests, we will use this tool to install the GNOME SDK. As you can see, the tool has two main columns, with each column having two sections each. The left-hand side column shows package categories whereas the right-hand side column shows the content of the selected categories (or the search results) and the description of the package. We will use this tool only by using the search functionality and not touching the categories to the left.

Similar to the Add/Remove Software tool in Fedora, YaST uses a mark-and-install paradigm, meaning we need to mark a software before installing it. With this concept, we can first select the software we want and then make the final move by just pressing a button to get the selections installed. Let's do it.

Marking SDK packages

SDK are scattered in many different development packages. Similar to Fedora, which uses the RPM package management system, the development package names are postfixed with -devel, and the corresponding library will get automatically installed when the development package is installed.

The following table provides a mapping between the openSUSE package names and the GNOME components described in the architecture section earlier. We can go ahead and type these names (one at a time) in the search box and tick a checkbox situated to the left of the search results entry. By ticking this checkbox, it means that the package is put into an installing queue. If you see that the checkbox is already ticked, it means the package is already installed.

Subsystem

Package names

Core libraries

glib2-devel (GIO and GObject are already inside this package)

User interface libraries

gtk3-devel

gtk3-devel-docs

libseed-gtk3-devel

cairo-devel

pango-devel

atk-devel

clutter-devel

libwebkitgtk3-devel

Multimedia libraries

gstreamer-0_10-devel

gstreamer-0_10-doc

gstreamer-0_10-fluendo-mp3

Data storage

evolution-data-server-devel

evolution-data-server-doc

Tools and basic development packages

vala

anjuta

glade (don't mix up with glade3!)

gtranslator

devhelp

Starting the installation

After marking the packages, let's now hit the Apply button to start the installation. Let's wait a while until all the packages are installed; after this, we are good to go to the next chapter.

 

Time for action – installing GNOME and SDK in Debian Testing


Debian Testing (also called Wheezy) uses GNOME 3 as its default desktop, so our focus now is to get the SDK installed. Same as Fedora, Debian Testing uses the Add/Remove Software tool to do the package management. So let's get started by running the tool:

  1. Click on the Activities button on the upper-left corner of the screen.

  2. Click on the Applications button.

  3. Click on the Add/Remove Software button.

  4. The following tool shows up:

What just happened?

The Add/Remove Software tool is a mark-and-install package management tool. It means that before doing any real installation, we are given a chance to select the packages we want to install. The installation is postponed until the time we provide confirmation by pressing the Apply button. With this installation style, we can keep browsing the packages without getting bothered by the installation process.

As you can see in the previous screenshot, the tool has two main columns. The left-hand side column shows the search box and the package categories. The right-hand side column shows the search results (or the category contents), and below it there is a box showing the package description.

Marking SDK packages

The SDK packages come in many development packages. The development packages contain the header and all the supporting files required during compilation and linking. It is not necessary for them to be installed when we just need to run the applications linked to a library.

These packages are named with the lib prefix and the -dev postfix. They have internal dependencies to the actual library needed by the applications; so whenever we install a development package, the package containing the actual library goes with it automatically.

Here is a map of the Debian packages and GNOME components described in the architecture section. Let's type the names of the packages into the search box and mark them for installation.

Subsystem

Package names

Core libraries

libglib2.0-dev 9 (GIO and GObject are already inside this package)

libglib2.0-doc

User interface libraries

libgtk-3-dev

libgtk-3-doc

libcairo2-dev

libcairo2-doc

libpango1.0-dev

libpango1.0-doc

libatk1.0-dev

libatk1.0-doc

libclutter-1.0-dev

libclutter-1.0-doc

libwebkitgtk-3.0-dev

libwebkitgtk-3.0-doc

Multimedia libraries

libgstreamer0.10-dev

Data storage

libecal1.2-dev

Tools and basic development packages

valac-0.16

anjuta

glade

gtranslator

devhelp

Applying the installation

After marking the packages, let's now hit the Apply button to start the installation. Let's sit back and relax. Wait a while until all the packages are installed. After that, we are clear to go to the next chapter.

 

Time for action – installing GNOME and SDK in Ubuntu 12.04


Ubuntu ships with its own desktop, called Unity. Our focus here is to install the GNOME 3 desktop as well as the SDK with the Ubuntu Software Center tool; let's see how this is done:

  1. Click on the Ubuntu Software Center icon on the left-hand side of the screen. The next screenshot shows this tool.

  2. Click within the search box and type gnome-shell.

  3. Click on the Install button of the first search result.

  4. GNOME Shell is installed.

What just happened?

What we have done is install the GNOME Shell desktop. Because the GNOME Panel is also coupled with the GNOME Shell in form of package dependencies specified internally, we will get both the UXs installed.

The Ubuntu Software Center tool doesn't use the mark-and-install paradigm, so we need to do installation on every search result. The installation process is done in the background, but unfortunately we can't search while installing. However, if some other package that we want to install appears on the same result page, we can click on the Install button to queue it in the installation process.

Continue installing the SDK

Ubuntu gets its root from Debian, hence the package naming system is the same. Let's see the mapping of the Ubuntu package names and GNOME components in the Debian section explained earlier. Get all the packages mentioned in the map installed one by one.

After all of the packages are installed, we are ready to go to the next chapter!

 

Summary


We learned a lot in this chapter about system requirements, basic architecture, and installing GNOME and the SDK. Specifically, we learned that GNOME 3 provides two UXs. We understood their system requirements for running as well as for developing on top of them. Also, we learned a small tip for getting it to work in a virtualization environment. We discussed the basic GNOME desktop architecture and the description of each of the components inside it, along with the tools that we are going to use in this book.

We also now know where certain GNOME components sit in the architecture diagram. We also know the tools we are going to use and how they are packaged in popular Linux distributions. We also learned how to install them. The advantage of this is that it will give us insight into how Linux distributions ship the system.

This is a good start for us to learn how to develop applications on top of GNOME 3. The next step is to prepare our development tools. We are going to learn how to use them and touch on a little bit of Vala, one of the programming languages we will use in this book.

About the Author

  • Mohammad Anwari

    Mohammad Anwari is a software hacker from Indonesia with more than 13 years of experience in software development. He has been working with Linux-based systems, applications in GNOME, and Qt platforms. The projects he has worked on range from the development of constrained devices and desktop applications, to high traffic server systems and applications. He worked for his own startup company during the dotcom era before moving to Finland to work for Nokia/MeeGo. Now he's back in Indonesia, regaining his entrepreneurship by establishing a new startup company that focuses on Node.js and Linux-based projects. In his free time, he serves as an executive director for BlankOn, one of the biggest open source projects in Indonesia. In the past, he has published a couple of books on Linux in the Indonesian language.

    Browse publications by this author
Book Title
Access this book, plus 7,500 other titles for FREE
Access now