diff --git a/README.md b/README.md index 329940b1..f755b7c8 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/src/kiwixapp.cpp b/src/kiwixapp.cpp index ce071290..e72e9ba3 100644 --- a/src/kiwixapp.cpp +++ b/src/kiwixapp.cpp @@ -34,7 +34,8 @@ KiwixApp::KiwixApp(int& argc, char *argv[]) mp_mainWindow(nullptr), mp_nameMapper(std::make_shared(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()); @@ -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()); @@ -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; +} diff --git a/src/kiwixapp.h b/src/kiwixapp.h index 5454150f..aa113e2f 100644 --- a/src/kiwixapp.h +++ b/src/kiwixapp.h @@ -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(); @@ -127,6 +128,7 @@ public slots: QSettings* mp_session; QAction* mpa_actions[MAX_ACTION]; + bool m_privateMode; void setupDirectoryMonitoring(); QString findLibraryDirectory(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 6b2feb85..6b8ead72 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,4 +1,3 @@ - #include "mainwindow.h" #include "portutils.h" #include "ui_mainwindow.h" @@ -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() @@ -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 + } +} diff --git a/src/mainwindow.h b/src/mainwindow.h index a97bef15..09e81dd6 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -38,6 +38,7 @@ private slots: void hideTabAndTop(); void showTabAndTop(); void updateTabButtons(); + void togglePrivateMode(); private: Ui::MainWindow *mp_ui; diff --git a/src/settingsmanager.cpp b/src/settingsmanager.cpp index 27006b61..95aaded1 100644 --- a/src/settingsmanager.cpp +++ b/src/settingsmanager.cpp @@ -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(); +} diff --git a/src/settingsmanager.h b/src/settingsmanager.h index 326b9379..b53bf4e8 100644 --- a/src/settingsmanager.h +++ b/src/settingsmanager.h @@ -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);