Exemple #1
0
	void DriveManager::handleUploadRequestFinished ()
	{
		QNetworkReply *reply = qobject_cast<QNetworkReply*> (sender ());
		if (!reply)
			return;

		reply->deleteLater ();
		QString path = Reply2FilePath_.take (reply);

		const int code = reply->
				attribute (QNetworkRequest::HttpStatusCodeAttribute).toInt ();
		if (code != 200)
		{
			qWarning () << Q_FUNC_INFO
					<< "upload initiating failed with code:"
					<< code;
			return;
		}

		emit uploadStatusChanged (tr ("Uploading..."), path);

		QFile *file = new QFile (path);
		if (!file->open (QIODevice::ReadOnly))
		{
			qWarning () << Q_FUNC_INFO
					<< "unable to open file: "
					<< file->errorString ();
			return;
		}

		QUrl url (reply->rawHeader ("Location"));
		QNetworkRequest request (url);
#ifdef HAVE_MAGIC
		request.setHeader (QNetworkRequest::ContentTypeHeader,
				magic_file (Magic_, path.toUtf8 ()));
#endif
		request.setHeader (QNetworkRequest::ContentLengthHeader,
				QString::number (QFileInfo (path).size ()).toUtf8 ());

		QNetworkReply *uploadReply = Core::Instance ().GetProxy ()->
				GetNetworkAccessManager ()->put (request, file);
		file->setParent (uploadReply);
		Reply2FilePath_ [uploadReply] = path;

		connect (uploadReply,
				SIGNAL (finished ()),
				this,
				SLOT (handleUploadFinished ()));
		connect (uploadReply,
				SIGNAL (error (QNetworkReply::NetworkError)),
				this,
				SLOT (handleUploadError (QNetworkReply::NetworkError)));
		connect (uploadReply,
				SIGNAL (uploadProgress (qint64, qint64)),
				this,
				SLOT (handleUploadProgress (qint64, qint64)));
	}
	CloudUploader::CloudUploader (ICloudStoragePlugin *cloud, QObject *parent)
	: QObject (parent)
	, Cloud_ (cloud)
	{
		connect (Cloud_->GetQObject (),
				SIGNAL (uploadFinished (QString, LeechCraft::LMP::CloudStorageError, QString)),
				this,
				SLOT (handleUploadFinished (QString, LeechCraft::LMP::CloudStorageError, QString)),
				Qt::UniqueConnection);
	}
Exemple #3
0
void AbstractMaemoUploadAndInstallStep::finishInitialization(const QString &displayName,
    AbstractMaemoPackageInstaller *installer)
{
    setDefaultDisplayName(displayName);
    m_installer = installer;
    m_extendedState = Inactive;

    m_uploader = new MaemoPackageUploader(this);
    connect(m_uploader, SIGNAL(progress(QString)),
        SLOT(handleProgressReport(QString)));
    connect(m_uploader, SIGNAL(uploadFinished(QString)),
        SLOT(handleUploadFinished(QString)));
    connect(m_installer, SIGNAL(stdoutData(QString)),
        SLOT(handleRemoteStdout(QString)));
    connect(m_installer, SIGNAL(stderrData(QString)),
        SLOT(handleRemoteStderr(QString)));
    connect(m_installer, SIGNAL(finished(QString)),
        SLOT(handleInstallationFinished(QString)));
}
Exemple #4
0
	void PendingUpload::HandleGotServer (QNetworkReply *reply)
	{
		if (!Conn_->CheckFinishedReply (reply))
			return;

		const auto& json = Util::ParseJson (reply, Q_FUNC_INFO);
		try
		{
			Conn_->CheckReplyData (json, reply);
		}
		catch (const VkConnection::RecoverableException&)
		{
			return;
		}
		catch (const VkConnection::UnrecoverableException& ex)
		{
			emit errorAppeared (TEProtocolError,
					tr ("Unable to get upload server from VKontakte, protocol error %1: %2.")
						.arg (ex.GetCode ())
						.arg (ex.GetMessage ()));
			emit stateChanged (TSFinished);
			return;
		}

		Acc_->GetLogger () << "got upload server:" << json;

		const QUrl uploadUrl { json.toMap () ["response"].toMap () ["upload_url"].toByteArray () };
		if (!uploadUrl.isValid ())
		{
			emit errorAppeared (TEProtocolError,
					tr ("Unable to get upload server from VKontakte"));
			emit stateChanged (TSFinished);
			return;
		}

		emit stateChanged (TSTransfer);

		const auto multipart = new QHttpMultiPart { QHttpMultiPart::FormDataType };
		QHttpPart filePart;
		filePart.setHeader (QNetworkRequest::ContentDispositionHeader,
				QString ("form-data; name=\"file\"; filename=\"%1\"")
					.arg (QFileInfo { Path_ }.fileName ()));
		const auto file = new QFile { Path_ };
		file->open (QIODevice::ReadOnly);
		filePart.setBodyDevice (file);
		file->setParent (multipart);
		multipart->append (filePart);

		const auto nam = Acc_->GetCoreProxy ()->GetNetworkAccessManager ();
		const auto upReply = nam->post (QNetworkRequest { uploadUrl }, multipart);
		connect (upReply,
				SIGNAL (uploadProgress (qint64, qint64)),
				this,
				SIGNAL (transferProgress (qint64, qint64)));
		connect (upReply,
				SIGNAL (finished ()),
				this,
				SLOT (handleUploadFinished ()));

		multipart->setParent (upReply);
	}
Exemple #5
0
	void Plugin::UploadTo (LIBMTP_mtpdevice_t *device, const QByteArray& storageId,
			const QString& localPath, const QString& origPath)
	{
		if (!device->storage)
			LIBMTP_Get_Storage (device, 0);

		auto storage = device->storage;

		while (storage)
		{
			qDebug () << "st" << storage->id;
			if (QByteArray::number (storage->id) == storageId)
				break;
			storage = storage->next;
		}

		if (!storage)
		{
			qWarning () << Q_FUNC_INFO
					<< "could not find storage"
					<< storageId;
			emit uploadFinished (localPath,
					QFile::ResourceError,
					tr ("Unable to find the requested storage."));
			return;
		}

		const auto id = storage->id;
		const auto& info = OrigInfos_.take (origPath);

		qDebug () << "uploading" << localPath << "of type" << GetFileType (info.FileFormat_) << "to" << storage->id;

		auto track = LIBMTP_new_track_t ();
		track->storage_id = id;

		auto getStr = [] (const QString& str) { return strdup (str.toUtf8 ().constData ()); };

		track->filename = getStr (QFileInfo (localPath).fileName ());
		track->album = getStr (info.Album_);
		track->title = getStr (info.TrackTitle_);
		track->genre = getStr (info.Genres_.join ("; "));
		track->artist = getStr (info.Artist_);
		track->tracknumber = info.TrackNumber_;
		track->filetype = GetFileType (info.FileFormat_);
		track->filesize = QFileInfo (localPath).size ();
		track->date = getStr (QString::number (info.AlbumYear_) + "0101T0000.0");

		auto watcher = new QFutureWatcher<UploadInfo> ();
		connect (watcher,
				SIGNAL (finished ()),
				this,
				SLOT (handleUploadFinished ()));
		const auto future = QtConcurrent::run ([=] () -> UploadInfo
			{
				const auto cbData = new CallbackData { this, 0 };
				const auto res = LIBMTP_Send_Track_From_File (device,
						localPath.toUtf8 ().constData (), track,
						TransferCallback, cbData);
				delete cbData;
				return { res, device, localPath, track, info };
			});
		watcher->setFuture (future);
	}