Data is matched with a specific file or data entry in a DATA_CRITERIA table. The DATA_CRITERIA table entries are sorted in decreasing order from most specific to least specific. For example, /usr/lib/lib* is more specific than /usr/* and would, therefore, appear first. When a request to type a file or data is made, the table is checked in sequence to find the best match using the information provided either from the file or from the data. When an information and entry match is found, DATA_ATTRIBUTES_NAME is used to find the proper DATA_ATTRIBUTES entry.
If you want your application to present data objects (either files or data buffers) to the user in a manner consistent with the desktop, use the DtDts* API to determine how to display the data objects and how to operate on them. For example, your application can determine the icon that represents a data object by calling the DtDtsDataTypeToAttributeValue function for the ICON attribute.
Dt/Dts.h
and Dt/Dt.h
.
Criteria | Description | Typical Usage |
DATA_ATTRIBUTES_NAME |
The name of this type of data. The value is a record_name in the data attributes table. |
POSTSCRIPT |
NAME_PATTERN |
A shell pattern-matching expression describing the file names that could match this data. The default is an empty string, which means to ignore file patterns in matching. | *.ps |
CONTENT |
Three values that are interpreted as the start, type, and value fields of the magic file used by the file utility. See the file (1) man page for more information. The default is an empty field, which means to ignore contents in matching. The following types are examples of what can be matched: string, byte, short, long, and file name. |
0 string !% |
MODE |
A string of zero to four characters that match the mode field of a stat structure. See the stat (2) man page for more information. The first character indicates:
The characters listed below can be either the first or subsequent characters:
For example the |
f&!x |
PATH_PATTERN |
A shell pattern-matching expression describing the absolute path names that could match this data. The default is an empty string, which means to ignore path patterns in matching. | */mysubdir/* |
LINK_NAME |
See dtdtsfile (4) man page. |
|
LINK_PATH |
See dtdtsfile (4) man page. |
Some of the more common attributes of data types, in alphabetical order, are:
Attribute | Description | Typical Usage |
DESCRIPTION |
A human-readable description of this data. If this field is
NULL or is not included in the data attribute record, the
name of the data attribute should be used. |
This is a PostScript page description |
ICON |
The name of the icon to be sued for this data. If this field is
NULL or is not included in the data attribute record, the
standard icon should be used. See dtdtsfile (4) for more
details on icon naming. |
Dtps |
PROPERTIES |
Keywords to indicate properties for this data. Valid values are
invisible and visible . If this field is
NULL or is not included in the data attribute record, the
visible property should be assumed. Use this if you want to
completely hide files from the user. |
invisible |
ACTIONS |
A list of actions that can be performed on this data. The list
refers to names in the action table for actions that are to be presented
of the user for objects of this type. If this field is
NULL or is not included in the data attribute record, no
action is available. |
Open , Print |
NAME_TEMPLATE Field |
A string used to create a new file for data of this type. The string
is passed to sprintf (3) with the file name as the single
argument. The default is empty. Contrast this field with the
NAME_PATTERN field of the data criteria table in that the
template is used to create a specific file, such as %s.c ,
whereas the pattern is used to find files, such as *.c . |
%s.ps |
IS_EXECUTABLE Field |
A string-Boolean value that tells users of this data type that it
can be executed as an application. If IS_EXECUTABLE is set
to true (see DtDtsIsTrue() ) the data is executable. If this field is
NULL , is not included in the data attribute record, or is
not set to true, then the data is considered not executable. |
true |
MOVE_TO_ACTION |
The name of an action to be invoked when an object is moved to the current object. | FILESYSTEM_MOVE |
COPY_TO_ACTION |
The name of an action to be invoked when an object is copied to the current object. | FILESYSTEM_COPY |
LINK_TO_ACTION |
The name of an action to be invoked when an object is linked to the current object. | FILESYSTEM_LINK |
IS_TEXT |
A string-Boolean value that tells users of this data type that it is
suitable for manipulation (viewing or editing) in a text editor or text
widget. The IS_TEXT field is set to true (see
DtDtsIsTrue() ) if the data is textual in nature and if it
should be presented to the user in text form. Criteria for making this
determination include whether data consists of human language, is
generated and maintained manually, is usefully viewable and editable in
a text editor, or contains no (or only minimal) structuring and
formatting information.
If the |
See Table 9-3 for examples. |
MEDIA Field |
The names in the MEDIA name space describe the form of
the data itself. MEDIA names are used as ICCCM selection
targets, named in the MEDIA field of the data-type records,
and used in the type parameter of ToolTalk Media Exchange messages.
The |
POSTSCRIPT |
MIME_TYPE |
MEDIA is the desktop internal, unique name for data
types. However, other external naming authorities have also established
name spaces. Multipurpose Internet Message Extensions (MIME), as
described in the referenced MIME RFC, is one of those external
registries, and is the standard-type name space for the desktop mailer. |
application/ |
X400_TYPE |
X.400 types are similar in structure to the MEDIA type,
but are formatted using different rules and have different naming
authorities. |
1 2 840 113556 3 2 850 |
INSTANCE_ICON Field |
The name of the icon to be used for this instance of data, typically
a value such as %name%.icon [Bug in
dtdtsfile (4) manpage, too]. If INSTANCE_ICON
is set, the application should use it instead of ICON . If
this field is NULL or is not included in the data attribute
record, the ICON field should be used. |
myicondir/%name%.bm |
DATA_HOST |
The DATA_HOST attribute is not a field that can be added
to the data attributes table in the *.dt file, but it may
be returned to an application reading attributes from the table. The
data-typing service adds this attribute automatically to indicate the
host system from which the data type was loaded. If this field is
NULL or is not included in the data attribute record,
the data type was loaded from the local system. |
|
The IS_TEXT field differs from the text attribute of the MIME_TYPE field, which is the MIME content type, as described in the referenced MIME_ RFC. The MIME content type determines whether the data consists of textual characters or byte values. If the data consists of textual characters, and the data is labeled as text/*, the IS_TEXT field determines whether it is appropriate for the data to be presented to users in textual form.
Table 9-3 shows some examples of IS_TEXT usage with different MIME_TYPE attributes.
Description and MIME_TYPE Attribute | IS_TEXT Value |
Human language encoded in ASCII with MIME_TYPE
text/plain |
IS_TEXT true |
Human language encoded in E*UC, JIS, Unicode, or an ISO Latin
charset with MIME_TYPE text/plain ;
charset=XXX |
IS_TEXT true |
CalendarAppointmentAttrs with a MIME_TYPE text/plain |
IS_TEXT false |
Hypertext Markup Language (HTML) with a MIME_TYPE
text/html |
IS_TEXT true |
PostScript with MIME_TYPE application/postscript |
IS_TEXT false |
C program source (C_SRC ) with MIME_TYPE text/plain |
IS_TEXT true |
Bitmaps and pixmaps (XBM and XPM ) with MIME_TYPE text/plain |
IS_TEXT false |
Project or module files for the desktop application building service
with MIME_TYPE text/plain |
IS_TEXT false |
Shell scripts with MIME_TYPE text/plain |
IS_TEXT false |
Encoded text produced by uuencode (1) with MIME_TYPE text/plain |
IS_TEXT false |
*MIME_TYPE text/plain |
IS_TEXT false |
See the dtdtsfile
(4) man page for more information about data-type attributes.
Function | Description |
DtDtsBufferToAttributeList |
Finds the list of data attributes for a given buffer. |
DtDtsBufferToAttributeValue |
Finds the data attribute for a given buffer. |
DtDtsBufferToDataType |
Finds the data-type name for a given buffer. |
DtDtsDataToDataType |
Finds the data type for a given set of data. |
DtDtsDataTypeIsAction |
Returns the resulting saved data type for the directory. |
DtDtsDataTypeNames |
Finds a complete list of available data types. |
DtDtsDataTypeToAttributeList |
Finds the attribute list for a given data attribute name. |
DtDtsDataTypeToAttributeValue |
Finds the attribute value for a given data attribute name. |
DtDtsFileToAttributeList |
Finds the list of data attributes for a given file. |
DtDtsFileToAttributeValue |
Finds the data attribute value for a given file. |
DtDtsFileToDataType |
Finds the data type for a given file. |
DtDtsFindAttribute |
Finds the list of data types where attribute name
matches value . |
DtDtsFreeAttributeList |
Frees the memory of the given attribute list. |
DtDtsFreeAttributeValue |
Frees the memory of the given attribute value. |
DtDtsFreeDataType |
Frees the application memory for a given data-type name. |
DtDtsFreeDataTypeNames |
Releases memory created with the DtDtsDataTypeNames or
DtDtsFindAttribute call. |
DtDtsIsTrue |
A convenience function that converts a string to a Boolean. |
DtDtsRelease |
Unloads the data-typing database information, generally in preparation for a reload. |
DtDtsSetDataType |
Sets the data type for the specified directory. |
DtsLoadDataTypes |
Initializes and loads the database fields for the data-typing
functions. Use instead of DtDbLoad when you do not need to
use actions or action types and you need extra performance. Use
DtDbLoad when you need to use actions.
|
You can type data and retrieve attributes in one of three ways: simple, intermediate, or advanced.
Using the intermediate data-typing functions is the recommended way to type data and retrieve attributes. These functions call the advanced data-typing functions and make the same assumptions about buffers as the simpler data typing.
DtDtsDataToDataType
To type a read-only buffer, a stat structure should be passed that has the st_mode field set to S_IFREG | S_IROTH | S_IRGRP | S_IRUSR.
When a user drags an object to a drop zone, your application determines which gesture (that is, which drag operation) was used to make the drop. Based on the drag operation and the drop zone's data type, the application retrieves a drop attribute from the data-typing database. It then calls DtActionInvoke, using the following two rules to determine its parameters:
See /usr/dt/appconfig/types/C/dtfile.dt for an example of how to define the MOVE_TO_ACTION, COPY_TO_ACTION, and LINK_TO_ACTION attributes. See Chapter 5, "Integrating with Drag and Drop," for information about how to use drag and drop.
datatyping file1 [file2 ...]
#include <Xm/Form.h> #include <Xm/Text.h> #include <Dt/Dts.h>
#define ApplicationClass "DtDatatyping"
static Widget text;
static void DisplayTypeInfo(int, char**);
int main(int argc, char **argv) { XtAppContext appContext; Widget toplevel, form; Arg args[20]; int n;
toplevel = XtAppInitialize(&appContext, ApplicationClass, NULL, 0, argc, argv, NULL, NULL, 0);
if (argc == 1) { printf("%s: No files specified.\n", argv[0]); exit(1); }
form = XmCreateForm(toplevel, "form", NULL, 0); XtManageChild(form); n = 0; XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++; XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++; XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; XtSetArg(args[n], XmNeditable, False); n++; XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++; XtSetArg(args[n], XmNrows, 25); n++; XtSetArg(args[n], XmNcolumns, 90); n++; text = XmCreateScrolledText(form, "text", args, n); XtManageChild(text);
XtRealizeWidget(toplevel);
if (DtAppInitialize(appContext, XtDisplay(toplevel), toplevel, argv[0], ApplicationClass) == False) { printf("%s: Couldn't initialize Dt\n", argv[0]); exit(1);
}
DtDbLoad(); DisplayTypeInfo(argc, argv); XtAppMainLoop(appContext);
}
static void DisplayTypeInfo(int argc, char **argv) { char *file; char *datatype; char *icon; char *actions; char str[100]; int i;
sprintf(str, "%-30s\t%-10s\t%-8s\t%-20s\n", "File", "DataType", "Icon", "Actions"); XmTextInsert(text, XmTextGetLastPosition(text), str);
sprintf(str, "%-30s\t%-10s\t%-8s\t%-20s\n", "-------------------", "--------", "----", "-------"); XmTextInsert(text, XmTextGetLastPosition(text), str);
for(i=1; i < argc; i++) { char *file = argv[i];
/* find out the Dts data type */ datatype = DtDtsFileToDataType(file);
if(datatype) { /* find the icon attribute for the data type */ icon = DtDtsDataTypeToAttributeValue(datatype, DtDTS_DA_ICON, file); }
/* Directly find the action attribute for a file */ actions = DtDtsFileToAttributeValue(file, DtDTS_DA_ACTION_LIST);
sprintf(str, "%-30s\t%-10s\t%-8s\t%s\n", file, datatype?datatype:"unknown", icon?icon:"unknown", actions?actions:"unknown"); XmTextInsert(text, XmTextGetLastPosition(text), str);
/* Free the space allocated by Dts */
DtDtsFreeAttributeValue(icon); DtDtsFreeAttributeValue(actions); DtDtsFreeDataType(datatype); } }