Deploying the Application

only for RuBoard - do not distribute or recompile

Deploying the Application

This section covers several methods of integrating custom applications with the user s desktop; a very simple method of getting the application onto the user s desktop workspace has already been covered (in the last part of Chapter 6, Order Entry Abstract and Design). That method will not be covered here, but you might want to review it if you haven t already. The methods covered here will focus on the Linux version of the ubiquitous Start Bar, specifically the GNOME Start Bar.

As you read this section, keep in mind that all this takes place on Red Hat version 6.2 with the GNOME desktop selected as the default. (At the time this is being written, that is the leading distribution and its default setup. So it is assumed that will also be true for the largest number of readers. Sorry, but there just isn t time or space to cover all the combinations and permutations .) By the time this gets into your hands, you may have a different distribution and desktop; if so, you re on your own to figure out its menuing system.

Manually Setting Up the GNOME Start Bar

The following steps walk you through putting an entry in the GNOME Start Menu.

  1. Open the GNOME Menu Editor application. Look in Start Settings. Figure 10.1 shows where to find it, along with a running instance.

    Figure 10.1. The GNOME Menu Editor: where to find it and what it looks like.
    graphics/10fig01.gif

    As you can see, the choices in the left pane of the GNOME Menu Editor window mirror those available on the GNOME Start Bar, from the lower-left corner of the screen.

  2. Create a subdirectory and call it In House Applications. In the Menu Editor, select System Menus and then New Submenu. For the Name and Comment, enter In House Applications. Change the icon to whatever you would like and click the Save button. Figure 10.2 shows the Menu Editor after this operation. Notice the statusbar at the bottom of the screen: It says /usr/share/gnome/ apps/In House Applications. This is the directory tree from which the GNOME Start Bar structure is taken.

    Figure 10.2. The Menu Editor after a new submenu is added.
    graphics/10fig02.gif
  1. To create the menu item that will launch the application, select In House Applications from the left pane of the GNOME Menu Editor, and then click the New Item button, which should give you an item called untitled. In the Name entry widget on the right side of the GNOME Menu Editor as well as the Comment field, enter Worldwide Commissions. Set the Command entry widget to /usr/local/bin/WCA. Change the icon if you like. Then click the Save button. Figure 10.3 shows the resulting GNOME Menu Editor screen.

    Figure 10.3. The Menu Editor after a new item is added.
    graphics/10fig03.gif
  2. Copy the compiled executable (in this instance, called WCA ) to the /usr/local/bin directory.

  3. From the GNOME Start Bar, select In House Applications and then select Worldwide Commissions. Figure 10.4 shows the GNOME Start Bar menu and the WCA in action.

    Figure 10.4. The application works (not running from a terminal window). WCA has been launched from the GNOME Start Bar.
    graphics/10fig04.gif

Now examine what the Menu Editor did. First, of course, it created a subdirectory called In House Applications. Second, it created a file called Worldwide Commissions.desktop that tells the operating system what to do when the user selects the item. Going to the /usr/share/gnome/apps/ directory, you will find the In House Applications directory. In that directory, you find the Worldwide Commissions.desktop file. Listing 10.3 shows the contents of the file.

Listing 10.3 Worldwide Commissions.desktop File Contents
 [Desktop Entry]  Name[en_US.ISO8859-1]=Worldwide Commissions  Comment[en_US.ISO8859-1]=Worldwide Commissions  Exec=/usr/local/bin/WCA  Icon=/usr/share/pixmaps/gnome-lockscreen.png  Terminal=false  MultipleArgs=false  Type=Application 

The file is self-explanatory. Next , return to the GNOME Menu Editor and select the Worldwide Commissions menu item. Note that there is a check box for running the application from a terminal window; it is labeled Run in Terminal. Click it, click Save, close the GNOME Menu Editor, and then rerun the Worldwide Commissions Application. Figure 10.5 shows the result.

Figure 10.5. The Worldwide Commissions Application with an attendant terminal window. Compare this figure with Figure 10.4
graphics/10fig05.gif

In the case of this application, it makes sense to have a terminal window running with the application because of the overuse of g_print() statements. My personal opinion is that this is a reasonably good method of communicating with the user, and it doesn t require the user to respond by clicking OK buttons in message boxes (when the user can t do anything about the message anyway). This has to be a design consideration because it is a possible method of communicating with the user, and (IMHO) it is a better option than the typical message boxes that pop up when something goes wrong. If you open the Worldwide Commissions.desktop file, you will find that the line that previously read Terminal=false now reads Terminal=true .

That is all it takes to integrate your own applications into the GNOME Desktop. Obviously, if you have a large number of installed users, going to each user s desk and performing these steps could get to be a hassle after a while. So the next obvious step is to write a shell script that will do it for you. Then all you have to do is provide the users with the shell script (for instance by email) and tell them how to run it. This shell script will be covered in the next section.

Using a Shell Script to Set Up the GNOME Start Bar

This section contains a small shell script that will set up the user s machine with the right files in the right places. This text makes the assumption that the system administrator has gathered the necessary files and somehow sent them to the user. You could provide those files as an email attachment or perhaps by sending the user a floppy. Of course, you would then have to assume that the user knows how to save files from email to a specific place in the directory structure, or how to mount a floppy, and so on. The shell script uses the default shell for Linux: bash. If you are running a different shell, you will need to make changes appropriate to your environment.

Listing 10.4 is the sample shell script. There could, of course, be more to this file. It could assume the files were either on a floppy or on a server that all the workstations have similarly mounted. (Of course, if you re going to do that, you could just as easily keep the executable on the server and only push the menu item file down to the desktop.) Also, it assumes that the .png file (the icon) is on the user s machine. Obviously, if the icon isn t on a particular user s machine, it would need to be included and moved to the location specified in Listing 10.3

Listing 10.4 Shell Script for Installing the Worldwide Commissions Application
 # This file is a shell script for moving the Worldwide  # Commissions Application into place on a user's machine.  # This file makes the following assumptions:  #    1. This shell script is being called from the same  #       directory where the application files have been stored.  # 2. The user has placed the following files here:  #          WCA  #          Worldwide Commissions.desktop  # First, create the necessary directories.  mkdir "/usr/share/gnome/apps/In House Applications/"  # Next, copy the target files into place.  cp "Worldwide Commissions.desktop" "/usr/share/gnome/apps/In House Applications"  cp WCA /usr/local/bin  # Now set the permissions.  chmod 755 /usr/local/bin/WCA  echo Finished. 

Adding the Install Target to Makefile

At this point, the Makefile you looked at in the previous section needs to be updated just a bit in preparation for RPM (as will become obvious in the next section). Specifically, Makefile needs to have an install target added to it. This lists the actions necessary to install the software to the user s machine, according to the shell script you just created (Listing 10.4).

Listing 10.5 Changes to Makefile to Add an Install Target
 # Makefile for the Worldwide Commissions Application.  # Chapters 8, 9, and 10.  INCLUDES = -I/usr/include/mysql  LIBS = -L/usr/include/mysql -L/usr/lib/mysql -lmysqlclient -lz  GTK-CONFIG = `gtk-config --cflags --libs`  WCA : main.o interface.o support.o callbacks.o comm_utils.o ddc.o        gcc -o WCA *.o $(GTK-CONFIG) $(INCLUDES) $(LIBS)  main.o : main.c        gcc -c main.c $(GTK-CONFIG)  interface.o : interface.c        gcc -c interface.c $(GTK-CONFIG)  support.o : support.c        gcc -c support.c $(GTK-CONFIG)  callbacks.o : callbacks.c        gcc -c callbacks.c $(GTK-CONFIG)  comm_utils.o : comm_utils.c        gcc -c comm_utils.c $(GTK-CONFIG) $(INCLUDES)  ddc.o : ddc.c        gcc -c ddc.c $(GTK-CONFIG) $(INCLUDES)  clean::        rm -f $(PROG).o $(PROG)  EXE_LOCATION = /usr/local/bin/  MENU_LOCATION = "/usr/share/gnome/apps/In House Applications/"  # In the commands below...  #     The  -p  after  mkdir  tells  mkdir  not to return an error if the  #            directory already exists.  #     The  -f  after  cp  tells  cp  to overwrite an existing file of  #            the same name in the target location if the file  #            already exists.  install : WCA        echo $(MENU_LOCATION)        mkdir -p $(MENU_LOCATION)        cp -f "Worldwide Commissions.desktop" $(MENU_LOCATION)        cp -f WCA $(EXE_LOCATION)WCA        chmod 755 $(EXE_LOCATION)WCA        echo Worldwide Commissions Application Installed. 

As you can see, the last third of the file is new; a couple of new macro variables were added, but it was essentially the same as Listing 10.4 after the install : WCA line. That line tells make that the install target is dependent on WCA, and that if it is up to date, to execute the following commands to install the software.

The normal way to use Makefile is for the user to type

 % make 

at the command line, followed by

 % make install 

These commands build and install the software; makeinstall tells the make to go directly to the install target.

Creating an RPM File

Red Hat Package Manager (RPM) is the best and closest thing the Linux community has to an installer. Refer to Chapter 1, MySQL for Access and SQL Server Developers and DBAs, for a brief overview of RPM.

This section covers the creation of a very simple spec file, which is used with the rpm command to build a *.rpm file. The rpm file provides a quick and easy way for a user to get an application installed or upgraded on his or her machine. I want to add here that Maximum RPM by Edward C. Bailey (RedHat Press/SAMS Publishing, 1997) was absolutely fundamental to completing this section. It is the only work I know of on the topic. Note that it is available online at http://rpmdp.org/rpmbook/. Other RPM information can be found at http://rpm.redhat.com/RPM-HOWTO/.

Listing 10.6 is the file that was used to create the RPM file for the WCA.

Listing 10.6 WCA_comm.spec: The spec File that rpm Uses to Build a *.rpm File
 # The spec file for building the rpm to distribute the  # Worldwide Commissions Application built in Chapters  # 8 and 9.  # The Preamble Section  Summary: Worldwide Commissions Applications  Name: WCA  Version: 0.1  Release: 1  Copyright: Proprietary  Group: Applications/Databases  Packager: Matt Stucky <stuckym@prodigy.net>  %description  In house application for computing Worldwide Commissions  each month.  # Preparation Section   %prep  # Clean out the rpm build and source directories in preparation for  # the build.  rm -rf $RPM_BUILD_DIR/*  rm -rf $RPM_SOURCE_DIR/*  # Copy the source files to the rpm BUILD and SOURCES directory.  cp /mnt/DOS_hda2/newriders/book/ch09/src/Makefile  /usr/src/redhat/SOURCES/Makefile  cp /mnt/DOS_hda2/newriders/book/ch09/src/*.c       /usr/src/redhat/SOURCES/  cp /mnt/DOS_hda2/newriders/book/ch09/src/*.h       /usr/src/redhat/SOURCES/  cp /mnt/DOS_hda2/newriders/book/ch09/src/*.desktop /usr/src/redhat/SOURCES/  cp /mnt/DOS_hda2/newriders/book/ch09/src/Makefile  /usr/src/redhat/BUILD/Makefile  cp /mnt/DOS_hda2/newriders/book/ch09/src/*.c       /usr/src/redhat/BUILD/  cp /mnt/DOS_hda2/newriders/book/ch09/src/*.h       /usr/src/redhat/BUILD/  cp /mnt/DOS_hda2/newriders/book/ch09/src/*.desktop /usr/src/redhat/BUILD/  # These next two sections are simple if you have already created the  #  make  file with a  make install  included.  %build  make  %install  make install  # Finally, here's a list of the files needed for the application to install.  %files  /usr/local/bin/WCA  "/usr/share/gnome/apps/In House Applications/Worldwide Commissions.desktop" 

To build the rpm file, type this at the command prompt:

 % rpm -ba WCA_comm.spec 

This will force a rebuild (the -b option) of all files (the a after the -b ) and will output two files: WCA-0.1-1.i386.rpm and WCA-0.1-1.src.rpm. The first is the install of the compiled application (the WCA executable), and the second is the Worldwide Commissions.desktop file, along with instructions as to how install the application. Listing 10.7 is the output of the rpm build command.

Listing 10.7 The Output of rpm During the WCA Build Process
 Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp. 78223Executing( %build): /bin/sh -e /var/tmp/rpm-tmp.85210  gcc -c main.c `gtk-config --cflags --libs`  gcc -c interface.c `gtk-config --cflags --libs`  gcc -c support.c `gtk-config --cflags --libs`  gcc -c callbacks.c `gtk-config --cflags --libs`  gcc -c comm_utils.c `gtk-config --cflags --libs` -I/usr/include/mysql  gcc -c ddc.c `gtk-config --cflags --libs` -I/usr/include/mysql  gcc -o WCA *.o `gtk-config --cflags --libs` -I/usr/include/mysql - L/usr/include/mysql -L/usr/lib/mysql -lmysqlclient -lz  Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.51916  echo "/usr/share/gnome/apps/In House Applications/"  /usr/share/gnome/apps/In House Applications/  mkdir -p "/usr/share/gnome/apps/In House Applications/"  cp -f "Worldwide Commissions.desktop" "/usr/share/gnome/apps/In House  Applications/"  cp -f WCA /usr/local/bin/WCA  chmod 755 /usr/local/bin/WCA  echo Worldwide Commissions Application Installed.  Worldwide Commissions Application Installed.  Processing files: WCA-0.1-1  Finding Provides: (using /usr/lib/rpm/find-provides)...  Finding Requires: (using /usr/lib/rpm/find-requires)...  Requires: ld-linux.so.2 libX11.so.6 libXext.so.6 libXi.so.6 libc.so.6 libdl.so.2  libgdk-1.2.so.0 libglib-1.2.so.0 libgmodule-1.2.so.0 libgtk-1.2.so.0 libm.so.6  libz.so.1 libc.so.6(GLIBC_2.0) libc.so.6(GLIBC_2.1)  Wrote: /usr/src/redhat/SRPMS/WCA-0.1-1.src.rpm  Wrote: /usr/src/redhat/RPMS/i386/WCA-0.1-1.i386.rpm 

If you have followed the make and makeinstall portions of this chapter to this point, most of this should be self-explanatory. The only thing I am going to point out quickly is the line that is third from the bottom ”the line that begins with Requires:. The last two lines show the packages that were output. This tells you which packages must be installed on the user s machine.

Figure 10.6 shows the package installed under KDE. Figure 10.7 shows the installed application from the KDE RPM manager. Figure 10.8 shows the application running on a client machine under KDE, and Figure 10.9 shows the application running on a client GNOME desktop.

Figure 10.6. Installing the package under KDE.
graphics/10fig06.gif
Figure 10.7. The installed package from the RPM manager ”in the Applications/Databases category.
graphics/10fig07.gif
Figure 10.8. The application running on a KDE. Notice the funky window manager.
graphics/10fig08.gif
Figure 10.9. WCA running on a GNOME desktop client.
graphics/10fig09.gif

A Quick Tour of the RPM Spec File

In order for RPM to build an *.rpm file, it must have a spec file to build from. Listing 10.6 is the spec file for this application ”and a very simple one at that. RPM is a topic by itself, and an in-depth discussion is far beyond the scope of this book. The following sections give a quick description of the various sections of an RPM file and the possibilities of each.

An RPM spec file can be divided into eight sections:

  • the preamble

  • prep

  • build

  • install

  • scripts

  • verify

  • clean

  • files

The preamble section describes the package and provides information about the package. In Listing 10.6, this is the entire section before %prep . The Group: line tells RPM what category the application in question should fall into; this is the categorization RPM keeps for itself, not a directory tree or other external path .

The prep section is used to prepare for the build. In other cases, this would be the place to unpack the sources if they had been sent to you in a tar ball (a *.tar or *.tar.gz file). In this case, it is the place where you clean out the build directories and copy the source files to /usr/source/redhat/.

The %build section (in Listing 10.6) is very simple because of the previous work in building a make file for this application. In this case, it consists of a shell script (make, which uses Makefile ), but it could also be more complex if the situation required.

The %install section is equally easy, again because of the previous work to create an install target in Makefile . Without this, the package author would need to put the necessary commands in this section in order to perform the install.

The scripts, verify, and clean sections are not present in Listing 10.6. If needed, shell scripts to be run before and/or after an install and/or uninstall can be included (in the scripts section), a verify script can be used to verify a working package beyond the capabilities of RPM, and the clean section can perform any necessary cleanup actions.

Last is the file list to be included in the binary rpm (the *86.rpm file). In this case, only two files are necessary: the executable and the shortcut or *.desktop file. Both point to the installed location on the development machine, but because those files also exist in the development subdirectory, they could have also pointed to that path.

Building a simple *.rpm file is not terribly difficult; for example, I found out in this example that the Copyright: line is required, even though I doubt that Proprietary is a recognized copyright value.

only for RuBoard - do not distribute or recompile


MySQL Building User Interfaces
MySQL: Building User Interfaces (Landmark)
ISBN: 073571049X
EAN: 2147483647
Year: 2001
Pages: 119

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net