void BackgroundInner::gotWallpapers(const MTPVector<MTPWallPaper> &result) { App::WallPapers wallpapers; wallpapers.push_back(App::WallPaper(0, ImagePtr(st::msgBG0), ImagePtr(st::msgBG0))); const QVector<MTPWallPaper> &v(result.c_vector().v); for (int i = 0, l = v.size(); i < l; ++i) { const MTPWallPaper w(v.at(i)); switch (w.type()) { case mtpc_wallPaper: { const MTPDwallPaper &d(w.c_wallPaper()); const QVector<MTPPhotoSize> &sizes(d.vsizes.c_vector().v); const MTPPhotoSize *thumb = 0, *full = 0; int32 thumbLevel = -1, fullLevel = -1; for (QVector<MTPPhotoSize>::const_iterator j = sizes.cbegin(), e = sizes.cend(); j != e; ++j) { char size = 0; int32 w = 0, h = 0; switch (j->type()) { case mtpc_photoSize: { const string &s(j->c_photoSize().vtype.c_string().v); if (s.size()) size = s[0]; w = j->c_photoSize().vw.v; h = j->c_photoSize().vh.v; } break; case mtpc_photoCachedSize: { const string &s(j->c_photoCachedSize().vtype.c_string().v); if (s.size()) size = s[0]; w = j->c_photoCachedSize().vw.v; h = j->c_photoCachedSize().vh.v; } break; } if (!size || !w || !h) continue; int32 newThumbLevel = qAbs((st::backgroundSize.width() * cIntRetinaFactor()) - w), newFullLevel = qAbs(2560 - w); if (thumbLevel < 0 || newThumbLevel < thumbLevel) { thumbLevel = newThumbLevel; thumb = &(*j); } if (fullLevel < 0 || newFullLevel < fullLevel) { fullLevel = newFullLevel; full = &(*j); } } if (thumb && full && full->type() != mtpc_photoSizeEmpty) { wallpapers.push_back(App::WallPaper(d.vid.v ? d.vid.v : INT_MAX, App::image(*thumb), App::image(*full))); } } break; case mtpc_wallPaperSolid: { const MTPDwallPaperSolid &d(w.c_wallPaperSolid()); } break; } } App::cSetServerBackgrounds(wallpapers); updateWallpapers(); }
BackgroundInner::BackgroundInner() : _bgCount(0), _rows(0), _over(-1), _overDown(-1) { if (App::cServerBackgrounds().isEmpty()) { resize(BackgroundsInRow * (st::backgroundSize.width() + st::backgroundPadding) + st::backgroundPadding, 2 * (st::backgroundSize.height() + st::backgroundPadding) + st::backgroundPadding); MTP::send(MTPaccount_GetWallPapers(), rpcDone(&BackgroundInner::gotWallpapers)); } else { updateWallpapers(); } setMouseTracking(true); }