summaryrefslogtreecommitdiffstats
path: root/kdejava/koala/org/kde/koala/KFilePlugin.java
blob: b904fa3830c3b013dc5e98670fedf1f8f58ce369 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//Auto-generated by kalyptus. DO NOT EDIT.
package org.kde.koala;

import org.kde.qt.Qt;
import org.kde.qt.TQMetaObject;
import org.kde.qt.QtSupport;
import org.kde.qt.TQObject;
import org.kde.qt.TQValidator;
import org.kde.qt.TQObject;

/**

 @brief Base class for a meta information plugin
 Meta information plugins are used to extract useful information from files
 of a given type. These plugins are used in Konqueror's file properties
 dialog, for example.
 If you want to write your own plugin, you need to derive from this class.
 In the constructor of your class, you need to call addMimeTypeInfo() to tell
 the KFile framework which mimetype(s) your plugin supports. For each
 mimetype, use the addGroupInfo() and addItemInfo() methods to declare the
 meta information items the plugin calculates and to group them accordingly.
 For groups, use setAttributes() to customize your group (see
 KFileMimeTypeInfo.Attributes). For items, use setAttributes() to define the
 behaviour of the item; use setHint() to define the meaning of the item; use
 setUnit() to define the Unit, such as KFileMimeTypeInfo.Seconds or
 KFileMimeTypeInfo.KiloBytes. In short, the constructor defines the data
 structure of the meta information supported by your plugin.
 Example:
  @code
  FooPlugin.FooPlugin(TQObject parent, String name,
                       ArrayListargs)
  {
      KFileMimeTypeInfo info = addMimeTypeInfo( "application/x-foo" );
      // our new group
      KFileMimeTypeInfo.GroupInfo group = null;
      group = addGroupInfo(info, "FooInfo", i18n("Foo Information"));
      KFileMimeTypeInfo.ItemInfo item;
      // our new items in the group
      item = addItemInfo(group, "Items", i18n("Items"), TQVariant.Int);
      item = addItemInfo(group, "Size", i18n("Size"), TQVariant.Int);
      setUnit(item, KFileMimeTypeInfo.KiloBytes);
      // strings are possible, too:
      //addItemInfo(group, "Document Type", i18n("Document type"), TQVariant.String);
  }
  @endcode
 Some meta information items are likely to be available in several different
 file formats, such as @c "Author", @c "Title" (for documents), and
 @c "Length" (for multimedia files). Be sure to use the naming scheme from
 existing plugins for your meta information items if possible. If, for
 example, the meta information of a group of files is shown in a table view,
 this will allow two files to share the same column (say "Length") even if
 they are of a different file type.
 You must overwrite the readInfo() method. In this method you need to extract
 the meta information of the given file. You can use a third-party library to
 achieve this task. This might be the best way for binary files, since a
 change in the file format is likely to be supported by subsequent releases
 of that library. Alternatively, for text-based file formats, you can use
 TQTextStream to parse the file. For simple file formats, TQRegExp can be of
 great help, too.
 After you extracted the relevant information, use appendGroup() and
 appendItem() to fill the meta information data structure (as defined in the
 constructor) with values. Note that you can leave out groups or items
 which are not appropriate for a particular file.
 Example:
  @code
  boolean FooPlugin.readInfo( KFileMetaInfo& info, uint what)
  {
      int numItems = 0;
      int size = 0;
      // do your calculations here, e.g. using a third-party
      // library or by writing an own parser using e.g. TQTextStream
      // calculate numItems and size ...
      // note: use the same key strings as in the constructor
      KFileMetaInfoGroup group = appendGroup(info, "FooInfo");
      appendItem(group, "Items", numItems);
      appendItem(group, "Size", size);
      return true;
  }
  @endcode
 If you want to define mutable meta information items, you need to overwrite
 the writeInfo() method. In this method, you can use third-party library
 (appropriate mostly for binary files, see above) or TQTextStream to write the
 information back to the file. If you use TQTextStream, be sure to write all
 file contents back.
 For some items, it might be that not all possible values are allowed. You
 can overwrite the createValidator() method to define constraints for a meta
 information item. For example, the @c "Year" field for an MP3 file could
 reject values outside the range 1500 - 2050 (at least for now). The
 validator is used to check values before the writeInfo() method is called so
 that writeInfo() is only provided correct values.
 In your plugin, you need to create a factory for the KFilePlugin
 Example:
  @code
  typedef KGenericFactory<FooPlugin> FooFactory;
  K_EXPORT_COMPONENT_FACTORY(kfile_foo, FooFactory("kfile_foo"));
  @endcode
 To make your plugin available within KDE, you also need to provide a
 <code>.desktop</code> file which describes your plugin. The retquired fields in the
 file are:
 - <code>Type</code>: must be @c "Service"
 - <code>Name</code>: the name of the plugin
 - <code>ServiceTypes</code>: must contain @c "KFilePlugin"
 - <code>X</code>-KDE-Library: the name of the library containing the KFile plugin
 - <code>MimeType</code>: the mimetype(s) which are supported by the plugin
 - <code>PreferredGroups</code>: a comma-separated list of the most important groups.
   This list defines the order in which the meta information groups should be
   displayed
 - <code>PreferredItems</code>: a comma-separated list of the most important items.
   This list defines the order in which the meta information items should be
   displayed
 Example:
  @code
  [Desktop Entry]
  Encoding=UTF-8
  Type=Service
  Name=Foo Info
  ServiceTypes=KFilePlugin
  X-KDE-Library=kfile_foo
  MimeType=application/x-foo
  PreferredGroups=FooInfo
  PreferredItems=Items,Size
  @endcode
		@short    @brief Base class for a meta information plugin

*/
public class KFilePlugin extends TQObject  {
	protected KFilePlugin(Class dummy){super((Class) null);}
	public native TQMetaObject metaObject();
	public native String className();
	/**	
		 Creates a new KFilePlugin instance. You need to implement a constructor
		 with the same argument list as this is retquired by KGenericFactory
			@param parent the parent of the TQObject, can be <code>0</code>
			@param name the name of the TQObject, can be <code>0</code>
			@param args currently ignored
				@short    Creates a new KFilePlugin instance.
		@see #addMimeTypeInfo
		@see #addGroupInfo
		@see #addItemInfo
		@see org.kde.qt.TQObject
	*/
	/**	
		 Read the info from the file in this method and insert it into the
		 provided KFileMetaInfo object. You can get the path to the file with
		 KFileMetaInfo.path(). Use appendGroup() and appendItem() to fill
		 <code>info</code> with the extracted values
			@param info the information will be written here
			@param what defines what to read, see KFileMetaInfo.What
				@return @c true if successful, @c false if it failed

		@short    Read the info from the file in this method and insert it into the  provided KFileMetaInfo object.
		@see #writeInfo
	*/
	public native boolean readInfo(KFileMetaInfo info, int what);
	public native boolean readInfo(KFileMetaInfo info);
	/**	
		 Similar to the readInfo() but for writing the info back to the file.
		 If you don't have any writable keys, don't implement this method
			@param info the information that will be written
				@return @c true if successful, @c false if it failed

		@short    Similar to the readInfo() but for writing the info back to the file.
	*/
	public native boolean writeInfo(KFileMetaInfo info);
	/**	
		 This method should create an appropriate validator for the specified
		 item if it's editable or return a null pointer if not. If you don't have
		 any editable items, you don't need to implement this method.
			 If you you don't need any validation, e.g. you accept any input, you can
		 simply return <code>null</code>, or not reimplement this method at all.
			@param mimeType the mime type
			@param group the group name of the validator item
			@param key the key name of the validator item
			@param parent the TQObject parent, can be <code>0</code>
			@param name the name of the TQObject, can be <code>0</code>
				@short    This method should create an appropriate validator for the specified  item if it's editable or return a null pointer if not.
	*/
	public native TQValidator createValidator(String mimeType, String group, String key, TQObject parent, String name);
}