Commit 6b92e24d authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Make it compile against qt6

parent 25cd2584
Pipeline #189190 passed with stage
in 47 seconds
......@@ -4,7 +4,7 @@
*/
#include "authhelper.h"
#include <kauth/helpersupport.h>
#include <QProcess>
#include <QRegularExpression>
......
......@@ -6,7 +6,7 @@
#ifndef AUTHHELPER_H
#define AUTHHELPER_H
#include <KAuth>
#include <KAuth/ActionReply>
using namespace KAuth;
......
......@@ -33,9 +33,8 @@
#include <KIO/CommandLauncherJob>
#include "model.h"
#include "usermanager.h"
#include "groupmanager.h"
#include "permissionshelper.h"
#ifdef SAMBA_INSTALL
#include "sambainstaller.h"
......@@ -43,124 +42,6 @@
K_PLUGIN_CLASS_WITH_JSON(SambaUserSharePlugin, "sambausershareplugin.json")
class ShareContext : public QObject
{
Q_OBJECT
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
Q_PROPERTY(bool canEnableGuest READ canEnableGuest CONSTANT)
Q_PROPERTY(bool guestEnabled READ guestEnabled WRITE setGuestEnabled NOTIFY guestEnabledChanged)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(int maximumNameLength READ maximumNameLength CONSTANT)
Q_PROPERTY(QString path READ path CONSTANT)
public:
explicit ShareContext(const QUrl &url, QObject *parent = nullptr)
: QObject(parent)
, m_shareData(resolveShare(url))
, m_enabled(KSambaShare::instance()->isDirectoryShared(m_shareData.path()))
// url isn't a member. always use .path()!
{
}
bool enabled() const
{
return m_enabled;
}
void setEnabled(bool enabled)
{
m_enabled = enabled;
Q_EMIT enabledChanged();
}
bool canEnableGuest()
{
return KSambaShare::instance()->areGuestsAllowed();
}
bool guestEnabled() const
{
// WTF is that enum even...
switch (m_shareData.guestPermission()) {
case KSambaShareData::GuestsNotAllowed:
return false;
case KSambaShareData::GuestsAllowed:
return true;
}
Q_UNREACHABLE();
return false;
}
void setGuestEnabled(bool enabled)
{
m_shareData.setGuestPermission(enabled ? KSambaShareData::GuestsAllowed : KSambaShareData::GuestsNotAllowed);
Q_EMIT guestEnabledChanged();
}
QString name() const
{
return m_shareData.name();
}
QString path() const {
return m_shareData.path();
}
void setName(const QString &name)
{
m_shareData.setName(name);
Q_EMIT nameChanged();
}
static constexpr int maximumNameLength()
{
// Windows 10 allows creating shares with a maximum of 60 characters when measured on 2020-08-13.
// We consider this kind of a soft limit as there appears to be no actual limit specified anywhere.
return 60;
}
Q_INVOKABLE static bool isNameFree(const QString &name)
{
return KSambaShare::instance()->isShareNameAvailable(name);
}
public Q_SLOTS:
QString newShareName(const QUrl &url)
{
Q_ASSERT(url.isValid());
Q_ASSERT(!url.isEmpty());
// TODO pretty sure this is buggy for urls with trailing slash where filename would be ""
return url.fileName().left(maximumNameLength());
}
Q_SIGNALS:
void enabledChanged();
void guestEnabledChanged();
void nameChanged();
private:
KSambaShareData resolveShare(const QUrl &url)
{
QFileInfo info(url.toLocalFile());
const QString path = info.canonicalFilePath();
Q_ASSERT(!path.isEmpty());
const QList<KSambaShareData> shareList = KSambaShare::instance()->getSharesByPath(path);
if (!shareList.isEmpty()) {
return shareList.first(); // FIXME: using just the first in the list for a while
}
KSambaShareData newShare;
newShare.setName(newShareName(url));
newShare.setGuestPermission(KSambaShareData::GuestsNotAllowed);
newShare.setPath(path);
return newShare;
}
public:
// TODO shouldn't be public may need refactoring though because the ACL model needs an immutable copy
KSambaShareData m_shareData;
private:
bool m_enabled = false; // this gets cached so we can manipulate its state from qml
};
SambaUserSharePlugin::SambaUserSharePlugin(QObject *parent, const QList<QVariant> &args)
: KPropertiesDialogPlugin(qobject_cast<KPropertiesDialog *>(parent))
......
......@@ -12,13 +12,133 @@
#include <kpropertiesdialog.h>
#include <KSambaShareData>
#include <KSambaShare>
#include <QFileInfo>
#include <memory>
#include "usermanager.h"
#include "model.h"
#include "permissionshelper.h"
class ShareContext : public QObject
{
Q_OBJECT
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
Q_PROPERTY(bool canEnableGuest READ canEnableGuest CONSTANT)
Q_PROPERTY(bool guestEnabled READ guestEnabled WRITE setGuestEnabled NOTIFY guestEnabledChanged)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(int maximumNameLength READ maximumNameLength CONSTANT)
Q_PROPERTY(QString path READ path CONSTANT)
public:
explicit ShareContext(const QUrl &url, QObject *parent = nullptr)
: QObject(parent)
, m_shareData(resolveShare(url))
, m_enabled(KSambaShare::instance()->isDirectoryShared(m_shareData.path()))
// url isn't a member. always use .path()!
{
}
bool enabled() const
{
return m_enabled;
}
void setEnabled(bool enabled)
{
m_enabled = enabled;
Q_EMIT enabledChanged();
}
bool canEnableGuest()
{
return KSambaShare::instance()->areGuestsAllowed();
}
bool guestEnabled() const
{
// WTF is that enum even...
switch (m_shareData.guestPermission()) {
case KSambaShareData::GuestsNotAllowed:
return false;
case KSambaShareData::GuestsAllowed:
return true;
}
Q_UNREACHABLE();
return false;
}
void setGuestEnabled(bool enabled)
{
m_shareData.setGuestPermission(enabled ? KSambaShareData::GuestsAllowed : KSambaShareData::GuestsNotAllowed);
Q_EMIT guestEnabledChanged();
}
QString name() const
{
return m_shareData.name();
}
QString path() const {
return m_shareData.path();
}
void setName(const QString &name)
{
m_shareData.setName(name);
Q_EMIT nameChanged();
}
static constexpr int maximumNameLength()
{
// Windows 10 allows creating shares with a maximum of 60 characters when measured on 2020-08-13.
// We consider this kind of a soft limit as there appears to be no actual limit specified anywhere.
return 60;
}
Q_INVOKABLE static bool isNameFree(const QString &name)
{
return KSambaShare::instance()->isShareNameAvailable(name);
}
public Q_SLOTS:
QString newShareName(const QUrl &url)
{
Q_ASSERT(url.isValid());
Q_ASSERT(!url.isEmpty());
// TODO pretty sure this is buggy for urls with trailing slash where filename would be ""
return url.fileName().left(maximumNameLength());
}
Q_SIGNALS:
void enabledChanged();
void guestEnabledChanged();
void nameChanged();
private:
KSambaShareData resolveShare(const QUrl &url)
{
QFileInfo info(url.toLocalFile());
const QString path = info.canonicalFilePath();
Q_ASSERT(!path.isEmpty());
const QList<KSambaShareData> shareList = KSambaShare::instance()->getSharesByPath(path);
if (!shareList.isEmpty()) {
return shareList.first(); // FIXME: using just the first in the list for a while
}
KSambaShareData newShare;
newShare.setName(newShareName(url));
newShare.setGuestPermission(KSambaShareData::GuestsNotAllowed);
newShare.setPath(path);
return newShare;
}
public:
// TODO shouldn't be public may need refactoring though because the ACL model needs an immutable copy
KSambaShareData m_shareData;
private:
bool m_enabled = false; // this gets cached so we can manipulate its state from qml
};
class UserPermissionModel;
class ShareContext;
class UserManager;
class PermissionsHelper;
class SambaUserSharePlugin : public KPropertiesDialogPlugin
{
......
Supports Markdown
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