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

Show Open/Save dialog on downloading files #1123

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions kiwix-desktop.pro
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ SOURCES += \
src/findinpagebar.cpp \
src/flowlayout.cpp \
src/kiwixchoicebox.cpp \
src/kiwixconfirmbox.cpp \
src/kiwixmessagebox.cpp \
src/kiwixlineedit.cpp \
src/kiwixlistwidget.cpp \
src/kiwixloader.cpp \
Expand Down Expand Up @@ -105,7 +105,7 @@ HEADERS += \
src/findinpagebar.h \
src/flowlayout.h \
src/kiwixchoicebox.h \
src/kiwixconfirmbox.h \
src/kiwixmessagebox.h \
src/kiwixlineedit.h \
src/kiwixlistwidget.h \
src/kiwixloader.h \
Expand Down Expand Up @@ -151,7 +151,7 @@ FORMS += \
src/contentmanagerview.ui \
src/findinpagebar.ui \
ui/kiwixchoicebox.ui \
ui/kiwixconfirmbox.ui \
ui/kiwixmessagebox.ui \
ui/mainwindow.ui \
ui/about.ui \
src/contentmanagerside.ui \
Expand Down
7 changes: 7 additions & 0 deletions resources/css/confirmBox.css → resources/css/messageBox.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@ QPushButton:hover {
color: white;
}

#closeButton {
border: 0;
}

#closeButton:hover {
background-color: transparent;
}

7 changes: 6 additions & 1 deletion resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"error-downloader-launch-message":"Impossible to launch downloader, Kiwix-desktop will start but all download functions will not working!",
"error-launch-server-message":"An error has occured!",
"error-archive":"Cannot get the archive",
"error-opening-file": "There was an error opening the file.",
"open-zim":"Open ZIM File",
"local-kiwix-server":"Local Kiwix Server",
"random-article":"Random Article",
Expand All @@ -23,6 +24,7 @@
"reopen-closed-tab":"Reopen closed tab",
"browse-library":"Browse library",
"open-file":"Open file",
"save-file": "Save file",
"open-recent":"Open recent",
"search-article":"Search article",
"search-in-library":"Search in library",
Expand All @@ -45,6 +47,7 @@
"donate-to-support-kiwix":"Donate to support Kiwix",
"exit":"Exit",
"save-file-as-window-title":"Save File as",
"download-finished": "Download Finished",
"download-finished-message":"The document has been downloaded.",
"file":"File",
"edit":"Edit",
Expand Down Expand Up @@ -173,5 +176,7 @@
"scroll-next-tab": "Scroll to next tab",
"scroll-previous-tab": "Scroll to previous tab",
"kiwix-search": "Kiwix search",
"search-options": "Search Options"
"search-options": "Search Options",
"save-or-open": "Save or Open file",
"save-or-open-text": "What should Kiwix do with this file?"
}
7 changes: 6 additions & 1 deletion resources/i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"error-downloader-launch-message": "Error text displayed to elaborate on the effect of the downloader failure.",
"error-launch-server-message": "Error text displayed when Kiwix server failed to launch.",
"error-archive": "Error text displayed when the retrieving the archive of a ZIM file failed.",
"error-opening-file": "Error text displayed when opening a downloaded file with an external application fails.",
"open-zim": "Caption text for file explorer window used to choose a ZIM file.",
"local-kiwix-server": "Describes a server hosted locally that contains the local kiwix library.",
"random-article": "A randomly chosen article in a ZIM file.",
Expand All @@ -31,6 +32,7 @@
"reopen-closed-tab": "Represents the action of reopen a tab that has just been closed.",
"browse-library": "Represents the action of browsing the local kiwix library.",
"open-file": "Represents the action of opening a file from the local file system.",
"save-file": "Represents the action of saving a file to the local file system.",
"open-recent": "Represents the action of choosing to open a file from those recently opened.",
"search-article": "Represents the action of Searching for a article in the current ZIM file.",
"search-in-library": "Represents the action of Searching for a text in the local Kiwix library.",
Expand All @@ -53,6 +55,7 @@
"donate-to-support-kiwix": "Represents the action of donating to support the Kiwix Organization.",
"exit": "Represents the action of exiting the desktop application",
"save-file-as-window-title": "Title text of the window prompting user to save as a new file.",
"download-finished": "Title of the message box announcing the completion of a download",
"download-finished-message": "Text displayed when the download action has been completed",
"file": "{{Identical|File}}",
"edit": "{{Identical|Edit}}",
Expand Down Expand Up @@ -181,5 +184,7 @@
"scroll-next-tab": "Represents the action of scrolling to the next tab of the current tab which toward the end of the tab bar.",
"scroll-previous-tab": "Represents the action of scrolling to the previous tab of the current tab which toward the start of the tab bar.",
"kiwix-search": "Title text for a list of search results, which notes to the user those are from Kiwix's Search Engine",
"search-options": "The term for a collection of additional search filtering options to help users narrow down search results."
"search-options": "The term for a collection of additional search filtering options to help users narrow down search results.",
"save-or-open": "Title of the message box allowing to choose whether a remote resource should be saved to disk or opened with a respective application",
"save-or-open-text": "Text of the message box allowing to choose whether a remote resource should be saved to disk or opened with a respective application"
}
2 changes: 1 addition & 1 deletion resources/style.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<file>css/style.css</file>
<file>css/popup.css</file>
<file>css/localServer.css</file>
<file>css/confirmBox.css</file>
<file>css/messageBox.css</file>
<file>css/contentmanagerside.css</file>
<file>css/choiceBox.css</file>
</qresource>
Expand Down
2 changes: 1 addition & 1 deletion src/contentmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "node.h"
#include "rownode.h"
#include "descriptionnode.h"
#include "kiwixconfirmbox.h"
#include "kiwixmessagebox.h"
#include <QtConcurrent/QtConcurrentRun>
#include "contentmanagerheader.h"
#include <QDesktopServices>
Expand Down
2 changes: 1 addition & 1 deletion src/downloadmanagement.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "downloadmanagement.h"

#include "kiwixapp.h"
#include "kiwixconfirmbox.h"
#include "kiwixmessagebox.h"

#include <QStorageInfo>
#include <QThread>
Expand Down
47 changes: 0 additions & 47 deletions src/kiwixconfirmbox.cpp

This file was deleted.

66 changes: 66 additions & 0 deletions src/kiwixmessagebox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "kiwixmessagebox.h"
#include "ui_kiwixmessagebox.h"
#include <QFile>
#include "kiwixapp.h"

KiwixMessageBox::KiwixMessageBox(QString confirmTitle, QString confirmText, bool okDialog, QWidget *parent,
QString leftAction, QString rightAction) :
QDialog(parent), m_confirmTitle(confirmTitle), m_confirmText(confirmText),
ui(new Ui::kiwixmessagebox)
{
ui->setupUi(this);
setWindowFlag(Qt::FramelessWindowHint, true);
setStyleSheet(KiwixApp::instance()->parseStyleFromFile(":/css/messageBox.css"));
connect(ui->yesButton, &QPushButton::clicked, [=]() {
emit yesClicked();
m_result = YesClicked;
accept();
});
connect(ui->noButton, &QPushButton::clicked, [=]() {
emit noClicked();
m_result = NoClicked;
reject();
});
connect(ui->okButton, &QPushButton::clicked, [=]() {
emit okClicked();
m_result = OkClicked;
});
connect(ui->closeButton, &QPushButton::clicked, [=]() {
this->close();
m_result = CloseClicked;
});
ui->confirmText->setText(confirmText);
ui->confirmTitle->setText(confirmTitle);
ui->yesButton->setText(leftAction);
ui->noButton->setText(rightAction);
ui->okButton->setText(gt("ok"));
ui->okButton->hide();
if (okDialog) {
ui->yesButton->hide();
ui->noButton->hide();
ui->okButton->show();
}
}

KiwixMessageBox::~KiwixMessageBox()
{
delete ui;
}

void showInfoBox(QString title, QString text, QWidget *parent)
{
KiwixMessageBox *dialog = new KiwixMessageBox(title, text, true, parent);
dialog->show();
QObject::connect(dialog, &KiwixMessageBox::okClicked, [=]() {
dialog->deleteLater();
});
}

KiwixMessageBox::Result showKiwixMessageBox(QString title, QString text, QWidget *parent, QString leftTitle, QString rightTitle)
{
KiwixMessageBox *dialog = new KiwixMessageBox(title, text, false, parent, leftTitle, rightTitle);
QObject::connect(dialog, &KiwixMessageBox::finished, [=]() {
dialog->deleteLater();
});
return dialog->execDialog();
}
juuz0 marked this conversation as resolved.
Show resolved Hide resolved
33 changes: 22 additions & 11 deletions src/kiwixconfirmbox.h → src/kiwixmessagebox.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
#ifndef KIWIXCONFIRMBOX_H
#define KIWIXCONFIRMBOX_H
#ifndef KIWIXMESSAGEBOX_H
#define KIWIXMESSAGEBOX_H

#include <QDialog>
#include "kiwixapp.h"

#include <stdexcept>

namespace Ui {
class kiwixconfirmbox;
class kiwixmessagebox;
}

class KiwixConfirmBox : public QDialog
class KiwixMessageBox : public QDialog
{
Q_OBJECT

public:
KiwixConfirmBox(QString confirmTitle, QString confirmText, bool okDialog, QWidget *parent = nullptr);
~KiwixConfirmBox();
KiwixMessageBox(QString confirmTitle, QString confirmText, bool okDialog, QWidget *parent = nullptr,
QString leftAction = gt("yes"), QString rightAction = gt("no"));
~KiwixMessageBox();
enum Result {
YesClicked,
NoClicked,
OkClicked,
CloseClicked
};
Result execDialog() { QDialog::exec(); return m_result; }

signals:
void yesClicked();
Expand All @@ -25,23 +34,25 @@ class KiwixConfirmBox : public QDialog
private:
QString m_confirmTitle;
QString m_confirmText;
Ui::kiwixconfirmbox *ui;
Ui::kiwixmessagebox *ui;
Result m_result;
};


void showInfoBox(QString title, QString text, QWidget *parent = nullptr);
KiwixMessageBox::Result showKiwixMessageBox(QString title, QString text, QWidget *parent, QString leftTitle, QString rightTitle);

template<class YesAction>
void showConfirmBox(QString title, QString text, QWidget *parent,
YesAction yesAction)
{
KiwixConfirmBox *dialog = new KiwixConfirmBox(title, text, false, parent);
KiwixMessageBox *dialog = new KiwixMessageBox(title, text, false, parent);
dialog->show();
QObject::connect(dialog, &KiwixConfirmBox::yesClicked, [=]() {
QObject::connect(dialog, &KiwixMessageBox::yesClicked, [=]() {
yesAction();
dialog->deleteLater();
});
QObject::connect(dialog, &KiwixConfirmBox::noClicked, [=]() {
QObject::connect(dialog, &KiwixMessageBox::noClicked, [=]() {
dialog->deleteLater();
});
}
Expand All @@ -66,4 +77,4 @@ inline void showErrorBox(const KiwixAppError& err, QWidget *parent = nullptr)
showInfoBox(err.summary(), err.details(), parent);
}

#endif // KIWIXCONFIRMBOX_H
#endif // KIWIXMESSAGEBOX_H
Loading
Loading