File indexing completed on 2024-05-19 16:15:04
0001 /* 0002 SPDX-FileCopyrightText: 2017 Marc Hübner <mahueb55@gmail.com> 0003 SPDX-FileCopyrightText: 2020 Thomas Baumgart <tbaumgart@kde.org> 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "platformtools.h" 0008 0009 #include <pwd.h> 0010 #include <unistd.h> 0011 #include <clocale> 0012 0013 #include <QDebug> 0014 #include <QString> 0015 0016 QString platformTools::osUsername() 0017 { 0018 QString name; 0019 struct passwd* pwd = getpwuid(geteuid()); 0020 if( pwd != nullptr) { 0021 name = QString::fromLatin1(pwd->pw_name); 0022 } 0023 return name; 0024 } 0025 0026 uint platformTools::processId() 0027 { 0028 return getpid(); 0029 } 0030 0031 platformTools::currencySymbolPosition_t platformTools::currencySymbolPosition(bool negativeValues) 0032 { 0033 platformTools::currencySymbolPosition_t rc = platformTools::AfterQuantityMoneyWithSpace; 0034 struct lconv* lc = std::localeconv(); 0035 if (lc) { 0036 const char precedes = negativeValues ? lc->n_cs_precedes : lc->p_cs_precedes; 0037 const char space = negativeValues ? lc->n_sep_by_space : lc->p_sep_by_space; 0038 if (precedes != 0) { 0039 rc = (space != 0) ? platformTools::BeforeQuantityMoneyWithSpace : platformTools::BeforeQuantityMoney; 0040 } else { 0041 rc = (space != 0) ? platformTools::AfterQuantityMoneyWithSpace : platformTools::AfterQuantityMoney; 0042 } 0043 } 0044 0045 if (rc > AfterQuantityMoneyWithSpace) { 0046 qDebug("currencySymbolPosition for %s values from locale is out of bounds (%d). Reset to default.", negativeValues ? "negative" : "positive", rc); 0047 rc = platformTools::AfterQuantityMoneyWithSpace; 0048 } 0049 return rc; 0050 } 0051 0052 platformTools::currencySignPosition_t platformTools::currencySignPosition(bool negativeValues) 0053 { 0054 platformTools::currencySignPosition_t rc = platformTools::PreceedQuantityAndSymbol; 0055 struct lconv* lc = std::localeconv(); 0056 if (lc) { 0057 rc = static_cast<platformTools::currencySignPosition_t>(negativeValues ? lc->n_sign_posn : lc->p_sign_posn); 0058 } 0059 0060 if (rc > SucceedSymbol) { 0061 qDebug("currencySignPosition for %s values from locale is out of bounds (%d). Reset to default.", negativeValues ? "negative" : "positive", rc); 0062 rc = platformTools::PreceedQuantityAndSymbol; 0063 } 0064 return rc; 0065 }