QTfrontend/util/HWDataManager.h
branchhedgeroid
changeset 7855 ddcdedd3330b
parent 6350 41b0a9955c47
parent 7854 0b447175594f
child 7857 2bc61f8841a1
equal deleted inserted replaced
6350:41b0a9955c47 7855:ddcdedd3330b
     1 /*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2006-2007 Igor Ulyanov <iulyanov@gmail.com>
       
     4  * Copyright (c) 2007-2011 Andrey Korotaev <unC0Rr@gmail.com>
       
     5  *
       
     6  * This program is free software; you can redistribute it and/or modify
       
     7  * it under the terms of the GNU General Public License as published by
       
     8  * the Free Software Foundation; version 2 of the License
       
     9  *
       
    10  * This program is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13  * GNU General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License
       
    16  * along with this program; if not, write to the Free Software
       
    17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
       
    18  */
       
    19 
       
    20 /**
       
    21  * @file
       
    22  * @brief HWDataManager class definition
       
    23  */
       
    24 
       
    25 #ifndef HEDGEWARS_HWDATAMANAGER_H
       
    26 #define HEDGEWARS_HWDATAMANAGER_H
       
    27 
       
    28 #include <QDir>
       
    29 #include <QFile>
       
    30 
       
    31 #include <QStringList>
       
    32 
       
    33 class QDir;
       
    34 class QFile;
       
    35 class QStringList;
       
    36 
       
    37 /**
       
    38  * @brief Offers access to the data files of hedgewars.
       
    39  * 
       
    40  * @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
       
    41  * 
       
    42  * @author sheepluva
       
    43  * @since 0.9.17
       
    44  */
       
    45 class HWDataManager
       
    46 {
       
    47 public:
       
    48     /**
       
    49      * @brief Returns reference to the <i>singleton</i> instance of this class.
       
    50      * 
       
    51      * @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
       
    52      * 
       
    53      * @return reference to the instance.
       
    54      */
       
    55     static HWDataManager & instance();
       
    56 
       
    57     /**
       
    58      * @brief Returns a sorted list of data directory entries.
       
    59      * 
       
    60      * @param subDirectory sub-directory to search.
       
    61      * @param filters filters for entry type.
       
    62      * @param nameFilters filters by name patterns.
       
    63      * @return a sorted list of matches in the subDirectory of data directory.
       
    64      */
       
    65     QStringList entryList(const QString & subDirectory,
       
    66                           QDir::Filters filters = QDir::NoFilter,
       
    67                           const QStringList & nameFilters = QStringList("*")
       
    68                          ) const;
       
    69 
       
    70     /**
       
    71      * @brief Returns the path for the desires data file.
       
    72      * 
       
    73      * Use this method if you want to read an existing data file.
       
    74      * 
       
    75      * @param relativeDataFilePath relative path of the data file.
       
    76      * @return real path to the file.
       
    77      */
       
    78     QString findFileForRead(const QString & relativeDataFilePath) const;
       
    79 
       
    80 
       
    81     /**
       
    82      * @brief Returns the path for the data file that is to be written.
       
    83      * 
       
    84      * Use this method if you want to create or write into a data file.
       
    85      * 
       
    86      * @param relativeDataFilePath relative path of data file write path.
       
    87      * @return destination of path data file.
       
    88      */
       
    89     QString findFileForWrite(const QString & relativeDataFilePath) const;
       
    90 
       
    91 
       
    92 private:
       
    93     /**
       
    94      * @brief Class constructor of the <i>singleton</i>.
       
    95      * 
       
    96      * Not to be used from outside the class,
       
    97      * use the static {@link HWDataManager::instance()} instead.
       
    98      * 
       
    99      * @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
       
   100      */
       
   101     HWDataManager();
       
   102 
       
   103     QDir * defaultData; ///< directory of the installed data
       
   104     QDir * userData;    ///< directory of custom data in the user's directory
       
   105 };
       
   106 
       
   107 #endif // HEDGEWARS_HWDATAMANAGER_H