QTfrontend/util/HWDataManager.h
author sheepluva
Thu, 20 Oct 2011 13:10:24 +0200
changeset 6159 c780b8cf4d75
child 6160 863d3edf5690
permissions -rw-r--r--
introduce HWDataManager util for transparent access to [user-]data files
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
/**
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    33
 * Offers access to the data files of hedgewars.
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    34
 * Note: singleton pattern
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    35
 * @author sheepluva
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    36
 * @since 0.9.17
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    37
 */
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    38
class HWDataManager
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
public:
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
     * Returns a pointer to the singleton instance of this class.
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    43
     * @return pointer to the instance.
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    44
     */
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    45
    static HWDataManager & instance();
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    46
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    47
    /**
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    48
     * Returns a pointer to the singleton instance of this class.
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    49
     * @param subDirectory sub-directory to search.
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    50
     * @param filters filters for entry type.
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    51
     * @param namefilters filters by name patterns.
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    52
     * @return a list of matches in the subDirectory of data directory.
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    53
     */
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    54
    QStringList entryList(const QString & subDirectory,
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    55
                          QDir::Filters filters = QDir::NoFilter,
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    56
                          const QStringList & nameFilters = QStringList()
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    57
                         ) const;
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    58
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
     * Creates a QFile for the desired data path and returns a pointer to it.
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    61
     * Use this method if you want to read an existing data file;
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    62
     * @param relativeDataFilePath path to the data file.
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    63
     * @return respective QFile pointer, the actual file may actually not exist.
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
    QFile * findFileForRead(const QString & relativeDataFilePath) const;
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    66
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    67
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    68
    /**
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    69
     * Creates a QFile for the desired data path and returns a pointer to it.
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    70
     * Use this method if you want to create or write into a data file.
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    71
     * @param relativeDataFilePath path to the data file.
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    72
     * @return respective QFile pointer.
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 * findFileForWrite(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
private:
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    78
    /**
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    79
     * Singleton class constructor.
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    80
     */
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    81
    HWDataManager();
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    82
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    83
    QDir * defaultData;
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    84
    QDir * userData;
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
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff changeset
    87
#endif // HEDGEWARS_HWDATAMANAGER_H