- enhancement: suppoort localization info in project templates

- change: template / project files use utf-8 encoding instead of ANSI
This commit is contained in:
Roy Qu 2022-01-08 11:46:39 +08:00
parent 2d9472d179
commit 6bc943ba9c
7 changed files with 41 additions and 5 deletions

View File

@ -1,3 +1,8 @@
Red Panda C++ Version 0.13.1
- enhancement: suppoort localization info in project templates
- change: template / project files use utf-8 encoding instead of ANSI
Red Panda C++ Version 0.12.7
- change: make current build system follow FHS specifications
- fix: crash when close settings dialog in Ubuntu 20.04 (but we'll leak memory now...)

View File

@ -18,6 +18,7 @@
#include <QFile>
#include <QMessageBox>
#include "mainwindow.h"
#include "settings.h"
ProjectTemplate::ProjectTemplate(QObject *parent) : QObject(parent)
{
@ -105,11 +106,20 @@ void ProjectTemplate::readTemplateFile(const QString &fileName)
return;
}
QString lang = pSettings->environment().language();
// template info
mDescription = fromByteArray(mIni->GetValue("Template", "Description", ""));
mIcon = fromByteArray(mIni->GetValue("Template", "Icon", ""));
mCategory = fromByteArray(mIni->GetValue("Template", "Category", ""));
mName = fromByteArray(mIni->GetValue("Template", "Name", ""));
if (!lang.isEmpty()) {
mCategory = fromByteArray(mIni->GetValue("Template", QString("Category[%1]").arg(lang).toUtf8(), ""));
mName = fromByteArray(mIni->GetValue("Template", QString("Name[%1]").arg(lang).toUtf8(), ""));
mDescription = fromByteArray(mIni->GetValue("Template", QString("Description[%1]").arg(lang).toUtf8(), ""));
}
if (mCategory.isEmpty())
mCategory = fromByteArray(mIni->GetValue("Template", "Category", ""));
if (mName.isEmpty())
mName = fromByteArray(mIni->GetValue("Template", "Name", ""));
if (mDescription.isEmpty())
mDescription = fromByteArray(mIni->GetValue("Template", "Description", ""));
mOptions.icon = mIni->GetValue("Project", "Icon", "");
mOptions.type = static_cast<ProjectType>(mIni->GetLongValue("Project", "Type", 0)); // default = gui

View File

@ -776,12 +776,20 @@ QString extractFileDir(const QString &fileName)
QByteArray toByteArray(const QString &s)
{
return s.toLocal8Bit();
//return s.toLocal8Bit();
return s.toUtf8();
}
QString fromByteArray(const QByteArray &s)
{
return QString::fromLocal8Bit(s);
QTextCodec* codec = QTextCodec::codecForName(ENCODING_UTF8);
QTextCodec::ConverterState state;
if (!codec)
return QString(s);
QString tmp = codec->toUnicode(s,s.length(),&state);
if (state.invalidChars>0)
tmp = QString::fromLocal8Bit(s);
return tmp;
}
QString linesToText(const QStringList &lines)

View File

@ -173,6 +173,7 @@ void NewProjectDialog::updateView()
icon,
t->name());
}
item->setData(Qt::ToolTipRole,t->name());
item->setData(Qt::UserRole,i);
ui->lstTemplates->addItem(item);
}

View File

@ -22,6 +22,12 @@
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="uniformItemSizes">
<bool>true</bool>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
<property name="itemAlignment">
<set>Qt::AlignCenter</set>
</property>

View File

@ -1,9 +1,12 @@
[Template]
ver=1
Name=Windows Application
Name[zh_CN]=Windows应用程序
Icon=Windows.ico
Description=A standard Windows application
Description[zh_CN]=基于Windows API开发的图形界面应用程序
Category=Basic
Category[zh_CN]=基础
[Unit0]
CName=main.c

View File

@ -1,9 +1,12 @@
[Template]
ver=1
Name=Console Application
Name[zh_CN]=控制台程序
Icon=ConsoleToo.ico
Description=A console application (MS-DOS window)
Description[zh_CN]=控制台应用程序
Category=Basic
Category[zh_CN]=基础
[Unit0]
CName=main.c