Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Plugin::Plugin()
throw "QSQLITE driver unavailable";

tryCreateDirectory(docsetsLocation());
tryCreateDirectory(customDocsetsLocation());
tryCreateDirectory(iconsLocation());

connect(this, &Plugin::docsetsChanged, this, &Plugin::updateIndexItems);
Expand Down Expand Up @@ -167,6 +168,19 @@ void Plugin::updateDocsetList()

docsets_.clear();

for (const auto &entry: filesystem::directory_iterator(customDocsetsLocation()))
{
const auto path = entry.path();
if (entry.is_directory() && path.extension() == ".docset" && filesystem::exists(path / "icon.png"))
{
const auto dirname = path.filename().string();
const auto name = QString::fromStdString(dirname.substr(0, dirname.length() - sizeof(".docset") + 1));
const auto icon_path = QString::fromStdString((path / "icon.png").string());
docsets_.emplace_back(name, name, u"custom"_s, icon_path);
docsets_.back().path = QString::fromStdString(path.string());
}
}

QJsonParseError parse_error;
const QJsonDocument json_document = QJsonDocument::fromJson(replyData, &parse_error);
if (parse_error.error == QJsonParseError::NoError)
Expand Down Expand Up @@ -229,10 +243,11 @@ void Plugin::downloadDocset(uint index)

connect(download_, &QNetworkReply::finished, this, [this, &ds]
{
auto docsetDir = QDir(docsetsLocation());
if (download_) // else aborted
{
debug(tr("Download finished."));
if (auto tmp_dir = QTemporaryDir();
if (auto tmp_dir = QTemporaryDir(docsetDir.filePath(u"extractXXXXXX"_s));
tmp_dir.isValid())
{
// write downloaded data to file
Expand All @@ -253,8 +268,7 @@ void Plugin::downloadDocset(uint index)
it.hasNext())
{
auto src = it.next();
auto dst = QDir(docsetsLocation())
.filePath(u"%1.docset"_s.arg(ds.name));
auto dst = docsetDir.filePath(u"%1.docset"_s.arg(ds.name));
debug(tr("Renaming '%1' to '%2'").arg(src, dst));
if (QFile::rename(src, dst))
{
Expand Down Expand Up @@ -350,4 +364,6 @@ void Plugin::error(const QString &msg, QWidget * modal_parent)

filesystem::path Plugin::docsetsLocation() const { return dataLocation() / "docsets"; }

filesystem::path Plugin::customDocsetsLocation() const { return dataLocation() / "custom_docsets"; }

filesystem::path Plugin::iconsLocation() const { return dataLocation() / "icons"; }
1 change: 1 addition & 0 deletions src/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Plugin : public albert::util::ExtensionPlugin,
void debug(const QString &);
void error(const QString &, QWidget *modal_parent = nullptr);
std::filesystem::path docsetsLocation() const;
std::filesystem::path customDocsetsLocation() const;
std::filesystem::path iconsLocation() const;

std::vector<Docset> docsets_;
Expand Down