Support for custom docset directory, and docset subdir in zeal binary dir (#37)

This commit is contained in:
Jerzy Kozera 2013-11-09 00:06:01 +01:00
parent 1e2f937af3
commit 11dabfb703
4 changed files with 118 additions and 21 deletions

View File

@ -31,6 +31,7 @@
#include <QWebFrame>
#include <QWebElement>
#include <QShortcut>
#include <QFileDialog>
#include "quazip/quazip.h"
#include "JlCompress.h"
@ -112,18 +113,7 @@ MainWindow::MainWindow(QWidget *parent) :
setHotKey(keySequence);
// initialise docsets
auto dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
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()));
}
}
initialiseDocsets();
// initialise ui
ui->setupUi(this);
@ -225,10 +215,10 @@ MainWindow::MainWindow(QWidget *parent) :
connect(reply3, &QNetworkReply::downloadProgress, progressCb);
} else {
if(reply->request().url().path().endsWith("tgz") || reply->request().url().path().endsWith("tar.bz2")) {
auto dataDir = QDir(dataLocation);
if(!dataDir.cd("docsets")) {
auto dataDir = QDir(docsetsDir());
if(!dataDir.exists()) {
QMessageBox::critical(&settingsDialog, "No docsets directory found",
QString("'docsets' directory not found in '%1'").arg(dataLocation));
QString("'%s' directory not found").arg(docsetsDir()));
} else {
#ifdef WIN32
QDir tardir(QCoreApplication::applicationDirPath());
@ -301,10 +291,10 @@ MainWindow::MainWindow(QWidget *parent) :
QuaZip zipfile(tmp);
if(zipfile.open(QuaZip::mdUnzip)) {
tmp->close();
auto dataDir = QDir(dataLocation);
if(!dataDir.cd("docsets")) {
auto dataDir = QDir(docsetsDir());
if(!dataDir.exists()) {
QMessageBox::critical(&settingsDialog, "No docsets directory found",
QString("'docsets' directory not found in '%1'").arg(dataLocation));
QString("'%1' directory not found").arg(docsetsDir()));
} else {
QStringList *files = new QStringList;
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(
settingsDialog.ui->listView->currentIndex().data().toString()));
if(answer == QMessageBox::Yes) {
auto dataDir = QDir(dataLocation);
auto dataDir = QDir(docsetsDir());
auto docsetName = settingsDialog.ui->listView->currentIndex().data().toString();
zealList.removeRow(settingsDialog.ui->listView->currentIndex().row());
if(dataDir.cd("docsets")) {
if(dataDir.exists()) {
settingsDialog.ui->docsetsProgress->show();
settingsDialog.ui->deleteButton->hide();
settingsDialog.ui->docsetsProgress->setRange(0, 0);
@ -434,6 +424,12 @@ MainWindow::MainWindow(QWidget *parent) :
settingsDialog.ui->docsetsProgress->show();
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, [=]() {
settingsDialog.setHotKey(hotKey);
settingsDialog.ui->minFontSize->setValue(settings.value("minFontSize").toInt());
@ -443,8 +439,15 @@ MainWindow::MainWindow(QWidget *parent) :
} else {
settingsDialog.ui->radioMinimize->setChecked(true);
}
settingsDialog.ui->storageEdit->setText(docsetsDir());
nativeFilter.setEnabled(false);
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());
settings.setValue("minFontSize", QVariant(ui->webView->settings()->fontSize(QWebSettings::MinimumFontSize)));
settings.setValue("hidingBehavior",
@ -723,3 +726,37 @@ void MainWindow::setHotKey(const QKeySequence& hotKey_) {
free(keycodes);
#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()));
}
}
}
}

View File

@ -48,6 +48,8 @@ private:
QMenu *trayIconMenu;
int naCount;
QMap<QString, QString> urls;
QString docsetsDir();
void initialiseDocsets();
protected:
void closeEvent(QCloseEvent *event) {
settings.setValue("geometry", saveGeometry());

View File

@ -78,6 +78,12 @@ public:
types.remove(name);
}
void clear() {
for(auto key : dbs.keys()) {
remove(key);
}
}
QString prepareQuery(const QString& rawQuery);
void runQuery(const QString& query);
const QList<ZealSearchResult>& getQueryResults();

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>459</width>
<width>568</width>
<height>505</height>
</rect>
</property>
@ -81,6 +81,58 @@
</item>
</layout>
</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>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;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.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
</layout>