diff --git a/Modules/samba/main.cpp b/Modules/samba/main.cpp index 007b014..be69f5c 100644 --- a/Modules/samba/main.cpp +++ b/Modules/samba/main.cpp @@ -1,82 +1,79 @@ /* SPDX-FileCopyrightText: 2020 Harald Sitter SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ #include #include #include #include #include #include #include #include #include "ksambasharemodel.h" #include "smbmountmodel.h" class SambaContainer : public KCModule { Q_OBJECT public: SambaContainer(QWidget *parent = nullptr, const QVariantList &list = QVariantList()); ~SambaContainer() override = default; private: QTableView *addTableView(const QString &localizedLabel, QAbstractListModel *model); }; K_PLUGIN_FACTORY(SambaFactory, registerPlugin(); ) SambaContainer::SambaContainer(QWidget *parent, const QVariantList &) : KCModule(parent) { KAboutData *about = new KAboutData(i18n("kcmsamba"), i18n("System Information Control Module"), QString(), QString(), KAboutLicense::GPL, i18n("(c) 2002 KDE Information Control Module Samba Team")); about->addAuthor(i18n("Michael Glauche"), QString(), QStringLiteral("glauche@isa.rwth-aachen.de")); about->addAuthor(i18n("Matthias Hoelzer"), QString(), QStringLiteral("hoelzer@kde.org")); about->addAuthor(i18n("David Faure"), QString(), QStringLiteral("faure@kde.org")); about->addAuthor(i18n("Harald Koschinski"), QString(), QStringLiteral("Harald.Koschinski@arcormail.de")); about->addAuthor(i18n("Wilco Greven"), QString(), QStringLiteral("greven@kde.org")); about->addAuthor(i18n("Alexander Neundorf"), QString(), QStringLiteral("neundorf@kde.org")); about->addAuthor(i18n("Harald Sitter"), QString(), QStringLiteral("sitter@kde.org")); setAboutData(about); QVBoxLayout *layout = new QVBoxLayout(this); Q_ASSERT(this->layout()); setLayout(layout); - addTableView(i18n("&Exports"), new KSambaShareModel(this)); + addTableView(i18nc("@title/group", "Exported Shares"), new KSambaShareModel(this)); - auto importsView = addTableView(i18n("&Imports"), new SmbMountModel(this)); + auto importsView = addTableView(i18nc("@title/group", "Mounted Shares"), new SmbMountModel(this)); importsView->horizontalHeader()->setSectionResizeMode(static_cast(SmbMountModel::ColumnRole::Accessible), QHeaderView::ResizeToContents); setButtons(Help); } QTableView *SambaContainer::addTableView(const QString &localizedLabel, QAbstractListModel *model) { - QString text = localizedLabel; auto title = new KTitleWidget(this); - // hackily remove ampersand to not break i18n too much in 5.18 - // TODO: replace i18n'd string to one without quick access marker - title->setText(text.remove("&")); + title->setText(localizedLabel); title->setLevel(2); layout()->addWidget(title); auto view = new QTableView(this); layout()->addWidget(view); view->setModel(model); view->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); view->horizontalHeader()->reset(); view->horizontalHeader()->setVisible(true); view->verticalHeader()->setVisible(false); return view; } #include "main.moc" diff --git a/Modules/samba/smbmountmodel.cpp b/Modules/samba/smbmountmodel.cpp index 5e76a14..ad7d9b8 100644 --- a/Modules/samba/smbmountmodel.cpp +++ b/Modules/samba/smbmountmodel.cpp @@ -1,147 +1,147 @@ /* SPDX-FileCopyrightText: 2020 Harald Sitter SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ #include "smbmountmodel.h" #include #include #include #include #include #include #include SmbMountModel::SmbMountModel(QObject *parent) : QAbstractListModel(parent) { connect(Solid::DeviceNotifier::instance(), &Solid::DeviceNotifier::deviceAdded, this, &SmbMountModel::addDevice); connect(Solid::DeviceNotifier::instance(), &Solid::DeviceNotifier::deviceRemoved, this, &SmbMountModel::removeDevice); reloadData(); } SmbMountModel::~SmbMountModel() = default; int SmbMountModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent) return m_devices.size(); } int SmbMountModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent) return static_cast(ColumnRole::ColumnCount); } QVariant SmbMountModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation != Qt::Horizontal || role != Qt::DisplayRole) { return {}; // we only have column headers. } Q_ASSERT(section (ColumnRole::ColumnCount)); switch (static_cast(section)) { case ColumnRole::Share: - return i18n("Resource"); // TODO: maybe reword for 5.19 + return i18n("Resource"); case ColumnRole::Path: - return i18n("Mounted Under"); // TODO: maybe reword for 5.19 + return i18n("Mounted Under"); case ColumnRole::Accessible: return i18nc("@title:column whether a samba share is accessible locally (i.e. mounted)", "Accessible"); case ColumnRole::ColumnCount: break; // noop } return {}; } QVariant SmbMountModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return {}; } Q_ASSERT(index.row() < m_devices.count()); Q_ASSERT(index.column() (ColumnRole::ColumnCount)); if (role == Qt::DisplayRole) { switch (static_cast(index.column())) { case ColumnRole::Share: return m_devices.at(index.row()).as()->url(); case ColumnRole::Path: return m_devices.at(index.row()).as()->filePath(); case ColumnRole::Accessible: break; // Decoration only case ColumnRole::ColumnCount: break; // noop } } if (role == Qt::DecorationRole) { switch (static_cast(index.column())) { case ColumnRole::Accessible: // Using characters here since we use a QTableView and can't just return m_devices.at(index.row()).as()->isAccessible() ? QIcon::fromTheme("dialog-ok") : QIcon::fromTheme("dialog-cancel"); case ColumnRole::Share: case ColumnRole::Path: break; // Display only case ColumnRole::ColumnCount: break; // noop } } return {}; } void SmbMountModel::addDevice(const QString &udi) { auto it = deviceForUdi(udi); if (it != m_devices.constEnd()) { return; // already in the list } beginInsertRows(QModelIndex(), m_devices.count(), m_devices.count()); m_devices.append(Solid::Device(udi)); endInsertRows(); } void SmbMountModel::removeDevice(const QString &udi) { auto it = deviceForUdi(udi); if (it == m_devices.constEnd()) { return; // untracked udi } const int index = static_cast(std::distance(m_devices.constBegin(), it)); beginRemoveRows(QModelIndex(), index, index); m_devices.removeAt(index); endRemoveRows(); } void SmbMountModel::reloadData() { beginResetModel(); m_devices.clear(); const auto devices = Solid::Device::listFromType(Solid::DeviceInterface::NetworkShare); for (auto it = devices.begin(); it != devices.end(); ++it) { switch (it->as()->type()) { case Solid::NetworkShare::Cifs: m_devices.append(*it); continue; case Solid::NetworkShare::Nfs: case Solid::NetworkShare::Unknown: continue; } } endResetModel(); } bool SmbMountModel::hasChildren(const QModelIndex &parent) const { return !parent.isValid() ? false : (rowCount(parent) > 0); }