mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-19 07:37:11 +02:00
Unified and moved to single place generating of song name from SongData.
This commit is contained in:
parent
f98e8f3e04
commit
690fbe83fd
17 changed files with 191 additions and 116 deletions
|
@ -1051,6 +1051,8 @@ PRIVATE
|
|||
ui/search_field_controller.h
|
||||
ui/special_buttons.cpp
|
||||
ui/special_buttons.h
|
||||
ui/text/format_song_document_name.cpp
|
||||
ui/text/format_song_document_name.h
|
||||
ui/unread_badge.cpp
|
||||
ui/unread_badge.h
|
||||
window/main_window.cpp
|
||||
|
|
|
@ -47,6 +47,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/widgets/input_fields.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/text/format_song_document_name.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/text/text_options.h"
|
||||
#include "ui/chat/attach/attach_prepare.h"
|
||||
|
@ -220,7 +221,7 @@ EditCaptionBox::EditCaptionBox(
|
|||
const auto document = _documentMedia->owner();
|
||||
const auto nameString = document->isVoiceMessage()
|
||||
? tr::lng_media_audio(tr::now)
|
||||
: document->composeNameString();
|
||||
: Ui::Text::FormatSongNameFor(document).string();
|
||||
setName(nameString, document->size);
|
||||
_isImage = document->isImage();
|
||||
_isAudio = document->isVoiceMessage()
|
||||
|
@ -549,10 +550,10 @@ void EditCaptionBox::updateEditPreview() {
|
|||
if (shouldAsDoc) {
|
||||
auto nameString = filename;
|
||||
if (const auto song = std::get_if<Info::Song>(fileMedia)) {
|
||||
nameString = Ui::ComposeNameString(
|
||||
nameString = Ui::Text::FormatSongName(
|
||||
filename,
|
||||
song->title,
|
||||
song->performer);
|
||||
song->performer).string();
|
||||
_isAudio = true;
|
||||
|
||||
if (auto cover = song->cover; !cover.isNull()) {
|
||||
|
|
|
@ -40,7 +40,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "boxes/confirm_box.h"
|
||||
#include "ui/image/image.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "base/base_file_utilities.h"
|
||||
#include "mainwindow.h"
|
||||
#include "core/application.h"
|
||||
|
@ -1464,16 +1463,6 @@ uint8 DocumentData::cacheTag() const {
|
|||
return 0;
|
||||
}
|
||||
|
||||
QString DocumentData::composeNameString() const {
|
||||
if (auto songData = song()) {
|
||||
return Ui::ComposeNameString(
|
||||
_filename,
|
||||
songData->title,
|
||||
songData->performer);
|
||||
}
|
||||
return Ui::ComposeNameString(_filename, QString(), QString());
|
||||
}
|
||||
|
||||
LocationType DocumentData::locationType() const {
|
||||
return isVoiceMessage()
|
||||
? AudioFileLocation
|
||||
|
|
|
@ -228,8 +228,6 @@ public:
|
|||
[[nodiscard]] Storage::Cache::Key cacheKey() const;
|
||||
[[nodiscard]] uint8 cacheTag() const;
|
||||
|
||||
[[nodiscard]] QString composeNameString() const;
|
||||
|
||||
[[nodiscard]] bool canBeStreamed() const;
|
||||
[[nodiscard]] auto createStreamingLoader(
|
||||
Data::FileOrigin origin,
|
||||
|
|
|
@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/view/media/history_view_slot_machine.h"
|
||||
#include "history/view/media/history_view_dice.h"
|
||||
#include "ui/image/image.h"
|
||||
#include "ui/text/format_song_document_name.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/text/text_options.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
|
@ -506,6 +507,7 @@ QString MediaFile::chatListText() const {
|
|||
return Media::chatListText();
|
||||
}
|
||||
const auto type = [&] {
|
||||
using namespace Ui::Text;
|
||||
if (_document->isVideoMessage()) {
|
||||
return tr::lng_in_dlg_video_message(tr::now);
|
||||
} else if (_document->isAnimation()) {
|
||||
|
@ -514,7 +516,7 @@ QString MediaFile::chatListText() const {
|
|||
return tr::lng_in_dlg_video(tr::now);
|
||||
} else if (_document->isVoiceMessage()) {
|
||||
return tr::lng_in_dlg_audio(tr::now);
|
||||
} else if (const auto name = _document->composeNameString();
|
||||
} else if (const auto name = FormatSongNameFor(_document).string();
|
||||
!name.isEmpty()) {
|
||||
return name;
|
||||
} else if (_document->isAudioFile()) {
|
||||
|
@ -576,7 +578,7 @@ QString MediaFile::pinnedTextSubstring() const {
|
|||
|
||||
TextForMimeData MediaFile::clipboardText() const {
|
||||
const auto attachType = [&] {
|
||||
const auto name = _document->composeNameString();
|
||||
const auto name = Ui::Text::FormatSongNameFor(_document).string();
|
||||
const auto addName = !name.isEmpty()
|
||||
? qstr(" : ") + name
|
||||
: QString();
|
||||
|
|
|
@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/view/media/history_view_media_common.h"
|
||||
#include "ui/image/image.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/text/format_song_document_name.h"
|
||||
#include "ui/cached_round_corners.h"
|
||||
#include "ui/ui_utility.h"
|
||||
#include "layout.h" // FullSelection
|
||||
|
@ -226,7 +227,7 @@ void Document::createComponents(bool caption) {
|
|||
|
||||
void Document::fillNamedFromData(HistoryDocumentNamed *named) {
|
||||
const auto nameString = named->_name = CleanTagSymbols(
|
||||
_data->composeNameString());
|
||||
Ui::Text::FormatSongNameFor(_data).string());
|
||||
named->_namew = st::semiboldFont->width(nameString);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/effects/ripple_animation.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/text/format_song_document_name.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "media/audio/media_audio.h"
|
||||
#include "media/view/media_view_playback_progress.h"
|
||||
|
@ -565,26 +566,8 @@ void Widget::handleSongChange() {
|
|||
textWithEntities.text = tr::lng_media_audio(tr::now);
|
||||
}
|
||||
} else {
|
||||
const auto song = document->song();
|
||||
if (!song || song->performer.isEmpty()) {
|
||||
textWithEntities.text = (!song || song->title.isEmpty())
|
||||
? (document->filename().isEmpty()
|
||||
? qsl("Unknown Track")
|
||||
: document->filename())
|
||||
: song->title;
|
||||
} else {
|
||||
auto title = song->title.isEmpty()
|
||||
? qsl("Unknown Track")
|
||||
: TextUtilities::Clean(song->title);
|
||||
auto dash = QString::fromUtf8(" \xe2\x80\x93 ");
|
||||
textWithEntities.text = song->performer + dash + title;
|
||||
textWithEntities.entities.append({
|
||||
EntityType::Semibold,
|
||||
0,
|
||||
song->performer.size(),
|
||||
QString()
|
||||
});
|
||||
}
|
||||
textWithEntities = Ui::Text::FormatSongNameFor(document)
|
||||
.textWithEntities(true);
|
||||
}
|
||||
_nameLabel->setMarkedText(textWithEntities);
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "base/qt_adapters.h"
|
||||
#include "ui/effects/round_checkbox.h"
|
||||
#include "ui/image/image.h"
|
||||
#include "ui/text/format_song_document_name.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/text/text_options.h"
|
||||
#include "ui/cached_round_corners.h"
|
||||
|
@ -56,38 +57,6 @@ TextParseOptions _documentNameOptions = {
|
|||
Qt::LayoutDirectionAuto, // dir
|
||||
};
|
||||
|
||||
TextWithEntities ComposeNameWithEntities(DocumentData *document) {
|
||||
TextWithEntities result;
|
||||
const auto song = document->song();
|
||||
if (!song || (song->title.isEmpty() && song->performer.isEmpty())) {
|
||||
result.text = document->filename().isEmpty()
|
||||
? qsl("Unknown File")
|
||||
: document->filename();
|
||||
result.entities.push_back({
|
||||
EntityType::Semibold,
|
||||
0,
|
||||
result.text.size()
|
||||
});
|
||||
} else if (song->performer.isEmpty()) {
|
||||
result.text = song->title;
|
||||
result.entities.push_back({
|
||||
EntityType::Semibold,
|
||||
0,
|
||||
result.text.size()
|
||||
});
|
||||
} else {
|
||||
result.text = song->performer
|
||||
+ QString::fromUtf8(" \xe2\x80\x93 ")
|
||||
+ (song->title.isEmpty() ? qsl("Unknown Track") : song->title);
|
||||
result.entities.push_back({
|
||||
EntityType::Semibold,
|
||||
0,
|
||||
song->performer.size()
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class Checkbox {
|
||||
|
@ -935,7 +904,10 @@ Document::Document(
|
|||
, _date(langDateTime(base::unixtime::parse(_data->date)))
|
||||
, _datew(st::normalFont->width(_date))
|
||||
, _colorIndex(documentColorIndex(_data, _ext)) {
|
||||
_name.setMarkedText(st::defaultTextStyle, ComposeNameWithEntities(_data), _documentNameOptions);
|
||||
_name.setMarkedText(
|
||||
st::defaultTextStyle,
|
||||
Ui::Text::FormatSongNameFor(_data).textWithEntities(),
|
||||
_documentNameOptions);
|
||||
|
||||
AddComponents(Info::Bit());
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "main/main_session.h"
|
||||
#include "mainwindow.h"
|
||||
#include "mainwidget.h"
|
||||
#include "ui/text/format_song_document_name.h"
|
||||
|
||||
#include <QtCore/QBuffer>
|
||||
#include <QtGui/QGuiApplication>
|
||||
|
@ -108,30 +109,21 @@ auto CreateMetadata(
|
|||
kFakeTrackPath.utf8().constData()));
|
||||
result["mpris:length"] = Glib::Variant<gint64>::create(
|
||||
state.length * 1000);
|
||||
result["xesam:title"] = Glib::Variant<Glib::ustring>::create(
|
||||
"Unknown Track");
|
||||
|
||||
const auto audioData = state.id.audio();
|
||||
const auto audioData = state.id.audio()
|
||||
? state.id.audio()
|
||||
: trackView
|
||||
? trackView->owner().get()
|
||||
: nullptr;
|
||||
if (audioData) {
|
||||
if (!audioData->filename().isEmpty()) {
|
||||
result["xesam:title"] = Glib::Variant<
|
||||
Glib::ustring
|
||||
>::create(audioData->filename().toStdString());
|
||||
}
|
||||
|
||||
if (audioData->isSong()) {
|
||||
const auto songData = audioData->song();
|
||||
if (!songData->performer.isEmpty()) {
|
||||
result["xesam:artist"] = Glib::Variant<
|
||||
std::vector<Glib::ustring>
|
||||
>::create({ songData->performer.toStdString() });
|
||||
}
|
||||
if (!songData->title.isEmpty()) {
|
||||
result["xesam:title"] = Glib::Variant<
|
||||
Glib::ustring
|
||||
>::create(songData->title.toStdString());
|
||||
}
|
||||
}
|
||||
const auto &[title, performer] =
|
||||
Ui::Text::FormatSongNameFor(audioData).composedName();
|
||||
result["xesam:title"] = Glib::Variant<
|
||||
Glib::ustring
|
||||
>::create(title.toStdString());
|
||||
result["xesam:artist"] = Glib::Variant<
|
||||
std::vector<Glib::ustring>
|
||||
>::create({ performer.toStdString() });
|
||||
}
|
||||
|
||||
if (trackView) {
|
||||
|
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/chat/attach/attach_single_file_preview.h"
|
||||
|
||||
#include "ui/chat/attach/attach_prepare.h"
|
||||
#include "ui/text/format_song_name.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/text/text_options.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
|
@ -115,7 +116,8 @@ void SingleFilePreview::preparePreview(const PreparedFile &file) {
|
|||
}
|
||||
}
|
||||
|
||||
_name = ComposeNameString(filename, songTitle, songPerformer);
|
||||
_name = Text::FormatSongName(filename, songTitle, songPerformer)
|
||||
.string();
|
||||
_statusText = FormatSizeText(fileinfo.size());
|
||||
}
|
||||
const auto &st = !isThumbedLayout()
|
||||
|
|
23
Telegram/SourceFiles/ui/text/format_song_document_name.cpp
Normal file
23
Telegram/SourceFiles/ui/text/format_song_document_name.cpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "ui/text/format_song_document_name.h"
|
||||
|
||||
#include "data/data_document.h"
|
||||
|
||||
namespace Ui::Text {
|
||||
|
||||
FormatSongName FormatSongNameFor(not_null<DocumentData*> document) {
|
||||
const auto song = document->song();
|
||||
|
||||
return FormatSongName(
|
||||
document->filename(),
|
||||
song ? song->title : QString(),
|
||||
song ? song->performer : QString());
|
||||
}
|
||||
|
||||
} // namespace Ui::Text
|
19
Telegram/SourceFiles/ui/text/format_song_document_name.h
Normal file
19
Telegram/SourceFiles/ui/text/format_song_document_name.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "ui/text/format_song_name.h"
|
||||
|
||||
class DocumentData;
|
||||
|
||||
namespace Ui::Text {
|
||||
|
||||
[[nodiscard]] FormatSongName FormatSongNameFor(
|
||||
not_null<DocumentData*> document);
|
||||
|
||||
} // namespace Ui::Text
|
76
Telegram/SourceFiles/ui/text/format_song_name.cpp
Normal file
76
Telegram/SourceFiles/ui/text/format_song_name.cpp
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "ui/text/format_song_name.h"
|
||||
|
||||
namespace Ui::Text {
|
||||
|
||||
namespace {
|
||||
|
||||
FormatSongName::ComposedName ComputeComposedName(
|
||||
const QString &filename,
|
||||
const QString &songTitle,
|
||||
const QString &songPerformer) {
|
||||
const auto unknown = u"Unknown Track"_q;
|
||||
if (songTitle.isEmpty() && songPerformer.isEmpty()) {
|
||||
return {
|
||||
.title = filename.isEmpty() ? unknown : filename,
|
||||
.performer = QString(),
|
||||
};
|
||||
}
|
||||
|
||||
if (songPerformer.isEmpty()) {
|
||||
return {
|
||||
.title = songTitle,
|
||||
.performer = QString(),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
.title = (songTitle.isEmpty() ? unknown : songTitle),
|
||||
.performer = songPerformer,
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
FormatSongName::FormatSongName(
|
||||
const QString &filename,
|
||||
const QString &songTitle,
|
||||
const QString &songPerformer)
|
||||
: _composedName(ComputeComposedName(filename, songTitle, songPerformer)) {
|
||||
}
|
||||
|
||||
FormatSongName::ComposedName FormatSongName::composedName() const {
|
||||
return _composedName;
|
||||
}
|
||||
|
||||
QString FormatSongName::string() const {
|
||||
const auto &[title, performer] = _composedName;
|
||||
const auto dash = (title.isEmpty() || performer.isEmpty())
|
||||
? QString()
|
||||
: QString::fromUtf8(" \xe2\x80\x93 ");
|
||||
return performer + dash + title;
|
||||
}
|
||||
|
||||
TextWithEntities FormatSongName::textWithEntities(
|
||||
bool boldOnlyPerformer) const {
|
||||
TextWithEntities result;
|
||||
result.text = string();
|
||||
if (!boldOnlyPerformer || !_composedName.performer.isEmpty()) {
|
||||
result.entities.push_back({
|
||||
EntityType::Semibold,
|
||||
0,
|
||||
_composedName.performer.isEmpty()
|
||||
? result.text.size()
|
||||
: _composedName.performer.size(),
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Ui::Text
|
34
Telegram/SourceFiles/ui/text/format_song_name.h
Normal file
34
Telegram/SourceFiles/ui/text/format_song_name.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace Ui::Text {
|
||||
|
||||
class FormatSongName final {
|
||||
public:
|
||||
struct ComposedName {
|
||||
QString title;
|
||||
QString performer;
|
||||
};
|
||||
|
||||
FormatSongName(
|
||||
const QString &filename,
|
||||
const QString &songTitle,
|
||||
const QString &songPerformer);
|
||||
|
||||
[[nodiscard]] ComposedName composedName() const;
|
||||
[[nodiscard]] QString string() const;
|
||||
[[nodiscard]] TextWithEntities textWithEntities(
|
||||
bool boldOnlyPerformer = false) const;
|
||||
|
||||
private:
|
||||
const ComposedName _composedName;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Ui::Text
|
|
@ -363,20 +363,4 @@ CurrencyRule LookupCurrencyRule(const QString ¤cy) {
|
|||
return result;
|
||||
}
|
||||
|
||||
QString ComposeNameString(
|
||||
const QString &filename,
|
||||
const QString &songTitle,
|
||||
const QString &songPerformer) {
|
||||
if (songTitle.isEmpty() && songPerformer.isEmpty()) {
|
||||
return filename.isEmpty() ? u"Unknown File"_q : filename;
|
||||
}
|
||||
|
||||
if (songPerformer.isEmpty()) {
|
||||
return songTitle;
|
||||
}
|
||||
|
||||
auto trackTitle = (songTitle.isEmpty() ? u"Unknown Track"_q : songTitle);
|
||||
return songPerformer + QString::fromUtf8(" \xe2\x80\x93 ") + trackTitle;
|
||||
}
|
||||
|
||||
} // namespace Ui
|
||||
|
|
|
@ -44,9 +44,4 @@ struct CurrencyRule {
|
|||
char decimal,
|
||||
char thousands);
|
||||
|
||||
[[nodiscard]] QString ComposeNameString(
|
||||
const QString &filename,
|
||||
const QString &songTitle,
|
||||
const QString &songPerformer);
|
||||
|
||||
} // namespace Ui
|
||||
|
|
|
@ -137,6 +137,8 @@ PRIVATE
|
|||
ui/controls/invite_link_label.h
|
||||
ui/controls/send_button.cpp
|
||||
ui/controls/send_button.h
|
||||
ui/text/format_song_name.cpp
|
||||
ui/text/format_song_name.h
|
||||
ui/text/format_values.cpp
|
||||
ui/text/format_values.h
|
||||
ui/text/text_options.cpp
|
||||
|
|
Loading…
Add table
Reference in a new issue