From b4bbefa5aff9298f73f2885caed37844aeda4ac8 Mon Sep 17 00:00:00 2001 From: ShaopengLin Date: Sun, 28 Jul 2024 15:18:13 -0400 Subject: [PATCH] Add reading list export Added Menu button to export reading list to file --- resources/i18n/en.json | 4 +++- resources/i18n/qqq.json | 4 +++- src/kiwixapp.cpp | 2 ++ src/kiwixapp.h | 1 + src/mainmenu.cpp | 1 + src/readinglistbar.cpp | 18 ++++++++++++++++++ src/readinglistbar.h | 1 + 7 files changed, 29 insertions(+), 2 deletions(-) diff --git a/resources/i18n/en.json b/resources/i18n/en.json index c6fcf6e..b5f19a6 100644 --- a/resources/i18n/en.json +++ b/resources/i18n/en.json @@ -173,5 +173,7 @@ "file-not-found-text": "ZIM file doesn't exist or is not readable", "zim-id": "Zim Id", "zim-name": "Zim Name", - "zim-path": "Zim File Path" + "zim-path": "Zim File Path", + "export-reading-list": "Export reading list", + "export-reading-list-error": "An error has occured during export of the reading list." } diff --git a/resources/i18n/qqq.json b/resources/i18n/qqq.json index 6b670f0..14d8378 100644 --- a/resources/i18n/qqq.json +++ b/resources/i18n/qqq.json @@ -180,5 +180,7 @@ "file-not-found-text": "Error description text for when the desktop application cannot find the Zim file needed to display the web page.", "zim-id": "The term for the unique identifier of a zim file.", "zim-name": "The term for the name of a Zim file", - "zim-path": "The term for the path of a Zim file" + "zim-path": "The term for the path of a Zim file", + "export-reading-list": "Represents the action of exporting the reading list to a file.", + "export-reading-list-error": "Error description text for when exporting the reading list to a file failed." } diff --git a/src/kiwixapp.cpp b/src/kiwixapp.cpp index 2df37e8..4f44caa 100644 --- a/src/kiwixapp.cpp +++ b/src/kiwixapp.cpp @@ -461,6 +461,8 @@ void KiwixApp::createActions() CREATE_ACTION_ONOFF_ICON_SHORTCUT(ToggleReadingListAction, "reading-list-active", "reading-list", gt("reading-list"), QKeySequence(Qt::CTRL | Qt::Key_B)); + CREATE_ACTION(ExportReadingListAction, gt("export-reading-list")); + CREATE_ACTION_ONOFF_ICON_SHORTCUT(ToggleAddBookmarkAction, "star-active", "star", gt("add-bookmark"), QKeySequence(Qt::CTRL | Qt::Key_D)); CREATE_ACTION_SHORTCUTS(ZoomInAction, gt("zoom-in"), QList({QKeySequence::ZoomIn, QKeySequence(Qt::CTRL | Qt::Key_Equal)})); diff --git a/src/kiwixapp.h b/src/kiwixapp.h index 898d2f3..cd87787 100644 --- a/src/kiwixapp.h +++ b/src/kiwixapp.h @@ -62,6 +62,7 @@ public: SettingAction, DonateAction, ExitAction, + ExportReadingListAction, MAX_ACTION }; diff --git a/src/mainmenu.cpp b/src/mainmenu.cpp index 2c0f155..c42f218 100644 --- a/src/mainmenu.cpp +++ b/src/mainmenu.cpp @@ -24,6 +24,7 @@ MainMenu::MainMenu(QWidget *parent) : m_fileMenu.ADD_ACTION(BrowseLibraryAction); m_fileMenu.ADD_ACTION(OpenFileAction); m_fileMenu.ADD_ACTION(OpenRecentAction); + m_fileMenu.ADD_ACTION(ExportReadingListAction); /* TODO See https://github.com/kiwix/kiwix-desktop/issues/77 m_fileMenu.ADD_ACTION(SavePageAsAction); diff --git a/src/readinglistbar.cpp b/src/readinglistbar.cpp index a5ff301..f1d1b20 100644 --- a/src/readinglistbar.cpp +++ b/src/readinglistbar.cpp @@ -5,6 +5,7 @@ #include "zim/item.h" #include +#include ReadingListBar::ReadingListBar(QWidget *parent) : QWidget(parent), @@ -28,6 +29,9 @@ ReadingListBar::ReadingListBar(QWidget *parent) : setupList(); + auto app = KiwixApp::instance(); + auto exportAction = app->getAction(KiwixApp::ExportReadingListAction); + connect(exportAction, &QAction::triggered, this, &ReadingListBar::onExport); ui->label->setText(gt("reading-list-title")); } @@ -104,6 +108,20 @@ void ReadingListBar::onItemActivated(QListWidgetItem* item, Qt::MouseButtons but } } +void ReadingListBar::onExport() +{ + auto app = KiwixApp::instance(); + auto kiwixLibrary = app->getLibrary()->getKiwixLibrary(); + QString fileName = QFileDialog::getSaveFileName(app->getMainWindow(), + gt("save-file-as-window-title"), + "kiwix_readinglist.xml", "(*.xml)"); + if (fileName.isEmpty()) + return; + + if (!kiwixLibrary->writeBookmarksToFile(fileName.toStdString())) + app->showMessage(gt("export-reading-list-error"), gt("error-title"), QMessageBox::Information); +} + void ReadingListBar::openUrl(QListWidgetItem* item, bool newTab) { int index = ui->listWidget->row(item); diff --git a/src/readinglistbar.h b/src/readinglistbar.h index 5a2f295..e9e0e6d 100644 --- a/src/readinglistbar.h +++ b/src/readinglistbar.h @@ -22,6 +22,7 @@ public slots: void onItemDoubleClicked(QListWidgetItem *item); void onItemPressed(QListWidgetItem* item, Qt::MouseButtons buttons); void onItemActivated(QListWidgetItem *item, Qt::MouseButtons buttons); + void onExport(); private: Ui::readinglistbar *ui; int clickKind;