Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a private/read-only mode #1217

Closed
wants to merge 1 commit into from
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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ environment variable:
LD_LIBRARY_PATH="<...>/BUILD_native_dyn/INSTALL/lib/x86_64-linux-gnu"
```

Private/Read-Only Mode
----------------------

Kiwix Desktop now includes a private/read-only mode to protect user privacy by not writing anything to storage. This mode can be activated via the UI or by creating a `.private` file in the same directory as the Kiwix executable.

To activate private mode via the UI:
1. Open Kiwix Desktop.
2. Go to the main menu and select "Toggle Private Mode".

To activate private mode via a `.private` file:
1. Create an empty file named `.private` in the same directory as the Kiwix executable.
2. Launch Kiwix Desktop.

When private mode is active, no write operations will be performed, ensuring that no data is written to storage.

## Communication

Available communication channels:
Expand Down
12 changes: 11 additions & 1 deletion src/kiwixapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ KiwixApp::KiwixApp(int& argc, char *argv[])
mp_mainWindow(nullptr),
mp_nameMapper(std::make_shared<kiwix::UpdatableNameMapper>(m_library.getKiwixLibrary(), false)),
m_server(m_library.getKiwixLibrary(), mp_nameMapper),
mp_session(nullptr)
mp_session(nullptr),
m_privateMode(m_settingsManager.isPrivateMode())
{
try {
m_translation.setTranslation(QLocale());
Expand Down Expand Up @@ -67,6 +68,11 @@ void KiwixApp::loadAndInstallTranslations(QTranslator& translator, const QString

void KiwixApp::init()
{
if (m_privateMode) {
qDebug() << "Private mode is active. No write operations will be performed.";
return;
}

mp_manager = new ContentManager(&m_library);
mp_manager->setLocal(!m_library.getBookIds().isEmpty());

Expand Down Expand Up @@ -560,3 +566,7 @@ QString KiwixApp::getPrevSaveDir() const
QDir dir(prevSaveDir);
return dir.exists() ? prevSaveDir : DEFAULT_SAVE_DIR;
}

bool KiwixApp::isPrivateMode() const {
return m_privateMode;
}
2 changes: 2 additions & 0 deletions src/kiwixapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class KiwixApp : public QtSingleApplication
void saveCurrentTabIndex();
void savePrevSaveDir(const QString& prevSaveDir);
QString getPrevSaveDir() const;
bool isPrivateMode() const;

public slots:
void newTab();
Expand Down Expand Up @@ -127,6 +128,7 @@ public slots:
QSettings* mp_session;

QAction* mpa_actions[MAX_ACTION];
bool m_privateMode;

void setupDirectoryMonitoring();
QString findLibraryDirectory();
Expand Down
18 changes: 17 additions & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include "mainwindow.h"
#include "portutils.h"
#include "ui_mainwindow.h"
Expand Down Expand Up @@ -84,6 +83,11 @@ MainWindow::MainWindow(QWidget *parent) :

mp_ui->contentmanagerside->setContentManager(app->getContentManager());
mp_ui->sideBar->setCurrentWidget(mp_ui->contentmanagerside);

// Add a new action in the UI to toggle the private mode status
QAction *togglePrivateModeAction = new QAction(tr("Toggle Private Mode"), this);
connect(togglePrivateModeAction, &QAction::triggered, this, &MainWindow::togglePrivateMode);
mp_ui->mainToolBar->addAction(togglePrivateModeAction);
}

MainWindow::~MainWindow()
Expand Down Expand Up @@ -203,3 +207,15 @@ TopWidget *MainWindow::getTopWidget()
{
return mp_ui->mainToolBar;
}

void MainWindow::togglePrivateMode()
{
auto app = KiwixApp::instance();
bool privateMode = app->isPrivateMode();
if (privateMode) {
QMessageBox::information(this, tr("Private Mode"), tr("Private mode is already active."));
} else {
QMessageBox::information(this, tr("Private Mode"), tr("Activating private mode."));
// Add logic to activate private mode here
}
}
1 change: 1 addition & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private slots:
void hideTabAndTop();
void showTabAndTop();
void updateTabButtons();
void togglePrivateMode();

private:
Ui::MainWindow *mp_ui;
Expand Down
8 changes: 8 additions & 0 deletions src/settingsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,11 @@ void SettingsManager::initSettings()

m_contentTypeList = m_settings.value("contentType", {}).toList();
}

bool SettingsManager::isPrivateMode() const
{
auto currentDataDir = QString::fromStdString(kiwix::removeLastPathElement(kiwix::getExecutablePath()));
auto privateFile = QFileInfo(currentDataDir, ".private");

return privateFile.exists();
}
1 change: 1 addition & 0 deletions src/settingsmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class SettingsManager : public QObject
FilterList getLanguageList() { return deducePair(m_langList); }
QStringList getCategoryList() { return m_categoryList; }
FilterList getContentType() { return deducePair(m_contentTypeList); }
bool isPrivateMode() const;

public slots:
void setKiwixServerPort(int port);
Expand Down