QTfrontend/util/DataManager.h
branchhedgeroid
changeset 15515 7030706266df
parent 12300 ac57d564efce
equal deleted inserted replaced
7861:bc7b6aa5d67a 15515:7030706266df
     1 /*
     1 /*
     2  * Hedgewars, a free turn based strategy game
     2  * Hedgewars, a free turn based strategy game
     3  * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
     3  * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
     4  *
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation; version 2 of the License
     7  * the Free Software Foundation; version 2 of the License
     8  *
     8  *
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    12  * GNU General Public License for more details.
    13  *
    13  *
    14  * You should have received a copy of the GNU General Public License
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program; if not, write to the Free Software
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    17  */
    17  */
    18 
    18 
    19 /**
    19 /**
    20  * @file
    20  * @file
    21  * @brief DataManager class definition
    21  * @brief DataManager class definition
    35 class QStandardItemModel;
    35 class QStandardItemModel;
    36 
    36 
    37 /**
    37 /**
    38  * @brief Offers access to the data files of hedgewars.
    38  * @brief Offers access to the data files of hedgewars.
    39  *
    39  *
    40  * @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
    40  * @see <a href="https://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
    41  *
    41  *
    42  * @author sheepluva
    42  * @author sheepluva
    43  * @since 0.9.17
    43  * @since 0.9.17
    44  */
    44  */
    45 class DataManager: public QObject
    45 class DataManager: public QObject
    48 
    48 
    49     public:
    49     public:
    50         /**
    50         /**
    51          * @brief Returns reference to the <i>singleton</i> instance of this class.
    51          * @brief Returns reference to the <i>singleton</i> instance of this class.
    52          *
    52          *
    53          * @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
    53          * @see <a href="https://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
    54          *
    54          *
    55          * @return reference to the instance.
    55          * @return reference to the instance.
    56          */
    56          */
    57         static DataManager & instance();
    57         static DataManager & instance();
    58 
    58 
    64          * @param nameFilters filters by name patterns.
    64          * @param nameFilters filters by name patterns.
    65          * @return a sorted list of matches in the subDirectory of data directory.
    65          * @return a sorted list of matches in the subDirectory of data directory.
    66          */
    66          */
    67         QStringList entryList(const QString & subDirectory,
    67         QStringList entryList(const QString & subDirectory,
    68                               QDir::Filters filters = QDir::NoFilter,
    68                               QDir::Filters filters = QDir::NoFilter,
    69                               const QStringList & nameFilters = QStringList("*")
    69                               const QStringList & nameFilters = QStringList("*"),
       
    70                               bool withDLC = true
    70                              ) const;
    71                              ) const;
    71 
       
    72         /**
       
    73          * @brief Returns the path for the desires data file.
       
    74          *
       
    75          * Use this method if you want to read an existing data file.
       
    76          *
       
    77          * @param relativeDataFilePath relative path of the data file.
       
    78          * @return real path to the file.
       
    79          */
       
    80         QString findFileForRead(const QString & relativeDataFilePath) const;
       
    81 
       
    82 
       
    83         /**
       
    84          * @brief Returns the path for the data file that is to be written.
       
    85          *
       
    86          * Use this method if you want to create or write into a data file.
       
    87          *
       
    88          * @param relativeDataFilePath relative path of data file write path.
       
    89          * @return destination of path data file.
       
    90          */
       
    91         QString findFileForWrite(const QString & relativeDataFilePath) const;
       
    92 
       
    93 
    72 
    94         /**
    73         /**
    95          * @brief Returns pointer to a model of available game styles.
    74          * @brief Returns pointer to a model of available game styles.
    96          *
    75          *
    97          * The model is updated automatically on data reload.
    76          * The model is updated automatically on data reload.
   108          * @return hat model pointer.
    87          * @return hat model pointer.
   109          */
    88          */
   110         HatModel * hatModel();
    89         HatModel * hatModel();
   111 
    90 
   112         /**
    91         /**
   113          * @brief Returns pointer to a model of available maps.
    92          * @brief Returns pointer to a model of available static maps.
   114          *
    93          *
   115          * The model is updated automatically on data reload.
    94          * The model is updated automatically on data reload.
   116          *
    95          *
   117          * @return map model pointer.
    96          * @return map model pointer.
   118          */
    97          */
   119         MapModel * mapModel();
    98         MapModel * staticMapModel();
       
    99 
       
   100         /**
       
   101          * @brief Returns pointer to a model of available mission maps.
       
   102          *
       
   103          * The model is updated automatically on data reload.
       
   104          *
       
   105          * @return map model pointer.
       
   106          */
       
   107         MapModel * missionMapModel();
   120 
   108 
   121         /**
   109         /**
   122          * @brief Returns pointer to a model of available themes.
   110          * @brief Returns pointer to a model of available themes.
   123          *
   111          *
   124          * The model is updated automatically on data reload.
   112          * The model is updated automatically on data reload.
   127          */
   115          */
   128         ThemeModel * themeModel();
   116         ThemeModel * themeModel();
   129 
   117 
   130         QStandardItemModel * colorsModel();
   118         QStandardItemModel * colorsModel();
   131         QStandardItemModel * bindsModel();
   119         QStandardItemModel * bindsModel();
       
   120 
       
   121         QString settingsFileName();
       
   122 
       
   123         static QString safeFileName(QString fileName);
       
   124 
       
   125         static bool ensureFileExists(const QString & fileName);
   132 
   126 
   133     public slots:
   127     public slots:
   134         /// Reloads data from storage.
   128         /// Reloads data from storage.
   135         void reload();
   129         void reload();
   136         void resetColors();
   130         void resetColors();
   146          * @brief Class constructor of the <i>singleton</i>.
   140          * @brief Class constructor of the <i>singleton</i>.
   147          *
   141          *
   148          * Not to be used from outside the class,
   142          * Not to be used from outside the class,
   149          * use the static {@link DataManager::instance()} instead.
   143          * use the static {@link DataManager::instance()} instead.
   150          *
   144          *
   151          * @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
   145          * @see <a href="https://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a>
   152          */
   146          */
   153         DataManager();
   147         DataManager();
   154 
   148 
   155         QDir * m_defaultData; ///< directory of the installed data
       
   156         QDir * m_userData;    ///< directory of custom data in the user's directory
       
   157 
       
   158         GameStyleModel * m_gameStyleModel; ///< game style model instance
   149         GameStyleModel * m_gameStyleModel; ///< game style model instance
   159         HatModel * m_hatModel; ///< hat model instance
   150         HatModel * m_hatModel; ///< hat model instance
   160         MapModel * m_mapModel; ///< map model instance
   151         MapModel * m_staticMapModel; ///< static map model instance
       
   152         MapModel * m_missionMapModel; ///< mission map model instance
   161         ThemeModel * m_themeModel; ///< theme model instance
   153         ThemeModel * m_themeModel; ///< theme model instance
   162         QStandardItemModel * m_colorsModel;
   154         QStandardItemModel * m_colorsModel;
   163         QStandardItemModel * m_bindsModel;
   155         QStandardItemModel * m_bindsModel;
       
   156         QString m_settingsFileName;
   164 };
   157 };
   165 
   158 
   166 #endif // HEDGEWARS_DATAMANAGER_H
   159 #endif // HEDGEWARS_DATAMANAGER_H