Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add option to auto-load built-in extension #3541

Merged
merged 12 commits into from
May 25, 2024
5 changes: 2 additions & 3 deletions src/AboutDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,14 @@
<x>0</x>
<y>0</y>
<width>635</width>
<height>349</height>
<height>350</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;DB Browser for SQLite is an open source, freeware visual tool used to create, design and edit SQLite database files.&lt;/p&gt;&lt;p&gt;It is bi-licensed under the Mozilla Public License Version 2, as well as the GNU General Public License Version 3 or later. You can modify or redistribute it under the conditions of these licenses.&lt;/p&gt;&lt;p&gt;See &lt;a href=&quot;http://www.gnu.org/licenses/gpl.html&quot;&gt;http://www.gnu.org/licenses/gpl.html&lt;/a&gt; and &lt;a href=&quot;https://www.mozilla.org/MPL/2.0/index.txt&quot;&gt;https://www.mozilla.org/MPL/2.0/index.txt&lt;/a&gt; for details.&lt;/p&gt;&lt;p&gt;For more information on this program please visit our website at: &lt;a href=&quot;http://sqlitebrowser.org&quot;&gt;http://sqlitebrowser.org&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-size:small;&quot;&gt;This software uses the GPL/LGPL Qt Toolkit from &lt;/span&gt;&lt;a href=&quot;http://qt-project.org/&quot;&gt;&lt;span style=&quot; font-size:small;&quot;&gt;http://qt-project.org/&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-size:small;&quot;&gt;&lt;br/&gt;See &lt;/span&gt;&lt;a href=&quot;http://qt-project.org/doc/qt-5/licensing.html&quot;&gt;&lt;span style=&quot; font-size:small;&quot;&gt;http://qt-project.org/doc/qt-5/licensing.html&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-size:small;&quot;&gt; for licensing terms and information.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-size:small;&quot;&gt;It also uses the Pastel SVG icon set by Michael Buckley under a Creative Commons
Attribution Share Alike 4.0 license.&lt;br/&gt;See &lt;/span&gt;&lt;a href=&quot;https://codefisher.org/pastel-svg/&quot;&gt;&lt;span style=&quot; font-size:small;&quot;&gt;https://codefisher.org/pastel-svg/&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-size:small;&quot;&gt; for details.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;DB Browser for SQLite is an open source, freeware visual tool used to create, design and edit SQLite database files.&lt;/p&gt;&lt;p&gt;It is bi-licensed under the Mozilla Public License Version 2, as well as the GNU General Public License Version 3 or later. You can modify or redistribute it under the conditions of these licenses.&lt;/p&gt;&lt;p&gt;See &lt;a href=&quot;http://www.gnu.org/licenses/gpl.html&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;http://www.gnu.org/licenses/gpl.html&lt;/span&gt;&lt;/a&gt; and &lt;a href=&quot;https://www.mozilla.org/MPL/2.0/index.txt&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;https://www.mozilla.org/MPL/2.0/index.txt&lt;/span&gt;&lt;/a&gt; for details.&lt;/p&gt;&lt;p&gt;For more information on this program please visit our website at: &lt;a href=&quot;http://sqlitebrowser.org&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;http://sqlitebrowser.org&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-size:small;&quot;&gt;This software uses the GPL/LGPL Qt Toolkit from &lt;/span&gt;&lt;a href=&quot;http://qt-project.org/&quot;&gt;&lt;span style=&quot; font-size:small; text-decoration: underline; color:#0000ff;&quot;&gt;http://qt-project.org/&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-size:small;&quot;&gt;&lt;br/&gt;See &lt;/span&gt;&lt;a href=&quot;http://qt-project.org/doc/qt-5/licensing.html&quot;&gt;&lt;span style=&quot; font-size:small; text-decoration: underline; color:#0000ff;&quot;&gt;http://qt-project.org/doc/qt-5/licensing.html&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-size:small;&quot;&gt; for licensing terms and information.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt;We use the nalgeon/sqlean library for SQLite extensions support.&lt;br/&gt;This library is licensed under the MIT license, see the following for more information:&lt;br/&gt;&lt;/span&gt;&lt;a href=&quot;https://github.com/nalgeon/sqlean&quot;&gt;&lt;span style=&quot; font-size:8pt; text-decoration: underline; color:#0000ff;&quot;&gt;https://github.com/nalgeon/sqlean&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-size:small;&quot;&gt;It also uses the Pastel SVG icon set by Michael Buckley under a Creative Commons Attribution Share Alike 4.0 license.&lt;br/&gt;See &lt;/span&gt;&lt;a href=&quot;https://codefisher.org/pastel-svg/&quot;&gt;&lt;span style=&quot; font-size:small; text-decoration: underline; color:#0000ff;&quot;&gt;https://codefisher.org/pastel-svg/&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-size:small;&quot;&gt; for details.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
Expand Down
34 changes: 34 additions & 0 deletions src/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ PreferencesDialog::PreferencesDialog(QWidget* parent, Tabs tab)
ui->checkUpdates->setVisible(false);
#endif

#ifdef Q_OS_MACX
listUpBuiltinExtension();
#else
ui->labeBuiltinExtensions->setVisible(false);
lucydodo marked this conversation as resolved.
Show resolved Hide resolved
ui->listBuiltinExtensions->setVisible(false);
#endif

loadSettings();

connect(ui->appStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(adjustColorsToStyle(int)));
Expand Down Expand Up @@ -206,6 +213,13 @@ void PreferencesDialog::loadSettings()
ui->checkCloseButtonOnTabs->setChecked(Settings::getValue("editor", "close_button_on_tabs").toBool());

ui->listExtensions->addItems(Settings::getValue("extensions", "list").toStringList());
#ifdef Q_OS_MACX
for (int i=0;i<ui->listBuiltinExtensions->count();++i)
{
QListWidgetItem* item = ui->listBuiltinExtensions->item(i);
item->setCheckState(Settings::getValue("extensions", "builtin").toMap().value(item->text()).toBool() ? Qt::Checked : Qt::Unchecked);
}
#endif
ui->checkRegexDisabled->setChecked(Settings::getValue("extensions", "disableregex").toBool());
ui->checkAllowLoadExtension->setChecked(Settings::getValue("extensions", "enable_load_extension").toBool());
fillLanguageBox();
Expand Down Expand Up @@ -281,6 +295,13 @@ void PreferencesDialog::saveSettings(bool accept)
Settings::setValue("extensions", "disableregex", ui->checkRegexDisabled->isChecked());
Settings::setValue("extensions", "enable_load_extension", ui->checkAllowLoadExtension->isChecked());

#ifdef Q_OS_MACX
QVariantMap builtinExtList;
for (int i=0;i<ui->listBuiltinExtensions->count();++i)
builtinExtList.insert(ui->listBuiltinExtensions->item(i)->text(), ui->listBuiltinExtensions->item(i)->checkState());
Settings::setValue("extensions", "builtin", QVariant::fromValue(builtinExtList));
#endif

// Save remote settings
Settings::setValue("remote", "active", ui->checkUseRemotes->isChecked());
QStringList old_client_certs = Settings::getValue("remote", "client_certificates").toStringList();
Expand Down Expand Up @@ -434,6 +455,19 @@ void PreferencesDialog::removeExtension()
ui->listExtensions->takeItem(ui->listExtensions->currentIndex().row());
}

void PreferencesDialog::listUpBuiltinExtension()
lucydodo marked this conversation as resolved.
Show resolved Hide resolved
{
const QDir dir(qApp->applicationDirPath() + "/../Extensions/");
QStringList files = dir.entryList(QStringList() << "*.dylib", QDir::Files);
lucydodo marked this conversation as resolved.
Show resolved Hide resolved
for (const QString& file: files) {
QListWidgetItem* item = new QListWidgetItem(file, ui->listBuiltinExtensions);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
// The check status is redetermined after the 'loadSettings()' function call.
item->setCheckState(Qt::Unchecked);
ui->listBuiltinExtensions->addItem(item);
}
}

void PreferencesDialog::fillLanguageBox()
{
QDir translationsDir(QCoreApplication::applicationDirPath() + "/translations",
Expand Down
1 change: 1 addition & 0 deletions src/PreferencesDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ private slots:
void chooseLocation();
void showColourDialog(QTreeWidgetItem* item, int column);
void addExtension();
void listUpBuiltinExtension();
void removeExtension();
void activateRemoteTab(bool active);
void addClientCertificate();
Expand Down
16 changes: 15 additions & 1 deletion src/PreferencesDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>4</number>
lucydodo marked this conversation as resolved.
Show resolved Hide resolved
lucydodo marked this conversation as resolved.
Show resolved Hide resolved
</property>
<widget class="QWidget" name="tab_4">
<attribute name="title">
Expand Down Expand Up @@ -1846,6 +1846,20 @@ Can be set to 0 for disabling completion.</string>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="labeBuiltinExtensions">
<property name="text">
<string>Select built-in extensions to load for every database:</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="listBuiltinExtensions">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkRegexDisabled">
<property name="toolTip">
Expand Down
12 changes: 12 additions & 0 deletions src/sqlitedb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2170,6 +2170,18 @@ void DBBrowserDB::loadExtensionsFromSettings()
if(loadExtension(ext) == false)
QMessageBox::warning(nullptr, QApplication::applicationName(), tr("Error loading extension: %1").arg(lastError()));
}

#ifdef Q_OS_MACX
const QVariantMap builtinList = Settings::getValue("extensions", "builtin").toMap();
for(const QString& ext : builtinList.keys())
{
if(builtinList.value(ext).toBool())
{
if(loadExtension(qApp->applicationDirPath() + "/../Extensions/" + ext) == false)
QMessageBox::warning(nullptr, QApplication::applicationName(), tr("Error loading built-in extension: %1").arg(lastError()));
}
}
#endif
}

std::vector<std::pair<std::string, std::string>> DBBrowserDB::queryColumnInformation(const std::string& schema_name, const std::string& object_name) const
Expand Down