Skip to content

Commit

Permalink
Merge branch 'master' into better-keyboard-selection
Browse files Browse the repository at this point in the history
  • Loading branch information
trollixx authored Oct 10, 2018
2 parents 1936d03 + eed785c commit f002e41
Show file tree
Hide file tree
Showing 27 changed files with 254 additions and 85 deletions.
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file allows automatic assignment of pull requests.
# See https://help.github.com/articles/about-codeowners/

* oleg@zealdocs.org
9 changes: 9 additions & 0 deletions .github/lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Configuration for the Lock Threads app - https://probot.github.io/apps/lock/

daysUntilLock: 180
lockComment: >
This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
a related request.
setLockReason: false
only: issues
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ Makefile*

# CMake
CMakeLists.txt.user

# VS Code
/.vscode

# Linux appdata
/assets/freedesktop/org.zealdocs.Zeal.appdata.xml
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.5.1)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

project(Zeal VERSION 0.6.0)
project(Zeal VERSION 0.6.1)
set(RELEASE_DATE 2018-09-28)

# Project information.
if(APPLE)
Expand All @@ -11,7 +12,7 @@ else()
endif()

set(PROJECT_COMPANY_NAME "ZealDocs")
string(TIMESTAMP PROJECT_COPYRIGHT "© 2015-%Y Oleg Shparber" UTC)
set(PROJECT_COPYRIGHT "© 2015-2018 Oleg Shparber")
set(PROJECT_DESCRIPTION "A simple documentation browser.")
set(PROJECT_URL "https://zealdocs.org")

Expand Down
18 changes: 1 addition & 17 deletions assets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1 @@
if(UNIX AND NOT APPLE)
find_package(ECM REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_KDE_MODULE_DIR})
include(KDEInstallDirs)

foreach(_i 16 24 32 64 128)
install(FILES "freedesktop/appicons/${_i}/zeal.png"
DESTINATION "${KDE_INSTALL_ICONDIR}/hicolor/${_i}x${_i}/apps"
# TODO: Use `RENAME zeal.png` and get rid of subdirectories.
)
endforeach()

# TODO: Generate via zeal.desktop.in.
install(FILES "freedesktop/zeal.desktop"
DESTINATION ${KDE_INSTALL_APPDIR}
)
endif()
add_subdirectory(freedesktop)
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
27 changes: 27 additions & 0 deletions assets/freedesktop/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
if(UNIX AND NOT APPLE)
find_package(ECM 1.0.0 REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
include(ECMInstallIcons)
include(KDEInstallDirs)

ecm_install_icons(ICONS "16-apps-zeal.png"
"24-apps-zeal.png"
"32-apps-zeal.png"
"64-apps-zeal.png"
"128-apps-zeal.png"
DESTINATION ${KDE_INSTALL_ICONDIR}
)

configure_file(
org.zealdocs.Zeal.appdata.xml.in
org.zealdocs.Zeal.appdata.xml
)

install(FILES ${CMAKE_BINARY_DIR}/assets/freedesktop/org.zealdocs.Zeal.appdata.xml
DESTINATION ${KDE_INSTALL_METAINFODIR}
)

install(FILES "org.zealdocs.Zeal.desktop"
DESTINATION ${KDE_INSTALL_APPDIR}
)
endif()
55 changes: 55 additions & 0 deletions assets/freedesktop/org.zealdocs.Zeal.appdata.xml.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<id>org.zealdocs.Zeal.desktop</id>
<name>Zeal</name>
<metadata_license>CC0-1.0</metadata_license>
<project_license>GPL-3.0-only</project_license>
<summary>Documentation browser</summary>
<description>
<p>Zeal is a simple offline documentation browser inspired by Dash.</p>
</description>
<url type="homepage">https://zealdocs.org/</url>
<url type="bugtracker">https://github.com/zealdocs/zeal/issues</url>
<url type="help">https://zealdocs.org/usage.html</url>
<screenshots>
<screenshot type="default">
<image>https://i.imgur.com/qBkZduS.png</image>
</screenshot>
</screenshots>
<provides>
<id>zeal.desktop</id>
</provides>
<releases>
<release date="${RELEASE_DATE}" version="${Zeal_VERSION}" />
</releases>
<update_contact>zeal@zealdocs.org</update_contact>
<content_rating type="oars-1.1">
<content_attribute id="violence-cartoon">none</content_attribute>
<content_attribute id="violence-fantasy">none</content_attribute>
<content_attribute id="violence-realistic">none</content_attribute>
<content_attribute id="violence-bloodshed">none</content_attribute>
<content_attribute id="violence-sexual">none</content_attribute>
<content_attribute id="violence-desecration">none</content_attribute>
<content_attribute id="violence-slavery">none</content_attribute>
<content_attribute id="violence-worship">none</content_attribute>
<content_attribute id="drugs-alcohol">none</content_attribute>
<content_attribute id="drugs-narcotics">none</content_attribute>
<content_attribute id="drugs-tobacco">none</content_attribute>
<content_attribute id="sex-nudity">none</content_attribute>
<content_attribute id="sex-themes">none</content_attribute>
<content_attribute id="sex-homosexuality">none</content_attribute>
<content_attribute id="sex-prostitution">none</content_attribute>
<content_attribute id="sex-adultery">none</content_attribute>
<content_attribute id="sex-appearance">none</content_attribute>
<content_attribute id="language-profanity">none</content_attribute>
<content_attribute id="language-humor">none</content_attribute>
<content_attribute id="language-discrimination">none</content_attribute>
<content_attribute id="social-chat">none</content_attribute>
<content_attribute id="social-info">none</content_attribute>
<content_attribute id="social-audio">none</content_attribute>
<content_attribute id="social-location">none</content_attribute>
<content_attribute id="social-contacts">none</content_attribute>
<content_attribute id="money-purchasing">none</content_attribute>
<content_attribute id="money-gambling">none</content_attribute>
</content_rating>
</component>
File renamed without changes.
78 changes: 57 additions & 21 deletions src/libs/core/extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,37 @@
#include <archive.h>
#include <archive_entry.h>

#include <sys/stat.h>

using namespace Zeal::Core;

Extractor::Extractor(QObject *parent) :
QObject(parent)
{
}

void Extractor::extract(const QString &filePath, const QString &destination, const QString &root)
void Extractor::extract(const QString &sourceFile, const QString &destination, const QString &root)
{
ExtractInfo info = {
this, // extractor
archive_read_new(), // archiveHandle
filePath, // filePath
QFileInfo(filePath).size(), // totalBytes
sourceFile, // filePath
QFileInfo(sourceFile).size(), // totalBytes
0 // extractedBytes
};

archive_read_support_filter_all(info.archiveHandle);
archive_read_support_format_all(info.archiveHandle);

int r = archive_read_open_filename(info.archiveHandle, qPrintable(filePath), 10240);
int r = archive_read_open_filename(info.archiveHandle, qPrintable(sourceFile), 10240);
if (r) {
emit error(filePath, QString::fromLocal8Bit(archive_error_string(info.archiveHandle)));
emit error(sourceFile, QString::fromLocal8Bit(archive_error_string(info.archiveHandle)));
return;
}

archive_read_extract_set_progress_callback(info.archiveHandle, &Extractor::progressCallback,
&info);

QDir destinationDir(destination);
if (!root.isEmpty())
if (!root.isEmpty()) {
destinationDir = destinationDir.filePath(root);
}

// TODO: Do not strip root directory in archive if it equals to 'root'
archive_entry *entry;
Expand All @@ -69,25 +68,62 @@ void Extractor::extract(const QString &filePath, const QString &destination, con
// TODO: Remove once https://github.com/libarchive/libarchive/issues/587 is resolved.
QString pathname = QString::fromWCharArray(archive_entry_pathname_w(entry));
#endif
if (!root.isEmpty())

if (!root.isEmpty()) {
pathname.remove(0, pathname.indexOf(QLatin1String("/")) + 1);
archive_entry_set_pathname(entry, qPrintable(destinationDir.filePath(pathname)));
archive_read_extract(info.archiveHandle, entry, 0);
}

const QString filePath = destinationDir.absoluteFilePath(pathname);

const auto filetype = archive_entry_filetype(entry);
if (filetype == S_IFDIR) {
QDir().mkpath(QFileInfo(filePath).absolutePath());
continue;
} else if (filetype != S_IFREG) {
qWarning("Unsupported filetype %d for %s!", filetype, qPrintable(pathname));
continue;
}

QScopedPointer<QFile> file(new QFile(filePath));
if (!file->open(QIODevice::WriteOnly)) {
qWarning("Cannot open file for writing: %s", qPrintable(pathname));
continue;
}

const void *buffer;
size_t size;
std::int64_t offset;
for (;;) {
int rc = archive_read_data_block(info.archiveHandle, &buffer, &size, &offset);
if (rc != ARCHIVE_OK) {
if (rc == ARCHIVE_EOF) {
break;
}

qWarning("Cannot read from archive: %s", archive_error_string(info.archiveHandle));
emit error(sourceFile,
QString::fromLocal8Bit(archive_error_string(info.archiveHandle)));
return;
}

file->write(static_cast<const char *>(buffer), size);
}

emitProgress(info);
}

emit completed(filePath);
emit completed(sourceFile);
archive_read_free(info.archiveHandle);
}

void Extractor::progressCallback(void *ptr)
void Extractor::emitProgress(ExtractInfo &info)
{
ExtractInfo *info = static_cast<ExtractInfo *>(ptr);

const qint64 extractedBytes = archive_filter_bytes(info->archiveHandle, -1);
if (extractedBytes == info->extractedBytes)
const qint64 extractedBytes = archive_filter_bytes(info.archiveHandle, -1);
if (extractedBytes == info.extractedBytes) {
return;
}

info->extractedBytes = extractedBytes;
info.extractedBytes = extractedBytes;

emit info->extractor->progress(info->filePath, extractedBytes, info->totalBytes);
emit progress(info.filePath, extractedBytes, info.totalBytes);
}
7 changes: 4 additions & 3 deletions src/libs/core/extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class Extractor : public QObject
explicit Extractor(QObject *parent = nullptr);

public slots:
void extract(const QString &filePath, const QString &destination, const QString &root = QString());
void extract(const QString &sourceFile,
const QString &destination,
const QString &root = QString());

signals:
void error(const QString &filePath, const QString &message);
Expand All @@ -46,14 +48,13 @@ public slots:

private:
struct ExtractInfo {
Extractor *extractor;
archive *archiveHandle;
QString filePath;
qint64 totalBytes;
qint64 extractedBytes;
};

static void progressCallback(void *ptr);
void emitProgress(ExtractInfo &info);
};

} // namespace Core
Expand Down
18 changes: 17 additions & 1 deletion src/libs/registry/docset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const char DashDocSetPluginKeyword[] = "DashDocSetPluginKeyword";
const char DashIndexFilePath[] = "dashIndexFilePath";
const char DocSetPlatformFamily[] = "DocSetPlatformFamily";
//const char IsDashDocset[] = "isDashDocset";
//const char IsJavaScriptEnabled[] = "isJavaScriptEnabled";
const char IsJavaScriptEnabled[] = "isJavaScriptEnabled";
}
}

Expand Down Expand Up @@ -163,6 +163,10 @@ Docset::Docset(const QString &path) :
}
}

if (plist.contains(InfoPlist::IsJavaScriptEnabled)) {
m_javaScriptEnabled = plist[InfoPlist::IsJavaScriptEnabled].toBool();
}

m_keywords.removeDuplicates();

// Prefer index path provided by the docset over metadata.
Expand Down Expand Up @@ -408,6 +412,13 @@ void Docset::countSymbols()

while (m_db->next()) {
const QString symbolTypeStr = m_db->value(0).toString();

// A workaround for https://github.com/zealdocs/zeal/issues/980.
if (symbolTypeStr.isEmpty()) {
qWarning("Empty symbol type in the '%s' docset, skipping...", qPrintable(m_name));
continue;
}

const QString symbolType = parseSymbolType(symbolTypeStr);
m_symbolStrings.insertMulti(symbolType, symbolTypeStr);
m_symbolCounts[symbolType] += m_db->value(1).toInt();
Expand Down Expand Up @@ -675,6 +686,11 @@ void Docset::setFuzzySearchEnabled(bool enabled)
m_fuzzySearchEnabled = enabled;
}

bool Docset::isJavaScriptEnabled() const
{
return m_javaScriptEnabled;
}

/**
* \brief Returns score based on a substring position in a string.
* \param str Original string.
Expand Down
3 changes: 3 additions & 0 deletions src/libs/registry/docset.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class Docset
bool isFuzzySearchEnabled() const;
void setFuzzySearchEnabled(bool enabled);

bool isJavaScriptEnabled() const;

private:
enum class Type {
Invalid,
Expand Down Expand Up @@ -113,6 +115,7 @@ class Docset
mutable QMap<QString, QMap<QString, QUrl>> m_symbols;
Util::SQLiteDatabase *m_db = nullptr;
bool m_fuzzySearchEnabled = false;
bool m_javaScriptEnabled = false;
};

} // namespace Registry
Expand Down
15 changes: 3 additions & 12 deletions src/libs/registry/searchquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,14 @@ bool SearchQuery::hasKeywords() const
return !m_keywords.isEmpty();
}

bool SearchQuery::hasKeyword(const QString &keyword) const
{
// Temporary workaround for #333
// TODO: Remove once #167 is implemented
for (const QString &kw : m_keywords) {
if (keyword.startsWith(kw, Qt::CaseInsensitive))
return true;
}
return false;
}

bool SearchQuery::hasKeywords(const QStringList &keywords) const
{
for (const QString &keyword : keywords) {
if (m_keywords.contains(keyword))
if (m_keywords.contains(keyword, Qt::CaseInsensitive)) {
return true;
}
}

return false;
}

Expand Down
3 changes: 1 addition & 2 deletions src/libs/registry/searchquery.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ class SearchQuery
/// Returns true if there's a docset filter for the given query
bool hasKeywords() const;

/// Returns true if the docset prefix match the ones given on query
bool hasKeyword(const QString &keyword) const;
/// Returns true if one the query contains one of the @c keywords.
bool hasKeywords(const QStringList &keywords) const;

/// Returns the docset filter raw size for the given query
Expand Down
Loading

0 comments on commit f002e41

Please sign in to comment.