Changeset View
Standalone View
importer/dialogpage.cpp
Show All 20 Lines | |||||
21 | // Self | 21 | // Self | ||
22 | #include "dialogpage.h" | 22 | #include "dialogpage.h" | ||
23 | 23 | | |||
24 | // Qt | 24 | // Qt | ||
25 | #include <QEventLoop> | 25 | #include <QEventLoop> | ||
26 | #include <QList> | 26 | #include <QList> | ||
27 | #include <QVBoxLayout> | 27 | #include <QVBoxLayout> | ||
28 | #include <QPushButton> | 28 | #include <QPushButton> | ||
29 | #include <QAction> | ||||
29 | 30 | | |||
30 | // KDE | 31 | // KDE | ||
31 | #include <KGuiItem> | 32 | #include <KGuiItem> | ||
33 | #include <KMessageBox> | ||||
32 | 34 | | |||
33 | // Local | 35 | // Local | ||
34 | #include <ui_dialogpage.h> | 36 | #include <ui_dialogpage.h> | ||
37 | #include "importdialog.h" | ||||
35 | 38 | | |||
36 | namespace Gwenview | 39 | namespace Gwenview | ||
37 | { | 40 | { | ||
38 | 41 | | |||
39 | struct DialogPagePrivate : public Ui_DialogPage | 42 | struct DialogPagePrivate : public Ui_DialogPage | ||
40 | { | 43 | { | ||
41 | QVBoxLayout* mLayout; | 44 | QVBoxLayout* mLayout; | ||
42 | QList<QPushButton*> mButtons; | 45 | QList<QPushButton*> mButtons; | ||
43 | QEventLoop* mEventLoop; | 46 | QEventLoop* mEventLoop; | ||
47 | DialogPage* q; | ||||
48 | QStringList failedFileList; | ||||
49 | QStringList failedDirList; | ||||
50 | QAction* fileDetails; | ||||
51 | QAction* dirDetails; | ||||
52 | | ||||
53 | void setupFailedListActions() | ||||
54 | { | ||||
55 | fileDetails = new QAction(i18n("Show failed files...")); | ||||
ngraham: Localize this string | |||||
56 | mErrorMessageWidget->addAction(fileDetails); | ||||
57 | QObject::connect(fileDetails, &QAction::triggered, | ||||
58 | q, &DialogPage::slotShowFailedFileDetails); | ||||
59 | fileDetails->setVisible(false); | ||||
60 | | ||||
61 | dirDetails = new QAction(i18n("Show failed subfolders...")); | ||||
ngraham: Localize this string | |||||
62 | mErrorMessageWidget->addAction(dirDetails); | ||||
63 | QObject::connect(dirDetails, &QAction::triggered, | ||||
64 | q, &DialogPage::slotShowFailedDirDetails); | ||||
65 | dirDetails->setVisible(false); | ||||
66 | } | ||||
67 | | ||||
68 | void showErrors(const QStringList& files, const QStringList& dirs) | ||||
69 | { | ||||
70 | mErrorMessageWidget->setVisible(true); | ||||
71 | failedFileList.clear(); | ||||
72 | failedDirList.clear(); | ||||
73 | QStringList message; | ||||
74 | if (files.count() > 0) { | ||||
75 | failedFileList = files; | ||||
76 | message << i18np("Failed to import %1 document.", | ||||
Use $1 instead of one (some languages use the singular form for numbers beyond the first) ngraham: Use `$1` instead of `one` (some languages use the singular form for numbers beyond the first) | |||||
77 | "Failed to import %1 documents.", | ||||
78 | files.count()); | ||||
79 | fileDetails->setVisible(true); | ||||
80 | } else fileDetails->setVisible(false); | ||||
81 | | ||||
82 | if (dirs.count() > 0) { | ||||
83 | failedDirList = dirs; | ||||
84 | message << i18np("Failed to create %1 destination subfolder.", | ||||
Use $1 instead of one (some languages use the singular form for numbers beyond the first) ngraham: Use `$1` instead of `one` (some languages use the singular form for numbers beyond the first) | |||||
85 | "Failed to create %1 destination subfolders.", | ||||
86 | dirs.count()); | ||||
87 | dirDetails->setVisible(true); | ||||
88 | } else dirDetails->setVisible(false); | ||||
89 | | ||||
90 | mErrorMessageWidget->setText(message.join("<br/>")); | ||||
We don't use raw HTML like this. Instead, do it like so: mErrorMessageWidget->setText(xi18nc("@info", message.join("<nl/>"))); See also https://api.kde.org/frameworks/ki18n/html/prg_guide.html#kuit_markup ngraham: We don't use raw HTML like this. Instead, do it like so:
```
mErrorMessageWidget->setText… | |||||
I tried the syntax above and variations thereof as described in the kuit_markup guide, but I couldn't get the correct behavior. None of the variants seemed to accept <br/> as line break. They all showed it as a literal string. At that point I realized that running it through an internationalization function is overkill. The only reason to have the join() function is to show two already internationalized strings on separate lines (only in case there are two strings, i.e. failed files AND failed folders). BTW, I took the original implementation with raw html from the already existing code to report the successful imports. So maybe that also needs to be updated then. bdevries: I tried the syntax above and variations thereof as described in the kuit_markup guide, but I… | |||||
It's <nl/> in this context, not <br/> But if the other code already does something else, let's copy that, and refactor them both in the next patch? Does that sound like a plan? ngraham: It's `<nl/>` in this context, not `<br/>` But if the other code already does something else… | |||||
91 | mErrorMessageWidget->animatedShow(); | ||||
92 | } | ||||
93 | | ||||
94 | void showFailedFileDetails() | ||||
95 | { | ||||
96 | QString message = i18n("Failed to import documents:"); | ||||
ngraham: Localize this string | |||||
97 | KMessageBox::errorList(q, | ||||
98 | message, | ||||
99 | failedFileList | ||||
100 | ); | ||||
101 | } | ||||
102 | | ||||
103 | void showFailedDirDetails() | ||||
104 | { | ||||
105 | QString message = i18n("Failed to create subfolders:"); | ||||
ngraham: Localize this string | |||||
106 | KMessageBox::errorList(q, | ||||
107 | message, | ||||
108 | failedDirList | ||||
109 | ); | ||||
110 | } | ||||
44 | }; | 111 | }; | ||
45 | 112 | | |||
46 | DialogPage::DialogPage(QWidget* parent) | 113 | DialogPage::DialogPage(QWidget* parent) | ||
47 | : QWidget(parent) | 114 | : QWidget(parent) | ||
48 | , d(new DialogPagePrivate) | 115 | , d(new DialogPagePrivate) | ||
49 | { | 116 | { | ||
117 | d->q = this; | ||||
50 | d->setupUi(this); | 118 | d->setupUi(this); | ||
51 | d->mLayout = new QVBoxLayout(d->mButtonContainer); | 119 | d->mLayout = new QVBoxLayout(d->mButtonContainer); | ||
120 | d->setupFailedListActions(); | ||||
121 | d->mErrorMessageWidget->hide(); | ||||
52 | } | 122 | } | ||
53 | 123 | | |||
54 | DialogPage::~DialogPage() | 124 | DialogPage::~DialogPage() | ||
55 | { | 125 | { | ||
56 | delete d; | 126 | delete d; | ||
57 | } | 127 | } | ||
58 | 128 | | |||
59 | void DialogPage::removeButtons() | 129 | void DialogPage::removeButtons() | ||
Show All 17 Lines | 141 | { | |||
77 | connect(button, &QAbstractButton::clicked, this, [this, id]() { | 147 | connect(button, &QAbstractButton::clicked, this, [this, id]() { | ||
78 | d->mEventLoop->exit(id); | 148 | d->mEventLoop->exit(id); | ||
79 | }); | 149 | }); | ||
80 | d->mLayout->addWidget(button); | 150 | d->mLayout->addWidget(button); | ||
81 | d->mButtons << button; | 151 | d->mButtons << button; | ||
82 | return id; | 152 | return id; | ||
83 | } | 153 | } | ||
84 | 154 | | |||
155 | void DialogPage::slotShowErrors(const QStringList& files, const QStringList& dirs) | ||||
156 | { | ||||
157 | d->showErrors(files, dirs); | ||||
158 | } | ||||
159 | | ||||
160 | void DialogPage::slotShowFailedFileDetails() | ||||
161 | { | ||||
162 | d->showFailedFileDetails(); | ||||
163 | } | ||||
164 | | ||||
165 | void DialogPage::slotShowFailedDirDetails() | ||||
166 | { | ||||
167 | d->showFailedDirDetails(); | ||||
168 | } | ||||
169 | | ||||
85 | int DialogPage::exec() | 170 | int DialogPage::exec() | ||
86 | { | 171 | { | ||
87 | QEventLoop loop; | 172 | QEventLoop loop; | ||
88 | d->mEventLoop = &loop; | 173 | d->mEventLoop = &loop; | ||
89 | return loop.exec(); | 174 | return loop.exec(); | ||
90 | } | 175 | } | ||
91 | 176 | | |||
92 | } // namespace | 177 | } // namespace |
Localize this string