Commit 41034c76 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Network Filesharing: Refactor foreach and emit, smaller improvements

Summary:
Compile without emit and foreach.
The private variables inside the model are prefixed with _, because
the userList variable shadowed class definition. This should clear things up.

And some better overloads and const qualifiers.

Test Plan: Compiles

Reviewers: #dolphin, ngraham

Reviewed By: #dolphin, ngraham

Differential Revision: https://phabricator.kde.org/D29118
parent bb0c8a4d
......@@ -62,6 +62,11 @@ add_feature_info("Samba Installation" SAMBA_INSTALL "Automatic installation of '
# KI18N Translation Domain for this library
add_definitions(-DTRANSLATION_DOMAIN=\"kfileshare\")
add_definitions(
-DQT_NO_FOREACH
-DQT_NO_EMIT
)
add_subdirectory(samba)
install(FILES org.kde.kdenetwork-filesharing.metainfo.xml
......
......@@ -29,16 +29,16 @@
UserPermissionModel::UserPermissionModel(KSambaShareData &shareData, QObject *parent)
: QAbstractTableModel(parent)
, userList(getUsersList())
, shareData(shareData)
, usersAcl()
, m_userList(getUsersList())
, m_shareData(shareData)
, m_usersAcl()
{
setupData();
}
void UserPermissionModel::setupData()
{
QStringList acl = shareData.acl().split(QStringLiteral(","),
const QStringList acl = m_shareData.acl().split(QLatin1Char(','),
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
QString::SkipEmptyParts);
#else
......@@ -47,11 +47,11 @@ void UserPermissionModel::setupData()
QList<QString>::const_iterator itr;
for (itr = acl.constBegin(); itr != acl.constEnd(); ++itr) {
QStringList userInfo = (*itr).trimmed().split(QLatin1Char(':'));
usersAcl.insert(userInfo.at(0), QVariant(userInfo.at(1)));
const QStringList userInfo = (*itr).trimmed().split(QLatin1Char(':'));
m_usersAcl.insert(userInfo.at(0), userInfo.at(1));
}
if (usersAcl.isEmpty()) {
usersAcl.insert(QStringLiteral("Everyone"), QStringLiteral("R"));
if (m_usersAcl.isEmpty()) {
m_usersAcl.insert(QStringLiteral("Everyone"), QStringLiteral("R"));
}
}
......@@ -83,8 +83,9 @@ QStringList UserPermissionModel::getUsersList() const
QStringList userList;
userList.append(QStringLiteral("Everyone"));
foreach (const QString &username, KUser::allUserNames()) {
if (username == QStringLiteral("nobody")) {
const QStringList userNames = KUser::allUserNames();
for (const QString &username : userNames) {
if (username == QLatin1String("nobody")) {
continue;
}
KUser user(username);
......@@ -100,7 +101,7 @@ QStringList UserPermissionModel::getUsersList() const
int UserPermissionModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return userList.count();
return m_userList.count();
}
int UserPermissionModel::columnCount(const QModelIndex &parent) const
......@@ -112,13 +113,13 @@ int UserPermissionModel::columnCount(const QModelIndex &parent) const
QVariant UserPermissionModel::data(const QModelIndex &index, int role) const
{
if ((role == Qt::DisplayRole) && (index.column() == 0)) {
return QVariant(userList.at(index.row()));
return QVariant(m_userList.at(index.row()));
}
if ((role == Qt::DisplayRole || role == Qt::EditRole) && (index.column() == 1)) {
QMap<QString, QVariant>::ConstIterator itr;
for (itr = usersAcl.constBegin(); itr != usersAcl.constEnd(); ++itr) {
if (itr.key().endsWith(userList.at(index.row()))) {
for (itr = m_usersAcl.constBegin(); itr != m_usersAcl.constEnd(); ++itr) {
if (itr.key().endsWith(m_userList.at(index.row()))) {
return itr.value();
}
}
......@@ -148,24 +149,24 @@ bool UserPermissionModel::setData(const QModelIndex &index, const QVariant &valu
QString key;
QMap<QString, QVariant>::ConstIterator itr;
for (itr = usersAcl.constBegin(); itr != usersAcl.constEnd(); ++itr) {
if (itr.key().endsWith(userList.at(index.row()))) {
for (itr = m_usersAcl.constBegin(); itr != m_usersAcl.constEnd(); ++itr) {
if (itr.key().endsWith(m_userList.at(index.row()))) {
key = itr.key();
break;
}
}
if (key.isEmpty()) {
key = userList.at(index.row());
key = m_userList.at(index.row());
}
if (value.isNull()) {
usersAcl.take(key);
m_usersAcl.take(key);
} else {
usersAcl.insert(key, value);
m_usersAcl.insert(key, value);
}
emit dataChanged(index, index);
Q_EMIT dataChanged(index, index);
return true;
}
......@@ -174,11 +175,11 @@ QString UserPermissionModel::getAcl() const
QString result;
QMap<QString, QVariant>::ConstIterator itr;
for (itr = usersAcl.constBegin(); itr != usersAcl.constEnd(); ++itr) {
for (itr = m_usersAcl.constBegin(); itr != m_usersAcl.constEnd(); ++itr) {
if (!itr.value().toString().isEmpty()) {
result.append(itr.key() + QStringLiteral(":") + itr.value().toString().toLower());
if (itr != (usersAcl.constEnd() - 1)) {
result.append(QStringLiteral(","));
if (itr != (m_usersAcl.constEnd() - 1)) {
result.append(QLatin1Char(','));
}
}
}
......
......@@ -45,9 +45,9 @@ public:
QString getAcl() const;
private:
QStringList userList;
KSambaShareData shareData;
QVariantMap usersAcl;
QStringList m_userList;
KSambaShareData m_shareData;
QVariantMap m_usersAcl;
void setupData();
QStringList getUsersList() const;
......
......@@ -62,7 +62,7 @@ SambaUserSharePlugin::SambaUserSharePlugin(QObject *parent, const QList<QVariant
return;
}
QFileInfo pathInfo(m_url);
const QFileInfo pathInfo(m_url);
if (!pathInfo.permission(QFile::ReadUser | QFile::WriteUser)) {
return;
}
......@@ -122,7 +122,7 @@ SambaUserSharePlugin::SambaUserSharePlugin(QObject *parent, const QList<QVariant
vLayoutMaster->addWidget(m_shareWidgets);
propertiesUi.setupUi(m_shareWidgets);
QList<KSambaShareData> shareList = KSambaShare::instance()->getSharesByPath(m_url);
const QList<KSambaShareData> shareList = KSambaShare::instance()->getSharesByPath(m_url);
if (!shareList.isEmpty()) {
shareData = shareList.at(0); // FIXME: using just the first in the list for a while
......@@ -167,7 +167,7 @@ SambaUserSharePlugin::~SambaUserSharePlugin()
#ifdef SAMBA_INSTALL
void SambaUserSharePlugin::installSamba()
{
QString package = QStringLiteral(SAMBA_PACKAGE_NAME);
const QString package = QStringLiteral(SAMBA_PACKAGE_NAME);
QStringList distroSambaPackages = package.split(QLatin1Char(','));
PackageKit::Transaction *transaction = PackageKit::Daemon::resolve(distroSambaPackages, PackageKit::Transaction::FilterArch);
......@@ -175,7 +175,8 @@ void SambaUserSharePlugin::installSamba()
QSharedPointer<QStringList> pkgids(new QStringList);
connect(transaction, &PackageKit::Transaction::package,
this, [pkgids] (PackageKit::Transaction::Info /*info*/, const QString& packageId, const QString& /*summary*/) { pkgids->append(packageId); });
this, [pkgids](PackageKit::Transaction::Info /*info*/, const QString &packageId,
const QString & /*summary*/) { pkgids->append(packageId); });
connect(transaction, &PackageKit::Transaction::finished,
this, [this, pkgids] (PackageKit::Transaction::Exit exit) {
......@@ -232,7 +233,7 @@ void SambaUserSharePlugin::setupViews()
void SambaUserSharePlugin::load()
{
bool guestAllowed = false;
bool sambaShared = KSambaShare::instance()->isDirectoryShared(m_url);
const bool sambaShared = KSambaShare::instance()->isDirectoryShared(m_url);
propertiesUi.sambaChk->setChecked(sambaShared);
toggleShareStatus(sambaShared);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment