tdesktop/Telegram/SourceFiles/boxes/peers/edit_participant_box.h

149 lines
3.4 KiB
C
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "boxes/abstract_box.h"
2019-01-08 10:54:18 +00:00
#include "base/unique_qptr.h"
namespace Ui {
class FlatLabel;
class LinkButton;
class Checkbox;
class Radiobutton;
class RadiobuttonGroup;
template <typename Widget>
class SlideWrap;
} // namespace Ui
class CalendarBox;
class EditParticipantBox : public BoxContent {
public:
EditParticipantBox(
QWidget*,
not_null<PeerData*> peer,
not_null<UserData*> user,
bool hasAdminRights);
protected:
void prepare() override;
not_null<UserData*> user() const {
return _user;
}
not_null<PeerData*> peer() const {
return _peer;
}
template <typename Widget>
2019-01-08 10:54:18 +00:00
Widget *addControl(object_ptr<Widget> widget, QMargins margin = {});
bool hasAdminRights() const {
return _hasAdminRights;
}
private:
not_null<PeerData*> _peer;
not_null<UserData*> _user;
bool _hasAdminRights = false;
class Inner;
QPointer<Inner> _inner;
};
class EditAdminBox : public EditParticipantBox {
public:
EditAdminBox(
QWidget*,
not_null<PeerData*> peer,
not_null<UserData*> user,
const MTPChatAdminRights &rights);
void setSaveCallback(
Fn<void(MTPChatAdminRights, MTPChatAdminRights)> callback) {
_saveCallback = std::move(callback);
}
protected:
void prepare() override;
private:
2019-01-03 14:39:19 +00:00
using Flag = MTPDchatAdminRights::Flag;
using Flags = MTPDchatAdminRights::Flags;
static MTPChatAdminRights Defaults(not_null<PeerData*> peer);
void transferOwnership();
bool handleTransferPasswordError(const RPCError &error);
void requestTransferPassword();
bool canSave() const {
return !!_saveCallback;
}
void refreshAboutAddAdminsText(bool canAddAdmins);
bool canTransferOwnership() const;
not_null<Ui::SlideWrap<Ui::RpWidget>*> setupTransferButton(bool isGroup);
2019-01-03 14:39:19 +00:00
const MTPChatAdminRights _oldRights;
Fn<void(MTPChatAdminRights, MTPChatAdminRights)> _saveCallback;
QPointer<Ui::FlatLabel> _aboutAddAdmins;
mtpRequestId _checkTransferRequestId = 0;
};
// Restricted box works with flags in the opposite way.
// If some flag is set in the rights then the checkbox is unchecked.
class EditRestrictedBox : public EditParticipantBox {
public:
EditRestrictedBox(
QWidget*,
not_null<PeerData*> peer,
not_null<UserData*> user,
bool hasAdminRights,
const MTPChatBannedRights &rights);
void setSaveCallback(
Fn<void(MTPChatBannedRights, MTPChatBannedRights)> callback) {
_saveCallback = std::move(callback);
}
protected:
void prepare() override;
private:
2019-01-03 14:39:19 +00:00
using Flag = MTPDchatBannedRights::Flag;
using Flags = MTPDchatBannedRights::Flags;
static MTPChatBannedRights Defaults(not_null<PeerData*> peer);
bool canSave() const {
return !!_saveCallback;
}
void showRestrictUntil();
void setRestrictUntil(TimeId until);
bool isUntilForever() const;
void createUntilGroup();
void createUntilVariants();
TimeId getRealUntilValue() const;
2019-01-03 14:39:19 +00:00
const MTPChatBannedRights _oldRights;
TimeId _until = 0;
2019-01-03 14:39:19 +00:00
Fn<void(MTPChatBannedRights, MTPChatBannedRights)> _saveCallback;
std::shared_ptr<Ui::RadiobuttonGroup> _untilGroup;
2019-01-08 10:54:18 +00:00
std::vector<base::unique_qptr<Ui::Radiobutton>> _untilVariants;
QPointer<CalendarBox> _restrictUntilBox;
static constexpr auto kUntilOneDay = -1;
static constexpr auto kUntilOneWeek = -2;
static constexpr auto kUntilCustom = -3;
};