mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-04-01 23:00:58 +00:00
Media shortcuts now are enabled only when in-app player is opened.
This commit is contained in:
parent
acc7e08a54
commit
fdead263d6
Telegram/SourceFiles
@ -100,7 +100,7 @@ MainWidget::MainWidget(MainWindow *window) : TWidget(window)
|
||||
App::wnd()->getTitle()->updateBackButton();
|
||||
_topBar->hide();
|
||||
|
||||
_player->hide();
|
||||
_player->hidePlayer();
|
||||
|
||||
orderWidgets();
|
||||
|
||||
@ -1558,15 +1558,17 @@ void MainWidget::documentPlayProgress(const SongMsgId &songId) {
|
||||
if (playing == songId) {
|
||||
_player->updateState(playing, playingState, playingPosition, playingDuration, playingFrequency);
|
||||
|
||||
if (!(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing && !_a_show.animating()) {
|
||||
if (_player->isHidden()) {
|
||||
_player->clearSelection();
|
||||
_player->show();
|
||||
if (!(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
||||
if (!_player->isOpened()) {
|
||||
_player->openPlayer();
|
||||
if (_player->isHidden() && !_a_show.animating()) {
|
||||
_player->showPlayer();
|
||||
_playerHeight = _contentScrollAddToY = _player->height();
|
||||
resizeEvent(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (HistoryItem *item = App::histItemById(songId.contextId)) {
|
||||
Ui::repaintHistoryItem(item);
|
||||
@ -1578,14 +1580,17 @@ void MainWidget::documentPlayProgress(const SongMsgId &songId) {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::hidePlayer() {
|
||||
if (!_player->isHidden()) {
|
||||
_player->hide();
|
||||
void MainWidget::closePlayer() {
|
||||
if (_player->isOpened()) {
|
||||
_player->closePlayer();
|
||||
if (!_player->isHidden() && !_a_show.animating()) {
|
||||
_player->hidePlayer();
|
||||
_contentScrollAddToY = -_player->height();
|
||||
_playerHeight = 0;
|
||||
resizeEvent(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::documentLoadProgress(FileLoader *loader) {
|
||||
mtpFileLoader *l = loader ? loader->mtpLoader() : 0;
|
||||
@ -2477,9 +2482,11 @@ void MainWidget::hideAll() {
|
||||
}
|
||||
_topBar->hide();
|
||||
_mediaType->hide();
|
||||
_player->hide();
|
||||
if (_player->isOpened() && !_player->isHidden()) {
|
||||
_player->hidePlayer();
|
||||
_playerHeight = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::showAll() {
|
||||
if (cPasswordRecovered()) {
|
||||
@ -2538,21 +2545,10 @@ void MainWidget::showAll() {
|
||||
_topBar->show();
|
||||
}
|
||||
}
|
||||
if (audioPlayer()) {
|
||||
SongMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
int64 playingPosition = 0, playingDuration = 0;
|
||||
int32 playingFrequency = 0;
|
||||
audioPlayer()->currentState(&playing, &playingState, &playingPosition, &playingDuration, &playingFrequency);
|
||||
if (playing) {
|
||||
_player->updateState(playing, playingState, playingPosition, playingDuration, playingFrequency);
|
||||
if (!(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
||||
_player->clearSelection();
|
||||
_player->show();
|
||||
if (_player->isOpened() && _player->isHidden()) {
|
||||
_player->showPlayer();
|
||||
_playerHeight = _player->height();
|
||||
}
|
||||
}
|
||||
}
|
||||
resizeEvent(0);
|
||||
|
||||
App::wnd()->checkHistoryActivation();
|
||||
|
@ -372,6 +372,8 @@ public:
|
||||
|
||||
bool isItemVisible(HistoryItem *item);
|
||||
|
||||
void closePlayer();
|
||||
|
||||
void app_sendBotCallback(const HistoryMessageReplyMarkup::Button *button, const HistoryItem *msg, int row, int col);
|
||||
|
||||
void ui_repaintHistoryItem(const HistoryItem *item);
|
||||
@ -422,7 +424,6 @@ public slots:
|
||||
void documentPlayProgress(const SongMsgId &songId);
|
||||
void inlineResultLoadProgress(FileLoader *loader);
|
||||
void inlineResultLoadFailed(FileLoader *loader, bool started);
|
||||
void hidePlayer();
|
||||
|
||||
void dialogsCancelled();
|
||||
|
||||
|
@ -19,41 +19,21 @@ Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
||||
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
||||
*/
|
||||
#include "stdafx.h"
|
||||
#include "playerwidget.h"
|
||||
|
||||
#include "shortcuts.h"
|
||||
#include "ui/style.h"
|
||||
#include "lang.h"
|
||||
|
||||
#include "boxes/addcontactbox.h"
|
||||
#include "application.h"
|
||||
#include "mainwindow.h"
|
||||
#include "playerwidget.h"
|
||||
#include "mainwidget.h"
|
||||
|
||||
#include "localstorage.h"
|
||||
|
||||
#include "audio.h"
|
||||
|
||||
PlayerWidget::PlayerWidget(QWidget *parent) : TWidget(parent)
|
||||
, _prevAvailable(false)
|
||||
, _nextAvailable(false)
|
||||
, _fullAvailable(false)
|
||||
, _over(OverNone)
|
||||
, _down(OverNone)
|
||||
, _downCoord(0)
|
||||
, _downFrequency(AudioVoiceMsgFrequency)
|
||||
, _downProgress(0.)
|
||||
, _a_state(animation(this, &PlayerWidget::step_state))
|
||||
, _msgmigrated(false)
|
||||
, _index(-1)
|
||||
, _migrated(0)
|
||||
, _history(0)
|
||||
, _timeWidth(0)
|
||||
, _repeat(false)
|
||||
, _showPause(false)
|
||||
, _position(0)
|
||||
, _duration(0)
|
||||
, _loaded(0)
|
||||
, a_progress(0., 0.)
|
||||
, a_loadProgress(0., 0.)
|
||||
, _a_progress(animation(this, &PlayerWidget::step_progress))
|
||||
, _sideShadow(this, st::shadowColor) {
|
||||
resize(st::wndMinWidth, st::playerHeight);
|
||||
@ -372,6 +352,29 @@ bool PlayerWidget::seekingSong(const SongMsgId &song) const {
|
||||
return (_down == OverPlayback) && (song == _song);
|
||||
}
|
||||
|
||||
void PlayerWidget::openPlayer() {
|
||||
_playerOpened = true;
|
||||
Shortcuts::enableMediaShortcuts();
|
||||
}
|
||||
|
||||
bool PlayerWidget::isOpened() const {
|
||||
return _playerOpened;
|
||||
}
|
||||
|
||||
void PlayerWidget::closePlayer() {
|
||||
_playerOpened = false;
|
||||
Shortcuts::disableMediaShortcuts();
|
||||
}
|
||||
|
||||
void PlayerWidget::showPlayer() {
|
||||
TWidget::show();
|
||||
}
|
||||
|
||||
void PlayerWidget::hidePlayer() {
|
||||
clearSelection();
|
||||
TWidget::hide();
|
||||
}
|
||||
|
||||
void PlayerWidget::step_state(uint64 ms, bool timer) {
|
||||
for (StateAnimations::iterator i = _stateAnimations.begin(); i != _stateAnimations.cend();) {
|
||||
int32 over = qAbs(i.key());
|
||||
@ -463,7 +466,7 @@ void PlayerWidget::mouseReleaseEvent(QMouseEvent *e) {
|
||||
}
|
||||
update();
|
||||
} else if (_down == OverClose && _over == OverClose) {
|
||||
stopPressed();
|
||||
closePressed();
|
||||
}
|
||||
_down = OverNone;
|
||||
}
|
||||
@ -545,7 +548,11 @@ void PlayerWidget::stopPressed() {
|
||||
if (!_song || isHidden()) return;
|
||||
|
||||
audioPlayer()->stop(OverviewFiles);
|
||||
if (App::main()) App::main()->hidePlayer();
|
||||
}
|
||||
|
||||
void PlayerWidget::closePressed() {
|
||||
stopPressed();
|
||||
if (App::main()) App::main()->closePlayer();
|
||||
}
|
||||
|
||||
void PlayerWidget::resizeEvent(QResizeEvent *e) {
|
||||
|
@ -42,6 +42,7 @@ public:
|
||||
void prevPressed();
|
||||
void nextPressed();
|
||||
void stopPressed();
|
||||
void closePressed();
|
||||
|
||||
void step_progress(float64 ms, bool timer);
|
||||
void step_state(uint64 ms, bool timer);
|
||||
@ -55,12 +56,23 @@ public:
|
||||
|
||||
bool seekingSong(const SongMsgId &song) const;
|
||||
|
||||
void openPlayer();
|
||||
bool isOpened() const;
|
||||
void closePlayer();
|
||||
|
||||
void showPlayer();
|
||||
void hidePlayer();
|
||||
|
||||
signals:
|
||||
|
||||
void playerSongChanged(const FullMsgId &msgId);
|
||||
|
||||
private:
|
||||
|
||||
// Use startPlayer()/stopPlayer() or showPlayer()/hidePlayer() instead.
|
||||
void show();
|
||||
void hide();
|
||||
|
||||
enum OverState {
|
||||
OverNone = 0,
|
||||
OverPrev,
|
||||
@ -87,12 +99,17 @@ private:
|
||||
QPoint _lastMousePos;
|
||||
void updateSelected();
|
||||
|
||||
bool _prevAvailable, _nextAvailable, _fullAvailable;
|
||||
OverState _over, _down;
|
||||
int32 _downCoord;
|
||||
bool _playerOpened = false;
|
||||
|
||||
bool _prevAvailable = false;
|
||||
bool _nextAvailable = false;
|
||||
bool _fullAvailable = false;
|
||||
OverState _over = OverNone;
|
||||
OverState _down = OverNone;
|
||||
int32 _downCoord = 0;
|
||||
int64 _downDuration;
|
||||
int32 _downFrequency;
|
||||
float64 _downProgress;
|
||||
int32 _downFrequency = AudioVoiceMsgFrequency;
|
||||
float64 _downProgress = 0.;
|
||||
|
||||
float64 _stateHovers[OverStateCount];
|
||||
typedef QMap<int32, uint64> StateAnimations;
|
||||
@ -100,20 +117,23 @@ private:
|
||||
Animation _a_state;
|
||||
|
||||
SongMsgId _song;
|
||||
bool _msgmigrated;
|
||||
int32 _index;
|
||||
History *_migrated, *_history;
|
||||
bool _msgmigrated = false;
|
||||
int32 _index = -1;
|
||||
History *_migrated = nullptr;
|
||||
History *_history = nullptr;
|
||||
QRect _playRect, _prevRect, _nextRect, _playbackRect;
|
||||
QRect _closeRect, _volumeRect, _fullRect, _repeatRect, _infoRect;
|
||||
int32 _timeWidth;
|
||||
bool _repeat;
|
||||
int32 _timeWidth = 0;
|
||||
bool _repeat = false;
|
||||
QString _time;
|
||||
Text _name;
|
||||
bool _showPause;
|
||||
int64 _position, _duration;
|
||||
int32 _loaded;
|
||||
bool _showPause = false;
|
||||
int64 _position = 0;
|
||||
int64 _duration = 0;
|
||||
int32 _loaded = 0;
|
||||
|
||||
anim::fvalue a_progress, a_loadProgress;
|
||||
anim::fvalue a_progress = { 0., 0. };
|
||||
anim::fvalue a_loadProgress = { 0., 0. };
|
||||
Animation _a_progress;
|
||||
|
||||
PlainShadow _sideShadow;
|
||||
|
@ -27,6 +27,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
||||
#include "playerwidget.h"
|
||||
|
||||
namespace ShortcutCommands {
|
||||
|
||||
typedef void(*Handler)();
|
||||
|
||||
void lock_telegram() {
|
||||
@ -125,7 +126,7 @@ namespace ShortcutCommands {
|
||||
|
||||
// other commands here
|
||||
|
||||
}
|
||||
} // namespace ShortcutCommands
|
||||
|
||||
inline bool qMapLessThanKey(const ShortcutCommands::Handler &a, const ShortcutCommands::Handler &b) {
|
||||
return a < b;
|
||||
@ -206,15 +207,21 @@ namespace Shortcuts {
|
||||
struct DataStruct;
|
||||
DataStruct *DataPtr = nullptr;
|
||||
|
||||
void _createCommand(const QString &command, ShortcutCommands::Handler handler);
|
||||
QKeySequence _setShortcut(const QString &keys, const QString &command);
|
||||
namespace {
|
||||
|
||||
void createCommand(const QString &command, ShortcutCommands::Handler handler);
|
||||
QKeySequence setShortcut(const QString &keys, const QString &command);
|
||||
void destroyShortcut(QShortcut *shortcut);
|
||||
|
||||
} // namespace
|
||||
|
||||
struct DataStruct {
|
||||
DataStruct() {
|
||||
t_assert(DataPtr == nullptr);
|
||||
DataPtr = this;
|
||||
|
||||
#define DeclareAlias(keys, command) _setShortcut(qsl(keys), qsl(#command))
|
||||
#define DeclareCommand(keys, command) _createCommand(qsl(#command), ShortcutCommands::command); DeclareAlias(keys, command)
|
||||
#define DeclareAlias(keys, command) setShortcut(qsl(keys), qsl(#command))
|
||||
#define DeclareCommand(keys, command) createCommand(qsl(#command), ShortcutCommands::command); DeclareAlias(keys, command)
|
||||
|
||||
DeclareCommand("ctrl+w", close_telegram);
|
||||
DeclareAlias("ctrl+f4", close_telegram);
|
||||
@ -264,15 +271,28 @@ namespace Shortcuts {
|
||||
QMap<QKeySequence, QShortcut*> sequences;
|
||||
QMap<int, ShortcutCommands::Handler> handlers;
|
||||
|
||||
QSet<QShortcut*> mediaShortcuts;
|
||||
|
||||
QSet<QString> autoRepeatCommands = {
|
||||
qsl("media_previous"),
|
||||
qsl("media_next"),
|
||||
qsl("next_chat"),
|
||||
qsl("previous_chat"),
|
||||
};
|
||||
|
||||
QSet<QString> mediaCommands = {
|
||||
qsl("media_play"),
|
||||
qsl("media_pause"),
|
||||
qsl("media_playpause"),
|
||||
qsl("media_stop"),
|
||||
qsl("media_previous"),
|
||||
qsl("media_next")
|
||||
};
|
||||
};
|
||||
|
||||
void _createCommand(const QString &command, ShortcutCommands::Handler handler) {
|
||||
namespace {
|
||||
|
||||
void createCommand(const QString &command, ShortcutCommands::Handler handler) {
|
||||
t_assert(DataPtr != nullptr);
|
||||
t_assert(!command.isEmpty());
|
||||
|
||||
@ -280,7 +300,7 @@ namespace Shortcuts {
|
||||
DataPtr->commandnames.insert(handler, command);
|
||||
}
|
||||
|
||||
QKeySequence _setShortcut(const QString &keys, const QString &command) {
|
||||
QKeySequence setShortcut(const QString &keys, const QString &command) {
|
||||
t_assert(DataPtr != nullptr);
|
||||
t_assert(!command.isEmpty());
|
||||
if (keys.isEmpty()) return QKeySequence();
|
||||
@ -293,30 +313,37 @@ namespace Shortcuts {
|
||||
if (it == DataPtr->commands.cend()) {
|
||||
LOG(("Warning: could not find shortcut command handler '%1'").arg(command));
|
||||
} else {
|
||||
QShortcut *shortcut(new QShortcut(seq, App::wnd(), nullptr, nullptr, Qt::ApplicationShortcut));
|
||||
auto shortcut = std_::make_unique<QShortcut>(seq, App::wnd(), nullptr, nullptr, Qt::ApplicationShortcut);
|
||||
if (!DataPtr->autoRepeatCommands.contains(command)) {
|
||||
shortcut->setAutoRepeat(false);
|
||||
}
|
||||
auto isMediaShortcut = DataPtr->mediaCommands.contains(command);
|
||||
if (isMediaShortcut) {
|
||||
shortcut->setEnabled(false);
|
||||
}
|
||||
int shortcutId = shortcut->id();
|
||||
if (!shortcutId) {
|
||||
DataPtr->errors.push_back(qsl("Could not create shortcut '%1'!").arg(keys));
|
||||
} else {
|
||||
QMap<QKeySequence, QShortcut*>::iterator seqIt = DataPtr->sequences.find(seq);
|
||||
auto seqIt = DataPtr->sequences.find(seq);
|
||||
if (seqIt == DataPtr->sequences.cend()) {
|
||||
seqIt = DataPtr->sequences.insert(seq, shortcut);
|
||||
seqIt = DataPtr->sequences.insert(seq, shortcut.release());
|
||||
} else {
|
||||
DataPtr->handlers.remove(seqIt.value()->id());
|
||||
delete seqIt.value();
|
||||
seqIt.value() = shortcut;
|
||||
auto oldShortcut = seqIt.value();
|
||||
seqIt.value() = shortcut.release();
|
||||
destroyShortcut(oldShortcut);
|
||||
}
|
||||
DataPtr->handlers.insert(shortcutId, it.value());
|
||||
if (isMediaShortcut) {
|
||||
DataPtr->mediaShortcuts.insert(seqIt.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return seq;
|
||||
}
|
||||
|
||||
QKeySequence _removeShortcut(const QString &keys) {
|
||||
QKeySequence removeShortcut(const QString &keys) {
|
||||
t_assert(DataPtr != nullptr);
|
||||
if (keys.isEmpty()) return QKeySequence();
|
||||
|
||||
@ -324,16 +351,26 @@ namespace Shortcuts {
|
||||
if (seq.isEmpty()) {
|
||||
DataPtr->errors.push_back(qsl("Could not derive key sequence '%1'!").arg(keys));
|
||||
} else {
|
||||
QMap<QKeySequence, QShortcut*>::iterator seqIt = DataPtr->sequences.find(seq);
|
||||
auto seqIt = DataPtr->sequences.find(seq);
|
||||
if (seqIt != DataPtr->sequences.cend()) {
|
||||
DataPtr->handlers.remove(seqIt.value()->id());
|
||||
delete seqIt.value();
|
||||
auto shortcut = seqIt.value();
|
||||
DataPtr->sequences.erase(seqIt);
|
||||
destroyShortcut(shortcut);
|
||||
}
|
||||
}
|
||||
return seq;
|
||||
}
|
||||
|
||||
void destroyShortcut(QShortcut *shortcut) {
|
||||
t_assert(DataPtr != nullptr);
|
||||
|
||||
DataPtr->handlers.remove(shortcut->id());
|
||||
DataPtr->mediaShortcuts.remove(shortcut);
|
||||
delete shortcut;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void start() {
|
||||
t_assert(Global::started());
|
||||
|
||||
@ -371,10 +408,10 @@ namespace Shortcuts {
|
||||
version.insert(qsl("version"), QString::number(AppVersion));
|
||||
shortcuts.push_back(version);
|
||||
|
||||
for (QMap<QKeySequence, QShortcut*>::const_iterator i = DataPtr->sequences.cbegin(), e = DataPtr->sequences.cend(); i != e; ++i) {
|
||||
QMap<int, ShortcutCommands::Handler>::const_iterator h = DataPtr->handlers.constFind(i.value()->id());
|
||||
for (auto i = DataPtr->sequences.cbegin(), e = DataPtr->sequences.cend(); i != e; ++i) {
|
||||
auto h = DataPtr->handlers.constFind(i.value()->id());
|
||||
if (h != DataPtr->handlers.cend()) {
|
||||
QMap<ShortcutCommands::Handler, QString>::const_iterator n = DataPtr->commandnames.constFind(h.value());
|
||||
auto n = DataPtr->commandnames.constFind(h.value());
|
||||
if (n != DataPtr->commandnames.cend()) {
|
||||
QJsonObject entry;
|
||||
entry.insert(qsl("keys"), i.key().toString().toLower());
|
||||
@ -415,9 +452,9 @@ namespace Shortcuts {
|
||||
if (keys == entry.constEnd() || command == entry.constEnd() || !(*keys).isString() || (!(*command).isString() && !(*command).isNull())) {
|
||||
DataPtr->errors.push_back(qsl("Bad entry! {\"keys\": \"...\", \"command\": [ \"...\" | null ]} expected"));
|
||||
} else if ((*command).isNull()) {
|
||||
seq = _removeShortcut((*keys).toString());
|
||||
seq = removeShortcut((*keys).toString());
|
||||
} else {
|
||||
seq = _setShortcut((*keys).toString(), (*command).toString());
|
||||
seq = setShortcut((*keys).toString(), (*command).toString());
|
||||
}
|
||||
if (!--limit) {
|
||||
DataPtr->errors.push_back(qsl("Too many entries! Limit is %1").arg(ShortcutsCountLimit));
|
||||
@ -460,7 +497,7 @@ namespace Shortcuts {
|
||||
bool launch(int shortcutId) {
|
||||
t_assert(DataPtr != nullptr);
|
||||
|
||||
QMap<int, ShortcutCommands::Handler>::const_iterator it = DataPtr->handlers.constFind(shortcutId);
|
||||
auto it = DataPtr->handlers.constFind(shortcutId);
|
||||
if (it == DataPtr->handlers.cend()) {
|
||||
return false;
|
||||
}
|
||||
@ -471,7 +508,7 @@ namespace Shortcuts {
|
||||
bool launch(const QString &command) {
|
||||
t_assert(DataPtr != nullptr);
|
||||
|
||||
QMap<QString, ShortcutCommands::Handler>::const_iterator it = DataPtr->commands.constFind(command);
|
||||
auto it = DataPtr->commands.constFind(command);
|
||||
if (it == DataPtr->commands.cend()) {
|
||||
return false;
|
||||
}
|
||||
@ -479,9 +516,23 @@ namespace Shortcuts {
|
||||
return true;
|
||||
}
|
||||
|
||||
void enableMediaShortcuts() {
|
||||
if (!DataPtr) return;
|
||||
for_const (auto shortcut, DataPtr->mediaShortcuts) {
|
||||
shortcut->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void disableMediaShortcuts() {
|
||||
if (!DataPtr) return;
|
||||
for_const (auto shortcut, DataPtr->mediaShortcuts) {
|
||||
shortcut->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void finish() {
|
||||
delete DataPtr;
|
||||
DataPtr = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Shortcuts
|
||||
|
@ -28,6 +28,12 @@ namespace Shortcuts {
|
||||
bool launch(int shortcutId);
|
||||
bool launch(const QString &command);
|
||||
|
||||
// Media shortcuts are not enabled by default, because other
|
||||
// applications also use them. They are enabled only when
|
||||
// the in-app player is active and disabled back after.
|
||||
void enableMediaShortcuts();
|
||||
void disableMediaShortcuts();
|
||||
|
||||
void finish();
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user