mirror of
https://github.com/zealdocs/zeal.git
synced 2024-11-26 15:43:49 +03:00
fix(ui): fix docset storage writable check
Checks if the directly is writable by attempting to write. Fixes #1036 and #1059.
This commit is contained in:
parent
bc390d3570
commit
de5ba7bd0c
@ -78,16 +78,7 @@ DocsetsDialog::DocsetsDialog(Core::Application *app, QWidget *parent)
|
|||||||
|
|
||||||
loadDocsetList();
|
loadDocsetList();
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
m_isStorageReadOnly = !isDirWritable(m_application->settings()->docsetPath);
|
||||||
qt_ntfs_permission_lookup++;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const QFileInfo fi(m_application->settings()->docsetPath);
|
|
||||||
m_isStorageReadOnly = !fi.isWritable();
|
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
|
||||||
qt_ntfs_permission_lookup--;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_MACOS
|
||||||
ui->availableDocsetList->setAttribute(Qt::WA_MacShowFocusRect, false);
|
ui->availableDocsetList->setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||||
@ -96,6 +87,8 @@ DocsetsDialog::DocsetsDialog(Core::Application *app, QWidget *parent)
|
|||||||
|
|
||||||
ui->statusLabel->clear(); // Clear text shown in the designer mode.
|
ui->statusLabel->clear(); // Clear text shown in the designer mode.
|
||||||
ui->storageStatusLabel->setVisible(m_isStorageReadOnly);
|
ui->storageStatusLabel->setVisible(m_isStorageReadOnly);
|
||||||
|
|
||||||
|
const QFileInfo fi(m_application->settings()->docsetPath);
|
||||||
ui->storageStatusLabel->setText(fi.exists() ? tr("<b>Docset storage is read only.</b>")
|
ui->storageStatusLabel->setText(fi.exists() ? tr("<b>Docset storage is read only.</b>")
|
||||||
: tr("<b>Docset storage does not exist.</b>"));
|
: tr("<b>Docset storage does not exist.</b>"));
|
||||||
|
|
||||||
@ -636,7 +629,10 @@ void DocsetsDialog::enableControls()
|
|||||||
void DocsetsDialog::disableControls()
|
void DocsetsDialog::disableControls()
|
||||||
{
|
{
|
||||||
// Dialog buttons.
|
// Dialog buttons.
|
||||||
ui->buttonBox->setStandardButtons(QDialogButtonBox::Cancel);
|
if (!m_isStorageReadOnly) {
|
||||||
|
// Always show the close button if storage is read only.
|
||||||
|
ui->buttonBox->setStandardButtons(QDialogButtonBox::Cancel);
|
||||||
|
}
|
||||||
|
|
||||||
// Installed docsets
|
// Installed docsets
|
||||||
ui->addFeedButton->setEnabled(false);
|
ui->addFeedButton->setEnabled(false);
|
||||||
@ -844,3 +840,9 @@ QString DocsetsDialog::cacheLocation(const QString &fileName)
|
|||||||
{
|
{
|
||||||
return QDir(Core::Application::cacheLocation()).filePath(fileName);
|
return QDir(Core::Application::cacheLocation()).filePath(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DocsetsDialog::isDirWritable(const QString &path)
|
||||||
|
{
|
||||||
|
auto file = std::make_unique<QTemporaryFile>(path + QLatin1String("/.zeal_writable_check_XXXXXX.tmp"));
|
||||||
|
return file->open();
|
||||||
|
}
|
||||||
|
@ -125,6 +125,7 @@ private:
|
|||||||
static inline int percent(qint64 fraction, qint64 total);
|
static inline int percent(qint64 fraction, qint64 total);
|
||||||
|
|
||||||
static QString cacheLocation(const QString &fileName);
|
static QString cacheLocation(const QString &fileName);
|
||||||
|
static bool isDirWritable(const QString &path);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace WidgetUi
|
} // namespace WidgetUi
|
||||||
|
Loading…
Reference in New Issue
Block a user