std::unique_ptr<HistoryMedia> CreateAttach(
		not_null<HistoryView::Element*> parent,
		DocumentData *document,
		PhotoData *photo,
		const std::vector<std::unique_ptr<Data::Media>> &collage,
		const QString &webpageUrl) {
	if (!collage.empty()) {
		return std::make_unique<HistoryGroupedMedia>(parent, collage);
	} else if (document) {
		if (document->sticker()) {
			return std::make_unique<HistorySticker>(parent, document);
		} else if (document->isAnimation()) {
			return std::make_unique<HistoryGif>(parent, document);
		} else if (document->isVideoFile()) {
			return std::make_unique<HistoryVideo>(
				parent,
				parent->data(),
				document);
		} else if (document->isWallPaper()) {
			return std::make_unique<HistoryWallPaper>(
				parent,
				document,
				webpageUrl);
		}
		return std::make_unique<HistoryDocument>(parent, document);
	} else if (photo) {
		return std::make_unique<HistoryPhoto>(
			parent,
			parent->data(),
			photo);
	}
	return nullptr;
}
Esempio n. 2
0
void MessageCursor::fillFrom(not_null<const Ui::InputField*> field) {
	const auto cursor = field->textCursor();
	position = cursor.position();
	anchor = cursor.anchor();
	const auto top = field->scrollTop().current();
	scroll = (top != field->scrollTopMax()) ? top : QFIXED_MAX;
}
Esempio n. 3
0
void PeerListContent::removeRow(not_null<PeerListRow*> row) {
	auto index = row->absoluteIndex();
	auto isSearchResult = row->isSearchResult();
	auto &eraseFrom = isSearchResult ? _searchRows : _rows;

	Assert(index >= 0 && index < eraseFrom.size());
	Assert(eraseFrom[index].get() == row);

	auto pressedData = saveSelectedData(_pressed);
	auto contextedData = saveSelectedData(_contexted);
	setSelected(Selected());
	setPressed(Selected());
	setContexted(Selected());

	_rowsById.erase(row->id());
	auto &byPeer = _rowsByPeer[row->peer()];
	byPeer.erase(ranges::remove(byPeer, row), end(byPeer));
	removeFromSearchIndex(row);
	_filterResults.erase(
		ranges::remove(_filterResults, row),
		end(_filterResults));
	removeRowAtIndex(eraseFrom, index);

	restoreSelection();
	setPressed(restoreSelectedData(pressedData));
	setContexted(restoreSelectedData(contextedData));
}
Esempio n. 4
0
void AdaptiveStepSize<ODE>::WriteToMessage(
    not_null<serialization::AdaptiveStepSizeIntegratorInstance::
                 AdaptiveStepSize*> const message) const {
  first_time_step.WriteToMessage(message->mutable_first_time_step());
  message->set_safety_factor(safety_factor);
  message->set_max_steps(max_steps);
}
Esempio n. 5
0
void ReplyPreview::prepare(
		not_null<Image*> image,
		FileOrigin origin,
		Images::Options options) {
	int w = image->width(), h = image->height();
	if (w <= 0) w = 1;
	if (h <= 0) h = 1;
	auto thumbSize = (w > h)
		? QSize(
			w * st::msgReplyBarSize.height() / h,
			st::msgReplyBarSize.height())
		: QSize(
			st::msgReplyBarSize.height(),
			h * st::msgReplyBarSize.height() / w);
	thumbSize *= cIntRetinaFactor();
	const auto prepareOptions = Images::Option::Smooth
		| Images::Option::TransparentBackground
		| options;
	auto outerSize = st::msgReplyBarSize.height();
	auto bitmap = image->pixNoCache(
		origin,
		thumbSize.width(),
		thumbSize.height(),
		prepareOptions,
		outerSize,
		outerSize);
	_data = std::make_unique<ReplyPreview::Data>(
		std::make_unique<Images::ImageSource>(
			bitmap.toImage(),
			"PNG"),
		((options & Images::Option::Blurred) == 0));
}
Esempio n. 6
0
  void TestRotatingBody() {
    using F = Frame<Tag, tag, true>;

    AngularVelocity<F> const angular_velocity =
        AngularVelocity<F>({-1 * Radian / Second,
                            2 * Radian / Second,
                            5 * Radian / Second});
    auto const rotating_body =
        RotatingBody<F>(17 * SIUnit<GravitationalParameter>(),
                        typename RotatingBody<F>::Parameters(
                            3 * Radian,
                            Instant() + 4 * Second,
                            angular_velocity));

    serialization::Body message;
    RotatingBody<F> const* cast_rotating_body;
    rotating_body.WriteToMessage(&message);
    EXPECT_TRUE(message.has_massive_body());
    EXPECT_FALSE(message.has_massless_body());
    EXPECT_TRUE(message.massive_body().HasExtension(
                    serialization::RotatingBody::rotating_body));

    not_null<std::unique_ptr<MassiveBody const>> const massive_body =
        MassiveBody::ReadFromMessage(message);
    EXPECT_EQ(rotating_body.gravitational_parameter(),
              massive_body->gravitational_parameter());
    cast_rotating_body = dynamic_cast<RotatingBody<F> const*>(&*massive_body);
    EXPECT_THAT(cast_rotating_body, NotNull());
  }
Esempio n. 7
0
bool Groups::isGrouped(not_null<HistoryItem*> item) const {
	if (!item->groupId()) {
		return false;
	}
	const auto media = item->media();
	return media && media->canBeGrouped();
}
Esempio n. 8
0
File: Odin.cpp Progetto: llnek/elmo
j::json evtToDoc(not_null<OdinEvent*> evt) {
  return j::json({
    {"type", (int) evt->getType() },
    {"code", (int) evt->getCode() },
    {"source", evt->getDoco() }
  });
}
Esempio n. 9
0
void Ephemeris<Frame>::ComputeMasslessBodiesGravitationalAccelerations(
      Instant const& t,
      std::vector<Position<Frame>> const& positions,
      not_null<std::vector<Vector<Acceleration, Frame>>*> const accelerations,
      not_null<std::vector<typename ContinuousTrajectory<Frame>::Hint>*>
          const hints) const {
  CHECK_EQ(positions.size(), accelerations->size());
  accelerations->assign(accelerations->size(), Vector<Acceleration, Frame>());

  for (std::size_t b1 = 0; b1 < number_of_oblate_bodies_; ++b1) {
    MassiveBody const& body1 = *bodies_[b1];
    ComputeGravitationalAccelerationByMassiveBodyOnMasslessBodies<
        /*body1_is_oblate=*/true>(
        t,
        body1, b1,
        positions,
        accelerations,
        &(*hints)[b1]);
  }
  for (std::size_t b1 = number_of_oblate_bodies_;
       b1 < number_of_oblate_bodies_ +
            number_of_spherical_bodies_;
       ++b1) {
    MassiveBody const& body1 = *bodies_[b1];
    ComputeGravitationalAccelerationByMassiveBodyOnMasslessBodies<
        /*body1_is_oblate=*/false>(
        t,
        body1, b1,
        positions,
        accelerations,
        &(*hints)[b1]);
  }
}
Esempio n. 10
0
void Ephemeris<Frame>::WriteToMessage(
    not_null<serialization::Ephemeris*> const message) const {
  LOG(INFO) << __FUNCTION__;
  // The bodies are serialized in the order in which they were given at
  // construction.
  for (auto const& unowned_body : unowned_bodies_) {
    unowned_body->WriteToMessage(message->add_body());
  }
  // The trajectories are serialized in the order resulting from the separation
  // between oblate and spherical bodies.
  if (checkpoints_.empty()) {
    for (auto const& trajectory : trajectories_) {
      trajectory->WriteToMessage(message->add_trajectory());
    }
    last_state_.WriteToMessage(message->mutable_last_state());
  } else {
    auto const& checkpoints = checkpoints_.front().checkpoints;
    CHECK_EQ(trajectories_.size(), checkpoints.size());
    for (int i = 0; i < trajectories_.size(); ++i) {
      trajectories_[i]->WriteToMessage(message->add_trajectory(),
                                       checkpoints[i]);
    }
    checkpoints_.front().system_state.WriteToMessage(
        message->mutable_last_state());
    t_max().WriteToMessage(message->mutable_t_max());
  }
  parameters_.WriteToMessage(message->mutable_fixed_step_parameters());
  fitting_tolerance_.WriteToMessage(message->mutable_fitting_tolerance());
  LOG(INFO) << NAMED(message->SpaceUsed());
  LOG(INFO) << NAMED(message->ByteSize());
}
Esempio n. 11
0
void Pair<T1, T2>::WriteToMessage(
    not_null<serialization::Pair*> const message) const {
  PointOrMultivectorSerializer<T1, serialization::Pair::Element>::
      WriteToMessage(t1_, message->mutable_t1());
  PointOrMultivectorSerializer<T2, serialization::Pair::Element>::
      WriteToMessage(t2_, message->mutable_t2());
}
Esempio n. 12
0
void MessageCursor::applyTo(not_null<Ui::InputField*> field) {
	auto cursor = field->textCursor();
	cursor.setPosition(anchor, QTextCursor::MoveAnchor);
	cursor.setPosition(position, QTextCursor::KeepAnchor);
	field->setTextCursor(cursor);
	field->scrollTo(scroll);
}
Esempio n. 13
0
Subset<Vessel>::Properties::Properties(not_null<ksp_plugin::Vessel*> vessel) {
  if (vessel->is_piled_up()) {
    missing_ = vessel->containing_pile_up()->iterator()->vessels().size() - 1;
  }
  vessels_.emplace_back(vessel);
  total_mass_ = vessel->mass();
  total_intrinsic_force_ = vessel->intrinsic_force();
}
Esempio n. 14
0
File: Odin.cpp Progetto: llnek/elmo
//////////////////////////////////////////////////////////////////////////////
// Send this msg through the socket
void netSend(not_null<OdinIO*> wss,
             MType m, EType e, const j::json &body) {

  if (wss->getState() == CType::S_CONNECTED) {
    auto d = evtToDoc(m,e,body);
    wss->getSocket()->send(d.dump());
  }
}
Esempio n. 15
0
void Frame<FrameTag, frame_tag, frame_is_inertial>::WriteToMessage(
    not_null<serialization::Frame*> const message) {
  std::string const& tag_type_full_name =
      google::protobuf::GetEnumDescriptor<Tag>()->full_name();

  message->set_tag_type_fingerprint(Fingerprint(tag_type_full_name));
  message->set_tag(tag);
  message->set_is_inertial(is_inertial);
}
Esempio n. 16
0
Source SourceFromPeer(not_null<PeerData*> peer) {
	if (peer->isUser()) {
		return Source::User;
	} else if (peer->isChat() || peer->isMegagroup()) {
		return Source::Group;
	} else {
		return Source::Channel;
	}
}
Esempio n. 17
0
inline void Celestial::WriteToMessage(
    not_null<serialization::Celestial*> const message) const {
  CHECK(is_initialized());
  body_->WriteToMessage(message->mutable_body());
  history_->WriteToMessage(
      message->mutable_history_and_prolongation()->mutable_history());
  prolongation_->WritePointerToMessage(
      message->mutable_history_and_prolongation()->mutable_prolongation());
}
Esempio n. 18
0
void BoxContent::setDimensionsToContent(
		int newWidth,
		not_null<Ui::RpWidget*> content) {
	content->resizeToWidth(newWidth);
	content->heightValue(
	) | rpl::start_with_next([=](int height) {
		setDimensions(newWidth, height);
	}, content->lifetime());
}
HistoryPhoto::HistoryPhoto(
	not_null<Element*> parent,
	not_null<PeerData*> chat,
	not_null<PhotoData*> photo,
	int width)
: HistoryFileMedia(parent, parent->data())
, _data(photo)
, _serviceWidth(width) {
	create(parent->data()->fullId(), chat);
}
Esempio n. 20
0
void Ephemeris<Frame>::AdaptiveStepParameters::WriteToMessage(
    not_null<serialization::Ephemeris::AdaptiveStepParameters*> const message)
    const {
  integrator_->WriteToMessage(message->mutable_integrator());
  message->set_max_steps(max_steps_);
  length_integration_tolerance_.WriteToMessage(
      message->mutable_length_integration_tolerance());
  speed_integration_tolerance_.WriteToMessage(
      message->mutable_speed_integration_tolerance());
}
Esempio n. 21
0
void DoublePrecision<T>::WriteToMessage(
    not_null<serialization::DoublePrecision*> const message) const {
  using ValueSerializer = PointOrMultivectorSerializer<
                              T, serialization::DoublePrecision::Value>;
  using ErrorSerializer = QuantityOrMultivectorSerializer<
                              Difference<T>,
                              serialization::DoublePrecision::Error>;
  ValueSerializer::WriteToMessage(value, message->mutable_value());
  ErrorSerializer::WriteToMessage(error, message->mutable_error());
}
Esempio n. 22
0
 static std::vector<Instant> Times(
     not_null<FakeTrajectory const*> const trajectory) {
   std::vector<Instant> times;
   for (FakeTrajectory::Iterator it = trajectory->Begin();
        it != trajectory->End();
        ++it) {
     times.push_back(*it.current());
   }
   return times;
 }
rpl::producer<bool> VerifiedValue(
		not_null<PeerData*> peer) {
	if (auto user = peer->asUser()) {
		return Data::PeerFlagValue(user, MTPDuser::Flag::f_verified);
	} else if (auto channel = peer->asChannel()) {
		return Data::PeerFlagValue(
			channel,
			MTPDchannel::Flag::f_verified);
	}
	return rpl::single(false);
}
Esempio n. 24
0
void
SpecialSecondOrderDifferentialEquation<Position>::SystemState::WriteToMessage(
        not_null<serialization::SystemState*> const message) const {
  for (auto const& position : positions) {
    position.WriteToMessage(message->add_position());
  }
  for (auto const& velocity : velocities) {
    velocity.WriteToMessage(message->add_velocity());
  }
  time.WriteToMessage(message->mutable_time());
}
Esempio n. 25
0
 static std::vector<Instant> After(
     not_null<FakeTrajectory const*> const trajectory,
     Instant const& time) {
   std::vector<Instant> after;
   for (FakeTrajectory::Iterator it = trajectory->Find(time);
        it != trajectory->End();
        ++it) {
     after.push_back(*it.current());
   }
   return after;
 }
Esempio n. 26
0
void PeerListContent::addToSearchIndex(not_null<PeerListRow*> row) {
	if (row->isSearchResult()) {
		return;
	}

	removeFromSearchIndex(row);
	row->setNameFirstLetters(row->peer()->nameFirstLetters());
	for (auto ch : row->nameFirstLetters()) {
		_searchIndex[ch].push_back(row);
	}
}
rpl::producer<int> KickedCountValue(
		not_null<ChannelData*> channel) {
	using Flag = Notify::PeerUpdate::Flag;
	return Notify::PeerUpdateValue(
		channel,
		Flag::BannedUsersChanged | Flag::ChannelRightsChanged
	) | rpl::map([channel] {
		return channel->canViewBanned()
			? channel->kickedCount()
			: 0;
	});
}
rpl::producer<int> AdminsCountValue(
		not_null<ChannelData*> channel) {
	using Flag = Notify::PeerUpdate::Flag;
	return Notify::PeerUpdateValue(
		channel,
		Flag::AdminsChanged | Flag::ChannelRightsChanged
	) | rpl::map([channel] {
		return channel->canViewAdmins()
			? channel->adminsCount()
			: 0;
	});
}
void ЧебышёвSeries<Vector>::WriteToMessage(
    not_null<serialization::ЧебышёвSeries*> const message) const {
    using Serializer = DoubleOrQuantityOrMultivectorSerializer<
                       Vector,
                       serialization::ЧебышёвSeries::Coefficient>;

    for (int k = 0; k <= helper_.degree(); ++k) {
        Serializer::WriteToMessage(helper_.coefficients(k),
                                   message->add_coefficient());
    }
    t_min_.WriteToMessage(message->mutable_t_min());
    t_max_.WriteToMessage(message->mutable_t_max());
}
Esempio n. 30
0
void HexEncode(not_null<benchmark::State*> const state,
              not_null<bool*> const correct,
              std::vector<uint8_t> const& input_bytes,
              std::vector<uint8_t> const& expected_digits) {
  state->PauseTiming();
  std::vector<uint8_t> digits(input_bytes.size() << 1);
  state->ResumeTiming();
  HexadecimalEncode({input_bytes.data(), input_bytes.size()},
                    {digits.data(), digits.size()});
  state->PauseTiming();
  *correct &= digits == expected_digits;
  state->ResumeTiming();
}