QTfrontend/util/HWDataManager.h
author sheepluva
Thu, 20 Oct 2011 23:25:16 +0200
changeset 6160 863d3edf5690
parent 6159 c780b8cf4d75
child 6162 437116977d43
permissions -rw-r--r--
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6159
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
     1
/*
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
     3
 * Copyright (c) 2006-2007 Igor Ulyanov <iulyanov@gmail.com>
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
     4
 * Copyright (c) 2007-2011 Andrey Korotaev <unC0Rr@gmail.com>
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
     5
 *
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License as published by
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
     8
 * the Free Software Foundation; version 2 of the License
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
     9
 *
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    13
 * GNU General Public License for more details.
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    14
 *
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    18
 */
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    19
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    20
#ifndef HEDGEWARS_HWDATAMANAGER_H
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    21
#define HEDGEWARS_HWDATAMANAGER_H
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    22
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    23
#include <QDir>
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    24
#include <QFile>
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    25
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    26
#include <QStringList>
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    27
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    28
class QDir;
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    29
class QFile;
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    30
class QStringList;
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    31
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    32
/**
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    33
 * @brief Offers access to the data files of hedgewars.
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    34
 * 
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    35
 * @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    36
 * 
6159
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    37
 * @author sheepluva
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    38
 * @since 0.9.17
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    39
 */
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    40
class HWDataManager
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    41
{
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    42
public:
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    43
    /**
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    44
     * @brief Returns a pointer to the <i>singleton</i> instance of this class.
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    45
     * 
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    46
     * @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    47
     * 
6159
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    48
     * @return pointer to the instance.
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    49
     */
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    50
    static HWDataManager & instance();
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    51
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    52
    /**
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    53
     * @brief Returns a pointer to the <i>singleton</i> instance of this class.
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    54
     * 
6159
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    55
     * @param subDirectory sub-directory to search.
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    56
     * @param filters filters for entry type.
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    57
     * @param nameFilters filters by name patterns.
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    58
     * @return a sorted list of matches in the subDirectory of data directory.
6159
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    59
     */
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    60
    QStringList entryList(const QString & subDirectory,
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    61
                          QDir::Filters filters = QDir::NoFilter,
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    62
                          const QStringList & nameFilters = QStringList("*")
6159
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    63
                         ) const;
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    64
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    65
    /**
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    66
     * @brief Creates a file object for the desired data path and
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    67
     * returns a pointer to it.
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    68
     * 
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    69
     * Use this method if you want to read an existing data file.
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    70
     * 
6159
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    71
     * @param relativeDataFilePath path to the data file.
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    72
     * @return respective <code>QFile</code> pointer, the file may not exist.
6159
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    73
     */
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    74
    QFile * findFileForRead(const QString & relativeDataFilePath) const;
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    75
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    76
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    77
    /**
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    78
     * @brief Creates a file object for the desired data path and
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    79
     * returns a pointer to it.
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    80
     * 
6159
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    81
     * Use this method if you want to create or write into a data file.
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    82
     * 
6159
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    83
     * @param relativeDataFilePath path to the data file.
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    84
     * @return respective <code>QFile</code> pointer.
6159
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    85
     */
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    86
    QFile * findFileForWrite(const QString & relativeDataFilePath) const;
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    87
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    88
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    89
private:
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    90
    /**
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    91
     * @brief Class constructor of the <i>singleton</i>.
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    92
     * 
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    93
     * Not to be used from outside the class,
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    94
     * use the static {@link HWDataManager::instance()} instead.
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    95
     * 
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
    96
     * @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
6159
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    97
     */
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    98
    HWDataManager();
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    99
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
   100
    QDir * defaultData;
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
   101
    QDir * userData;
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
   102
};
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
   103
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
   104
#endif // HEDGEWARS_HWDATAMANAGER_H