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
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2016-09-06 12:28:37 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/abstract_box.h"
|
|
|
|
#include "base/observer.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-10-20 16:32:15 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2017-06-27 20:11:38 +00:00
|
|
|
QString AppendShareGameScoreUrl(const QString &url, const FullMsgId &fullId);
|
|
|
|
void ShareGameScoreByHash(const QString &hash);
|
2016-09-07 09:04:57 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
class ShareBox : public BoxContent, public RPCSender {
|
2016-09-06 12:28:37 +00:00
|
|
|
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-12-13 17:07:56 +00:00
|
|
|
ShareBox(QWidget*, CopyCallback &©Callback, SubmitCallback &&submitCallback, FilterCallback &&filterCallback);
|
2016-09-06 12:28:37 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
protected:
|
|
|
|
void prepare() override;
|
|
|
|
void setInnerFocus() override;
|
2016-09-06 12:28:37 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
|
|
|
|
|
|
|
private slots:
|
2016-09-06 12:28:37 +00:00
|
|
|
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
|
|
|
private:
|
2016-12-07 13:32:25 +00:00
|
|
|
void scrollAnimationCallback();
|
|
|
|
|
2016-10-22 13:03:20 +00:00
|
|
|
void onFilterUpdate(const QString &query);
|
|
|
|
void onSelectedChanged();
|
2016-12-13 17:07:56 +00:00
|
|
|
void updateButtons();
|
|
|
|
void createButtons();
|
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-12-13 17:07:56 +00:00
|
|
|
FilterCallback _filterCallback;
|
2016-09-06 12:28:37 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::MultiSelect> _select;
|
2016-09-06 12:28:37 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
class Inner;
|
|
|
|
QPointer<Inner> _inner;
|
2016-09-06 12:28:37 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
bool _hasSelected = false;
|
2016-09-06 12:28:37 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<QTimer> _searchTimer;
|
2016-09-06 12:28:37 +00:00
|
|
|
QString _peopleQuery;
|
|
|
|
bool _peopleFull = false;
|
|
|
|
mtpRequestId _peopleRequest = 0;
|
|
|
|
|
|
|
|
using PeopleCache = QMap<QString, MTPcontacts_Found>;
|
|
|
|
PeopleCache _peopleCache;
|
|
|
|
|
|
|
|
using PeopleQueries = QMap<mtpRequestId, QString>;
|
|
|
|
PeopleQueries _peopleQueries;
|
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _scrollAnimation;
|
2016-09-06 14:45:10 +00:00
|
|
|
|
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
|
|
|
|
2017-02-26 11:32:13 +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 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:
|
2017-09-13 16:57:44 +00:00
|
|
|
void visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) override;
|
|
|
|
|
2016-09-06 12:28:37 +00:00
|
|
|
void paintEvent(QPaintEvent *e) override;
|
2017-02-11 11:24:37 +00:00
|
|
|
void enterEventHook(QEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
2016-09-06 12:28:37 +00:00
|
|
|
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-12-20 13:03:51 +00:00
|
|
|
void invalidateCache();
|
2016-09-06 12:28:37 +00:00
|
|
|
|
2016-09-06 14:45:10 +00:00
|
|
|
int displayedChatsCount() const;
|
|
|
|
|
2016-09-06 12:28:37 +00:00
|
|
|
struct Chat {
|
2017-02-26 11:32:13 +00:00
|
|
|
Chat(PeerData *peer, base::lambda<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-12-07 13:32:25 +00:00
|
|
|
Animation nameActive;
|
2016-09-06 12:28:37 +00:00
|
|
|
};
|
2016-12-01 19:20:33 +00:00
|
|
|
void paintChat(Painter &p, TimeMs 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;
|
2017-02-21 13:45:56 +00:00
|
|
|
std::unique_ptr<Dialogs::IndexedList> _chatsIndexed;
|
2016-09-06 12:28:37 +00:00
|
|
|
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
|
|
|
|
|
|
|
};
|