2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

webPage links preview previews done

This commit is contained in:
John Preston
2015-04-07 01:15:29 +03:00
parent 11dd70cb1a
commit 9ede565a00
25 changed files with 1093 additions and 630 deletions

View File

@@ -30,7 +30,7 @@ _about(st::boxWidth - st::addContactPadding.left() - st::addContactPadding.right
_saveButton(this, lang(_turningOff ? lng_passcode_remove_button : lng_settings_save), st::btnSelectDone),
_cancelButton(this, lang(lng_cancel), st::btnSelectCancel),
_oldPasscode(this, st::inpAddContact, lang(lng_passcode_enter_old)),
_newPasscode(this, st::inpAddContact, lang(lng_passcode_enter_new)),
_newPasscode(this, st::inpAddContact, lang(cHasPasscode() ? lng_passcode_enter_new : lng_passcode_enter_first)),
_reenterPasscode(this, st::inpAddContact, lang(lng_passcode_confirm_new)),
_passwordHint(this, st::inpAddContact, lang(lng_cloud_password_hint)),
_recoverEmail(this, st::inpAddContact, lang(lng_cloud_password_email)),
@@ -45,7 +45,7 @@ _about(st::boxWidth - st::addContactPadding.left() - st::addContactPadding.right
_saveButton(this, lang(_turningOff ? lng_passcode_remove_button : lng_settings_save), st::btnSelectDone),
_cancelButton(this, lang(lng_cancel), st::btnSelectCancel),
_oldPasscode(this, st::inpAddContact, lang(lng_cloud_password_enter_old)),
_newPasscode(this, st::inpAddContact, lang(lng_cloud_password_enter_new)),
_newPasscode(this, st::inpAddContact, lang(curSalt.isEmpty() ? lng_cloud_password_enter_first : lng_cloud_password_enter_new)),
_reenterPasscode(this, st::inpAddContact, lang(lng_cloud_password_confirm_new)),
_passwordHint(this, st::inpAddContact, lang(lng_cloud_password_hint)),
_recoverEmail(this, st::inpAddContact, lang(lng_cloud_password_email)),

View File

@@ -36,7 +36,7 @@ void SessionsInner::paintEvent(QPaintEvent *e) {
p.fillRect(r, st::white->b);
p.setFont(st::linkFont->f);
int32 x = st::sessionPadding.left(), xact = st::sessionTerminateSkip + st::sessionTerminate.width + st::sessionTerminateSkip;
int32 x = st::sessionPadding.left(), xact = st::sessionTerminateSkip + st::sessionTerminate.iconPos.x();// st::sessionTerminateSkip + st::sessionTerminate.width + st::sessionTerminateSkip;
int32 w = width() - 2 * x, availw = width() - 2 * xact;
int32 from = (r.top() >= 0) ? qFloor(r.top() / st::sessionHeight) : 0, count = _list->size();
if (from < count) {
@@ -55,8 +55,10 @@ void SessionsInner::paintEvent(QPaintEvent *e) {
p.drawTextRight(xact, st::sessionPadding.top(), availw, auth.active, auth.activeWidth);
p.setFont(st::sessionInfoFont->f);
p.setPen(st::sessionInfoColor->p);
p.setPen(st::black->p);
p.drawTextLeft(x, st::sessionPadding.top() + st::sessionNameFont->height, w, auth.info, auth.infoWidth);
p.setPen(st::sessionInfoColor->p);
p.drawTextLeft(x, st::sessionPadding.top() + st::sessionNameFont->height + st::sessionInfoFont->height, w, auth.ip, auth.ipWidth);
p.translate(0, st::sessionHeight);
}
@@ -221,9 +223,10 @@ void SessionsBox::paintEvent(QPaintEvent *e) {
p.drawTextRight(x, st::sessionPadding.top(), w, _current.active, _current.activeWidth);
p.setFont(st::sessionInfoFont->f);
p.setPen(st::sessionInfoColor->p);
p.setPen(st::black->p);
p.drawTextLeft(x, st::sessionPadding.top() + st::sessionNameFont->height, w, _current.info, _current.infoWidth);
p.setPen(st::sessionInfoColor->p);
p.drawTextLeft(x, st::sessionPadding.top() + st::sessionNameFont->height + st::sessionInfoFont->height, w, _current.ip, _current.ipWidth);
p.translate(0, st::sessionHeight);
if (_list.isEmpty()) {
paintTitle(p, lang(lng_sessions_no_other), true);
@@ -245,7 +248,7 @@ void SessionsBox::gotAuthorizations(const MTPaccount_Authorizations &result) {
_shortPollRequest = 0;
int32 availCurrent = st::boxWidth - st::sessionPadding.left() - st::sessionTerminateSkip;
int32 availOther = availCurrent - st::sessionTerminate.width - st::sessionTerminateSkip;
int32 availOther = availCurrent - st::sessionTerminate.iconPos.x();// -st::sessionTerminate.width - st::sessionTerminateSkip;
_list.clear();
const QVector<MTPAuthorization> &v(result.c_account_authorizations().vauthorizations.c_vector().v);
@@ -259,29 +262,39 @@ void SessionsBox::gotAuthorizations(const MTPaccount_Authorizations &result) {
SessionData data;
data.hash = d.vhash.v;
QString appName, systemVer = qs(d.vsystem_version), deviceModel = qs(d.vdevice_model);
if (d.vapi_id.v == 17349) {
appName = qs(d.vapp_name);// (d.vapi_id.v == 2040) ? qsl("Telegram Desktop") : qsl("Telegram Desktop (GitHub)");
if (systemVer == QLatin1String("windows")) {
deviceModel = qsl("Windows");
} else if (systemVer == QLatin1String("os x")) {
deviceModel = qsl("Mac OS X");
} else if (systemVer == QLatin1String("linux")) {
deviceModel = qsl("Linux");
QString appName, appVer = qs(d.vapp_version), systemVer = qs(d.vsystem_version), deviceModel = qs(d.vdevice_model);
if (d.vapi_id.v == 2040 || d.vapi_id.v == 17349) {
appName = (d.vapi_id.v == 2040) ? qsl("Telegram Desktop") : qsl("Telegram Desktop (GitHub)");
// if (systemVer == QLatin1String("windows")) {
// deviceModel = qsl("Windows");
// } else if (systemVer == QLatin1String("os x")) {
// deviceModel = qsl("OS X");
// } else if (systemVer == QLatin1String("linux")) {
// deviceModel = qsl("Linux");
// }
if (appVer == QString::number(appVer.toInt())) {
int32 ver = appVer.toInt();
appVer = QString("%1.%2").arg(ver / 1000000).arg((ver % 1000000) / 1000) + ((ver % 1000) ? ('.' + QString::number(ver % 1000)) : QString());
} else {
appVer = QString();
}
} else {
appName = qs(d.vapp_name);// +qsl(" for ") + qs(d.vplatform);
if (appVer.indexOf('(') >= 0) appVer = appVer.mid(appVer.indexOf('('));
}
data.name = appName;
if (!appVer.isEmpty()) data.name += ' ' + appVer;
data.nameWidth = st::sessionNameFont->m.width(data.name);
QString country = qs(d.vcountry);
CountriesByISO2::const_iterator j = countries.constFind(country);
if (j != countries.cend()) country = QString::fromUtf8(j.value()->name);
QString country = qs(d.vcountry), platform = qs(d.vplatform);
//CountriesByISO2::const_iterator j = countries.constFind(country);
//if (j != countries.cend()) country = QString::fromUtf8(j.value()->name);
MTPint active = d.vdate_active.v ? d.vdate_active : d.vdate_created;
data.activeTime = active.v;
data.info = country + QLatin1String(" (") + qs(d.vip) + QLatin1String("), ") + deviceModel;
data.info = qs(d.vdevice_model) + QLatin1String(", ") + (platform.isEmpty() ? QString() : platform + ' ') + qs(d.vsystem_version);
data.ip = qs(d.vip) + (country.isEmpty() ? QString() : QString::fromUtf8(" \xe2\x80\x93 ") + country);
if (!data.hash || (d.vflags.v & 1)) {
data.active = QString();
data.activeWidth = 0;
@@ -294,6 +307,11 @@ void SessionsBox::gotAuthorizations(const MTPaccount_Authorizations &result) {
data.info = st::sessionInfoFont->m.elidedText(data.info, Qt::ElideRight, availCurrent);
data.infoWidth = st::sessionInfoFont->m.width(data.info);
}
data.ipWidth = st::sessionInfoFont->m.width(data.ip);
if (data.ipWidth > availCurrent) {
data.ip = st::sessionInfoFont->m.elidedText(data.ip, Qt::ElideRight, availCurrent);
data.ipWidth = st::sessionInfoFont->m.width(data.ip);
}
_current = data;
} else {
QDateTime now(QDateTime::currentDateTime()), lastTime(date(active));
@@ -317,6 +335,11 @@ void SessionsBox::gotAuthorizations(const MTPaccount_Authorizations &result) {
data.info = st::sessionInfoFont->m.elidedText(data.info, Qt::ElideRight, availOther);
data.infoWidth = st::sessionInfoFont->m.width(data.info);
}
data.ipWidth = st::sessionInfoFont->m.width(data.ip);
if (data.ipWidth > availOther) {
data.ip = st::sessionInfoFont->m.elidedText(data.ip, Qt::ElideRight, availOther);
data.ipWidth = st::sessionInfoFont->m.width(data.ip);
}
_list.push_back(data);
for (int32 i = _list.size(); i > 1;) {

View File

@@ -25,8 +25,8 @@ struct SessionData {
uint64 hash;
int32 activeTime;
int32 nameWidth, activeWidth, infoWidth;
QString name, active, info;
int32 nameWidth, activeWidth, infoWidth, ipWidth;
QString name, active, info, ip;
};
typedef QList<SessionData> SessionsList;