mirror of
https://github.com/zealdocs/zeal.git
synced 2024-11-30 13:13:53 +03:00
Support for custom docset directory, and docset subdir in zeal binary dir (#37)
This commit is contained in:
parent
1e2f937af3
commit
11dabfb703
@ -31,6 +31,7 @@
|
|||||||
#include <QWebFrame>
|
#include <QWebFrame>
|
||||||
#include <QWebElement>
|
#include <QWebElement>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
|
#include <QFileDialog>
|
||||||
#include "quazip/quazip.h"
|
#include "quazip/quazip.h"
|
||||||
#include "JlCompress.h"
|
#include "JlCompress.h"
|
||||||
|
|
||||||
@ -112,18 +113,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
setHotKey(keySequence);
|
setHotKey(keySequence);
|
||||||
|
|
||||||
// initialise docsets
|
// initialise docsets
|
||||||
auto dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
|
initialiseDocsets();
|
||||||
auto dataDir = QDir(dataLocation);
|
|
||||||
if(!dataDir.cd("docsets")) {
|
|
||||||
dataDir.mkpath("docsets");
|
|
||||||
}
|
|
||||||
dataDir.cd("docsets");
|
|
||||||
for(auto subdir : dataDir.entryInfoList()) {
|
|
||||||
if(subdir.isDir() && subdir.fileName() != "." && subdir.fileName() != "..") {
|
|
||||||
QMetaObject::invokeMethod(docsets, "addDocset", Qt::BlockingQueuedConnection,
|
|
||||||
Q_ARG(QString, subdir.absoluteFilePath()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// initialise ui
|
// initialise ui
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
@ -225,10 +215,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
connect(reply3, &QNetworkReply::downloadProgress, progressCb);
|
connect(reply3, &QNetworkReply::downloadProgress, progressCb);
|
||||||
} else {
|
} else {
|
||||||
if(reply->request().url().path().endsWith("tgz") || reply->request().url().path().endsWith("tar.bz2")) {
|
if(reply->request().url().path().endsWith("tgz") || reply->request().url().path().endsWith("tar.bz2")) {
|
||||||
auto dataDir = QDir(dataLocation);
|
auto dataDir = QDir(docsetsDir());
|
||||||
if(!dataDir.cd("docsets")) {
|
if(!dataDir.exists()) {
|
||||||
QMessageBox::critical(&settingsDialog, "No docsets directory found",
|
QMessageBox::critical(&settingsDialog, "No docsets directory found",
|
||||||
QString("'docsets' directory not found in '%1'").arg(dataLocation));
|
QString("'%s' directory not found").arg(docsetsDir()));
|
||||||
} else {
|
} else {
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
QDir tardir(QCoreApplication::applicationDirPath());
|
QDir tardir(QCoreApplication::applicationDirPath());
|
||||||
@ -301,10 +291,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
QuaZip zipfile(tmp);
|
QuaZip zipfile(tmp);
|
||||||
if(zipfile.open(QuaZip::mdUnzip)) {
|
if(zipfile.open(QuaZip::mdUnzip)) {
|
||||||
tmp->close();
|
tmp->close();
|
||||||
auto dataDir = QDir(dataLocation);
|
auto dataDir = QDir(docsetsDir());
|
||||||
if(!dataDir.cd("docsets")) {
|
if(!dataDir.exists()) {
|
||||||
QMessageBox::critical(&settingsDialog, "No docsets directory found",
|
QMessageBox::critical(&settingsDialog, "No docsets directory found",
|
||||||
QString("'docsets' directory not found in '%1'").arg(dataLocation));
|
QString("'%1' directory not found").arg(docsetsDir()));
|
||||||
} else {
|
} else {
|
||||||
QStringList *files = new QStringList;
|
QStringList *files = new QStringList;
|
||||||
settingsDialog.ui->docsetsProgress->setRange(0, 0);
|
settingsDialog.ui->docsetsProgress->setRange(0, 0);
|
||||||
@ -382,10 +372,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
"Clicking 'Cancel' in this dialog box will not revert the deletion.").arg(
|
"Clicking 'Cancel' in this dialog box will not revert the deletion.").arg(
|
||||||
settingsDialog.ui->listView->currentIndex().data().toString()));
|
settingsDialog.ui->listView->currentIndex().data().toString()));
|
||||||
if(answer == QMessageBox::Yes) {
|
if(answer == QMessageBox::Yes) {
|
||||||
auto dataDir = QDir(dataLocation);
|
auto dataDir = QDir(docsetsDir());
|
||||||
auto docsetName = settingsDialog.ui->listView->currentIndex().data().toString();
|
auto docsetName = settingsDialog.ui->listView->currentIndex().data().toString();
|
||||||
zealList.removeRow(settingsDialog.ui->listView->currentIndex().row());
|
zealList.removeRow(settingsDialog.ui->listView->currentIndex().row());
|
||||||
if(dataDir.cd("docsets")) {
|
if(dataDir.exists()) {
|
||||||
settingsDialog.ui->docsetsProgress->show();
|
settingsDialog.ui->docsetsProgress->show();
|
||||||
settingsDialog.ui->deleteButton->hide();
|
settingsDialog.ui->deleteButton->hide();
|
||||||
settingsDialog.ui->docsetsProgress->setRange(0, 0);
|
settingsDialog.ui->docsetsProgress->setRange(0, 0);
|
||||||
@ -434,6 +424,12 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
settingsDialog.ui->docsetsProgress->show();
|
settingsDialog.ui->docsetsProgress->show();
|
||||||
settingsDialog.ui->docsetsProgress->setRange(0, 0);
|
settingsDialog.ui->docsetsProgress->setRange(0, 0);
|
||||||
});
|
});
|
||||||
|
connect(settingsDialog.ui->storageButton, &QPushButton::clicked, [=]() {
|
||||||
|
QString dir = QFileDialog::getExistingDirectory(0, "Open Directory");
|
||||||
|
if(!dir.isEmpty()) {
|
||||||
|
settingsDialog.ui->storageEdit->setText(dir);
|
||||||
|
}
|
||||||
|
});
|
||||||
connect(settingsAction, &QAction::triggered, [=]() {
|
connect(settingsAction, &QAction::triggered, [=]() {
|
||||||
settingsDialog.setHotKey(hotKey);
|
settingsDialog.setHotKey(hotKey);
|
||||||
settingsDialog.ui->minFontSize->setValue(settings.value("minFontSize").toInt());
|
settingsDialog.ui->minFontSize->setValue(settings.value("minFontSize").toInt());
|
||||||
@ -443,8 +439,15 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
} else {
|
} else {
|
||||||
settingsDialog.ui->radioMinimize->setChecked(true);
|
settingsDialog.ui->radioMinimize->setChecked(true);
|
||||||
}
|
}
|
||||||
|
settingsDialog.ui->storageEdit->setText(docsetsDir());
|
||||||
nativeFilter.setEnabled(false);
|
nativeFilter.setEnabled(false);
|
||||||
if(settingsDialog.exec()) {
|
if(settingsDialog.exec()) {
|
||||||
|
if(settingsDialog.ui->storageEdit->text() != docsetsDir()) {
|
||||||
|
// set new docsets dir
|
||||||
|
settings.setValue("docsetsDir", settingsDialog.ui->storageEdit->text());
|
||||||
|
// reload docsets:
|
||||||
|
initialiseDocsets();
|
||||||
|
}
|
||||||
setHotKey(settingsDialog.hotKey());
|
setHotKey(settingsDialog.hotKey());
|
||||||
settings.setValue("minFontSize", QVariant(ui->webView->settings()->fontSize(QWebSettings::MinimumFontSize)));
|
settings.setValue("minFontSize", QVariant(ui->webView->settings()->fontSize(QWebSettings::MinimumFontSize)));
|
||||||
settings.setValue("hidingBehavior",
|
settings.setValue("hidingBehavior",
|
||||||
@ -723,3 +726,37 @@ void MainWindow::setHotKey(const QKeySequence& hotKey_) {
|
|||||||
free(keycodes);
|
free(keycodes);
|
||||||
#endif // WIN32 or LINUX
|
#endif // WIN32 or LINUX
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString MainWindow::docsetsDir() {
|
||||||
|
if(settings.contains("docsetsDir")) {
|
||||||
|
return settings.value("docsetsDir").toString();
|
||||||
|
} else {
|
||||||
|
auto dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
|
||||||
|
auto dataDir = QDir(dataLocation);
|
||||||
|
if(!dataDir.cd("docsets")) {
|
||||||
|
dataDir.mkpath("docsets");
|
||||||
|
}
|
||||||
|
dataDir.cd("docsets");
|
||||||
|
return dataDir.absolutePath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::initialiseDocsets() {
|
||||||
|
docsets->clear();
|
||||||
|
QDir dataDir(docsetsDir());
|
||||||
|
for(auto subdir : dataDir.entryInfoList()) {
|
||||||
|
if(subdir.isDir() && subdir.fileName() != "." && subdir.fileName() != "..") {
|
||||||
|
QMetaObject::invokeMethod(docsets, "addDocset", Qt::BlockingQueuedConnection,
|
||||||
|
Q_ARG(QString, subdir.absoluteFilePath()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QDir appDir(QCoreApplication::applicationDirPath());
|
||||||
|
if(appDir.cd("docsets")) {
|
||||||
|
for(auto subdir : appDir.entryInfoList()) {
|
||||||
|
if(subdir.isDir() && subdir.fileName() != "." && subdir.fileName() != "..") {
|
||||||
|
QMetaObject::invokeMethod(docsets, "addDocset", Qt::BlockingQueuedConnection,
|
||||||
|
Q_ARG(QString, subdir.absoluteFilePath()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -48,6 +48,8 @@ private:
|
|||||||
QMenu *trayIconMenu;
|
QMenu *trayIconMenu;
|
||||||
int naCount;
|
int naCount;
|
||||||
QMap<QString, QString> urls;
|
QMap<QString, QString> urls;
|
||||||
|
QString docsetsDir();
|
||||||
|
void initialiseDocsets();
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event) {
|
void closeEvent(QCloseEvent *event) {
|
||||||
settings.setValue("geometry", saveGeometry());
|
settings.setValue("geometry", saveGeometry());
|
||||||
|
@ -78,6 +78,12 @@ public:
|
|||||||
types.remove(name);
|
types.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clear() {
|
||||||
|
for(auto key : dbs.keys()) {
|
||||||
|
remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString prepareQuery(const QString& rawQuery);
|
QString prepareQuery(const QString& rawQuery);
|
||||||
void runQuery(const QString& query);
|
void runQuery(const QString& query);
|
||||||
const QList<ZealSearchResult>& getQueryResults();
|
const QList<ZealSearchResult>& getQueryResults();
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>459</width>
|
<width>568</width>
|
||||||
<height>505</height>
|
<height>505</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -81,6 +81,58 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="4" column="0">
|
||||||
|
<widget class="QLabel" name="label_5">
|
||||||
|
<property name="text">
|
||||||
|
<string>Docsets storage directory</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="1">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="storageEdit"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="storageButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Browse...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_4" stretch="0,1">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_7">
|
||||||
|
<property name="text">
|
||||||
|
<string>NOTE:</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_6">
|
||||||
|
<property name="text">
|
||||||
|
<string><html><head/><body><p>Zeal will also look for docsets in the 'docsets' subdirectory of the directory containing zeal binary file, if such 'docsets' subdirectory exists. This is meant to be useful for creating portable versions of Zeal.</p></body></html></string>
|
||||||
|
</property>
|
||||||
|
<property name="scaledContents">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
Loading…
Reference in New Issue
Block a user