mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 02:01:40 -05:00
Showing in folder instead of launching media files with bad extensions.
Thanks for the report to: Sadegh Ahmadzadegan - Omid Ghaffarinia.
This commit is contained in:
parent
da293755ef
commit
8909943bd3
4 changed files with 44 additions and 6 deletions
|
@ -215,3 +215,23 @@ style::sprite documentCorner(int32 colorIndex) {
|
||||||
RoundCorners documentCorners(int32 colorIndex) {
|
RoundCorners documentCorners(int32 colorIndex) {
|
||||||
return RoundCorners(DocBlueCorners + (colorIndex & 3));
|
return RoundCorners(DocBlueCorners + (colorIndex & 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool documentIsValidMediaFile(const QString &filepath) {
|
||||||
|
static StaticNeverFreedPointer<QList<QString>> validMediaTypes(([] {
|
||||||
|
std_::unique_ptr<QList<QString>> result = std_::make_unique<QList<QString>>();
|
||||||
|
*result = qsl("\
|
||||||
|
webm mkv flv vob ogv ogg drc gif gifv mng avi mov qt wmv yuv rm rmvb asf amv mp4 m4p \
|
||||||
|
m4v mpg mp2 mpeg mpe mpv m2v svi 3gp 3g2 mxf roq nsv f4v f4p f4a f4b wma divx evo mk3d \
|
||||||
|
mka mks mcf m2p ps ts m2ts ifo aaf avchd cam dat dsh dvr-ms m1v fla flr sol wrap smi swf \
|
||||||
|
wtv 8svx 16svx iff aiff aif aifc au bwf cdda raw wav flac la pac m4a ape ofr ofs off rka \
|
||||||
|
shn tak tta wv brstm dts dtshd dtsma ast amr mp3 spx gsm aac mpc vqf ra ots swa vox voc \
|
||||||
|
dwd smp aup cust mid mus sib sid ly gym vgm psf nsf mod ptb s3m xm it mt2 minipsf psflib \
|
||||||
|
2sf dsf gsf psf2 qsf ssf usf rmj spc niff mxl xml txm ym jam mp1 mscz \
|
||||||
|
").split(' ');
|
||||||
|
return result.release();
|
||||||
|
})());
|
||||||
|
|
||||||
|
QFileInfo info(filepath);
|
||||||
|
auto parts = info.fileName().split('.', QString::SkipEmptyParts);
|
||||||
|
return !parts.isEmpty() && (validMediaTypes->indexOf(parts.back().toLower()) >= 0);
|
||||||
|
}
|
||||||
|
|
|
@ -81,6 +81,7 @@ style::color documentOverColor(int32 colorIndex);
|
||||||
style::color documentSelectedColor(int32 colorIndex);
|
style::color documentSelectedColor(int32 colorIndex);
|
||||||
style::sprite documentCorner(int32 colorIndex);
|
style::sprite documentCorner(int32 colorIndex);
|
||||||
RoundCorners documentCorners(int32 colorIndex);
|
RoundCorners documentCorners(int32 colorIndex);
|
||||||
|
bool documentIsValidMediaFile(const QString &filepath);
|
||||||
|
|
||||||
class PaintContextBase {
|
class PaintContextBase {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -1541,7 +1541,11 @@ void MainWidget::audioPlayProgress(const AudioMsgId &audioId) {
|
||||||
DocumentData *audio = audioId.audio;
|
DocumentData *audio = audioId.audio;
|
||||||
QString filepath = audio->filepath(DocumentData::FilePathResolveSaveFromData);
|
QString filepath = audio->filepath(DocumentData::FilePathResolveSaveFromData);
|
||||||
if (!filepath.isEmpty()) {
|
if (!filepath.isEmpty()) {
|
||||||
psOpenFile(filepath);
|
if (documentIsValidMediaFile(filepath)) {
|
||||||
|
psOpenFile(filepath);
|
||||||
|
} else {
|
||||||
|
psShowInFolder(filepath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1568,7 +1572,11 @@ void MainWidget::documentPlayProgress(const SongMsgId &songId) {
|
||||||
DocumentData *document = songId.song;
|
DocumentData *document = songId.song;
|
||||||
QString filepath = document->filepath(DocumentData::FilePathResolveSaveFromData);
|
QString filepath = document->filepath(DocumentData::FilePathResolveSaveFromData);
|
||||||
if (!filepath.isEmpty()) {
|
if (!filepath.isEmpty()) {
|
||||||
psOpenFile(filepath);
|
if (documentIsValidMediaFile(filepath)) {
|
||||||
|
psOpenFile(filepath);
|
||||||
|
} else {
|
||||||
|
psShowInFolder(filepath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -975,8 +975,13 @@ void DocumentOpenClickHandler::doOpen(DocumentData *data, ActionOnLoad action) {
|
||||||
audioPlayer()->play(song);
|
audioPlayer()->play(song);
|
||||||
if (App::main()) App::main()->documentPlayProgress(song);
|
if (App::main()) App::main()->documentPlayProgress(song);
|
||||||
}
|
}
|
||||||
} else if (data->voice() || data->isVideo()) {
|
} else if (data->voice() || data->song() || data->isVideo()) {
|
||||||
psOpenFile(location.name());
|
auto filepath = location.name();
|
||||||
|
if (documentIsValidMediaFile(filepath)) {
|
||||||
|
psOpenFile(filepath);
|
||||||
|
} else {
|
||||||
|
psShowInFolder(filepath);
|
||||||
|
}
|
||||||
if (App::main()) App::main()->mediaMarkRead(data);
|
if (App::main()) App::main()->mediaMarkRead(data);
|
||||||
} else if (data->size < MediaViewImageSizeLimit) {
|
} else if (data->size < MediaViewImageSizeLimit) {
|
||||||
if (!data->data().isEmpty() && playAnimation) {
|
if (!data->data().isEmpty() && playAnimation) {
|
||||||
|
@ -1270,8 +1275,12 @@ void DocumentData::performActionOnLoad() {
|
||||||
psOpenFile(already, true);
|
psOpenFile(already, true);
|
||||||
}
|
}
|
||||||
} else if (_actionOnLoad == ActionOnLoadOpen || _actionOnLoad == ActionOnLoadPlayInline) {
|
} else if (_actionOnLoad == ActionOnLoadOpen || _actionOnLoad == ActionOnLoadPlayInline) {
|
||||||
if (voice() || isVideo()) {
|
if (voice() || song() || isVideo()) {
|
||||||
psOpenFile(already);
|
if (documentIsValidMediaFile(already)) {
|
||||||
|
psOpenFile(already);
|
||||||
|
} else {
|
||||||
|
psShowInFolder(already);
|
||||||
|
}
|
||||||
if (App::main()) App::main()->mediaMarkRead(this);
|
if (App::main()) App::main()->mediaMarkRead(this);
|
||||||
} else if (loc.accessEnable()) {
|
} else if (loc.accessEnable()) {
|
||||||
if (showImage && QImageReader(loc.name()).canRead()) {
|
if (showImage && QImageReader(loc.name()).canRead()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue