Alpha 0.10.27: appoint admins in your supergroups from context menu.

This commit is contained in:
John Preston 2017-01-11 09:30:51 +04:00
parent c09dab2b3a
commit 30c9bcb985
25 changed files with 233 additions and 48 deletions

View File

@ -851,6 +851,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
"lng_context_pin_to_top" = "Pin to top"; "lng_context_pin_to_top" = "Pin to top";
"lng_context_unpin_from_top" = "Unpin from top"; "lng_context_unpin_from_top" = "Unpin from top";
"lng_context_promote_admin" = "Promote to admin";
"lng_context_remove_admin" = "Remove from admins";
"lng_context_remove_from_group" = "Remove from group";
"lng_context_copy_link" = "Copy Link"; "lng_context_copy_link" = "Copy Link";
"lng_context_copy_post_link" = "Copy Post Link"; "lng_context_copy_post_link" = "Copy Post Link";
"lng_context_copy_email" = "Copy Email Address"; "lng_context_copy_email" = "Copy Email Address";

View File

@ -851,6 +851,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
"lng_context_pin_to_top" = "Anheften"; "lng_context_pin_to_top" = "Anheften";
"lng_context_unpin_from_top" = "Entfernen"; "lng_context_unpin_from_top" = "Entfernen";
"lng_context_promote_admin" = "Zum Admin machen";
"lng_context_remove_admin" = "Als Admin entfernen";
"lng_context_remove_from_group" = "Aus Gruppe entfernen";
"lng_context_copy_link" = "Link kopieren"; "lng_context_copy_link" = "Link kopieren";
"lng_context_copy_post_link" = "Nachrichtenlink kopieren"; "lng_context_copy_post_link" = "Nachrichtenlink kopieren";
"lng_context_copy_email" = "E-Mail-Adresse kopieren"; "lng_context_copy_email" = "E-Mail-Adresse kopieren";

View File

@ -851,8 +851,12 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
"lng_context_pin_to_top" = "Anclar"; "lng_context_pin_to_top" = "Anclar";
"lng_context_unpin_from_top" = "Desanclar"; "lng_context_unpin_from_top" = "Desanclar";
"lng_context_promote_admin" = "Nombrar administrador";
"lng_context_remove_admin" = "Eliminar de los administradores";
"lng_context_remove_from_group" = "Eliminar del grupo";
"lng_context_copy_link" = "Copiar enlace"; "lng_context_copy_link" = "Copiar enlace";
"lng_context_copy_post_link" = "Copiar enlace"; "lng_context_copy_post_link" = "Copiar enlace de la publicación";
"lng_context_copy_email" = "Copiar e-mail"; "lng_context_copy_email" = "Copiar e-mail";
"lng_context_copy_hashtag" = "Copiar hashtag"; "lng_context_copy_hashtag" = "Copiar hashtag";
"lng_context_copy_mention" = "Copiar alias"; "lng_context_copy_mention" = "Copiar alias";
@ -919,7 +923,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
"lng_reply_cant_forward" = "Lo sentimos, no puedes responder un mensaje viejo en un supergrupo :( ¿Quieres reenviarlo y añadir un comentario?"; "lng_reply_cant_forward" = "Lo sentimos, no puedes responder un mensaje viejo en un supergrupo :( ¿Quieres reenviarlo y añadir un comentario?";
"lng_share_title" = "Compartir con"; "lng_share_title" = "Compartir con";
"lng_share_copy_link" = "Copiar enlace"; "lng_share_copy_link" = "Copiar enlace para compartir";
"lng_share_confirm" = "Enviar"; "lng_share_confirm" = "Enviar";
"lng_share_wrong_user" = "Este juego fue abierto por un usuario diferente."; "lng_share_wrong_user" = "Este juego fue abierto por un usuario diferente.";
"lng_share_game_link_copied" = "Enlace del juego copiado al portapapeles."; "lng_share_game_link_copied" = "Enlace del juego copiado al portapapeles.";

View File

@ -33,7 +33,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
"lng_open_from_tray" = "Apri Telegram"; "lng_open_from_tray" = "Apri Telegram";
"lng_minimize_to_tray" = "Riduci a icona"; "lng_minimize_to_tray" = "Riduci a icona";
"lng_quit_from_tray" = "Chiudi Telegram"; "lng_quit_from_tray" = "Chiudi Telegram";
"lng_tray_icon_text" = "Telegram è ancora attivo qui,\npuoi cambiarlo nelle impostazioni.\nSe l'icona scompare dall'area di notifica,\npuoi ripristinarla dalle icone nascoste."; "lng_tray_icon_text" = "Telegram è ancora attivo qui,\npuoi cambiarlo nelle impostazioni.\nSe l'icona di notifica scompare,\npuoi ripristinarla dalle icone nascoste.";
"lng_month1" = "Gennaio"; "lng_month1" = "Gennaio";
"lng_month2" = "Febbraio"; "lng_month2" = "Febbraio";
@ -851,6 +851,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
"lng_context_pin_to_top" = "Fissa in alto"; "lng_context_pin_to_top" = "Fissa in alto";
"lng_context_unpin_from_top" = "Togli dall'alto"; "lng_context_unpin_from_top" = "Togli dall'alto";
"lng_context_promote_admin" = "Rendi amministratore";
"lng_context_remove_admin" = "Rimuovi dagli amministratori";
"lng_context_remove_from_group" = "Rimuovi dal gruppo";
"lng_context_copy_link" = "Copia link"; "lng_context_copy_link" = "Copia link";
"lng_context_copy_post_link" = "Copia link post"; "lng_context_copy_post_link" = "Copia link post";
"lng_context_copy_email" = "Copia indirizzo email"; "lng_context_copy_email" = "Copia indirizzo email";

View File

@ -851,6 +851,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
"lng_context_pin_to_top" = "상단에 고정"; "lng_context_pin_to_top" = "상단에 고정";
"lng_context_unpin_from_top" = "상단에서 고정해제"; "lng_context_unpin_from_top" = "상단에서 고정해제";
"lng_context_promote_admin" = "관리자로 지정";
"lng_context_remove_admin" = "관리자에서 제외";
"lng_context_remove_from_group" = "그룹에서 추방";
"lng_context_copy_link" = "링크 복사"; "lng_context_copy_link" = "링크 복사";
"lng_context_copy_post_link" = "메시지 링크 복사"; "lng_context_copy_post_link" = "메시지 링크 복사";
"lng_context_copy_email" = "이메일 복사"; "lng_context_copy_email" = "이메일 복사";

View File

@ -851,6 +851,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
"lng_context_pin_to_top" = "Vastzetten"; "lng_context_pin_to_top" = "Vastzetten";
"lng_context_unpin_from_top" = "Losmaken"; "lng_context_unpin_from_top" = "Losmaken";
"lng_context_promote_admin" = "Beheerder maken";
"lng_context_remove_admin" = "Ontslaan als beheerder";
"lng_context_remove_from_group" = "Uit de groep verwijderen";
"lng_context_copy_link" = "Link kopiëren"; "lng_context_copy_link" = "Link kopiëren";
"lng_context_copy_post_link" = "Berichtlink kopiëren"; "lng_context_copy_post_link" = "Berichtlink kopiëren";
"lng_context_copy_email" = "E-mailadres kopiëren"; "lng_context_copy_email" = "E-mailadres kopiëren";

View File

@ -851,6 +851,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
"lng_context_pin_to_top" = "Fixar no topo"; "lng_context_pin_to_top" = "Fixar no topo";
"lng_context_unpin_from_top" = "Desafixar do topo"; "lng_context_unpin_from_top" = "Desafixar do topo";
"lng_context_promote_admin" = "Promover a administrador";
"lng_context_remove_admin" = "Remover dos administradores";
"lng_context_remove_from_group" = "Remover do grupo";
"lng_context_copy_link" = "Copiar Link"; "lng_context_copy_link" = "Copiar Link";
"lng_context_copy_post_link" = "Copiar Link do Post"; "lng_context_copy_post_link" = "Copiar Link do Post";
"lng_context_copy_email" = "Copiar Endereço de Email"; "lng_context_copy_email" = "Copiar Endereço de Email";

View File

@ -34,8 +34,8 @@ IDI_ICON1 ICON "..\\art\\icon256.ico"
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,10,26,0 FILEVERSION 0,10,27,0
PRODUCTVERSION 0,10,26,0 PRODUCTVERSION 0,10,27,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -51,10 +51,10 @@ BEGIN
BLOCK "040904b0" BLOCK "040904b0"
BEGIN BEGIN
VALUE "CompanyName", "Telegram Messenger LLP" VALUE "CompanyName", "Telegram Messenger LLP"
VALUE "FileVersion", "0.10.26.0" VALUE "FileVersion", "0.10.27.0"
VALUE "LegalCopyright", "Copyright (C) 2014-2016" VALUE "LegalCopyright", "Copyright (C) 2014-2016"
VALUE "ProductName", "Telegram Desktop" VALUE "ProductName", "Telegram Desktop"
VALUE "ProductVersion", "0.10.26.0" VALUE "ProductVersion", "0.10.27.0"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View File

@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,10,26,0 FILEVERSION 0,10,27,0
PRODUCTVERSION 0,10,26,0 PRODUCTVERSION 0,10,27,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -43,10 +43,10 @@ BEGIN
BEGIN BEGIN
VALUE "CompanyName", "Telegram Messenger LLP" VALUE "CompanyName", "Telegram Messenger LLP"
VALUE "FileDescription", "Telegram Updater" VALUE "FileDescription", "Telegram Updater"
VALUE "FileVersion", "0.10.26.0" VALUE "FileVersion", "0.10.27.0"
VALUE "LegalCopyright", "Copyright (C) 2014-2016" VALUE "LegalCopyright", "Copyright (C) 2014-2016"
VALUE "ProductName", "Telegram Desktop" VALUE "ProductName", "Telegram Desktop"
VALUE "ProductVersion", "0.10.26.0" VALUE "ProductVersion", "0.10.27.0"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View File

@ -1069,8 +1069,8 @@ void AppClass::checkMapVersion() {
if (Local::oldMapVersion() < AppVersion) { if (Local::oldMapVersion() < AppVersion) {
if (Local::oldMapVersion()) { if (Local::oldMapVersion()) {
QString versionFeatures; QString versionFeatures;
if ((cAlphaVersion() || cBetaVersion()) && Local::oldMapVersion() < 10026) { if ((cAlphaVersion() || cBetaVersion()) && Local::oldMapVersion() < 10027) {
versionFeatures = QString::fromUtf8("\xe2\x80\x94 You can use t.me instead of telegram.me\n\xe2\x80\x94 OpenAL updated to the latest version\n\xe2\x80\x94 Bug fixes and other minor improvements"); versionFeatures = QString::fromUtf8("\xe2\x80\x94 Appoint admins in your supergroups from members list context menu\n\xe2\x80\x94 Bug fixes and other minor improvements");
} else if (!(cAlphaVersion() || cBetaVersion()) && Local::oldMapVersion() < 10018) { } else if (!(cAlphaVersion() || cBetaVersion()) && Local::oldMapVersion() < 10018) {
versionFeatures = langNewVersionText(); versionFeatures = langNewVersionText();
} else { } else {

View File

@ -24,7 +24,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#define BETA_VERSION_MACRO (0ULL) #define BETA_VERSION_MACRO (0ULL)
constexpr int AppVersion = 10026; constexpr int AppVersion = 10027;
constexpr str_const AppVersionStr = "0.10.26"; constexpr str_const AppVersionStr = "0.10.27";
constexpr bool AppAlphaVersion = true; constexpr bool AppAlphaVersion = true;
constexpr uint64 AppBetaVersion = BETA_VERSION_MACRO; constexpr uint64 AppBetaVersion = BETA_VERSION_MACRO;

View File

@ -863,7 +863,7 @@ void DialogsInner::contextMenuEvent(QContextMenuEvent *e) {
mousePressReleased(_pressButton); mousePressReleased(_pressButton);
} }
_menu = new Ui::PopupMenu(); _menu = new Ui::PopupMenu(nullptr);
App::main()->fillPeerMenu(_menuPeer, [this](const QString &text, base::lambda<void()> &&callback) { App::main()->fillPeerMenu(_menuPeer, [this](const QString &text, base::lambda<void()> &&callback) {
return _menu->addAction(text, std_::move(callback)); return _menu->addAction(text, std_::move(callback));
}, true); }, true);

View File

@ -1229,7 +1229,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
isUponSelected = hasSelected; isUponSelected = hasSelected;
} }
_menu = new Ui::PopupMenu(); _menu = new Ui::PopupMenu(nullptr);
_contextMenuLnk = ClickHandler::getActive(); _contextMenuLnk = ClickHandler::getActive();
HistoryItem *item = App::hoveredItem() ? App::hoveredItem() : App::hoveredLinkItem(); HistoryItem *item = App::hoveredItem() ? App::hoveredItem() : App::hoveredLinkItem();
@ -2988,6 +2988,7 @@ void SilentToggle::setChecked(bool checked) {
} }
void SilentToggle::leaveEvent(QEvent *e) { void SilentToggle::leaveEvent(QEvent *e) {
IconButton::leaveEvent(e);
Ui::Tooltip::Hide(); Ui::Tooltip::Hide();
} }

View File

@ -177,7 +177,7 @@ void MainWindow::onWindowActiveChanged() {
void MainWindow::firstShow() { void MainWindow::firstShow() {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
trayIconMenu = new Ui::PopupMenu(); trayIconMenu = new Ui::PopupMenu(nullptr);
trayIconMenu->deleteOnHide(false); trayIconMenu->deleteOnHide(false);
#else // Q_OS_WIN #else // Q_OS_WIN
trayIconMenu = new QMenu(this); trayIconMenu = new QMenu(this);

View File

@ -2534,7 +2534,7 @@ void MediaView::contextMenuEvent(QContextMenuEvent *e) {
_menu->deleteLater(); _menu->deleteLater();
_menu = 0; _menu = 0;
} }
_menu = new Ui::PopupMenu(st::mediaviewPopupMenu); _menu = new Ui::PopupMenu(nullptr, st::mediaviewPopupMenu);
updateActions(); updateActions();
for_const (auto &action, _actions) { for_const (auto &action, _actions) {
_menu->addAction(action.text, this, action.member)->setEnabled(true); _menu->addAction(action.text, this, action.member)->setEnabled(true);

View File

@ -1205,7 +1205,7 @@ void OverviewInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
bool lnkIsAudio = lnkDocument ? (lnkDocument->document()->voice() != nullptr) : false; bool lnkIsAudio = lnkDocument ? (lnkDocument->document()->voice() != nullptr) : false;
bool lnkIsSong = lnkDocument ? (lnkDocument->document()->song() != nullptr) : false; bool lnkIsSong = lnkDocument ? (lnkDocument->document()->song() != nullptr) : false;
if (lnkPhoto || lnkDocument) { if (lnkPhoto || lnkDocument) {
_menu = new Ui::PopupMenu(); _menu = new Ui::PopupMenu(nullptr);
if (App::hoveredLinkItem()) { if (App::hoveredLinkItem()) {
_menu->addAction(lang(lng_context_to_msg), this, SLOT(goToMessage()))->setEnabled(true); _menu->addAction(lang(lng_context_to_msg), this, SLOT(goToMessage()))->setEnabled(true);
} }
@ -1251,7 +1251,7 @@ void OverviewInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
repaintItem(App::contextItem()); repaintItem(App::contextItem());
if (_selectedMsgId) repaintItem(_selectedMsgId, -1); if (_selectedMsgId) repaintItem(_selectedMsgId, -1);
} else if (!ignoreMousedItem && App::mousedItem() && App::mousedItem()->channelId() == itemChannel(_mousedItem) && App::mousedItem()->id == itemMsgId(_mousedItem)) { } else if (!ignoreMousedItem && App::mousedItem() && App::mousedItem()->channelId() == itemChannel(_mousedItem) && App::mousedItem()->id == itemMsgId(_mousedItem)) {
_menu = new Ui::PopupMenu(); _menu = new Ui::PopupMenu(nullptr);
QString linkCopyToClipboardText = _contextMenuLnk ? _contextMenuLnk->copyToClipboardContextItemText() : QString(); QString linkCopyToClipboardText = _contextMenuLnk ? _contextMenuLnk->copyToClipboardContextItemText() : QString();
if (!linkCopyToClipboardText.isEmpty()) { if (!linkCopyToClipboardText.isEmpty()) {
_menu->addAction(linkCopyToClipboardText, this, SLOT(copyContextUrl()))->setEnabled(true); _menu->addAction(linkCopyToClipboardText, this, SLOT(copyContextUrl()))->setEnabled(true);

View File

@ -24,6 +24,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "styles/style_profile.h" #include "styles/style_profile.h"
#include "ui/widgets/labels.h" #include "ui/widgets/labels.h"
#include "boxes/confirmbox.h" #include "boxes/confirmbox.h"
#include "ui/widgets/popup_menu.h"
#include "mainwidget.h" #include "mainwidget.h"
#include "apiwrap.h" #include "apiwrap.h"
#include "observer_peer.h" #include "observer_peer.h"
@ -50,16 +51,7 @@ GroupMembersWidget::GroupMembersWidget(QWidget *parent, PeerData *peer, TitleVis
})); }));
setRemovedCallback([this, peer](PeerData *selectedPeer) { setRemovedCallback([this, peer](PeerData *selectedPeer) {
auto user = selectedPeer->asUser(); removePeer(selectedPeer);
auto text = lng_profile_sure_kick(lt_user, user->firstName);
Ui::show(Box<ConfirmBox>(text, lang(lng_box_remove), base::lambda_guarded(this, [peer, user] {
Ui::hideLayer();
if (auto chat = peer->asChat()) {
if (App::main()) App::main()->kickParticipant(chat, user);
} else if (auto channel = peer->asChannel()) {
if (App::api()) App::api()->kickParticipant(channel, user);
}
})));
}); });
setSelectedCallback([this](PeerData *selectedPeer) { setSelectedCallback([this](PeerData *selectedPeer) {
Ui::showPeerProfile(selectedPeer); Ui::showPeerProfile(selectedPeer);
@ -74,6 +66,59 @@ GroupMembersWidget::GroupMembersWidget(QWidget *parent, PeerData *peer, TitleVis
refreshMembers(); refreshMembers();
} }
void GroupMembersWidget::addAdmin(PeerData *selectedPeer) {
auto user = selectedPeer->asUser();
auto text = lng_channel_admin_sure(lt_user, user->firstName);
Ui::show(Box<ConfirmBox>(text, base::lambda_guarded(this, [this, user] {
Ui::hideLayer();
if (auto chat = peer()->asChat()) {
// not supported
} else if (auto channel = peer()->asMegagroup()) {
MTP::send(MTPchannels_EditAdmin(channel->inputChannel, user->inputUser, MTP_channelRoleEditor()), rpcDone(base::lambda_guarded(this, [this, channel, user](const MTPUpdates &result) {
if (App::main()) App::main()->sentUpdatesReceived(result);
channel->mgInfo->lastAdmins.insert(user);
channel->setAdminsCount(channel->adminsCount() + 1);
if (App::main()) emit App::main()->peerUpdated(channel);
Notify::peerUpdatedDelayed(channel, Notify::PeerUpdate::Flag::AdminsChanged);
})));
}
})));
}
void GroupMembersWidget::removeAdmin(PeerData *selectedPeer) {
auto user = selectedPeer->asUser();
auto text = lng_profile_sure_kick_admin(lt_user, user->firstName);
Ui::show(Box<ConfirmBox>(text, lang(lng_box_remove), base::lambda_guarded(this, [this, user] {
Ui::hideLayer();
if (auto chat = peer()->asChat()) {
// not supported
} else if (auto channel = peer()->asMegagroup()) {
MTP::send(MTPchannels_EditAdmin(channel->inputChannel, user->inputUser, MTP_channelRoleEmpty()), rpcDone(base::lambda_guarded(this, [this, channel, user](const MTPUpdates &result) {
if (App::main()) App::main()->sentUpdatesReceived(result);
channel->mgInfo->lastAdmins.remove(user);
if (channel->adminsCount() > 1) {
channel->setAdminsCount(channel->adminsCount() - 1);
if (App::main()) emit App::main()->peerUpdated(channel);
}
Notify::peerUpdatedDelayed(channel, Notify::PeerUpdate::Flag::AdminsChanged);
})));
}
})));
}
void GroupMembersWidget::removePeer(PeerData *selectedPeer) {
auto user = selectedPeer->asUser();
auto text = lng_profile_sure_kick(lt_user, user->firstName);
Ui::show(Box<ConfirmBox>(text, lang(lng_box_remove), base::lambda_guarded(this, [user, peer = peer()] {
Ui::hideLayer();
if (auto chat = peer->asChat()) {
if (App::main()) App::main()->kickParticipant(chat, user);
} else if (auto channel = peer->asChannel()) {
if (App::api()) App::api()->kickParticipant(channel, user);
}
})));
}
void GroupMembersWidget::notifyPeerUpdated(const Notify::PeerUpdate &update) { void GroupMembersWidget::notifyPeerUpdated(const Notify::PeerUpdate &update) {
if (update.peer != peer()) { if (update.peer != peer()) {
if (update.flags & UpdateFlag::UserOnlineChanged) { if (update.flags & UpdateFlag::UserOnlineChanged) {
@ -152,6 +197,49 @@ void GroupMembersWidget::paintContents(Painter &p) {
PeerListWidget::paintContents(p); PeerListWidget::paintContents(p);
} }
Ui::PopupMenu *GroupMembersWidget::fillPeerMenu(PeerData *selectedPeer) {
if (emptyTitle()) {
return nullptr;
}
auto result = new Ui::PopupMenu(nullptr);
result->addAction(lang(lng_context_view_profile), [selectedPeer] {
Ui::showPeerProfile(selectedPeer);
});
auto chat = peer()->asChat();
auto channel = peer()->asMegagroup();
for_const (auto item, items()) {
if (item->peer == selectedPeer) {
auto canRemoveAdmin = [item, chat, channel] {
if (item->hasAdminStar && !item->peer->isSelf()) {
if (chat) {
// Adding of admins from context menu of chat participants
// is not supported, so the removing is also disabled.
return false;//chat->amCreator();
} else if (channel) {
return channel->amCreator();
}
}
return false;
};
if (channel && channel->amCreator() && !item->hasAdminStar) {
result->addAction(lang(lng_context_promote_admin), base::lambda_guarded(this, [this, selectedPeer] {
addAdmin(selectedPeer);
}));
} else if (canRemoveAdmin()) {
result->addAction(lang(lng_context_remove_admin), base::lambda_guarded(this, [this, selectedPeer] {
removeAdmin(selectedPeer);
}));
}
if (item->hasRemoveLink) {
result->addAction(lang(lng_context_remove_from_group), base::lambda_guarded(this, [this, selectedPeer] {
removePeer(selectedPeer);
}));
}
}
}
return result;
}
void GroupMembersWidget::updateItemStatusText(Item *item) { void GroupMembersWidget::updateItemStatusText(Item *item) {
auto member = getMember(item); auto member = getMember(item);
auto user = member->user(); auto user = member->user();

View File

@ -55,6 +55,8 @@ protected:
void paintContents(Painter &p) override; void paintContents(Painter &p) override;
Ui::PopupMenu *fillPeerMenu(PeerData *peer) override;
signals: signals:
void onlineCountUpdated(int onlineCount); void onlineCountUpdated(int onlineCount);
@ -65,6 +67,9 @@ private:
// Observed notifications. // Observed notifications.
void notifyPeerUpdated(const Notify::PeerUpdate &update); void notifyPeerUpdated(const Notify::PeerUpdate &update);
void addAdmin(PeerData *selectedPeer);
void removeAdmin(PeerData *selectedPeer);
void removePeer(PeerData *selectedPeer);
void refreshMembers(); void refreshMembers();
void fillChatMembers(ChatData *chat); void fillChatMembers(ChatData *chat);
void fillMegagroupMembers(ChannelData *megagroup); void fillMegagroupMembers(ChannelData *megagroup);

View File

@ -22,6 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "profile/profile_block_peer_list.h" #include "profile/profile_block_peer_list.h"
#include "ui/effects/ripple_animation.h" #include "ui/effects/ripple_animation.h"
#include "ui/widgets/popup_menu.h"
#include "styles/style_profile.h" #include "styles/style_profile.h"
#include "styles/style_widgets.h" #include "styles/style_widgets.h"
@ -70,7 +71,7 @@ void PeerListWidget::paintContents(Painter &p) {
auto to = ceilclamp(_visibleBottom - top, st::profileMemberHeight, 0, _items.size()); auto to = ceilclamp(_visibleBottom - top, st::profileMemberHeight, 0, _items.size());
for (auto i = from; i < to; ++i) { for (auto i = from; i < to; ++i) {
auto y = top + i * st::profileMemberHeight; auto y = top + i * st::profileMemberHeight;
auto selected = (_pressed >= 0) ? (i == _pressed) : (i == _selected); auto selected = (_menuRowIndex >= 0) ? (i == _menuRowIndex) : (_pressed >= 0) ? (i == _pressed) : (i == _selected);
auto selectedRemove = selected && _selectedRemove; auto selectedRemove = selected && _selectedRemove;
if (_pressed >= 0 && !_pressedRemove) { if (_pressed >= 0 && !_pressedRemove) {
selectedRemove = false; selectedRemove = false;
@ -144,6 +145,7 @@ void PeerListWidget::mousePressEvent(QMouseEvent *e) {
_mousePosition = e->globalPos(); _mousePosition = e->globalPos();
updateSelection(); updateSelection();
_pressButton = e->button();
_pressed = _selected; _pressed = _selected;
_pressedRemove = _selectedRemove; _pressedRemove = _selectedRemove;
if (_pressed >= 0 && !_pressedRemove) { if (_pressed >= 0 && !_pressedRemove) {
@ -162,9 +164,10 @@ void PeerListWidget::mousePressEvent(QMouseEvent *e) {
} }
void PeerListWidget::mouseReleaseEvent(QMouseEvent *e) { void PeerListWidget::mouseReleaseEvent(QMouseEvent *e) {
_mousePosition = e->globalPos(); mousePressReleased(e->button());
updateSelection(); }
void PeerListWidget::mousePressReleased(Qt::MouseButton button) {
repaintRow(_pressed); repaintRow(_pressed);
auto pressed = base::take(_pressed, -1); auto pressed = base::take(_pressed, -1);
auto pressedRemove = base::take(_pressedRemove); auto pressedRemove = base::take(_pressedRemove);
@ -172,7 +175,7 @@ void PeerListWidget::mouseReleaseEvent(QMouseEvent *e) {
if (auto &ripple = _items[pressed]->ripple) { if (auto &ripple = _items[pressed]->ripple) {
ripple->lastStop(); ripple->lastStop();
} }
if (pressed == _selected && pressedRemove == _selectedRemove) { if (pressed == _selected && pressedRemove == _selectedRemove && button == Qt::LeftButton) {
if (auto &callback = (pressedRemove ? _removedCallback : _selectedCallback)) { if (auto &callback = (pressedRemove ? _removedCallback : _selectedCallback)) {
callback(_items[pressed]->peer); callback(_items[pressed]->peer);
} }
@ -182,6 +185,46 @@ void PeerListWidget::mouseReleaseEvent(QMouseEvent *e) {
repaintSelectedRow(); repaintSelectedRow();
} }
void PeerListWidget::contextMenuEvent(QContextMenuEvent *e) {
if (_menu) {
_menu->deleteLater();
_menu = nullptr;
}
if (_menuRowIndex >= 0) {
repaintRow(_menuRowIndex);
_menuRowIndex = -1;
}
if (e->reason() == QContextMenuEvent::Mouse) {
_mousePosition = e->globalPos();
updateSelection();
}
_menuRowIndex = _selected;
if (_pressButton != Qt::LeftButton) {
mousePressReleased(_pressButton);
}
if (_selected < 0 || _selected >= _items.size()) {
return;
}
_menu = fillPeerMenu(_items[_selected]->peer);
if (_menu) {
_menu->setDestroyedCallback(base::lambda_guarded(this, [this, menu = _menu] {
if (_menu == menu) {
_menu = nullptr;
}
repaintRow(_menuRowIndex);
_menuRowIndex = -1;
_mousePosition = QCursor::pos();
updateSelection();
}));
_menu->popup(e->globalPos());
e->accept();
}
}
void PeerListWidget::enterEvent(QEvent *e) { void PeerListWidget::enterEvent(QEvent *e) {
_mousePosition = QCursor::pos(); _mousePosition = QCursor::pos();
updateSelection(); updateSelection();

View File

@ -25,6 +25,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
namespace Ui { namespace Ui {
class RippleAnimation; class RippleAnimation;
class PopupMenu;
} // namespace Ui } // namespace Ui
namespace Notify { namespace Notify {
@ -105,6 +106,7 @@ protected:
void mouseMoveEvent(QMouseEvent *e) override; void mouseMoveEvent(QMouseEvent *e) override;
void mousePressEvent(QMouseEvent *e) override; void mousePressEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override; void mouseReleaseEvent(QMouseEvent *e) override;
void contextMenuEvent(QContextMenuEvent *e) override;
void enterEvent(QEvent *e) override; void enterEvent(QEvent *e) override;
void enterFromChildEvent(QEvent *e, QWidget *child) override { void enterFromChildEvent(QEvent *e, QWidget *child) override {
enterEvent(e); enterEvent(e);
@ -114,7 +116,12 @@ protected:
leaveEvent(e); leaveEvent(e);
} }
virtual Ui::PopupMenu *fillPeerMenu(PeerData *peer) {
return nullptr;
}
private: private:
void mousePressReleased(Qt::MouseButton button);
void updateSelection(); void updateSelection();
void setSelected(int selected, bool selectedRemove); void setSelected(int selected, bool selectedRemove);
void repaintSelectedRow(); void repaintSelectedRow();
@ -138,6 +145,7 @@ private:
int _selected = -1; int _selected = -1;
int _pressed = -1; int _pressed = -1;
Qt::MouseButton _pressButton = Qt::LeftButton;
bool _selectedRemove = false; bool _selectedRemove = false;
bool _pressedRemove = false; bool _pressedRemove = false;
QPoint _mousePosition; QPoint _mousePosition;
@ -145,6 +153,9 @@ private:
QString _removeText; QString _removeText;
int _removeWidth = 0; int _removeWidth = 0;
Ui::PopupMenu *_menu = nullptr;
int _menuRowIndex = -1;
}; };
} // namespace Profile } // namespace Profile

View File

@ -1452,7 +1452,7 @@ void FlatTextarea::dropEvent(QDropEvent *e) {
void FlatTextarea::contextMenuEvent(QContextMenuEvent *e) { void FlatTextarea::contextMenuEvent(QContextMenuEvent *e) {
if (auto menu = createStandardContextMenu()) { if (auto menu = createStandardContextMenu()) {
(new Ui::PopupMenu(menu))->popup(e->globalPos()); (new Ui::PopupMenu(nullptr, menu))->popup(e->globalPos());
} }
} }
@ -1620,7 +1620,7 @@ void FlatInput::updatePlaceholderText() {
void FlatInput::contextMenuEvent(QContextMenuEvent *e) { void FlatInput::contextMenuEvent(QContextMenuEvent *e) {
if (auto menu = createStandardContextMenu()) { if (auto menu = createStandardContextMenu()) {
(new Ui::PopupMenu(menu))->popup(e->globalPos()); (new Ui::PopupMenu(nullptr, menu))->popup(e->globalPos());
} }
} }
@ -2409,7 +2409,7 @@ void InputArea::Inner::keyPressEvent(QKeyEvent *e) {
void InputArea::Inner::contextMenuEvent(QContextMenuEvent *e) { void InputArea::Inner::contextMenuEvent(QContextMenuEvent *e) {
if (auto menu = createStandardContextMenu()) { if (auto menu = createStandardContextMenu()) {
(new Ui::PopupMenu(menu))->popup(e->globalPos()); (new Ui::PopupMenu(nullptr, menu))->popup(e->globalPos());
} }
} }
@ -3170,7 +3170,7 @@ void InputField::Inner::keyPressEvent(QKeyEvent *e) {
void InputField::Inner::contextMenuEvent(QContextMenuEvent *e) { void InputField::Inner::contextMenuEvent(QContextMenuEvent *e) {
if (auto menu = createStandardContextMenu()) { if (auto menu = createStandardContextMenu()) {
(new Ui::PopupMenu(menu))->popup(e->globalPos()); (new Ui::PopupMenu(nullptr, menu))->popup(e->globalPos());
} }
} }
@ -3482,7 +3482,7 @@ void MaskedInputField::createPlaceholderPath() {
void MaskedInputField::contextMenuEvent(QContextMenuEvent *e) { void MaskedInputField::contextMenuEvent(QContextMenuEvent *e) {
if (auto menu = createStandardContextMenu()) { if (auto menu = createStandardContextMenu()) {
(new Ui::PopupMenu(menu))->popup(e->globalPos()); (new Ui::PopupMenu(nullptr, menu))->popup(e->globalPos());
} }
} }

View File

@ -496,7 +496,7 @@ void FlatLabel::showContextMenu(QContextMenuEvent *e, ContextMenuReason reason)
uponSelection = hasSelection; uponSelection = hasSelection;
} }
_contextMenu = new Ui::PopupMenu(); _contextMenu = new Ui::PopupMenu(nullptr);
_contextMenuClickHandler = ClickHandler::getActive(); _contextMenuClickHandler = ClickHandler::getActive();

View File

@ -25,13 +25,13 @@
namespace Ui { namespace Ui {
PopupMenu::PopupMenu(const style::PopupMenu &st) : TWidget(nullptr) PopupMenu::PopupMenu(QWidget*, const style::PopupMenu &st) : TWidget(nullptr)
, _st(st) , _st(st)
, _menu(this, _st.menu) { , _menu(this, _st.menu) {
init(); init();
} }
PopupMenu::PopupMenu(QMenu *menu, const style::PopupMenu &st) : TWidget(nullptr) PopupMenu::PopupMenu(QWidget*, QMenu *menu, const style::PopupMenu &st) : TWidget(nullptr)
, _st(st) , _st(st)
, _menu(this, menu, _st.menu) { , _menu(this, menu, _st.menu) {
init(); init();
@ -478,6 +478,9 @@ PopupMenu::~PopupMenu() {
w->reActivateWindow(); w->reActivateWindow();
} }
#endif #endif
if (_destroyedCallback) {
_destroyedCallback();
}
} }
} // namespace Ui } // namespace Ui

View File

@ -25,8 +25,8 @@ namespace Ui {
class PopupMenu : public TWidget { class PopupMenu : public TWidget {
public: public:
PopupMenu(const style::PopupMenu &st = st::defaultPopupMenu); PopupMenu(QWidget*, const style::PopupMenu &st = st::defaultPopupMenu);
PopupMenu(QMenu *menu, const style::PopupMenu &st = st::defaultPopupMenu); PopupMenu(QWidget*, QMenu *menu, const style::PopupMenu &st = st::defaultPopupMenu);
QAction *addAction(const QString &text, const QObject *receiver, const char* member, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr); QAction *addAction(const QString &text, const QObject *receiver, const char* member, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr);
QAction *addAction(const QString &text, base::lambda<void()> &&callback, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr); QAction *addAction(const QString &text, base::lambda<void()> &&callback, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr);
@ -40,6 +40,10 @@ public:
void popup(const QPoint &p); void popup(const QPoint &p);
void hideMenu(bool fast = false); void hideMenu(bool fast = false);
void setDestroyedCallback(base::lambda<void()> &&callback) {
_destroyedCallback = std_::move(callback);
}
~PopupMenu(); ~PopupMenu();
protected: protected:
@ -130,6 +134,8 @@ private:
bool _triggering = false; bool _triggering = false;
bool _deleteLater = false; bool _deleteLater = false;
base::lambda<void()> _destroyedCallback;
}; };
} // namespace Ui } // namespace Ui

View File

@ -1,6 +1,6 @@
AppVersion 10026 AppVersion 10027
AppVersionStrMajor 0.10 AppVersionStrMajor 0.10
AppVersionStrSmall 0.10.26 AppVersionStrSmall 0.10.27
AppVersionStr 0.10.26 AppVersionStr 0.10.27
AlphaChannel 1 AlphaChannel 1
BetaVersion 0 BetaVersion 0