15 #include <QApplication>
17 #include <QFontMetrics>
18 #include <QHeaderView>
19 #include <QMessageBox>
20 #include <QModelIndex>
21 #include <QPushButton>
22 #include <QStandardItem>
23 #include <QStandardItemModel>
24 #include <QStringLiteral>
29 #include <QVBoxLayout>
30 #include <QWizardPage>
31 #include "../../backend/config/btconfig.h"
32 #include "../../backend/btinstallbackend.h"
33 #include "../../util/btconnect.h"
40 #pragma GCC diagnostic push
41 #pragma GCC diagnostic ignored "-Wextra-semi"
42 #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
43 #include <installmgr.h>
45 #pragma GCC diagnostic pop
52 QString
const SourcesKey =
"GUI/BookshelfWizard/sources";
68 m_model =
new QStandardItemModel(
this);
71 this, &QWizardPage::completeChanged);
75 setTitle(QApplication::translate(
"BookshelfWizard",
76 "Choose Remote Libraries"));
77 setSubTitle(QApplication::translate(
79 "Choose one or more remote libraries to install works from."));
91 QStringList saveSources;
94 if (saveSources.empty())
110 for (
int row = 0; row <
m_model->rowCount(); ++row) {
111 QStandardItem *
const item =
m_model->item(row,0);
112 if (sources.contains(item->text()))
113 item->setCheckState(Qt::Checked);
122 auto const addButton = [
this](
int row,
int column,
123 QString
const & text,
bool const tag) {
124 QPushButton *
const button =
new QPushButton(text,
this);
130 QString
const removeText = tr(
"Remove");
131 for (
auto const &
source : sourceList) {
132 auto *
const item =
new QStandardItem(
source);
133 item->setCheckable(
true);
135 int const row =
m_model->rowCount() - 1;
141 m_model->appendRow(
new QStandardItem(tr(
"< Add new remote library >")));
142 int const row =
m_model->rowCount() - 1;
143 QString
const addText = tr(
"Add");
144 QPushButton *
const button = addButton(row, 1, addText,
ButtonTagAdd);
149 m_sourcesTableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
156 qMax(fontMetrics.horizontalAdvance(removeText),
157 fontMetrics.horizontalAdvance(addText)) + 60);
161 for (
int row = 0; row <
m_model->rowCount(); ++row)
162 if (
m_model->item(row, 0)->checkState() == Qt::Checked)
169 for (
int row = 0; row <
m_model->rowCount(); ++row) {
170 QStandardItem *
const item =
m_model->item(row, 0);
171 if (item->checkState() == Qt::Checked)
172 sources << item->text();
178 QModelIndex
const index =
m_model->index(row, 1);
179 if (
static_cast<QPushButton *
>(
183 if (QMessageBox::warning(
186 tr(
"Do you really want to delete this source?"),
187 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
189 m_model->item(index.row(), 0)->text());
198 if (dlg.exec() != QDialog::Accepted)
205 sword::InstallSource newSource = dlg.
getSource();
206 if (*(newSource.type.c_str()) !=
'\0')
BtConfig & btConfig()
This is a shortchand for BtConfig::getInstance().
void slotButtonClicked(int row)
void selectSourcesInModel(QStringList const &sources)
QStandardItemModel * m_model
void initializePage() final override
BtBookshelfSourcesPage(QWidget *parent=nullptr)
void updateSourcesModel()
bool isComplete() const final override
QStringList selectedSources() const
QTableView * m_sourcesTableView
QVBoxLayout * m_verticalLayout
int nextId() const final override
BtBookshelfWizard & btWizard() const noexcept
BtBookshelfLanguagesPage & languagesPage() const noexcept
T value(QString const &key, T const &defaultValue=T()) const
Returns the settings value for the given global key.
bool wasRemoteListAdded()
sword::InstallSource getSource()
bool deleteSource(const QString &name)
bool addSource(sword::InstallSource &source)
sword::InstallSource source(const QString &name)
QStringList sourceNameList()
QStringList const initialSelection
constexpr bool const ButtonTagRemove
char const buttonPropertyName[]
constexpr bool const ButtonTagAdd