KVIrc 5.2.0
Developer APIs
KviEnvironment.h
Go to the documentation of this file.
1#ifndef _KVI_ENV_H_
2#define _KVI_ENV_H_
3//=============================================================================
4//
5// File : KviEnvironment.h
6// Creation date : Sat May 05 2002 02:15:21 CEST by Szymon Stefanek
7//
8// This file is part of the KVIrc IRC client distribution
9// Copyright (C) 2002-2010 Szymon Stefanek (pragma@kvirc.net)
10//
11// This program is FREE software. You can redistribute it and/or
12// modify it under the terms of the GNU General Public License
13// as published by the Free Software Foundation; either version 2
14// of the License, or (at your option) any later version.
15//
16// This program is distributed in the HOPE that it will be USEFUL,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19// See the GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program. If not, write to the Free Software Foundation,
23// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24//
25//=============================================================================
26
33#include "kvi_settings.h"
34
35#include <QString>
36
37#include <stdlib.h>
38
39#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
40#include <windows.h>
41#define MAX_ENV_SIZE 32767
42#endif
43
44namespace KviEnvironment
45{
46
47#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
48 inline QString getVariable(const QString & szName)
49 {
50 LPTSTR szRet = (LPTSTR)::malloc(MAX_ENV_SIZE * sizeof(TCHAR));
51 QString szValue;
52 if (GetEnvironmentVariable(szName.toStdWString().c_str(), szRet, MAX_ENV_SIZE))
53 szValue = QString::fromStdWString(szRet);
54 ::free(szRet);
55 return szValue;
56 }
57
58 inline void setVariable(const QString & szName, const QString & szValue)
59 {
60 SetEnvironmentVariable(szName.toStdWString().c_str(),
61 szValue.toStdWString().c_str());
62 }
63
64 inline void unsetVariable(const QString & szName)
65 {
66 SetEnvironmentVariable(szName.toStdWString().c_str(), nullptr);
67 }
68#else
74 inline QString getVariable(const QString & szName)
75 {
76 auto name = szName.toLocal8Bit();
77 return QString::fromLocal8Bit(getenv(name.data()));
78 }
79
86 KVILIB_API bool setVariable(const QString & szName, const QString & szValue);
87
93 KVILIB_API void unsetVariable(const QString & szName);
94#endif
95}
96
97#endif //_KVI_ENV_H_
This file contains compile time settings.
#define KVILIB_API
Definition kvi_settings.h:124
Definition KviEnvironment.cpp:32
bool setVariable(const QString &szName, const QString &szValue)
Sets environment variable.
Definition KviEnvironment.cpp:36
void unsetVariable(const QString &szName)
Unsets environment variable.
Definition KviEnvironment.cpp:65
QString getVariable(const QString &szName)
Gets environment variable.
Definition KviEnvironment.h:74