void DataFilterUploader::UploadToAcc (const QByteArray& accId)
	{
		const auto acc = AccMgr_->GetAccount (accId);
		if (!acc)
		{
			qWarning () << Q_FUNC_INFO
					<< "no account for ID"
					<< accId;
			deleteLater ();
			return;
		}

		const auto& image = Entity_.Entity_.value<QImage> ();
		const auto& localFile = Entity_.Entity_.toUrl ().toLocalFile ();
		if (!image.isNull ())
		{
			auto tempFile = new QTemporaryFile { this };
			Entity_.Entity_.value<QImage> ().save (tempFile, "PNG", 0);
			UploadFileName_ = tempFile->fileName ();
		}
		else if (QFile::exists (localFile))
			UploadFileName_ = localFile;

		const auto dia = new UploadPhotosDialog { acc->GetQObject () };
		dia->LockFiles ();
		dia->SetFiles ({ { UploadFileName_, {} } });
		dia->open ();
		dia->setAttribute (Qt::WA_DeleteOnClose);

		new Util::SlotClosure<Util::DeleteLaterPolicy>
		{
			[this, dia, acc]
			{
				connect (acc->GetQObject (),
						SIGNAL (itemUploaded (UploadItem, QUrl)),
						this,
						SLOT (checkItemUploaded (UploadItem, QUrl)));

				const auto isu = qobject_cast<ISupportUploads*> (acc->GetQObject ());
				isu->UploadImages (dia->GetSelectedCollection (), dia->GetSelectedFiles ());
			},
			dia,
			SIGNAL (accepted ()),
			dia
		};

		connect (dia,
				SIGNAL (rejected ()),
				this,
				SLOT (deleteLater ()));
	}
Example #2
0
	void DataFilterUploader::UploadToAcc (const QByteArray& accId)
	{
		bool shouldCleanup = true;
		auto deleteGuard = std::shared_ptr<void> (nullptr,
				[this, shouldCleanup] (void*)
				{
					if (shouldCleanup)
						deleteLater ();
				});

		const auto acc = AccMgr_->GetAccount (accId);
		if (!acc)
		{
			qWarning () << Q_FUNC_INFO
					<< "no account for ID"
					<< accId;
			return;
		}

		const auto& image = Entity_.Entity_.value<QImage> ();
		const auto& localFile = Entity_.Entity_.toUrl ().toLocalFile ();
		if (!image.isNull ())
		{
			auto tempFile = new QTemporaryFile { this };
			Entity_.Entity_.value<QImage> ().save (tempFile, "PNG", 0);
			UploadFileName_ = tempFile->fileName ();
		}
		else if (QFile::exists (localFile))
			UploadFileName_ = localFile;

		UploadPhotosDialog dia { acc->GetQObject() };
		dia.LockFiles ();
		dia.SetFiles ({ { UploadFileName_, {} } });
		if (dia.exec () != QDialog::Accepted)
			return;

		connect (acc->GetQObject (),
				SIGNAL (itemUploaded (UploadItem, QUrl)),
				this,
				SLOT (checkItemUploaded (UploadItem, QUrl)));

		const auto isu = qobject_cast<ISupportUploads*> (acc->GetQObject ());
		isu->UploadImages (dia.GetSelectedCollection (), dia.GetSelectedFiles ());
		shouldCleanup = false;
	}