mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-25 13:56:39 -04:00
commit
6eb886208f
@ -46,6 +46,8 @@ SOURCES += \
|
||||
src/kiwixapp.cpp \
|
||||
src/blobbuffer.cpp \
|
||||
src/library.cpp \
|
||||
src/settingsmanager.cpp \
|
||||
src/settingsmanagerview.cpp \
|
||||
src/topwidget.cpp \
|
||||
src/urlschemehandler.cpp \
|
||||
src/webview.cpp \
|
||||
@ -68,6 +70,8 @@ HEADERS += \
|
||||
src/kiwixapp.h \
|
||||
src/blobbuffer.h \
|
||||
src/library.h \
|
||||
src/settingsmanager.h \
|
||||
src/settingsmanagerview.h \
|
||||
src/topwidget.h \
|
||||
src/kconstants.h \
|
||||
src/urlschemehandler.h \
|
||||
@ -148,6 +152,7 @@ RESOURCES += \
|
||||
resources/kiwix.qrc \
|
||||
resources/translations.qrc \
|
||||
resources/contentmanager.qrc \
|
||||
resources/settingsmanager.qrc \
|
||||
resources/style.qrc
|
||||
|
||||
unix {
|
||||
|
28
resources/css/_settingsManager.css
Normal file
28
resources/css/_settingsManager.css
Normal file
@ -0,0 +1,28 @@
|
||||
html, body {
|
||||
padding: 0;
|
||||
margin: auto;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
width: 75%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#settings {
|
||||
height: 100%;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
border-top: 1px solid grey;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
input[type=number]::-webkit-inner-spin-button,
|
||||
input[type=number]::-webkit-outer-spin-button {
|
||||
opacity: 1;
|
||||
}
|
24
resources/js/_settingsManager.js
Normal file
24
resources/js/_settingsManager.js
Normal file
@ -0,0 +1,24 @@
|
||||
function init() {
|
||||
new QWebChannel(qt.webChannelTransport, function(channel) {
|
||||
settingsManager = channel.objects.settingsManager;
|
||||
app = new Vue({
|
||||
el: "#settings",
|
||||
data: {
|
||||
settingsManager: settingsManager,
|
||||
kiwixServerPort: settingsManager.kiwixServerPort,
|
||||
},
|
||||
methods: {
|
||||
setPort : function() {
|
||||
// regex for valid port
|
||||
if (/^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$/.test(this.kiwixServerPort))
|
||||
{
|
||||
settingsManager.setKiwixServerPort(this.kiwixServerPort);
|
||||
} else {
|
||||
alert("invalid port");
|
||||
this.kiwixServerPort = settingsManager.kiwixServerPort;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
7
resources/settingsmanager.qrc
Normal file
7
resources/settingsmanager.qrc
Normal file
@ -0,0 +1,7 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>texts/_settingsManager.html</file>
|
||||
<file>css/_settingsManager.css</file>
|
||||
<file>js/_settingsManager.js</file>
|
||||
</qresource>
|
||||
</RCC>
|
18
resources/texts/_settingsManager.html
Normal file
18
resources/texts/_settingsManager.html
Normal file
@ -0,0 +1,18 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<script src="qrc:///js/vue.js"></script>
|
||||
<script src="qrc:///qtwebchannel/qwebchannel.js"></script>
|
||||
<script src="qrc:///js/_settingsManager.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="qrc:///css/_settingsManager.css"/>
|
||||
</head>
|
||||
<body onload="init()">
|
||||
<div id="settings">
|
||||
<h1>Settings</h1>
|
||||
<div class="row">
|
||||
<label>Port for local Kiwix server : </label>
|
||||
<input type="number" min="1" max="65535" v-model="kiwixServerPort" v-on:change="setPort()">
|
||||
</div>
|
||||
</div>
|
||||
</body></html>
|
||||
|
@ -27,13 +27,14 @@ kiwix::Downloader* createDownloader() {
|
||||
|
||||
KiwixApp::KiwixApp(int& argc, char *argv[])
|
||||
: QApplication(argc, argv),
|
||||
m_settingsManager(),
|
||||
m_libraryDirectory(findLibraryDirectory()),
|
||||
m_library(),
|
||||
mp_downloader(createDownloader()),
|
||||
m_manager(&m_library, mp_downloader),
|
||||
mp_server(new kiwix::KiwixServe(
|
||||
appendToDirectory(m_libraryDirectory.toStdString(),"library.xml"),
|
||||
8181))
|
||||
m_settingsManager.getKiwixServerPort()))
|
||||
{
|
||||
m_qtTranslator.load(QLocale(), "qt", "_",
|
||||
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
||||
@ -377,8 +378,7 @@ void KiwixApp::createAction()
|
||||
CREATE_ACTION(AboutAction, tr("About Kiwix"));
|
||||
|
||||
CREATE_ACTION_ICON(SettingAction, "settings", tr("Settings"));
|
||||
SET_SHORTCUT(SettingAction, QKeySequence::Preferences);
|
||||
HIDE_ACTION(SettingAction);
|
||||
SET_SHORTCUT(SettingAction, QKeySequence(Qt::Key_F12));
|
||||
|
||||
CREATE_ACTION_ICON(DonateAction, "donate", tr("Donate to support Kiwix"));
|
||||
SET_SHORTCUT(DonateAction, QKeySequence("Ctrl+<,3"));
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "tabbar.h"
|
||||
#include "tocsidebar.h"
|
||||
#include "urlschemehandler.h"
|
||||
#include "settingsmanager.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QErrorMessage>
|
||||
@ -75,6 +76,7 @@ public:
|
||||
QAction* getAction(Actions action);
|
||||
QString getLibraryDirectory() { return m_libraryDirectory; };
|
||||
kiwix::KiwixServe* getLocalServer() { return mp_server; }
|
||||
SettingsManager* getSettingsManager() { return &m_settingsManager; };
|
||||
|
||||
bool isCurrentArticleBookmarked();
|
||||
|
||||
@ -97,6 +99,7 @@ protected:
|
||||
|
||||
private:
|
||||
QTranslator m_qtTranslator, m_appTranslator;
|
||||
SettingsManager m_settingsManager;
|
||||
UrlSchemeHandler m_schemeHandler;
|
||||
QString m_libraryDirectory;
|
||||
Library m_library;
|
||||
|
@ -23,6 +23,8 @@ LocalKiwixServer::LocalKiwixServer(QWidget *parent) :
|
||||
|
||||
connect(ui->KiwixServerButton, SIGNAL(clicked()), this, SLOT(runOrStopServer()));
|
||||
connect(ui->OpenInBrowserButton, SIGNAL(clicked()), this, SLOT(openInBrowser()));
|
||||
connect(KiwixApp::instance()->getSettingsManager(), &SettingsManager::portChanged,
|
||||
this, [=](int port) { m_port = port; });
|
||||
const QHostAddress &localhost = QHostAddress(QHostAddress::LocalHost);
|
||||
for (const QHostAddress &address: QNetworkInterface::allAddresses()) {
|
||||
if (address.protocol() == QAbstractSocket::IPv4Protocol && address != localhost) {
|
||||
@ -44,13 +46,14 @@ void LocalKiwixServer::openInBrowser()
|
||||
QUrl url;
|
||||
url.setScheme("http");
|
||||
url.setHost(m_ipAddress);
|
||||
url.setPort(m_port);
|
||||
url.setPort(mp_server->getPort());
|
||||
QDesktopServices::openUrl(url);
|
||||
}
|
||||
|
||||
void LocalKiwixServer::runOrStopServer()
|
||||
{
|
||||
if (!m_active) {
|
||||
mp_server->setPort(m_port);
|
||||
mp_server->run();
|
||||
ui->IpAddress->setText(m_ipAddress + ":" + QString::number(m_port));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
|
31
src/settingsmanager.cpp
Normal file
31
src/settingsmanager.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include "settingsmanager.h"
|
||||
|
||||
SettingsManager::SettingsManager(QObject *parent)
|
||||
: QObject(parent),
|
||||
m_settings("Kiwix", "Kiwix-desktop"),
|
||||
m_settingsViewDisplayed(false)
|
||||
{
|
||||
setSettings();
|
||||
}
|
||||
|
||||
SettingsManagerView* SettingsManager::getView()
|
||||
{
|
||||
auto view = new SettingsManagerView();
|
||||
view->registerObject("settingsManager", this);
|
||||
view->setHtml();
|
||||
connect(view, &QObject::destroyed, this, [=]() { m_settingsViewDisplayed = false; });
|
||||
m_settingsViewDisplayed = true;
|
||||
return view;
|
||||
}
|
||||
|
||||
void SettingsManager::setKiwixServerPort(int port)
|
||||
{
|
||||
m_kiwixServerPort = port;
|
||||
m_settings.setValue("localKiwixServer/port", port);
|
||||
emit(portChanged(port));
|
||||
}
|
||||
|
||||
void SettingsManager::setSettings()
|
||||
{
|
||||
m_kiwixServerPort = m_settings.value("localKiwixServer/port", 8181).toInt();
|
||||
}
|
35
src/settingsmanager.h
Normal file
35
src/settingsmanager.h
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef SETTINGSMANAGER_H
|
||||
#define SETTINGSMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
#include "settingsmanagerview.h"
|
||||
|
||||
class SettingsManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int kiwixServerPort READ getKiwixServerPort NOTIFY portChanged)
|
||||
public:
|
||||
explicit SettingsManager(QObject *parent = nullptr);
|
||||
virtual ~SettingsManager() {};
|
||||
|
||||
SettingsManagerView* getView();
|
||||
bool isSettingsViewdisplayed() { return m_settingsViewDisplayed; };
|
||||
|
||||
public slots:
|
||||
void setKiwixServerPort(int port);
|
||||
int getKiwixServerPort() { return m_kiwixServerPort; };
|
||||
|
||||
private:
|
||||
void setSettings();
|
||||
|
||||
signals:
|
||||
void portChanged(int port);
|
||||
|
||||
private:
|
||||
QSettings m_settings;
|
||||
bool m_settingsViewDisplayed;
|
||||
int m_kiwixServerPort;
|
||||
};
|
||||
|
||||
#endif // SETTINGSMANAGER_H
|
24
src/settingsmanagerview.cpp
Normal file
24
src/settingsmanagerview.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "settingsmanagerview.h"
|
||||
#include "kiwixapp.h"
|
||||
#include <QFile>
|
||||
#include <QWebEngineProfile>
|
||||
|
||||
SettingsManagerView::SettingsManagerView(QWidget *parent) : QWebEngineView(parent)
|
||||
{
|
||||
page()->setWebChannel(&m_webChannel);
|
||||
setContextMenuPolicy( Qt::NoContextMenu );
|
||||
}
|
||||
|
||||
void SettingsManagerView::registerObject(const QString& id, QObject* object)
|
||||
{
|
||||
m_webChannel.registerObject(id, object);
|
||||
}
|
||||
|
||||
void SettingsManagerView::setHtml()
|
||||
{
|
||||
QFile contentFile(":texts/_settingsManager.html");
|
||||
contentFile.open(QIODevice::ReadOnly);
|
||||
auto byteContent = contentFile.readAll();
|
||||
contentFile.close();
|
||||
QWebEngineView::setHtml(byteContent);
|
||||
}
|
18
src/settingsmanagerview.h
Normal file
18
src/settingsmanagerview.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef SETTINGSMANAGERVIEW_H
|
||||
#define SETTINGSMANAGERVIEW_H
|
||||
|
||||
#include <QWebEngineView>
|
||||
#include <QWebChannel>
|
||||
|
||||
class SettingsManagerView : public QWebEngineView
|
||||
{
|
||||
public:
|
||||
SettingsManagerView(QWidget *parent = nullptr);
|
||||
void registerObject(const QString &id, QObject *object);
|
||||
void setHtml();
|
||||
|
||||
private:
|
||||
QWebChannel m_webChannel;
|
||||
};
|
||||
|
||||
#endif // SETTINGSMANAGERVIEW_H
|
@ -12,7 +12,8 @@
|
||||
#define CURRENTIFNULL(VIEW) if(nullptr==VIEW) { VIEW = currentWidget();}
|
||||
|
||||
TabBar::TabBar(QWidget *parent) :
|
||||
QTabBar(parent)
|
||||
QTabBar(parent),
|
||||
m_settingsIndex(-1)
|
||||
{
|
||||
setTabsClosable(true);
|
||||
setElideMode(Qt::ElideRight);
|
||||
@ -67,6 +68,18 @@ TabBar::TabBar(QWidget *parent) :
|
||||
QUITIFNULL(current);
|
||||
current->setUrl("zim://" + current->zimId() + ".zim/");
|
||||
});
|
||||
connect(app->getAction(KiwixApp::SettingAction), &QAction::triggered,
|
||||
this, [=]() {
|
||||
if (KiwixApp::instance()->getSettingsManager()->isSettingsViewdisplayed()) {
|
||||
return;
|
||||
}
|
||||
auto index = currentIndex() + 1;
|
||||
auto view = KiwixApp::instance()->getSettingsManager()->getView();
|
||||
mp_stackedWidget->insertWidget(index, view);
|
||||
insertTab(index,QIcon(":/icons/settings.svg"), tr("Settings"));
|
||||
setCurrentIndex(index);
|
||||
m_settingsIndex = index;
|
||||
});
|
||||
}
|
||||
|
||||
void TabBar::setStackedWidget(QStackedWidget *widget) {
|
||||
@ -214,6 +227,12 @@ void TabBar::closeTab(int index)
|
||||
{
|
||||
if (index == 0 || index == this->count() - 1)
|
||||
return;
|
||||
if (index == m_settingsIndex) {
|
||||
m_settingsIndex = -1;
|
||||
}
|
||||
if (index < m_settingsIndex) {
|
||||
m_settingsIndex--;
|
||||
}
|
||||
setSelectionBehaviorOnRemove(index);
|
||||
auto webview = widget(index);
|
||||
mp_stackedWidget->removeWidget(webview);
|
||||
@ -237,8 +256,13 @@ void TabBar::onCurrentChanged(int index)
|
||||
{
|
||||
if (index == -1)
|
||||
return;
|
||||
if (index)
|
||||
{
|
||||
if (index == m_settingsIndex) {
|
||||
emit webActionEnabledChanged(QWebEnginePage::Back, false);
|
||||
emit webActionEnabledChanged(QWebEnginePage::Forward, false);
|
||||
emit libraryPageDisplayed(false);
|
||||
KiwixApp::instance()->setSideBar(KiwixApp::NONE);
|
||||
QTimer::singleShot(0, [=](){emit currentTitleChanged("");});
|
||||
} else if (index) {
|
||||
auto view = widget(index);
|
||||
emit webActionEnabledChanged(QWebEnginePage::Back, view->isWebActionEnabled(QWebEnginePage::Back));
|
||||
emit webActionEnabledChanged(QWebEnginePage::Forward, view->isWebActionEnabled(QWebEnginePage::Forward));
|
||||
|
@ -53,6 +53,7 @@ public slots:
|
||||
private:
|
||||
ContentManagerView* mp_contentManagerView;
|
||||
QStackedWidget* mp_stackedWidget;
|
||||
int m_settingsIndex;
|
||||
|
||||
void setSelectionBehaviorOnRemove(int index);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user