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/language.h"
45#include "../../backend/managers/cswordbackend.h"
46#include "../../util/btassert.h"
47#include "../../util/btconnect.h"
48#include "../btbookshelfgroupingmenu.h"
49#include "../btbookshelfview.h"
54#pragma GCC diagnostic push
55#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
56#include <installmgr.h>
59#pragma GCC diagnostic pop
65 "GUI/BookshelfWizard/InstallPage/installPathIndex");
68 QStringList
const & languages,
73 && languages.contains(mInfo->
language()->translatedName());
76 using CSV = sword::SWVersion
const;
77 CSMI
const *
const installedModule =
79 return installedModule
80 && (CSV(installedModule->config(CSMI::ModuleVersion).toLatin1())
81 < CSV(mInfo->
config(CSMI::ModuleVersion).toLatin1()));
106 QVBoxLayout *
const verticalLayout =
new QVBoxLayout(
this);
108 QHBoxLayout * horizontalLayout =
new QHBoxLayout;
114 verticalLayout->addLayout(horizontalLayout);
119 QHeaderView::ResizeToContents);
123 m_msgLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
127 QHBoxLayout *
const pathLayout =
new QHBoxLayout();
132 QComboBox::AdjustToMinimumContentsLengthWithIcon);
134 QSizePolicy::Minimum);
135 m_pathCombo->view()->setTextElideMode(Qt::ElideMiddle);
141 pathLayout->setContentsMargins(0, 8, 0, 0);
145 pathLayout->addStretch();
157 verticalLayout->addLayout(pathLayout);
192 this, &BtBookshelfWorksPage::completeChanged);
204 setTitle(QApplication::translate(
"BookshelfWizard",
"Install Works"));
205 setSubTitle(QApplication::translate(
"BookshelfWizard",
206 "Choose one or more works to "
208 setButtonText(QWizard::NextButton,tr(
"Install Works >"));
210 setTitle(QApplication::translate(
"BookshelfWizard",
"Update Works"));
211 setSubTitle(QApplication::translate(
"BookshelfWizard",
212 "Choose one or more works to "
214 setButtonText(QWizard::NextButton,tr(
"Update Works >"));
217 setTitle(QApplication::translate(
"BookshelfWizard",
"Remove Works"));
218 setSubTitle(QApplication::translate(
"BookshelfWizard",
219 "Choose one or more works to "
221 setButtonText(QWizard::NextButton,tr(
"Remove Works >"));
226 m_pathCombo->setToolTip(tr(
"The folder where the new works will be "
231 m_msgLabel->setText(tr(
"There are no works to update."));
233 m_msgLabel->setText(tr(
"No works are currently installed so they "
234 "cannot be removed."));
238 tr(
"No works can be installed with the current selection of "
239 "remote libraries and languages. Please go back and make a "
240 "different selection."));
246 tr(
"Change the grouping of items in the bookshelf."));
258 QStringList languages;
270 for (
auto const & sourceName : sources) {
271 sword::InstallSource
const source =
273 std::unique_ptr<CSwordBackend const> backend(
275 bool backendUsed =
false;
276 for (
auto *
const module : backend->moduleList()) {
278 QString
const & moduleName =
module->name();
279 if (addedModuleNames.contains(moduleName))
281 addedModuleNames.insert(moduleName);
283 module->setProperty("installSourceName",
284 QString(source.caption.c_str()));
294 bool const noWorks = (addedModuleNames.count() == 0);
304 if (languages.count() == 1) {
340 QDir
const dir(path);
341 if (!dir.exists() || !dir.isReadable())
343 return QFileInfo(dir.canonicalPath()).isWritable();
348 bool haveUsableTargets =
false;
351 m_pathCombo->addItem(QDir::toNativeSeparators(target));
352 haveUsableTargets =
true;
358 if (haveUsableTargets) {
361 int const cfgValue =
btConfig().
value<
int>(installPathKey, 0);
363 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)