Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 9aa6013c authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Use a camera picture for showing the effects for the first time

CCBUG: 404456
BUG: 403121
parent 0b013190
......@@ -51,16 +51,6 @@ Kamoso::Kamoso(WebcamControl *webcamControl)
if (!dirlist.isEmpty())
m_sampleImagePath = dirlist.first().absoluteFilePath();
}
if (m_sampleImagePath.isEmpty()) {
QTemporaryFile* temporary = new QTemporaryFile(QDir::temp().absoluteFilePath("XXXXXX-sampleimage.jpg"), this);
temporary->open();
auto sampleIcon = QIcon::fromTheme(QStringLiteral("kde"));
sampleIcon.pixmap(200, 200).save(temporary);
m_sampleImagePath = temporary->fileName();
temporary->close();
}
}
Kamoso::~Kamoso() = default;
......@@ -88,7 +78,7 @@ const QString Kamoso::takePhoto()
}
const QUrl path = fileNameSuggestion(saveUrl, "picture", "jpg");
m_webcamControl->takePhoto(path);
m_webcamControl->takePhoto(path, true);
if (path.isLocalFile()) {
m_sampleImagePath = path.toLocalFile();
......@@ -147,3 +137,16 @@ void Kamoso::trashFiles(const QJsonArray& urls)
KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash, list, QUrl("trash:/"), job);
// KJobWidgets::setWindow(job, window);
}
QString Kamoso::sampleImage()
{
if (m_sampleImagePath.isEmpty()) {
QScopedPointer<QTemporaryFile> temporary(new QTemporaryFile(QDir::temp().absoluteFilePath("XXXXXX-sampleimage.jpg"), this));
temporary->open();
m_sampleImagePath = temporary->fileName();
temporary->close();
m_webcamControl->takePhoto(QUrl::fromLocalFile(m_sampleImagePath), false);
}
return m_sampleImagePath;
}
......@@ -46,7 +46,7 @@ Q_OBJECT
void setRecording(bool recording);
Q_SCRIPTABLE void trashFiles(const QJsonArray& urls);
QString sampleImage() const { return m_sampleImagePath; }
QString sampleImage();
public Q_SLOTS:
const QString takePhoto();
......
......@@ -77,7 +77,8 @@ GridView {
view.model.remove(index)
}
description: "filesrc location=\"" + webcam.sampleImage + "\" ! decodebin ! imagefreeze ! videoconvert ! " + model.filters + " name=last"
readonly property string sampleImage: view.visible ? webcam.sampleImage : ""
description: "filesrc location=\"" + sampleImage + "\" ! decodebin ! imagefreeze ! videoconvert ! " + model.filters + " name=last"
}
surface: pipe.surface
}
......
......@@ -318,7 +318,7 @@ void WebcamControl::onBusMessage(GstMessage* message)
break;
case GST_MESSAGE_ERROR: {//Some error occurred.
static int error = 0;
qCritical() << "errorrrrrrrrrrrrrrrrrrrrrrrrr:" << debugMessage(message);
qCritical() << "error:" << debugMessage(message);
stop();
if (error < 3) {
play();
......@@ -330,7 +330,8 @@ void WebcamControl::onBusMessage(GstMessage* message)
auto structure = gst_message_get_structure (message);
if (gst_structure_get_name (structure) == QByteArray("image-done")) {
const gchar *filename = gst_structure_get_string (structure, "filename");
Q_EMIT photoTaken(QString::fromUtf8(filename));
if (m_emitTaken)
Q_EMIT photoTaken(QString::fromUtf8(filename));
}
} else {
qDebug() << "skipping message..." << GST_MESSAGE_SRC_NAME (message);
......@@ -342,12 +343,14 @@ void WebcamControl::onBusMessage(GstMessage* message)
break;
}
}
void WebcamControl::takePhoto(const QUrl &url)
void WebcamControl::takePhoto(const QUrl &url, bool emitTaken)
{
if (!m_pipeline) {
qWarning() << "couldn't take photo, no pipeline";
return;
}
m_emitTaken = emitTaken;
g_object_set(m_pipeline.data(), "mode", 1, nullptr);
const QString path = url.isLocalFile() ? url.toLocalFile() : QStandardPaths::writableLocation(QStandardPaths::TempLocation)+"/kamoso_photo.jpg";
......
......@@ -51,7 +51,7 @@ class WebcamControl : public QObject
bool play();
bool playDevice(Device* device);
void stop();
void takePhoto(const QUrl& url);
void takePhoto(const QUrl& url, bool emitTaken);
void startRecording();
QString stopRecording();
......@@ -71,6 +71,7 @@ class WebcamControl : public QObject
QScopedPointer<GstPipeline, GstPointerCleanup<GstPipeline> > m_pipeline;
QScopedPointer<GstElement, GstPointerCleanup<GstElement> > m_cameraSource;
QGst::Quick::VideoSurface* m_surface = nullptr;
bool m_emitTaken = true;
};
#endif // WEBCAMCONTROL_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment