X-Git-Url: http://cgit.sxemacs.org/?p=harmattan%2Fcameraplus;a=blobdiff_plain;f=lib%2Fqtcammode_p.h;h=b724ffd9650de6ff3527530ad77a5340b4be4e17;hp=201d0ac8d32361a79680280696b4b8b53edb6de2;hb=2f83aedd8945838e64037ff02dc3b994c2f1cee0;hpb=b5d64ba56b64a176af1c1d54c9a846c2d54358df diff --git a/lib/qtcammode_p.h b/lib/qtcammode_p.h index 201d0ac..b724ffd 100644 --- a/lib/qtcammode_p.h +++ b/lib/qtcammode_p.h @@ -3,7 +3,7 @@ /*! * This file is part of CameraPlus. * - * Copyright (C) 2012 Mohammed Sameer + * Copyright (C) 2012-2013 Mohammed Sameer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -24,9 +24,13 @@ #define QT_CAM_MODE_P_H #include +#include +#include #include "qtcamdevice_p.h" +#include "qtcamanalysisbin.h" #include #include +#include "qtcamgstreamermessagehandler.h" #ifndef GST_USE_UNSTABLE_API #define GST_USE_UNSTABLE_API @@ -44,6 +48,10 @@ public: QtCamModePrivate(QtCamDevicePrivate *d) : id(-1), dev(d) {} virtual ~QtCamModePrivate() {} + void init(DoneHandler *handler) { + doneHandler = handler; + } + int modeId(const char *mode) { if (!dev->cameraBin) { return -1; @@ -73,8 +81,17 @@ public: GstEncodingProfile *loadProfile(const QString& path, const QString& name) { GError *error = NULL; + QString targetPath; + QFileInfo info(path); + if (!info.isAbsolute()) { + targetPath = QDir(DATA_DIR).absoluteFilePath(path); + } + else { + targetPath = info.filePath(); + } - GstEncodingTarget *target = gst_encoding_target_load_from_file(path.toUtf8().data(), &error); + GstEncodingTarget *target = gst_encoding_target_load_from_file(targetPath.toUtf8().constData(), + &error); if (!target) { qCritical() << "Failed to load encoding target from" << path << error->message; g_error_free(error); @@ -168,7 +185,13 @@ public: else { QString preview = QString(PREVIEW_CAPS).arg(size.width()).arg(size.height()); - GstCaps *caps = gst_caps_from_string(preview.toAscii()); + GstCaps *caps = gst_caps_from_string(preview.toLatin1()); + + if (!dev->conf->isPreviewSupported()) { + qWarning() << "Cannot set preview caps. Preview not supported"; + gst_caps_unref(caps); + return; + } g_object_set(dev->cameraBin, "preview-caps", caps, "post-previews", TRUE, NULL); @@ -179,10 +202,23 @@ public: void setFileName(const QString& file) { fileName = file; } + void setTempFileName(const QString& file) { tempFileName = file; } + void enableViewfinderFilters() { + if (dev->viewfinderFilters) { + dev->viewfinderFilters->setBlocked(false); + } + } + + void disableViewfinderFilters() { + if (dev->viewfinderFilters) { + dev->viewfinderFilters->setBlocked(true); + } + } + int id; QtCamMode *q_ptr; QtCamDevicePrivate *dev; @@ -192,4 +228,41 @@ public: QString tempFileName; }; +class DoneHandler : public QtCamGStreamerMessageHandler { +public: + DoneHandler(QtCamModePrivate *m, const char *done, QObject *parent = 0) : + QtCamGStreamerMessageHandler(done, parent) { + mode = m; + } + + virtual ~DoneHandler() { } + + virtual void handleMessage(GstMessage *message) { + // If we have a temp file then we rename it: + if (!mode->tempFileName.isEmpty() && !mode->fileName.isEmpty()) { + if (!QFile::rename(mode->tempFileName, mode->fileName)) { + qCritical() << "Failed to rename" << mode->tempFileName << "to" << mode->fileName; + } + } + + QString fileName; + const GstStructure *s = gst_message_get_structure(message); + if (gst_structure_has_field(s, "filename")) { + const char *str = gst_structure_get_string(s, "filename"); + if (str) { + fileName = QString::fromUtf8(str); + } + } + + if (fileName.isEmpty()) { + fileName = mode->fileName; + } + + QMetaObject::invokeMethod(mode->q_ptr, "saved", Qt::QueuedConnection, + Q_ARG(QString, fileName)); + } + + QtCamModePrivate *mode; +}; + #endif /* QT_CAM_MODE_P_H */