cmake-gui: Fix code to respect current locale.

This means non-ascii characters now work correctly on systems that
have a non-ascii 8 bit encoding as the current locale.
This commit is contained in:
Clinton Stimpson 2012-07-06 13:26:39 -06:00
parent 370c422def
commit ecfc53da7e
6 changed files with 90 additions and 86 deletions

View File

@ -15,7 +15,7 @@
#include <QCompleter>
static const int NumTypes = 4;
static const QString TypeStrings[NumTypes] =
static const QByteArray TypeStrings[NumTypes] =
{ "BOOL", "PATH", "FILEPATH", "STRING" };
static const QCMakeProperty::PropertyType Types[NumTypes] =
{ QCMakeProperty::BOOL, QCMakeProperty::PATH,

View File

@ -125,7 +125,7 @@ int main(int argc, char** argv)
// pick up translation files if they exists in the data directory
QDir translationsDir = cmExecDir;
translationsDir.cd(".." CMAKE_DATA_DIR);
translationsDir.cd(QString::fromLocal8Bit(".." CMAKE_DATA_DIR));
translationsDir.cd("i18n");
QTranslator translator;
QString transfile = QString("cmake_%1").arg(QLocale::system().name());
@ -157,15 +157,15 @@ int main(int argc, char** argv)
arg.Parse();
if(!sourceDirectory.empty() && !binaryDirectory.empty())
{
dialog.setSourceDirectory(sourceDirectory.c_str());
dialog.setBinaryDirectory(binaryDirectory.c_str());
dialog.setSourceDirectory(QString::fromLocal8Bit(sourceDirectory.c_str()));
dialog.setBinaryDirectory(QString::fromLocal8Bit(binaryDirectory.c_str()));
}
else
{
QStringList args = app.arguments();
if(args.count() == 2)
{
cmsys_stl::string filePath = cmSystemTools::CollapseFullPath(args[1].toAscii().data());
cmsys_stl::string filePath = cmSystemTools::CollapseFullPath(args[1].toLocal8Bit().data());
// check if argument is a directory containing CMakeCache.txt
cmsys_stl::string buildFilePath =
@ -184,12 +184,18 @@ int main(int argc, char** argv)
if(cmSystemTools::FileExists(buildFilePath.c_str()))
{
dialog.setBinaryDirectory(cmSystemTools::GetFilenamePath(buildFilePath).c_str());
dialog.setBinaryDirectory(
QString::fromLocal8Bit(
cmSystemTools::GetFilenamePath(buildFilePath).c_str()
)
);
}
else if(cmSystemTools::FileExists(srcFilePath.c_str()))
{
dialog.setSourceDirectory(filePath.c_str());
dialog.setBinaryDirectory(cmSystemTools::CollapseFullPath(".").c_str());
dialog.setSourceDirectory(QString::fromLocal8Bit(filePath.c_str()));
dialog.setBinaryDirectory(
QString::fromLocal8Bit(cmSystemTools::CollapseFullPath(".").c_str())
);
}
}
}

View File

@ -299,9 +299,8 @@ bool CMakeSetupDialog::prepareConfigure()
if(!dir.exists())
{
QString msg = tr("Build directory does not exist, "
"should I create it?")
+ "\n\n"
+ tr("Directory: ");
"should I create it?\n\n"
"Directory: ");
msg += bindir;
QString title = tr("Create Directory");
QMessageBox::StandardButton btn;
@ -490,9 +489,9 @@ void CMakeSetupDialog::closeEvent(QCloseEvent* e)
// don't close if we're busy, unless the user really wants to
if(this->CurrentState == Configuring)
{
QString msg = "You are in the middle of a Configure.\n"
QString msg = tr("You are in the middle of a Configure.\n"
"If you Exit now the configure information will be lost.\n"
"Are you sure you want to Exit?";
"Are you sure you want to Exit?");
QString title = tr("Confirm Exit");
QMessageBox::StandardButton btn;
btn = QMessageBox::critical(this, title, msg,
@ -715,33 +714,33 @@ bool CMakeSetupDialog::setupFirstConfigure()
QString mode = dialog.getCrossIncludeMode();
m->insertProperty(QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_INCLUDE",
"CMake Find Include Mode", mode, false);
tr("CMake Find Include Mode"), mode, false);
mode = dialog.getCrossLibraryMode();
m->insertProperty(QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_LIBRARY",
"CMake Find Library Mode", mode, false);
tr("CMake Find Library Mode"), mode, false);
mode = dialog.getCrossProgramMode();
m->insertProperty(QCMakeProperty::STRING, "CMAKE_FIND_ROOT_PATH_MODE_PROGRAM",
"CMake Find Program Mode", mode, false);
tr("CMake Find Program Mode"), mode, false);
QString rootPath = dialog.getCrossRoot();
m->insertProperty(QCMakeProperty::PATH, "CMAKE_FIND_ROOT_PATH",
"CMake Find Root Path", rootPath, false);
tr("CMake Find Root Path"), rootPath, false);
QString systemName = dialog.getSystemName();
m->insertProperty(QCMakeProperty::STRING, "CMAKE_SYSTEM_NAME",
"CMake System Name", systemName, false);
tr("CMake System Name"), systemName, false);
QString cxxCompiler = dialog.getCXXCompiler();
m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER",
"CXX compiler.", cxxCompiler, false);
tr("CXX compiler."), cxxCompiler, false);
QString cCompiler = dialog.getCCompiler();
m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_C_COMPILER",
"C compiler.", cCompiler, false);
tr("C compiler."), cCompiler, false);
}
else if(dialog.crossCompilerToolChainFile())
{
QString toolchainFile = dialog.getCrossCompilerToolChainFile();
m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_TOOLCHAIN_FILE",
"Cross Compile ToolChain File", toolchainFile, false);
tr("Cross Compile ToolChain File"), toolchainFile, false);
}
return true;
}
@ -772,7 +771,7 @@ void CMakeSetupDialog::doReloadCache()
void CMakeSetupDialog::doDeleteCache()
{
QString title = tr("Delete Cache");
QString msg = "Are you sure you want to delete the cache?";
QString msg = tr("Are you sure you want to delete the cache?");
QMessageBox::StandardButton btn;
btn = QMessageBox::information(this, title, msg,
QMessageBox::Yes | QMessageBox::No);
@ -786,9 +785,9 @@ void CMakeSetupDialog::doDeleteCache()
void CMakeSetupDialog::doAbout()
{
QString msg = "CMake %1\n"
QString msg = tr("CMake %1\n"
"Using Qt %2\n"
"www.cmake.org";
"www.cmake.org");
msg = msg.arg(cmVersion::GetCMakeVersion());
msg = msg.arg(qVersion());

View File

@ -17,10 +17,10 @@ StartCompilerSetup::StartCompilerSetup(QWidget* p)
l->addWidget(this->GeneratorOptions);
l->addSpacing(6);
this->CompilerSetupOptions[0] = new QRadioButton("Use default native compilers", this);
this->CompilerSetupOptions[1] = new QRadioButton("Specify native compilers", this);
this->CompilerSetupOptions[2] = new QRadioButton("Specify toolchain file for cross-compiling", this);
this->CompilerSetupOptions[3] = new QRadioButton("Specify options for cross-compiling", this);
this->CompilerSetupOptions[0] = new QRadioButton(tr("Use default native compilers"), this);
this->CompilerSetupOptions[1] = new QRadioButton(tr("Specify native compilers"), this);
this->CompilerSetupOptions[2] = new QRadioButton(tr("Specify toolchain file for cross-compiling"), this);
this->CompilerSetupOptions[3] = new QRadioButton(tr("Specify options for cross-compiling"), this);
l->addWidget(this->CompilerSetupOptions[0]);
l->addWidget(this->CompilerSetupOptions[1]);
l->addWidget(this->CompilerSetupOptions[2]);
@ -159,9 +159,9 @@ CrossCompilerSetup::CrossCompilerSetup(QWidget* p)
// fill in combo boxes
QStringList modes;
modes << "Search in Target Root, then native system";
modes << "Search only in Target Root";
modes << "Search only in native system";
modes << tr("Search in Target Root, then native system");
modes << tr("Search only in Target Root");
modes << tr("Search only in native system");
crossProgramMode->addItems(modes);
crossLibraryMode->addItems(modes);
crossIncludeMode->addItems(modes);

View File

@ -46,16 +46,16 @@ QCMake::QCMake(QObject* p)
}
#endif
QString cmakeCommand = QString("cmake")+cmSystemTools::GetExecutableExtension();
QString cmakeCommand = QString("cmake")+QString::fromLocal8Bit(cmSystemTools::GetExecutableExtension());
cmakeCommand = execDir.filePath(cmakeCommand);
cmSystemTools::DisableRunCommandOutput();
cmSystemTools::SetRunCommandHideConsole(true);
cmSystemTools::SetErrorCallback(QCMake::errorCallback, this);
cmSystemTools::FindExecutableDirectory(cmakeCommand.toAscii().data());
cmSystemTools::FindExecutableDirectory(cmakeCommand.toLocal8Bit().data());
this->CMakeInstance = new cmake;
this->CMakeInstance->SetCMakeCommand(cmakeCommand.toAscii().data());
this->CMakeInstance->SetCMakeCommand(cmakeCommand.toLocal8Bit().data());
#if defined(Q_OS_MAC)
this->CMakeInstance->SetCMakeEditCommand("cmake-gui.app/Contents/MacOS/cmake-gui");
#else
@ -79,7 +79,7 @@ QCMake::QCMake(QObject* p)
{
continue;
}
this->AvailableGenerators.append(iter->c_str());
this->AvailableGenerators.append(QString::fromLocal8Bit(iter->c_str()));
}
}
@ -97,7 +97,7 @@ void QCMake::loadCache(const QString& dir)
void QCMake::setSourceDirectory(const QString& _dir)
{
QString dir =
cmSystemTools::GetActualCaseForPath(_dir.toAscii().data()).c_str();
QString::fromLocal8Bit(cmSystemTools::GetActualCaseForPath(_dir.toLocal8Bit().data()).c_str());
if(this->SourceDirectory != dir)
{
this->SourceDirectory = QDir::fromNativeSeparators(dir);
@ -108,7 +108,7 @@ void QCMake::setSourceDirectory(const QString& _dir)
void QCMake::setBinaryDirectory(const QString& _dir)
{
QString dir =
cmSystemTools::GetActualCaseForPath(_dir.toAscii().data()).c_str();
QString::fromLocal8Bit(cmSystemTools::GetActualCaseForPath(_dir.toLocal8Bit().data()).c_str());
if(this->BinaryDirectory != dir)
{
this->BinaryDirectory = QDir::fromNativeSeparators(dir);
@ -132,14 +132,14 @@ void QCMake::setBinaryDirectory(const QString& _dir)
cmCacheManager::CacheIterator itm = cachem->NewIterator();
if ( itm.Find("CMAKE_HOME_DIRECTORY"))
{
setSourceDirectory(itm.GetValue());
setSourceDirectory(QString::fromLocal8Bit(itm.GetValue()));
}
if ( itm.Find("CMAKE_GENERATOR"))
{
const char* extraGen = cachem->GetCacheValue("CMAKE_EXTRA_GENERATOR");
std::string curGen = cmExternalMakefileProjectGenerator::
CreateFullGeneratorName(itm.GetValue(), extraGen);
this->setGenerator(curGen.c_str());
this->setGenerator(QString::fromLocal8Bit(curGen.c_str()));
}
}
}
@ -160,12 +160,12 @@ void QCMake::configure()
UINT lastErrorMode = SetErrorMode(0);
#endif
this->CMakeInstance->SetHomeDirectory(this->SourceDirectory.toAscii().data());
this->CMakeInstance->SetStartDirectory(this->SourceDirectory.toAscii().data());
this->CMakeInstance->SetHomeOutputDirectory(this->BinaryDirectory.toAscii().data());
this->CMakeInstance->SetStartOutputDirectory(this->BinaryDirectory.toAscii().data());
this->CMakeInstance->SetHomeDirectory(this->SourceDirectory.toLocal8Bit().data());
this->CMakeInstance->SetStartDirectory(this->SourceDirectory.toLocal8Bit().data());
this->CMakeInstance->SetHomeOutputDirectory(this->BinaryDirectory.toLocal8Bit().data());
this->CMakeInstance->SetStartOutputDirectory(this->BinaryDirectory.toLocal8Bit().data());
this->CMakeInstance->SetGlobalGenerator(
this->CMakeInstance->CreateGlobalGenerator(this->Generator.toAscii().data()));
this->CMakeInstance->CreateGlobalGenerator(this->Generator.toLocal8Bit().data()));
this->CMakeInstance->LoadCache();
this->CMakeInstance->SetSuppressDevWarnings(this->SuppressDevWarnings);
this->CMakeInstance->SetWarnUninitialized(this->WarnUninitializedMode);
@ -222,11 +222,11 @@ void QCMake::setProperties(const QCMakePropertyList& newProps)
}
QCMakeProperty prop;
prop.Key = i.GetName();
prop.Key = QString::fromLocal8Bit(i.GetName());
int idx = props.indexOf(prop);
if(idx == -1)
{
toremove.append(i.GetName());
toremove.append(QString::fromLocal8Bit(i.GetName()));
}
else
{
@ -237,7 +237,7 @@ void QCMake::setProperties(const QCMakePropertyList& newProps)
}
else
{
i.SetValue(prop.Value.toString().toAscii().data());
i.SetValue(prop.Value.toString().toLocal8Bit().data());
}
props.removeAt(idx);
}
@ -247,47 +247,47 @@ void QCMake::setProperties(const QCMakePropertyList& newProps)
// remove some properites
foreach(QString s, toremove)
{
this->CMakeInstance->UnwatchUnusedCli(s.toAscii().data());
this->CMakeInstance->UnwatchUnusedCli(s.toLocal8Bit().data());
cachem->RemoveCacheEntry(s.toAscii().data());
cachem->RemoveCacheEntry(s.toLocal8Bit().data());
}
// add some new properites
foreach(QCMakeProperty s, props)
{
this->CMakeInstance->WatchUnusedCli(s.Key.toAscii().data());
this->CMakeInstance->WatchUnusedCli(s.Key.toLocal8Bit().data());
if(s.Type == QCMakeProperty::BOOL)
{
this->CMakeInstance->AddCacheEntry(s.Key.toAscii().data(),
this->CMakeInstance->AddCacheEntry(s.Key.toLocal8Bit().data(),
s.Value.toBool() ? "ON" : "OFF",
s.Help.toAscii().data(),
s.Help.toLocal8Bit().data(),
cmCacheManager::BOOL);
}
else if(s.Type == QCMakeProperty::STRING)
{
this->CMakeInstance->AddCacheEntry(s.Key.toAscii().data(),
s.Value.toString().toAscii().data(),
s.Help.toAscii().data(),
this->CMakeInstance->AddCacheEntry(s.Key.toLocal8Bit().data(),
s.Value.toString().toLocal8Bit().data(),
s.Help.toLocal8Bit().data(),
cmCacheManager::STRING);
}
else if(s.Type == QCMakeProperty::PATH)
{
this->CMakeInstance->AddCacheEntry(s.Key.toAscii().data(),
s.Value.toString().toAscii().data(),
s.Help.toAscii().data(),
this->CMakeInstance->AddCacheEntry(s.Key.toLocal8Bit().data(),
s.Value.toString().toLocal8Bit().data(),
s.Help.toLocal8Bit().data(),
cmCacheManager::PATH);
}
else if(s.Type == QCMakeProperty::FILEPATH)
{
this->CMakeInstance->AddCacheEntry(s.Key.toAscii().data(),
s.Value.toString().toAscii().data(),
s.Help.toAscii().data(),
this->CMakeInstance->AddCacheEntry(s.Key.toLocal8Bit().data(),
s.Value.toString().toLocal8Bit().data(),
s.Help.toLocal8Bit().data(),
cmCacheManager::FILEPATH);
}
}
cachem->SaveCache(this->BinaryDirectory.toAscii().data());
cachem->SaveCache(this->BinaryDirectory.toLocal8Bit().data());
}
QCMakePropertyList QCMake::properties() const
@ -307,9 +307,9 @@ QCMakePropertyList QCMake::properties() const
}
QCMakeProperty prop;
prop.Key = i.GetName();
prop.Help = i.GetProperty("HELPSTRING");
prop.Value = i.GetValue();
prop.Key = QString::fromLocal8Bit(i.GetName());
prop.Help = QString::fromLocal8Bit(i.GetProperty("HELPSTRING"));
prop.Value = QString::fromLocal8Bit(i.GetValue());
prop.Advanced = i.GetPropertyAsBool("ADVANCED");
if(i.GetType() == cmCacheManager::BOOL)
@ -330,7 +330,7 @@ QCMakePropertyList QCMake::properties() const
prop.Type = QCMakeProperty::STRING;
if (i.PropertyExists("STRINGS"))
{
prop.Strings = QString(i.GetProperty("STRINGS")).split(";");
prop.Strings = QString::fromLocal8Bit(i.GetProperty("STRINGS")).split(";");
}
}
@ -356,11 +356,11 @@ void QCMake::progressCallback(const char* msg, float percent, void* cd)
QCMake* self = reinterpret_cast<QCMake*>(cd);
if(percent >= 0)
{
emit self->progressChanged(msg, percent);
emit self->progressChanged(QString::fromLocal8Bit(msg), percent);
}
else
{
emit self->outputMessage(msg);
emit self->outputMessage(QString::fromLocal8Bit(msg));
}
QCoreApplication::processEvents();
}
@ -369,7 +369,7 @@ void QCMake::errorCallback(const char* msg, const char* /*title*/,
bool& /*stop*/, void* cd)
{
QCMake* self = reinterpret_cast<QCMake*>(cd);
emit self->errorMessage(msg);
emit self->errorMessage(QString::fromLocal8Bit(msg));
QCoreApplication::processEvents();
}
@ -396,9 +396,9 @@ QStringList QCMake::availableGenerators() const
void QCMake::deleteCache()
{
// delete cache
this->CMakeInstance->GetCacheManager()->DeleteCache(this->BinaryDirectory.toAscii().data());
this->CMakeInstance->GetCacheManager()->DeleteCache(this->BinaryDirectory.toLocal8Bit().data());
// reload to make our cache empty
this->CMakeInstance->GetCacheManager()->LoadCache(this->BinaryDirectory.toAscii().data());
this->CMakeInstance->GetCacheManager()->LoadCache(this->BinaryDirectory.toLocal8Bit().data());
// emit no generator and no properties
this->setGenerator(QString());
QCMakePropertyList props = this->properties();
@ -411,7 +411,7 @@ void QCMake::reloadCache()
QCMakePropertyList props;
emit this->propertiesChanged(props);
// reload
this->CMakeInstance->GetCacheManager()->LoadCache(this->BinaryDirectory.toAscii().data());
this->CMakeInstance->GetCacheManager()->LoadCache(this->BinaryDirectory.toLocal8Bit().data());
// emit new cache properties
props = this->properties();
emit this->propertiesChanged(props);

View File

@ -34,12 +34,11 @@ void QMacInstallDialog::DoInstall()
{
QDir installDir(this->Internals->InstallPrefix->text());
QString installTo = installDir.path();
if(!cmSystemTools::FileExists(installTo.toAscii().data()))
if(!cmSystemTools::FileExists(installTo.toLocal8Bit().data()))
{
QString message = tr("Build install does not exist, "
"should I create it?")
+ "\n\n"
+ tr("Directory: ");
"should I create it?\n\n"
"Directory: ");
message += installDir.path();
QString title = tr("Create Directory");
QMessageBox::StandardButton btn;
@ -47,7 +46,7 @@ void QMacInstallDialog::DoInstall()
QMessageBox::Yes | QMessageBox::No);
if(btn == QMessageBox::Yes)
{
cmSystemTools::MakeDirectory(installTo.toAscii().data());
cmSystemTools::MakeDirectory(installTo.toLocal8Bit().data());
}
}
QDir cmExecDir(QApplication::applicationDirPath());
@ -66,14 +65,14 @@ void QMacInstallDialog::DoInstall()
newName += "/";
newName += filename;
// Remove the old files
if(cmSystemTools::FileExists(newName.toAscii().data()))
if(cmSystemTools::FileExists(newName.toLocal8Bit().data()))
{
std::cout << "rm [" << newName.toAscii().data() << "]\n";
if(!cmSystemTools::RemoveFile(newName.toAscii().data()))
std::cout << "rm [" << newName.toLocal8Bit().data() << "]\n";
if(!cmSystemTools::RemoveFile(newName.toLocal8Bit().data()))
{
QString message = tr("Failed to remove file "
"installation may be incomplete: ");
message += newName.toAscii().data();
message += newName;
QString title = tr("Error Removing file");
QMessageBox::StandardButton btn =
QMessageBox::critical(this, title, message,
@ -84,14 +83,14 @@ void QMacInstallDialog::DoInstall()
}
}
}
std::cout << "ln -s [" << file.toAscii().data() << "] [";
std::cout << newName.toAscii().data() << "]\n";
if(!cmSystemTools::CreateSymlink(file.toAscii().data(),
newName.toAscii().data()))
std::cout << "ln -s [" << file.toLocal8Bit().data() << "] [";
std::cout << newName.toLocal8Bit().data() << "]\n";
if(!cmSystemTools::CreateSymlink(file.toLocal8Bit().data(),
newName.toLocal8Bit().data()))
{
QString message = tr("Failed create symlink "
"installation may be incomplete: ");
message += newName.toAscii().data();
message += newName;
QString title = tr("Error Creating Symlink");
QMessageBox::StandardButton btn =
QMessageBox::critical(this, title, message,