ENH: Use translation file if it exists for the locale.

Consolidate some strings.

      More responsive interrupting.  Prompt user if they try to close during
      configure, and allow them to close.
This commit is contained in:
Clinton Stimpson 2008-02-01 10:41:29 -05:00
parent 587419db83
commit 41ad9d20df
4 changed files with 46 additions and 29 deletions

View File

@ -18,6 +18,7 @@
#include <QApplication> #include <QApplication>
#include <QFileInfo> #include <QFileInfo>
#include <QDir> #include <QDir>
#include <QTranslator>
#include "CMakeSetupDialog.h" #include "CMakeSetupDialog.h"
#include "cmDocumentation.h" #include "cmDocumentation.h"
@ -64,6 +65,12 @@ int main(int argc, char** argv)
{ {
cmSystemTools::FindExecutableDirectory(argv[0]); cmSystemTools::FindExecutableDirectory(argv[0]);
QApplication app(argc, argv); QApplication app(argc, argv);
QTranslator translator;
QString transfile = QString("cmake_%1").arg(QLocale::system().name());
translator.load(transfile, app.applicationDirPath());
app.installTranslator(&translator);
app.setApplicationName("CMakeSetup"); app.setApplicationName("CMakeSetup");
app.setOrganizationName("Kitware"); app.setOrganizationName("Kitware");
app.setWindowIcon(QIcon(":/Icons/CMakeSetup.png")); app.setWindowIcon(QIcon(":/Icons/CMakeSetup.png"));
@ -99,7 +106,7 @@ int main(int argc, char** argv)
} }
CMakeSetupDialog dialog; CMakeSetupDialog dialog;
dialog.setWindowTitle("CMakeSetup"); dialog.setWindowTitle(QApplication::applicationName());
dialog.show(); dialog.show();
// for now: args support specifying build and/or source directory // for now: args support specifying build and/or source directory

View File

@ -48,19 +48,9 @@ QCMake* QCMakeThread::cmakeInstance() const
return this->CMakeInstance; return this->CMakeInstance;
} }
void QCMakeThread::processEvents()
{
QCoreApplication::processEvents();
}
void QCMakeThread::run() void QCMakeThread::run()
{ {
this->CMakeInstance = new QCMake; this->CMakeInstance = new QCMake;
// make the cmake thread to process events it receives from the GUI thread
QObject::connect(this->CMakeInstance, SIGNAL(progressChanged(QString, float)),
this, SLOT(processEvents()), Qt::DirectConnection);
QObject::connect(this->CMakeInstance, SIGNAL(outputMessage(QString)),
this, SLOT(processEvents()), Qt::DirectConnection);
// emit that this cmake thread is ready for use // emit that this cmake thread is ready for use
emit this->cmakeInitialized(); emit this->cmakeInitialized();
this->exec(); this->exec();
@ -233,7 +223,7 @@ CMakeSetupDialog::~CMakeSetupDialog()
// wait for thread to stop // wait for thread to stop
this->CMakeThread->quit(); this->CMakeThread->quit();
this->CMakeThread->wait(); this->CMakeThread->wait(2000);
} }
void CMakeSetupDialog::doConfigure() void CMakeSetupDialog::doConfigure()
@ -250,8 +240,9 @@ void CMakeSetupDialog::doConfigure()
if(!dir.exists()) if(!dir.exists())
{ {
QString message = tr("Build directory does not exist, " QString message = tr("Build directory does not exist, "
"should I create it?\n\n" "should I create it?")
"Directory: "); + "\n\n"
+ tr("Directory: ");
message += bindir; message += bindir;
QString title = tr("Create Directory"); QString title = tr("Create Directory");
QMessageBox::StandardButton btn; QMessageBox::StandardButton btn;
@ -330,13 +321,7 @@ void CMakeSetupDialog::doGenerate()
void CMakeSetupDialog::closeEvent(QCloseEvent* e) void CMakeSetupDialog::closeEvent(QCloseEvent* e)
{ {
// don't close if we're busy // prompt for close if there are unsaved changes, and we're not busy
if(this->CurrentState == Configuring || this->CurrentState == Generating)
{
e->ignore();
}
// prompt for close if there are unsaved changes
if(this->CacheModified) if(this->CacheModified)
{ {
QString message = tr("You have changed options but not rebuilt, " QString message = tr("You have changed options but not rebuilt, "
@ -350,6 +335,32 @@ void CMakeSetupDialog::closeEvent(QCloseEvent* e)
e->ignore(); e->ignore();
} }
} }
// don't close if we're busy, unless the user really wants to
if(this->CurrentState == Configuring)
{
QString message = "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?";
QString title = tr("Confirm Exit");
QMessageBox::StandardButton btn;
btn = QMessageBox::critical(this, title, message,
QMessageBox::Yes | QMessageBox::No);
if(btn == QMessageBox::No)
{
e->ignore();
}
else
{
this->doInterrupt();
}
}
// let the generate finish
if(this->CurrentState == Generating)
{
e->ignore();
}
} }
void CMakeSetupDialog::doHelp() void CMakeSetupDialog::doHelp()
@ -373,7 +384,7 @@ void CMakeSetupDialog::doHelp()
"directory."); "directory.");
QDialog dialog; QDialog dialog;
dialog.setWindowTitle(tr("CMakeSetup Help")); dialog.setWindowTitle(tr("Help"));
QVBoxLayout* l = new QVBoxLayout(&dialog); QVBoxLayout* l = new QVBoxLayout(&dialog);
QLabel* lab = new QLabel(&dialog); QLabel* lab = new QLabel(&dialog);
l->addWidget(lab); l->addWidget(lab);
@ -484,7 +495,7 @@ void CMakeSetupDialog::promptForGenerator()
QStringList gens = this->CMakeThread->cmakeInstance()->availableGenerators(); QStringList gens = this->CMakeThread->cmakeInstance()->availableGenerators();
QDialog dialog; QDialog dialog;
dialog.setWindowTitle(tr("CMakeSetup choose generator")); dialog.setWindowTitle(tr("Choose Generator"));
QLabel* lab = new QLabel(&dialog); QLabel* lab = new QLabel(&dialog);
lab->setText(tr("Please select what build system you want CMake to generate files for.\n" lab->setText(tr("Please select what build system you want CMake to generate files for.\n"
"You should select the tool that you will use to build the project.\n" "You should select the tool that you will use to build the project.\n"
@ -539,10 +550,10 @@ void CMakeSetupDialog::doDeleteCache()
void CMakeSetupDialog::doAbout() void CMakeSetupDialog::doAbout()
{ {
QString msg = "CMakeSetup\nwww.cmake.org"; QString msg = QApplication::applicationName() + "\nwww.cmake.org";
QDialog dialog; QDialog dialog;
dialog.setWindowTitle(tr("About CMakeSetup")); dialog.setWindowTitle(tr("About"));
QVBoxLayout* l = new QVBoxLayout(&dialog); QVBoxLayout* l = new QVBoxLayout(&dialog);
QLabel* lab = new QLabel(&dialog); QLabel* lab = new QLabel(&dialog);
l->addWidget(lab); l->addWidget(lab);
@ -762,7 +773,7 @@ void CMakeSetupDialog::addCacheEntry()
{ {
QDialog dialog(this); QDialog dialog(this);
dialog.resize(400, 200); dialog.resize(400, 200);
dialog.setWindowTitle(tr("CMakeSetup Help")); dialog.setWindowTitle(tr("Add Cache Entry"));
QVBoxLayout* l = new QVBoxLayout(&dialog); QVBoxLayout* l = new QVBoxLayout(&dialog);
AddCacheEntry* w = new AddCacheEntry(&dialog); AddCacheEntry* w = new AddCacheEntry(&dialog);
QDialogButtonBox* btns = new QDialogButtonBox( QDialogButtonBox* btns = new QDialogButtonBox(

View File

@ -103,9 +103,6 @@ public:
signals: signals:
void cmakeInitialized(); void cmakeInitialized();
protected slots:
void processEvents();
protected: protected:
virtual void run(); virtual void run();
QCMake* CMakeInstance; QCMake* CMakeInstance;

View File

@ -292,6 +292,7 @@ void QCMake::progressCallback(const char* msg, float percent, void* cd)
{ {
emit self->outputMessage(msg); emit self->outputMessage(msg);
} }
QCoreApplication::processEvents();
} }
void QCMake::errorCallback(const char* msg, const char* /*title*/, void QCMake::errorCallback(const char* msg, const char* /*title*/,
@ -299,6 +300,7 @@ void QCMake::errorCallback(const char* msg, const char* /*title*/,
{ {
QCMake* self = reinterpret_cast<QCMake*>(cd); QCMake* self = reinterpret_cast<QCMake*>(cd);
emit self->errorMessage(msg); emit self->errorMessage(msg);
QCoreApplication::processEvents();
} }
QString QCMake::binaryDirectory() const QString QCMake::binaryDirectory() const