mirror of
https://github.com/zealdocs/zeal.git
synced 2024-11-22 21:53:03 +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();
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
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
|
||||
m_isStorageReadOnly = !isDirWritable(m_application->settings()->docsetPath);
|
||||
|
||||
#ifdef Q_OS_MACOS
|
||||
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->storageStatusLabel->setVisible(m_isStorageReadOnly);
|
||||
|
||||
const QFileInfo fi(m_application->settings()->docsetPath);
|
||||
ui->storageStatusLabel->setText(fi.exists() ? tr("<b>Docset storage is read only.</b>")
|
||||
: tr("<b>Docset storage does not exist.</b>"));
|
||||
|
||||
@ -636,7 +629,10 @@ void DocsetsDialog::enableControls()
|
||||
void DocsetsDialog::disableControls()
|
||||
{
|
||||
// Dialog buttons.
|
||||
if (!m_isStorageReadOnly) {
|
||||
// Always show the close button if storage is read only.
|
||||
ui->buttonBox->setStandardButtons(QDialogButtonBox::Cancel);
|
||||
}
|
||||
|
||||
// Installed docsets
|
||||
ui->addFeedButton->setEnabled(false);
|
||||
@ -844,3 +840,9 @@ QString DocsetsDialog::cacheLocation(const QString &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 QString cacheLocation(const QString &fileName);
|
||||
static bool isDirWritable(const QString &path);
|
||||
};
|
||||
|
||||
} // namespace WidgetUi
|
||||
|
Loading…
Reference in New Issue
Block a user