2016-09-06 12:28:37 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
#include "boxes/abstractbox.h"
|
2016-09-06 12:28:37 +00:00
|
|
|
#include "core/observer.h"
|
2016-09-26 12:09:59 +00:00
|
|
|
#include "core/vector_of_moveable.h"
|
2016-11-21 17:46:29 +00:00
|
|
|
#include "ui/effects/round_checkbox.h"
|
2016-09-06 12:28:37 +00:00
|
|
|
|
|
|
|
namespace Dialogs {
|
|
|
|
class Row;
|
|
|
|
class IndexedList;
|
|
|
|
} // namespace Dialogs
|
|
|
|
|
|
|
|
namespace Notify {
|
|
|
|
struct PeerUpdate;
|
|
|
|
} // namespace Notify
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
namespace Ui {
|
2016-10-22 13:03:20 +00:00
|
|
|
class MultiSelect;
|
2016-11-11 13:46:04 +00:00
|
|
|
class RoundButton;
|
2016-10-20 16:32:15 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2016-09-07 09:04:57 +00:00
|
|
|
QString appendShareGameScoreUrl(const QString &url, const FullMsgId &fullId);
|
|
|
|
void shareGameScoreByHash(const QString &hash);
|
|
|
|
|
2016-09-06 12:28:37 +00:00
|
|
|
class ShareBox : public ItemListBox, public RPCSender {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2016-11-20 12:54:07 +00:00
|
|
|
using CopyCallback = base::lambda<void()>;
|
|
|
|
using SubmitCallback = base::lambda<void(const QVector<PeerData*> &)>;
|
|
|
|
using FilterCallback = base::lambda<bool(PeerData*)>;
|
2016-09-28 16:23:25 +00:00
|
|
|
ShareBox(CopyCallback &©Callback, SubmitCallback &&submitCallback, FilterCallback &&filterCallback);
|
2016-09-06 12:28:37 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void onScroll();
|
|
|
|
|
|
|
|
bool onSearchByUsername(bool searchCache = false);
|
|
|
|
void onNeedSearchByUsername();
|
|
|
|
|
2016-09-19 10:18:21 +00:00
|
|
|
void onSubmit();
|
|
|
|
void onCopyLink();
|
2016-09-06 12:28:37 +00:00
|
|
|
|
2016-09-06 14:45:10 +00:00
|
|
|
void onMustScrollTo(int top, int bottom);
|
|
|
|
|
2016-09-06 12:28:37 +00:00
|
|
|
protected:
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
2016-09-06 14:45:10 +00:00
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
2016-09-06 12:28:37 +00:00
|
|
|
|
|
|
|
void doSetInnerFocus() override;
|
|
|
|
|
|
|
|
private:
|
2016-10-22 13:03:20 +00:00
|
|
|
void onFilterUpdate(const QString &query);
|
|
|
|
void onSelectedChanged();
|
2016-09-06 12:28:37 +00:00
|
|
|
void moveButtons();
|
2016-09-19 10:18:21 +00:00
|
|
|
void updateButtonsVisibility();
|
2016-10-22 13:03:20 +00:00
|
|
|
int getTopScrollSkip() const;
|
|
|
|
void updateScrollSkips();
|
|
|
|
|
|
|
|
void addPeerToMultiSelect(PeerData *peer, bool skipAnimation = false);
|
|
|
|
void onPeerSelectedChanged(PeerData *peer, bool checked);
|
2016-09-06 12:28:37 +00:00
|
|
|
|
|
|
|
void peopleReceived(const MTPcontacts_Found &result, mtpRequestId requestId);
|
|
|
|
bool peopleFailed(const RPCError &error, mtpRequestId requestId);
|
|
|
|
|
2016-09-19 10:18:21 +00:00
|
|
|
CopyCallback _copyCallback;
|
|
|
|
SubmitCallback _submitCallback;
|
2016-09-06 12:28:37 +00:00
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
class Inner;
|
|
|
|
ChildWidget<Inner> _inner;
|
2016-10-22 13:03:20 +00:00
|
|
|
ChildWidget<Ui::MultiSelect> _select;
|
2016-09-06 12:28:37 +00:00
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
ChildWidget<Ui::RoundButton> _copy;
|
|
|
|
ChildWidget<Ui::RoundButton> _share;
|
|
|
|
ChildWidget<Ui::RoundButton> _cancel;
|
2016-09-06 12:28:37 +00:00
|
|
|
|
|
|
|
ChildWidget<ScrollableBoxShadow> _topShadow;
|
|
|
|
ChildWidget<ScrollableBoxShadow> _bottomShadow;
|
|
|
|
|
|
|
|
QTimer _searchTimer;
|
|
|
|
QString _peopleQuery;
|
|
|
|
bool _peopleFull = false;
|
|
|
|
mtpRequestId _peopleRequest = 0;
|
|
|
|
|
|
|
|
using PeopleCache = QMap<QString, MTPcontacts_Found>;
|
|
|
|
PeopleCache _peopleCache;
|
|
|
|
|
|
|
|
using PeopleQueries = QMap<mtpRequestId, QString>;
|
|
|
|
PeopleQueries _peopleQueries;
|
|
|
|
|
2016-09-06 14:45:10 +00:00
|
|
|
IntAnimation _scrollAnimation;
|
|
|
|
|
2016-09-06 12:28:37 +00:00
|
|
|
};
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
// This class is hold in header because it requires Qt preprocessing.
|
2016-10-26 16:43:13 +00:00
|
|
|
class ShareBox::Inner : public TWidget, public RPCSender, private base::Subscriber {
|
2016-09-06 12:28:37 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2016-10-20 16:32:15 +00:00
|
|
|
Inner(QWidget *parent, ShareBox::FilterCallback &&filterCallback);
|
2016-09-06 12:28:37 +00:00
|
|
|
|
2016-11-20 12:54:07 +00:00
|
|
|
void setPeerSelectedChangedCallback(base::lambda<void(PeerData *peer, bool selected)> &&callback);
|
2016-10-22 13:03:20 +00:00
|
|
|
void peerUnselected(PeerData *peer);
|
|
|
|
|
2016-09-06 12:28:37 +00:00
|
|
|
QVector<PeerData*> selected() const;
|
|
|
|
bool hasSelected() const;
|
|
|
|
|
|
|
|
void peopleReceived(const QString &query, const QVector<MTPPeer> &people);
|
|
|
|
|
2016-09-06 14:45:10 +00:00
|
|
|
void activateSkipRow(int direction);
|
|
|
|
void activateSkipColumn(int direction);
|
|
|
|
void activateSkipPage(int pageHeight, int direction);
|
2016-09-06 12:28:37 +00:00
|
|
|
void setVisibleTopBottom(int visibleTop, int visibleBottom) override;
|
|
|
|
void updateFilter(QString filter = QString());
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
~Inner();
|
2016-09-06 12:28:37 +00:00
|
|
|
|
2016-09-06 14:45:10 +00:00
|
|
|
public slots:
|
|
|
|
void onSelectActive();
|
|
|
|
|
2016-09-06 12:28:37 +00:00
|
|
|
signals:
|
2016-09-06 14:45:10 +00:00
|
|
|
void mustScrollTo(int ymin, int ymax);
|
2016-09-06 12:28:37 +00:00
|
|
|
void searchByUsername();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void enterEvent(QEvent *e) override;
|
|
|
|
void leaveEvent(QEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Observed notifications.
|
|
|
|
void notifyPeerUpdated(const Notify::PeerUpdate &update);
|
|
|
|
|
2016-09-06 14:45:10 +00:00
|
|
|
int displayedChatsCount() const;
|
|
|
|
|
2016-09-06 12:28:37 +00:00
|
|
|
struct Chat {
|
2016-11-20 12:54:07 +00:00
|
|
|
Chat(PeerData *peer, const base::lambda_copy<void()> &updateCallback);
|
2016-10-20 11:34:48 +00:00
|
|
|
|
2016-09-06 12:28:37 +00:00
|
|
|
PeerData *peer;
|
2016-10-20 11:34:48 +00:00
|
|
|
Ui::RoundImageCheckbox checkbox;
|
2016-09-06 12:28:37 +00:00
|
|
|
Text name;
|
2016-11-07 11:24:19 +00:00
|
|
|
FloatAnimation nameActive;
|
2016-09-06 12:28:37 +00:00
|
|
|
};
|
2016-10-23 21:25:29 +00:00
|
|
|
void paintChat(Painter &p, uint64 ms, Chat *chat, int index);
|
2016-09-06 12:28:37 +00:00
|
|
|
void updateChat(PeerData *peer);
|
|
|
|
void updateChatName(Chat *chat, PeerData *peer);
|
|
|
|
void repaintChat(PeerData *peer);
|
|
|
|
int chatIndex(PeerData *peer) const;
|
|
|
|
void repaintChatAtIndex(int index);
|
|
|
|
Chat *getChatAtIndex(int index);
|
|
|
|
|
|
|
|
void loadProfilePhotos(int yFrom);
|
|
|
|
void changeCheckState(Chat *chat);
|
2016-10-22 13:03:20 +00:00
|
|
|
enum class ChangeStateWay {
|
|
|
|
Default,
|
|
|
|
SkipCallback,
|
|
|
|
};
|
|
|
|
void changePeerCheckState(Chat *chat, bool checked, ChangeStateWay useCallback = ChangeStateWay::Default);
|
2016-09-06 12:28:37 +00:00
|
|
|
|
|
|
|
Chat *getChat(Dialogs::Row *row);
|
|
|
|
void setActive(int active);
|
|
|
|
void updateUpon(const QPoint &pos);
|
|
|
|
|
|
|
|
void refresh();
|
|
|
|
|
|
|
|
float64 _columnSkip = 0.;
|
|
|
|
float64 _rowWidthReal = 0.;
|
|
|
|
int _rowsLeft = 0;
|
|
|
|
int _rowsTop = 0;
|
|
|
|
int _rowWidth = 0;
|
|
|
|
int _rowHeight = 0;
|
|
|
|
int _columnCount = 4;
|
|
|
|
int _active = -1;
|
|
|
|
int _upon = -1;
|
|
|
|
|
2016-09-28 16:23:25 +00:00
|
|
|
ShareBox::FilterCallback _filterCallback;
|
2016-09-06 12:28:37 +00:00
|
|
|
std_::unique_ptr<Dialogs::IndexedList> _chatsIndexed;
|
|
|
|
QString _filter;
|
|
|
|
using FilteredDialogs = QVector<Dialogs::Row*>;
|
|
|
|
FilteredDialogs _filtered;
|
|
|
|
|
|
|
|
using DataMap = QMap<PeerData*, Chat*>;
|
|
|
|
DataMap _dataMap;
|
|
|
|
using SelectedChats = OrderedSet<PeerData*>;
|
|
|
|
SelectedChats _selected;
|
|
|
|
|
2016-11-20 12:54:07 +00:00
|
|
|
base::lambda<void(PeerData *peer, bool selected)> _peerSelectedChangedCallback;
|
2016-10-22 13:03:20 +00:00
|
|
|
|
2016-09-06 12:28:37 +00:00
|
|
|
ChatData *data(Dialogs::Row *row);
|
|
|
|
|
|
|
|
bool _searching = false;
|
|
|
|
QString _lastQuery;
|
|
|
|
using ByUsernameRows = QVector<PeerData*>;
|
|
|
|
using ByUsernameDatas = QVector<Chat*>;
|
2016-09-06 14:45:10 +00:00
|
|
|
ByUsernameRows _byUsernameFiltered;
|
|
|
|
ByUsernameDatas d_byUsernameFiltered;
|
2016-09-06 12:28:37 +00:00
|
|
|
|
|
|
|
};
|