File indexing completed on 2024-05-12 16:42:16
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 <windows.h> 0010 #include <lmcons.h> 0011 #include <process.h> 0012 #include <locale.h> 0013 0014 #include <QDebug> 0015 #include <QString> 0016 0017 QString platformTools::osUsername() 0018 { 0019 QString name; 0020 DWORD size = UNLEN+1; 0021 wchar_t wcname[UNLEN+1]; 0022 if(GetUserNameW((LPWSTR) wcname, &size)) { 0023 name = QString::fromWCharArray(wcname); 0024 } 0025 return name; 0026 } 0027 0028 uint platformTools::processId() 0029 { 0030 return _getpid(); 0031 } 0032 0033 static struct lconv* localeconv_with_init() 0034 { 0035 static bool needInit = true; 0036 if (needInit) { 0037 setlocale(LC_ALL, ".UTF8"); 0038 needInit = false; 0039 } 0040 return localeconv(); 0041 } 0042 0043 platformTools::currencySymbolPosition_t platformTools::currencySymbolPosition(bool negativeValues) 0044 { 0045 platformTools::currencySymbolPosition_t rc = platformTools::AfterQuantityMoneyWithSpace; 0046 struct lconv* lc = localeconv_with_init(); 0047 if (lc) { 0048 const char precedes = negativeValues ? lc->n_cs_precedes : lc->p_cs_precedes; 0049 const char space = negativeValues ? lc->n_sep_by_space : lc->p_sep_by_space; 0050 if (precedes != 0) { 0051 rc = (space != 0) ? platformTools::BeforeQuantityMoneyWithSpace : platformTools::BeforeQuantityMoney; 0052 } else { 0053 rc = (space != 0) ? platformTools::AfterQuantityMoneyWithSpace : platformTools::AfterQuantityMoney; 0054 } 0055 } 0056 0057 if (rc > AfterQuantityMoneyWithSpace) { 0058 qDebug("currencySymbolPosition for %s values from locale is out of bounds (%d). Reset to default.", negativeValues ? "negative" : "positive", rc); 0059 rc = platformTools::AfterQuantityMoneyWithSpace; 0060 } 0061 return rc; 0062 } 0063 0064 platformTools::currencySignPosition_t platformTools::currencySignPosition(bool negativeValues) 0065 { 0066 platformTools::currencySignPosition_t rc = platformTools::PreceedQuantityAndSymbol; 0067 struct lconv* lc = localeconv_with_init(); 0068 if (lc) { 0069 rc = static_cast<platformTools::currencySignPosition_t>(negativeValues ? lc->n_sign_posn : lc->p_sign_posn); 0070 } 0071 0072 if (rc > SucceedSymbol) { 0073 qDebug("currencySignPosition for %s values from locale is out of bounds (%d). Reset to default.", negativeValues ? "negative" : "positive", rc); 0074 rc = platformTools::PreceedQuantityAndSymbol; 0075 } 0076 return rc; 0077 }