Skip to content

Commit 089f927

Browse files
committed
First version to be upload to github
1 parent 9cd8d2d commit 089f927

File tree

420 files changed

+246086
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

420 files changed

+246086
-0
lines changed

COPYING

Lines changed: 619 additions & 0 deletions
Large diffs are not rendered by default.

ZealT.pro

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#-------------------------------------------------
2+
#
3+
# Project created by QtCreator 2021-07-30T16:28:03
4+
#
5+
#-------------------------------------------------
6+
7+
QT += core gui network concurrent
8+
9+
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10+
11+
TARGET = ZealT
12+
TEMPLATE = app
13+
14+
# The following define makes your compiler emit warnings if you use
15+
# any feature of Qt which has been marked as deprecated (the exact warnings
16+
# depend on your compiler). Please consult the documentation of the
17+
# deprecated API in order to know how to port your code away from it.
18+
DEFINES += QT_DEPRECATED_WARNINGS
19+
20+
# You can also make your code fail to compile if you use deprecated APIs.
21+
# In order to do so, uncomment the following line.
22+
# You can also select to disable deprecated APIs only up to a certain version of Qt.
23+
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
24+
25+
26+
SOURCES += \
27+
core/application.cpp \
28+
core/applicationsingleton.cpp \
29+
core/filemanager.cpp \
30+
core/networkaccessmanager.cpp \
31+
core/settings.cpp \
32+
main.cpp \
33+
registry/docset.cpp \
34+
registry/docsetmetadata.cpp \
35+
registry/docsetregistry.cpp \
36+
registry/listmodel.cpp \
37+
registry/searchmodel.cpp \
38+
registry/searchquery.cpp \
39+
ui/aboutdialog.cpp \
40+
ui/docsetlistitemdelegate.cpp \
41+
ui/docsetsdialog.cpp \
42+
ui/mainwindow.cpp \
43+
ui/progressitemdelegate.cpp \
44+
ui/qxtglobalshortcut/qxtglobalshortcut.cpp \
45+
ui/qxtglobalshortcut/qxtglobalshortcut_win.cpp \
46+
ui/searchitemdelegate.cpp \
47+
ui/settingsdialog.cpp \
48+
ui/webbridge.cpp \
49+
ui/widgets/searchedit.cpp \
50+
ui/widgets/searchtoolbar.cpp \
51+
ui/widgets/shortcutedit.cpp \
52+
ui/widgets/toolbarframe.cpp \
53+
util/plist.cpp \
54+
util/sqlitedatabase.cpp \
55+
util/version.cpp
56+
57+
HEADERS += \
58+
core/application.h \
59+
core/applicationsingleton.h \
60+
core/filemanager.h \
61+
core/networkaccessmanager.h \
62+
core/settings.h \
63+
registry/cancellationtoken.h \
64+
registry/docset.h \
65+
registry/docsetmetadata.h \
66+
registry/docsetregistry.h \
67+
registry/itemdatarole.h \
68+
registry/listmodel.h \
69+
registry/searchmodel.h \
70+
registry/searchquery.h \
71+
registry/searchresult.h \
72+
ui/aboutdialog.h \
73+
ui/docsetlistitemdelegate.h \
74+
ui/docsetsdialog.h \
75+
ui/mainwindow.h \
76+
ui/progressitemdelegate.h \
77+
ui/qxtglobalshortcut/qxtglobalshortcut.h \
78+
ui/qxtglobalshortcut/qxtglobalshortcut_p.h \
79+
ui/searchitemdelegate.h \
80+
ui/settingsdialog.h \
81+
ui/webbridge.h \
82+
ui/widgets/searchedit.h \
83+
ui/widgets/searchtoolbar.h \
84+
ui/widgets/shortcutedit.h \
85+
ui/widgets/toolbarframe.h \
86+
util/plist.h \
87+
util/sqlitedatabase.h \
88+
util/version.h
89+
90+
FORMS += \
91+
ui/aboutdialog.ui \
92+
ui/docsetsdialog.ui \
93+
ui/mainwindow.ui \
94+
ui/settingsdialog.ui
95+
96+
RESOURCES += \
97+
resources/zeal.qrc
98+
99+
100+
# LIBS += -L"$$PWD/libarchive/lib" -larchive.lib
101+
# LIBS += -l"$$PWD/libarchive/lib/archive.lib"
102+
LIBS += "$$PWD/libarchive/lib/archive.lib"
103+
# LIBS += -L"$$PWD/libarchive/lib" -larchive_static
104+
105+
INCLUDEPATH += libarchive/include
106+
DEPENDPATH += libarchive/include
107+
108+
# LIBS += -L"$$PWD/sqlite/lib" -lsqlite3.lib
109+
# LIBS += -l"$$PWD/sqlite/lib/sqlite3.lib"
110+
LIBS += "$$PWD/sqlite/lib/sqlite3.lib"
111+
112+
INCLUDEPATH += sqlite/include
113+
DEPENDPATH += sqlite/include

core/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
add_library(Core
2+
application.cpp
3+
applicationsingleton.cpp
4+
extractor.cpp
5+
filemanager.cpp
6+
networkaccessmanager.cpp
7+
settings.cpp
8+
)
9+
10+
target_link_libraries(Core Registry Ui)
11+
12+
find_package(Qt5 COMPONENTS Network WebKit Widgets REQUIRED)
13+
target_link_libraries(Core Qt5::Network Qt5::WebKit Qt5::Widgets)
14+
15+
find_package(LibArchive REQUIRED)
16+
include_directories(${LibArchive_INCLUDE_DIRS})
17+
target_link_libraries(Core ${LibArchive_LIBRARIES})

core/application.cpp

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
/****************************************************************************
2+
**
3+
** Copyright (C) 2015-2016 Oleg Shparber
4+
** Contact: https://go.zealdocs.org/l/contact
5+
**
6+
** This file is part of Zeal.
7+
**
8+
** Zeal is free software: you can redistribute it and/or modify
9+
** it under the terms of the GNU General Public License as published by
10+
** the Free Software Foundation, either version 3 of the License, or
11+
** (at your option) any later version.
12+
**
13+
** Zeal is distributed in the hope that it will be useful,
14+
** but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
** GNU General Public License for more details.
17+
**
18+
** You should have received a copy of the GNU General Public License
19+
** along with Zeal. If not, see <https://www.gnu.org/licenses/>.
20+
**
21+
****************************************************************************/
22+
23+
#include "application.h"
24+
25+
#include "extractor.h"
26+
#include "filemanager.h"
27+
#include "networkaccessmanager.h"
28+
#include "settings.h"
29+
30+
#include <registry/docsetregistry.h>
31+
#include <registry/searchquery.h>
32+
#include <ui/mainwindow.h>
33+
#include <util/version.h>
34+
35+
#include <QCoreApplication>
36+
#include <QJsonArray>
37+
#include <QJsonDocument>
38+
#include <QJsonObject>
39+
#include <QMetaObject>
40+
#include <QNetworkProxy>
41+
#include <QNetworkReply>
42+
#include <QScopedPointer>
43+
#include <QSysInfo>
44+
#include <QThread>
45+
46+
using namespace Zeal;
47+
using namespace Zeal::Core;
48+
49+
namespace {
50+
const char ReleasesApiUrl[] = "http://api.zealdocs.org/v1/releases";
51+
}
52+
53+
Application *Application::m_instance = nullptr;
54+
55+
Application::Application(QObject *parent) :
56+
QObject(parent)
57+
{
58+
// Ensure only one instance of Application
59+
Q_ASSERT(!m_instance);
60+
m_instance = this;
61+
62+
m_settings = new Settings(this);
63+
m_networkManager = new NetworkAccessManager(this);
64+
65+
m_fileManager = new FileManager(this);
66+
67+
// Extractor setup
68+
// m_extractorThread = new QThread(this);
69+
// m_extractor = new Extractor();
70+
// m_extractor->moveToThread(m_extractorThread);
71+
// m_extractorThread->start();
72+
// connect(m_extractor, &Extractor::completed, this, &Application::extractionCompleted);
73+
// connect(m_extractor, &Extractor::error, this, &Application::extractionError);
74+
// connect(m_extractor, &Extractor::progress, this, &Application::extractionProgress);
75+
76+
m_docsetRegistry = new Registry::DocsetRegistry();
77+
78+
connect(m_settings, &Settings::updated, this, &Application::applySettings);
79+
applySettings();
80+
81+
m_mainWindow = new WidgetUi::MainWindow(this);
82+
83+
if (m_settings->startMinimized) {
84+
if (m_settings->showSystrayIcon && m_settings->minimizeToSystray)
85+
return;
86+
87+
m_mainWindow->showMinimized();
88+
} else {
89+
m_mainWindow->show();
90+
}
91+
}
92+
93+
Application::~Application()
94+
{
95+
// m_extractorThread->quit();
96+
// m_extractorThread->wait();
97+
// delete m_extractor;
98+
delete m_mainWindow;
99+
delete m_docsetRegistry;
100+
}
101+
102+
/*!
103+
* \internal
104+
* \brief Returns a pointer to the Core::Application instance.
105+
* \return A pointer or \c nullptr, if no instance has been created.
106+
*/
107+
Application *Application::instance()
108+
{
109+
return m_instance;
110+
}
111+
112+
WidgetUi::MainWindow *Application::mainWindow() const
113+
{
114+
return m_mainWindow;
115+
}
116+
117+
QNetworkAccessManager *Application::networkManager() const
118+
{
119+
return m_networkManager;
120+
}
121+
122+
Settings *Application::settings() const
123+
{
124+
return m_settings;
125+
}
126+
127+
Registry::DocsetRegistry *Application::docsetRegistry()
128+
{
129+
return m_docsetRegistry;
130+
}
131+
132+
FileManager *Application::fileManager() const
133+
{
134+
return m_fileManager;
135+
}
136+
137+
void Application::executeQuery(const Registry::SearchQuery &query, bool preventActivation)
138+
{
139+
m_mainWindow->search(query);
140+
141+
if (preventActivation)
142+
return;
143+
144+
m_mainWindow->bringToFront();
145+
}
146+
147+
//void Application::extract(const QString &filePath, const QString &destination, const QString &root)
148+
//{
149+
//// QMetaObject::invokeMethod(m_extractor, "extract", Qt::QueuedConnection,
150+
//// Q_ARG(QString, filePath), Q_ARG(QString, destination),
151+
//// Q_ARG(QString, root));
152+
//}
153+
154+
QNetworkReply *Application::download(const QUrl &url)
155+
{
156+
static const QString ua = userAgent();
157+
static const QByteArray uaJson = userAgentJson().toUtf8();
158+
159+
QNetworkRequest request(url);
160+
request.setHeader(QNetworkRequest::UserAgentHeader, ua);
161+
162+
if (url.host().endsWith(QLatin1String(".zealdocs.org", Qt::CaseInsensitive)))
163+
request.setRawHeader("X-Zeal-User-Agent", uaJson);
164+
165+
return m_networkManager->get(request);
166+
}
167+
168+
/*!
169+
\internal
170+
171+
Performs a check whether a new Zeal version is available. Setting \a quiet to true supresses
172+
error and "you are using the latest version" message boxes.
173+
*/
174+
// void Application::checkForUpdates(bool quiet)
175+
// {
176+
// QNetworkReply *reply = download(QUrl(ReleasesApiUrl));
177+
// connect(reply, &QNetworkReply::finished, this, [this, quiet]() {
178+
// QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply(
179+
// qobject_cast<QNetworkReply *>(sender()));
180+
181+
// if (reply->error() != QNetworkReply::NoError) {
182+
// if (!quiet)
183+
// emit updateCheckError(reply->errorString());
184+
// return;
185+
// }
186+
187+
// QJsonParseError jsonError;
188+
// const QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &jsonError);
189+
190+
// if (jsonError.error != QJsonParseError::NoError) {
191+
// if (!quiet)
192+
// emit updateCheckError(jsonError.errorString());
193+
// return;
194+
// }
195+
196+
// const QJsonObject latestVersionInfo = jsonDoc.array().first().toObject();
197+
// const Util::Version latestVersion = latestVersionInfo[QStringLiteral("version")].toString();
198+
// if (latestVersion > Util::Version(QCoreApplication::applicationVersion()))
199+
// emit updateCheckDone(latestVersion.toString());
200+
// else if (!quiet)
201+
// emit updateCheckDone();
202+
// });
203+
// }
204+
205+
void Application::applySettings()
206+
{
207+
m_docsetRegistry->setStoragePath(m_settings->docsetPath);
208+
m_docsetRegistry->setFuzzySearchEnabled(m_settings->fuzzySearchEnabled);
209+
210+
// HTTP Proxy Settings
211+
switch (m_settings->proxyType) {
212+
case Core::Settings::ProxyType::None:
213+
QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy);
214+
break;
215+
216+
case Core::Settings::ProxyType::System:
217+
QNetworkProxyFactory::setUseSystemConfiguration(true);
218+
break;
219+
220+
case Core::Settings::ProxyType::UserDefined: {
221+
QNetworkProxy proxy(QNetworkProxy::HttpProxy, m_settings->proxyHost, m_settings->proxyPort);
222+
if (m_settings->proxyAuthenticate) {
223+
proxy.setUser(m_settings->proxyUserName);
224+
proxy.setPassword(m_settings->proxyPassword);
225+
}
226+
227+
QNetworkProxy::setApplicationProxy(proxy);
228+
229+
// Force NM to pick up changes.
230+
m_networkManager->clearAccessCache();
231+
break;
232+
}
233+
}
234+
}
235+
236+
QString Application::userAgent()
237+
{
238+
return QStringLiteral("Zeal/%1").arg(QCoreApplication::applicationVersion());
239+
}
240+
241+
QString Application::userAgentJson() const
242+
{
243+
QJsonObject app = {
244+
{QStringLiteral("version"), QCoreApplication::applicationVersion()},
245+
{QStringLiteral("qt_version"), qVersion()},
246+
{QStringLiteral("install_id"), m_settings->installId}
247+
};
248+
249+
QJsonObject os = {
250+
{QStringLiteral("arch"), QSysInfo::currentCpuArchitecture()},
251+
{QStringLiteral("name"), QSysInfo::prettyProductName()},
252+
{QStringLiteral("product_type"), QSysInfo::productType()},
253+
{QStringLiteral("product_version"), QSysInfo::productVersion()},
254+
{QStringLiteral("kernel_type"), QSysInfo::kernelType()},
255+
{QStringLiteral("kernel_version"), QSysInfo::kernelVersion()},
256+
{QStringLiteral("locale"), QLocale::system().name()}
257+
};
258+
259+
QJsonObject ua = {
260+
{QStringLiteral("app"), app},
261+
{QStringLiteral("os"), os}
262+
};
263+
264+
return QString::fromUtf8(QJsonDocument(ua).toJson(QJsonDocument::Compact));
265+
}

0 commit comments

Comments
 (0)