Esempio n. 1
0
	void Plugin::Upload (const QString& localPath, const QString& to, const QString& relPath)
	{
		QString target = to;
		if (!target.endsWith ('/') && !relPath.startsWith ('/'))
			target += '/';
		target += relPath;

		const QString& dirPath = relPath.left (relPath.lastIndexOf ('/'));
		if (!QDir (to).mkpath (dirPath))
		{
			emit uploadFinished (localPath,
					QFile::PermissionsError,
					tr ("Unable to create the directory path %1 on target device %2.")
						.arg (dirPath)
						.arg (to));
			return;
		}

		auto watcher = new QFutureWatcher<QFile_ptr> (this);
		connect (watcher,
				SIGNAL (finished ()),
				this,
				SLOT (handleCopyFinished ()));

		std::function<QFile_ptr (void)> copier = [target, localPath] ()
				{
					QFile_ptr file (new QFile (localPath));
					file->copy (target);
					return file;
				};
		const auto& future = QtConcurrent::run (copier);
		watcher->setFuture (future);
	}
Esempio n. 2
0
	void GraffitiTab::handleIterateFinished ()
	{
		auto recIterator = qobject_cast<RecIterator*> (sender ());
		recIterator->deleteLater ();

		const auto& files = recIterator->GetResult ();

		FilesWatcher_->AddFiles (files);
		FilesModel_->AddFiles (files);

		auto resolver = LMPProxy_->GetTagResolver ();
		auto worker = [resolver, files] () -> QList<MediaInfo>
		{
			QList<MediaInfo> infos;
			for (const auto& file : files)
				try
				{
					infos << resolver->ResolveInfo (file.absoluteFilePath ());
				}
				catch (const std::exception& e)
				{
					qWarning () << Q_FUNC_INFO
							<< e.what ();
				}
			return infos;
		};

		auto scanWatcher = new QFutureWatcher<QList<MediaInfo>> ();
		connect (scanWatcher,
				SIGNAL (finished ()),
				this,
				SLOT (handleScanFinished ()));
		scanWatcher->setProperty ("LMP/Graffiti/Filename", recIterator->property ("LMP/Graffiti/Filename"));
		scanWatcher->setFuture (QtConcurrent::run (std::function<QList<MediaInfo> ()> (worker)));
	}
Esempio n. 3
0
	void IcecastFetcher::ParseList ()
	{
		auto watcher = new QFutureWatcher<Stations_t> (this);
		connect (watcher,
				SIGNAL (finished ()),
				this,
				SLOT (handleParsed ()));
		watcher->setFuture (QtConcurrent::run (ParseWorker));
	}
void KdeWaylandImageGrabber::startReadImage(int readPipe)
{
    auto watcher = new QFutureWatcher<QImage>(this);
    QObject::connect(watcher, &QFutureWatcher<QImage>::finished, this,
    [watcher, this] {
        watcher->deleteLater();
        auto image = watcher->result();
        emit finished(QPixmap::fromImage(image));
    });
    watcher->setFuture(QtConcurrent::run(readImage, readPipe));
}
HistoryMessagesPrepender::HistoryMessagesPrepender(QFuture<SortedMessages> messages, WebkitMessagesView *chatMessagesView, QObject *parent) :
		QObject{parent},
		m_messages{std::move(messages)},
		m_messagesView(chatMessagesView)
{
	Q_ASSERT(m_messagesView);

	connect(m_messagesView, SIGNAL(destroyed()), this, SLOT(deleteLater()));

	auto futureWatcher = make_owned<QFutureWatcher<SortedMessages>>(this);
	connect(futureWatcher.get(), SIGNAL(finished()), this, SLOT(messagesAvailable()));

	futureWatcher->setFuture(m_messages);
}
Esempio n. 6
0
	void Plugin::pollDevices ()
	{
		if (IsPolling_)
			return;

		auto watcher = new QFutureWatcher<USBDevInfos_t> ();
		connect (watcher,
				SIGNAL (finished ()),
				this,
				SLOT (handlePollFinished ()));
		auto future = QtConcurrent::run (EnumerateWorker);
		watcher->setFuture (future);

		IsPolling_ = true;
	}
	void AlbumArtManagerDialog::handleImages (const Media::AlbumInfo& info, const QList<QImage>& images)
	{
		qDebug () << Q_FUNC_INFO << images.size ();
		if (info.Album_ != GetAlbum () || info.Artist_ != GetArtist ())
			return;

		auto watcher = new QFutureWatcher<ScaleResult> ();
		connect (watcher,
				SIGNAL (finished ()),
				this,
				SLOT (handleResized ()));
		auto worker = [info] (const QImage& image) -> ScaleResult
		{
			const auto& scaled = image.scaled (200, 200, Qt::KeepAspectRatio, Qt::SmoothTransformation);
			return { scaled, image, info };
		};
		watcher->setFuture (QtConcurrent::mapped (images, std::function<ScaleResult (QImage)> (worker)));
	}
	void StreamListFetcherBase::HandleData (const QByteArray& data)
	{
		auto watcher = new QFutureWatcher<decltype (Parse (data))> ();
		connect (watcher,
				SIGNAL (finished ()),
				this,
				SLOT (handleParsed ()));

		auto task = [this, data] () -> decltype (Parse (data))
		{
			auto result = Parse (data);
			std::sort (result.begin (), result.end (),
					[] (decltype (result.at (0)) left, decltype (result.at (0)) right)
						{ return QString::localeAwareCompare (left.Name_, right.Name_) < 0; });
			return result;
		};
		watcher->setFuture (QtConcurrent::run (task));
	}
Esempio n. 9
0
	void BioViewManager::handleAlbumArt (const Media::AlbumInfo& info, const QList<QImage>& images)
	{
		if (info.Artist_ != CurrentArtist_ || images.isEmpty ())
			return;

		auto img = images.first ();
		if (img.width () <= AASize)
		{
			SetAlbumImage (info.Album_, img);
			return;
		}

		auto watcher = new QFutureWatcher<ScaleResult> ();
		connect (watcher,
				SIGNAL (finished ()),
				this,
				SLOT (handleImageScaled ()));

		watcher->setFuture (QtConcurrent::run ([img, info] () -> ScaleResult
				{ return { img.scaled (AASize, AASize, Qt::KeepAspectRatio, Qt::SmoothTransformation), info.Album_ }; }));
	}
Esempio n. 10
0
void MainWindow::openDocument(const QUrl &url)
{
    Q_D(MainWindow);
    if (!url.isLocalFile()) {
        return;
    }

    d->_url = url;

    using Result = std::pair<ImageIOResult, ImageContents>;

    auto worker = [](const QString &path)
    {
        ImageIO io(path);
        return io.read();
    };

    auto finisher = [this, d]()
    {
        const auto watcher = static_cast<QFutureWatcher<Result> *>(sender());
        const auto result = watcher->future().result();
        const auto &status = result.first;
        const auto &contents = result.second;
        watcher->deleteLater();
        if (status) {
            d->_document->setContents(contents);
        } else {
            QMessageBox::warning(this,
                                 tr("Open"),
                                 tr("Can't open file"),
                                 QMessageBox::Close);
        }
    };

    auto watcher = new QFutureWatcher<Result>(this);
    connect(watcher, &QFutureWatcherBase::finished, this, finisher);
    watcher->setFuture(QtConcurrent::run(worker, url.toLocalFile()));
}
Esempio n. 11
0
void MainWindow::saveDocument(const QUrl &url, const QByteArray &subType, const ImageOptions &options)
{
    Q_D(MainWindow);

    if (!url.isLocalFile()) {
        return;
    }

    const auto workerSubType = subType;
    const auto workerOptions = options;
    using Result = ImageIOResult;

    auto worker = [workerSubType, workerOptions](const QString &path, const ImageContents &contents)
    {
        ImageIO io(path);
        io.setSubType(workerSubType);
        return io.write(contents, workerOptions);
    };

    auto finisher = [this]()
    {
        const auto watcher = static_cast<QFutureWatcher<Result> *>(sender());
        const auto result = watcher->future().result();
        watcher->deleteLater();
        if (!result) {
            QMessageBox::warning(this,
                                 tr("Save"),
                                 tr("Can't save file"),
                                 QMessageBox::Close);
        }
    };

    auto watcher = new QFutureWatcher<Result>(this);
    connect(watcher, &QFutureWatcherBase::finished, this, finisher);
    watcher->setFuture(QtConcurrent::run(worker, url.toLocalFile(), d->_document->toContents()));
}
Esempio n. 12
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);
	}