comparison base/ResourceFinder.h @ 679:c8badbd4c005

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