mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
ContentManagerError -> KiwixAppError
Also introduced `showErrorBox()`
This commit is contained in:
parent
c7295fbc05
commit
cdd5353859
@ -32,47 +32,32 @@ SettingsManager* getSettingsManager()
|
|||||||
return KiwixApp::instance()->getSettingsManager();
|
return KiwixApp::instance()->getSettingsManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContentManagerError : public std::runtime_error
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ContentManagerError(const QString& summary, const QString& details)
|
|
||||||
: std::runtime_error(summary.toStdString())
|
|
||||||
, m_details(details)
|
|
||||||
{}
|
|
||||||
|
|
||||||
QString summary() const { return QString::fromStdString(what()); }
|
|
||||||
QString details() const { return m_details; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString m_details;
|
|
||||||
};
|
|
||||||
|
|
||||||
void throwDownloadUnavailableError()
|
void throwDownloadUnavailableError()
|
||||||
{
|
{
|
||||||
throw ContentManagerError(gt("download-unavailable"),
|
throw KiwixAppError(gt("download-unavailable"),
|
||||||
gt("download-unavailable-text"));
|
gt("download-unavailable-text"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkThatBookCanBeSaved(const kiwix::Book& book, QString targetDir)
|
void checkThatBookCanBeSaved(const kiwix::Book& book, QString targetDir)
|
||||||
{
|
{
|
||||||
const QFileInfo targetDirInfo(targetDir);
|
const QFileInfo targetDirInfo(targetDir);
|
||||||
if ( !targetDirInfo.isDir() ) {
|
if ( !targetDirInfo.isDir() ) {
|
||||||
throw ContentManagerError(gt("download-storage-error"),
|
throw KiwixAppError(gt("download-storage-error"),
|
||||||
gt("download-dir-missing"));
|
gt("download-dir-missing"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: This may lie under Windows
|
// XXX: This may lie under Windows
|
||||||
// XXX: (see https://doc.qt.io/qt-5/qfile.html#platform-specific-issues)
|
// XXX: (see https://doc.qt.io/qt-5/qfile.html#platform-specific-issues)
|
||||||
if ( !targetDirInfo.isWritable() ) {
|
if ( !targetDirInfo.isWritable() ) {
|
||||||
throw ContentManagerError(gt("download-storage-error"),
|
throw KiwixAppError(gt("download-storage-error"),
|
||||||
gt("download-dir-not-writable"));
|
gt("download-dir-not-writable"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QStorageInfo storage(targetDir);
|
QStorageInfo storage(targetDir);
|
||||||
auto bytesAvailable = storage.bytesAvailable();
|
auto bytesAvailable = storage.bytesAvailable();
|
||||||
if (bytesAvailable == -1 || book.getSize() > (unsigned long long) bytesAvailable) {
|
if (bytesAvailable == -1 || book.getSize() > (unsigned long long) bytesAvailable) {
|
||||||
throw ContentManagerError(gt("download-storage-error"),
|
throw KiwixAppError(gt("download-storage-error"),
|
||||||
gt("download-storage-error-text"));
|
gt("download-storage-error-text"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,9 +541,9 @@ void ContentManager::downloadBook(const QString &id)
|
|||||||
managerModel->setDownloadState(id, downloadState);
|
managerModel->setDownloadState(id, downloadState);
|
||||||
emit(oneBookChanged(id));
|
emit(oneBookChanged(id));
|
||||||
}
|
}
|
||||||
catch ( const ContentManagerError& err )
|
catch ( const KiwixAppError& err )
|
||||||
{
|
{
|
||||||
showInfoBox(err.summary(), err.details(), mp_view);
|
showErrorBox(err, mp_view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,4 +44,24 @@ void showConfirmBox(QString title, QString text, QWidget *parent,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class KiwixAppError : public std::runtime_error
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KiwixAppError(const QString& summary, const QString& details)
|
||||||
|
: std::runtime_error(summary.toStdString())
|
||||||
|
, m_details(details)
|
||||||
|
{}
|
||||||
|
|
||||||
|
QString summary() const { return QString::fromStdString(what()); }
|
||||||
|
QString details() const { return m_details; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_details;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline void showErrorBox(const KiwixAppError& err, QWidget *parent = nullptr)
|
||||||
|
{
|
||||||
|
showInfoBox(err.summary(), err.details(), parent);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // KIWIXCONFIRMBOX_H
|
#endif // KIWIXCONFIRMBOX_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user