2015-04-04 20:01:34 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
|
|
|
Copyright (c) 2014 John Preston, https://desktop.telegram.org
|
|
|
|
*/
|
|
|
|
#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"
|
|
|
|
|
|
|
|
#include "audio.h"
|
|
|
|
#include "localstorage.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
int32 peerColorIndex(const PeerId &peer) {
|
2015-09-03 10:48:40 +00:00
|
|
|
int32 myId(MTP::authedId()), peerId(peerToBareInt(peer));
|
2015-04-04 20:01:34 +00: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 10:48:40 +00:00
|
|
|
return (md5[peerId & 0x0F] & (peerIsUser(peer) ? 0x07 : 0x03));
|
2015-04-04 20:01:34 +00: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) {
|
|
|
|
static const ImagePtr userDefPhotos[8] = {
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
NotifySettings globalNotifyAll, globalNotifyUsers, globalNotifyChats;
|
|
|
|
NotifySettingsPtr globalNotifyAllPtr = UnknownNotifySettings, globalNotifyUsersPtr = UnknownNotifySettings, globalNotifyChatsPtr = UnknownNotifySettings;
|
|
|
|
|
|
|
|
PeerData::PeerData(const PeerId &id) : id(id)
|
|
|
|
, loaded(false)
|
|
|
|
, colorIndex(peerColorIndex(id))
|
|
|
|
, color(peerColor(colorIndex))
|
2015-09-03 10:48:40 +00:00
|
|
|
, photo((isChat() || isChannel()) ? chatDefPhoto(colorIndex) : userDefPhoto(colorIndex))
|
2015-08-07 12:11:50 +00:00
|
|
|
, photoId(UnknownPeerPhotoId)
|
2015-04-04 20:01:34 +00:00
|
|
|
, nameVersion(0)
|
|
|
|
, notify(UnknownNotifySettings)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerData::updateName(const QString &newName, const QString &newNameOrPhone, const QString &newUsername) {
|
2015-09-03 10:48:40 +00:00
|
|
|
if (name == newName && nameOrPhone == newNameOrPhone && (!isUser() || asUser()->username == newUsername) && nameVersion > 0) return;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
|
|
|
++nameVersion;
|
|
|
|
name = newName;
|
|
|
|
nameOrPhone = newNameOrPhone;
|
2015-09-03 10:48:40 +00:00
|
|
|
if (isUser()) asUser()->username = newUsername;
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
Names oldNames = names;
|
|
|
|
NameFirstChars oldChars = chars;
|
|
|
|
fillNames();
|
|
|
|
App::history(id)->updateNameText();
|
2015-06-25 10:12:38 +00:00
|
|
|
nameUpdated();
|
2015-04-04 20:01:34 +00:00
|
|
|
if (App::main()) {
|
|
|
|
emit App::main()->peerNameChanged(this, oldNames, oldChars);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-07 12:11:50 +00:00
|
|
|
void UserData::setPhoto(const MTPUserProfilePhoto &p) { // see Local::readPeer as well
|
2015-06-29 22:09:23 +00:00
|
|
|
PhotoId newPhotoId = photoId;
|
|
|
|
ImagePtr newPhoto = photo;
|
2015-08-07 12:11:50 +00:00
|
|
|
StorageImageLocation newPhotoLoc = photoLoc;
|
2015-04-04 20:01:34 +00:00
|
|
|
switch (p.type()) {
|
|
|
|
case mtpc_userProfilePhoto: {
|
|
|
|
const MTPDuserProfilePhoto d(p.c_userProfilePhoto());
|
2015-06-29 22:09:23 +00:00
|
|
|
newPhotoId = d.vphoto_id.v;
|
2015-08-07 12:11:50 +00:00
|
|
|
newPhotoLoc = App::imageLocation(160, 160, d.vphoto_small);
|
|
|
|
newPhoto = newPhotoLoc.isNull() ? userDefPhoto(colorIndex) : ImagePtr(newPhotoLoc);
|
2015-09-03 10:48:40 +00:00
|
|
|
//App::feedPhoto(App::photoFromUserPhoto(peerToUser(id), MTP_int(unixtime()), p));
|
2015-04-04 20:01:34 +00:00
|
|
|
} break;
|
|
|
|
default: {
|
2015-06-29 22:09:23 +00:00
|
|
|
newPhotoId = 0;
|
2015-04-04 20:01:34 +00:00
|
|
|
if (id == ServiceUserId) {
|
2015-06-29 22:09:23 +00:00
|
|
|
if (photo->isNull()) {
|
|
|
|
newPhoto = ImagePtr(QPixmap::fromImage(App::wnd()->iconLarge().scaledToWidth(160, Qt::SmoothTransformation), Qt::ColorOnly), "PNG");
|
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
} else {
|
2015-06-29 22:09:23 +00:00
|
|
|
newPhoto = userDefPhoto(colorIndex);
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
2015-08-07 12:11:50 +00:00
|
|
|
newPhotoLoc = StorageImageLocation();
|
2015-04-04 20:01:34 +00:00
|
|
|
} break;
|
|
|
|
}
|
2015-08-07 12:11:50 +00:00
|
|
|
if (newPhotoId != photoId || newPhoto.v() != photo.v() || newPhotoLoc != photoLoc) {
|
2015-06-29 22:09:23 +00:00
|
|
|
photoId = newPhotoId;
|
|
|
|
photo = newPhoto;
|
2015-08-07 12:11:50 +00:00
|
|
|
photoLoc = newPhotoLoc;
|
2015-06-29 22:09:23 +00:00
|
|
|
emit App::main()->peerPhotoChanged(this);
|
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PeerData::fillNames() {
|
|
|
|
names.clear();
|
|
|
|
chars.clear();
|
|
|
|
QString toIndex = textAccentFold(name);
|
|
|
|
if (nameOrPhone != name) {
|
|
|
|
toIndex += ' ' + textAccentFold(nameOrPhone);
|
|
|
|
}
|
2015-09-03 10:48:40 +00:00
|
|
|
if (isUser()) {
|
2015-04-04 20:01:34 +00:00
|
|
|
toIndex += ' ' + textAccentFold(asUser()->username);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
updateName(lastName.isEmpty() ? firstName : (firstName + ' ' + lastName), phoneName, usern);
|
|
|
|
}
|
|
|
|
if (updUsername) {
|
|
|
|
if (App::main()) {
|
|
|
|
App::main()->peerUsernameChanged(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserData::setPhone(const QString &newPhone) {
|
|
|
|
phone = newPhone;
|
|
|
|
}
|
|
|
|
|
2015-06-10 12:48:26 +00:00
|
|
|
void UserData::setBotInfoVersion(int32 version) {
|
2015-06-15 17:19:24 +00:00
|
|
|
if (version < 0) {
|
|
|
|
delete botInfo;
|
|
|
|
botInfo = 0;
|
|
|
|
} else if (!botInfo) {
|
2015-06-10 12:48:26 +00:00
|
|
|
botInfo = new BotInfo();
|
|
|
|
botInfo->version = version;
|
|
|
|
} else if (botInfo->version < version) {
|
2015-07-03 15:55:22 +00:00
|
|
|
if (!botInfo->commands.isEmpty()) {
|
|
|
|
botInfo->commands.clear();
|
|
|
|
if (App::main()) App::main()->botCommandsChanged(this);
|
|
|
|
}
|
2015-06-10 12:48:26 +00:00
|
|
|
botInfo->description.clear();
|
|
|
|
botInfo->shareText.clear();
|
|
|
|
botInfo->version = version;
|
2015-06-10 15:54:24 +00:00
|
|
|
botInfo->inited = false;
|
2015-06-10 12:48:26 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-07 12:11:50 +00:00
|
|
|
|
2015-06-10 12:48:26 +00:00
|
|
|
void UserData::setBotInfo(const MTPBotInfo &info) {
|
|
|
|
switch (info.type()) {
|
|
|
|
case mtpc_botInfoEmpty:
|
2015-07-03 15:55:22 +00:00
|
|
|
if (botInfo && !botInfo->commands.isEmpty()) {
|
|
|
|
if (App::main()) App::main()->botCommandsChanged(this);
|
|
|
|
}
|
2015-06-10 12:48:26 +00:00
|
|
|
delete botInfo;
|
|
|
|
botInfo = 0;
|
|
|
|
break;
|
|
|
|
case mtpc_botInfo: {
|
|
|
|
const MTPDbotInfo &d(info.c_botInfo());
|
2015-09-03 10:48:40 +00:00
|
|
|
if (peerFromUser(d.vuser_id.v) != id) return;
|
2015-06-10 15:54:24 +00:00
|
|
|
|
|
|
|
if (botInfo) {
|
|
|
|
botInfo->version = d.vversion.v;
|
|
|
|
} else {
|
|
|
|
setBotInfoVersion(d.vversion.v);
|
|
|
|
}
|
|
|
|
|
2015-06-15 17:19:24 +00:00
|
|
|
QString desc = qs(d.vdescription);
|
2015-06-10 15:54:24 +00:00
|
|
|
if (botInfo->description != desc) {
|
|
|
|
botInfo->description = desc;
|
2015-06-15 17:19:24 +00:00
|
|
|
botInfo->text = Text(st::msgMinWidth);
|
2015-06-10 15:54:24 +00:00
|
|
|
}
|
2015-06-10 12:48:26 +00:00
|
|
|
botInfo->shareText = qs(d.vshare_text);
|
|
|
|
|
|
|
|
const QVector<MTPBotCommand> &v(d.vcommands.c_vector().v);
|
|
|
|
botInfo->commands.reserve(v.size());
|
2015-07-03 15:55:22 +00:00
|
|
|
bool changedCommands = false;
|
|
|
|
int32 j = 0;
|
2015-06-10 12:48:26 +00:00
|
|
|
for (int32 i = 0, l = v.size(); i < l; ++i) {
|
2015-07-03 15:55:22 +00: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 12:48:26 +00:00
|
|
|
}
|
2015-07-03 15:55:22 +00:00
|
|
|
++j;
|
|
|
|
}
|
|
|
|
while (j < botInfo->commands.size()) {
|
|
|
|
botInfo->commands.pop_back();
|
|
|
|
changedCommands = true;
|
2015-06-10 12:48:26 +00:00
|
|
|
}
|
2015-06-10 15:54:24 +00:00
|
|
|
|
|
|
|
botInfo->inited = true;
|
2015-07-03 15:55:22 +00:00
|
|
|
|
|
|
|
if (changedCommands && App::main()) {
|
|
|
|
App::main()->botCommandsChanged(this);
|
|
|
|
}
|
2015-06-10 12:48:26 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
void UserData::nameUpdated() {
|
|
|
|
nameText.setText(st::msgNameFont, name, _textNameOptions);
|
|
|
|
}
|
|
|
|
|
2015-06-10 12:48:26 +00:00
|
|
|
void UserData::madeAction() {
|
2015-06-24 17:24:48 +00:00
|
|
|
if (botInfo || isServiceUser(id)) return;
|
|
|
|
|
2015-06-10 12:48:26 +00:00
|
|
|
int32 t = unixtime();
|
|
|
|
if (onlineTill <= 0 && -onlineTill < t) {
|
|
|
|
onlineTill = -t - SetOnlineAfterActivity;
|
2015-06-29 22:09:23 +00:00
|
|
|
App::markPeerUpdated(this);
|
2015-06-10 12:48:26 +00:00
|
|
|
} else if (onlineTill > 0 && onlineTill < t + 1) {
|
|
|
|
onlineTill = t + SetOnlineAfterActivity;
|
2015-06-29 22:09:23 +00:00
|
|
|
App::markPeerUpdated(this);
|
2015-06-10 12:48:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-07 12:11:50 +00: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 20:01:34 +00:00
|
|
|
switch (p.type()) {
|
|
|
|
case mtpc_chatPhoto: {
|
|
|
|
const MTPDchatPhoto d(p.c_chatPhoto());
|
2015-06-29 22:09:23 +00:00
|
|
|
if (phId != UnknownPeerPhotoId) {
|
2015-08-07 12:11:50 +00:00
|
|
|
newPhotoId = phId;
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
2015-08-07 12:11:50 +00: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 20:01:34 +00:00
|
|
|
} break;
|
|
|
|
default: {
|
2015-08-07 12:11:50 +00:00
|
|
|
newPhotoId = 0;
|
|
|
|
newPhotoLoc = StorageImageLocation();
|
|
|
|
newPhoto = chatDefPhoto(colorIndex);
|
|
|
|
// photoFull = ImagePtr();
|
2015-04-04 20:01:34 +00:00
|
|
|
} break;
|
|
|
|
}
|
2015-08-07 12:11:50 +00:00
|
|
|
if (newPhotoId != photoId || newPhoto.v() != photo.v() || newPhotoLoc != photoLoc) {
|
|
|
|
photoId = newPhotoId;
|
|
|
|
photo = newPhoto;
|
|
|
|
photoLoc = newPhotoLoc;
|
|
|
|
emit App::main()->peerPhotoChanged(this);
|
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 10:48:40 +00: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);
|
|
|
|
newPhoto = newPhotoLoc.isNull() ? chatDefPhoto(colorIndex) : ImagePtr(newPhotoLoc);
|
|
|
|
// photoFull = ImagePtr(640, 640, d.vphoto_big, chatDefPhoto(colorIndex));
|
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
newPhotoId = 0;
|
|
|
|
newPhotoLoc = StorageImageLocation();
|
|
|
|
newPhoto = chatDefPhoto(colorIndex);
|
|
|
|
// photoFull = ImagePtr();
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
if (newPhotoId != photoId || newPhoto.v() != photo.v() || newPhotoLoc != photoLoc) {
|
|
|
|
photoId = newPhotoId;
|
|
|
|
photo = newPhoto;
|
|
|
|
photoLoc = newPhotoLoc;
|
|
|
|
emit App::main()->peerPhotoChanged(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
void PhotoLink::onClick(Qt::MouseButton button) const {
|
|
|
|
if (button == Qt::LeftButton) {
|
|
|
|
App::wnd()->showPhoto(this, App::hoveredLinkItem());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
QString saveFileName(const QString &title, const QString &filter, const QString &prefix, QString name, bool savingAs, const QDir &dir) {
|
2015-04-04 20:01:34 +00: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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return filedialogGetSaveFile(name, title, filter, name) ? name : QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
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 18:01:32 +00:00
|
|
|
if (!data->date || button != Qt::LeftButton) return;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
|
|
|
QString already = data->already(true);
|
|
|
|
if (!already.isEmpty()) {
|
|
|
|
psOpenFile(already);
|
2015-04-30 13:53:36 +00:00
|
|
|
if (App::main()) App::main()->videoMarkRead(data);
|
2015-04-04 20:01:34 +00: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 10:48:40 +00:00
|
|
|
data->openOnSaveMsgId = App::hoveredLinkItem() ? App::hoveredLinkItem()->fullId() : (App::contextItem() ? App::contextItem()->fullId() : FullMsgId());
|
2015-04-04 20:01:34 +00:00
|
|
|
data->save(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
void VideoSaveLink::doSave(VideoData *data, bool forceSavingAs) {
|
2015-08-12 18:01:32 +00:00
|
|
|
if (!data->date) return;
|
2015-04-04 20:01:34 +00: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 10:48:40 +00:00
|
|
|
data->openOnSaveMsgId = App::hoveredLinkItem() ? App::hoveredLinkItem()->fullId() : FullMsgId();
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
data->save(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoSaveLink::onClick(Qt::MouseButton button) const {
|
|
|
|
if (button != Qt::LeftButton) return;
|
2015-04-19 10:29:19 +00:00
|
|
|
doSave(video());
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoCancelLink::onClick(Qt::MouseButton button) const {
|
|
|
|
VideoData *data = video();
|
2015-08-12 18:01:32 +00:00
|
|
|
if (!data->date || button != Qt::LeftButton) return;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
|
|
|
data->cancel();
|
|
|
|
}
|
|
|
|
|
2015-08-12 18:01:32 +00: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 10:48:40 +00: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-05-19 15:46:45 +00:00
|
|
|
location = Local::readFileLocation(mediaKey(VideoFileLocation, dc, id));
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoData::save(const QString &toFile) {
|
|
|
|
cancel(true);
|
|
|
|
loader = new mtpFileLoader(dc, id, access, mtpc_inputVideoFileLocation, toFile, size);
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString VideoData::already(bool check) {
|
|
|
|
if (!check) return location.name;
|
2015-05-19 15:46:45 +00:00
|
|
|
if (!location.check()) location = Local::readFileLocation(mediaKey(VideoFileLocation, dc, id));
|
2015-04-04 20:01:34 +00:00
|
|
|
return location.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioOpenLink::onClick(Qt::MouseButton button) const {
|
|
|
|
AudioData *data = audio();
|
2015-08-12 18:01:32 +00:00
|
|
|
if (!data->date || button != Qt::LeftButton) return;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
|
|
|
QString already = data->already(true);
|
2015-06-30 21:07:05 +00:00
|
|
|
bool play = App::hoveredLinkItem() && audioPlayer();
|
2015-04-04 20:01:34 +00:00
|
|
|
if (!already.isEmpty() || (!data->data.isEmpty() && play)) {
|
|
|
|
if (play) {
|
2015-06-30 21:07:05 +00:00
|
|
|
AudioMsgId playing;
|
2015-05-29 18:52:43 +00:00
|
|
|
AudioPlayerState playingState = AudioPlayerStopped;
|
|
|
|
audioPlayer()->currentState(&playing, &playingState);
|
2015-09-03 10:48:40 +00:00
|
|
|
if (playing.msgId == App::hoveredLinkItem()->fullId() && !(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
2015-06-30 21:07:05 +00:00
|
|
|
audioPlayer()->pauseresume(OverviewAudios);
|
2015-04-04 20:01:34 +00:00
|
|
|
} else {
|
2015-09-03 10:48:40 +00:00
|
|
|
audioPlayer()->play(AudioMsgId(data, App::hoveredLinkItem()->fullId()));
|
2015-04-30 13:53:36 +00:00
|
|
|
if (App::main()) App::main()->audioMarkRead(data);
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
psOpenFile(already);
|
2015-04-30 13:53:36 +00:00
|
|
|
if (App::main()) App::main()->audioMarkRead(data);
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->status != FileReady) return;
|
|
|
|
|
2015-06-27 13:02:00 +00:00
|
|
|
bool mp3 = (data->mime == qstr("audio/mp3"));
|
2015-04-04 20:01:34 +00: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 10:48:40 +00:00
|
|
|
data->openOnSaveMsgId = App::hoveredLinkItem() ? App::hoveredLinkItem()->fullId() : (App::contextItem() ? App::contextItem()->fullId() : FullMsgId());
|
2015-04-04 20:01:34 +00:00
|
|
|
data->save(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
void AudioSaveLink::doSave(AudioData *data, bool forceSavingAs) {
|
2015-08-12 18:01:32 +00:00
|
|
|
if (!data->date) return;
|
2015-04-04 20:01:34 +00: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 13:02:00 +00:00
|
|
|
bool mp3 = (data->mime == qstr("audio/mp3"));
|
2015-04-04 20:01:34 +00: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 10:48:40 +00:00
|
|
|
data->openOnSaveMsgId = App::hoveredLinkItem() ? App::hoveredLinkItem()->fullId() : (App::contextItem() ? App::contextItem()->fullId() : FullMsgId());
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
data->save(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioSaveLink::onClick(Qt::MouseButton button) const {
|
|
|
|
if (button != Qt::LeftButton) return;
|
2015-04-19 10:29:19 +00:00
|
|
|
doSave(audio());
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioCancelLink::onClick(Qt::MouseButton button) const {
|
|
|
|
AudioData *data = audio();
|
2015-08-12 18:01:32 +00:00
|
|
|
if (!data->date || button != Qt::LeftButton) return;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
|
|
|
data->cancel();
|
|
|
|
}
|
|
|
|
|
2015-06-19 21:58:01 +00:00
|
|
|
bool StickerData::setInstalled() const {
|
|
|
|
switch (set.type()) {
|
|
|
|
case mtpc_inputStickerSetID: {
|
|
|
|
return (cStickerSets().constFind(set.c_inputStickerSetID().vid.v) != cStickerSets().cend());
|
|
|
|
} break;
|
|
|
|
case mtpc_inputStickerSetShortName: {
|
|
|
|
QString name = qs(set.c_inputStickerSetShortName().vshort_name).toLower();
|
|
|
|
for (StickerSets::const_iterator i = cStickerSets().cbegin(), e = cStickerSets().cend(); i != e; ++i) {
|
|
|
|
if (i->shortName.toLower() == name) return true;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-12 18:01:32 +00:00
|
|
|
AudioData::AudioData(const AudioId &id, const uint64 &access, int32 date, const QString &mime, int32 duration, int32 dc, int32 size) :
|
2015-09-03 10:48:40 +00:00
|
|
|
id(id), access(access), date(date), mime(mime), duration(duration), dc(dc), size(size), status(FileReady), uploadOffset(0), openOnSave(0), loader(0) {
|
2015-05-19 15:46:45 +00:00
|
|
|
location = Local::readFileLocation(mediaKey(AudioFileLocation, dc, id));
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioData::save(const QString &toFile) {
|
|
|
|
cancel(true);
|
|
|
|
loader = new mtpFileLoader(dc, id, access, mtpc_inputAudioFileLocation, toFile, size, (size < AudioVoiceMsgInMemory));
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AudioData::already(bool check) {
|
|
|
|
if (!check) return location.name;
|
2015-05-19 15:46:45 +00:00
|
|
|
if (!location.check()) location = Local::readFileLocation(mediaKey(AudioFileLocation, dc, id));
|
2015-04-04 20:01:34 +00:00
|
|
|
return location.name;
|
|
|
|
}
|
|
|
|
|
2015-07-03 08:47:16 +00:00
|
|
|
void DocumentOpenLink::doOpen(DocumentData *data) {
|
|
|
|
if (!data->date) return;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2015-06-30 21:07:05 +00:00
|
|
|
bool play = data->song() && App::hoveredLinkItem() && audioPlayer();
|
2015-04-04 20:01:34 +00:00
|
|
|
QString already = data->already(true);
|
2015-06-30 21:07:05 +00:00
|
|
|
if (!already.isEmpty() || (!data->data.isEmpty() && play)) {
|
|
|
|
if (play) {
|
|
|
|
SongMsgId playing;
|
|
|
|
AudioPlayerState playingState = AudioPlayerStopped;
|
|
|
|
audioPlayer()->currentState(&playing, &playingState);
|
2015-09-03 10:48:40 +00:00
|
|
|
if (playing.msgId == App::hoveredLinkItem()->fullId() && !(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) {
|
2015-06-30 21:07:05 +00:00
|
|
|
audioPlayer()->pauseresume(OverviewDocuments);
|
|
|
|
} else {
|
2015-09-03 10:48:40 +00:00
|
|
|
SongMsgId song(data, App::hoveredLinkItem()->fullId());
|
2015-07-03 08:47:16 +00:00
|
|
|
audioPlayer()->play(song);
|
|
|
|
if (App::main()) App::main()->documentPlayProgress(song);
|
2015-06-30 21:07:05 +00:00
|
|
|
}
|
|
|
|
} else if (data->size < MediaViewImageSizeLimit) {
|
2015-04-04 20:01:34 +00:00
|
|
|
QImageReader reader(already);
|
|
|
|
if (reader.canRead()) {
|
|
|
|
if (reader.supportsAnimation() && reader.imageCount() > 1 && App::hoveredLinkItem()) {
|
|
|
|
startGif(App::hoveredLinkItem(), already);
|
2015-05-29 18:52:43 +00:00
|
|
|
} else if (App::hoveredLinkItem() || App::contextItem()) {
|
|
|
|
App::wnd()->showDocument(data, App::hoveredLinkItem() ? App::hoveredLinkItem() : App::contextItem());
|
2015-04-04 20:01:34 +00:00
|
|
|
} else {
|
2015-05-29 18:52:43 +00:00
|
|
|
psOpenFile(already);
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
psOpenFile(already);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
psOpenFile(already);
|
|
|
|
}
|
|
|
|
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()) {
|
|
|
|
filter = qsl("All files (*.*)");
|
|
|
|
} 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 10:48:40 +00:00
|
|
|
data->openOnSaveMsgId = App::hoveredLinkItem() ? App::hoveredLinkItem()->fullId() : (App::contextItem() ? App::contextItem()->fullId() : FullMsgId());
|
2015-04-04 20:01:34 +00:00
|
|
|
data->save(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-03 08:47:16 +00:00
|
|
|
void DocumentOpenLink::onClick(Qt::MouseButton button) const {
|
|
|
|
if (button != Qt::LeftButton) return;
|
|
|
|
doOpen(document());
|
|
|
|
}
|
|
|
|
|
2015-04-19 10:29:19 +00:00
|
|
|
void DocumentSaveLink::doSave(DocumentData *data, bool forceSavingAs) {
|
2015-04-04 20:01:34 +00: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()) {
|
|
|
|
filter = qsl("All files (*.*)");
|
|
|
|
} 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 10:48:40 +00:00
|
|
|
data->openOnSaveMsgId = App::hoveredLinkItem() ? App::hoveredLinkItem()->fullId() : (App::contextItem() ? App::contextItem()->fullId() : FullMsgId());
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
data->save(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DocumentSaveLink::onClick(Qt::MouseButton button) const {
|
|
|
|
if (button != Qt::LeftButton) return;
|
2015-04-19 10:29:19 +00:00
|
|
|
doSave(document());
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DocumentCancelLink::onClick(Qt::MouseButton button) const {
|
|
|
|
DocumentData *data = document();
|
|
|
|
if (!data->date || button != Qt::LeftButton) return;
|
|
|
|
|
|
|
|
data->cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentData::DocumentData(const DocumentId &id, const uint64 &access, int32 date, const QVector<MTPDocumentAttribute> &attributes, const QString &mime, const ImagePtr &thumb, int32 dc, int32 size) :
|
2015-09-03 10:48:40 +00:00
|
|
|
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) {
|
2015-04-04 20:01:34 +00:00
|
|
|
setattributes(attributes);
|
2015-05-19 15:46:45 +00:00
|
|
|
location = Local::readFileLocation(mediaKey(DocumentFileLocation, dc, id));
|
2015-04-04 20:01:34 +00: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-06-30 21:07:05 +00:00
|
|
|
case mtpc_documentAttributeAnimated: if (type == FileDocument || type == StickerDocument) {
|
|
|
|
type = AnimatedDocument;
|
|
|
|
delete _additional;
|
|
|
|
_additional = 0;
|
|
|
|
} break;
|
2015-04-04 20:01:34 +00:00
|
|
|
case mtpc_documentAttributeSticker: {
|
|
|
|
const MTPDdocumentAttributeSticker &d(attributes[i].c_documentAttributeSticker());
|
2015-06-30 21:07:05 +00:00
|
|
|
if (type == FileDocument) {
|
|
|
|
type = StickerDocument;
|
|
|
|
StickerData *sticker = new StickerData();
|
|
|
|
_additional = sticker;
|
2015-05-11 12:44:27 +00:00
|
|
|
sticker->alt = qs(d.valt);
|
|
|
|
sticker->set = d.vstickerset;
|
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
} break;
|
|
|
|
case mtpc_documentAttributeVideo: {
|
|
|
|
const MTPDdocumentAttributeVideo &d(attributes[i].c_documentAttributeVideo());
|
|
|
|
type = VideoDocument;
|
2015-06-30 21:07:05 +00:00
|
|
|
// duration = d.vduration.v;
|
2015-04-04 20:01:34 +00:00
|
|
|
dimensions = QSize(d.vw.v, d.vh.v);
|
|
|
|
} break;
|
|
|
|
case mtpc_documentAttributeAudio: {
|
|
|
|
const MTPDdocumentAttributeAudio &d(attributes[i].c_documentAttributeAudio());
|
2015-06-30 21:07:05 +00: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 20:01:34 +00:00
|
|
|
} break;
|
|
|
|
case mtpc_documentAttributeFilename: name = qs(attributes[i].c_documentAttributeFilename().vfile_name); break;
|
|
|
|
}
|
|
|
|
}
|
2015-06-30 21:07:05 +00: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 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DocumentData::save(const QString &toFile) {
|
|
|
|
cancel(true);
|
|
|
|
bool isSticker = (type == StickerDocument) && (dimensions.width() > 0) && (dimensions.height() > 0) && (size < StickerInMemory);
|
|
|
|
loader = new mtpFileLoader(dc, id, access, mtpc_inputDocumentFileLocation, toFile, size, isSticker);
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DocumentData::already(bool check) {
|
|
|
|
if (!check) return location.name;
|
2015-05-19 15:46:45 +00:00
|
|
|
if (!location.check()) location = Local::readFileLocation(mediaKey(DocumentFileLocation, dc, id));
|
2015-04-04 20:01:34 +00:00
|
|
|
return location.name;
|
|
|
|
}
|
|
|
|
|
2015-08-30 14:57:21 +00: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 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PeerLink::onClick(Qt::MouseButton button) const {
|
|
|
|
if (button == Qt::LeftButton && App::main()) {
|
|
|
|
App::main()->showPeerProfile(peer());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-07-17 19:17:37 +00:00
|
|
|
App::main()->showPeerHistory(peer(), msgid());
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MsgId clientMsgId() {
|
|
|
|
static MsgId current = -2000000000;
|
|
|
|
return ++current;
|
|
|
|
}
|