mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-21 19:18:39 -04:00
Merge pull request #1163 from kiwix/Issue#61-export-bookmark
Introduce Ex/Import Reading List
This commit is contained in:
commit
5cc48d783f
@ -329,3 +329,18 @@ ContentTypeFilter {
|
||||
font-size: 16px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
#readinglistbar QPushButton {
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
#readinglistbar QPushButton::hover {
|
||||
border: 1px solid #3366CC;
|
||||
background-color: #D9E9FF;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
#readinglistbar QPushButton::menu-indicator {
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
@ -173,5 +173,9 @@
|
||||
"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.",
|
||||
"import-reading-list": "Import reading list",
|
||||
"import-reading-list-error": "An error has occured during import of the reading list."
|
||||
}
|
||||
|
@ -180,5 +180,9 @@
|
||||
"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.",
|
||||
"import-reading-list": "Represents the action of importing a reading list from a file.",
|
||||
"import-reading-list-error": "Error description text for when importing a reading list from a file failed."
|
||||
}
|
||||
|
1
resources/icons/more-vertical.svg
Normal file
1
resources/icons/more-vertical.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="1"></circle><circle cx="12" cy="5" r="1"></circle><circle cx="12" cy="19" r="1"></circle></svg>
|
After Width: | Height: | Size: 298 B |
@ -64,5 +64,6 @@
|
||||
<file>icons/check-solid.svg</file>
|
||||
<file>icons/xmark-solid.svg</file>
|
||||
<file>icons/home-button.svg</file>
|
||||
<file>icons/more-vertical.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -461,6 +461,10 @@ 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(ImportReadingListAction, gt("import-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>({QKeySequence::ZoomIn, QKeySequence(Qt::CTRL | Qt::Key_Equal)}));
|
||||
|
@ -62,6 +62,8 @@ public:
|
||||
SettingAction,
|
||||
DonateAction,
|
||||
ExitAction,
|
||||
ExportReadingListAction,
|
||||
ImportReadingListAction,
|
||||
MAX_ACTION
|
||||
};
|
||||
|
||||
|
@ -209,6 +209,16 @@ Library::QStringSet Library::getLibraryZimsFromDir(QString dir) const
|
||||
return zimsInDir;
|
||||
}
|
||||
|
||||
bool Library::readBookMarksFile(const std::string &filename)
|
||||
{
|
||||
kiwix::Manager manager(mp_library);
|
||||
if (!manager.readBookmarkFile(filename))
|
||||
return false;
|
||||
|
||||
emit bookmarksChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
const kiwix::Book &Library::getBookById(QString id) const
|
||||
{
|
||||
return mp_library->getBookById(id.toStdString());
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
void removeBookFromLibraryById(const QString& id);
|
||||
void addBookmark(kiwix::Bookmark& bookmark);
|
||||
void removeBookmark(const QString& zimId, const QString& url);
|
||||
bool readBookMarksFile(const std::string& filename);
|
||||
void save();
|
||||
kiwix::LibraryPtr getKiwixLibrary() { return mp_library; }
|
||||
public slots:
|
||||
|
@ -24,6 +24,8 @@ MainMenu::MainMenu(QWidget *parent) :
|
||||
m_fileMenu.ADD_ACTION(BrowseLibraryAction);
|
||||
m_fileMenu.ADD_ACTION(OpenFileAction);
|
||||
m_fileMenu.ADD_ACTION(OpenRecentAction);
|
||||
m_fileMenu.ADD_ACTION(ExportReadingListAction);
|
||||
m_fileMenu.ADD_ACTION(ImportReadingListAction);
|
||||
|
||||
/* TODO See https://github.com/kiwix/kiwix-desktop/issues/77
|
||||
m_fileMenu.ADD_ACTION(SavePageAsAction);
|
||||
|
@ -5,6 +5,10 @@
|
||||
#include "zim/item.h"
|
||||
|
||||
#include <QListWidgetItem>
|
||||
#include <QFileDialog>
|
||||
#include <QStandardPaths>
|
||||
|
||||
const QString documentsDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
|
||||
|
||||
ReadingListBar::ReadingListBar(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
@ -28,7 +32,17 @@ ReadingListBar::ReadingListBar(QWidget *parent) :
|
||||
|
||||
setupList();
|
||||
|
||||
auto app = KiwixApp::instance();
|
||||
auto exportAction = app->getAction(KiwixApp::ExportReadingListAction);
|
||||
auto importAction = app->getAction(KiwixApp::ImportReadingListAction);
|
||||
connect(exportAction, &QAction::triggered, this, &ReadingListBar::onExport);
|
||||
connect(importAction, &QAction::triggered, this, &ReadingListBar::onImport);
|
||||
ui->label->setText(gt("reading-list-title"));
|
||||
|
||||
QMenu *portMenu = new QMenu(this);
|
||||
portMenu->addAction(exportAction);
|
||||
portMenu->addAction(importAction);
|
||||
ui->readingListMenuButton->setMenu(portMenu);
|
||||
}
|
||||
|
||||
ReadingListBar::~ReadingListBar()
|
||||
@ -104,6 +118,35 @@ void ReadingListBar::onItemActivated(QListWidgetItem* item, Qt::MouseButtons but
|
||||
}
|
||||
}
|
||||
|
||||
void ReadingListBar::onExport()
|
||||
{
|
||||
auto app = KiwixApp::instance();
|
||||
auto kiwixLibrary = app->getLibrary()->getKiwixLibrary();
|
||||
auto suggestedFilePath = documentsDir + "/kiwix_readinglist.xml";
|
||||
QString fileName = QFileDialog::getSaveFileName(app->getMainWindow(),
|
||||
gt("save-file-as-window-title"),
|
||||
suggestedFilePath, "(*.xml)");
|
||||
if (fileName.isEmpty())
|
||||
return;
|
||||
|
||||
if (!kiwixLibrary->writeBookmarksToFile(fileName.toStdString()))
|
||||
app->showMessage(gt("export-reading-list-error"), gt("error-title"), QMessageBox::Information);
|
||||
}
|
||||
|
||||
void ReadingListBar::onImport()
|
||||
{
|
||||
auto app = KiwixApp::instance();
|
||||
auto library = app->getLibrary();
|
||||
QString fileName = QFileDialog::getOpenFileName(app->getMainWindow(),
|
||||
gt("open-file"),
|
||||
documentsDir, "(*.xml)");
|
||||
if (fileName.isEmpty())
|
||||
return;
|
||||
|
||||
if (!library->readBookMarksFile(fileName.toStdString()))
|
||||
app->showMessage(gt("import-reading-list-error"), gt("error-title"), QMessageBox::Information);
|
||||
}
|
||||
|
||||
void ReadingListBar::openUrl(QListWidgetItem* item, bool newTab)
|
||||
{
|
||||
int index = ui->listWidget->row(item);
|
||||
|
@ -22,6 +22,8 @@ public slots:
|
||||
void onItemDoubleClicked(QListWidgetItem *item);
|
||||
void onItemPressed(QListWidgetItem* item, Qt::MouseButtons buttons);
|
||||
void onItemActivated(QListWidgetItem *item, Qt::MouseButtons buttons);
|
||||
void onExport();
|
||||
void onImport();
|
||||
private:
|
||||
Ui::readinglistbar *ui;
|
||||
int clickKind;
|
||||
|
@ -27,16 +27,53 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>16</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Reading List</string>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>16</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Reading List</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="readingListMenuButton">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/kiwix.qrc">
|
||||
<normaloff>:/icons/more-vertical.svg</normaloff>:/icons/more-vertical.svg</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>30</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="listWidget">
|
||||
@ -68,6 +105,8 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<resources>
|
||||
<include location="../resources/kiwix.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -12,6 +12,9 @@ BookmarkButton::BookmarkButton(QWidget *parent) :
|
||||
connect(this, &QToolButton::triggered, this, &BookmarkButton::on_buttonClicked);
|
||||
connect(this, &QToolButton::triggered, this, &BookmarkButton::update_display);
|
||||
setDefaultAction(KiwixApp::instance()->getAction(KiwixApp::Actions::ToggleAddBookmarkAction));
|
||||
|
||||
auto library = KiwixApp::instance()->getLibrary();
|
||||
connect(library, &Library::bookmarksChanged, this, &BookmarkButton::update_display);
|
||||
}
|
||||
|
||||
void BookmarkButton::update_display()
|
||||
|
Loading…
x
Reference in New Issue
Block a user