annotate base/ResourceFinder.h @ 679:c8badbd4c005

* Introduce ResourceFinder
author Chris Cannam
date Wed, 04 May 2011 14:05:08 +0100
parents
children 27cdabba2d3e
rev   line source
Chris@679 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@679 2
Chris@679 3 /*
Chris@679 4 Sonic Visualiser
Chris@679 5 An audio file viewer and annotation editor.
Chris@679 6 Centre for Digital Music, Queen Mary, University of London.
Chris@679 7
Chris@679 8 This program is free software; you can redistribute it and/or
Chris@679 9 modify it under the terms of the GNU General Public License as
Chris@679 10 published by the Free Software Foundation; either version 2 of the
Chris@679 11 License, or (at your option) any later version. See the file
Chris@679 12 COPYING included with this distribution for more information.
Chris@679 13 */
Chris@679 14
Chris@679 15 /*
Chris@679 16 This is a modified version of a source file from the
Chris@679 17 Rosegarden MIDI and audio sequencer and notation editor.
Chris@679 18 This file copyright 2005-2011 Chris Cannam and the Rosegarden
Chris@679 19 development team.
Chris@679 20 */
Chris@679 21
Chris@679 22 #ifndef _RESOURCE_FINDER_H_
Chris@679 23 #define _RESOURCE_FINDER_H_
Chris@679 24
Chris@679 25 #include <QString>
Chris@679 26
Chris@679 27 class ResourceFinder
Chris@679 28 {
Chris@679 29 public:
Chris@679 30 ResourceFinder() { }
Chris@679 31 virtual ~ResourceFinder() { }
Chris@679 32
Chris@679 33 /**
Chris@679 34 * Return the location (as a true file path, or a Qt4 ":"-prefixed
Chris@679 35 * resource path) of the file best matching the given resource
Chris@679 36 * filename in the given resource category.
Chris@679 37 *
Chris@679 38 * Category should be a relative directory path without leading or
Chris@679 39 * trailing slashes, for example "chords". The fileName is the
Chris@679 40 * remainder of the file name without any path content, for
Chris@679 41 * example "user_chords.xml".
Chris@679 42 *
Chris@679 43 * Returns an empty string if no matching resource is found.
Chris@679 44 *
Chris@679 45 * Use this when you know that a particular resource is required
Chris@679 46 * and just need to locate it.
Chris@679 47 */
Chris@679 48 QString getResourcePath(QString resourceCat, QString fileName);
Chris@679 49
Chris@679 50 /**
Chris@679 51 * Return a list of full file paths for files with the given file
Chris@679 52 * extension, found in the given resource category.
Chris@679 53 *
Chris@679 54 * Category should be a relative directory path without leading or
Chris@679 55 * trailing slashes, for example "chords". File extension should
Chris@679 56 * be the extension without the dot, for example "xml". Returned
Chris@679 57 * list may mix true file paths in both installed and user
Chris@679 58 * locations with Qt4 ":"-prefixed resource paths.
Chris@679 59 *
Chris@679 60 * Use this when you need to enumerate the options available for
Chris@679 61 * use directly in the program (rather than e.g. offering the user
Chris@679 62 * a file-open dialog).
Chris@679 63 */
Chris@679 64 QStringList getResourceFiles(QString resourceCat, QString fileExt);
Chris@679 65
Chris@679 66 /**
Chris@679 67 * Return the true file path for installed resource files in the
Chris@679 68 * given resource category. Category should be a relative
Chris@679 69 * directory path without leading or trailing slashes, for example
Chris@679 70 * "chords". Note that resources may also exist in the Qt4
Chris@679 71 * resource bundle; this method only returns the external
Chris@679 72 * (installed) resource location. Use getResourceFiles instead to
Chris@679 73 * return an authoritative list of available resources of a given
Chris@679 74 * type.
Chris@679 75 *
Chris@679 76 * Use this when you need a file path, e.g. for use in a file
Chris@679 77 * finder dialog.
Chris@679 78 */
Chris@679 79 QString getResourceDir(QString resourceCat);
Chris@679 80
Chris@679 81 /**
Chris@679 82 * Return the true file path for the location in which the named
Chris@679 83 * resource file in the given resource category should be saved.
Chris@679 84 */
Chris@679 85 QString getResourceSavePath(QString resourceCat, QString fileName);
Chris@679 86
Chris@679 87 /**
Chris@679 88 * Return the true file path for the location in which resource
Chris@679 89 * files in the given resource category should be saved.
Chris@679 90 */
Chris@679 91 QString getResourceSaveDir(QString resourceCat);
Chris@679 92
Chris@679 93 /**
Chris@679 94 * If the named resource file in the given resource category is
Chris@679 95 * available only as a bundled resource, copy it out into the user
Chris@679 96 * location returned by getResourceSavePath so that it can be read
Chris@679 97 * by non-Qt code. Any subsequent call to getResourcePath for
Chris@679 98 * this resource should return a true file path (if the resource
Chris@679 99 * exists) in either user or system location, or an empty string
Chris@679 100 * (if the resource does not exist), but never a ":"-prefixed
Chris@679 101 * resource path. This function does not overwrite any existing
Chris@679 102 * unbundled copy of the resource.
Chris@679 103 *
Chris@679 104 * Return false if a system error occurs during unbundling
Chris@679 105 * (e.g. disk full).
Chris@679 106 */
Chris@679 107 bool unbundleResource(QString resourceCat, QString fileName);
Chris@679 108
Chris@679 109 protected:
Chris@679 110 QString getUserResourcePrefix();
Chris@679 111 QStringList getSystemResourcePrefixList();
Chris@679 112 QStringList getResourcePrefixList();
Chris@679 113 };
Chris@679 114
Chris@679 115 #endif
Chris@679 116
Chris@679 117