2015-04-04 23:01:34 +03: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.
|
|
|
|
|
2015-10-03 16:16:42 +03:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2015-04-04 23:01:34 +03:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2015-10-03 16:16:42 +03:00
|
|
|
Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
|
2015-04-04 23:01:34 +03:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "style.h"
|
|
|
|
#include "lang.h"
|
|
|
|
|
|
|
|
#include "history.h"
|
|
|
|
#include "mainwidget.h"
|
|
|
|
#include "application.h"
|
|
|
|
#include "fileuploader.h"
|
|
|
|
#include "window.h"
|
|
|
|
#include "gui/filedialog.h"
|
|
|
|
|
2015-09-21 23:57:42 +03:00
|
|
|
#include "boxes/confirmbox.h"
|
|
|
|
|
2015-04-04 23:01:34 +03:00
|
|
|
#include "audio.h"
|
|
|
|
#include "localstorage.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
int32 peerColorIndex(const PeerId &peer) {
|
2015-09-03 13:48:40 +03:00
|
|
|
int32 myId(MTP::authedId()), peerId(peerToBareInt(peer));
|
2015-04-04 23:01:34 +03:00
|
|
|
QByteArray both(qsl("%1%2").arg(peerId).arg(myId).toUtf8());
|
|
|
|
if (both.size() > 15) {
|
|
|
|
both = both.mid(0, 15);
|
|
|
|
}
|
|
|
|
uchar md5[16];
|
|
|
|
hashMd5(both.constData(), both.size(), md5);
|
2015-09-03 13:48:40 +03:00
|
|
|
return (md5[peerId & 0x0F] & (peerIsUser(peer) ? 0x07 : 0x03));
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
style::color peerColor(int32 index) {
|
|
|
|
static const style::color peerColors[8] = {
|
|
|
|
style::color(st::color1),
|
|
|
|
style::color(st::color2),
|
|
|
|
style::color(st::color3),
|
|
|
|
style::color(st::color4),
|
|
|
|
style::color(st::color5),
|
|
|
|
style::color(st::color6),
|
|
|
|
style::color(st::color7),
|
|
|
|
style::color(st::color8)
|
|
|
|
};
|
|
|
|
return peerColors[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
ImagePtr userDefPhoto(int32 index) {
|
2015-12-13 01:29:33 +03:00
|
|
|
static const ImagePtr userDefPhotos[UserColorsCount] = {
|
2015-04-04 23:01:34 +03:00
|
|
|
ImagePtr(qsl(":/ava/art/usercolor1.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/usercolor2.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/usercolor3.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/usercolor4.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/usercolor5.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/usercolor6.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/usercolor7.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/usercolor8.png"), "PNG"),
|
|
|
|
};
|
|
|
|
return userDefPhotos[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
ImagePtr chatDefPhoto(int32 index) {
|
|
|
|
static const ImagePtr chatDefPhotos[4] = {
|
|
|
|
ImagePtr(qsl(":/ava/art/chatcolor1.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/chatcolor2.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/chatcolor3.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/chatcolor4.png"), "PNG"),
|
|
|
|
};
|
|
|
|
return chatDefPhotos[index];
|
|
|
|
}
|
|
|
|
|
2015-09-22 13:26:39 +03:00
|
|
|
ImagePtr channelDefPhoto(int32 index) {
|
|
|
|
static const ImagePtr channelDefPhotos[4] = {
|
|
|
|
ImagePtr(qsl(":/ava/art/channelcolor1.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/channelcolor2.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/channelcolor3.png"), "PNG"),
|
|
|
|
ImagePtr(qsl(":/ava/art/channelcolor4.png"), "PNG"),
|
|
|
|
};
|
|
|
|
return channelDefPhotos[index];
|
|
|
|
}
|
|
|
|
|
2015-04-04 23:01:34 +03:00
|
|
|
NotifySettings globalNotifyAll, globalNotifyUsers, globalNotifyChats;
|
|
|
|
NotifySettingsPtr globalNotifyAllPtr = UnknownNotifySettings, globalNotifyUsersPtr = UnknownNotifySettings, globalNotifyChatsPtr = UnknownNotifySettings;
|
|
|
|
|
2015-09-04 16:01:31 +03:00
|
|
|
PeerData::PeerData(const PeerId &id) : id(id), lnk(new PeerLink(this))
|
2015-04-04 23:01:34 +03:00
|
|
|
, loaded(false)
|
|
|
|
, colorIndex(peerColorIndex(id))
|
|
|
|
, color(peerColor(colorIndex))
|
2015-11-06 12:48:49 -05:00
|
|
|
, photo((isChat() || isMegagroup()) ? chatDefPhoto(colorIndex) : (isChannel() ? channelDefPhoto(colorIndex) : userDefPhoto(colorIndex)))
|
2015-08-07 15:11:50 +03:00
|
|
|
, photoId(UnknownPeerPhotoId)
|
2015-04-04 23:01:34 +03:00
|
|
|
, nameVersion(0)
|
|
|
|
, notify(UnknownNotifySettings)
|
|
|
|
{
|
2015-09-06 13:17:09 +03:00
|
|
|
if (!peerIsUser(id) && !peerIsChannel(id)) updateName(QString(), QString(), QString());
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void PeerData::updateName(const QString &newName, const QString &newNameOrPhone, const QString &newUsername) {
|
2015-09-16 16:04:08 +03:00
|
|
|
if (name == newName && nameVersion > 0) {
|
|
|
|
if (isUser()) {
|
|
|
|
if (asUser()->nameOrPhone == newNameOrPhone && asUser()->username == newUsername) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (isChannel()) {
|
|
|
|
if (asChannel()->username == newUsername) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (isChat()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-04-04 23:01:34 +03:00
|
|
|
|
|
|
|
++nameVersion;
|
|
|
|
name = newName;
|
2015-09-04 16:01:31 +03:00
|
|
|
nameText.setText(st::msgNameFont, name, _textNameOptions);
|
|
|
|
if (isUser()) {
|
|
|
|
asUser()->username = newUsername;
|
|
|
|
asUser()->setNameOrPhone(newNameOrPhone);
|
2015-09-13 22:15:45 +03:00
|
|
|
} else if (isChannel()) {
|
2015-09-23 20:43:08 +03:00
|
|
|
if (asChannel()->username != newUsername) {
|
|
|
|
asChannel()->username = newUsername;
|
|
|
|
if (newUsername.isEmpty()) {
|
|
|
|
asChannel()->flags &= ~MTPDchannel::flag_username;
|
|
|
|
} else {
|
|
|
|
asChannel()->flags |= MTPDchannel::flag_username;
|
|
|
|
}
|
|
|
|
if (App::main()) {
|
|
|
|
App::main()->peerUsernameChanged(this);
|
|
|
|
}
|
|
|
|
}
|
2015-09-04 16:01:31 +03:00
|
|
|
}
|
2015-09-03 13:48:40 +03:00
|
|
|
|
2015-04-04 23:01:34 +03:00
|
|
|
Names oldNames = names;
|
|
|
|
NameFirstChars oldChars = chars;
|
|
|
|
fillNames();
|
2015-09-04 16:01:31 +03:00
|
|
|
|
2015-04-04 23:01:34 +03:00
|
|
|
if (App::main()) {
|
|
|
|
emit App::main()->peerNameChanged(this, oldNames, oldChars);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-20 17:05:07 +03:00
|
|
|
const Text &BotCommand::descriptionText() const {
|
|
|
|
if (_descriptionText.isEmpty() && !_description.isEmpty()) {
|
|
|
|
_descriptionText.setText(st::mentionFont, _description, _textNameOptions);
|
|
|
|
}
|
|
|
|
return _descriptionText;
|
|
|
|
}
|
|
|
|
|
2015-08-07 15:11:50 +03:00
|
|
|
void UserData::setPhoto(const MTPUserProfilePhoto &p) { // see Local::readPeer as well
|
2015-06-30 01:09:23 +03:00
|
|
|
PhotoId newPhotoId = photoId;
|
|
|
|
ImagePtr newPhoto = photo;
|
2015-08-07 15:11:50 +03:00
|
|
|
StorageImageLocation newPhotoLoc = photoLoc;
|
2015-04-04 23:01:34 +03:00
|
|
|
switch (p.type()) {
|
|
|
|
case mtpc_userProfilePhoto: {
|
|
|
|
const MTPDuserProfilePhoto d(p.c_userProfilePhoto());
|
2015-06-30 01:09:23 +03:00
|
|
|
newPhotoId = d.vphoto_id.v;
|
2015-08-07 15:11:50 +03:00
|
|
|
newPhotoLoc = App::imageLocation(160, 160, d.vphoto_small);
|
|
|
|
newPhoto = newPhotoLoc.isNull() ? userDefPhoto(colorIndex) : ImagePtr(newPhotoLoc);
|
2015-09-03 13:48:40 +03:00
|
|
|
//App::feedPhoto(App::photoFromUserPhoto(peerToUser(id), MTP_int(unixtime()), p));
|
2015-04-04 23:01:34 +03:00
|
|
|
} break;
|
|
|
|
default: {
|
2015-06-30 01:09:23 +03:00
|
|
|
newPhotoId = 0;
|
2015-04-04 23:01:34 +03:00
|
|
|
if (id == ServiceUserId) {
|
2015-06-30 01:09:23 +03:00
|
|
|
if (photo->isNull()) {
|
|
|
|
newPhoto = ImagePtr(QPixmap::fromImage(App::wnd()->iconLarge().scaledToWidth(160, Qt::SmoothTransformation), Qt::ColorOnly), "PNG");
|
|
|
|
}
|
2015-04-04 23:01:34 +03:00
|
|
|
} else {
|
2015-06-30 01:09:23 +03:00
|
|
|
newPhoto = userDefPhoto(colorIndex);
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
2015-08-07 15:11:50 +03:00
|
|
|
newPhotoLoc = StorageImageLocation();
|
2015-04-04 23:01:34 +03:00
|
|
|
} break;
|
|
|
|
}
|
2015-08-07 15:11:50 +03:00
|
|
|
if (newPhotoId != photoId || newPhoto.v() != photo.v() || newPhotoLoc != photoLoc) {
|
2015-06-30 01:09:23 +03:00
|
|
|
photoId = newPhotoId;
|
|
|
|
photo = newPhoto;
|
2015-08-07 15:11:50 +03:00
|
|
|
photoLoc = newPhotoLoc;
|
2015-06-30 01:09:23 +03:00
|
|
|
emit App::main()->peerPhotoChanged(this);
|
|
|
|
}
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void PeerData::fillNames() {
|
|
|
|
names.clear();
|
|
|
|
chars.clear();
|
|
|
|
QString toIndex = textAccentFold(name);
|
2015-09-03 13:48:40 +03:00
|
|
|
if (isUser()) {
|
2015-09-04 16:01:31 +03:00
|
|
|
if (!asUser()->nameOrPhone.isEmpty() && asUser()->nameOrPhone != name) toIndex += ' ' + textAccentFold(asUser()->nameOrPhone);
|
|
|
|
if (!asUser()->username.isEmpty()) toIndex += ' ' + textAccentFold(asUser()->username);
|
2015-09-13 22:15:45 +03:00
|
|
|
} else if (isChannel()) {
|
|
|
|
if (!asChannel()->username.isEmpty()) toIndex += ' ' + textAccentFold(asChannel()->username);
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
if (cRussianLetters().match(toIndex).hasMatch()) {
|
|
|
|
toIndex += ' ' + translitRusEng(toIndex);
|
|
|
|
}
|
|
|
|
toIndex += ' ' + rusKeyboardLayoutSwitch(toIndex);
|
|
|
|
|
|
|
|
QStringList namesList = toIndex.toLower().split(cWordSplit(), QString::SkipEmptyParts);
|
|
|
|
for (QStringList::const_iterator i = namesList.cbegin(), e = namesList.cend(); i != e; ++i) {
|
|
|
|
names.insert(*i);
|
|
|
|
chars.insert(i->at(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserData::setName(const QString &first, const QString &last, const QString &phoneName, const QString &usern) {
|
|
|
|
bool updName = !first.isEmpty() || !last.isEmpty(), updUsername = (username != usern);
|
|
|
|
|
|
|
|
if (updName && first.trimmed().isEmpty()) {
|
|
|
|
firstName = last;
|
|
|
|
lastName = QString();
|
|
|
|
updateName(firstName, phoneName, usern);
|
|
|
|
} else {
|
|
|
|
if (updName) {
|
|
|
|
firstName = first;
|
|
|
|
lastName = last;
|
|
|
|
}
|
2015-09-23 20:43:08 +03:00
|
|
|
updateName(lastName.isEmpty() ? firstName : lng_full_name(lt_first_name, firstName, lt_last_name, lastName), phoneName, usern);
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
if (updUsername) {
|
|
|
|
if (App::main()) {
|
|
|
|
App::main()->peerUsernameChanged(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserData::setPhone(const QString &newPhone) {
|
|
|
|
phone = newPhone;
|
|
|
|
}
|
|
|
|
|
2015-06-10 15:48:26 +03:00
|
|
|
void UserData::setBotInfoVersion(int32 version) {
|
2015-06-15 20:19:24 +03:00
|
|
|
if (version < 0) {
|
2015-11-20 16:34:37 +03:00
|
|
|
if (botInfo) {
|
|
|
|
if (!botInfo->commands.isEmpty()) {
|
|
|
|
botInfo->commands.clear();
|
|
|
|
Notify::botCommandsChanged(this);
|
|
|
|
}
|
|
|
|
delete botInfo;
|
|
|
|
botInfo = 0;
|
|
|
|
Notify::userIsBotChanged(this);
|
|
|
|
}
|
2015-06-15 20:19:24 +03:00
|
|
|
} else if (!botInfo) {
|
2015-06-10 15:48:26 +03:00
|
|
|
botInfo = new BotInfo();
|
|
|
|
botInfo->version = version;
|
2015-11-20 16:34:37 +03:00
|
|
|
Notify::userIsBotChanged(this);
|
2015-06-10 15:48:26 +03:00
|
|
|
} else if (botInfo->version < version) {
|
2015-07-03 18:55:22 +03:00
|
|
|
if (!botInfo->commands.isEmpty()) {
|
|
|
|
botInfo->commands.clear();
|
2015-11-20 16:34:37 +03:00
|
|
|
Notify::botCommandsChanged(this);
|
2015-07-03 18:55:22 +03:00
|
|
|
}
|
2015-06-10 15:48:26 +03:00
|
|
|
botInfo->description.clear();
|
|
|
|
botInfo->shareText.clear();
|
|
|
|
botInfo->version = version;
|
2015-06-10 18:54:24 +03:00
|
|
|
botInfo->inited = false;
|
2015-06-10 15:48:26 +03:00
|
|
|
}
|
|
|
|
}
|
2015-08-07 15:11:50 +03:00
|
|
|
|
2015-06-10 15:48:26 +03:00
|
|
|
void UserData::setBotInfo(const MTPBotInfo &info) {
|
|
|
|
switch (info.type()) {
|
|
|
|
case mtpc_botInfoEmpty:
|
2015-11-20 16:34:37 +03:00
|
|
|
if (botInfo) {
|
|
|
|
if (!botInfo->commands.isEmpty()) {
|
|
|
|
botInfo->commands.clear();
|
|
|
|
Notify::botCommandsChanged(this);
|
|
|
|
}
|
|
|
|
delete botInfo;
|
|
|
|
botInfo = 0;
|
|
|
|
Notify::userIsBotChanged(this);
|
2015-07-03 18:55:22 +03:00
|
|
|
}
|
2015-06-10 15:48:26 +03:00
|
|
|
break;
|
|
|
|
case mtpc_botInfo: {
|
|
|
|
const MTPDbotInfo &d(info.c_botInfo());
|
2015-09-03 13:48:40 +03:00
|
|
|
if (peerFromUser(d.vuser_id.v) != id) return;
|
2015-06-10 18:54:24 +03:00
|
|
|
|
|
|
|
if (botInfo) {
|
|
|
|
botInfo->version = d.vversion.v;
|
|
|
|
} else {
|
|
|
|
setBotInfoVersion(d.vversion.v);
|
|
|
|
}
|
|
|
|
|
2015-06-15 20:19:24 +03:00
|
|
|
QString desc = qs(d.vdescription);
|
2015-06-10 18:54:24 +03:00
|
|
|
if (botInfo->description != desc) {
|
|
|
|
botInfo->description = desc;
|
2015-06-15 20:19:24 +03:00
|
|
|
botInfo->text = Text(st::msgMinWidth);
|
2015-06-10 18:54:24 +03:00
|
|
|
}
|
2015-06-10 15:48:26 +03:00
|
|
|
botInfo->shareText = qs(d.vshare_text);
|
|
|
|
|
|
|
|
const QVector<MTPBotCommand> &v(d.vcommands.c_vector().v);
|
|
|
|
botInfo->commands.reserve(v.size());
|
2015-07-03 18:55:22 +03:00
|
|
|
bool changedCommands = false;
|
|
|
|
int32 j = 0;
|
2015-06-10 15:48:26 +03:00
|
|
|
for (int32 i = 0, l = v.size(); i < l; ++i) {
|
2015-07-03 18:55:22 +03:00
|
|
|
if (v.at(i).type() != mtpc_botCommand) continue;
|
|
|
|
|
|
|
|
QString cmd = qs(v.at(i).c_botCommand().vcommand), desc = qs(v.at(i).c_botCommand().vdescription);
|
|
|
|
if (botInfo->commands.size() <= j) {
|
|
|
|
botInfo->commands.push_back(BotCommand(cmd, desc));
|
|
|
|
changedCommands = true;
|
|
|
|
} else {
|
|
|
|
if (botInfo->commands[j].command != cmd) {
|
|
|
|
botInfo->commands[j].command = cmd;
|
|
|
|
changedCommands = true;
|
|
|
|
}
|
|
|
|
if (botInfo->commands[j].setDescription(desc)) {
|
|
|
|
changedCommands = true;
|
|
|
|
}
|
2015-06-10 15:48:26 +03:00
|
|
|
}
|
2015-07-03 18:55:22 +03:00
|
|
|
++j;
|
|
|
|
}
|
|
|
|
while (j < botInfo->commands.size()) {
|
|
|
|
botInfo->commands.pop_back();
|
|
|
|
changedCommands = true;
|
2015-06-10 15:48:26 +03:00
|
|
|
}
|
2015-06-10 18:54:24 +03:00
|
|
|
|
|
|
|
botInfo->inited = true;
|
2015-07-03 18:55:22 +03:00
|
|
|
|
2015-11-20 16:34:37 +03:00
|
|
|
if (changedCommands) {
|
|
|
|
Notify::botCommandsChanged(this);
|
2015-07-03 18:55:22 +03:00
|
|
|
}
|
2015-06-10 15:48:26 +03:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-04 16:01:31 +03:00
|
|
|
void UserData::setNameOrPhone(const QString &newNameOrPhone) {
|
|
|
|
if (nameOrPhone != newNameOrPhone) {
|
|
|
|
nameOrPhone = newNameOrPhone;
|
|
|
|
phoneText.setText(st::msgNameFont, nameOrPhone, _textNameOptions);
|
|
|
|
}
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
2015-06-10 15:48:26 +03:00
|
|
|
void UserData::madeAction() {
|
2015-06-24 20:24:48 +03:00
|
|
|
if (botInfo || isServiceUser(id)) return;
|
|
|
|
|
2015-06-10 15:48:26 +03:00
|
|
|
int32 t = unixtime();
|
|
|
|
if (onlineTill <= 0 && -onlineTill < t) {
|
|
|
|
onlineTill = -t - SetOnlineAfterActivity;
|
2015-06-30 01:09:23 +03:00
|
|
|
App::markPeerUpdated(this);
|
2015-06-10 15:48:26 +03:00
|
|
|
} else if (onlineTill > 0 && onlineTill < t + 1) {
|
|
|
|
onlineTill = t + SetOnlineAfterActivity;
|
2015-06-30 01:09:23 +03:00
|
|
|
App::markPeerUpdated(this);
|
2015-06-10 15:48:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-07 15:11:50 +03:00
|
|
|
void ChatData::setPhoto(const MTPChatPhoto &p, const PhotoId &phId) { // see Local::readPeer as well
|
|
|
|
PhotoId newPhotoId = photoId;
|
|
|
|
ImagePtr newPhoto = photo;
|
|
|
|
StorageImageLocation newPhotoLoc = photoLoc;
|
2015-04-04 23:01:34 +03:00
|
|
|
switch (p.type()) {
|
|
|
|
case mtpc_chatPhoto: {
|
|
|
|
const MTPDchatPhoto d(p.c_chatPhoto());
|
2015-06-30 01:09:23 +03:00
|
|
|
if (phId != UnknownPeerPhotoId) {
|
2015-08-07 15:11:50 +03:00
|
|
|
newPhotoId = phId;
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
2015-08-07 15:11:50 +03:00
|
|
|
newPhotoLoc = App::imageLocation(160, 160, d.vphoto_small);
|
|
|
|
newPhoto = newPhotoLoc.isNull() ? chatDefPhoto(colorIndex) : ImagePtr(newPhotoLoc);
|
|
|
|
// photoFull = ImagePtr(640, 640, d.vphoto_big, chatDefPhoto(colorIndex));
|
2015-04-04 23:01:34 +03:00
|
|
|
} break;
|
|
|
|
default: {
|
2015-08-07 15:11:50 +03:00
|
|
|
newPhotoId = 0;
|
|
|
|
newPhotoLoc = StorageImageLocation();
|
|
|
|
newPhoto = chatDefPhoto(colorIndex);
|
|
|
|
// photoFull = ImagePtr();
|
2015-04-04 23:01:34 +03:00
|
|
|
} break;
|
|
|
|
}
|
2015-08-07 15:11:50 +03:00
|
|
|
if (newPhotoId != photoId || newPhoto.v() != photo.v() || newPhotoLoc != photoLoc) {
|
|
|
|
photoId = newPhotoId;
|
|
|
|
photo = newPhoto;
|
|
|
|
photoLoc = newPhotoLoc;
|
|
|
|
emit App::main()->peerPhotoChanged(this);
|
|
|
|
}
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
2015-09-03 13:48:40 +03:00
|
|
|
void ChannelData::setPhoto(const MTPChatPhoto &p, const PhotoId &phId) { // see Local::readPeer as well
|
|
|
|
PhotoId newPhotoId = photoId;
|
|
|
|
ImagePtr newPhoto = photo;
|
|
|
|
StorageImageLocation newPhotoLoc = photoLoc;
|
|
|
|
switch (p.type()) {
|
|
|
|
case mtpc_chatPhoto: {
|
|
|
|
const MTPDchatPhoto d(p.c_chatPhoto());
|
|
|
|
if (phId != UnknownPeerPhotoId) {
|
|
|
|
newPhotoId = phId;
|
|
|
|
}
|
|
|
|
newPhotoLoc = App::imageLocation(160, 160, d.vphoto_small);
|
2015-11-06 12:48:49 -05:00
|
|
|
newPhoto = newPhotoLoc.isNull() ? (isMegagroup() ? chatDefPhoto(colorIndex) : channelDefPhoto(colorIndex)) : ImagePtr(newPhotoLoc);
|
|
|
|
// photoFull = ImagePtr(640, 640, d.vphoto_big, (isMegagroup() ? chatDefPhoto(colorIndex) : channelDefPhoto(colorIndex)));
|
2015-09-03 13:48:40 +03:00
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
newPhotoId = 0;
|
|
|
|
newPhotoLoc = StorageImageLocation();
|
2015-11-06 12:48:49 -05:00
|
|
|
newPhoto = (isMegagroup() ? chatDefPhoto(colorIndex) : channelDefPhoto(colorIndex));
|
2015-09-03 13:48:40 +03:00
|
|
|
// photoFull = ImagePtr();
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
if (newPhotoId != photoId || newPhoto.v() != photo.v() || newPhotoLoc != photoLoc) {
|
|
|
|
photoId = newPhotoId;
|
|
|
|
photo = newPhoto;
|
|
|
|
photoLoc = newPhotoLoc;
|
2015-10-03 14:33:51 +03:00
|
|
|
if (App::main()) emit App::main()->peerPhotoChanged(this);
|
2015-09-03 13:48:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-06 13:17:09 +03:00
|
|
|
void ChannelData::setName(const QString &newName, const QString &usern) {
|
|
|
|
bool updName = !newName.isEmpty(), updUsername = (username != usern);
|
|
|
|
|
|
|
|
updateName(newName.isEmpty() ? name : newName, QString(), usern);
|
|
|
|
}
|
|
|
|
|
2015-09-23 20:43:08 +03:00
|
|
|
void ChannelData::updateFull(bool force) {
|
|
|
|
if (!_lastFullUpdate || force || getms(true) > _lastFullUpdate + UpdateFullChannelTimeout) {
|
2015-10-03 14:33:51 +03:00
|
|
|
if (App::api()) {
|
|
|
|
App::api()->requestFullPeer(this);
|
|
|
|
if (!amCreator() && !inviter) App::api()->requestSelfParticipant(this);
|
|
|
|
}
|
2015-09-21 23:57:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelData::fullUpdated() {
|
|
|
|
_lastFullUpdate = getms(true);
|
|
|
|
}
|
|
|
|
|
2015-11-13 18:14:33 +03:00
|
|
|
void ChannelData::flagsUpdated() {
|
|
|
|
if (isMegagroup()) {
|
|
|
|
if (!mgInfo) {
|
|
|
|
mgInfo = new MegagroupInfo();
|
|
|
|
}
|
|
|
|
if (History *h = App::historyLoaded(id)) {
|
|
|
|
if (h->asChannelHistory()->onlyImportant()) {
|
|
|
|
MsgId fixInScrollMsgId = 0;
|
|
|
|
int32 fixInScrollMsgTop = 0;
|
|
|
|
h->asChannelHistory()->getSwitchReadyFor(SwitchAtTopMsgId, fixInScrollMsgId, fixInScrollMsgTop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (mgInfo) {
|
|
|
|
delete mgInfo;
|
|
|
|
mgInfo = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-06 12:48:49 -05:00
|
|
|
ChannelData::~ChannelData() {
|
|
|
|
delete mgInfo;
|
|
|
|
}
|
|
|
|
|
2015-09-13 11:41:27 +03:00
|
|
|
uint64 PtsWaiter::ptsKey(PtsSkippedQueue queue) {
|
|
|
|
return _queue.insert(uint64(uint32(_last)) << 32 | uint64(uint32(_count)), queue).key();
|
|
|
|
}
|
|
|
|
|
2015-09-20 12:54:22 +03:00
|
|
|
void PtsWaiter::setWaitingForSkipped(ChannelData *channel, int32 ms) {
|
|
|
|
if (ms >= 0) {
|
|
|
|
if (App::main()) {
|
|
|
|
App::main()->ptsWaiterStartTimerFor(channel, ms);
|
|
|
|
}
|
|
|
|
_waitingForSkipped = true;
|
|
|
|
} else {
|
|
|
|
_waitingForSkipped = false;
|
|
|
|
checkForWaiting(channel);
|
|
|
|
}
|
2015-09-20 11:55:41 +03:00
|
|
|
}
|
|
|
|
|
2015-09-20 12:54:22 +03:00
|
|
|
void PtsWaiter::setWaitingForShortPoll(ChannelData *channel, int32 ms) {
|
|
|
|
if (ms >= 0) {
|
|
|
|
if (App::main()) {
|
|
|
|
App::main()->ptsWaiterStartTimerFor(channel, ms);
|
|
|
|
}
|
|
|
|
_waitingForShortPoll = true;
|
|
|
|
} else {
|
|
|
|
_waitingForShortPoll = false;
|
|
|
|
checkForWaiting(channel);
|
|
|
|
}
|
2015-09-20 11:55:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void PtsWaiter::checkForWaiting(ChannelData *channel) {
|
|
|
|
if (!_waitingForSkipped && !_waitingForShortPoll && App::main()) {
|
|
|
|
App::main()->ptsWaiterStartTimerFor(channel, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-13 11:41:27 +03:00
|
|
|
void PtsWaiter::applySkippedUpdates(ChannelData *channel) {
|
2015-09-20 12:54:22 +03:00
|
|
|
if (!_waitingForSkipped) return;
|
|
|
|
|
|
|
|
setWaitingForSkipped(channel, -1);
|
2015-09-20 11:55:41 +03:00
|
|
|
|
|
|
|
if (!App::main() || _queue.isEmpty()) return;
|
2015-09-13 11:41:27 +03:00
|
|
|
|
|
|
|
++_applySkippedLevel;
|
|
|
|
for (QMap<uint64, PtsSkippedQueue>::const_iterator i = _queue.cbegin(), e = _queue.cend(); i != e; ++i) {
|
|
|
|
switch (i.value()) {
|
|
|
|
case SkippedUpdate: App::main()->feedUpdate(_updateQueue.value(i.key())); break;
|
2015-09-21 23:57:42 +03:00
|
|
|
case SkippedUpdates: App::main()->feedUpdates(_updatesQueue.value(i.key())); break;
|
2015-09-13 11:41:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
--_applySkippedLevel;
|
|
|
|
clearSkippedUpdates();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PtsWaiter::clearSkippedUpdates() {
|
|
|
|
_queue.clear();
|
|
|
|
_updateQueue.clear();
|
|
|
|
_updatesQueue.clear();
|
|
|
|
_applySkippedLevel = 0;
|
|
|
|
}
|
|
|
|
|
2015-09-21 23:57:42 +03:00
|
|
|
bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count) {
|
|
|
|
if (_requesting || _applySkippedLevel) {
|
|
|
|
return true;
|
2015-09-28 17:19:37 +03:00
|
|
|
} else if (pts <= _good && count > 0) {
|
2015-09-21 23:57:42 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return check(channel, pts, count);
|
|
|
|
}
|
|
|
|
|
2015-09-28 17:19:37 +03:00
|
|
|
bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count, const MTPUpdates &updates) {
|
2015-09-21 23:57:42 +03:00
|
|
|
if (_requesting || _applySkippedLevel) {
|
|
|
|
return true;
|
2015-09-28 17:19:37 +03:00
|
|
|
} else if (pts <= _good && count > 0) {
|
2015-09-21 23:57:42 +03:00
|
|
|
return false;
|
2015-09-28 17:19:37 +03:00
|
|
|
} else if (check(channel, pts, count)) {
|
2015-09-21 23:57:42 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
_updatesQueue.insert(ptsKey(SkippedUpdates), updates);
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-13 11:41:27 +03:00
|
|
|
|
2015-09-28 17:19:37 +03:00
|
|
|
bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count, const MTPUpdate &update) {
|
2015-09-21 23:57:42 +03:00
|
|
|
if (_requesting || _applySkippedLevel) {
|
|
|
|
return true;
|
2015-09-28 17:19:37 +03:00
|
|
|
} else if (pts <= _good && count > 0) {
|
2015-09-21 23:57:42 +03:00
|
|
|
return false;
|
2015-09-28 17:19:37 +03:00
|
|
|
} else if (check(channel, pts, count)) {
|
2015-09-21 23:57:42 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
_updateQueue.insert(ptsKey(SkippedUpdate), update);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PtsWaiter::check(ChannelData *channel, int32 pts, int32 count) { // return false if need to save that update and apply later
|
2015-09-13 11:41:27 +03:00
|
|
|
if (!inited()) {
|
|
|
|
init(pts);
|
|
|
|
return true;
|
|
|
|
}
|
2015-09-21 23:57:42 +03:00
|
|
|
|
2015-09-13 11:41:27 +03:00
|
|
|
_last = qMax(_last, pts);
|
|
|
|
_count += count;
|
|
|
|
if (_last == _count) {
|
|
|
|
_good = _last;
|
|
|
|
return true;
|
|
|
|
} else if (_last < _count) {
|
2015-09-20 12:54:22 +03:00
|
|
|
setWaitingForSkipped(channel, 1);
|
2015-09-13 11:41:27 +03:00
|
|
|
} else {
|
2015-09-20 12:54:22 +03:00
|
|
|
setWaitingForSkipped(channel, WaitForSkippedTimeout);
|
2015-09-13 11:41:27 +03:00
|
|
|
}
|
|
|
|
return !count;
|
|
|
|
}
|
|
|
|
|
2015-04-04 23:01:34 +03:00
|
|
|
void PhotoLink::onClick(Qt::MouseButton button) const {
|
|
|
|
if (button == Qt::LeftButton) {
|
|
|
|
App::wnd()->showPhoto(this, App::hoveredLinkItem());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-19 13:29:19 +03:00
|
|
|
QString saveFileName(const QString &title, const QString &filter, const QString &prefix, QString name, bool savingAs, const QDir &dir) {
|
2015-04-04 23:01:34 +03:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
name = name.replace(QRegularExpression(qsl("[\\\\\\/\\:\\*\\?\\\"\\<\\>\\|]")), qsl("_"));
|
|
|
|
#elif defined Q_OS_MAC
|
|
|
|
name = name.replace(QRegularExpression(qsl("[\\:]")), qsl("_"));
|
|
|
|
#elif defined Q_OS_LINUX
|
|
|
|
name = name.replace(QRegularExpression(qsl("[\\/]")), qsl("_"));
|
|
|
|
#endif
|
|
|
|
if (cAskDownloadPath() || savingAs) {
|
|
|
|
if (!name.isEmpty() && name.at(0) == QChar::fromLatin1('.')) {
|
|
|
|
name = filedialogDefaultName(prefix, name);
|
|
|
|
} else if (dir.path() != qsl(".")) {
|
|
|
|
QString path = dir.absolutePath();
|
|
|
|
if (path != cDialogLastPath()) {
|
|
|
|
cSetDialogLastPath(path);
|
|
|
|
Local::writeUserSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 13:38:00 +02:00
|
|
|
// check if extension of filename is present in filter
|
|
|
|
// it should be in first filter section on the first place
|
|
|
|
// place it there, if it is not
|
|
|
|
QString ext = QFileInfo(name).suffix(), fil = filter, sep = qsl(";;");
|
|
|
|
if (!ext.isEmpty()) {
|
|
|
|
if (QRegularExpression(qsl("^[a-zA-Z_0-9]+$")).match(ext).hasMatch()) {
|
|
|
|
QStringList filters = filter.split(sep);
|
|
|
|
if (filters.size() > 1) {
|
|
|
|
QString first = filters.at(0);
|
|
|
|
int32 start = first.indexOf(qsl("(*."));
|
|
|
|
if (start >= 0) {
|
|
|
|
if (!QRegularExpression(qsl("\\(\\*\\.") + ext + qsl("[\\)\\s]"), QRegularExpression::CaseInsensitiveOption).match(first).hasMatch()) {
|
|
|
|
QRegularExpressionMatch m = QRegularExpression(qsl(" \\*\\.") + ext + qsl("[\\)\\s]"), QRegularExpression::CaseInsensitiveOption).match(first);
|
|
|
|
if (m.hasMatch() && m.capturedStart() > start + 3) {
|
|
|
|
int32 oldpos = m.capturedStart(), oldend = m.capturedEnd();
|
|
|
|
fil = first.mid(0, start + 3) + ext + qsl(" *.") + first.mid(start + 3, oldpos - start - 3) + first.mid(oldend - 1) + sep + filters.mid(1).join(sep);
|
|
|
|
} else {
|
|
|
|
fil = first.mid(0, start + 3) + ext + qsl(" *.") + first.mid(start + 3) + sep + filters.mid(1).join(sep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fil = QString();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fil = QString();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fil = QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return filedialogGetSaveFile(name, title, fil, name) ? name : QString();
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QString path;
|
|
|
|
if (cDownloadPath().isEmpty()) {
|
|
|
|
path = psDownloadPath();
|
|
|
|
} else if (cDownloadPath() == qsl("tmp")) {
|
|
|
|
path = cTempDir();
|
|
|
|
} else {
|
|
|
|
path = cDownloadPath();
|
|
|
|
}
|
|
|
|
if (name.isEmpty()) name = qsl(".unknown");
|
|
|
|
if (name.at(0) == QChar::fromLatin1('.')) {
|
|
|
|
if (!QDir().exists(path)) QDir().mkpath(path);
|
|
|
|
return filedialogDefaultName(prefix, name, path);
|
|
|
|
}
|
|
|
|
if (dir.path() != qsl(".")) {
|
|
|
|
path = dir.absolutePath() + '/';
|
|
|
|
}
|
|
|
|
|
|
|
|
QString nameStart, extension;
|
|
|
|
int32 extPos = name.lastIndexOf('.');
|
|
|
|
if (extPos >= 0) {
|
|
|
|
nameStart = name.mid(0, extPos);
|
|
|
|
extension = name.mid(extPos);
|
|
|
|
} else {
|
|
|
|
nameStart = name;
|
|
|
|
}
|
|
|
|
QString nameBase = path + nameStart;
|
|
|
|
name = nameBase + extension;
|
|
|
|
for (int i = 0; QFileInfo(name).exists(); ++i) {
|
|
|
|
name = nameBase + QString(" (%1)").arg(i + 2) + extension;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!QDir().exists(path)) QDir().mkpath(path);
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoOpenLink::onClick(Qt::MouseButton button) const {
|
|
|
|
VideoData *data = video();
|
2015-08-12 21:01:32 +03:00
|
|
|
if (!data->date || button != Qt::LeftButton) return;
|
2015-04-04 23:01:34 +03:00
|
|
|
|
|
|
|
QString already = data->already(true);
|
|
|
|
if (!already.isEmpty()) {
|
|
|
|
psOpenFile(already);
|
2015-04-30 16:53:36 +03:00
|
|
|
if (App::main()) App::main()->videoMarkRead(data);
|
2015-04-04 23:01:34 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->status != FileReady) return;
|
|
|
|
|
|
|
|
QString filename = saveFileName(lang(lng_save_video), qsl("MOV Video (*.mov);;All files (*.*)"), qsl("video"), qsl(".mov"), false);
|
|
|
|
if (!filename.isEmpty()) {
|
|
|
|
data->openOnSave = 1;
|
2015-09-03 13:48:40 +03:00
|
|
|
data->openOnSaveMsgId = App::hoveredLinkItem() ? App::hoveredLinkItem()->fullId() : (App::contextItem() ? App::contextItem()->fullId() : FullMsgId());
|
2015-04-04 23:01:34 +03:00
|
|
|
data->save(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-19 13:29:19 +03:00
|
|
|
void VideoSaveLink::doSave(VideoData *data, bool forceSavingAs) {
|
2015-08-12 21:01:32 +03:00
|
|
|
if (!data->date) return;
|
2015-04-04 23:01:34 +03:00
|
|
|
|
|
|
|
QString already = data->already(true);
|
|
|
|
if (!already.isEmpty() && !forceSavingAs) {
|
|
|
|
QPoint pos(QCursor::pos());
|
|
|
|
if (!psShowOpenWithMenu(pos.x(), pos.y(), already)) {
|
|
|
|
psOpenFile(already, true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
QFileInfo alreadyInfo(already);
|
|
|
|
QDir alreadyDir(already.isEmpty() ? QDir() : alreadyInfo.dir());
|
|
|
|
QString name = already.isEmpty() ? QString(".mov") : alreadyInfo.fileName();
|
|
|
|
QString filename = saveFileName(lang(lng_save_video), qsl("MOV Video (*.mov);;All files (*.*)"), qsl("video"), name, forceSavingAs, alreadyDir);
|
|
|
|
if (!filename.isEmpty()) {
|
|
|
|
if (forceSavingAs) {
|
|
|
|
data->cancel();
|
|
|
|
} else if (!already.isEmpty()) {
|
|
|
|
data->openOnSave = -1;
|
2015-09-03 13:48:40 +03:00
|
|
|
data->openOnSaveMsgId = App::hoveredLinkItem() ? App::hoveredLinkItem()->fullId() : FullMsgId();
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
data->save(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoSaveLink::onClick(Qt::MouseButton button) const {
|
|
|
|
if (button != Qt::LeftButton) return;
|
2015-04-19 13:29:19 +03:00
|
|
|
doSave(video());
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoCancelLink::onClick(Qt::MouseButton button) const {
|
|
|
|
VideoData *data = video();
|
2015-08-12 21:01:32 +03:00
|
|
|
if (!data->date || button != Qt::LeftButton) return;
|
2015-04-04 23:01:34 +03:00
|
|
|
|
|
|
|
data->cancel();
|
|
|
|
}
|
|
|
|
|
2015-08-12 21:01:32 +03:00
|
|
|
VideoData::VideoData(const VideoId &id, const uint64 &access, int32 date, int32 duration, int32 w, int32 h, const ImagePtr &thumb, int32 dc, int32 size) :
|
2015-09-03 13:48:40 +03:00
|
|
|
id(id), access(access), date(date), duration(duration), w(w), h(h), thumb(thumb), dc(dc), size(size), status(FileReady), uploadOffset(0), fileType(0), openOnSave(0), loader(0) {
|
2015-11-26 20:34:52 +03:00
|
|
|
_location = Local::readFileLocation(mediaKey(VideoFileLocation, dc, id));
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoData::save(const QString &toFile) {
|
|
|
|
cancel(true);
|
2015-09-29 18:29:21 +03:00
|
|
|
loader = new mtpFileLoader(dc, id, access, VideoFileLocation, toFile, size);
|
2015-04-04 23:01:34 +03:00
|
|
|
loader->connect(loader, SIGNAL(progress(mtpFileLoader*)), App::main(), SLOT(videoLoadProgress(mtpFileLoader*)));
|
|
|
|
loader->connect(loader, SIGNAL(failed(mtpFileLoader*, bool)), App::main(), SLOT(videoLoadFailed(mtpFileLoader*, bool)));
|
|
|
|
loader->start();
|
2015-12-13 18:21:20 +03:00
|
|
|
|
|
|
|
notifyLayoutChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoData::notifyLayoutChanged() const {
|
|
|
|
const VideoItems &items(App::videoItems());
|
|
|
|
VideoItems::const_iterator i = items.constFind(const_cast<VideoData*>(this));
|
|
|
|
if (i != items.cend()) {
|
|
|
|
for (HistoryItemsMap::const_iterator j = i->cbegin(), e = i->cend(); j != e; ++j) {
|
|
|
|
Notify::historyItemLayoutChanged(j.key());
|
|
|
|
}
|
|
|
|
}
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QString VideoData::already(bool check) {
|
2015-11-26 20:34:52 +03:00
|
|
|
return location(check).name();
|
|
|
|
}
|
|
|
|
|
|
|
|
const FileLocation &VideoData::location(bool check) {
|
|
|
|
if (check && !_location.check()) _location = Local::readFileLocation(mediaKey(VideoFileLocation, dc, id));
|
|
|
|
return _location;
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioOpenLink::onClick(Qt::MouseButton button) const {
|
|
|
|
AudioData *data = audio();
|
2015-08-12 21:01:32 +03:00
|
|
|
if (!data->date || button != Qt::LeftButton) return;
|
2015-04-04 23:01:34 +03:00
|
|
|
|
|
|
|
QString already = data->already(true);
|
2015-07-01 00:07:05 +03:00
|
|
|
bool play = App::hoveredLinkItem() && audioPlayer();
|
2015-04-04 23:01:34 +03:00
|
|
|
if (!already.isEmpty() || (!data->data.isEmpty() && play)) {
|
|
|
|
if (play) {
|
2015-07-01 00:07:05 +03:00
|
|
|
AudioMsgId playing;
|
2015-05-29 21:52:43 +03:00
|
|
|
AudioPlayerState playingState = AudioPlayerStopped;
|
|
|
|
audioPlayer()->currentState(&playing, &playingState);
|
2015-09-03 13:48:40 +03:00
|
|
|
if (playing.msgId == App::hoveredLinkItem()->fullId() && !(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
2015-07-01 00:07:05 +03:00
|
|
|
audioPlayer()->pauseresume(OverviewAudios);
|
2015-04-04 23:01:34 +03:00
|
|
|
} else {
|
2015-09-03 13:48:40 +03:00
|
|
|
audioPlayer()->play(AudioMsgId(data, App::hoveredLinkItem()->fullId()));
|
2015-04-30 16:53:36 +03:00
|
|
|
if (App::main()) App::main()->audioMarkRead(data);
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
psOpenFile(already);
|
2015-04-30 16:53:36 +03:00
|
|
|
if (App::main()) App::main()->audioMarkRead(data);
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->status != FileReady) return;
|
|
|
|
|
2015-06-27 16:02:00 +03:00
|
|
|
bool mp3 = (data->mime == qstr("audio/mp3"));
|
2015-04-04 23:01:34 +03:00
|
|
|
QString filename = saveFileName(lang(lng_save_audio), mp3 ? qsl("MP3 Audio (*.mp3);;All files (*.*)") : qsl("OGG Opus Audio (*.ogg);;All files (*.*)"), qsl("audio"), mp3 ? qsl(".mp3") : qsl(".ogg"), false);
|
|
|
|
if (!filename.isEmpty()) {
|
|
|
|
data->openOnSave = 1;
|
2015-09-03 13:48:40 +03:00
|
|
|
data->openOnSaveMsgId = App::hoveredLinkItem() ? App::hoveredLinkItem()->fullId() : (App::contextItem() ? App::contextItem()->fullId() : FullMsgId());
|
2015-04-04 23:01:34 +03:00
|
|
|
data->save(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-19 13:29:19 +03:00
|
|
|
void AudioSaveLink::doSave(AudioData *data, bool forceSavingAs) {
|
2015-08-12 21:01:32 +03:00
|
|
|
if (!data->date) return;
|
2015-04-04 23:01:34 +03:00
|
|
|
|
|
|
|
QString already = data->already(true);
|
|
|
|
if (!already.isEmpty() && !forceSavingAs) {
|
|
|
|
QPoint pos(QCursor::pos());
|
|
|
|
if (!psShowOpenWithMenu(pos.x(), pos.y(), already)) {
|
|
|
|
psOpenFile(already, true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
QFileInfo alreadyInfo(already);
|
|
|
|
QDir alreadyDir(already.isEmpty() ? QDir() : alreadyInfo.dir());
|
2015-06-27 16:02:00 +03:00
|
|
|
bool mp3 = (data->mime == qstr("audio/mp3"));
|
2015-04-04 23:01:34 +03:00
|
|
|
QString name = already.isEmpty() ? (mp3 ? qsl(".mp3") : qsl(".ogg")) : alreadyInfo.fileName();
|
|
|
|
QString filename = saveFileName(lang(lng_save_audio), mp3 ? qsl("MP3 Audio (*.mp3);;All files (*.*)") : qsl("OGG Opus Audio (*.ogg);;All files (*.*)"), qsl("audio"), name, forceSavingAs, alreadyDir);
|
|
|
|
if (!filename.isEmpty()) {
|
|
|
|
if (forceSavingAs) {
|
|
|
|
data->cancel();
|
|
|
|
} else if (!already.isEmpty()) {
|
|
|
|
data->openOnSave = -1;
|
2015-09-03 13:48:40 +03:00
|
|
|
data->openOnSaveMsgId = App::hoveredLinkItem() ? App::hoveredLinkItem()->fullId() : (App::contextItem() ? App::contextItem()->fullId() : FullMsgId());
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
data->save(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioSaveLink::onClick(Qt::MouseButton button) const {
|
|
|
|
if (button != Qt::LeftButton) return;
|
2015-04-19 13:29:19 +03:00
|
|
|
doSave(audio());
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioCancelLink::onClick(Qt::MouseButton button) const {
|
|
|
|
AudioData *data = audio();
|
2015-08-12 21:01:32 +03:00
|
|
|
if (!data->date || button != Qt::LeftButton) return;
|
2015-04-04 23:01:34 +03:00
|
|
|
|
|
|
|
data->cancel();
|
|
|
|
}
|
|
|
|
|
2015-06-20 00:58:01 +03:00
|
|
|
bool StickerData::setInstalled() const {
|
|
|
|
switch (set.type()) {
|
|
|
|
case mtpc_inputStickerSetID: {
|
2015-12-02 20:17:53 +03:00
|
|
|
StickerSets::const_iterator it = cStickerSets().constFind(set.c_inputStickerSetID().vid.v);
|
|
|
|
return (it != cStickerSets().cend()) && !(it->flags & MTPDstickerSet::flag_disabled);
|
2015-06-20 00:58:01 +03:00
|
|
|
} break;
|
|
|
|
case mtpc_inputStickerSetShortName: {
|
|
|
|
QString name = qs(set.c_inputStickerSetShortName().vshort_name).toLower();
|
2015-12-02 20:17:53 +03:00
|
|
|
for (StickerSets::const_iterator it = cStickerSets().cbegin(), e = cStickerSets().cend(); it != e; ++it) {
|
|
|
|
if (it->shortName.toLower() == name) {
|
|
|
|
return !(it->flags & MTPDstickerSet::flag_disabled);
|
|
|
|
}
|
2015-06-20 00:58:01 +03:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-12 21:01:32 +03:00
|
|
|
AudioData::AudioData(const AudioId &id, const uint64 &access, int32 date, const QString &mime, int32 duration, int32 dc, int32 size) :
|
2015-09-03 13:48:40 +03:00
|
|
|
id(id), access(access), date(date), mime(mime), duration(duration), dc(dc), size(size), status(FileReady), uploadOffset(0), openOnSave(0), loader(0) {
|
2015-11-26 20:34:52 +03:00
|
|
|
_location = Local::readFileLocation(mediaKey(AudioFileLocation, dc, id));
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioData::save(const QString &toFile) {
|
|
|
|
cancel(true);
|
2015-09-29 18:29:21 +03:00
|
|
|
loader = new mtpFileLoader(dc, id, access, AudioFileLocation, toFile, size, (size < AudioVoiceMsgInMemory));
|
2015-04-04 23:01:34 +03:00
|
|
|
loader->connect(loader, SIGNAL(progress(mtpFileLoader*)), App::main(), SLOT(audioLoadProgress(mtpFileLoader*)));
|
|
|
|
loader->connect(loader, SIGNAL(failed(mtpFileLoader*, bool)), App::main(), SLOT(audioLoadFailed(mtpFileLoader*, bool)));
|
|
|
|
loader->start();
|
2015-12-13 01:29:33 +03:00
|
|
|
|
|
|
|
notifyLayoutChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioData::notifyLayoutChanged() const {
|
|
|
|
const AudioItems &items(App::audioItems());
|
|
|
|
AudioItems::const_iterator i = items.constFind(const_cast<AudioData*>(this));
|
|
|
|
if (i != items.cend()) {
|
|
|
|
for (HistoryItemsMap::const_iterator j = i->cbegin(), e = i->cend(); j != e; ++j) {
|
|
|
|
Notify::historyItemLayoutChanged(j.key());
|
|
|
|
}
|
|
|
|
}
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QString AudioData::already(bool check) {
|
2015-11-26 20:34:52 +03:00
|
|
|
return location(check).name();
|
|
|
|
}
|
|
|
|
|
|
|
|
const FileLocation &AudioData::location(bool check) {
|
|
|
|
if (check && !_location.check()) _location = Local::readFileLocation(mediaKey(AudioFileLocation, dc, id));
|
|
|
|
return _location;
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
2015-07-03 11:47:16 +03:00
|
|
|
void DocumentOpenLink::doOpen(DocumentData *data) {
|
|
|
|
if (!data->date) return;
|
2015-04-04 23:01:34 +03:00
|
|
|
|
2015-07-01 00:07:05 +03:00
|
|
|
bool play = data->song() && App::hoveredLinkItem() && audioPlayer();
|
2015-11-26 20:34:52 +03:00
|
|
|
const FileLocation &location(data->location(true));
|
|
|
|
if (!location.isEmpty() || (!data->data.isEmpty() && play)) {
|
2015-07-01 00:07:05 +03:00
|
|
|
if (play) {
|
|
|
|
SongMsgId playing;
|
|
|
|
AudioPlayerState playingState = AudioPlayerStopped;
|
|
|
|
audioPlayer()->currentState(&playing, &playingState);
|
2015-09-03 13:48:40 +03:00
|
|
|
if (playing.msgId == App::hoveredLinkItem()->fullId() && !(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
2015-07-01 00:07:05 +03:00
|
|
|
audioPlayer()->pauseresume(OverviewDocuments);
|
|
|
|
} else {
|
2015-09-03 13:48:40 +03:00
|
|
|
SongMsgId song(data, App::hoveredLinkItem()->fullId());
|
2015-07-03 11:47:16 +03:00
|
|
|
audioPlayer()->play(song);
|
|
|
|
if (App::main()) App::main()->documentPlayProgress(song);
|
2015-07-01 00:07:05 +03:00
|
|
|
}
|
2015-11-26 20:34:52 +03:00
|
|
|
} else if (data->size < MediaViewImageSizeLimit && location.accessEnable()) {
|
2015-12-19 00:36:16 +03:00
|
|
|
if (!App::hoveredLinkItem() || !App::hoveredLinkItem()->getMedia() || !App::hoveredLinkItem()->getMedia()->playInline(App::hoveredLinkItem())) {
|
2015-12-15 17:50:51 +03:00
|
|
|
QImageReader reader(location.name());
|
|
|
|
if (reader.canRead() && (App::hoveredLinkItem() || App::contextItem())) {
|
2015-05-29 21:52:43 +03:00
|
|
|
App::wnd()->showDocument(data, App::hoveredLinkItem() ? App::hoveredLinkItem() : App::contextItem());
|
2015-04-04 23:01:34 +03:00
|
|
|
} else {
|
2015-11-26 20:34:52 +03:00
|
|
|
psOpenFile(location.name());
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-26 20:34:52 +03:00
|
|
|
location.accessDisable();
|
2015-04-04 23:01:34 +03:00
|
|
|
} else {
|
2015-11-26 20:34:52 +03:00
|
|
|
psOpenFile(location.name());
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->status != FileReady) return;
|
|
|
|
|
|
|
|
QString name = data->name, filter;
|
|
|
|
MimeType mimeType = mimeTypeForName(data->mime);
|
|
|
|
QStringList p = mimeType.globPatterns();
|
|
|
|
QString pattern = p.isEmpty() ? QString() : p.front();
|
|
|
|
if (name.isEmpty()) {
|
|
|
|
name = pattern.isEmpty() ? qsl(".unknown") : pattern.replace('*', QString());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pattern.isEmpty()) {
|
2015-10-18 13:38:00 +02:00
|
|
|
filter = QString();
|
2015-04-04 23:01:34 +03:00
|
|
|
} else {
|
|
|
|
filter = mimeType.filterString() + qsl(";;All files (*.*)");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString filename = saveFileName(lang(lng_save_file), filter, qsl("doc"), name, false);
|
|
|
|
if (!filename.isEmpty()) {
|
|
|
|
data->openOnSave = 1;
|
2015-09-03 13:48:40 +03:00
|
|
|
data->openOnSaveMsgId = App::hoveredLinkItem() ? App::hoveredLinkItem()->fullId() : (App::contextItem() ? App::contextItem()->fullId() : FullMsgId());
|
2015-04-04 23:01:34 +03:00
|
|
|
data->save(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-03 11:47:16 +03:00
|
|
|
void DocumentOpenLink::onClick(Qt::MouseButton button) const {
|
|
|
|
if (button != Qt::LeftButton) return;
|
|
|
|
doOpen(document());
|
|
|
|
}
|
|
|
|
|
2015-04-19 13:29:19 +03:00
|
|
|
void DocumentSaveLink::doSave(DocumentData *data, bool forceSavingAs) {
|
2015-04-04 23:01:34 +03:00
|
|
|
if (!data->date) return;
|
|
|
|
|
|
|
|
QString already = data->already(true);
|
|
|
|
if (!already.isEmpty() && !forceSavingAs) {
|
|
|
|
QPoint pos(QCursor::pos());
|
|
|
|
if (!psShowOpenWithMenu(pos.x(), pos.y(), already)) {
|
|
|
|
psOpenFile(already, true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
QFileInfo alreadyInfo(already);
|
|
|
|
QDir alreadyDir(already.isEmpty() ? QDir() : alreadyInfo.dir());
|
|
|
|
QString name = already.isEmpty() ? data->name : alreadyInfo.fileName(), filter;
|
|
|
|
MimeType mimeType = mimeTypeForName(data->mime);
|
|
|
|
QStringList p = mimeType.globPatterns();
|
|
|
|
QString pattern = p.isEmpty() ? QString() : p.front();
|
|
|
|
if (name.isEmpty()) {
|
|
|
|
name = pattern.isEmpty() ? qsl(".unknown") : pattern.replace('*', QString());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pattern.isEmpty()) {
|
2015-10-18 13:38:00 +02:00
|
|
|
filter = QString();
|
2015-04-04 23:01:34 +03:00
|
|
|
} else {
|
|
|
|
filter = mimeType.filterString() + qsl(";;All files (*.*)");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString filename = saveFileName(lang(lng_save_file), filter, qsl("doc"), name, forceSavingAs, alreadyDir);
|
|
|
|
if (!filename.isEmpty()) {
|
|
|
|
if (forceSavingAs) {
|
|
|
|
data->cancel();
|
|
|
|
} else if (!already.isEmpty()) {
|
|
|
|
data->openOnSave = -1;
|
2015-09-03 13:48:40 +03:00
|
|
|
data->openOnSaveMsgId = App::hoveredLinkItem() ? App::hoveredLinkItem()->fullId() : (App::contextItem() ? App::contextItem()->fullId() : FullMsgId());
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
data->save(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DocumentSaveLink::onClick(Qt::MouseButton button) const {
|
|
|
|
if (button != Qt::LeftButton) return;
|
2015-04-19 13:29:19 +03:00
|
|
|
doSave(document());
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void DocumentCancelLink::onClick(Qt::MouseButton button) const {
|
|
|
|
DocumentData *data = document();
|
|
|
|
if (!data->date || button != Qt::LeftButton) return;
|
|
|
|
|
|
|
|
data->cancel();
|
|
|
|
}
|
|
|
|
|
2015-12-10 16:37:45 +03:00
|
|
|
DocumentData::DocumentData(const DocumentId &id, const uint64 &access, int32 date, const QVector<MTPDocumentAttribute> &attributes, const QString &mime, const ImagePtr &thumb, int32 dc, int32 size) : id(id)
|
|
|
|
, type(FileDocument)
|
|
|
|
, access(access)
|
|
|
|
, date(date)
|
|
|
|
, mime(mime)
|
|
|
|
, thumb(thumb)
|
|
|
|
, dc(dc)
|
|
|
|
, size(size)
|
|
|
|
, status(FileReady)
|
|
|
|
, uploadOffset(0)
|
|
|
|
, openOnSave(0)
|
|
|
|
, loader(0)
|
|
|
|
, _additional(0)
|
|
|
|
, _isImage(false) {
|
2015-04-04 23:01:34 +03:00
|
|
|
setattributes(attributes);
|
2015-11-26 20:34:52 +03:00
|
|
|
_location = Local::readFileLocation(mediaKey(DocumentFileLocation, dc, id));
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void DocumentData::setattributes(const QVector<MTPDocumentAttribute> &attributes) {
|
|
|
|
for (int32 i = 0, l = attributes.size(); i < l; ++i) {
|
|
|
|
switch (attributes[i].type()) {
|
|
|
|
case mtpc_documentAttributeImageSize: {
|
|
|
|
const MTPDdocumentAttributeImageSize &d(attributes[i].c_documentAttributeImageSize());
|
|
|
|
dimensions = QSize(d.vw.v, d.vh.v);
|
|
|
|
} break;
|
2015-12-17 20:31:28 +03:00
|
|
|
case mtpc_documentAttributeAnimated: if (type == FileDocument || type == StickerDocument || type == VideoDocument) {
|
2015-07-01 00:07:05 +03:00
|
|
|
type = AnimatedDocument;
|
|
|
|
delete _additional;
|
|
|
|
_additional = 0;
|
|
|
|
} break;
|
2015-04-04 23:01:34 +03:00
|
|
|
case mtpc_documentAttributeSticker: {
|
|
|
|
const MTPDdocumentAttributeSticker &d(attributes[i].c_documentAttributeSticker());
|
2015-07-01 00:07:05 +03:00
|
|
|
if (type == FileDocument) {
|
|
|
|
type = StickerDocument;
|
|
|
|
StickerData *sticker = new StickerData();
|
|
|
|
_additional = sticker;
|
2015-05-11 15:44:27 +03:00
|
|
|
sticker->alt = qs(d.valt);
|
|
|
|
sticker->set = d.vstickerset;
|
|
|
|
}
|
2015-04-04 23:01:34 +03:00
|
|
|
} break;
|
|
|
|
case mtpc_documentAttributeVideo: {
|
|
|
|
const MTPDdocumentAttributeVideo &d(attributes[i].c_documentAttributeVideo());
|
2015-12-17 20:31:28 +03:00
|
|
|
if (type == FileDocument) {
|
|
|
|
type = VideoDocument;
|
|
|
|
}
|
2015-07-01 00:07:05 +03:00
|
|
|
// duration = d.vduration.v;
|
2015-04-04 23:01:34 +03:00
|
|
|
dimensions = QSize(d.vw.v, d.vh.v);
|
|
|
|
} break;
|
|
|
|
case mtpc_documentAttributeAudio: {
|
|
|
|
const MTPDdocumentAttributeAudio &d(attributes[i].c_documentAttributeAudio());
|
2015-07-01 00:07:05 +03:00
|
|
|
type = SongDocument;
|
|
|
|
SongData *song = new SongData();
|
|
|
|
_additional = song;
|
|
|
|
song->duration = d.vduration.v;
|
|
|
|
song->title = qs(d.vtitle);
|
|
|
|
song->performer = qs(d.vperformer);
|
2015-04-04 23:01:34 +03:00
|
|
|
} break;
|
|
|
|
case mtpc_documentAttributeFilename: name = qs(attributes[i].c_documentAttributeFilename().vfile_name); break;
|
|
|
|
}
|
|
|
|
}
|
2015-07-01 00:07:05 +03:00
|
|
|
if (type == StickerDocument) {
|
|
|
|
if (dimensions.width() <= 0 || dimensions.height() <= 0 || dimensions.width() > StickerMaxSize || dimensions.height() > StickerMaxSize || size > StickerInMemory) {
|
|
|
|
type = FileDocument;
|
|
|
|
delete _additional;
|
|
|
|
_additional = 0;
|
|
|
|
}
|
|
|
|
}
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void DocumentData::save(const QString &toFile) {
|
|
|
|
cancel(true);
|
|
|
|
bool isSticker = (type == StickerDocument) && (dimensions.width() > 0) && (dimensions.height() > 0) && (size < StickerInMemory);
|
2015-09-29 18:29:21 +03:00
|
|
|
loader = new mtpFileLoader(dc, id, access, DocumentFileLocation, toFile, size, isSticker);
|
2015-04-04 23:01:34 +03:00
|
|
|
loader->connect(loader, SIGNAL(progress(mtpFileLoader*)), App::main(), SLOT(documentLoadProgress(mtpFileLoader*)));
|
|
|
|
loader->connect(loader, SIGNAL(failed(mtpFileLoader*, bool)), App::main(), SLOT(documentLoadFailed(mtpFileLoader*, bool)));
|
|
|
|
loader->start();
|
2015-12-13 01:29:33 +03:00
|
|
|
|
|
|
|
notifyLayoutChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DocumentData::notifyLayoutChanged() const {
|
|
|
|
const DocumentItems &items(App::documentItems());
|
|
|
|
DocumentItems::const_iterator i = items.constFind(const_cast<DocumentData*>(this));
|
|
|
|
if (i != items.cend()) {
|
|
|
|
for (HistoryItemsMap::const_iterator j = i->cbegin(), e = i->cend(); j != e; ++j) {
|
|
|
|
Notify::historyItemLayoutChanged(j.key());
|
|
|
|
}
|
|
|
|
}
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QString DocumentData::already(bool check) {
|
2015-11-26 20:34:52 +03:00
|
|
|
return location(check).name();
|
|
|
|
}
|
|
|
|
|
|
|
|
const FileLocation &DocumentData::location(bool check) {
|
|
|
|
if (check && !_location.check()) _location = Local::readFileLocation(mediaKey(DocumentFileLocation, dc, id));
|
|
|
|
return _location;
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
2015-12-19 17:37:28 +03:00
|
|
|
bool fileIsImage(const QString &name, const QString &mime) {
|
2015-12-10 16:37:45 +03:00
|
|
|
QString lowermime = mime.toLower(), namelower = name.toLower();
|
|
|
|
if (lowermime.startsWith(qstr("image/"))) {
|
2015-12-19 17:37:28 +03:00
|
|
|
return true;
|
2015-12-10 16:37:45 +03:00
|
|
|
} else if (namelower.endsWith(qstr(".bmp"))
|
|
|
|
|| namelower.endsWith(qstr(".jpg"))
|
|
|
|
|| namelower.endsWith(qstr(".jpeg"))
|
|
|
|
|| namelower.endsWith(qstr(".gif"))
|
|
|
|
|| namelower.endsWith(qstr(".webp"))
|
|
|
|
|| namelower.endsWith(qstr(".tga"))
|
|
|
|
|| namelower.endsWith(qstr(".tiff"))
|
|
|
|
|| namelower.endsWith(qstr(".tif"))
|
|
|
|
|| namelower.endsWith(qstr(".psd"))
|
|
|
|
|| namelower.endsWith(qstr(".png"))) {
|
2015-12-19 17:37:28 +03:00
|
|
|
return true;
|
2015-12-10 16:37:45 +03:00
|
|
|
}
|
2015-12-19 17:37:28 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DocumentData::recountIsImage() {
|
|
|
|
_isImage = fileIsImage(name, mime);
|
2015-12-10 16:37:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
WebPageData::WebPageData(const WebPageId &id, WebPageType type, const QString &url, const QString &displayUrl, const QString &siteName, const QString &title, const QString &description, PhotoData *photo, DocumentData *doc, int32 duration, const QString &author, int32 pendingTill) : id(id)
|
|
|
|
, type(type)
|
|
|
|
, url(url)
|
|
|
|
, displayUrl(displayUrl)
|
|
|
|
, siteName(siteName)
|
|
|
|
, title(title)
|
|
|
|
, description(description)
|
|
|
|
, duration(duration)
|
|
|
|
, author(author)
|
|
|
|
, photo(photo)
|
|
|
|
, doc(doc)
|
|
|
|
, pendingTill(pendingTill) {
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void PeerLink::onClick(Qt::MouseButton button) const {
|
|
|
|
if (button == Qt::LeftButton && App::main()) {
|
2015-09-13 20:27:29 +03:00
|
|
|
if (peer() && peer()->isChannel() && App::main()->historyPeer() != peer()) {
|
2015-09-23 20:43:08 +03:00
|
|
|
if (!peer()->asChannel()->isPublic() && !peer()->asChannel()->amIn()) {
|
2015-12-07 21:09:05 +03:00
|
|
|
Ui::showLayer(new InformBox(lang((peer()->isMegagroup()) ? lng_group_not_accessible : lng_channel_not_accessible)));
|
2015-09-21 23:57:42 +03:00
|
|
|
} else {
|
2015-12-13 14:36:08 +03:00
|
|
|
Ui::showPeerHistory(peer(), ShowAtUnreadMsgId);
|
2015-09-21 23:57:42 +03:00
|
|
|
}
|
2015-09-13 20:27:29 +03:00
|
|
|
} else {
|
|
|
|
App::main()->showPeerProfile(peer());
|
|
|
|
}
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessageLink::onClick(Qt::MouseButton button) const {
|
|
|
|
if (button == Qt::LeftButton && App::main()) {
|
|
|
|
HistoryItem *current = App::mousedItem();
|
|
|
|
if (current && current->history()->peer->id == peer()) {
|
|
|
|
App::main()->pushReplyReturn(current);
|
|
|
|
}
|
2015-12-13 14:36:08 +03:00
|
|
|
Ui::showPeerHistory(peer(), msgid());
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-19 12:13:21 +03:00
|
|
|
void CommentsLink::onClick(Qt::MouseButton button) const {
|
|
|
|
if (button == Qt::LeftButton && App::main() && _item->history()->isChannel()) {
|
2015-12-13 14:36:08 +03:00
|
|
|
Ui::showPeerHistoryAtItem(_item);
|
2015-09-19 12:13:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-04 23:01:34 +03:00
|
|
|
MsgId clientMsgId() {
|
2015-11-09 12:51:22 +03:00
|
|
|
static MsgId currentClientMsgId = StartClientMsgId;
|
|
|
|
Q_ASSERT(currentClientMsgId < EndClientMsgId);
|
|
|
|
return currentClientMsgId++;
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|