A tar front end

A tar front end

This tutorial constructs a more complex dialog, that acts as a graphical user interface to the tar command line program.

Setting up the main choice

When using the tar program, there is always a main choice. This choice might be to extract, to append to, to create or perhaps list the contents of an archive. The user must select one of these choices and to allow them to do this we're going to setup some radio buttons inside a button group box.

Create a new dialog by going to File -> New and selecting the form type 'Dialog'. A new dialog should appear in the Editor main window. Start by selecting the Button Group widget from the Kommander toolbar



. A ButtonGroup widget is like a frame for a group of buttons. When a group of RadioButtons are inserted into a ButtonGroup for example, only one radio button may be selected at a time which is the correct functionality in most cases. Click near the top of your empty dialog to insert the Button Group. Change the 'title' property of the Button Group to be 'Main Choice' by selecting the property in the Property Editor window and typing it in.

The next step is to actually insert our buttons. Double click the radio button widget in the Kommander toolbar



so that we can insert multiple radio buttons quickly. Insert eight radio buttons, one below the other so that in the end you have a vertical list of radio buttons. On each of the radio buttons right click and select the menu option “Edit Text” (you can also double click on a radio button which does the same thing). Set their text to the following list.

  1. Append to archive

  2. Create archive

  3. Find differences between archive and file system

  4. Delete from archive

  5. Append to the end of an archive

  6. List contents

  7. Update archive

  8. Extract from archive

Don't be surprised if the text label you set for each widget doesn't show up, it's just because the borders of the widget are cutting it off. Click in some empty space of the button group that the radio buttons are in so that the only widget selected is the Button Group itself. In the Layout toolbar, click the 'Lay Out Horizontally' button; all of the widgets are automatically aligned for us. You may need to resize the dialog and/or the button group to see the effect. What you have so far should look something like the screenshot below. Make sure that all of the radio buttons are in the order presented in the screenshot because we make this assumption for the rest of the tutorial. If you find they they're not, simply click the layout you want to redo and then click the Break Layout button from the Layout toolbar



. Reorganise your widgets into the right order and apply the vertical layout again.



Next we need to set up our text associations for the widgets we have created so far, including the buttons and group box. The widget text of the group box is the evaluated text associations of all of its chlidren, together in the order the widgets were created. The fact that only one widget will ever be selected in our Button Group means the widget text of the Button Group will be the text association of the selected radio button. This is exactly what we want in this case, as it means the text association of the ButtonGroup will effectively be the portion of the the command line to tar that determines the type of action to be taken. We'll see how this works together in '3. Putting it together'.

First set the name property of the ButtonGroup to be 'mainChoice', which you do by setting the value for the name property in the Property Editor window. Next, right click on the ButtonGroup and select the menu option 'Edit Text Associations'; the text association editor dialog pops up. Click the 'Widget Text' button in the Insert frame to the right of the text edit. This inserts the special '@widgetText' and saves us typing it manually. Click OK - text associations are setup for the Button Group.

Now for the text associations of the buttons themselves. We haven't yet configured text associations for widgets with more than one state. A radio button has two states in Kommander - 'checked' and 'unchecked'. If a radio button is unchecked in our dialog, we want its text association to evaluate to nothing so that it does not have an effect in the overall text generation, so we leave all text associations for state 'unchecked' blank. When setting text associations, you select the state by selecting an item from the 'States' combo box at the top of the text associations editor dialog.

Set the text associations for state 'checked' for each of our radio buttons, in the order we created them, to these strings(without quotes).

  1. A

  2. c

  3. d

  4. -delete

  5. r

  6. t

  7. u

  8. X

You would be correct if you recognised these as command line options to the tar program. Below is a screenshot showing the editing of the text association for the first widget. Notice the 'States' combo box is set to state checked, which is the state we want to associate our command line option with. You should have set this combo box to state checked when we set our text associations.



We don't need to set the names of the radio buttons, as we never reference them directly and only access their text associations through the ButtonGroup widget.

Setting up the read options

Options for tar change the way the primary choice behaves, and are in the form of additional command line options to the tar program. The option to tar can be broken into two groups - read and write. You might guess correctly that we will use a GroupBox widget widgets buttons as the GUI elements that represent these options.

Start by creating a ButtonGroup widget - click the ButtonGroup widget in the Kommander toolbar



and click in the empty space of the dialog to insert it. Set the title property of the ButtonGroup widget to 'Read options' in the Property Editor window. Finally, also in the property editor, set the name property of the ButtonGroup widget to be 'readOptions'(without quotes, of course).

We now need to use some buttons to represent the different command line options to the tar program. For example, if the user wants to extract with absolute file names and keep existing files, the -P and -k options must be passed to tar respectively. Notice in this last sentence that we talked about multiple selections; the user needs to able to select any number of the available buttons unlike when we setup the Main Choice ButtonGroup in the previous section, we only gave the user one choice in the form of radio buttons where only a single radio button can be selected inside the ButtonGroup. In this case, we use CheckBox buttons so that the user can select multiple options to suit their needs.

Double click the CheckBox widget in the Kommander toolbar



to allow us to insert multiple widgets consecutively. In the ButtonGroup we already created, insert four check boxes one after the other, so that they approximately form a vertical list of check boxes. Now for each check box, right click and select the menu option “Edit Text” and type the following(without quotes)

  1. Ignore failed read

  2. Keep existing files

  3. Extract all protection information

  4. Absolute path names

Click in some empty space inside the ButtonGroup you inserted the CheckBox widgets into, and then click the “Layout Vertically” in the Layout toolbar. The widgets should be aligned vertically inside the ButtonGroup, and what you have so far should look like the screenshot below.



Make sure that the order of your CheckBox widgets inside the ButtonGroup matches the order in the screenshot, as we assume this for the rest of the tutorial. If they are not, simply click inside some empty space inside the GroupBox. Click the 'Break Layout' button



in the Layout toolbar, rearrange the widgets appropriately, then once again vertically align the widgets by clicking the 'Vertically Align' button in the Layout toolbar [IMAGE layoutvertically.png]

The last thing we need to do for the Read options ButtonGroup is setup our text associations. Right click on the ButtonGroup and select the menu option "Edit Text Associations'. Click the 'Widget Text' button, which inserts the '@widgetText' special into the association. Click OK. For each check box of the four check box widgets inside the group box, edit their text associations, select the state 'checked' from the States combo box, and set the text association to the following(without quotes) -

  1. --ignore-failed-read

  2. -k

  3. -p

  4. -P

These are the corresponding command line options of the widgets to the tar program that control the way tar reads its input.

Setting up the write options

Setting up the write options of the tar program is much the same as the read options, so rather than repeat previous material we outline briefly what needs to be done, and explain more indepth only the abberations from the previous section.

Insert a ButtonGroup preferably to the right of the previous ButtonGroup and under the 'Main Choice' GroupBox, and set its title property to 'Write options' and its name property to 'writeOptions'. Insert four check boxes inside it, and set each of their labels to the following (without quotes) -

  1. Dump files, not just symlinks

  2. Remove files after adding to archive

  3. Verbosely list files proceeded

  4. Compression

For the last option “Compression”, there are actually two types of options - “bzip” and “gzip”. To represent these two sub-options, we are going to have another ButtonGroup with two radiobuttons which acts as a sub-option selector for the compression type.

Start by creating a ButtonGroup widget inside the “Write options” ButtonGroup. You don't need to set its title property to anything, as later we will make the frame of the widget unvisible. However, still sets its name property to be 'compressionType'.

Seeing as the RadioButtons inside the ButtonGroup are going to be sub-options of the “Compression” CheckBox, it makes visual and representational sense for the RadioButtons to be tabbed on the left slightly which we will take care of now. Inside the newly created ButtonGroup insert two RadioButtons, one below the other. Set the first RadioButton's label to “bzip” and the second RadioButton's label to “gzip”. Click the first RadioButton, then hold shift and click the second RadioButton and then click 'Layout Vertically' from the Layout toolbar



. Select the Spacer widget and insert preferably to the left of the RadioButtons' layout choosing “Horizontal” when prompted. Select the Spacer widget, and in the Property Editor window change the “sizeType” property to “Fixed”. Click the ButtonGroup the RadioButtons are in and align horizontally, by clicking the “Layout Horizontally” button in the Layout toolbar


.

The two sub-option RadioButtons are now tabbed, but it still doesn't look quite right. The layouts we made infact have spacing between other widgets, and between other layouts. To alter this, first select the Layout aligning the two RadioButtons vertically. Sucessfully selecting the two RadioButtons looks something like the image below.



While the layout is selected, set the 'layoutSpacing' and 'layoutMargin' properties both to 0. Now select the 'compressionType' ButtonGroup by clicking in some of its empty space, and then set the same properties both to 0. This brings the two RadioButtons closer to the 'Compression' CheckBox, so that they look like a part of it rather than separate. Align all of the buttons by clicking in the 'Write options' ButtonGroup so that it is the only widget selected and then clicking the 'Layout Vertically' Button [IMAGE layoutvertically.png]. Finally, we said we wanted to 'compressionType' ButtonGroup to not have a frame so that it simply looks like the RadioButtons are tabbed inside the “Compression” CheckBox. To do this, select the 'compressionType' ButtonGroup and in the Property Editor window, set the 'lineWidth' property to 0 which doesn't draw the line at all. The result should look something similar to the following -



We are almost finished setting up the “Write options” ButtonGroup, but we have yet to setup text associations. For the CheckBox widgets, set their text associations for state “checked” to the following(without quotes) -

  1. --de-reference

  2. --remove-files

  3. -v

  4. @compressionType

Notice for the 4th CheckBox which is “Compression”, its text association is the ButtonGroup that contains the RadioButtons. In other words, the “Compression” CheckBox's text association will end being the association of the checked RadioButton.

Finally, set the text association for state “checked” of the “bzip” RadioButton to be “-j” and the “gzip” RadioButton to “-z”. These text associations are the command line options to the tar program that specify compression type, one of which will be the text association for the “Compression” CheckBox.

Adding I/O handling widgets

There are two other things that the tar program needs to know; the output archive name and the files you wish to work with, which might be a file/folder name or perhaps even a regular expression.

For the first case, a FileSelector widget that allows the user to select a file to save to will be ideal. First insert a Text Label widget



, then select the FileSelector widget from Kommander toolbar


and insert it under all other widgets currently in the dialog including the label, resizing the dialog if necessary. Right click on the label and select the menu option “Edit Text”. Type in (without quotes) “Archive Name”. Next, make sure the FileSelector is selected and in the Property Editor window set the “name” property to be “@outputName”. Also in the Property Editor set the “selectionType” property to “Save”. This means when the button in the FileSelector is clicked, the user will be presented with a save file dialog. Now edit the FileSelector's text associations and set its text association for state “default”(the only state) to be @widgetText. Remember, this is simply the text inside the LineEdit of the FileSelector.

The second case is even simpler as a LineEdit will be sufficient for getting the files to work with. Again insert a text label, but this time set its text label to (without quotes) “Files”. Then, click the LineEdit widget in the Kommander toolbar



and again insert it below all other widgets in the dialog including the text label you created just before, resizing the dialog if required. Set its text association for state default to “@widgetText”, and set its name property in the Property Editor to “files”.

Final widgets

We have added most of the widgets we need, except for the all important ExecButton and the CloseButton. In this section we will see how the ExecButton references the other widgets in the dialog and therefore initiates the evaluations of text associations. In the text association tree, the ExecButton is the first to evaluate its text association and can therefore be considered as the root node for those familiar with the tree data structure.

Insert a Spacer, followed by an ExecButton, followed by another Spacer, followed by a CloseButton concluded by another Spacer. These should all be horizontal to eachother and below all other widgets in the dialog, although the former is optional as long as you select the widgets in the same order when you align them in the next section.

Set the text association for ExecButton for state “default” to be the following string (without quotes):

tar @mainChoice @readOptions @writeOptions -f @outputName @files

Here we see that the text association for the ExecButton is made up of the text associations of all the other widgets in the dialog, and because of the order we've specified them in the association, the text association will be expanded into a valid command line to the tar program. The ExecButton executes this text and the tar program is run with the options the user selected. All that is left is the final superficial touches. What you should have so far is something like the image below.



Laying out the final dialog

The functionality of the dialog is complete. The only thing left to do is layout the widgets we've created.

We will work from bottom to top. Start by selecting the Spacer, the ExecButon, the second Spacer, the CloseButton, and the last Spacer. Do this by clicking the first Spacer, then Shift+Clicking the other widgets. From the Layout toolbar, select “Layout Horizontally”



to align al the widgets.

Next, click the “Files” text label widget, and then Shift+Click the corresponding LineEdit below it. Click the 'Layout Vertically' button from the Layout toolbar



. Repeat this process for the “Archive Name” text label and the FileSelector widget above.

The next thing we need to align is the two options ButtonGroups side by side. Click the “Read options” ButtonGroup, and then Shift+Click the “Write options” ButtonGroup. Click the “Layout Horizontally” button in the Layout toolbar



to align the two ButtonGroups side by side.

Finally, click in some empty space of the dialog so that no other widgets are selected. Make sure that all of your widgets are roughly in their correct position vertically, then click the “Layout Vertically” button in the Layout toolbar



which aligns all of the widgets vertically in the dialog. Resize the dialog to be the minimum size for the widgets it contains. Save the dialog the way you desire, and you've just finished creating quite a useful dialog frontend to the tar command line program. Try running your dialog with the executor as described in the Executor section of Part II. Below is the final result.



KDE Logo