-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
RabbitCommonDir.h
167 lines (154 loc) · 6.87 KB
/
RabbitCommonDir.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/** @copyright Copyright (c) Kang Lin studio, All Rights Reserved
* @author Kang Lin <[email protected]>
* @abstract Directory operator
*/
#ifndef RABBITCOMM_CGLOBALDIR_H
#define RABBITCOMM_CGLOBALDIR_H
#pragma once
#include <QString>
#if HAVE_RABBITCOMMON_GUI
#include <QFileDialog>
#endif
#include "rabbitcommon_export.h"
namespace RabbitCommon {
/**
*
* Default directory:
* \code
* ApplicationInstallRoot(The folder is only read) GetDirApplicationInstallRoot()
* |- bin GetDirApplication()
* |- etc GetDirConfig()
* | |- xml GetDirApplicationXml()
* | |- applicationName.conf GetFileApplicationConfigure()
* |- share GetDirData()
* | |- translations GetDirTranslations()
* | |- doc GetDirDocument()
* | | |- ${ProjectName} GetDirDocument(QCoreApplication::applicationName())
* | |- icons GetDirIcons()
* | |- db GetDirDatabase()
* | |- database.db GetDirDatabaseFile()
* |- plugins GetDirPlugins()
* | |- translations GetDirPluginsTranslation()
* | |- szDir GetDirPlugins("plugins/szDir")
* | | - translations GetDirPluginsTranslation("plugins/szDir")
*
*
* The follow folder is write and read:
* ${DocumentRoot}/Rabbit/${ApplicationName} GetDirUserDocument()
* |- applicationName.conf GetFileUserConfigure()
* |- etc GetDirUserConfig()
* |- share GetDirUserData()
* | |- image GetDirUserImage()
* | |- db GetDirUserDatabase()
* | | |- database.db GetDirUserDatabaseFile()
* | |- xml GetDirUserXml()
*
* System temp folder
* |- log
* | |- ${ApplicationName} GetDirLog()
*
*
* Android:
* assets (The folder is only read) GetDirApplicationInstallRoot()
* |- etc GetDirConfig()
* | |- xml GetDirApplicationXml()
* | |- applicationName.conf GetFileApplicationConfigure()
* |- share GetDirData()
* | |- translations GetDirTranslations()
* | |- icons GetDirIcons()
* | |- db GetDirDatabase()
* | |- database.db GetDirDatabaseFile()
* |- plugins
* | |- translations GetDirPluginsTranslation()
* | |- szDir
* | | - translations GetDirPluginsTranslation("plugins/szDir")
*
* ${DocumentRoot}/Rabbit/${applicationName} (Write and read)
* |- root
* | |- etc GetDirConfig(true)
* | | |- xml GetDirApplicationXml(true)
* | | |- applicationName.conf GetFileApplicationConfigure(true)
* | |- log GetDirLog()
* | |- share GetDirData(true)
* | | |- db GetDirDatabase(true)
* | |- database.db GetDirDatabaseFile(true)
*
* \endcode
*
* \note In android, copy contents to DocumentRoot/Rabbit/applicationName from assets
*
* \see
* - [GNU installation Directories in cmake](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html#module:GNUInstallDirs)
* - [GNU installation Directories](https://www.gnu.org/prep/standards/html_node/Directory-Variables.html)
*
* \ingroup API
*/
class RABBITCOMMON_EXPORT CDir
{
public:
static CDir* Instance();
QString GetDirApplication();
int SetDirApplication(const QString &szPath);
QString GetDirApplicationInstallRoot();
int SetDirApplicationInstallRoot(const QString &szPath);
QString GetDirConfig(bool bReadOnly = false);
QString GetDirLog();
/*!
* Get data directory
* \param bReadOnly
* \return data directory
* \note the data directory is ${CMAKE_INSTALL_DATADIR} in CMakeLists.txt
* \see
* - [GNU installation Directories in cmake](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html#module:GNUInstallDirs)
* - [GNU installation Directories](https://www.gnu.org/prep/standards/html_node/Directory-Variables.html)
*/
QString GetDirData(bool bReadOnly = false);
/*!
* \brief GetDirDocument
* \param szProjectName: project name
* \param bReadOnly
* \return the document directory
* \note the data directory is ${CMAKE_INSTALL_DOCDIR} in CMakeLists.txt
* \see
* - [GNU installation Directories in cmake](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html#module:GNUInstallDirs)
* - [GNU installation Directories](https://www.gnu.org/prep/standards/html_node/Directory-Variables.html)
*/
QString GetDirDocument(QString szProjectName = QString(),
bool bReadOnly = false);
QString GetDirDatabase(bool bReadOnly = false);
QString GetDirDatabaseFile(const QString &szFile = QString(),
bool bReadOnly = false);
QString GetDirApplicationXml(bool bReadOnly = false);
QString GetDirIcons(bool bReadOnly = false);
/*!
* \see cmake/Translations.cmake
* \see CTools::InstallTranslator
*/
QString GetDirTranslations(QString szPrefix = QString());
QString GetDirPluginsTranslation(QString szDir = "plugins");
QString GetDirPlugins(const QString &szDir = "");
QString GetFileApplicationConfigure(bool bReadOnly = false);
QString GetDirUserDocument();
/*!
* \brief Set user document directory
* \param szPath: If is empty, set system user document
*/
int SetDirUserDocument(QString szPath = QString());
QString GetDirUserConfig();
QString GetDirUserData();
QString GetDirUserDatabase();
QString GetDirUserDatabaseFile(const QString &szFile = QString());
QString GetDirUserXml();
QString GetDirUserImage();
QString GetFileUserConfigure();
static int CopyDirectory(const QString &fromDir,
const QString &toDir,
bool bCoverIfFileExists = true);
private:
CDir();
QString m_szDocumentPath;
QString m_szApplicationDir;
QString m_szApplicationInstallRootDir;
};
} //namespace RabbitCommon
#endif // RABBITCOMM_CGLOBALDIR_H