Patch: KFileMetaInfo documentation
Sébastien Laoût
slaout at linux62.org
Sun Sep 18 15:24:19 BST 2005
I wanted to list all metainfos of a file (eg. the author, title... or a PDF
file...).
But the class KFileMetaInfo lack some documentation and it took me some time
to find out how to do that, and know which methods to call.
Ie. what to choose between groups(), supportedGroups(), preferredGroups(),
preferredKeys(), supportedKeys()... where the documentation barelly tell us
that it "Returns a list of all supported groups" or "Returns a list of the
preferred groups"!
Some example of usage would not be bad.
I propose to add this code snippet in the KFileMetaInfo Detailed Description:
/** The following example illustrate how to show the list of metainfos
* of a file to the user, with translated keys and formated string values:
*/
KFileMetaInfo infos = KFileMetaInfo(theUrlOfTheFile);
// If the file actually have metainfos:
if (infos.isValid() && !infos.isEmpty())
{
// Get the keys specific to the file MIME type and that the file have:
QStringList groups = infos.preferredKeys();
for (QStringList::Iterator it = groups.begin(); it != groups.end(); ++it)
{
KFileMetaInfoItem metaInfoItem = infos.item(*it);
if (!metaInfoItem.string().isEmpty())
{
std::cout << metaInfoItem.translatedKey() << ": " <<
metaInfoItem.string() << std::endl;
}
}
}
It will hopefully help other developpers to quickly get used to this class.
Best regards,
Sébastien Laoût.
More information about the kde-core-devel
mailing list