mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Improve translatability of the application
Head towards a translatable application by loading translation files for the current locale and using tr() where ever it's needed.
This commit is contained in:
@@ -89,9 +89,7 @@ void CreateIndexDialog::accept()
|
||||
sql.append(");");
|
||||
|
||||
if(pdb->executeSQL(sql))
|
||||
{
|
||||
QDialog::accept();
|
||||
} else {
|
||||
QMessageBox::warning(this, QApplication::applicationName(), tr("Creating the index failed:\n").arg(pdb->lastErrorMessage));
|
||||
}
|
||||
else
|
||||
QMessageBox::warning(this, QApplication::applicationName(), tr("Creating the index failed:\n%1").arg(pdb->lastErrorMessage));
|
||||
}
|
||||
|
||||
@@ -41,13 +41,12 @@ void EditDialog::setDataType(int type, int size)
|
||||
{
|
||||
case kSQLiteMediaType_String:
|
||||
ui->labelType->setText(tr("Type of data currently in cell: Text / Numeric"));
|
||||
if(ui->editData->toPlainText().length() == 1) charstr = QString("char"); else charstr = QString("chars");
|
||||
ui->labelSize->setText(QString("%1 %2").arg(ui->editData->toPlainText().length()).arg(charstr));
|
||||
ui->labelSize->setText(tr("%n char(s)", "", ui->editData->toPlainText().length()));
|
||||
enableExport(true);
|
||||
break;
|
||||
case kSQLiteMediaType_Void:
|
||||
ui->labelType->setText("Type of data currently in cell: Empty");
|
||||
ui->labelSize->setText("");
|
||||
ui->labelType->setText(tr("Type of data currently in cell: Empty"));
|
||||
ui->labelSize->setText(tr(""));
|
||||
enableExport(false);
|
||||
break;
|
||||
}
|
||||
@@ -78,7 +77,7 @@ void EditDialog::importData()
|
||||
this,
|
||||
tr("Choose a file"),
|
||||
defaultlocation,
|
||||
QString("Text files(*.txt);;All files(*)"));
|
||||
tr("Text files(*.txt);;All files(*)"));
|
||||
if(QFile::exists(fileName))
|
||||
{
|
||||
type = kSQLiteMediaType_String;
|
||||
@@ -99,7 +98,7 @@ void EditDialog::exportData()
|
||||
switch (dataType)
|
||||
{
|
||||
case kSQLiteMediaType_String:
|
||||
filter = "Text files(*.txt)";
|
||||
filter = tr("Text files(*.txt)");
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
@@ -107,7 +106,7 @@ void EditDialog::exportData()
|
||||
|
||||
QString fileName = QFileDialog::getSaveFileName(
|
||||
this,
|
||||
"Choose a filename to export data",
|
||||
tr("Choose a filename to export data"),
|
||||
defaultlocation,
|
||||
filter);
|
||||
|
||||
@@ -144,7 +143,7 @@ void EditDialog::accept()
|
||||
emit updateRecordText(curRow, curCol, ui->editData->toPlainText());
|
||||
|
||||
if (dataType == kSQLiteMediaType_Void)
|
||||
emit updateRecordText(curRow, curCol, QString(""));
|
||||
emit updateRecordText(curRow, curCol, "");
|
||||
|
||||
emit goingAway();
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ void EditTableDialog::accept()
|
||||
// Create table
|
||||
if(!pdb->createTable(ui->editTableName->text(), tbl_structure))
|
||||
{
|
||||
QMessageBox::warning(this, QApplication::applicationName(), QString("Error creating table. Message from database engine:\n%1").arg(pdb->lastErrorMessage));
|
||||
QMessageBox::warning(this, QApplication::applicationName(), tr("Error creating table. Message from database engine:\n%1").arg(pdb->lastErrorMessage));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -31,9 +31,9 @@ void ExportCsvDialog::accept()
|
||||
// Get filename
|
||||
QString fileName = QFileDialog::getSaveFileName(
|
||||
this,
|
||||
"Choose a filename to export data",
|
||||
tr("Choose a filename to export data"),
|
||||
defaultLocation,
|
||||
"Text files(*.csv *.txt)");
|
||||
tr("Text files(*.csv *.txt)"));
|
||||
|
||||
// Only if the user hasn't clicked the cancel button
|
||||
if(fileName.size() > 0)
|
||||
@@ -45,7 +45,7 @@ void ExportCsvDialog::accept()
|
||||
QString quoteChar = ui->comboQuoteCharacter->currentText();
|
||||
QString quotequoteChar = quoteChar + quoteChar;
|
||||
QString sepChar = ui->comboFieldSeparator->currentText();
|
||||
if(sepChar == "Tab") sepChar = "\t";
|
||||
if(sepChar == tr("Tab")) sepChar = "\t";
|
||||
QString newlineChar = "\n";
|
||||
|
||||
// Open file
|
||||
@@ -87,10 +87,10 @@ void ExportCsvDialog::accept()
|
||||
|
||||
// Done writing the file
|
||||
file.close();
|
||||
QMessageBox::information(this, QApplication::applicationName(), "Export completed.");
|
||||
QMessageBox::information(this, QApplication::applicationName(), tr("Export completed."));
|
||||
QDialog::accept();
|
||||
} else {
|
||||
QMessageBox::warning(this, QApplication::applicationName(), "Could not open output file.");
|
||||
QMessageBox::warning(this, QApplication::applicationName(), tr("Could not open output file."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ void FindDialog::resetFields(QStringList fieldlist)
|
||||
ui->editSearchString->setText("");
|
||||
ui->comboOperator->setCurrentIndex(0);
|
||||
ui->tableResults->clearContents();
|
||||
ui->labelNumberResults->setText("Found: 0");
|
||||
ui->labelNumberResults->setText(tr("Found: 0"));
|
||||
}
|
||||
|
||||
void FindDialog::recordSelected(QTableWidgetItem* witem)
|
||||
|
||||
@@ -63,7 +63,7 @@ void ImportCsvDialog::accept()
|
||||
}
|
||||
|
||||
// Show progress dialog
|
||||
QProgressDialog progress("Inserting data...", "Cancel", 0, curList.size());
|
||||
QProgressDialog progress(tr("Inserting data..."), tr("Cancel"), 0, curList.size());
|
||||
progress.setWindowModality(Qt::ApplicationModal);
|
||||
|
||||
// declare local variables we will need before the rollback jump
|
||||
@@ -118,7 +118,7 @@ void ImportCsvDialog::accept()
|
||||
rollback:
|
||||
progress.hide();
|
||||
QApplication::restoreOverrideCursor(); // restore original cursor
|
||||
QString error = QString("Error importing data. Message from database engine: %1").arg(pdb->lastErrorMessage);
|
||||
QString error = tr("Error importing data. Message from database engine: %1").arg(pdb->lastErrorMessage);
|
||||
QMessageBox::warning(this, QApplication::applicationName(), error);
|
||||
pdb->executeSQL("ROLLBACK TO SAVEPOINT CSVIMPORT;", false);
|
||||
}
|
||||
@@ -187,5 +187,5 @@ char ImportCsvDialog::currentQuoteChar()
|
||||
|
||||
char ImportCsvDialog::currentSeparatorChar()
|
||||
{
|
||||
return ui->comboSeparator->currentText() == "Tab" ? '\t' : ui->comboSeparator->currentText().at(0).toAscii();
|
||||
return ui->comboSeparator->currentText() == tr("Tab") ? '\t' : ui->comboSeparator->currentText().at(0).toAscii();
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ void MainWindow::fileOpen(const QString & fileName)
|
||||
{
|
||||
wFile = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
"Choose a database file",
|
||||
tr("Choose a database file"),
|
||||
defaultlocation);
|
||||
}
|
||||
if(QFile::exists(wFile) )
|
||||
@@ -131,8 +131,7 @@ void MainWindow::fileOpen(const QString & fileName)
|
||||
{
|
||||
setCurrentFile(wFile);
|
||||
} else {
|
||||
QString err = "An error occurred: ";
|
||||
err.append(db.lastErrorMessage);
|
||||
QString err = tr("An error occurred: %1").arg(db.lastErrorMessage);
|
||||
QMessageBox::warning(this, QApplication::applicationName(), err);
|
||||
}
|
||||
populateStructure();
|
||||
@@ -149,7 +148,7 @@ void MainWindow::fileOpen()
|
||||
|
||||
void MainWindow::fileNew()
|
||||
{
|
||||
QString fileName = QFileDialog::getSaveFileName(this, "Choose a filename to save under", defaultlocation);
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Choose a filename to save under"), defaultlocation);
|
||||
if(!fileName.isEmpty())
|
||||
{
|
||||
if(QFile::exists(fileName))
|
||||
@@ -297,16 +296,11 @@ void MainWindow::fileExit()
|
||||
{
|
||||
if (db.getDirty())
|
||||
{
|
||||
QString msg = "Do you want to save the changes made to the database file ";
|
||||
msg.append(db.curDBFilename);
|
||||
msg.append("?");
|
||||
if (QMessageBox::question( this, QApplication::applicationName() ,msg, QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes)
|
||||
{
|
||||
QString msg = tr("Do you want to save the changes made to the database file %1?").arg(db.curDBFilename);
|
||||
if(QMessageBox::question( this, QApplication::applicationName() ,msg, QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes)
|
||||
db.save();
|
||||
} else {
|
||||
//not really necessary, I think... but will not hurt.
|
||||
db.revert();
|
||||
}
|
||||
else
|
||||
db.revert(); //not really necessary, I think... but will not hurt.
|
||||
}
|
||||
db.close();
|
||||
}
|
||||
@@ -330,10 +324,10 @@ void MainWindow::addRecord()
|
||||
updateTableView(db.getRecordCount()-1);
|
||||
}else{
|
||||
QMessageBox::information( this, QApplication::applicationName(),
|
||||
"Error adding record, make sure a table is selected.\n\n"
|
||||
tr("Error adding record, make sure a table is selected.\n\n"
|
||||
"If the table contain fields declared as NOT NULL\n"
|
||||
"please select EDIT->PREFERENCES and adjust the\n"
|
||||
"default value for new records to insert an empty string." );
|
||||
"default value for new records to insert an empty string."));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,7 +346,7 @@ void MainWindow::deleteRecord()
|
||||
selectTableLine(nextselected);
|
||||
}
|
||||
} else {
|
||||
QMessageBox::information( this, QApplication::applicationName(), "Please select a record first" );
|
||||
QMessageBox::information( this, QApplication::applicationName(), tr("Please select a record first"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,7 +467,7 @@ void MainWindow::setRecordsetLabel()
|
||||
if(to == -2)
|
||||
to = total;
|
||||
|
||||
ui->labelRecordset->setText(QString("%1 - %2 of %3").arg(from).arg(to).arg(total));
|
||||
ui->labelRecordset->setText(tr("%1 - %2 of %3").arg(from).arg(to).arg(total));
|
||||
}
|
||||
|
||||
void MainWindow::browseFind(bool open)
|
||||
@@ -508,7 +502,7 @@ void MainWindow::browseRefresh()
|
||||
void MainWindow::lookfor( const QString & wfield, const QString & woperator, const QString & wsearchterm )
|
||||
{
|
||||
if (!db.isOpen()){
|
||||
QMessageBox::information( this, QApplication::applicationName(), "There is no database opened. Please open or create a new database file." );
|
||||
QMessageBox::information( this, QApplication::applicationName(), tr("There is no database opened. Please open or create a new database file."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -517,7 +511,8 @@ void MainWindow::lookfor( const QString & wfield, const QString & woperator, con
|
||||
QString finalsearchterm = wsearchterm;
|
||||
|
||||
//special case for CONTAINS operator: use LIKE and surround the search word with % characters
|
||||
if (woperator.compare("contains")==0){
|
||||
if(woperator.compare(tr("contains")) == 0)
|
||||
{
|
||||
finaloperator = QString("LIKE");
|
||||
QString newsearchterm = "%";
|
||||
newsearchterm.append(wsearchterm);
|
||||
@@ -554,7 +549,7 @@ void MainWindow::lookfor( const QString & wfield, const QString & woperator, con
|
||||
void MainWindow::createTable()
|
||||
{
|
||||
if (!db.isOpen()){
|
||||
QMessageBox::information( this, QApplication::applicationName(), "There is no database opened. Please open or create a new database file." );
|
||||
QMessageBox::information( this, QApplication::applicationName(), tr("There is no database opened. Please open or create a new database file."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -569,7 +564,7 @@ void MainWindow::createTable()
|
||||
void MainWindow::createIndex()
|
||||
{
|
||||
if (!db.isOpen()){
|
||||
QMessageBox::information( this, QApplication::applicationName(), "There is no database opened. Please open or create a new database file." );
|
||||
QMessageBox::information( this, QApplication::applicationName(), tr("There is no database opened. Please open or create a new database file."));
|
||||
return;
|
||||
}
|
||||
CreateIndexDialog dialog(&db, this);
|
||||
@@ -584,13 +579,12 @@ void MainWindow::compact()
|
||||
{
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||
if (!db.compact()){
|
||||
QString error = "Error: could not compact the database file. Message from database engine: ";
|
||||
error.append(db.lastErrorMessage);
|
||||
QString error = tr("Error: could not compact the database file. Message from database engine: %1").arg(db.lastErrorMessage);
|
||||
QApplication::restoreOverrideCursor( );
|
||||
QMessageBox::warning( this, QApplication::applicationName(), error );
|
||||
} else {
|
||||
QApplication::restoreOverrideCursor( );
|
||||
QMessageBox::information(this, QApplication::applicationName(), "Database successfully compacted.");
|
||||
QMessageBox::information(this, QApplication::applicationName(), tr("Database successfully compacted."));
|
||||
}
|
||||
db.open(db.curDBFilename);
|
||||
populateStructure();
|
||||
@@ -611,7 +605,7 @@ void MainWindow::deleteObject()
|
||||
QString statement = QString("DROP %1 `%2`;").arg(type.toUpper()).arg(table);
|
||||
if(!db.executeSQL( statement))
|
||||
{
|
||||
QString error = QString("Error: could not delete the %1. Message from database engine:\n%2").arg(type).arg(db.lastErrorMessage);
|
||||
QString error = tr("Error: could not delete the %1. Message from database engine:\n%2").arg(type).arg(db.lastErrorMessage);
|
||||
QMessageBox::warning(this, QApplication::applicationName(), error);
|
||||
} else {
|
||||
populateStructure();
|
||||
@@ -623,7 +617,7 @@ void MainWindow::deleteObject()
|
||||
void MainWindow::editTable()
|
||||
{
|
||||
if (!db.isOpen()){
|
||||
QMessageBox::information( this, QApplication::applicationName(), "There is no database opened." );
|
||||
QMessageBox::information( this, QApplication::applicationName(), tr("There is no database opened."));
|
||||
return;
|
||||
}
|
||||
if(!ui->dbTreeWidget->selectionModel()->hasSelection()){
|
||||
@@ -684,7 +678,7 @@ void MainWindow::helpAbout()
|
||||
void MainWindow::updateRecordText(int row, int col, QString newtext)
|
||||
{
|
||||
if (!db.updateRecord(row, col, newtext)){
|
||||
QMessageBox::information( this, QApplication::applicationName(), "Data could not be updated" );
|
||||
QMessageBox::information( this, QApplication::applicationName(), tr("Data could not be updated"));
|
||||
}
|
||||
|
||||
rowList tab = db.browseRecs;
|
||||
@@ -740,7 +734,7 @@ void MainWindow::executeQuery()
|
||||
QString query = ui->sqlTextEdit->toPlainText().trimmed();
|
||||
if (query.isEmpty())
|
||||
{
|
||||
QMessageBox::information( this, QApplication::applicationName(), "Query string is empty" );
|
||||
QMessageBox::information( this, QApplication::applicationName(), tr("Query string is empty"));
|
||||
return;
|
||||
}
|
||||
//log the query
|
||||
@@ -750,7 +744,7 @@ void MainWindow::executeQuery()
|
||||
const char *tail = utf8Query.data();
|
||||
int ncol;
|
||||
int err=0;
|
||||
QString lastErrorMessage = QString("No error");
|
||||
QString lastErrorMessage = tr("No error");
|
||||
//Accept multi-line queries, by looping until the tail is empty
|
||||
do
|
||||
{
|
||||
@@ -819,9 +813,9 @@ void MainWindow::importTableFromCSV()
|
||||
{
|
||||
QString wFile = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
"Choose a text file",
|
||||
tr("Choose a text file"),
|
||||
defaultlocation,
|
||||
"Text files(*.csv *.txt);;All files(*)");
|
||||
tr("Text files(*.csv *.txt);;All files(*)"));
|
||||
|
||||
if (QFile::exists(wFile) )
|
||||
{
|
||||
@@ -830,7 +824,7 @@ void MainWindow::importTableFromCSV()
|
||||
{
|
||||
populateStructure();
|
||||
resetBrowser();
|
||||
QMessageBox::information( this, QApplication::applicationName(), "Import completed" );
|
||||
QMessageBox::information(this, QApplication::applicationName(), tr("Import completed"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -849,16 +843,14 @@ void MainWindow::dbState( bool dirty )
|
||||
|
||||
void MainWindow::fileSave()
|
||||
{
|
||||
if (db.isOpen()){
|
||||
if(db.isOpen())
|
||||
db.save();
|
||||
//dbStatusBar->showMessage("Date written to file", 4000)
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::fileRevert()
|
||||
{
|
||||
if (db.isOpen()){
|
||||
QString msg = QString("Are you sure you want to undo all changes made to the database file '%1' since the last save?").arg(db.curDBFilename);
|
||||
QString msg = tr("Are you sure you want to undo all changes made to the database file '%1' since the last save?").arg(db.curDBFilename);
|
||||
if(QMessageBox::question(this, QApplication::applicationName(), msg, QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape) == QMessageBox::Yes)
|
||||
{
|
||||
db.revert();
|
||||
@@ -872,16 +864,16 @@ void MainWindow::exportDatabaseToSQL()
|
||||
{
|
||||
QString fileName = QFileDialog::getSaveFileName(
|
||||
this,
|
||||
"Choose a filename to export",
|
||||
tr("Choose a filename to export"),
|
||||
defaultlocation,
|
||||
"Text files(*.sql *.txt)");
|
||||
tr("Text files(*.sql *.txt)"));
|
||||
|
||||
if(fileName.size())
|
||||
{
|
||||
if(!db.dump(fileName))
|
||||
QMessageBox::warning(this, QApplication::applicationName(), "Export cancelled or failed.");
|
||||
QMessageBox::warning(this, QApplication::applicationName(), tr("Export cancelled or failed."));
|
||||
else
|
||||
QMessageBox::information(this, QApplication::applicationName(), "Export completed.");
|
||||
QMessageBox::information(this, QApplication::applicationName(), tr("Export completed."));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -889,41 +881,33 @@ void MainWindow::importDatabaseFromSQL()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
"Choose a file to import",
|
||||
tr("Choose a file to import"),
|
||||
defaultlocation,
|
||||
"Text files(*.sql *.txt);;All files(*)");
|
||||
tr("Text files(*.sql *.txt);;All files(*)"));
|
||||
|
||||
if (fileName.size() > 0)
|
||||
{
|
||||
QString msg = "Do you want to create a new database file to hold the imported data?\nIf you answer NO we will attempt to import data in the .sql file to the current database.";
|
||||
QString msg = tr("Do you want to create a new database file to hold the imported data?\nIf you answer NO we will attempt to import data in the .sql file to the current database.");
|
||||
if (QMessageBox::question( this, QApplication::applicationName() ,msg, QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes)
|
||||
{
|
||||
QString newDBfile = QFileDialog::getSaveFileName(
|
||||
this,
|
||||
"Choose a filename to save under",
|
||||
tr("Choose a filename to save under"),
|
||||
defaultlocation);
|
||||
if (QFile::exists(newDBfile) )
|
||||
{
|
||||
QString err = "File ";
|
||||
err.append(newDBfile);
|
||||
err.append(" already exists. Please choose a different name");
|
||||
QString err = tr("File %1 already exists. Please choose a different name.").arg(newDBfile);
|
||||
QMessageBox::information( this, QApplication::applicationName() ,err);
|
||||
return;
|
||||
}
|
||||
if (!fileName.isNull())
|
||||
{
|
||||
if(!fileName.isNull())
|
||||
db.create(newDBfile);
|
||||
}
|
||||
}
|
||||
int lineErr;
|
||||
if (!db.reload(fileName, &lineErr))
|
||||
{
|
||||
QMessageBox::information( this, QApplication::applicationName(), QString("Error importing data at line %1").arg(lineErr) );
|
||||
}
|
||||
QMessageBox::information(this, QApplication::applicationName(), tr("Error importing data at line %1").arg(lineErr) );
|
||||
else
|
||||
{
|
||||
QMessageBox::information( this, QApplication::applicationName(), "Import completed" );
|
||||
}
|
||||
QMessageBox::information(this, QApplication::applicationName(), tr("Import completed"));
|
||||
populateStructure();
|
||||
resetBrowser();
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ void PreferencesDialog::chooseLocation()
|
||||
if(!s.isEmpty())
|
||||
{
|
||||
defaultlocation = s;
|
||||
ui->locationEdit->setText(defaultlocation);
|
||||
ui->locationEdit->setText(defaultlocation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* true to construct a modal dialog.
|
||||
*/
|
||||
SQLLogDock::SQLLogDock(QWidget* parent)
|
||||
: QDockWidget("SQL Log", parent)
|
||||
: QDockWidget(tr("SQL Log"), parent)
|
||||
{
|
||||
setupUi();
|
||||
}
|
||||
|
||||
11
src/main.cpp
11
src/main.cpp
@@ -1,6 +1,9 @@
|
||||
#include "MainWindow.h"
|
||||
#include <QApplication>
|
||||
#include <QTextCodec>
|
||||
#include <QTranslator>
|
||||
#include <QLibraryInfo>
|
||||
#include <QLocale>
|
||||
|
||||
#if defined(Q_WS_MAC)
|
||||
#include <Carbon/Carbon.h>
|
||||
@@ -79,6 +82,14 @@ int main( int argc, char ** argv )
|
||||
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
|
||||
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
|
||||
|
||||
// Enable translation
|
||||
QTranslator translator;
|
||||
translator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
||||
a.installTranslator(&translator);
|
||||
QTranslator apptranslator;
|
||||
apptranslator.load("translations/tr_" + QLocale::system().name());
|
||||
a.installTranslator(&apptranslator);
|
||||
|
||||
MainWindow w;
|
||||
#if defined(Q_WS_MAC)
|
||||
AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
|
||||
|
||||
@@ -89,15 +89,15 @@ bool DBBrowserDB::open ( const QString & db)
|
||||
QString contents = QString(buffer);
|
||||
dbfile.close();
|
||||
if (!contents.startsWith("SQLite format 3")) {
|
||||
lastErrorMessage = QString("File is not a SQLite 3 database");
|
||||
lastErrorMessage = QObject::tr("File is not a SQLite 3 database");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
lastErrorMessage = QString("File could not be read");
|
||||
lastErrorMessage = QObject::tr("File could not be read");
|
||||
return false;
|
||||
}
|
||||
|
||||
lastErrorMessage = QString("no error");
|
||||
lastErrorMessage = QObject::tr("no error");
|
||||
|
||||
err = sqlite3_open_v2(db.toUtf8(), &_db, SQLITE_OPEN_READWRITE, NULL);
|
||||
if ( err ) {
|
||||
@@ -167,7 +167,7 @@ bool DBBrowserDB::create ( const QString & db)
|
||||
|
||||
if (isOpen()) close();
|
||||
|
||||
lastErrorMessage = QString("no error");
|
||||
lastErrorMessage = QObject::tr("no error");
|
||||
|
||||
if( sqlite3_open(db.toUtf8(), &_db) != SQLITE_OK ){
|
||||
lastErrorMessage = sqlite3_errmsg(_db);
|
||||
@@ -198,16 +198,11 @@ void DBBrowserDB::close (){
|
||||
{
|
||||
if (getDirty())
|
||||
{
|
||||
QString msg = "Do you want to save the changes made to the database file ";
|
||||
msg.append(curDBFilename);
|
||||
msg.append(" ?");
|
||||
QString msg = QObject::tr("Do you want to save the changes made to the database file %1?").arg(curDBFilename);
|
||||
if (QMessageBox::question( 0, QApplication::applicationName() ,msg, QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes)
|
||||
{
|
||||
save();
|
||||
} else {
|
||||
//not really necessary, I think... but will not hurt.
|
||||
revert();
|
||||
}
|
||||
else
|
||||
revert(); //not really necessary, I think... but will not hurt.
|
||||
}
|
||||
sqlite3_close(_db);
|
||||
}
|
||||
@@ -271,7 +266,7 @@ bool DBBrowserDB::dump(const QString& filename)
|
||||
QList<DBBrowserObject> tables = objMap.values("table");
|
||||
for(QList<DBBrowserObject>::ConstIterator it=tables.begin();it!=tables.end();++it)
|
||||
numRecordsTotal += getFindResults(QString("SELECT COUNT(*) FROM `%1`;").arg((*it).getname())).value(0).toInt();
|
||||
QProgressDialog progress("Exporting database to SQL file...", "Cancel", 0, numRecordsTotal);
|
||||
QProgressDialog progress(QObject::tr("Exporting database to SQL file..."), QObject::tr("Cancel"), 0, numRecordsTotal);
|
||||
progress.setWindowModality(Qt::ApplicationModal);
|
||||
|
||||
// Regular expression to check for numeric strings
|
||||
@@ -386,7 +381,7 @@ bool DBBrowserDB::addRecord ( )
|
||||
if (i<fields) statement.append(", ");
|
||||
}
|
||||
statement.append(");");
|
||||
lastErrorMessage = QString("no error");
|
||||
lastErrorMessage = QObject::tr("no error");
|
||||
if (_db){
|
||||
logSQL(statement, kLogMsg_App);
|
||||
setDirty(true);
|
||||
@@ -517,7 +512,7 @@ bool DBBrowserDB::renameColumn(QString tablename, QString from, QString to, QStr
|
||||
DBBrowserObject table = getObjectByName(tablename);
|
||||
if(table.getname() == "" || table.getField(from).getname() == "")
|
||||
{
|
||||
lastErrorMessage = QString("renameColumn: cannot find table %1 with column %2").arg(tablename).arg(from);
|
||||
lastErrorMessage = QObject::tr("renameColumn: cannot find table %1 with column %2").arg(tablename).arg(from);
|
||||
qDebug(lastErrorMessage.toStdString().c_str());
|
||||
return false;
|
||||
}
|
||||
@@ -525,7 +520,7 @@ bool DBBrowserDB::renameColumn(QString tablename, QString from, QString to, QStr
|
||||
// Create savepoint to be able to go back to it in case of any error
|
||||
if(!executeSQL("SAVEPOINT sqlitebrowser_rename_column"))
|
||||
{
|
||||
lastErrorMessage = "renameColumn: creating savepoint failed";
|
||||
lastErrorMessage = QObject::tr("renameColumn: creating savepoint failed. DB says: %1").arg(lastErrorMessage);
|
||||
qDebug(lastErrorMessage.toStdString().c_str());
|
||||
return false;
|
||||
}
|
||||
@@ -543,7 +538,7 @@ bool DBBrowserDB::renameColumn(QString tablename, QString from, QString to, QStr
|
||||
}
|
||||
if(!createTable("sqlitebrowser_rename_column_new_table", new_table_structure))
|
||||
{
|
||||
lastErrorMessage = QString("renameColumn: creating new table failed. DB says: %1").arg(lastErrorMessage);
|
||||
lastErrorMessage = QObject::tr("renameColumn: creating new table failed. DB says: %1").arg(lastErrorMessage);
|
||||
qDebug(lastErrorMessage.toStdString().c_str());
|
||||
executeSQL("ROLLBACK TO SAVEPOINT sqlitebrowser_rename_column;");
|
||||
return false;
|
||||
@@ -552,7 +547,7 @@ bool DBBrowserDB::renameColumn(QString tablename, QString from, QString to, QStr
|
||||
// Copy the data from the old table to the new one
|
||||
if(!executeSQL(QString("INSERT INTO sqlitebrowser_rename_column_new_table SELECT * FROM `%1`;").arg(tablename)))
|
||||
{
|
||||
lastErrorMessage = QString("renameColumn: copying data to new table failed. DB says: %1").arg(lastErrorMessage);
|
||||
lastErrorMessage = QObject::tr("renameColumn: copying data to new table failed. DB says: %1").arg(lastErrorMessage);
|
||||
qDebug(lastErrorMessage.toStdString().c_str());
|
||||
executeSQL("ROLLBACK TO SAVEPOINT sqlitebrowser_rename_column;");
|
||||
return false;
|
||||
@@ -561,7 +556,7 @@ bool DBBrowserDB::renameColumn(QString tablename, QString from, QString to, QStr
|
||||
// Delete the old table
|
||||
if(!executeSQL(QString("DROP TABLE `%1`;").arg(tablename)))
|
||||
{
|
||||
lastErrorMessage = QString("renameColumn: deleting old table failed. DB says: %1").arg(lastErrorMessage);
|
||||
lastErrorMessage = QObject::tr("renameColumn: deleting old table failed. DB says: %1").arg(lastErrorMessage);
|
||||
qDebug(lastErrorMessage.toStdString().c_str());
|
||||
executeSQL("ROLLBACK TO SAVEPOINT sqlitebrowser_rename_column;");
|
||||
return false;
|
||||
@@ -577,7 +572,7 @@ bool DBBrowserDB::renameColumn(QString tablename, QString from, QString to, QStr
|
||||
// Release the savepoint - everything went fine
|
||||
if(!executeSQL("RELEASE SAVEPOINT sqlitebrowser_rename_column;"))
|
||||
{
|
||||
lastErrorMessage = QString("renameColumn: releasing savepoint failed. DB says: %1").arg(lastErrorMessage);
|
||||
lastErrorMessage = QObject::tr("renameColumn: releasing savepoint failed. DB says: %1").arg(lastErrorMessage);
|
||||
qDebug(lastErrorMessage.toStdString().c_str());
|
||||
return false;
|
||||
}
|
||||
@@ -597,7 +592,7 @@ bool DBBrowserDB::dropColumn(QString tablename, QString column)
|
||||
DBBrowserObject table = getObjectByName(tablename);
|
||||
if(table.getname() == "" || table.getField(column).getname() == "" || table.fldmap.count() == 1)
|
||||
{
|
||||
lastErrorMessage = QString("dropColumn: cannot find table %1 or column %2. Also you can not delete the last column").arg(tablename).arg(column);
|
||||
lastErrorMessage = QObject::tr("dropColumn: cannot find table %1 or column %2. Also you can not delete the last column").arg(tablename).arg(column);
|
||||
qDebug(lastErrorMessage.toStdString().c_str());
|
||||
return false;
|
||||
}
|
||||
@@ -605,7 +600,7 @@ bool DBBrowserDB::dropColumn(QString tablename, QString column)
|
||||
// Create savepoint to be able to go back to it in case of any error
|
||||
if(!executeSQL("SAVEPOINT sqlitebrowser_drop_column"))
|
||||
{
|
||||
lastErrorMessage = "dropColumn: creating savepoint failed";
|
||||
lastErrorMessage = QObject::tr("dropColumn: creating savepoint failed");
|
||||
qDebug(lastErrorMessage.toStdString().c_str());
|
||||
return false;
|
||||
}
|
||||
@@ -625,7 +620,7 @@ bool DBBrowserDB::dropColumn(QString tablename, QString column)
|
||||
}
|
||||
if(!createTable("sqlitebrowser_drop_column_new_table", new_table_structure))
|
||||
{
|
||||
lastErrorMessage = QString("dropColumn: creating new table failed. DB says: %1").arg(lastErrorMessage);
|
||||
lastErrorMessage = QObject::tr("dropColumn: creating new table failed. DB says: %1").arg(lastErrorMessage);
|
||||
qDebug(lastErrorMessage.toStdString().c_str());
|
||||
executeSQL("ROLLBACK TO SAVEPOINT sqlitebrowser_drop_column;");
|
||||
return false;
|
||||
@@ -635,7 +630,7 @@ bool DBBrowserDB::dropColumn(QString tablename, QString column)
|
||||
// Copy the data from the old table to the new one
|
||||
if(!executeSQL(QString("INSERT INTO sqlitebrowser_drop_column_new_table SELECT %1 FROM `%2`;").arg(select_cols).arg(tablename)))
|
||||
{
|
||||
lastErrorMessage = QString("dropColumn: copying data to new table failed. DB says: %1").arg(lastErrorMessage);
|
||||
lastErrorMessage = QObject::tr("dropColumn: copying data to new table failed. DB says: %1").arg(lastErrorMessage);
|
||||
qDebug(lastErrorMessage.toStdString().c_str());
|
||||
executeSQL("ROLLBACK TO SAVEPOINT sqlitebrowser_drop_column;");
|
||||
return false;
|
||||
@@ -644,7 +639,7 @@ bool DBBrowserDB::dropColumn(QString tablename, QString column)
|
||||
// Delete the old table
|
||||
if(!executeSQL(QString("DROP TABLE `%1`;").arg(tablename)))
|
||||
{
|
||||
lastErrorMessage = QString("dropColumn: deleting old table failed. DB says: %1").arg(lastErrorMessage);
|
||||
lastErrorMessage = QObject::tr("dropColumn: deleting old table failed. DB says: %1").arg(lastErrorMessage);
|
||||
qDebug(lastErrorMessage.toStdString().c_str());
|
||||
executeSQL("ROLLBACK TO SAVEPOINT sqlitebrowser_drop_column;");
|
||||
return false;
|
||||
@@ -660,7 +655,7 @@ bool DBBrowserDB::dropColumn(QString tablename, QString column)
|
||||
// Release the savepoint - everything went fine
|
||||
if(!executeSQL("RELEASE SAVEPOINT sqlitebrowser_drop_column;"))
|
||||
{
|
||||
lastErrorMessage = QString("dropColumn: releasing savepoint failed. DB says: %1").arg(lastErrorMessage);
|
||||
lastErrorMessage = QObject::tr("dropColumn: releasing savepoint failed. DB says: %1").arg(lastErrorMessage);
|
||||
qDebug(lastErrorMessage.toStdString().c_str());
|
||||
return false;
|
||||
}
|
||||
@@ -674,7 +669,7 @@ bool DBBrowserDB::renameTable(QString from_table, QString to_table)
|
||||
QString sql = QString("ALTER TABLE `%1` RENAME TO `%2`").arg(from_table, to_table);
|
||||
if(!executeSQL(sql))
|
||||
{
|
||||
QString error = QString("Error renaming table '%1' to '%2'. Message from database engine:\n%3").arg(from_table).arg(to_table).arg(lastErrorMessage);
|
||||
QString error = QObject::tr("Error renaming table '%1' to '%2'. Message from database engine:\n%3").arg(from_table).arg(to_table).arg(lastErrorMessage);
|
||||
lastErrorMessage = error;
|
||||
qDebug(error.toStdString().c_str());
|
||||
return false;
|
||||
@@ -695,7 +690,7 @@ void DBBrowserDB::getTableRecords( const QString & tablename, const QString& ord
|
||||
// int tabnum = 0;
|
||||
browseRecs.clear();
|
||||
idmap.clear();
|
||||
lastErrorMessage = QString("no error");
|
||||
lastErrorMessage = QObject::tr("no error");
|
||||
|
||||
QString statement = QString("SELECT rowid, * FROM `%1` ORDER BY %2;").arg(GetEncodedQString(tablename)).arg(orderby);
|
||||
logSQL(statement, kLogMsg_App);
|
||||
@@ -723,7 +718,7 @@ void DBBrowserDB::getTableRecords( const QString & tablename, const QString& ord
|
||||
|
||||
sqlite3_finalize(vm);
|
||||
}else{
|
||||
lastErrorMessage = QString ("could not get fields");
|
||||
lastErrorMessage = QObject::tr("could not get fields");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -737,7 +732,7 @@ resultMap DBBrowserDB::getFindResults( const QString & wstatement)
|
||||
// char *errmsg;
|
||||
int err=0;
|
||||
resultMap res;
|
||||
lastErrorMessage = QString("no error");
|
||||
lastErrorMessage = QObject::tr("no error");
|
||||
QString encstatement = GetEncodedQString(wstatement);
|
||||
logSQL(encstatement, kLogMsg_App);
|
||||
err=sqlite3_prepare(_db,encstatement.toUtf8(),encstatement.length(),
|
||||
@@ -875,7 +870,7 @@ void DBBrowserDB::logSQL(QString statement, int msgtype)
|
||||
if ((statement.length() > loglimit)&&(msgtype==kLogMsg_App))
|
||||
{
|
||||
statement.truncate(32);
|
||||
statement.append("... <string too wide to log, probably contains binary data> ...");
|
||||
statement.append(QObject::tr("... <string too wide to log, probably contains binary data> ..."));
|
||||
}
|
||||
logWin->log(statement, msgtype);
|
||||
}
|
||||
@@ -890,7 +885,7 @@ void DBBrowserDB::updateSchema( )
|
||||
|
||||
objMap.clear();
|
||||
|
||||
lastErrorMessage = QString("no error");
|
||||
lastErrorMessage = QObject::tr("no error");
|
||||
QString statement = "SELECT type, name, sql FROM sqlite_master;";
|
||||
|
||||
err=sqlite3_prepare(_db, (const char *) statement.toUtf8(),statement.length(),
|
||||
@@ -906,11 +901,11 @@ void DBBrowserDB::updateSchema( )
|
||||
if(val1 == "table" || val1 == "index" || val1 == "view" || val1 == "trigger")
|
||||
objMap.insert(val1, DBBrowserObject(GetDecodedQString(val2), GetDecodedQString(val3), GetDecodedQString(val1)));
|
||||
else
|
||||
qDebug("unknown object type %s", val1.toStdString().c_str());
|
||||
qDebug(QObject::tr("unknown object type %1").arg(val1).toStdString().c_str());
|
||||
}
|
||||
sqlite3_finalize(vm);
|
||||
}else{
|
||||
qDebug ("could not get list of db objects: %d, %s",err,sqlite3_errmsg(_db));
|
||||
qDebug(QObject::tr("could not get list of db objects: %1, %2").arg(err).arg(sqlite3_errmsg(_db)).toStdString().c_str());
|
||||
}
|
||||
|
||||
//now get the field list for each table
|
||||
@@ -933,16 +928,16 @@ void DBBrowserDB::updateSchema( )
|
||||
val1 = QString((const char *) sqlite3_column_text(vm, 1));
|
||||
val2 = QString((const char *) sqlite3_column_text(vm, 2));
|
||||
ispk = sqlite3_column_int(vm, 5);
|
||||
if (ispk==1){
|
||||
if(ispk==1)
|
||||
val2.append(QString(" PRIMARY KEY"));
|
||||
}
|
||||
|
||||
(*it).addField(e,GetDecodedQString(val1),GetDecodedQString(val2));
|
||||
e++;
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(vm);
|
||||
} else{
|
||||
lastErrorMessage = QString ("could not get types");
|
||||
lastErrorMessage = QObject::tr("could not get types");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -959,7 +954,7 @@ QStringList DBBrowserDB::decodeCSV(const QString & csvfilename, char sep, char q
|
||||
*numfields = 0;
|
||||
|
||||
if ( file.open( QIODevice::ReadWrite ) ) {
|
||||
QProgressDialog progress("Decoding CSV file...", "Cancel", 0, file.size());
|
||||
QProgressDialog progress(QObject::tr("Decoding CSV file..."), QObject::tr("Cancel"), 0, file.size());
|
||||
progress.setWindowModality(Qt::ApplicationModal);
|
||||
char c=0;
|
||||
while(file.getChar(&c))
|
||||
@@ -1050,10 +1045,10 @@ QString DBBrowserDB::getPragma(QString pragma)
|
||||
sqlite3_finalize(vm);
|
||||
} else {
|
||||
sqlite3_finalize(vm);
|
||||
qDebug("didn't receive any output from pragma %s", pragma.toStdString().c_str());
|
||||
qDebug(QObject::tr("didn't receive any output from pragma %1").arg(pragma).toStdString().c_str());
|
||||
}
|
||||
} else {
|
||||
qDebug ("could not execute pragma command: %d, %s", err, sqlite3_errmsg(_db));
|
||||
qDebug(QObject::tr("could not execute pragma command: %1, %2").arg(err).arg(sqlite3_errmsg(_db)).toStdString().c_str());
|
||||
}
|
||||
|
||||
// Make changes to the value when needed
|
||||
@@ -1143,7 +1138,7 @@ bool DBBrowserDB::setPragma(QString pragma, QString value)
|
||||
QString sql = QString("PRAGMA %1 = %2;").arg(pragma).arg(value);
|
||||
if(!executeSQL(sql))
|
||||
{
|
||||
qDebug("Error setting pragma %s to %s: %s", pragma.toStdString().c_str(), value.toStdString().c_str(), lastErrorMessage.toStdString().c_str());
|
||||
qDebug(QObject::tr("Error setting pragma %1 to %2: %3").arg(pragma).arg(value).arg(lastErrorMessage).toStdString().c_str());
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
|
||||
0
src/translations/place_translations_here
Normal file
0
src/translations/place_translations_here
Normal file
Reference in New Issue
Block a user