Skip to content

Commit

Permalink
Fix the template file name in the DocType editor.
Browse files Browse the repository at this point in the history
Always consider the language.
  • Loading branch information
dragotin committed Oct 15, 2018
1 parent c1f9a8d commit 48124bc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
14 changes: 11 additions & 3 deletions src/doctype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,17 @@ QString DocType::templateFile( const QString& lang )

QString DocType::defaultTemplateFile() const
{
const QString findFile = "kraft/reports/invoice.trml";
const QString re = QStandardPaths::locate(QStandardPaths::GenericDataLocation, findFile);
return re;
// first check for a country specific file
const QString country = DefaultProvider::self()->locale()->bcp47Name();
QString findFile = QString("kraft/reports/%1/invoice.trml").arg(country);
QString re = QStandardPaths::locate(QStandardPaths::GenericDataLocation, findFile);

if( re.isEmpty() ) {
// No lang specific one.
findFile = "kraft/reports/invoice.trml";
re = QStandardPaths::locate(QStandardPaths::GenericDataLocation, findFile);
}
return re;
}

void DocType::setTemplateFile( const QString& name )
Expand Down
2 changes: 1 addition & 1 deletion src/doctype.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class KRAFTCAT_EXPORT DocType
void setNumberCycleName( const QString& );

QString defaultTemplateFile() const;
QString templateFile( const QString& language = QString() );
QString templateFile( const QString& language );
void setTemplateFile( const QString& );

QString watermarkFile();
Expand Down
6 changes: 4 additions & 2 deletions src/doctypeedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ void DocTypeEdit::slotDocTypeSelected( const QString& newValue )
mNumberCycleCombo->setCurrentIndex(mNumberCycleCombo->findText( dt.numberCycleName() ));
// mHeader->setText( i18n( "Details for %1:", dt.name() ) );
mExampleId->setText( dt.generateDocumentIdent( 0, nextNum ) );
mTemplateUrl->setText( dt.templateFile() );

const QString country = DefaultProvider::self()->locale()->bcp47Name();
mTemplateUrl->setText( dt.templateFile(country) );

mWatermarkUrl->setText( dt.watermarkFile() );
int mergeIdent = dt.mergeIdent().toInt();
Expand Down Expand Up @@ -326,7 +328,7 @@ void DocTypeEdit::slotTemplateUrlChanged( const QString& newUrl )
dt = mChangedDocTypes[docType];
}

if ( newUrl != dt.templateFile() ) {
if ( newUrl != dt.defaultTemplateFile() ) {
dt.setTemplateFile( newUrl );
mChangedDocTypes[docType] = dt;
}
Expand Down
2 changes: 1 addition & 1 deletion src/reportgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ QString ReportGenerator::findTemplate( const QString& type )

if ( tmplFile.isEmpty() ) {
QMessageBox msgBox;
msgBox.setText(i18n("A document template named %1 could not be loaded. ", dType.templateFile()));
msgBox.setText(i18n("A document template named %1 could not be loaded. ", tmplFile));
msgBox.setInformativeText(i18n("Please check your installation!"));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
Expand Down

0 comments on commit 48124bc

Please sign in to comment.