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"
53#pragma GCC diagnostic push
54#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
55#include <installmgr.h>
58#pragma GCC diagnostic pop
64 "GUI/BookshelfWizard/InstallPage/installPathIndex");
67 QStringList
const & languages,
72 && languages.contains(mInfo->
language()->translatedName());
75 using CSV = sword::SWVersion
const;
76 CSMI
const *
const installedModule =
78 return installedModule
79 && (CSV(installedModule->config(CSMI::ModuleVersion).toLatin1())
80 < CSV(mInfo->
config(CSMI::ModuleVersion).toLatin1()));
105 QVBoxLayout *
const verticalLayout =
new QVBoxLayout(
this);
107 QHBoxLayout * horizontalLayout =
new QHBoxLayout;
113 verticalLayout->addLayout(horizontalLayout);
118 QHeaderView::ResizeToContents);
122 m_msgLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
126 QHBoxLayout *
const pathLayout =
new QHBoxLayout();
131 QComboBox::AdjustToMinimumContentsLengthWithIcon);
133 QSizePolicy::Minimum);
134 m_pathCombo->view()->setTextElideMode(Qt::ElideMiddle);
140 pathLayout->setContentsMargins(0, 8, 0, 0);
144 pathLayout->addStretch();
156 verticalLayout->addLayout(pathLayout);
191 this, &BtBookshelfWorksPage::completeChanged);
203 setTitle(QApplication::translate(
"BookshelfWizard",
"Install Works"));
204 setSubTitle(QApplication::translate(
"BookshelfWizard",
205 "Choose one or more works to "
207 setButtonText(QWizard::NextButton,tr(
"Install Works >"));
209 setTitle(QApplication::translate(
"BookshelfWizard",
"Update Works"));
210 setSubTitle(QApplication::translate(
"BookshelfWizard",
211 "Choose one or more works to "
213 setButtonText(QWizard::NextButton,tr(
"Update Works >"));
216 setTitle(QApplication::translate(
"BookshelfWizard",
"Remove Works"));
217 setSubTitle(QApplication::translate(
"BookshelfWizard",
218 "Choose one or more works to "
220 setButtonText(QWizard::NextButton,tr(
"Remove Works >"));
225 m_pathCombo->setToolTip(tr(
"The folder where the new works will be "
230 m_msgLabel->setText(tr(
"There are no works to update."));
232 m_msgLabel->setText(tr(
"No works are currently installed so they "
233 "cannot be removed."));
237 tr(
"No works can be installed with the current selection of "
238 "remote libraries and languages. Please go back and make a "
239 "different selection."));
245 tr(
"Change the grouping of items in the bookshelf."));
257 QStringList languages;
269 for (
auto const & sourceName : sources) {
270 sword::InstallSource
const source =
272 std::unique_ptr<CSwordBackend const> backend(
274 bool backendUsed =
false;
275 for (
auto *
const module : backend->moduleList()) {
277 QString
const & moduleName =
module->name();
278 if (addedModuleNames.contains(moduleName))
280 addedModuleNames.insert(moduleName);
282 module->setProperty("installSourceName",
283 QString(source.caption.c_str()));
293 bool const noWorks = (addedModuleNames.count() == 0);
303 if (languages.count() == 1) {
339 QDir
const dir(path);
340 if (!dir.exists() || !dir.isReadable())
342 return QFileInfo(dir.canonicalPath()).isWritable();
347 bool haveUsableTargets =
false;
350 m_pathCombo->addItem(QDir::toNativeSeparators(target));
351 haveUsableTargets =
true;
357 if (haveUsableTargets) {
360 int const cfgValue =
btConfig().
value<
int>(installPathKey, 0);
362 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 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)