source: calamares/trunk/fuentes/src/libcalamares/utils/CalamaresUtils.h @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 17 months ago

sync with github

File size: 4.4 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2013-2016, Teo Mrnjavac <teo@kde.org>
4 *
5 *   Originally from Tomahawk, portions:
6 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
7 *   Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
8 *   Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
9 *
10 *   Calamares is free software: you can redistribute it and/or modify
11 *   it under the terms of the GNU General Public License as published by
12 *   the Free Software Foundation, either version 3 of the License, or
13 *   (at your option) any later version.
14 *
15 *   Calamares is distributed in the hope that it will be useful,
16 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
17 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 *   GNU General Public License for more details.
19 *
20 *   You should have received a copy of the GNU General Public License
21 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#ifndef CALAMARESUTILS_H
25#define CALAMARESUTILS_H
26
27#include "DllMacro.h"
28
29#include <QLocale>
30
31#define RESPATH ":/data/"
32
33class QDir;
34class QObject;
35
36/**
37 * @brief The CalamaresUtils namespace contains utility functions.
38 */
39namespace CalamaresUtils
40{
41    DLLEXPORT QDir qmlModulesDir();
42
43    /**
44     * @brief appDataDir returns the directory with common application data.
45     * Defaults to CMAKE_INSTALL_FULL_DATADIR (usually /usr/share/calamares).
46     */
47    DLLEXPORT QDir appDataDir();
48
49    /**
50     * @brief appLogDir returns the directory for Calamares logs.
51     * Defaults to QStandardPaths::CacheLocation (usually ~/.cache/Calamares).
52     */
53    DLLEXPORT QDir appLogDir();
54
55    /**
56     * @brief systemLibDir returns the system's lib directory.
57     * Defaults to CMAKE_INSTALL_FULL_LIBDIR (usually /usr/lib64 or /usr/lib).
58     */
59    DLLEXPORT QDir systemLibDir();
60
61    /**
62     * @brief installTranslator changes the application language.
63     * @param locale the new locale.
64     * @param brandingTranslationsPrefix the branding path prefix, from Calamares::Branding.
65     * @param parent the parent QObject.
66     */
67    DLLEXPORT void installTranslator( const QLocale& locale,
68                                      const QString& brandingTranslationsPrefix,
69                                      QObject* parent );
70
71    DLLEXPORT QString translatorLocaleName();
72
73    /**
74     * Override app data dir. Only for testing purposes.
75     */
76    DLLEXPORT void setAppDataDir( const QDir& dir );
77    DLLEXPORT bool isAppDataDirOverridden();
78
79    DLLEXPORT void setQmlModulesDir( const QDir& dir );
80
81    /**
82     * @brief removeDiacritics replaces letters with diacritics and ligatures with
83     * alternative forms and digraphs.
84     * @param string the string to transform.
85     * @return the output string with plain characters.
86     */
87    DLLEXPORT QString removeDiacritics( const QString& string );
88
89    /**
90     * @brief obscure is a bidirectional obfuscation function, from KStringHandler.
91     * @param string the input string.
92     * @return the obfuscated string.
93     */
94    DLLEXPORT QString obscure( const QString& string );
95
96    /**
97     * @brief crash makes Calamares crash immediately.
98     */
99    DLLEXPORT void crash();
100
101    /**
102     * Get a bool value from a mapping with a given key; returns the default
103     * if no value is stored in the map.
104     */
105    DLLEXPORT bool getBool( const QVariantMap& map, const QString& key, bool d );
106
107    /**
108     * Get a string value from a mapping; returns empty QString if no value.
109     */
110    DLLEXPORT QString getString( const QVariantMap& map, const QString& key );
111
112    /**
113     * Get an integer value from a mapping; returns @p d if no value.
114     */
115    DLLEXPORT int getInteger( const QVariantMap& map, const QString& key, int d );
116
117    /**
118     * Get a double value from a mapping (integers are converted); returns @p d if no value.
119     */
120    DLLEXPORT double getDouble( const QVariantMap& map, const QString& key, double d );
121
122    /**
123     * Returns a sub-map (i.e. a nested map) from the given mapping with the
124     * given key. @p success is set to true if the @p key exists
125     * in @p map and converts to a map, false otherwise.
126     *
127     * Returns an empty map if there is no such key or it is not a map-value.
128     * (e.g. if @p success is false).
129     */
130    DLLEXPORT QVariantMap getSubMap( const QVariantMap& map, const QString& key, bool& success );
131}
132
133#endif // CALAMARESUTILS_H
Note: See TracBrowser for help on using the repository browser.