mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added ability to reorder accounts in MainMenu.
This commit is contained in:
parent
5939c2dbfc
commit
a8c3d6c39b
4 changed files with 94 additions and 10 deletions
|
@ -113,7 +113,8 @@ QByteArray Settings::serialize() const {
|
||||||
+ sizeof(qint64)
|
+ sizeof(qint64)
|
||||||
+ sizeof(qint32) * 2
|
+ sizeof(qint32) * 2
|
||||||
+ Serialize::bytearraySize(windowPosition)
|
+ Serialize::bytearraySize(windowPosition)
|
||||||
+ sizeof(qint32);
|
+ sizeof(qint32) * 2
|
||||||
|
+ (_accountsOrder.size() * sizeof(quint64));
|
||||||
for (const auto &[id, rating] : recentEmojiPreloadData) {
|
for (const auto &[id, rating] : recentEmojiPreloadData) {
|
||||||
size += Serialize::stringSize(id) + sizeof(quint16);
|
size += Serialize::stringSize(id) + sizeof(quint16);
|
||||||
}
|
}
|
||||||
|
@ -229,6 +230,12 @@ QByteArray Settings::serialize() const {
|
||||||
<< qint32(_playerRepeatMode.current())
|
<< qint32(_playerRepeatMode.current())
|
||||||
<< qint32(_playerOrderMode.current())
|
<< qint32(_playerOrderMode.current())
|
||||||
<< qint32(_macWarnBeforeQuit ? 1 : 0);
|
<< qint32(_macWarnBeforeQuit ? 1 : 0);
|
||||||
|
|
||||||
|
stream
|
||||||
|
<< qint32(_accountsOrder.size());
|
||||||
|
for (const auto &id : _accountsOrder) {
|
||||||
|
stream << quint64(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -316,6 +323,8 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
||||||
qint32 playerRepeatMode = static_cast<qint32>(_playerRepeatMode.current());
|
qint32 playerRepeatMode = static_cast<qint32>(_playerRepeatMode.current());
|
||||||
qint32 playerOrderMode = static_cast<qint32>(_playerOrderMode.current());
|
qint32 playerOrderMode = static_cast<qint32>(_playerOrderMode.current());
|
||||||
qint32 macWarnBeforeQuit = _macWarnBeforeQuit ? 1 : 0;
|
qint32 macWarnBeforeQuit = _macWarnBeforeQuit ? 1 : 0;
|
||||||
|
qint32 accountsOrderCount = 0;
|
||||||
|
std::vector<uint64> accountsOrder;
|
||||||
|
|
||||||
stream >> themesAccentColors;
|
stream >> themesAccentColors;
|
||||||
if (!stream.atEnd()) {
|
if (!stream.atEnd()) {
|
||||||
|
@ -487,6 +496,16 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
||||||
if (!stream.atEnd()) {
|
if (!stream.atEnd()) {
|
||||||
stream >> macWarnBeforeQuit;
|
stream >> macWarnBeforeQuit;
|
||||||
}
|
}
|
||||||
|
if (!stream.atEnd()) {
|
||||||
|
stream >> accountsOrderCount;
|
||||||
|
if (stream.status() == QDataStream::Ok) {
|
||||||
|
for (auto i = 0; i != accountsOrderCount; ++i) {
|
||||||
|
quint64 sessionUniqueId;
|
||||||
|
stream >> sessionUniqueId;
|
||||||
|
accountsOrder.emplace_back(sessionUniqueId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (stream.status() != QDataStream::Ok) {
|
if (stream.status() != QDataStream::Ok) {
|
||||||
LOG(("App Error: "
|
LOG(("App Error: "
|
||||||
"Bad data for Core::Settings::constructFromSerialized()"));
|
"Bad data for Core::Settings::constructFromSerialized()"));
|
||||||
|
@ -629,6 +648,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
||||||
_photoEditorBrush = photoEditorBrush;
|
_photoEditorBrush = photoEditorBrush;
|
||||||
_closeToTaskbar = (closeToTaskbar == 1);
|
_closeToTaskbar = (closeToTaskbar == 1);
|
||||||
_customDeviceModel = customDeviceModel;
|
_customDeviceModel = customDeviceModel;
|
||||||
|
_accountsOrder = accountsOrder;
|
||||||
const auto uncheckedPlayerRepeatMode = static_cast<Media::Player::RepeatMode>(playerRepeatMode);
|
const auto uncheckedPlayerRepeatMode = static_cast<Media::Player::RepeatMode>(playerRepeatMode);
|
||||||
switch (uncheckedPlayerRepeatMode) {
|
switch (uncheckedPlayerRepeatMode) {
|
||||||
case Media::Player::RepeatMode::None:
|
case Media::Player::RepeatMode::None:
|
||||||
|
@ -922,6 +942,8 @@ void Settings::resetOnLastLogout() {
|
||||||
_emojiVariants.clear();
|
_emojiVariants.clear();
|
||||||
|
|
||||||
_workMode = WorkMode::WindowAndTray;
|
_workMode = WorkMode::WindowAndTray;
|
||||||
|
|
||||||
|
_accountsOrder.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Settings::ThirdColumnByDefault() {
|
bool Settings::ThirdColumnByDefault() {
|
||||||
|
|
|
@ -656,6 +656,12 @@ public:
|
||||||
[[nodiscard]] rpl::producer<Media::Player::OrderMode> playerOrderModeChanges() const {
|
[[nodiscard]] rpl::producer<Media::Player::OrderMode> playerOrderModeChanges() const {
|
||||||
return _playerOrderMode.changes();
|
return _playerOrderMode.changes();
|
||||||
}
|
}
|
||||||
|
[[nodiscard]] std::vector<uint64> accountsOrder() const {
|
||||||
|
return _accountsOrder;
|
||||||
|
}
|
||||||
|
void setAccountsOrder(const std::vector<uint64> &order) {
|
||||||
|
_accountsOrder = order;
|
||||||
|
}
|
||||||
|
|
||||||
void setMacWarnBeforeQuit(bool value) {
|
void setMacWarnBeforeQuit(bool value) {
|
||||||
_macWarnBeforeQuit = value;
|
_macWarnBeforeQuit = value;
|
||||||
|
@ -768,6 +774,7 @@ private:
|
||||||
rpl::variable<Media::Player::RepeatMode> _playerRepeatMode;
|
rpl::variable<Media::Player::RepeatMode> _playerRepeatMode;
|
||||||
rpl::variable<Media::Player::OrderMode> _playerOrderMode;
|
rpl::variable<Media::Player::OrderMode> _playerOrderMode;
|
||||||
bool _macWarnBeforeQuit = true;
|
bool _macWarnBeforeQuit = true;
|
||||||
|
std::vector<uint64> _accountsOrder;
|
||||||
|
|
||||||
bool _tabbedReplacedWithInfo = false; // per-window
|
bool _tabbedReplacedWithInfo = false; // per-window
|
||||||
rpl::event_stream<bool> _tabbedReplacedWithInfoValue; // per-window
|
rpl::event_stream<bool> _tabbedReplacedWithInfoValue; // per-window
|
||||||
|
|
|
@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/widgets/shadow.h"
|
#include "ui/widgets/shadow.h"
|
||||||
#include "ui/wrap/slide_wrap.h"
|
#include "ui/wrap/slide_wrap.h"
|
||||||
#include "ui/wrap/vertical_layout.h"
|
#include "ui/wrap/vertical_layout.h"
|
||||||
|
#include "ui/wrap/vertical_layout_reorder.h"
|
||||||
#include "ui/text/format_values.h" // Ui::FormatPhone
|
#include "ui/text/format_values.h" // Ui::FormatPhone
|
||||||
#include "ui/text/text_utilities.h"
|
#include "ui/text/text_utilities.h"
|
||||||
#include "ui/special_buttons.h"
|
#include "ui/special_buttons.h"
|
||||||
|
@ -140,6 +141,27 @@ void ShowCallsBox(not_null<Window::SessionController*> window) {
|
||||||
window->show(Box<PeerListBox>(std::move(controller), initBox));
|
window->show(Box<PeerListBox>(std::move(controller), initBox));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] std::vector<not_null<Main::Account*>> OrderedAccounts() {
|
||||||
|
const auto order = Core::App().settings().accountsOrder();
|
||||||
|
auto accounts = ranges::views::all(
|
||||||
|
Core::App().domain().accounts()
|
||||||
|
) | ranges::views::transform([](const Main::Domain::AccountWithIndex &a) {
|
||||||
|
return not_null{ a.account.get() };
|
||||||
|
}) | ranges::to_vector;
|
||||||
|
ranges::stable_sort(accounts, [&](
|
||||||
|
not_null<Main::Account*> a,
|
||||||
|
not_null<Main::Account*> b) {
|
||||||
|
const auto aIt = a->sessionExists()
|
||||||
|
? ranges::find(order, a->session().uniqueId())
|
||||||
|
: end(order);
|
||||||
|
const auto bIt = b->sessionExists()
|
||||||
|
? ranges::find(order, b->session().uniqueId())
|
||||||
|
: end(order);
|
||||||
|
return aIt < bIt;
|
||||||
|
});
|
||||||
|
return accounts;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace Window {
|
namespace Window {
|
||||||
|
@ -817,11 +839,37 @@ void MainMenu::setupAccounts() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainMenu::rebuildAccounts() {
|
void MainMenu::rebuildAccounts() {
|
||||||
const auto inner = _accounts->entity();
|
const auto inner = _accounts->entity()->insert(
|
||||||
|
1, // After skip with the fixed height.
|
||||||
|
object_ptr<Ui::VerticalLayout>(_accounts.get()));
|
||||||
|
|
||||||
auto count = 0;
|
_reorder = std::make_unique<Ui::VerticalLayoutReorder>(inner);
|
||||||
for (const auto &[index, pointer] : Core::App().domain().accounts()) {
|
_reorder->updates(
|
||||||
const auto account = pointer.get();
|
) | rpl::start_with_next([=](Ui::VerticalLayoutReorder::Single data) {
|
||||||
|
using State = Ui::VerticalLayoutReorder::State;
|
||||||
|
if (data.state == State::Started) {
|
||||||
|
++_reordering;
|
||||||
|
} else {
|
||||||
|
Ui::PostponeCall(inner, [=] {
|
||||||
|
--_reordering;
|
||||||
|
});
|
||||||
|
if (data.state == State::Applied) {
|
||||||
|
std::vector<uint64> order;
|
||||||
|
order.reserve(inner->count());
|
||||||
|
for (auto i = 0; i < inner->count(); i++) {
|
||||||
|
for (const auto &[account, button] : _watched) {
|
||||||
|
if (button.get() == inner->widgetAt(i)) {
|
||||||
|
order.push_back(account->session().uniqueId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Core::App().settings().setAccountsOrder(order);
|
||||||
|
Core::App().saveSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, inner->lifetime());
|
||||||
|
|
||||||
|
for (const auto &account : OrderedAccounts()) {
|
||||||
auto i = _watched.find(account);
|
auto i = _watched.find(account);
|
||||||
Assert(i != _watched.end());
|
Assert(i != _watched.end());
|
||||||
|
|
||||||
|
@ -829,16 +877,19 @@ void MainMenu::rebuildAccounts() {
|
||||||
if (!account->sessionExists()) {
|
if (!account->sessionExists()) {
|
||||||
button = nullptr;
|
button = nullptr;
|
||||||
} else if (!button) {
|
} else if (!button) {
|
||||||
button.reset(inner->insert(
|
button.reset(inner->add(
|
||||||
++count,
|
|
||||||
object_ptr<AccountButton>(inner, account)));
|
object_ptr<AccountButton>(inner, account)));
|
||||||
button->setClickedCallback([=] {
|
button->setClickedCallback([=] {
|
||||||
|
if (_reordering) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (account == &Core::App().domain().active()) {
|
if (account == &Core::App().domain().active()) {
|
||||||
closeLayer();
|
closeLayer();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto activate = [=, guard = _accountSwitchGuard.make_guard()]{
|
auto activate = [=, guard = _accountSwitchGuard.make_guard()]{
|
||||||
if (guard) {
|
if (guard) {
|
||||||
|
_reorder->finishReordering();
|
||||||
Core::App().domain().maybeActivate(account);
|
Core::App().domain().maybeActivate(account);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -847,15 +898,15 @@ void MainMenu::rebuildAccounts() {
|
||||||
account,
|
account,
|
||||||
std::move(activate));
|
std::move(activate));
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
++count;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inner->resizeToWidth(_accounts->width());
|
inner->resizeToWidth(_accounts->width());
|
||||||
|
|
||||||
_addAccount->toggle(
|
_addAccount->toggle(
|
||||||
(count < Main::Domain::kMaxAccounts),
|
(inner->count() < Main::Domain::kMaxAccounts),
|
||||||
anim::type::instant);
|
anim::type::instant);
|
||||||
|
|
||||||
|
_reorder->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
not_null<Ui::SlideWrap<Ui::RippleButton>*> MainMenu::setupAddAccount(
|
not_null<Ui::SlideWrap<Ui::RippleButton>*> MainMenu::setupAddAccount(
|
||||||
|
|
|
@ -20,6 +20,7 @@ class UserpicButton;
|
||||||
class PopupMenu;
|
class PopupMenu;
|
||||||
class ScrollArea;
|
class ScrollArea;
|
||||||
class VerticalLayout;
|
class VerticalLayout;
|
||||||
|
class VerticalLayoutReorder;
|
||||||
class RippleButton;
|
class RippleButton;
|
||||||
class PlainShadow;
|
class PlainShadow;
|
||||||
template <typename Widget>
|
template <typename Widget>
|
||||||
|
@ -94,6 +95,9 @@ private:
|
||||||
base::Timer _nightThemeSwitch;
|
base::Timer _nightThemeSwitch;
|
||||||
base::unique_qptr<Ui::PopupMenu> _contextMenu;
|
base::unique_qptr<Ui::PopupMenu> _contextMenu;
|
||||||
|
|
||||||
|
std::unique_ptr<Ui::VerticalLayoutReorder> _reorder;
|
||||||
|
int _reordering = 0;
|
||||||
|
|
||||||
base::binary_guard _accountSwitchGuard;
|
base::binary_guard _accountSwitchGuard;
|
||||||
|
|
||||||
QString _phoneText;
|
QString _phoneText;
|
||||||
|
|
Loading…
Add table
Reference in a new issue