2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-04-11 21:33:08 +08:00
|
|
|
#include "systemconsts.h"
|
2021-09-14 23:56:08 +08:00
|
|
|
#include "utils.h"
|
2021-04-11 21:33:08 +08:00
|
|
|
#include <QObject>
|
2021-09-14 23:56:08 +08:00
|
|
|
#include <QSet>
|
2021-04-11 21:33:08 +08:00
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
2021-09-14 23:56:08 +08:00
|
|
|
#include <QTextCodec>
|
2021-04-11 21:33:08 +08:00
|
|
|
|
|
|
|
SystemConsts* pSystemConsts;
|
|
|
|
|
|
|
|
SystemConsts::SystemConsts(): mDefaultFileFilters()
|
|
|
|
{
|
2023-01-07 20:29:57 +08:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
addDefaultFileFilter(QObject::tr("All files"),"*.*");
|
|
|
|
#else
|
2021-09-11 18:42:49 +08:00
|
|
|
addDefaultFileFilter(QObject::tr("All files"),"*");
|
2023-01-07 20:29:57 +08:00
|
|
|
#endif
|
2021-09-11 18:42:49 +08:00
|
|
|
addDefaultFileFilter(QObject::tr("Dev C++ Project files"),"*.dev");
|
2021-04-11 21:33:08 +08:00
|
|
|
addDefaultFileFilter(QObject::tr("C files"),"*.c");
|
|
|
|
addDefaultFileFilter(QObject::tr("C++ files"),"*.cpp *.cc *.cxx");
|
2022-12-22 22:01:55 +08:00
|
|
|
addDefaultFileFilter(QObject::tr("Header files"),"*.h *.hh *.hpp");
|
2023-02-12 18:13:24 +08:00
|
|
|
addDefaultFileFilter(QObject::tr("GAS files"),"*.s *.S");
|
2023-02-16 12:26:35 +08:00
|
|
|
addDefaultFileFilter(QObject::tr("Lua files"),"*.lua");
|
2021-09-14 23:56:08 +08:00
|
|
|
|
|
|
|
addFileFilter(mIconFileFilters, QObject::tr("Icon files"), "*.ico");
|
|
|
|
|
|
|
|
mCodecNames.append(ENCODING_AUTO_DETECT);
|
|
|
|
mCodecNames.append(ENCODING_SYSTEM_DEFAULT);
|
|
|
|
mCodecNames.append(ENCODING_UTF8);
|
2022-05-06 15:23:41 +08:00
|
|
|
mCodecNames.append(ENCODING_UTF8_BOM);
|
2021-09-14 23:56:08 +08:00
|
|
|
QStringList codecNames;
|
|
|
|
QSet<QByteArray> codecAlias;
|
|
|
|
codecAlias.insert("system");
|
|
|
|
codecAlias.insert("utf-8");
|
|
|
|
|
|
|
|
foreach (const QByteArray& name, QTextCodec::availableCodecs()){
|
|
|
|
QByteArray lname = name.toLower();
|
|
|
|
if (lname.startsWith("cp"))
|
|
|
|
continue;
|
|
|
|
if (codecAlias.contains(lname))
|
|
|
|
continue;
|
|
|
|
codecNames.append(lname);
|
|
|
|
codecAlias.insert(lname);
|
|
|
|
QTextCodec* codec = QTextCodec::codecForName(name);
|
|
|
|
if (codec) {
|
|
|
|
foreach (const QByteArray& alias, codec->aliases()) {
|
|
|
|
codecAlias.insert(alias.toLower());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::sort(codecNames.begin(),codecNames.end());
|
|
|
|
mCodecNames.append(codecNames);
|
2022-02-28 22:40:09 +08:00
|
|
|
|
|
|
|
mDefaultFileNameFilters.append("*.c");
|
|
|
|
mDefaultFileNameFilters.append("*.cpp");
|
|
|
|
mDefaultFileNameFilters.append("*.cc");
|
|
|
|
mDefaultFileNameFilters.append("*.C");
|
|
|
|
mDefaultFileNameFilters.append("*.cxx");
|
|
|
|
mDefaultFileNameFilters.append("*.cxx");
|
|
|
|
mDefaultFileNameFilters.append("*.h");
|
|
|
|
mDefaultFileNameFilters.append("*.hpp");
|
|
|
|
mDefaultFileNameFilters.append("*.hxx");
|
|
|
|
mDefaultFileNameFilters.append(".gitignore");
|
|
|
|
mDefaultFileNameFilters.append("*.vs");
|
|
|
|
mDefaultFileNameFilters.append("*.fs");
|
|
|
|
mDefaultFileNameFilters.append("*.txt");
|
2022-06-12 15:48:19 +08:00
|
|
|
mDefaultFileNameFilters.append("*.in");
|
|
|
|
mDefaultFileNameFilters.append("*.out");
|
|
|
|
mDefaultFileNameFilters.append("*.dat");
|
2022-02-28 22:40:09 +08:00
|
|
|
mDefaultFileNameFilters.append("*.md");
|
|
|
|
mDefaultFileNameFilters.append("*.dev");
|
2023-06-29 00:27:06 +08:00
|
|
|
mDefaultFileNameFilters.append("*.s");
|
2023-11-18 16:54:44 +08:00
|
|
|
mDefaultFileNameFilters.append("*.ini");
|
2023-06-29 00:27:06 +08:00
|
|
|
mDefaultFileNameFilters.append("*.S");
|
2021-04-11 21:33:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const QStringList &SystemConsts::defaultFileFilters() const noexcept
|
|
|
|
{
|
|
|
|
return mDefaultFileFilters;
|
|
|
|
}
|
|
|
|
|
2024-03-30 00:19:36 +08:00
|
|
|
QString SystemConsts::defaultCFileFilter() const noexcept
|
2021-08-30 18:36:44 +08:00
|
|
|
{
|
2021-09-11 18:42:49 +08:00
|
|
|
return mDefaultFileFilters[2];
|
2021-08-30 18:36:44 +08:00
|
|
|
}
|
|
|
|
|
2024-03-30 00:19:36 +08:00
|
|
|
QString SystemConsts::defaultCPPFileFilter() const noexcept
|
2021-04-11 21:33:08 +08:00
|
|
|
{
|
2021-09-11 18:42:49 +08:00
|
|
|
return mDefaultFileFilters[3];
|
2021-04-11 21:33:08 +08:00
|
|
|
}
|
|
|
|
|
2024-03-30 00:19:36 +08:00
|
|
|
QString SystemConsts::defaultAllFileFilter() const noexcept
|
2021-08-30 19:52:38 +08:00
|
|
|
{
|
2021-09-11 18:42:49 +08:00
|
|
|
return mDefaultFileFilters[0];
|
2021-09-09 00:15:12 +08:00
|
|
|
}
|
|
|
|
|
2024-03-30 00:19:36 +08:00
|
|
|
QString SystemConsts::executableFileFilter() const noexcept
|
2024-03-27 23:55:34 +08:00
|
|
|
{
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
return QObject::tr("Executable files (*.exe)");
|
|
|
|
#else
|
|
|
|
return QObject::tr("All files (*.*)");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-02-12 22:33:34 +08:00
|
|
|
QString SystemConsts::fileFilterFor(const QString &suffix)
|
|
|
|
{
|
|
|
|
QString t="*."+suffix;
|
|
|
|
foreach(const QString filter,mDefaultFileFilters) {
|
|
|
|
int pos = filter.lastIndexOf("(");
|
|
|
|
int pos2 = filter.lastIndexOf(")");
|
|
|
|
if (pos<0 || pos2<=pos)
|
|
|
|
continue;
|
|
|
|
QString suffixes=filter.mid(pos+1,pos2-pos-1);
|
|
|
|
QStringList suffixList = suffixes.split(" ");
|
|
|
|
foreach( const QString& s, suffixList) {
|
|
|
|
if (s.trimmed()==t)
|
|
|
|
return filter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2021-04-11 21:33:08 +08:00
|
|
|
void SystemConsts::addDefaultFileFilter(const QString &name, const QString &fileExtensions)
|
|
|
|
{
|
2021-09-14 23:56:08 +08:00
|
|
|
addFileFilter(mDefaultFileFilters,name,fileExtensions);
|
|
|
|
}
|
|
|
|
|
2021-09-16 23:51:05 +08:00
|
|
|
void SystemConsts::addFileFilter(QStringList& filters, const QString &name, const QString &fileExtensions)
|
2021-09-14 23:56:08 +08:00
|
|
|
{
|
|
|
|
filters.append(name+ " (" + fileExtensions+")");
|
|
|
|
}
|
|
|
|
|
2022-02-28 22:40:09 +08:00
|
|
|
const QStringList &SystemConsts::defaultFileNameFilters() const
|
|
|
|
{
|
|
|
|
return mDefaultFileNameFilters;
|
|
|
|
}
|
|
|
|
|
2021-09-14 23:56:08 +08:00
|
|
|
const QStringList &SystemConsts::codecNames() const
|
|
|
|
{
|
|
|
|
return mCodecNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QStringList &SystemConsts::iconFileFilters() const
|
|
|
|
{
|
|
|
|
return mIconFileFilters;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &SystemConsts::iconFileFilter() const
|
|
|
|
{
|
|
|
|
return mIconFileFilters[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemConsts::setIconFileFilters(const QStringList &newIconFileFilters)
|
|
|
|
{
|
|
|
|
mIconFileFilters = newIconFileFilters;
|
2021-04-11 21:33:08 +08:00
|
|
|
}
|