Skip to content

Commit

Permalink
PreferencesDialog: Add new tab for extension loading
Browse files Browse the repository at this point in the history
Add new settings to preferences dialog for automated loading of
extensions for all databases.
  • Loading branch information
MKleusberg committed May 3, 2013
1 parent e36b17a commit 2d8cad2
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ void MainWindow::fileOpen(const QString & fileName)
resetBrowser();
if(ui->mainTab->currentIndex() == 2)
loadPragmas();
loadExtensionsFromSettings();
}
}

Expand Down Expand Up @@ -848,6 +849,7 @@ void MainWindow::openPreferences()
createSyntaxHighlighters();
populateStructure();
resetBrowser();
loadExtensionsFromSettings();
}
}

Expand Down Expand Up @@ -1176,3 +1178,13 @@ void MainWindow::loadExtension()
else
QMessageBox::warning(this, QApplication::applicationName(), tr("Error loading extension: %1").arg(db.lastErrorMessage));
}

void MainWindow::loadExtensionsFromSettings()
{
QStringList list = PreferencesDialog::getSettingsValue("extensions", "list").toStringList();
foreach(QString ext, list)
{
if(db.loadExtension(ext) == false)
QMessageBox::warning(this, QApplication::applicationName(), tr("Error loading extension: %1").arg(db.lastErrorMessage));
}
}
1 change: 1 addition & 0 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class MainWindow : public QMainWindow
void updateRecentFileActions();
void setCurrentFile(const QString& fileName);
void activateFields(bool enable = true);
void loadExtensionsFromSettings();

protected:
void closeEvent(QCloseEvent *);
Expand Down
29 changes: 29 additions & 0 deletions src/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ void PreferencesDialog::loadSettings()
ui->treeSyntaxHighlighting->topLevelItem(i)->setCheckState(4, getSettingsValue("syntaxhighlighter", name + "_italic").toBool() ? Qt::Checked : Qt::Unchecked);
ui->treeSyntaxHighlighting->topLevelItem(i)->setCheckState(5, getSettingsValue("syntaxhighlighter", name + "_underline").toBool() ? Qt::Checked : Qt::Unchecked);
}

ui->listExtensions->addItems(getSettingsValue("extensions", "list").toStringList());
}

void PreferencesDialog::saveSettings()
Expand All @@ -75,6 +77,11 @@ void PreferencesDialog::saveSettings()
setSettingsValue("syntaxhighlighter", name + "_underline", ui->treeSyntaxHighlighting->topLevelItem(i)->checkState(5) == Qt::Checked);
}

QStringList extList;
foreach(QListWidgetItem* item, ui->listExtensions->findItems(QString("*"), Qt::MatchWrap | Qt::MatchWildcard))
extList.append(item->text());
setSettingsValue("extensions", "list", extList);

accept();
}

Expand Down Expand Up @@ -173,6 +180,10 @@ QVariant PreferencesDialog::getSettingsDefaultValue(const QString& group, const
}
}

// extensions/list?
if(group == "extensions" && name == "list")
return QStringList();

// Unknown combination of group and name? Return an invalid QVariant!
return QVariant();
}
Expand All @@ -190,3 +201,21 @@ void PreferencesDialog::showColourDialog(QTreeWidgetItem* item, int column)
item->setText(column, colour.name());
}
}

void PreferencesDialog::addExtension()
{
QString file = QFileDialog::getOpenFileName(
this,
tr("Select extension file"),
PreferencesDialog::getSettingsValue("db", "defaultlocation").toString(),
tr("Extensions(*.so *.dll);;All files(*)"));

if(QFile::exists(file))
ui->listExtensions->addItem(file);
}

void PreferencesDialog::removeExtension()
{
if(ui->listExtensions->currentIndex().isValid())
ui->listExtensions->takeItem(ui->listExtensions->currentIndex().row());
}
5 changes: 4 additions & 1 deletion src/PreferencesDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ class PreferencesDialog : public QDialog
static void setSettingsValue(const QString& group, const QString& name, const QVariant& value);

private slots:
virtual void chooseLocation();
virtual void loadSettings();
virtual void saveSettings();

virtual void chooseLocation();
virtual void showColourDialog(QTreeWidgetItem* item, int column);
virtual void addExtension();
virtual void removeExtension();

private:
Ui::PreferencesDialog *ui;
Expand Down
105 changes: 104 additions & 1 deletion src/PreferencesDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,73 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>&amp;Extensions</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Select extensions to load for every database:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QListWidget" name="listExtensions">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QToolButton" name="buttonAddExtension">
<property name="toolTip">
<string>Add extension</string>
</property>
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/load_extension</normaloff>:/icons/load_extension</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonRemoveExtension">
<property name="toolTip">
<string>Remove extension</string>
</property>
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/remove_extension</normaloff>:/icons/remove_extension</iconset>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item>
Expand All @@ -295,7 +362,9 @@
<tabstop>treeSyntaxHighlighting</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<resources>
<include location="icons/icons.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
Expand Down Expand Up @@ -361,10 +430,44 @@
</hint>
</hints>
</connection>
<connection>
<sender>buttonAddExtension</sender>
<signal>clicked()</signal>
<receiver>PreferencesDialog</receiver>
<slot>addExtension()</slot>
<hints>
<hint type="sourcelabel">
<x>464</x>
<y>64</y>
</hint>
<hint type="destinationlabel">
<x>245</x>
<y>137</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonRemoveExtension</sender>
<signal>clicked()</signal>
<receiver>PreferencesDialog</receiver>
<slot>removeExtension()</slot>
<hints>
<hint type="sourcelabel">
<x>464</x>
<y>93</y>
</hint>
<hint type="destinationlabel">
<x>245</x>
<y>137</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>saveSettings()</slot>
<slot>chooseLocation()</slot>
<slot>showColourDialog(QTreeWidgetItem*,int)</slot>
<slot>addExtension()</slot>
<slot>removeExtension()</slot>
</slots>
</ui>
1 change: 1 addition & 0 deletions src/icons/icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<file alias="save_sql">page_save.png</file>
<file alias="open_sql">page_white_database.png</file>
<file alias="load_extension">plugin_add.png</file>
<file alias="remove_extension">plugin_delete.png</file>
</qresource>
<qresource prefix="/oldimages">
<file alias="128">oldimages/128.png</file>
Expand Down
Binary file added src/icons/plugin_delete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2d8cad2

Please sign in to comment.