16#include <QAbstractItemView>
17#include <QApplication>
27#include <QNonConstOverload>
31#include <QStringLiteral>
37#include "../../backend/btinstallbackend.h"
38#include "../../backend/bookshelfmodel/btbookshelfmodel.h"
39#include "../../backend/bookshelfmodel/btbookshelffiltermodel.h"
40#include "../../backend/bookshelfmodel/btbookshelftreemodel.h"
41#include "../../backend/config/btconfig.h"
42#include "../../backend/drivers/btmoduleset.h"
43#include "../../backend/drivers/cswordmoduleinfo.h"
44#include "../../backend/managers/cswordbackend.h"
45#include "../../util/btassert.h"
46#include "../../util/btconnect.h"
47#include "../btbookshelfgroupingmenu.h"
48#include "../btbookshelfview.h"
55#pragma GCC diagnostic push
56#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
58#include <installmgr.h>
62#pragma GCC diagnostic pop
69 "GUI/BookshelfWizard/InstallPage/installPathIndex");
72 QStringList
const & languages,
77 && languages.contains(mInfo->
language()->translatedName());
80 using CSV = sword::SWVersion
const;
81 CSMI
const *
const installedModule =
83 return installedModule
84 && (CSV(installedModule->config(CSMI::ModuleVersion).toLatin1())
85 < CSV(mInfo->
config(CSMI::ModuleVersion).toLatin1()));
110 QVBoxLayout *
const verticalLayout =
new QVBoxLayout(
this);
112 QHBoxLayout * horizontalLayout =
new QHBoxLayout;
118 verticalLayout->addLayout(horizontalLayout);
123 QHeaderView::ResizeToContents);
127 m_msgLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
131 QHBoxLayout *
const pathLayout =
new QHBoxLayout();
136 QComboBox::AdjustToMinimumContentsLengthWithIcon);
138 QSizePolicy::Minimum);
139 m_pathCombo->view()->setTextElideMode(Qt::ElideMiddle);
145 pathLayout->setContentsMargins(0, 8, 0, 0);
149 pathLayout->addStretch();
161 verticalLayout->addLayout(pathLayout);
196 this, &BtBookshelfWorksPage::completeChanged);
208 setTitle(QApplication::translate(
"BookshelfWizard",
"Install Works"));
209 setSubTitle(QApplication::translate(
"BookshelfWizard",
210 "Choose one or more works to "
212 setButtonText(QWizard::NextButton,tr(
"Install Works >"));
214 setTitle(QApplication::translate(
"BookshelfWizard",
"Update Works"));
215 setSubTitle(QApplication::translate(
"BookshelfWizard",
216 "Choose one or more works to "
218 setButtonText(QWizard::NextButton,tr(
"Update Works >"));
221 setTitle(QApplication::translate(
"BookshelfWizard",
"Remove Works"));
222 setSubTitle(QApplication::translate(
"BookshelfWizard",
223 "Choose one or more works to "
225 setButtonText(QWizard::NextButton,tr(
"Remove Works >"));
230 m_pathCombo->setToolTip(tr(
"The folder where the new works will be "
235 m_msgLabel->setText(tr(
"There are no works to update."));
237 m_msgLabel->setText(tr(
"No works are currently installed so they "
238 "cannot be removed."));
242 tr(
"No works can be installed with the current selection of "
243 "remote libraries and languages. Please go back and make a "
244 "different selection."));
250 tr(
"Change the grouping of items in the bookshelf."));
262 QStringList languages;
274 for (
auto const & sourceName : sources) {
275 sword::InstallSource
const source =
277 std::unique_ptr<CSwordBackend const> backend(
279 bool backendUsed =
false;
280 for (
auto *
const module : backend->moduleList()) {
282 QString
const & moduleName =
module->name();
283 if (addedModuleNames.contains(moduleName))
285 addedModuleNames.insert(moduleName);
287 module->setProperty("installSourceName",
288 QString(source.caption.c_str()));
298 bool const noWorks = (addedModuleNames.count() == 0);
308 if (languages.count() == 1) {
324 return (numModules > 0)
347 QDir
const dir(path);
348 if (!dir.exists() || !dir.isReadable())
350 return QFileInfo(dir.canonicalPath()).isWritable();
355 bool haveUsableTargets =
false;
358 m_pathCombo->addItem(QDir::toNativeSeparators(target));
359 haveUsableTargets =
true;
365 if (haveUsableTargets) {
368 int const cfgValue =
btConfig().
value<
int>(installPathKey, 0);
370 m_pathCombo->setCurrentIndex(cfgValue > lastIdx ? lastIdx : cfgValue);
static bool installPathIsUsable(QString const &path)
BtConfig & btConfig()
This is a shortchand for BtConfig::getInstance().
void setNameFilterFixedString(QString const &nameFilter)
static constexpr int const MAX_MODULES
static std::shared_ptr< BtBookshelfModel > newInstance()
auto const & list() const noexcept
static Grouping const DEFAULT
static Grouping const CAT
static Grouping const CAT_LANG
void saveTo(BtConfigCore &config, QString const &key) const
bool loadFrom(BtConfigCore const &config, QString const &key)
void groupingOrderChanged(BtBookshelfTreeModel::Grouping newGrouping)
void setDefaultChecked(CheckedBehavior const b)
BtModuleSet const & checkedModules() const
void setGroupingOrder(BtBookshelfTreeModel::Grouping const &groupingOrder, bool emitSignal=true)
void setSourceModel(std::shared_ptr< QAbstractItemModel > sourceModel)
void moduleChecked(CSwordModuleInfo *module, bool checked)
BtBookshelfWizard & btWizard() const noexcept
QStringList selectedSources() const
QStringList selectedLanguages() const
QToolButton * m_groupingButton
bool isComplete() const final override
void initializePage() final override
QLineEdit * m_nameFilterEdit
std::shared_ptr< BtBookshelfModel > m_bookshelfModel
std::vector< std::unique_ptr< CSwordBackend const > > m_usedBackends
void slotGroupingActionTriggered(BtBookshelfTreeModel::Grouping const &grouping)
BtModuleSet const & checkedModules() const
int nextId() const final override
QString installPath() const
QLabel * m_nameFilterLabel
void slotGroupingOrderChanged(BtBookshelfTreeModel::Grouping const &g)
WizardTaskType const m_taskType
BtBookshelfTreeModel::Grouping m_groupingOrder
void slotPathChanged(int const index)
BtBookshelfGroupingMenu * m_groupingMenu
BtBookshelfWorksPage(WizardTaskType iType, QWidget *parent=nullptr)
QMenu * m_itemContextMenu
BtBookshelfView * m_bookshelfView
BtInstallPageModel * m_installPageModel
T value(QString const &key, T const &defaultValue=T()) const
Returns the settings value for the given global key.
void setValue(QString const &key, T const &value)
Sets a value for a key.
QStringList swordDirList() const
Sword prefix list.
CSwordModuleInfo * findModuleByName(const QString &name) const
Searches for a module with the given name.
void sigSwordSetupChanged()
static CSwordBackend & instance() noexcept
QString config(const CSwordModuleInfo::ConfigEntry entry) const
QString const & name() const
std::shared_ptr< Language const > language() const
sword::InstallSource source(const QString &name)
QStringList sourceNameList()
std::unique_ptr< CSwordBackend > backend(sword::InstallSource const &is)
QString const groupingOrderKey("GUI/BookshelfWizard/InstallPage/grouping")
QString const installPathKey("GUI/BookshelfWizard/InstallPage/installPathIndex")
bool filter(WizardTaskType const taskType, QStringList const &languages, CSwordModuleInfo const *const mInfo)