From c3a61d51cff6c6ac6ddfbde90834b52219231da1 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Tue, 24 Sep 2024 14:23:19 -0500 Subject: [PATCH] removing all of the legacy cpp code --- src/cpp/filemanager.cpp | 187 ------- src/cpp/filemanager.h | 40 -- src/cpp/framedecoder.cpp | 439 ----------------- src/cpp/framedecoder.h | 78 --- src/cpp/imagesqlmodel.cpp | 252 ---------- src/cpp/imagesqlmodel.h | 74 --- src/cpp/presentationsqlmodel.cpp | 283 ----------- src/cpp/presentationsqlmodel.h | 80 --- src/cpp/qsettingscxx.h | 24 - src/cpp/serviceitem.cpp | 222 --------- src/cpp/serviceitem.h | 100 ---- src/cpp/serviceitemmodel.cpp | 793 ----------------------------- src/cpp/serviceitemmodel.h | 101 ---- src/cpp/slide.cpp | 253 ---------- src/cpp/slide.h | 117 ----- src/cpp/slidehelper.cpp | 210 -------- src/cpp/slidehelper.h | 60 --- src/cpp/slidemodel.cpp | 823 ------------------------------- src/cpp/slidemodel.h | 107 ---- src/cpp/songsqlmodel.cpp | 778 ----------------------------- src/cpp/songsqlmodel.h | 152 ------ src/cpp/thumbnail.cpp | 159 ------ src/cpp/thumbnail.h | 74 --- src/cpp/videosqlmodel.cpp | 394 --------------- src/cpp/videosqlmodel.h | 95 ---- src/main.cpp | 48 -- 26 files changed, 5943 deletions(-) delete mode 100644 src/cpp/filemanager.cpp delete mode 100644 src/cpp/filemanager.h delete mode 100644 src/cpp/framedecoder.cpp delete mode 100644 src/cpp/framedecoder.h delete mode 100644 src/cpp/imagesqlmodel.cpp delete mode 100644 src/cpp/imagesqlmodel.h delete mode 100644 src/cpp/presentationsqlmodel.cpp delete mode 100644 src/cpp/presentationsqlmodel.h delete mode 100644 src/cpp/qsettingscxx.h delete mode 100644 src/cpp/serviceitem.cpp delete mode 100644 src/cpp/serviceitem.h delete mode 100644 src/cpp/serviceitemmodel.cpp delete mode 100644 src/cpp/serviceitemmodel.h delete mode 100644 src/cpp/slide.cpp delete mode 100644 src/cpp/slide.h delete mode 100644 src/cpp/slidehelper.cpp delete mode 100644 src/cpp/slidehelper.h delete mode 100644 src/cpp/slidemodel.cpp delete mode 100644 src/cpp/slidemodel.h delete mode 100644 src/cpp/songsqlmodel.cpp delete mode 100644 src/cpp/songsqlmodel.h delete mode 100644 src/cpp/thumbnail.cpp delete mode 100644 src/cpp/thumbnail.h delete mode 100644 src/cpp/videosqlmodel.cpp delete mode 100644 src/cpp/videosqlmodel.h diff --git a/src/cpp/filemanager.cpp b/src/cpp/filemanager.cpp deleted file mode 100644 index 7b929a5..0000000 --- a/src/cpp/filemanager.cpp +++ /dev/null @@ -1,187 +0,0 @@ -#include "filemanager.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -File::File(QObject *parent) - : QObject{parent} -{ - qDebug() << "Initializing empty file"; -} - -File::File(const QString &name, const QString &filePath, QObject *parent) - : QObject(parent),m_name(name),m_filePath(filePath) -{ - qDebug() << "Initializing file with defaults"; -} - -QString File::name() const { - return m_name; -} - -QString File::filePath() const { - return m_filePath; -} - -void File::setName(QString name) -{ - if (m_name == name) - return; - - qDebug() << "####changing name to: " << name; - m_name = name; - emit nameChanged(m_name); -} - -void File::setFilePath(QString filePath) -{ - if (m_filePath == filePath) - return; - - qDebug() << "####changing filePath to: " << filePath; - m_filePath = filePath; - emit filePathChanged(m_filePath); -} - -bool File::save(QUrl file, QVariantList serviceList) { - qDebug() << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"; - qDebug() << "Saving..."; - qDebug() << "File path is: " << file.toString(); - qDebug() << "serviceList is: " << serviceList; - qDebug() << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"; - - //first we'll get a json representation of our serviceList - //save that to a temp file in case we need it but also convert - //it to a byte array just before putting it into the archive - - QJsonArray jsonData; - - // save all the audio and files in jsonData as just the base name - // so that they are properly mapped in the resulting archive - for (int i = 0; i < serviceList.length(); i++) { - // qDebug() << serviceList[i]; - QMap item = serviceList[i].toMap(); - qDebug() << "AUDIO IS: " << item.value("audio").toString(); - QFileInfo audioFile = item.value("audio").toString(); - qDebug() << audioFile.fileName(); - item["flatAudio"] = audioFile.fileName(); - qDebug() << "AUDIO IS NOW: " << item.value("audio").toString(); - - QFileInfo backgroundFile = item.value("background").toString(); - item["flatBackground"] = backgroundFile.fileName(); - qDebug() << "BACKGRUOND IS: " << item.value("background").toString(); - // qDebug() << serviceList[i].value(); - QJsonObject obj = QJsonObject::fromVariantMap(item); - qDebug() << obj; - jsonData.insert(i, obj); - } - - qDebug() << jsonData; - QJsonDocument jsonText(jsonData); - QTemporaryFile jsonFile; - - if (!jsonFile.exists()) - qDebug() << "NOT EXISTS!"; - - if (!jsonFile.open()) - return false; - - //finalize the temp json file, in case something goes wrong in the - //archive, we'll have this to jump back to - jsonFile.write(jsonText.toJson()); - qDebug() << jsonFile.fileName(); - jsonFile.close(); - - //now we create our archive file and set it's parameters - QString filename = file.toString().right(file.toString().size() - 7); - qDebug() << filename; - - // KCompressionDevice dev(filename, KCompressionDevice::Zstd); - // if (!dev.open(QIODevice::WriteOnly)) { - // qDebug() << dev.isOpen(); - // return false; - // } - KTar tar(filename, "application/zstd"); - - if (tar.open(QIODevice::WriteOnly)) { - qDebug() << tar.isOpen(); - - //write our json data to the archive - tar.writeFile("servicelist.json", - jsonText.toJson()); - - //let's add the backgrounds and audios to the archive - for (int i = 0; i < serviceList.size(); i++) { - QMap item = serviceList[i].toMap(); - QString background = item.value("background").toString(); - QString backgroundFile = background.right(background.size() - 5); - qDebug() << backgroundFile; - QString audio = item.value("audio").toString(); - QString audioFile = audio.right(audio.size() - 5); - qDebug() << audioFile; - - //here we need to cut off all the directories before - //adding into the archive - tar.addLocalFile(backgroundFile, - backgroundFile.right(backgroundFile.size() - - backgroundFile.lastIndexOf("/") - 1)); - tar.addLocalFile(audioFile, - audioFile.right(audioFile.size() - - audioFile.lastIndexOf("/") - 1)); - } - - //close the archive so that everything is done - tar.close(); - // dev.close(); - return true; - } - - - - return false; -} - -QVariantList File::load(QUrl file) { - qDebug() << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"; - qDebug() << "Loading..."; - qDebug() << "File path is: " << file.toString(); - qDebug() << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"; - - - QString fileUrl = file.toString().right(file.toString().size() - 7); - KTar tar(fileUrl); - - if (tar.open(QIODevice::ReadOnly)){ - qDebug() << tar.isOpen(); - const KArchiveDirectory *dir = tar.directory(); - - const KArchiveEntry *e = dir->entry("servicelist.json"); - if (!e) { - qDebug() << "File not found!"; - } - const KArchiveFile *f = static_cast(e); - QByteArray arr(f->data()); - QJsonDocument jsonText = QJsonDocument::fromJson(arr); - qDebug() << jsonText; // the file contents - - QJsonArray array = jsonText.array(); - - QVariantList serviceList = array.toVariantList(); - qDebug() << serviceList; - return serviceList; - - } - - QVariantList blankList; - return blankList; - -} diff --git a/src/cpp/filemanager.h b/src/cpp/filemanager.h deleted file mode 100644 index 16df81e..0000000 --- a/src/cpp/filemanager.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef FILEMANAGER_H -#define FILEMANAGER_H - -#include -#include -#include -#include - - -class File : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) - Q_PROPERTY(QString filePath READ filePath WRITE setFilePath NOTIFY filePathChanged) - // QML_ELEMENT - -public: - explicit File(QObject *parent = nullptr); - File(const QString &name, const QString &filePath, - QObject * parent = nullptr); - - QString name() const; - QString filePath() const; - - Q_INVOKABLE void setName(QString name); - Q_INVOKABLE void setFilePath(QString filePath); - - Q_INVOKABLE bool save(QUrl file, QVariantList serviceList); - Q_INVOKABLE QVariantList load(QUrl file); - -signals: - Q_INVOKABLE void nameChanged(QString name); - Q_INVOKABLE void filePathChanged(QString filePath); - -private: - QString m_name; - QString m_filePath; -}; - -#endif //FILEMANAGER_H diff --git a/src/cpp/framedecoder.cpp b/src/cpp/framedecoder.cpp deleted file mode 100644 index 96a9af3..0000000 --- a/src/cpp/framedecoder.cpp +++ /dev/null @@ -1,439 +0,0 @@ -/* - SPDX-FileCopyrightText: 2010 Dirk Vanden Boer - - SPDX-License-Identifier: GPL-2.0-or-later -*/ - -#include "framedecoder.h" - -#include -#include -#include - -extern "C" { -#include -#include -} - -using namespace std; - -FrameDecoder::FrameDecoder(const QString &filename, AVFormatContext *pavContext) - : m_VideoStream(-1) - , m_pFormatContext(pavContext) - , m_pVideoCodecContext(nullptr) - , m_pVideoCodec(nullptr) - , m_pFrame(nullptr) - , m_pFrameBuffer(nullptr) - , m_pPacket(nullptr) - , m_FormatContextWasGiven(pavContext != nullptr) - , m_AllowSeek(true) - , m_initialized(false) - , m_bufferSinkContext(nullptr) - , m_bufferSourceContext(nullptr) - , m_filterGraph(nullptr) - , m_filterFrame(nullptr) -{ - initialize(filename); -} - -FrameDecoder::~FrameDecoder() -{ - destroy(); -} - -void FrameDecoder::initialize(const QString &filename) -{ - m_lastWidth = -1; - m_lastHeight = -1; - m_lastPixfmt = AV_PIX_FMT_NONE; - -#if (LIBAVFORMAT_VERSION_MAJOR < 58) - av_register_all(); -#endif - - QFileInfo fileInfo(filename); - - if ((!m_FormatContextWasGiven) && avformat_open_input(&m_pFormatContext, fileInfo.absoluteFilePath().toLocal8Bit().data(), nullptr, nullptr) != 0) { - qDebug() << "Could not open input file: " << fileInfo.absoluteFilePath(); - return; - } - - if (avformat_find_stream_info(m_pFormatContext, nullptr) < 0) { - qDebug() << "Could not find stream information"; - return; - } - - if (!initializeVideo()) { - // It already printed a message - return; - } - m_pFrame = av_frame_alloc(); - - if (m_pFrame) { - m_initialized = true; - } -} - -bool FrameDecoder::getInitialized() -{ - return m_initialized; -} - -void FrameDecoder::destroy() -{ - deleteFilterGraph(); - if (m_pVideoCodecContext) { - avcodec_close(m_pVideoCodecContext); - avcodec_free_context(&m_pVideoCodecContext); - m_pVideoCodecContext = nullptr; - } - - if ((!m_FormatContextWasGiven) && m_pFormatContext) { - avformat_close_input(&m_pFormatContext); - m_pFormatContext = nullptr; - } - - if (m_pPacket) { - av_packet_unref(m_pPacket); - delete m_pPacket; - m_pPacket = nullptr; - } - - if (m_pFrame) { - av_frame_free(&m_pFrame); - m_pFrame = nullptr; - } - - if (m_pFrameBuffer) { - av_free(m_pFrameBuffer); - m_pFrameBuffer = nullptr; - } -} - -QString FrameDecoder::getCodec() -{ - QString codecName; - if (m_pVideoCodec) { - codecName = QString::fromLatin1(m_pVideoCodec->name); - } - return codecName; -} - -bool FrameDecoder::initializeVideo() -{ - m_VideoStream = av_find_best_stream(m_pFormatContext, AVMEDIA_TYPE_VIDEO, -1, -1, &m_pVideoCodec, 0); - if (m_VideoStream < 0) { - qDebug() << "Could not find video stream"; - return false; - } - - m_pVideoCodecContext = avcodec_alloc_context3(m_pVideoCodec); - avcodec_parameters_to_context(m_pVideoCodecContext, m_pFormatContext->streams[m_VideoStream]->codecpar); - - if (m_pVideoCodec == nullptr) { - // set to nullptr, otherwise avcodec_close(m_pVideoCodecContext) crashes - m_pVideoCodecContext = nullptr; - qDebug() << "Video Codec not found"; - return false; - } - - m_pVideoCodecContext->workaround_bugs = 1; - - if (avcodec_open2(m_pVideoCodecContext, m_pVideoCodec, nullptr) < 0) { - qDebug() << "Could not open video codec"; - return false; - } - - return true; -} - -int FrameDecoder::getWidth() -{ - if (m_pVideoCodecContext) { - return m_pVideoCodecContext->width; - } - - return -1; -} - -int FrameDecoder::getHeight() -{ - if (m_pVideoCodecContext) { - return m_pVideoCodecContext->height; - } - - return -1; -} - -int FrameDecoder::getDuration() -{ - if (m_pFormatContext) { - return static_cast(m_pFormatContext->duration / AV_TIME_BASE); - } - - return 0; -} - -void FrameDecoder::seek(int timeInSeconds) -{ - if (!m_AllowSeek) { - return; - } - - qint64 timestamp = AV_TIME_BASE * static_cast(timeInSeconds); - - if (timestamp < 0) { - timestamp = 0; - } - - int ret = av_seek_frame(m_pFormatContext, -1, timestamp, 0); - if (ret >= 0) { - avcodec_flush_buffers(m_pVideoCodecContext); - } else { - qDebug() << "Seeking in video failed"; - return; - } - - int keyFrameAttempts = 0; - bool gotFrame = 0; - - do { - int count = 0; - gotFrame = 0; - - while (!gotFrame && count < 20) { - getVideoPacket(); - gotFrame = decodeVideoPacket(); - ++count; - } - - ++keyFrameAttempts; - } while ((!gotFrame || !m_pFrame->key_frame) && keyFrameAttempts < 200); - - if (gotFrame == 0) { - qDebug() << "Seeking in video failed"; - } -} - -bool FrameDecoder::decodeVideoFrame() -{ - bool frameFinished = false; - - while (!frameFinished && getVideoPacket()) { - frameFinished = decodeVideoPacket(); - } - - if (!frameFinished) { - qDebug() << "decodeVideoFrame() failed: frame not finished"; - } - - return frameFinished; -} - -bool FrameDecoder::decodeVideoPacket() -{ - if (m_pPacket->stream_index != m_VideoStream) { - return false; - } - - av_frame_unref(m_pFrame); - - avcodec_send_packet(m_pVideoCodecContext, m_pPacket); - int ret = avcodec_receive_frame(m_pVideoCodecContext, m_pFrame); - if (ret == AVERROR(EAGAIN)) { - return false; - } - - return true; -} - -bool FrameDecoder::getVideoPacket() -{ - bool framesAvailable = true; - bool frameDecoded = false; - - int attempts = 0; - - if (m_pPacket) { - av_packet_unref(m_pPacket); - delete m_pPacket; - } - - m_pPacket = new AVPacket(); - - while (framesAvailable && !frameDecoded && (attempts++ < 1000)) { - framesAvailable = av_read_frame(m_pFormatContext, m_pPacket) >= 0; - if (framesAvailable) { - frameDecoded = m_pPacket->stream_index == m_VideoStream; - if (!frameDecoded) { - av_packet_unref(m_pPacket); - } - } - } - - return frameDecoded; -} - -void FrameDecoder::deleteFilterGraph() -{ - if (m_filterGraph) { - av_frame_free(&m_filterFrame); - avfilter_graph_free(&m_filterGraph); - m_filterGraph = nullptr; - } -} - -bool FrameDecoder::initFilterGraph(enum AVPixelFormat pixfmt, int width, int height) -{ - AVFilterInOut *inputs = nullptr, *outputs = nullptr; - - deleteFilterGraph(); - m_filterGraph = avfilter_graph_alloc(); - - QByteArray arguments("buffer="); - arguments += "video_size=" + QByteArray::number(width) + 'x' + QByteArray::number(height) + ':'; - arguments += "pix_fmt=" + QByteArray::number(pixfmt) + ':'; - arguments += "time_base=1/1:pixel_aspect=0/1[in];"; - arguments += "[in]yadif[out];"; - arguments += "[out]buffersink"; - - int ret = avfilter_graph_parse2(m_filterGraph, arguments.constData(), &inputs, &outputs); - if (ret < 0) { - qWarning() << "Unable to parse filter graph"; - return false; - } - - if (inputs || outputs) { - return false; - } - - ret = avfilter_graph_config(m_filterGraph, nullptr); - if (ret < 0) { - qWarning() << "Unable to validate filter graph"; - return false; - } - - m_bufferSourceContext = avfilter_graph_get_filter(m_filterGraph, "Parsed_buffer_0"); - m_bufferSinkContext = avfilter_graph_get_filter(m_filterGraph, "Parsed_buffersink_2"); - if (!m_bufferSourceContext || !m_bufferSinkContext) { - qWarning() << "Unable to get source or sink"; - return false; - } - m_filterFrame = av_frame_alloc(); - m_lastWidth = width; - m_lastHeight = height; - m_lastPixfmt = pixfmt; - - return true; -} - -bool FrameDecoder::processFilterGraph(AVFrame *dst, const AVFrame *src, enum AVPixelFormat pixfmt, int width, int height) -{ - if (!m_filterGraph || width != m_lastWidth || height != m_lastHeight || pixfmt != m_lastPixfmt) { - if (!initFilterGraph(pixfmt, width, height)) { - return false; - } - } - - memcpy(m_filterFrame->data, src->data, sizeof(src->data)); - memcpy(m_filterFrame->linesize, src->linesize, sizeof(src->linesize)); - m_filterFrame->width = width; - m_filterFrame->height = height; - m_filterFrame->format = pixfmt; - - int ret = av_buffersrc_add_frame(m_bufferSourceContext, m_filterFrame); - if (ret < 0) { - return false; - } - - ret = av_buffersink_get_frame(m_bufferSinkContext, m_filterFrame); - if (ret < 0) { - return false; - } - - av_image_copy(dst->data, dst->linesize, (const uint8_t **)m_filterFrame->data, m_filterFrame->linesize, pixfmt, width, height); - av_frame_unref(m_filterFrame); - - return true; -} - -void FrameDecoder::getScaledVideoFrame(int scaledSize, bool maintainAspectRatio, QImage &videoFrame) -{ - if (m_pFrame->interlaced_frame) { - processFilterGraph((AVFrame *)m_pFrame, (AVFrame *)m_pFrame, m_pVideoCodecContext->pix_fmt, m_pVideoCodecContext->width, m_pVideoCodecContext->height); - } - - int scaledWidth, scaledHeight; - convertAndScaleFrame(AV_PIX_FMT_RGB24, scaledSize, maintainAspectRatio, scaledWidth, scaledHeight); - // .copy() since QImage otherwise assumes the memory will continue to be available. - // We could instead pass a custom deleter, but meh. - videoFrame = QImage(m_pFrame->data[0], scaledWidth, scaledHeight, m_pFrame->linesize[0], QImage::Format_RGB888).copy(); -} - -void FrameDecoder::convertAndScaleFrame(AVPixelFormat format, int scaledSize, bool maintainAspectRatio, int &scaledWidth, int &scaledHeight) -{ - calculateDimensions(scaledSize, maintainAspectRatio, scaledWidth, scaledHeight); - SwsContext *scaleContext = sws_getContext(m_pVideoCodecContext->width, - m_pVideoCodecContext->height, - m_pVideoCodecContext->pix_fmt, - scaledWidth, - scaledHeight, - format, - SWS_BICUBIC, - nullptr, - nullptr, - nullptr); - - if (nullptr == scaleContext) { - qDebug() << "Failed to create resize context"; - return; - } - - AVFrame *convertedFrame = nullptr; - uint8_t *convertedFrameBuffer = nullptr; - - createAVFrame(&convertedFrame, &convertedFrameBuffer, scaledWidth, scaledHeight, format); - - sws_scale(scaleContext, m_pFrame->data, m_pFrame->linesize, 0, m_pVideoCodecContext->height, convertedFrame->data, convertedFrame->linesize); - sws_freeContext(scaleContext); - - av_frame_free(&m_pFrame); - av_free(m_pFrameBuffer); - - m_pFrame = convertedFrame; - m_pFrameBuffer = convertedFrameBuffer; -} - -void FrameDecoder::calculateDimensions(int squareSize, bool maintainAspectRatio, int &destWidth, int &destHeight) -{ - if (!maintainAspectRatio) { - destWidth = squareSize; - destHeight = squareSize; - } else { - int srcWidth = m_pVideoCodecContext->width; - int srcHeight = m_pVideoCodecContext->height; - int ascpectNominator = m_pVideoCodecContext->sample_aspect_ratio.num; - int ascpectDenominator = m_pVideoCodecContext->sample_aspect_ratio.den; - - if (ascpectNominator != 0 && ascpectDenominator != 0) { - srcWidth = srcWidth * ascpectNominator / ascpectDenominator; - } - - if (srcWidth > srcHeight) { - destWidth = squareSize; - destHeight = int(float(squareSize) / srcWidth * srcHeight); - } else { - destWidth = int(float(squareSize) / srcHeight * srcWidth); - destHeight = squareSize; - } - } -} - -void FrameDecoder::createAVFrame(AVFrame **avFrame, quint8 **frameBuffer, int width, int height, AVPixelFormat format) -{ - *avFrame = av_frame_alloc(); - - int numBytes = av_image_get_buffer_size(format, width + 1, height + 1, 16); - *frameBuffer = reinterpret_cast(av_malloc(numBytes)); - av_image_fill_arrays((*avFrame)->data, (*avFrame)->linesize, *frameBuffer, format, width, height, 1); -} diff --git a/src/cpp/framedecoder.h b/src/cpp/framedecoder.h deleted file mode 100644 index 8530ada..0000000 --- a/src/cpp/framedecoder.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - SPDX-FileCopyrightText: 2010 Dirk Vanden Boer - - SPDX-License-Identifier: GPL-2.0-or-later -*/ - -#ifndef MOVIEDECODER_H -#define MOVIEDECODER_H - -#include - -class QImage; - -extern "C" { -#include -#include -#include -#include -#include -} - -class FrameDecoder -{ -public: - explicit FrameDecoder(const QString &filename, AVFormatContext *pavContext = nullptr); - ~FrameDecoder(); - - QString getCodec(); - void seek(int timeInSeconds); - bool decodeVideoFrame(); - void getScaledVideoFrame(int scaledSize, bool maintainAspectRatio, QImage &videoFrame); - - int getWidth(); - int getHeight(); - int getDuration(); - - void initialize(const QString &filename); - void destroy(); - bool getInitialized(); - -private: - bool initializeVideo(); - - bool decodeVideoPacket(); - bool getVideoPacket(); - void convertAndScaleFrame(AVPixelFormat format, int scaledSize, bool maintainAspectRatio, int &scaledWidth, int &scaledHeight); - void createAVFrame(AVFrame **avFrame, quint8 **frameBuffer, int width, int height, AVPixelFormat format); - void calculateDimensions(int squareSize, bool maintainAspectRatio, int &destWidth, int &destHeight); - - void deleteFilterGraph(); - bool initFilterGraph(enum AVPixelFormat pixfmt, int width, int height); - bool processFilterGraph(AVFrame *dst, const AVFrame *src, enum AVPixelFormat pixfmt, int width, int height); - -private: - int m_VideoStream; - AVFormatContext *m_pFormatContext; - AVCodecContext *m_pVideoCodecContext; -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(59, 0, 100) - AVCodec *m_pVideoCodec; -#else - const AVCodec *m_pVideoCodec; -#endif - AVFrame *m_pFrame; - quint8 *m_pFrameBuffer; - AVPacket *m_pPacket; - bool m_FormatContextWasGiven; - bool m_AllowSeek; - bool m_initialized; - AVFilterContext *m_bufferSinkContext; - AVFilterContext *m_bufferSourceContext; - AVFilterGraph *m_filterGraph; - AVFrame *m_filterFrame; - int m_lastWidth; - int m_lastHeight; - enum AVPixelFormat m_lastPixfmt; -}; - -#endif diff --git a/src/cpp/imagesqlmodel.cpp b/src/cpp/imagesqlmodel.cpp deleted file mode 100644 index 5fb041e..0000000 --- a/src/cpp/imagesqlmodel.cpp +++ /dev/null @@ -1,252 +0,0 @@ -#include "imagesqlmodel.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static const char *imagesTableName = "images"; - -static void createImageTable() -{ - if(QSqlDatabase::database().tables().contains(imagesTableName)) { - return; - } - - QSqlQuery query; - if (!query.exec("CREATE TABLE IF NOT EXISTS 'images' (" - " 'id' INTEGER NOT NULL," - " 'title' TEXT NOT NULL," - " 'filePath' TEXT NOT NULL," - " PRIMARY KEY(id))")) { - qFatal("Failed to query database: %s", - qPrintable(query.lastError().text())); - } - qDebug() << query.lastQuery(); - qDebug() << "inserting into images"; - - query.exec("INSERT INTO images (title, filePath) VALUES ('Dec 180', 'file:///home/chris/nextcloud/tfc/openlp/180-dec.png')"); - qDebug() << query.lastQuery(); - query.exec("INSERT INTO images (title, filePath) VALUES ('No TFC', " - "'file:///home/chris/nextcloud/tfc/openlp/No TFC.png')"); - - query.exec("select * from images"); - qDebug() << query.lastQuery(); -} - -ImageSqlModel::ImageSqlModel(QObject *parent) : QSqlTableModel(parent) { - qDebug() << "creating image table"; - createImageTable(); - setTable(imagesTableName); - setEditStrategy(QSqlTableModel::OnManualSubmit); - // make sure to call select else the model won't fill - select(); -} - -QVariant ImageSqlModel::data(const QModelIndex &index, int role) const { - if (role < Qt::UserRole) { - return QSqlTableModel::data(index, role); - } - - // qDebug() << role; - const QSqlRecord sqlRecord = record(index.row()); - return sqlRecord.value(role - Qt::UserRole); -} - -QHash ImageSqlModel::roleNames() const -{ - QHash names; - names[Qt::UserRole] = "id"; - names[Qt::UserRole + 1] = "title"; - names[Qt::UserRole + 2] = "filePath"; - return names; -} - -void ImageSqlModel::newImage(const QUrl &filePath) { - qDebug() << "adding new image"; - int rows = rowCount(); - - qDebug() << rows; - QSqlRecord recordData = record(); - QFileInfo fileInfo = filePath.toString(); - QString title = fileInfo.baseName(); - recordData.setValue("title", title); - recordData.setValue("filePath", filePath); - - if (insertRecord(rows, recordData)) { - submitAll(); - } else { - qDebug() << lastError(); - }; -} - -void ImageSqlModel::deleteImage(const int &row) { - QSqlRecord recordData = record(row); - if (recordData.isEmpty()) - return; - - removeRow(row); - submitAll(); -} - -int ImageSqlModel::id() const { - return m_id; -} - -QString ImageSqlModel::title() const { - return m_title; -} - -void ImageSqlModel::setTitle(const QString &title) { - if (title == m_title) - return; - - m_title = title; - - select(); - emit titleChanged(); -} - -// This function is for updating the title from outside the delegate -void ImageSqlModel::updateTitle(const int &row, const QString &title) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from images"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - // qDebug() << rowdata.value(0); - rowdata.setValue("title", title); - bool suc = setRecord(id, rowdata); - qDebug() << "#############"; - qDebug() << rowdata.value("title"); - qDebug() << "was it successful? " << suc; - qDebug() << "#############"; - bool suca = submitAll(); - // qDebug() << suca; - emit titleChanged(); -} - -QUrl ImageSqlModel::filePath() const { - return m_filePath; -} - -void ImageSqlModel::setFilePath(const QUrl &filePath) { - if (filePath == m_filePath) - return; - - m_filePath = filePath; - - select(); - emit filePathChanged(); -} - -// This function is for updating the filepath from outside the delegate -void ImageSqlModel::updateFilePath(const int &row, const QUrl &filePath) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from images"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - qDebug() << rowdata; - rowdata.setValue("filePath", filePath); - setRecord(id, rowdata); - qDebug() << rowdata; - submitAll(); - emit filePathChanged(); -} - -QVariantMap ImageSqlModel::getImage(const int &row) { - // qDebug() << "Row we are getting is " << row; - // QUrl image; - // QSqlRecord rec = record(row); - // qDebug() << rec.value("filePath").toUrl(); - // // image.append(rec.value("title")); - // // image.append(rec.value("filePath")); - // image = rec.value("filePath").toUrl(); - // return image; - - QVariantMap data; - const QModelIndex idx = this->index(row,0); - // qDebug() << idx; - if( !idx.isValid() ) - return data; - const QHash rn = roleNames(); - // qDebug() << rn; - QHashIterator it(rn); - while (it.hasNext()) { - it.next(); - qDebug() << it.key() << ":" << it.value(); - data[it.value()] = idx.data(it.key()); - } - return data; -} - -// ImageProxyModel - -ImageProxyModel::ImageProxyModel(QObject *parent) - :QSortFilterProxyModel(parent) -{ - m_imageModel = new ImageModel; - m_imageModel->setup(); - setSourceModel(m_imageModel); - setDynamicSortFilter(true); - setFilterRole(1); - setFilterCaseSensitivity(Qt::CaseInsensitive); -} - -ImageModel *ImageProxyModel::imageModel() { - return m_imageModel; -} - -QModelIndex ImageProxyModel::idx(int row) { - QModelIndex idx = index(row, 0); - // qDebug() << idx; - return idx; -} - -void ImageProxyModel::newItem(const QUrl &url) { - auto model = qobject_cast(sourceModel()); - model->newItem(url); -} - -QVariantMap ImageProxyModel::getImage(const int &row) { - auto model = qobject_cast(sourceModel()); - QVariantMap image = model->getItem(mapToSource(index(row, 0)).row()); - return image; -} - -void ImageProxyModel::deleteImage(const int &row) { - auto model = qobject_cast(sourceModel()); - model->removeItem(row); -} - -void ImageProxyModel::deleteImages(const QVector &rows) { - auto model = qobject_cast(sourceModel()); - qDebug() << "DELETING!!!!!!!!!!!!!!!!!!!!!!!" << rows; - for (int i = rows.size() - 1; i >= 0; i--) { - qDebug() << "deleting" << rows.at(i); - model->removeItem(rows.at(i)); - } -} diff --git a/src/cpp/imagesqlmodel.h b/src/cpp/imagesqlmodel.h deleted file mode 100644 index 262cae5..0000000 --- a/src/cpp/imagesqlmodel.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef IMAGESQLMODEL_H -#define IMAGESQLMODEL_H - -#include -#include -#include -#include -#include -#include -#include -#include "cxx-qt-gen/image_model.cxxqt.h" - -class ImageSqlModel : public QSqlTableModel -{ - Q_OBJECT - Q_PROPERTY(int id READ id) - Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) - Q_PROPERTY(QUrl filePath READ filePath WRITE setFilePath NOTIFY filePathChanged) - QML_ELEMENT - -public: - ImageSqlModel(QObject *parent = 0); - - int id() const; - QString title() const; - QUrl filePath() const; - - void setTitle(const QString &title); - void setFilePath(const QUrl &filePath); - - Q_INVOKABLE void updateTitle(const int &row, const QString &title); - Q_INVOKABLE void updateFilePath(const int &row, const QUrl &filePath); - - Q_INVOKABLE void newImage(const QUrl &filePath); - Q_INVOKABLE void deleteImage(const int &row); - Q_INVOKABLE QVariantMap getImage(const int &row); - - QVariant data(const QModelIndex &index, int role) const override; - QHash roleNames() const override; - -signals: - void titleChanged(); - void filePathChanged(); - -private: - int m_id; - QString m_title; - QUrl m_filePath; -}; - -class ImageProxyModel : public QSortFilterProxyModel -{ - Q_OBJECT - Q_PROPERTY(ImageModel *imageModel READ imageModel) - -public: - explicit ImageProxyModel(QObject *parent = nullptr); - ~ImageProxyModel() = default; - - ImageModel *imageModel(); - Q_INVOKABLE QModelIndex idx(int row); - -public slots: - Q_INVOKABLE QVariantMap getImage(const int &row); - Q_INVOKABLE void newItem(const QUrl &url); - Q_INVOKABLE void deleteImage(const int &row); - Q_INVOKABLE void deleteImages(const QVector &rows); - -private: - ImageModel *m_imageModel; -}; - - -#endif //IMAGESQLMODEL_H diff --git a/src/cpp/presentationsqlmodel.cpp b/src/cpp/presentationsqlmodel.cpp deleted file mode 100644 index 080ac75..0000000 --- a/src/cpp/presentationsqlmodel.cpp +++ /dev/null @@ -1,283 +0,0 @@ -#include "presentationsqlmodel.h" - -#include -#include -#include -#include -#include -#include -// #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static const char *presentationsTableName = "presentations"; - -static void createPresentationTable() -{ - QSqlQuery query; - if(QSqlDatabase::database().tables().contains(presentationsTableName)) { - // query.exec("DROP TABLE 'presentations'"); - // qDebug() << query.lastQuery(); - return; - } - - if (!query.exec("CREATE TABLE IF NOT EXISTS 'presentations' (" - " 'id' INTEGER NOT NULL," - " 'title' TEXT NOT NULL," - " 'filePath' TEXT NOT NULL," - " 'pageCount' INTEGER," - " PRIMARY KEY(id))")) { - qFatal("Failed to query database: %s", - qPrintable(query.lastError().text())); - } - qDebug() << query.lastQuery(); - qDebug() << "inserting into presentations"; - - query.exec("INSERT INTO presentations (title, filePath) VALUES ('Dec 180', 'file:///home/chris/nextcloud/tfc/openlp/5 slides-1.pdf')"); - qDebug() << query.lastQuery(); - query.exec("INSERT INTO presentations (title, filePath) VALUES ('No TFC', " - "'file:///home/chris/nextcloud/tfc/openlp/5 slides-2.pdf')"); - - query.exec("select * from presentations"); - qDebug() << query.lastQuery(); -} - -PresentationSqlModel::PresentationSqlModel(QObject *parent) : QSqlTableModel(parent) { - qDebug() << "creating presentation table"; - createPresentationTable(); - setTable(presentationsTableName); - setEditStrategy(QSqlTableModel::OnManualSubmit); - // make sure to call select else the model won't fill - select(); -} - -QVariant PresentationSqlModel::data(const QModelIndex &index, int role) const { - if (role < Qt::UserRole) { - return QSqlTableModel::data(index, role); - } - - // qDebug() << role; - const QSqlRecord sqlRecord = record(index.row()); - return sqlRecord.value(role - Qt::UserRole); -} - -QHash PresentationSqlModel::roleNames() const -{ - QHash names; - names[Qt::UserRole] = "id"; - names[Qt::UserRole + 1] = "title"; - names[Qt::UserRole + 2] = "filePath"; - names[Qt::UserRole + 3] = "pageCount"; - return names; -} - -void PresentationSqlModel::newPresentation(const QUrl &filePath, int pageCount) { - qDebug() << "adding new presentation"; - int rows = rowCount(); - - qDebug() << rows; - QSqlRecord recordData = record(); - QFileInfo fileInfo = filePath.toString(); - QString title = fileInfo.baseName(); - recordData.setValue("title", title); - recordData.setValue("filePath", filePath); - recordData.setValue("pageCount", pageCount); - - if (insertRecord(rows, recordData)) { - submitAll(); - } else { - qDebug() << lastError(); - }; -} - -void PresentationSqlModel::deletePresentation(const int &row) { - QSqlRecord recordData = record(row); - if (recordData.isEmpty()) - return; - - removeRow(row); - submitAll(); -} - -int PresentationSqlModel::id() const { - return m_id; -} - -QString PresentationSqlModel::title() const { - return m_title; -} - -void PresentationSqlModel::setTitle(const QString &title) { - if (title == m_title) - return; - - m_title = title; - - select(); - emit titleChanged(); -} - -// This function is for updating the title from outside the delegate -void PresentationSqlModel::updateTitle(const int &row, const QString &title) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from presentations"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - qDebug() << rowdata; - rowdata.setValue("title", title); - setRecord(id, rowdata); - qDebug() << rowdata; - submitAll(); - emit titleChanged(); -} - -QUrl PresentationSqlModel::filePath() const { - return m_filePath; -} - -void PresentationSqlModel::setFilePath(const QUrl &filePath) { - if (filePath == m_filePath) - return; - - m_filePath = filePath; - - select(); - emit filePathChanged(); -} - -// This function is for updating the filepath from outside the delegate -void PresentationSqlModel::updateFilePath(const int &row, const QUrl &filePath) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from presentations"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - qDebug() << rowdata; - rowdata.setValue("filePath", filePath); - setRecord(id, rowdata); - qDebug() << rowdata; - submitAll(); - emit filePathChanged(); -} - -int PresentationSqlModel::pageCount() const { - return m_pageCount; -} - -void PresentationSqlModel::setPageCount(const int &pageCount) { - if (pageCount == m_pageCount) - return; - - m_pageCount = pageCount; - - select(); - emit pageCountChanged(); -} - -// This function is for updating the pageCount from outside the delegate -void PresentationSqlModel::updatePageCount(const int &row, const int &pageCount) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from presentations"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - qDebug() << rowdata; - rowdata.setValue("pageCount", pageCount); - setRecord(id, rowdata); - qDebug() << rowdata; - submitAll(); - emit pageCountChanged(); -} - -QVariantMap PresentationSqlModel::getPresentation(const int &row) { - // qDebug() << "Row we are getting is " << row; - // QUrl presentation; - // QSqlRecord rec = record(row); - // qDebug() << rec.value("filePath").toUrl(); - // // presentation.append(rec.value("title")); - // // presentation.append(rec.value("filePath")); - // presentation = rec.value("filePath").toUrl(); - // return presentation; - - QVariantMap data; - const QModelIndex idx = this->index(row,0); - // qDebug() << idx; - if( !idx.isValid() ) - return data; - const QHash rn = roleNames(); - // qDebug() << rn; - QHashIterator it(rn); - while (it.hasNext()) { - it.next(); - qDebug() << it.key() << ":" << it.value(); - data[it.value()] = idx.data(it.key()); - } - return data; -} -// PresentationProxyModel - -PresentationProxyModel::PresentationProxyModel(QObject *parent) - :QSortFilterProxyModel(parent) -{ - m_presentationModel = new PresentationModel; - m_presentationModel->setup(); - setSourceModel(m_presentationModel); - setDynamicSortFilter(true); - setFilterRole(Qt::UserRole + 1); - setFilterCaseSensitivity(Qt::CaseInsensitive); -} - -PresentationModel *PresentationProxyModel::presentationModel() { - return m_presentationModel; -} - -QModelIndex PresentationProxyModel::idx(int row) { - QModelIndex idx = index(row, 0); - // qDebug() << idx; - return idx; -} - -QVariantMap PresentationProxyModel::getPresentation(const int &row) { - qDebug() << "Getting Presentation through cpp"; - auto model = qobject_cast(sourceModel()); - QVariantMap presentation = model->getItem(mapToSource(index(row, 0)).row()); - return presentation; -} - -void PresentationProxyModel::deletePresentation(const int &row) { - auto model = qobject_cast(sourceModel()); - model->removeItem(row); -} - -void PresentationProxyModel::deletePresentations(const QVector &rows) { - auto model = qobject_cast(sourceModel()); - qDebug() << "DELETING!!!!!!!!!!!!!!!!!!!!!!!" << rows; - for (int i = rows.size() - 1; i >= 0; i--) { - qDebug() << "deleting" << rows.at(i); - model->removeItem(rows.at(i)); - } -} diff --git a/src/cpp/presentationsqlmodel.h b/src/cpp/presentationsqlmodel.h deleted file mode 100644 index 86f5b43..0000000 --- a/src/cpp/presentationsqlmodel.h +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef PRESENTATIONSQLMODEL_H -#define PRESENTATIONSQLMODEL_H - -#include -#include -#include -#include -#include -#include -#include -#include "cxx-qt-gen/presentation_model.cxxqt.h" - - -class PresentationSqlModel : public QSqlTableModel -{ - Q_OBJECT - Q_PROPERTY(int id READ id) - Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) - Q_PROPERTY(QUrl filePath READ filePath WRITE setFilePath NOTIFY filePathChanged) - Q_PROPERTY(int pageCount READ pageCount WRITE setPageCount NOTIFY pageCountChanged) - QML_ELEMENT - -public: - PresentationSqlModel(QObject *parent = 0); - - int id() const; - QString title() const; - QUrl filePath() const; - int pageCount() const; - - void setTitle(const QString &title); - void setFilePath(const QUrl &filePath); - void setPageCount(const int &pageCount); - - Q_INVOKABLE void updateTitle(const int &row, const QString &title); - Q_INVOKABLE void updateFilePath(const int &row, const QUrl &filePath); - Q_INVOKABLE void updatePageCount(const int &row, const int &pageCount); - - Q_INVOKABLE void newPresentation(const QUrl &filePath, int pageCount); - Q_INVOKABLE void deletePresentation(const int &row); - Q_INVOKABLE QVariantMap getPresentation(const int &row); - - QVariant data(const QModelIndex &index, int role) const override; - QHash roleNames() const override; - -signals: - void titleChanged(); - void filePathChanged(); - void pageCountChanged(); - -private: - int m_id; - QString m_title; - QUrl m_filePath; - int m_pageCount; -}; - - -class PresentationProxyModel : public QSortFilterProxyModel -{ - Q_OBJECT - Q_PROPERTY(PresentationModel *presentationModel READ presentationModel) - -public: - explicit PresentationProxyModel(QObject *parent = nullptr); - ~PresentationProxyModel() = default; - - PresentationModel *presentationModel(); - Q_INVOKABLE QModelIndex idx(int row); - -public slots: - Q_INVOKABLE QVariantMap getPresentation(const int &row); - Q_INVOKABLE void deletePresentation(const int &row); - Q_INVOKABLE void deletePresentations(const QVector &row); - -private: - PresentationModel *m_presentationModel; -}; - -#endif //PRESENTATIONSQLMODEL_H diff --git a/src/cpp/qsettingscxx.h b/src/cpp/qsettingscxx.h deleted file mode 100644 index ddc9340..0000000 --- a/src/cpp/qsettingscxx.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include - -#include "rust/cxx.h" - -class QSettingsCXX : public QSettings -{ -public: - explicit QSettingsCXX(QObject* parent = nullptr) - : QSettings(parent) - { - } - - // Can't define in CXX as they are protected - // so crate public methods that are proxied - void setValue(QString key, QString value) - { - QSettings::setValue(key, value); - } - - void sync() { QSettings::sync(); } - -}; diff --git a/src/cpp/serviceitem.cpp b/src/cpp/serviceitem.cpp deleted file mode 100644 index 36b1653..0000000 --- a/src/cpp/serviceitem.cpp +++ /dev/null @@ -1,222 +0,0 @@ -#include "serviceitem.h" -#include - -ServiceItem::ServiceItem(QObject *parent) - : QObject{parent} -{ - -} - -ServiceItem::ServiceItem(const QString &name, const QString &type, QObject *parent) - : QObject(parent),m_name(name),m_type(type) -{ - -} - -ServiceItem::ServiceItem(const QString &name, const QString &type, const QString &background, - const QString &backgroundType, QObject *parent) - : QObject(parent),m_name(name),m_type(type),m_background(background), - m_backgroundType(backgroundType) -{ - -} - -ServiceItem::ServiceItem(const QString &name, const QString &type, const QString &background, - const QString &backgroundType, const QStringList &text, - QObject *parent) - : QObject(parent),m_name(name),m_type(type),m_background(background), - m_backgroundType(backgroundType),m_text(text) -{ - -} - -ServiceItem::ServiceItem(const QString &name, const QString &type, const QString &background, - const QString &backgroundType, const QStringList &text, - const QString &audio, QObject *parent) - : QObject(parent),m_name(name),m_type(type),m_background(background), - m_backgroundType(backgroundType),m_text(text),m_audio(audio) -{ - -} - -ServiceItem::ServiceItem(const QString &name, const QString &type, const QString &background, - const QString &backgroundType, const QStringList &text, - const QString &audio, const QString &font, const int &fontSize, - QObject *parent) - : QObject(parent),m_name(name),m_type(type),m_background(background), - m_backgroundType(backgroundType),m_text(text),m_audio(audio),m_font(font),m_fontSize(fontSize) -{ - -} - -ServiceItem::ServiceItem(const QString &name, const QString &type, const QString &background, - const QString &backgroundType, const QStringList &text, - const QString &audio, const QString &font, const int &fontSize, - const int &slideNumber, const bool &loop, QObject *parent) - : QObject(parent),m_name(name),m_type(type),m_background(background), - m_backgroundType(backgroundType),m_text(text),m_audio(audio),m_font(font),m_fontSize(fontSize),m_slideNumber(slideNumber),m_loop(loop) -{ - -} - -QString ServiceItem::name() const { - return m_name; -} - -QString ServiceItem::type() const { - return m_type; -} - -QString ServiceItem::background() const -{ - return m_background; -} - -QString ServiceItem::backgroundType() const -{ - return m_backgroundType; -} - -QStringList ServiceItem::text() const -{ - return m_text; -} - -QString ServiceItem::audio() const { - return m_audio; -} - -QString ServiceItem::font() const { - return m_font; -} - -int ServiceItem::fontSize() const { - return m_fontSize; -} - -int ServiceItem::slideNumber() const { - return m_slideNumber; -} - -bool ServiceItem::active() const { - return m_active; -} - -bool ServiceItem::selected() const { - return m_selected; -} - -bool ServiceItem::loop() const { - return m_loop; -} - -void ServiceItem::setName(QString name) -{ - if (m_name == name) - return; - - m_name = name; - emit nameChanged(m_name); -} - -void ServiceItem::setType(QString type) -{ - if (m_type == type) - return; - - m_type = type; - emit typeChanged(m_type); -} - -void ServiceItem::setBackground(QString background) -{ - if (m_background == background) - return; - - m_background = background; - emit backgroundChanged(m_background); -} - -void ServiceItem::setBackgroundType(QString backgroundType) -{ - if (m_backgroundType == backgroundType) - return; - - m_backgroundType = backgroundType; - emit backgroundTypeChanged(m_backgroundType); -} - -void ServiceItem::setText(QStringList text) -{ - if (m_text == text) - return; - - m_text = text; - emit textChanged(m_text); - -} - -void ServiceItem::setAudio(QString audio) -{ - if (m_audio == audio) - return; - - m_audio = audio; - emit audioChanged(m_audio); -} - -void ServiceItem::setFont(QString font) -{ - if (m_font == font) - return; - - m_font = font; - emit fontChanged(m_font); -} - -void ServiceItem::setFontSize(int fontSize) -{ - if (m_fontSize == fontSize) - return; - - m_fontSize = fontSize; - emit fontSizeChanged(m_fontSize); -} - -void ServiceItem::setSlideNumber(int slideNumber) -{ - if (m_slideNumber == slideNumber) - return; - - m_slideNumber = slideNumber; - emit slideNumberChanged(m_slideNumber); -} - -void ServiceItem::setActive(bool active) -{ - qDebug() << "::::::::::::::::::::"; - qDebug() << "CHANGE ME!"; - if (m_active == active) - return; - - m_active = active; - emit activeChanged(m_active); -} - -void ServiceItem::setSelected(bool selected) -{ - if (m_selected == selected) - return; - - m_selected = selected; - emit selectedChanged(m_selected); -} - -void ServiceItem::setLoop(bool loop) -{ - if (m_loop == loop) - return; - - m_loop = loop; - emit loopChanged(m_loop); -} diff --git a/src/cpp/serviceitem.h b/src/cpp/serviceitem.h deleted file mode 100644 index 7849d88..0000000 --- a/src/cpp/serviceitem.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef SERVICEITEM_H -#define SERVICEITEM_H - -#include -#include -#include "thumbnail.h" - -class ServiceItem : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) - Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged) - Q_PROPERTY(QString background READ background WRITE setBackground NOTIFY backgroundChanged) - Q_PROPERTY(QString backgroundType READ backgroundType WRITE setBackgroundType NOTIFY backgroundTypeChanged) - Q_PROPERTY(QStringList text READ text WRITE setText NOTIFY textChanged) - Q_PROPERTY(QString audio READ audio WRITE setAudio NOTIFY audioChanged) - Q_PROPERTY(QString font READ font WRITE setFont NOTIFY fontChanged) - Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) - Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged) - Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectedChanged) - Q_PROPERTY(bool loop READ loop WRITE setLoop NOTIFY loopChanged) - Q_PROPERTY(int slideNumber READ slideNumber WRITE setSlideNumber NOTIFY slideNumberChanged) - // Q_PROPERTY(Thumbnail thumbnail READ thumbnail WRITE setThumbnail NOTIFY thumbnailChanged) - -public: - explicit ServiceItem(QObject *parent = nullptr); - ServiceItem(const QString &name, const QString &type, QObject * parent = nullptr); - ServiceItem(const QString &name, const QString &type, const QString &background, - const QString &backgroundType, QObject * parent = nullptr); - ServiceItem(const QString &name, const QString &type, const QString &background, - const QString &backgroundType, const QStringList &text, - QObject * parent = nullptr); - ServiceItem(const QString &name, const QString &type, const QString &background, - const QString &backgroundType, const QStringList &text, const QString &audio, - QObject * parent = nullptr); - ServiceItem(const QString &name, const QString &type, const QString &background, - const QString &backgroundType, const QStringList &text, const QString &audio, - const QString &font, const int &fontSize, QObject * parent = nullptr); - ServiceItem(const QString &name, const QString &type, const QString &background, - const QString &backgroundType, const QStringList &text, const QString &audio, - const QString &font, const int &fontSize, const int &slideNumber, - const bool &loop, QObject * parent = nullptr); - - QString name() const; - QString type() const; - QString background() const; - QString backgroundType() const; - QStringList text() const; - QString audio() const; - QString font() const; - int fontSize() const; - bool active() const; - bool selected() const; - bool loop() const; - int slideNumber() const; - // Thumbnail thumbnail() const; - - void setName(QString name); - void setType(QString type); - void setBackground(QString background); - void setBackgroundType(QString backgroundType); - void setText(QStringList text); - void setAudio(QString audio); - void setFont(QString font); - void setFontSize(int fontSize); - void setSlideNumber(int slideNumber); - void setActive(bool active); - void setSelected(bool selected); - void setLoop(bool loop); - -signals: - void nameChanged(QString name); - void typeChanged(QString type); - void backgroundChanged(QString background); - void backgroundTypeChanged(QString backgroundType); - void textChanged(QStringList text); - void audioChanged(QString audio); - void fontChanged(QString font); - void fontSizeChanged(int fontSize); - void slideNumberChanged(int slideNumber); - void activeChanged(bool active); - void selectedChanged(bool selected); - void loopChanged(bool loop); - -private: - QString m_name; - QString m_type; - QString m_background; - QString m_backgroundType; - QStringList m_text; - QString m_audio; - QString m_font; - int m_fontSize; - int m_slideNumber; - bool m_active; - bool m_selected; - bool m_loop; -}; - -#endif // SERVICEITEM_H diff --git a/src/cpp/serviceitemmodel.cpp b/src/cpp/serviceitemmodel.cpp deleted file mode 100644 index 0611127..0000000 --- a/src/cpp/serviceitemmodel.cpp +++ /dev/null @@ -1,793 +0,0 @@ -#include "serviceitemmodel.h" -#include "serviceitem.h" -#include "filemanager.h" -#include "slidemodel.h" -#include -#include -#include -#include -// #include -// #include -// #include -// #include -// #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "cxx-qt-gen/slide_model.cxxqt.h" -#include "cxx-qt-gen/service_item_model.cxxqt.h" - -ServiceItemModelCpp::ServiceItemModelCpp(QObject *parent) - : QAbstractListModel(parent) { -} - -int ServiceItemModelCpp::rowCount(const QModelIndex &parent) const { - // For list models only the root node (an invalid parent) should return the - // list's size. For all other (valid) parents, rowCount() should return 0 so - // that it does not become a tree model. - if (parent.isValid()) - return 0; - - // FIXME: Implement me! - return m_items.size(); -} - -QVariant ServiceItemModelCpp::data(const QModelIndex &index, int role) const { - if (!index.isValid()) - return QVariant(); - - ServiceItem *item = m_items[index.row()]; - switch (role) { - case NameRole: - return item->name(); - case TypeRole: - return item->type(); - case BackgroundRole: - return item->background(); - case BackgroundTypeRole: - return item->backgroundType(); - case TextRole: - return item->text(); - case AudioRole: - return item->audio(); - case FontRole: - return item->font(); - case FontSizeRole: - return item->fontSize(); - case SlideNumberRole: - return item->slideNumber(); - case ActiveRole: - return item->active(); - case SelectedRole: - return item->selected(); - case LoopRole: - return item->loop(); - default: - return QVariant(); - } -} - -QHash ServiceItemModelCpp::roleNames() const { - static QHash mapping{{NameRole, "name"}, - {TypeRole, "type"}, - {BackgroundRole, "background"}, - {BackgroundTypeRole, "backgroundType"}, - {TextRole, "text"}, - {AudioRole, "audio"}, - {FontRole, "font"}, - {FontSizeRole, "fontSize"}, - {SlideNumberRole, "slideNumber"}, - {ActiveRole, "active"}, - {SelectedRole, "selected"}, - {LoopRole, "loop"}}; - - return mapping; -} - -bool ServiceItemModelCpp::setData(const QModelIndex &index, const QVariant &value, - int role) { - - ServiceItem *item = m_items[index.row()]; - bool somethingChanged = false; - - switch (role) { - case NameRole: - if (item->name() != value.toString()) { - item->setName(value.toString()); - somethingChanged = true; - } - break; - case TypeRole: - if (item->type() != value.toString()) { - item->setType(value.toString()); - somethingChanged = true; - } - break; - case BackgroundRole: - if (item->background() != value.toString()) { - item->setBackground(value.toString()); - somethingChanged = true; - } - break; - case BackgroundTypeRole: - if (item->backgroundType() != value.toString()) { - item->setBackgroundType(value.toString()); - somethingChanged = true; - } - break; - case TextRole: - if (item->text() != value.toStringList()) { - item->setText(value.toStringList()); - somethingChanged = true; - } - break; - case AudioRole: - if (item->audio() != value.toString()) { - item->setAudio(value.toString()); - somethingChanged = true; - } - break; - case FontRole: - if (item->font() != value.toString()) { - item->setFont(value.toString()); - somethingChanged = true; - } - break; - case FontSizeRole: - if (item->fontSize() != value.toInt()) { - item->setFontSize(value.toInt()); - somethingChanged = true; - } - break; - case SlideNumberRole: - if (item->slideNumber() != value.toInt()) { - item->setSlideNumber(value.toInt()); - somethingChanged = true; - } - break; - case ActiveRole: - if (item->active() != value.toBool()) { - item->setActive(value.toBool()); - somethingChanged = true; - } - break; - case SelectedRole: - if (item->selected() != value.toBool()) { - item->setSelected(value.toBool()); - somethingChanged = true; - } - break; - case LoopRole: - if (item->loop() != value.toBool()) { - item->setLoop(value.toBool()); - somethingChanged = true; - } - break; - if (somethingChanged) { - emit dataChanged(index, index, QVector() << role); - return true; - } - } - - return false; -} - -Qt::ItemFlags ServiceItemModelCpp::flags(const QModelIndex &index) const { - if (!index.isValid()) - return Qt::NoItemFlags; - - return Qt::ItemIsEditable; // FIXME: Implement me! -} - -void ServiceItemModelCpp::addItem(ServiceItem *item) { - const int index = m_items.size(); - qDebug() << index; - // foreach (item, m_items) { - // qDebug() << item; - // } - beginInsertRows(QModelIndex(), index, index); - m_items.append(item); - endInsertRows(); -} - -void ServiceItemModelCpp::insertItem(const int &index, ServiceItem *item) { - beginInsertRows(this->index(index).parent(), index, index); - m_items.insert(index, item); - endInsertRows(); - qDebug() << "Success"; -} - -void ServiceItemModelCpp::addItem(const QString &name, const QString &type, - const QString &background, const QString &backgroundType, - const QStringList &text, const QString &audio, - const QString &font, const int &fontSize, - const int &slideNumber, const bool &loop) { - qDebug() << "*************************"; - qDebug() << "Plain adding item: " << name; - qDebug() << "*************************"; - ServiceItem *item = new ServiceItem(name, type, background, backgroundType, - text, audio, font, fontSize, slideNumber, loop); - item->setSelected(false); - item->setActive(false); - addItem(item); - - QVariantMap itm; - const QModelIndex idx = this->index(rowCount() - 1); - qDebug() << idx; - qDebug() << rowCount(); - if( idx.isValid() ) { - const QHash rn = roleNames(); - // qDebug() << rn; - QHashIterator it(rn); - while (it.hasNext()) { - it.next(); - qDebug() << "trains"; - qDebug() << it.key() << ":" << it.value() << ":" << idx.data(it.key()); - itm[it.value()] = idx.data(it.key()); - } - } else - qDebug() << "idx isn't valid"; - qDebug() << "*&"; - qDebug() << itm; - qDebug() << "*&"; - // emit itemAdded(rowCount() - 1, *item); - emit itemAddedRust(rowCount() - 1, itm); - qDebug() << "EMITTED ITEM ADDED" << rowCount(); - qDebug() << "#################################"; - qDebug() << name << type << font << fontSize << slideNumber; - qDebug() << "#################################"; -} - -void ServiceItemModelCpp::insertItem(const int &index, const QString &name, - const QString &type,const QString &background, - const QString &backgroundType,const QStringList &text, - const QString &audio, const QString &font, - const int &fontSize, const int &slideNumber, - const bool &loop) { - qDebug() << "*************************"; - qDebug() << "Inserting serviceItem: " << name << " and index is " << index; - qDebug() << "*************************"; - ServiceItem *item = new ServiceItem(name, type, background, backgroundType, - text, audio, font, fontSize, slideNumber, loop); - item->setSelected(false); - item->setActive(false); - insertItem(index, item); - - QVariantMap itm; - const QModelIndex idx = this->index(index); - qDebug() << idx; - if( idx.isValid() ) { - const QHash rn = roleNames(); - // qDebug() << rn; - QHashIterator it(rn); - while (it.hasNext()) { - it.next(); - qDebug() << "trains"; - qDebug() << it.key() << ":" << it.value() << ":" << idx.data(it.key()); - itm[it.value()] = idx.data(it.key()); - } - } else - qDebug() << "idx isn't valid"; - - // emit itemInserted(index, *item); - emit itemInsertedRust(index, itm); - - qDebug() << "EMITTED ITEM INSERTED"; - qDebug() << "#################################"; - qDebug() << "INSERTING SERVICE ITEM!"; - qDebug() << name << type << font << fontSize << slideNumber << index; - qDebug() << "#################################"; -} - -void ServiceItemModelCpp::removeItem(int index) { - beginRemoveRows(QModelIndex(), index, index); - m_items.removeAt(index); - endRemoveRows(); -} - -void ServiceItemModelCpp::removeItems() { - for (int i = m_items.length() - 1; i > -1; i--) { - QModelIndex idx = index(i); - ServiceItem *item = m_items[idx.row()]; - if (item->selected()) { - qDebug() << "Removing item:" << i; - beginRemoveRows(QModelIndex(), i, i); - m_items.removeAt(i); - endRemoveRows(); - QVariantMap map = getItem(i); - emit rowRemoved(i, *item); - emit rowRemovedRust(i, map); - qDebug() << "emitted removal of item:" << item->name(); - } - } - -} - -bool ServiceItemModelCpp::moveRows(int sourceIndex, int destIndex, int count) { - qDebug() << sourceIndex; - qDebug() << destIndex; - - const int lastIndex = rowCount() - 1; - - if (sourceIndex == destIndex - || (sourceIndex < 0 || sourceIndex > lastIndex) - || (destIndex < 0 || destIndex > lastIndex)) { - return false; - } - - const QModelIndex parent = index(sourceIndex).parent(); - const bool isMoveDown = destIndex > sourceIndex; - - if (!beginMoveRows(parent, sourceIndex, sourceIndex + count - 1, - parent, isMoveDown ? destIndex + 1 : destIndex)) { - qDebug() << "Can't move rows"; - return false; - } - - qDebug() << "starting move: " << "source: " << sourceIndex << "dest: " << destIndex; - - m_items.move(sourceIndex, destIndex); - - endMoveRows(); - - QModelIndex idx = index(destIndex); - ServiceItem *item = m_items[idx.row()]; - emit rowMoved(sourceIndex, destIndex, *item); - QVariantMap map = getItem(destIndex); - emit rowMovedRust(sourceIndex, destIndex, map); - - return true; -} - -bool ServiceItemModelCpp::moveDown(int id) { - qDebug() << index(id).row(); - qDebug() << index(id + 1).row(); - QModelIndex parent = index(id).parent(); - - bool begsuc = beginMoveRows(parent, id, - id, parent, id + 2); - if (begsuc) { - int dest = id + 1; - if (dest >= m_items.size()) - { - qDebug() << "dest too big, moving to end"; - m_items.move(id, m_items.size() - 1); - } - else - m_items.move(id, dest); - endMoveRows(); - return true; - } - return false; -} - -bool ServiceItemModelCpp::moveUp(int id) { - qDebug() << index(id).row(); - qDebug() << index(id - 1).row(); - QModelIndex parent = index(id).parent(); - - bool begsuc = beginMoveRows(parent, id, - id, parent, id - 1); - if (begsuc) { - int dest = id - 1; - if (dest <= -1) - { - qDebug() << "dest too big, moving to beginning"; - m_items.move(id, 0); - } - else - m_items.move(id, dest); - endMoveRows(); - return true; - } - - return false; -} - -bool ServiceItemModelCpp::moveRowsRust(int source, int dest, int count, ServiceItemModel *rustModel) { - const QModelIndex parent = index(source).parent(); - const bool isMoveDown = dest > source; - - if (!beginMoveRows(parent, source, source + count - 1, - parent, dest)) { - qDebug() << "Can't move rows"; - return false; - } - - const bool moved = rustModel->moveRows(source, dest, count); - endMoveRows(); - return moved; -} - -QVariantMap ServiceItemModelCpp::getRust(int index, ServiceItemModel *rustModel) const { - QVariantMap item = rustModel->getItem(index); - return item; -} - -QVariantMap ServiceItemModelCpp::getItem(int index) const { - QVariantMap data; - const QModelIndex idx = this->index(index,0); - // qDebug() << idx; - if( !idx.isValid() ) - return data; - const QHash rn = roleNames(); - // qDebug() << rn; - QHashIterator it(rn); - while (it.hasNext()) { - it.next(); - // qDebug() << it.key() << ":" << it.value(); - data[it.value()] = idx.data(it.key()); - } - return data; -} - -QVariantList ServiceItemModelCpp::getItems() { - QVariantList data; - ServiceItem * item; - foreach (item, m_items) { - qDebug() << item->name(); - QVariantMap itm; - itm["name"] = item->name(); - itm["type"] = item->type(); - itm["background"] = item->background(); - itm["backgroundType"] = item->backgroundType(); - itm["text"] = item->text(); - itm["audio"] = item->audio(); - itm["font"] = item->font(); - itm["fontSize"] = item->fontSize(); - itm["slideNumber"] = item->slideNumber(); - itm["selected"] = item->selected(); - itm["loop"] = item->loop(); - itm["active"] = item->active(); - data.append(itm); - } - qDebug() << "$$$$$$$$$$$$$$$$$$$$$$$$$$$"; - qDebug() << data; - qDebug() << "$$$$$$$$$$$$$$$$$$$$$$$$$$$"; - return data; -} - -bool ServiceItemModelCpp::select(int id) { - for (int i = 0; i < m_items.length(); i++) { - QModelIndex idx = index(i); - ServiceItem *item = m_items[idx.row()]; - if (item->selected()) { - item->setSelected(false); - qDebug() << "################"; - qDebug() << "deselected" << item->name(); - qDebug() << "################"; - emit dataChanged(idx, idx, QVector() << SelectedRole); - } - } - QModelIndex idx = index(id); - ServiceItem *item = m_items[idx.row()]; - item->setSelected(true); - qDebug() << "################"; - qDebug() << "selected" << item->name(); - qDebug() << "################"; - emit dataChanged(idx, idx, QVector() << SelectedRole); - return true; -} - -bool ServiceItemModelCpp::selectItems(QVariantList items) { - qDebug() << "Let's select some items!"; - for (int i = 0; i < m_items.length(); i++) { - QModelIndex idx = index(i); - ServiceItem *item = m_items[idx.row()]; - if (item->selected()) { - item->setSelected(false); - qDebug() << "################"; - qDebug() << "deselected" << item->name(); - qDebug() << "################"; - emit dataChanged(idx, idx, QVector() << SelectedRole); - } - } - qDebug() << "All things have been deselected"; - foreach (QVariant it, items) { - int i = it.toInt(); - QModelIndex idx = index(i); - ServiceItem *item = m_items[idx.row()]; - if (!item->selected()) { - item->setSelected(true); - qDebug() << "################"; - qDebug() << "selected" << item->name(); - qDebug() << "################"; - emit dataChanged(idx, idx, QVector() << SelectedRole); - } - } - return true; -} - -bool ServiceItemModelCpp::activate(int id) { - QModelIndex idx = index(id); - ServiceItem *item = m_items[idx.row()]; - - for (int i = 0; i < m_items.length(); i++) { - QModelIndex idx = index(i); - ServiceItem *itm = m_items[idx.row()]; - if (itm->active()) { - itm->setActive(false); - qDebug() << "################"; - qDebug() << "deactivated" << itm->name(); - qDebug() << "################"; - emit dataChanged(idx, idx, QVector() << ActiveRole); - } - } - - item->setActive(true); - qDebug() << "################"; - qDebug() << "activated" << item->name(); - qDebug() << "################"; - emit dataChanged(idx, idx, QVector() << ActiveRole); - return true; -} - -bool ServiceItemModelCpp::deactivate(int id) { - QModelIndex idx = index(id); - ServiceItem *item = m_items[idx.row()]; - - item->setActive(false); - qDebug() << "################"; - qDebug() << "deactivated" << item->name(); - qDebug() << "################"; - emit dataChanged(idx, idx, QVector() << ActiveRole); - return true; -} - -// bool ServiceItemModelCpp::save(QUrl file) { -// qDebug() << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"; -// qDebug() << "Saving..."; -// qDebug() << "File path is: " << file.toString(); -// qDebug() << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"; - -// //first we'll get a json representation of our serviceList -// //save that to a temp file in case we need it but also convert -// //it to a byte array just before putting it into the archive - -// QJsonArray jsonData; - -// // save all the data and files in jsonData as just the base name -// // so that they are properly mapped in the resulting archive -// for (int i = 0; i < m_items.length(); i++) { -// // qDebug() << serviceList[i]; -// QMap item; -// qDebug() << m_items[i]->name(); - -// item.insert("name", m_items[i]->name()); -// item.insert("background", m_items[i]->background()); -// item.insert("backgroundType", m_items[i]->backgroundType()); -// item.insert("audio", m_items[i]->audio()); -// item.insert("font", m_items[i]->font()); -// item.insert("fontSize", m_items[i]->fontSize()); -// item.insert("slideNumber", m_items[i]->slideNumber()); -// item.insert("text", m_items[i]->text()); -// item.insert("type", m_items[i]->type()); -// item.insert("loop", m_items[i]->loop()); - -// qDebug() << "AUDIO IS: " << item.value("audio").toString(); -// QFileInfo audioFile = item.value("audio").toString(); -// qDebug() << audioFile.fileName(); -// item["flatAudio"] = audioFile.fileName(); -// qDebug() << "AUDIO IS NOW: " << item.value("audio").toString(); - -// QFileInfo backgroundFile = item.value("background").toString(); -// item["flatBackground"] = backgroundFile.fileName(); -// qDebug() << "BACKGRUOND IS: " << item.value("background").toString(); -// // qDebug() << serviceList[i].value(); -// QJsonObject obj = QJsonObject::fromVariantMap(item); -// qDebug() << obj; -// jsonData.insert(i, obj); -// } - -// qDebug() << jsonData; -// QJsonDocument jsonText(jsonData); -// QTemporaryFile jsonFile; - -// if (!jsonFile.exists()) -// qDebug() << "NOT EXISTS!"; - -// if (!jsonFile.open()) -// return false; - -// //finalize the temp json file, in case something goes wrong in the -// //archive, we'll have this to jump back to -// jsonFile.write(jsonText.toJson()); -// qDebug() << jsonFile.fileName(); -// jsonFile.close(); - -// //now we create our archive file and set it's parameters -// QString filename = file.toString().right(file.toString().size() - 7); -// qDebug() << filename; - -// QString tarname; -// if (filename.endsWith(".pres")) { -// qDebug() << "Perfect just go with it!"; -// tarname = filename; -// } else -// tarname = filename + ".pres"; - -// KTar tar(tarname, "application/zstd"); - -// if (tar.open(QIODevice::WriteOnly)) { -// qDebug() << tar.isOpen(); - -// //write our json data to the archive -// tar.writeFile("servicelist.json", -// jsonText.toJson()); - -// //let's add the backgrounds and audios to the archive -// for (int i = 0; i < m_items.size(); i++) { -// qDebug() << m_items[i]->name(); -// QString background = m_items[i]->background(); -// QString backgroundFile = background.right(background.size() - 5); -// qDebug() << backgroundFile; -// QString audio = m_items[i]->audio(); -// QString audioFile = audio.right(audio.size() - 5); -// qDebug() << audioFile; - -// //here we need to cut off all the directories before -// //adding into the archive -// tar.addLocalFile(backgroundFile, -// backgroundFile.right(backgroundFile.size() - -// backgroundFile.lastIndexOf("/") - 1)); -// tar.addLocalFile(audioFile, -// audioFile.right(audioFile.size() - -// audioFile.lastIndexOf("/") - 1)); -// } - -// //close the archive so that everything is done -// tar.close(); - -// QSettings settings; -// settings.setValue("lastSaveFile", file); - -// settings.sync(); - -// qDebug() << settings.value("lastSaveFile"); -// return true; -// } - - -// return false; -// } - -// bool ServiceItemModelCpp::load(QUrl file) { -// qDebug() << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"; -// qDebug() << "Loading..."; -// qDebug() << "File path is: " << file.toString(); -// qDebug() << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"; - -// QFileInfo loadInfo = QFileInfo(file.toLocalFile()); -// if (!loadInfo.exists()) -// return false; - -// QString fileUrl = file.toString().right(file.toString().size() - 7); -// KTar tar(fileUrl); - -// if (tar.open(QIODevice::ReadOnly)){ -// qDebug() << tar.isOpen(); -// const KArchiveDirectory *dir = tar.directory(); - -// const KArchiveEntry *e = dir->entry("servicelist.json"); -// if (!e) { -// qDebug() << "File not found!"; -// } -// const KArchiveFile *f = static_cast(e); -// QByteArray arr(f->data()); -// QJsonDocument jsonText = QJsonDocument::fromJson(arr); -// qDebug() << jsonText; // the file contents - -// QJsonArray array = jsonText.array(); - -// QVariantList serviceList = array.toVariantList(); -// qDebug() << serviceList; - -// // now lets remove all items from current list and add loaded ones -// clearAll(); - -// for (int i = 0; i < serviceList.length(); i++) { -// // int id = serviceList -// qDebug() << "*********************************"; -// qDebug() << serviceList[i].toMap(); -// qDebug() << "*********************************"; - -// QMap item = serviceList[i].toMap(); - -// QString backgroundString = item.value("background").toString(); -// QFileInfo backgroundFile = backgroundString.right(backgroundString.size() - 7); - -// QString audioString = item.value("audio").toString(); -// QFileInfo audioFile = audioString.right(audioString.size() - 7); - -// qDebug() << "POOPPOPOPOPOPOPOPOPOPOPOPOPO"; -// qDebug() << backgroundFile; -// qDebug() << backgroundFile.exists(); -// qDebug() << audioFile; -// qDebug() << audioFile.exists(); -// qDebug() << "POOPPOPOPOPOPOPOPOPOPOPOPOPO"; - -// QString realBackground; -// QString realAudio; - -// QFileInfo serviceFile = file.toString().right(file.toString().size() - 7); -// QString serviceName = serviceFile.baseName(); -// QDir localDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); -// localDir.mkdir(serviceName); -// QDir serviceDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) -// + "/" + serviceName; -// qDebug() << serviceDir.path(); - -// realBackground = backgroundString; -// realAudio = audioString; -// // If the background file is on disk use that, else use the one in archive -// if (!backgroundFile.exists() && backgroundString.length() > 0) { -// const KArchiveEntry *e = dir->entry(backgroundFile.fileName()); -// if (!e) { -// qDebug() << "Background File not found!"; -// continue; -// } -// const KArchiveFile *f = static_cast(e); -// if (!f->copyTo(serviceDir.path())) -// qDebug() << "FILE COULDN'T BE CREATED!"; - -// QFileInfo bgFile = serviceDir.path() + "/" + backgroundFile.fileName(); - -// qDebug() << bgFile.filePath(); - -// realBackground = bgFile.filePath(); -// } - -// // If the audio file is on disk use that, else use the one in archive -// if (!audioFile.exists() && audioString.length() > 0) { -// const KArchiveEntry *e = dir->entry(audioFile.fileName()); -// if (!e) { -// qDebug() << "Audio File not found!"; -// continue; -// } -// const KArchiveFile *f = static_cast(e); -// if (!f->copyTo(serviceDir.path())) -// qDebug() << "FILE COULDN'T BE CREATED!"; - -// QFileInfo audFile = serviceDir.path() + "/" + audioFile.fileName(); - -// qDebug() << audFile.filePath(); - -// realAudio = audFile.filePath(); -// } - -// addItem(item.value("name").toString(), item.value("type").toString(), -// realBackground, -// item.value("backgroundType").toString(), -// item.value("text").toStringList(), realAudio, -// item.value("font").toString(), item.value("fontSize").toInt(), -// item.value("slideNumber").toInt(), item.value("loop").toBool()); -// } - -// return true; - -// } - -// return false; -// } - -void ServiceItemModelCpp::clearAll() { - for (int i = m_items.size(); i >= 0; i--) { - removeItem(i); - } - emit allRemoved(); -} - -bool ServiceItemModelCpp::loadLastSaved() { - QSettings settings; - return load(settings.value("lastSaveFile").toUrl()); -} diff --git a/src/cpp/serviceitemmodel.h b/src/cpp/serviceitemmodel.h deleted file mode 100644 index e552264..0000000 --- a/src/cpp/serviceitemmodel.h +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef SERVICEITEMMODEL_H -#define SERVICEITEMMODEL_H - -#include "serviceitem.h" -#include "slidemodel.h" -#include -#include -#include -#include -#include - -#include "cxx-qt-gen/service_item_model.cxxqt.h" - -class ServiceItemModelCpp : public QAbstractListModel { - Q_OBJECT - -public: - explicit ServiceItemModelCpp(QObject *parent = nullptr); - - enum Roles { - NameRole = Qt::UserRole, - TypeRole, - BackgroundRole, - BackgroundTypeRole, - TextRole, - AudioRole, - FontRole, - FontSizeRole, - SlideNumberRole, - ActiveRole, - SelectedRole, - LoopRole - }; - - // Basic functionality: - int rowCount(const QModelIndex &parent = QModelIndex()) const override; - // int columnCount(const QModelIndex &parent = QModelIndex()) const override; - QVariant data(const QModelIndex &index, - int role = Qt::DisplayRole) const override; - QHash roleNames() const override; - - // Q_INVOKABLE int index(int row, int column, - // const QModelIndex &parent = QModelIndex()) const override; - // Q_INVOKABLE QModelIndex parent(const QModelIndex &index) const override; - - // Editable: - bool setData(const QModelIndex &index, const QVariant &value, - int role = Qt::EditRole) override; - Qt::ItemFlags flags(const QModelIndex &index) const override; - - // Helper methods - void addItem(ServiceItem *item); - void insertItem(const int &index, ServiceItem *item); - Q_INVOKABLE void addItem(const QString &name, const QString &type, - const QString &background, - const QString &backgroundType, - const QStringList &text, const QString &audio, - const QString &font, const int &fontSize, - const int &slideNumber, const bool &loop); - Q_INVOKABLE void insertItem(const int &index, const QString &name, - const QString &type, const QString &background, - const QString &backgroundType, const QStringList &text, - const QString &audio, const QString &font, - const int &fontSize, const int &slideNumber, - const bool &loop); - Q_INVOKABLE void removeItem(int index); - Q_INVOKABLE void removeItems(); - Q_INVOKABLE bool moveRows(int sourceIndex, int destIndex, int count); - Q_INVOKABLE bool moveRowsRust(int source, int dest, int count, ServiceItemModel *rustModel); - Q_INVOKABLE bool moveDown(int index); - Q_INVOKABLE bool moveUp(int index); - Q_INVOKABLE bool select(int id); - Q_INVOKABLE bool selectItems(QVariantList items); - Q_INVOKABLE bool activate(int id); - Q_INVOKABLE bool deactivate(int id); - Q_INVOKABLE QVariantMap getItem(int index) const; - Q_INVOKABLE QVariantMap getRust(int index, ServiceItemModel *rustModel) const; - Q_INVOKABLE QVariantList getItems(); - Q_INVOKABLE void clearAll(); - - // Q_INVOKABLE bool save(QUrl file); - // Q_INVOKABLE bool load(QUrl file); - Q_INVOKABLE bool loadLastSaved(); - -signals: - void itemAdded(const int &, const ServiceItem &); - void itemAddedRust(const int &, const QVariantMap &); - void itemInserted(const int &, const ServiceItem &); - void itemInsertedRust(const int &, const QVariantMap &); - void rowMoved(const int &, const int &, const ServiceItem &); - void rowMovedRust(const int &, const int &, const QVariantMap &); - void rowRemoved(const int &, const ServiceItem &); - void rowRemovedRust(const int &, const QVariantMap &); - void allRemoved(); - -private: - - QList m_items; -}; - -#endif // SERVICEITEMMODEL_H diff --git a/src/cpp/slide.cpp b/src/cpp/slide.cpp deleted file mode 100644 index f1cd623..0000000 --- a/src/cpp/slide.cpp +++ /dev/null @@ -1,253 +0,0 @@ -#include "slide.h" -#include "serviceitemmodel.h" - -#include - -Slide::Slide(QObject *parent) - : QObject{parent} -{ - qDebug() << "Initializing slide"; -} - -Slide::Slide(const QString &text, const QString &audio, const QString &imageBackground, - const QString &videoBackground, const QString &horizontalTextAlignment, - const QString &verticalTextAlignment, const QString &font, - const int &fontSize, const int &imageCount, - const QString &type, const int &slideIndex, const bool &loop, QObject *parent) - : QObject(parent),m_text(text),m_audio(audio),m_imageBackground(imageBackground), - m_videoBackground(videoBackground),m_verticalTextAlignment(verticalTextAlignment), - m_horizontalTextAlignment(horizontalTextAlignment),m_font(font), - m_fontSize(fontSize),m_imageCount(imageCount),m_type(type), - m_slideIndex(slideIndex),m_active(false),m_selected(false),m_loop(loop) -{ - qDebug() << "Initializing slide with defaults"; -} - -QString Slide::text() const { - return m_text; -} - -QString Slide::type() const { - return m_type; -} - -int Slide::serviceItemId() const { - return m_serviceItemId; -} - -QString Slide::audio() const { - return m_audio; -} - -QString Slide::imageBackground() const -{ - return m_imageBackground; -} - -QString Slide::vidThumbnail() const -{ - return m_vidThumbnail; -} - -QString Slide::videoBackground() const -{ - return m_videoBackground; -} - -QString Slide::horizontalTextAlignment() const -{ - return m_horizontalTextAlignment; -} - -QString Slide::verticalTextAlignment() const -{ - return m_verticalTextAlignment; -} - -QString Slide::font() const -{ - return m_font; -} - -int Slide::fontSize() const -{ - return m_fontSize; -} - -int Slide::imageCount() const -{ - return m_imageCount; -} - -int Slide::slideIndex() const -{ - return m_slideIndex; -} - -bool Slide::active() const { - return m_active; -} - -bool Slide::selected() const { - return m_selected; -} - -bool Slide::loop() const { - return m_loop; -} - -void Slide::setText(QString text) -{ - if (m_text == text) - return; - - qDebug() << "####changing text to: " << text; - m_text = text; - emit textChanged(m_text); -} - -void Slide::setType(QString type) -{ - if (m_type == type) - return; - - qDebug() << "####changing type to: " << type; - m_type = type; - emit typeChanged(m_type); -} - -void Slide::setServiceItemId(int serviceItemId) -{ - if (m_serviceItemId == serviceItemId) - return; - - qDebug() << "####changing serviceItemId of slide:" << m_serviceItemId << "and" << m_slideIndex << "TO:" << serviceItemId; - m_serviceItemId = serviceItemId; - qDebug() << "####changed serviceItemId of slide:" << "to" << m_serviceItemId; - emit serviceItemIdChanged(m_serviceItemId); -} - -void Slide::setAudio(QString audio) -{ - if (m_audio == audio) - return; - - qDebug() << "####changing audio to: " << audio; - m_audio = audio; - emit audioChanged(m_audio); -} - -void Slide::setImageBackground(QString imageBackground) -{ - if (m_imageBackground == imageBackground) - return; - - qDebug() << "####changing image background to: " << imageBackground; - m_imageBackground = imageBackground; - emit imageBackgroundChanged(m_imageBackground); -} - -void Slide::setVidThumbnail(QString vidThumbnail) -{ - if (m_vidThumbnail == vidThumbnail) - return; - - qDebug() << "####changing video thumbnail to: " << vidThumbnail; - m_vidThumbnail = vidThumbnail; - emit vidThumbnailChanged(m_vidThumbnail); -} - -void Slide::setVideoBackground(QString videoBackground) -{ - if (m_videoBackground == videoBackground) - return; - - qDebug() << "####changing video background to: " << videoBackground; - m_videoBackground = videoBackground; - emit videoBackgroundChanged(m_videoBackground); -} - -void Slide::setHorizontalTextAlignment(QString horizontalTextAlignment) -{ - if (m_horizontalTextAlignment == horizontalTextAlignment) - return; - - m_horizontalTextAlignment = horizontalTextAlignment; - emit horizontalTextAlignmentChanged(m_horizontalTextAlignment); -} - -void Slide::setVerticalTextAlignment(QString verticalTextAlignment) -{ - if (m_verticalTextAlignment == verticalTextAlignment) - return; - - m_verticalTextAlignment = verticalTextAlignment; - emit verticalTextAlignmentChanged(m_verticalTextAlignment); -} - -void Slide::setFont(QString font) -{ - if (m_font == font) - return; - - m_font = font; - emit fontChanged(m_font); -} - -void Slide::setFontSize(int fontSize) -{ - if (m_fontSize == fontSize) - return; - - m_fontSize = fontSize; - emit fontSizeChanged(m_fontSize); -} - -void Slide::setImageCount(int imageCount) -{ - if (m_imageCount == imageCount) - return; - - qDebug() << "####changing imageCount to: " << imageCount; - m_imageCount = imageCount; - emit imageCountChanged(m_imageCount); -} - -void Slide::setSlideIndex(int slideIndex) -{ - if (m_slideIndex == slideIndex) - return; - - qDebug() << "####changing slideIndex to: " << slideIndex; - m_slideIndex = slideIndex; - emit slideIndexChanged(m_slideIndex); -} - -void Slide::setActive(bool active) -{ - qDebug() << "::::::::::::::::::::"; - qDebug() << "CHANGE ME!"; - if (m_active == active) - return; - - m_active = active; - emit activeChanged(m_active); -} - -void Slide::setSelected(bool selected) -{ - if (m_selected == selected) - return; - - m_selected = selected; - emit selectedChanged(m_selected); -} - -void Slide::setLoop(bool loop) -{ - if (m_loop == loop) - return; - - m_loop = loop; - emit loopChanged(m_loop); -} diff --git a/src/cpp/slide.h b/src/cpp/slide.h deleted file mode 100644 index c5ad299..0000000 --- a/src/cpp/slide.h +++ /dev/null @@ -1,117 +0,0 @@ -#ifndef SLIDE_H -#define SLIDE_H - -#include -#include -#include -#include - -class Slide : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) - Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged) - Q_PROPERTY(int serviceItemId READ serviceItemId WRITE setServiceItemId - NOTIFY serviceItemIdChanged) - Q_PROPERTY(QString audio READ audio WRITE setAudio NOTIFY audioChanged) - Q_PROPERTY(QString imageBackground READ imageBackground WRITE setImageBackground - NOTIFY imageBackgroundChanged) - Q_PROPERTY(QString videoBackground READ videoBackground WRITE setVideoBackground - NOTIFY videoBackgroundChanged) - Q_PROPERTY(QString horizontalTextAlignment READ horizontalTextAlignment - WRITE setHorizontalTextAlignment NOTIFY horizontalTextAlignmentChanged) - Q_PROPERTY(QString verticalTextAlignment READ verticalTextAlignment - WRITE setVerticalTextAlignment NOTIFY verticalTextAlignmentChanged) - Q_PROPERTY(QString font READ font WRITE setFont NOTIFY fontChanged) - Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) - Q_PROPERTY(int imageCount READ imageCount WRITE setImageCount NOTIFY imageCountChanged) - Q_PROPERTY(int slideIndex READ slideIndex WRITE setSlideIndex NOTIFY slideIndexChanged) - Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged) - Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectedChanged) - Q_PROPERTY(bool loop READ loop WRITE setLoop NOTIFY loopChanged) - Q_PROPERTY(QString vidThumbnail READ vidThumbnail WRITE setVidThumbnail - NOTIFY vidThumbnailChanged) - // QML_ELEMENT - -public: - explicit Slide(QObject *parent = nullptr); - Slide(const QString &text, const QString &audio, - const QString &imageBackground, const QString &videoBackground, - const QString &horizontalTextAlignment, const QString &verticalTextAlignment, - const QString &font, const int &fontSize, const int &imageCount, - const QString &type, const int &slideIndex, const bool &loop, - QObject * parent = nullptr); - - QString text() const; - QString type() const; - QString audio() const; - QString imageBackground() const; - QString videoBackground() const; - QString horizontalTextAlignment() const; - QString verticalTextAlignment() const; - QString font() const; - int fontSize() const; - int imageCount() const; - int slideIndex() const; - int serviceItemId() const; - bool active() const; - bool selected() const; - bool loop() const; - QString vidThumbnail() const; - - Q_INVOKABLE void setText(QString text); - Q_INVOKABLE void setType(QString type); - Q_INVOKABLE void setServiceItemId(int serviceItemId); - Q_INVOKABLE void setAudio(QString audio); - Q_INVOKABLE void setImageBackground(QString imageBackground); - Q_INVOKABLE void setVideoBackground(QString videoBackground); - Q_INVOKABLE void setHorizontalTextAlignment(QString horizontalTextAlignment); - Q_INVOKABLE void setVerticalTextAlignment(QString verticalTextAlignment); - Q_INVOKABLE void setFont(QString font); - Q_INVOKABLE void setFontSize(int fontSize); - Q_INVOKABLE void setImageCount(int imageCount); - Q_INVOKABLE void setSlideIndex(int slideIndex); - Q_INVOKABLE void setActive(bool active); - Q_INVOKABLE void setSelected(bool selected); - Q_INVOKABLE void setLoop(bool loop); - Q_INVOKABLE void setVidThumbnail(QString vidThumbnail); - -signals: - Q_INVOKABLE void textChanged(QString text); - Q_INVOKABLE void typeChanged(QString type); - Q_INVOKABLE void serviceItemIdChanged(int serviceItemId); - Q_INVOKABLE void audioChanged(QString audio); - Q_INVOKABLE void imageBackgroundChanged(QString imageBackground); - Q_INVOKABLE void videoBackgroundChanged(QString videoBackground); - Q_INVOKABLE void horizontalTextAlignmentChanged(QString horizontalTextAlignment); - Q_INVOKABLE void verticalTextAlignmentChanged(QString verticalTextAlignment); - Q_INVOKABLE void fontChanged(QString font); - Q_INVOKABLE void fontSizeChanged(int fontSize); - Q_INVOKABLE void imageCountChanged(int imageCount); - Q_INVOKABLE void slideIndexChanged(int slideIndex); - Q_INVOKABLE void activeChanged(bool active); - Q_INVOKABLE void selectedChanged(bool selected); - Q_INVOKABLE void loopChanged(bool loop); - Q_INVOKABLE void vidThumbnailChanged(QString vidThumbnail); - -private: - int m_id; - QString m_text; - QString m_type; - int m_serviceItemId; - QString m_audio; - QString m_imageBackground; - QString m_videoBackground; - QString m_horizontalTextAlignment; - QString m_verticalTextAlignment; - QString m_font; - int m_fontSize; - int m_imageCount; - int m_slideIndex; - bool m_active; - bool m_selected; - bool m_loop; - QString m_vidThumbnail; -}; - -#endif //SLIDE_H diff --git a/src/cpp/slidehelper.cpp b/src/cpp/slidehelper.cpp deleted file mode 100644 index b4d05ec..0000000 --- a/src/cpp/slidehelper.cpp +++ /dev/null @@ -1,210 +0,0 @@ -#include "slidehelper.h" -#include "serviceitemmodel.h" -#include "slidemodel.h" - -// #include -#include - -// using namespace PoDoFo; -SlideHelper::SlideHelper(QObject *parent) - : Slide{parent} -{ - qDebug() << "Initializing slide"; -} - -SlideHelper::SlideHelper(const QString &text, const QString &audio, - const QString &imageBackground, - const QString &videoBackground, - const QString &horizontalTextAlignment, - const QString &verticalTextAlignment, - const QString &font, - const int &fontSize, - const int &imageCount, - const bool &isPlaying, - const QString &type, - QObject *parent) -: Slide(parent), - m_isPlaying(isPlaying), - m_slideIndex(0) -{ - setText(text); - setAudio(audio), - setImageBackground(imageBackground), - setVideoBackground(videoBackground), - setVerticalTextAlignment(verticalTextAlignment), - setHorizontalTextAlignment(horizontalTextAlignment), - setFont(font), - setFontSize(fontSize), - setImageCount(imageCount), - setType(type), - qDebug() << "Initializing slide with defaults"; -} - -bool SlideHelper::isPlaying() const -{ - return m_isPlaying; -} - -int SlideHelper::slideIndex() const -{ - return m_slideIndex; -} - -int SlideHelper::slideSize() const -{ - return m_slideSize; -} - -bool SlideHelper::loop() const -{ - return m_loop; -} - -void SlideHelper::chngSlide(QVariantMap item, int index, SlideObject *slideObject) { - // qDebug() << "Here is the pointer to the slideObj" << slideObj; - // qDebug() << "Here is the item" << item; - slideObject->changeSlide(item, index); -} - -void SlideHelper::changeSlide(QVariantMap item, int index) -{ - // QVariantMap serviceItem = serviceItemModel->getItem(item.value("serviceItemId").toInt()); - if (item.value("text").toString() != text()) - setText(item.value("text").toString()); - if (item.value("type").toString() != type()) - setType(item.value("type").toString()); - if (item.value("audio").toString() != audio()) - setAudio(item.value("audio").toString()); - if (item.value("imageBackground").toString() != imageBackground()) - setImageBackground(item.value("imageBackground").toString()); - if (item.value("videoBackground").toString() != videoBackground()) { - qDebug() << "Setting VIDEOBACKGROUND to:" << item.value("videoBackground").toString(); - setVideoBackground(item.value("videoBackground").toString()); - } - if (item.value("verticalTextAlignment").toString() != verticalTextAlignment()) - setVerticalTextAlignment(item.value("verticalTextAlignment").toString()); - if (item.value("horizontalTextAlignment").toString() != horizontalTextAlignment()) - setHorizontalTextAlignment(item.value("horizontalTextAlignment").toString()); - if (item.value("font").toString() != font()) - setFont(item.value("font").toString()); - if (item.value("fontSize").toInt() != fontSize()) - setFontSize(item.value("fontSize").toInt()); - - if (loop() != item.value("loop").toBool()) { - setLoop(item.value("loop").toBool()); - emit loopChanged(loop()); - } - setImageCount(item.value("imageCount").toInt()); - setSlideIndex(item.value("slideIndex").toInt()); - qDebug() << "THIS IS THE INDEX OF THE SLIDE!"; - qDebug() << index; - emit slideChanged(index); - // m_slideSize = serviceItem.value("slideNumber").toInt(); - - // emit slideSizeChanged(m_slideSize); -} - -bool SlideHelper::next(QVariantMap nextItem, SlideModel *slideModel) -{ - // QVariantMap serviceItem = serviceItemModel->getItem(nextItem.value("serviceItemId").toInt()); - setText(nextItem.value("text").toString()); - setType(nextItem.value("type").toString()); - setAudio(nextItem.value("audio").toString()); - setImageBackground(nextItem.value("imageBackground").toString()); - setVideoBackground(nextItem.value("videoBackground").toString()); - setVerticalTextAlignment(nextItem.value("verticalTextAlignment").toString()); - setHorizontalTextAlignment(nextItem.value("horizontalTextAlignment").toString()); - setFont(nextItem.value("font").toString()); - setFontSize(nextItem.value("fontSize").toInt()); - setImageCount(nextItem.value("imageCount").toInt()); - setSlideIndex(nextItem.value("slideIndex").toInt()); - if (loop() != nextItem.value("loop").toBool()) { - setLoop(nextItem.value("loop").toBool()); - emit loopChanged(loop()); - } - // m_slideSize = serviceItem.value("slideNumber").toInt(); - - - // emit slideSizeChanged(m_slideSize); - return false; -} - -bool SlideHelper::previous(QVariantMap prevItem, SlideModel *slideModel) -{ - // QVariantMap serviceItem = serviceItemModel->getItem(prevItem.value("serviceItemId").toInt()); - setText(prevItem.value("text").toString()); - setType(prevItem.value("type").toString()); - setAudio(prevItem.value("audio").toString()); - setImageBackground(prevItem.value("imageBackground").toString()); - setVideoBackground(prevItem.value("videoBackground").toString()); - setVerticalTextAlignment(prevItem.value("verticalTextAlignment").toString()); - setHorizontalTextAlignment(prevItem.value("horizontalTextAlignment").toString()); - setFont(prevItem.value("font").toString()); - setFontSize(prevItem.value("fontSize").toInt()); - setImageCount(prevItem.value("imageCount").toInt()); - setSlideIndex(prevItem.value("slideIndex").toInt()); - if (loop() != prevItem.value("loop").toBool()) { - setLoop(prevItem.value("loop").toBool()); - emit loopChanged(loop()); - } - // m_slideSize = serviceItem.value("slideNumber").toInt(); - - // emit slideSizeChanged(m_slideSize); - return false; -} - -bool SlideHelper::changeSlideIndex(int index) -{ - qDebug() << "Starting to change slide index."; - qDebug() << "SlideHelper Index: " << slideIndex() << " SlideHelper Size: " << slideSize(); - // QStringList text = serviceItemId().value("text").toStringList(); - if (index > slideSize() - 1 || index < 0) { - qDebug() << "index is invalid: " << index; - return false; - } - - // since the string list is 0 indexed m_slideIndex actually - // maps to the next item. So the prev text is minus 2 - if (type() == "song") { - int textIndex = index; - qDebug() << textIndex; - // qDebug() << text[textIndex]; - // setText(text[textIndex]); - m_slideIndex = index; - emit slideIndexChanged(m_slideIndex); - return true; - } - - if (type() == "presentation") { - qDebug() << "prev slide index: " << slideIndex(); - m_slideIndex = index; - qDebug() << "new slide index: " << slideIndex(); - emit slideIndexChanged(m_slideIndex); - return true; - } - return false; -} - -void SlideHelper::play() -{ - m_isPlaying = true; - emit isPlayingChanged(m_isPlaying); -} - -void SlideHelper::setLoop(bool loop) -{ - m_loop = loop; - emit loopChanged(m_loop); -} - -void SlideHelper::pause() -{ - m_isPlaying = false; - emit isPlayingChanged(m_isPlaying); -} - -void SlideHelper::playPause() -{ - m_isPlaying = !m_isPlaying; - emit isPlayingChanged(m_isPlaying); -} diff --git a/src/cpp/slidehelper.h b/src/cpp/slidehelper.h deleted file mode 100644 index e17f438..0000000 --- a/src/cpp/slidehelper.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef SLIDEOBJECT_H -#define SLIDEOBJECT_H - -#include "serviceitemmodel.h" -#include "slide.h" -#include "slidemodel.h" -#include -#include -#include -#include -#include "cxx-qt-gen/slide_object.cxxqt.h" - -class SlideHelper : public Slide -{ - Q_OBJECT - Q_PROPERTY(bool isPlaying READ isPlaying NOTIFY isPlayingChanged) - Q_PROPERTY(int slideIndex READ slideIndex NOTIFY slideIndexChanged) - Q_PROPERTY(int slideSize READ slideSize NOTIFY slideSizeChanged) - Q_PROPERTY(bool loop READ loop NOTIFY loopChanged) - // QML_ELEMENT - -public: - explicit SlideHelper(QObject *parent = nullptr); - SlideHelper(const QString &text, const QString &audio, - const QString &imageBackground, const QString &videoBackground, - const QString &horizontalTextAlignment, const QString &verticalTextAlignment, - const QString &font, const int &fontSize, const int &imageCount, - const bool &isPlaying, const QString &type, - QObject * parent = nullptr); - - bool isPlaying() const; - int slideIndex() const; - int slideSize() const; - bool loop() const; - - Q_INVOKABLE void changeSlide(QVariantMap item, int index); - Q_INVOKABLE void chngSlide(QVariantMap item, int index, SlideObject *slideObject); - Q_INVOKABLE void play(); - Q_INVOKABLE void pause(); - Q_INVOKABLE void playPause(); - Q_INVOKABLE bool next(QVariantMap nextItem, SlideModel *slideModel); - Q_INVOKABLE bool previous(QVariantMap prevItem, SlideModel *slideModel); - Q_INVOKABLE bool changeSlideIndex(int index); - Q_INVOKABLE void setLoop(bool loop); - -signals: - Q_INVOKABLE void isPlayingChanged(bool isPlaying); - Q_INVOKABLE void slideIndexChanged(int slideIndex); - Q_INVOKABLE void slideSizeChanged(int slideSize); - Q_INVOKABLE void slideChanged(int slide); - Q_INVOKABLE void loopChanged(bool loop); - -private: - bool m_isPlaying; - int m_slideIndex; - int m_slideSize; - bool m_loop; -}; - -#endif //SLIDEOBJECT_H diff --git a/src/cpp/slidemodel.cpp b/src/cpp/slidemodel.cpp deleted file mode 100644 index 6ffdc90..0000000 --- a/src/cpp/slidemodel.cpp +++ /dev/null @@ -1,823 +0,0 @@ -#include "slidemodel.h" -#include "mpv/mpvobject.h" -#include "serviceitem.h" -#include "slide.h" -#include "framedecoder.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - - -const QDir writeDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); - -SlideModelCpp::SlideModelCpp(QObject *parent) - : QAbstractListModel(parent) { - // if () { - // addItem(new Slide("10,000 Reasons", "song", - // "file:/home/chris/nextcloud/tfc/openlp/CMG - Nature King 21.jpg", - // "image", QString("Yip Yip"), - // "file:/home/chris/nextcloud/tfc/openlp/music/Eden-Phil Wickham [lyrics].mp3")); - // addItem(new Slide("Marvelous Light", "song", - // "file:/home/chris/nextcloud/tfc/openlp/Fire Embers_Loop.mp4", - // "video", QString("Hallelujah!"))); - // addItem(new Slide("BP Text", "video", - // "file:/home/chris/nextcloud/tfc/openlp/videos/test.mp4", - // "video", QString())); - // } -} - -int SlideModelCpp::rowCount(const QModelIndex &parent) const { - // For list models only the root node (an invalid parent) should return the - // list's size. For all other (valid) parents, rowCount() should return 0 so - // that it does not become a tree model. - if (parent.isValid()) - return 0; - - // FIXME: Implement me! - return m_items.size(); -} - -QVariant SlideModelCpp::data(const QModelIndex &index, int role) const { - if (!index.isValid()) - return QVariant(); - - Slide *item = m_items[index.row()]; - switch (role) { - case TextRole: - return item->text(); - case TypeRole: - return item->type(); - case ImageBackgroundRole: - return item->imageBackground(); - case VideoBackgroundRole: - return item->videoBackground(); - case AudioRole: - return item->audio(); - case FontRole: - return item->font(); - case FontSizeRole: - return item->fontSize(); - case ServiceItemIdRole: - return item->serviceItemId(); - case SlideIndexRole: - return item->slideIndex(); - case HorizontalTextAlignmentRole: - return item->horizontalTextAlignment(); - case VerticalTextAlignmentRole: - return item->verticalTextAlignment(); - case ActiveRole: - return item->active(); - case SelectedRole: - return item->selected(); - case LoopRole: - return item->loop(); - case VidThumbnailRole: - return item->vidThumbnail(); - default: - return QVariant(); - } -} - -QHash SlideModelCpp::roleNames() const { - static QHash mapping { - {TextRole, "text"}, - {TypeRole, "type"}, - {ImageBackgroundRole, "imageBackground"}, - {VideoBackgroundRole, "videoBackground"}, - {AudioRole, "audio"}, - {FontRole, "font"}, - {FontSizeRole, "fontSize"}, - {ServiceItemIdRole, "serviceItemId"}, - {HorizontalTextAlignmentRole, "horizontalTextAlignment"}, - {VerticalTextAlignmentRole, "verticalTextAlignment"}, - {SlideIndexRole, "slideIndex"}, - {ActiveRole, "active"}, - {SelectedRole, "selected"}, - {LoopRole, "loop"}, - {VidThumbnailRole, "vidThumbnail"} - }; - - return mapping; -} - -bool SlideModelCpp::setData(const QModelIndex &index, const QVariant &value, - int role) { - - Slide *item = m_items[index.row()]; - bool somethingChanged = false; - - switch (role) { - case TypeRole: - if (item->type() != value.toString()) { - item->setType(value.toString()); - somethingChanged = true; - } - break; - case ImageBackgroundRole: - if (item->imageBackground() != value.toString()) { - item->setImageBackground(value.toString()); - somethingChanged = true; - } - break; - case VideoBackgroundRole: - if (item->videoBackground() != value.toString()) { - item->setVideoBackground(value.toString()); - somethingChanged = true; - } - break; - case TextRole: - if (item->text() != value.toString()) { - item->setText(value.toString()); - somethingChanged = true; - } - break; - case AudioRole: - if (item->audio() != value.toString()) { - item->setAudio(value.toString()); - somethingChanged = true; - } - break; - case FontRole: - if (item->font() != value.toString()) { - item->setFont(value.toString()); - somethingChanged = true; - } - break; - case FontSizeRole: - if (item->fontSize() != value.toInt()) { - item->setFontSize(value.toInt()); - somethingChanged = true; - } - break; - case ServiceItemIdRole: - if (item->serviceItemId() != value.toInt()) { - item->setServiceItemId(value.toInt()); - somethingChanged = true; - } - break; - case SlideIndexRole: - if (item->slideIndex() != value.toInt()) { - item->setSlideIndex(value.toInt()); - somethingChanged = true; - } - break; - case HorizontalTextAlignmentRole: - if (item->horizontalTextAlignment() != value.toString()) { - item->setHorizontalTextAlignment(value.toString()); - somethingChanged = true; - } - break; - case VerticalTextAlignmentRole: - if (item->verticalTextAlignment() != value.toString()) { - item->setVerticalTextAlignment(value.toString()); - somethingChanged = true; - } - break; - case ActiveRole: - if (item->active() != value.toBool()) { - item->setActive(value.toBool()); - somethingChanged = true; - } - break; - case SelectedRole: - if (item->selected() != value.toBool()) { - item->setSelected(value.toBool()); - somethingChanged = true; - } - break; - case LoopRole: - if (item->loop() != value.toBool()) { - item->setLoop(value.toBool()); - somethingChanged = true; - } - break; - case VidThumbnailRole: - if (item->vidThumbnail() != value.toString()) { - item->setVidThumbnail(value.toString()); - somethingChanged = true; - } - break; - if (somethingChanged) { - emit dataChanged(index, index, QVector() << role); - return true; - } - } - - return false; -} - -Qt::ItemFlags SlideModelCpp::flags(const QModelIndex &index) const { - if (!index.isValid()) - return Qt::NoItemFlags; - - return Qt::ItemIsEditable; // FIXME: Implement me! -} - -// int SlideyMod::index(int row, int column, const QModelIndex &parent) { -// if (!hasIndex(row, column, parent)) -// return QModelIndex(); - -// Slide *parentItem; - -// if (!parent.isValid()) -// parentItem = rootItem; -// else -// parentItem = static_cast(parent.internalPointer()); - -// Slide *childItem = parentItem->child(row); -// if (childItem) -// return createIndex(row, column, childItem); -// return QModelIndex(); -// } - -void SlideModelCpp::addItem(Slide *item) { - const int index = m_items.size(); - qDebug() << index; - // foreach (item, m_items) { - // qDebug() << item; - // } - beginInsertRows(QModelIndex(), index, index); - m_items.append(item); - endInsertRows(); -} - -void SlideModelCpp::insertItem(const int &index, Slide *item) { - beginInsertRows(this->index(index).parent(), index, index); - m_items.insert(index, item); - endInsertRows(); - qDebug() << "Success"; -} - -void SlideModelCpp::addItem(const QString &text, const QString &type, - const QString &imageBackground, const QString &videoBackground, - const QString &audio, - const QString &font, const int &fontSize, - const QString &horizontalTextAlignment, - const QString &verticalTextAlignment, - const int &serviceItemId, const int &slideIndex, - const int &imageCount, const bool &loop) { - Slide *item = new Slide(text, audio, imageBackground, videoBackground, - horizontalTextAlignment, - verticalTextAlignment, - font, fontSize, imageCount, type, slideIndex, loop); - item->setSelected(false); - item->setActive(false); - item->setServiceItemId(serviceItemId); - addItem(item); - qDebug() << "#################################"; - qDebug() << type << font << fontSize << serviceItemId; - qDebug() << "#################################"; -} - -void SlideModelCpp::insertItem(const int &index, - const QString &type, const QString &imageBackground, - const QString &videoBackground, const QString &text, - const QString &audio, const QString &font, - const int &fontSize, const QString &horizontalTextAlignment, - const QString &verticalTextAlignment, - const int &serviceItemId, const int &slideIndex, - const int &imageCount, const bool &loop) { - Slide *item = new Slide(text, audio, imageBackground, videoBackground, - horizontalTextAlignment, verticalTextAlignment, font, fontSize, - imageCount, type, slideIndex, loop); - item->setSelected(false); - item->setActive(false); - item->setServiceItemId(serviceItemId); - insertItem(index, item); - qDebug() << "#################################"; - qDebug() << "ADDING A NEW SLIDE INTO MODEL!"; - qDebug() << type << font << fontSize << slideIndex; - qDebug() << "#################################"; -} - -void SlideModelCpp::removeItem(int index) { - beginRemoveRows(QModelIndex(), index, index); - m_items.removeAt(index); - endRemoveRows(); -} - -void SlideModelCpp::removeServiceItem(const int &index, const ServiceItem &item) { - qDebug() << "Need to remove serviceItem:" - << item.name() - << "with" - << item.slideNumber() - << "slides."; - int id = findSlideIdFromServItm(index); - if (id < 0) { - qWarning() << "There is no slide with that ServiceItem"; - return; - } - if (item.slideNumber() > 1) { - qDebug() << "need to remove" << item.slideNumber() << "slides"; - for (int i = id + item.slideNumber() - 1; i >= id; i--) { - qDebug() << "Removing multiple slides"; - qDebug() << "Removing slide:" << i; - beginRemoveRows(QModelIndex(), i, i); - m_items.removeAt(i); - endRemoveRows(); - } - for (int i = id; i < m_items.length(); i++) - m_items[i]->setServiceItemId(m_items[i]->serviceItemId() - 1); - } else { - qDebug() << "Removing serviceItem:" << id; - beginRemoveRows(QModelIndex(), id, id); - m_items.removeAt(id); - endRemoveRows(); - for (int i = id; i < m_items.length(); i++) - m_items[i]->setServiceItemId(m_items[i]->serviceItemId() - 1); - } -} - -void SlideModelCpp::removeItems() { - for (int i = m_items.length() - 1; i > -1; i--) { - QModelIndex idx = index(i); - Slide *item = m_items[idx.row()]; - if (item->selected()) { - qDebug() << "Removing item:" << i; - beginRemoveRows(QModelIndex(), i, i); - m_items.removeAt(i); - endRemoveRows(); - } - } -} - -bool SlideModelCpp::moveRows(int sourceIndex, int destIndex, int count) { - qDebug() << index(sourceIndex).row(); - qDebug() << index(destIndex).row(); - - const int lastIndex = rowCount() - 1; - - if (sourceIndex == destIndex - || (sourceIndex < 0 || sourceIndex > lastIndex) - || (destIndex < 0 || destIndex > lastIndex)) { - return false; - } - - const QModelIndex parent = index(sourceIndex).parent(); - const bool isMoveDown = destIndex > sourceIndex; - - if (!beginMoveRows(parent, sourceIndex, sourceIndex + count - 1, - parent, isMoveDown ? destIndex + 1 : destIndex)) { - qDebug() << "Can't move rows"; - return false; - } - - qDebug() << "starting move: " << "source: " << sourceIndex << "dest: " << destIndex; - - qDebug() << "items " << m_items; - for (int i = 0; i < count; i++) { - m_items.move(sourceIndex, destIndex); - } - qDebug() << "items " << m_items; - - endMoveRows(); - return true; -} - -bool SlideModelCpp::moveDown(int id) { - qDebug() << index(id).row(); - qDebug() << index(id + 1).row(); - QModelIndex parent = index(id).parent(); - - bool begsuc = beginMoveRows(parent, id, - id, parent, id + 2); - if (begsuc) { - int dest = id + 1; - if (dest >= m_items.size()) - { - qDebug() << "dest too big, moving to end"; - m_items.move(id, m_items.size() - 1); - } - else - m_items.move(id, dest); - endMoveRows(); - return true; - } - return false; -} - -bool SlideModelCpp::moveUp(int id) { - qDebug() << index(id).row(); - qDebug() << index(id - 1).row(); - QModelIndex parent = index(id).parent(); - - bool begsuc = beginMoveRows(parent, id, - id, parent, id - 1); - if (begsuc) { - int dest = id - 1; - if (dest <= -1) - { - qDebug() << "dest too big, moving to beginning"; - m_items.move(id, 0); - } - else - m_items.move(id, dest); - endMoveRows(); - return true; - } - - return false; -} - -QVariantMap SlideModelCpp::getItem(int index) const { - QVariantMap data; - const QModelIndex idx = this->index(index,0); - // qDebug() << idx; - if( !idx.isValid() ) - return data; - const QHash rn = roleNames(); - // qDebug() << rn; - QHashIterator it(rn); - while (it.hasNext()) { - it.next(); - qDebug() << it.key() << ":" << it.value(); - data[it.value()] = idx.data(it.key()); - } - return data; -} - -QVariantMap SlideModelCpp::getItemRust(int index, SlideModel *slidemodel) const { - QVariantMap data = slidemodel->getItem(index); - qDebug() << data; - return data; -} - -QVariantList SlideModelCpp::getItems() { - QVariantList data; - Slide * item; - foreach (item, m_items) { - qDebug() << item->serviceItemId(); - QVariantMap itm; - itm["type"] = item->type(); - itm["imageBackground"] = item->imageBackground(); - itm["videoBackground"] = item->videoBackground(); - itm["text"] = item->text(); - itm["audio"] = item->audio(); - itm["font"] = item->font(); - itm["fontSize"] = item->fontSize(); - itm["horizontalTextAlignment"] = item->horizontalTextAlignment(); - itm["verticalTextAlignment"] = item->verticalTextAlignment(); - itm["serviceItemId"] = item->serviceItemId(); - itm["selected"] = item->selected(); - itm["active"] = item->active(); - itm["loop"] = item->loop(); - data.append(itm); - } - qDebug() << "$$$$$$$$$$$$$$$$$$$$$$$$$$$"; - qDebug() << data; - qDebug() << "$$$$$$$$$$$$$$$$$$$$$$$$$$$"; - return data; -} - -bool SlideModelCpp::select(int id) { - for (int i = 0; i < m_items.length(); i++) { - QModelIndex idx = index(i); - Slide *item = m_items[idx.row()]; - if (item->selected()) { - item->setSelected(false); - qDebug() << "################"; - qDebug() << "deselected" << item->slideIndex(); - qDebug() << "################"; - emit dataChanged(idx, idx, QVector() << SelectedRole); - } - } - QModelIndex idx = index(id); - Slide *item = m_items[idx.row()]; - item->setSelected(true); - qDebug() << "################"; - qDebug() << "selected" << item->slideIndex(); - qDebug() << "################"; - emit dataChanged(idx, idx, QVector() << SelectedRole); - return true; -} - -bool SlideModelCpp::activate(int id) { - QModelIndex idx = index(id); - Slide *item = m_items[idx.row()]; - qDebug() << item->type(); - - for (int i = 0; i < m_items.length(); i++) { - QModelIndex idx = index(i); - Slide *itm = m_items[idx.row()]; - // qDebug() << i << m_items.length() << item->active() << itm->active(); - if (itm->active()) { - itm->setActive(false); - // qDebug() << "################"; - // qDebug() << "deactivated" << itm->slideIndex(); - // qDebug() << "################"; - emit dataChanged(idx, idx, QVector() << ActiveRole); - } - } - - item->setActive(true); - qDebug() << "################"; - qDebug() << "slide activated" << item->slideIndex(); - qDebug() << "################"; - emit dataChanged(idx, idx, QVector() << ActiveRole); - return true; -} - -bool SlideModelCpp::deactivate(int id) { - QModelIndex idx = index(id); - Slide *item = m_items[idx.row()]; - - item->setActive(false); - // qDebug() << "################"; - // qDebug() << "deactivated" << item->slideIndex(); - // qDebug() << "################"; - emit dataChanged(idx, idx, QVector() << ActiveRole); - return true; -} - -void SlideModelCpp::clearAll() { - for (int i = m_items.size(); i >= 0; i--) { - removeItem(i); - } -} - -int SlideModelCpp::findSlideIdFromServItm(int index) { - for (int i = 0; i < m_items.size(); i++) { - Slide *itm = m_items[i]; - if (itm->serviceItemId() == index) { - return i; - } - } - return 0; -} - -void SlideModelCpp::addItemFromService(const int &index, const ServiceItem &item) { - qDebug() << "***INSERTING SLIDE FROM SERVICEITEM***"; - if (item.type() == "song") { - for (int i = 0; i < item.text().size(); i++) { - if (item.backgroundType() == "image") { - addItem(item.text()[i], item.type(), item.background(), "", - item.audio(), item.font(), item.fontSize(), "center", "center", - index, i, item.text().size(), item.loop()); - } else { - addItem(item.text()[i], item.type(), "", item.background(), - item.audio(), item.font(), item.fontSize(), "center", "center", - index, i, item.text().size(), item.loop()); - } - } - } else if (item.type() == "presentation") { - for (int i = 0; i < item.slideNumber(); i++) { - addItem("", item.type(), item.background(), "", - item.audio(), item.font(), item.fontSize(), - "center", "center", - index, i, item.slideNumber(), item.loop()); - } - } else if (item.type() == "video") { - addItem("", item.type(), "", item.background(), - item.audio(), item.font(), item.fontSize(), - "center", "center", - index, 0, 1, item.loop()); - } else { - addItem("", item.type(), item.background(), "", - item.audio(), item.font(), item.fontSize(), - "center", "center", - index, 0, 1, item.loop()); - } - -} - -void SlideModelCpp::insertItemFromService(const int &index, const ServiceItem &item) { - qDebug() << "***INSERTING SLIDE FROM SERVICEITEM***"; - int slideId = findSlideIdFromServItm(index); - // move all slides to the next serviceItem - // this needs to happen first so that the slides are - // shifted appropriately - for (int i = slideId; i < rowCount(); i++) { - m_items[i]->setServiceItemId(m_items[i]->serviceItemId() + 1); - } - // inserting item - if (item.type() == "song") { - for (int i = 0; i < item.text().size(); i++) { - if (item.backgroundType() == "image") { - insertItem(slideId + i, item.type(), item.background(), "", item.text()[i], - item.audio(), item.font(), item.fontSize(), "center", "center", - index, i, item.text().size(), item.loop()); - } else { - insertItem(slideId + i, item.type(), "", item.background(), item.text()[i], - item.audio(), item.font(), item.fontSize(), "center", "center", - index, i, item.text().size(), item.loop()); - } - } - } else if (item.type() == "presentation") { - for (int i = 0; i < item.slideNumber(); i++) { - insertItem(slideId + i, item.type(), item.background(), "", - "", item.audio(), item.font(), item.fontSize(), - "center", "center", - index, i, item.slideNumber(), item.loop()); - } - } else if (item.type() == "video") { - insertItem(slideId, item.type(), "", item.background(), "", - item.audio(), item.font(), item.fontSize(), - "center", "center", - index, 0, 1, item.loop()); - } else { - insertItem(slideId, item.type(), item.background(), "", "", - item.audio(), item.font(), item.fontSize(), - "center", "center", - index, 0, 1, item.loop()); - } - -} - -void SlideModelCpp::moveRowFromService(const int &fromIndex, - const int &toIndex, - const ServiceItem &item) { - const bool isMoveDown = toIndex > fromIndex; - qDebug() << "@@@Move SIs" << fromIndex << "to" << toIndex << "@@@"; - int sourceStartId = findSlideIdFromServItm(fromIndex); - int count; - if (item.type() == "song") - count = item.text().length(); - else if (item.type() == "presentation") - count = item.slideNumber(); - else - count = 1; - int sourceEndId = sourceStartId + count; - qDebug() << sourceStartId << sourceEndId; - // Slide toSlide = m_items[sourceEndId]; - // int toCount = toSlide.imageCount(); - // int toId = count + sourceStartId; - qDebug() << "@@@Move Row" << sourceStartId << "to" << sourceEndId << "@@@"; - qDebug() << count; - // if (isMoveDown) { - // qDebug() << "Moving Down in service list" << sourceStartId << "to" << sourceEndId; - // if (sourceEndId - sourceStartId > 1) - // if (!moveRows(sourceStartId, sourceEndId - 1, count)) { - // // failed code - // return; - // } - // else - // if (!moveRows(sourceStartId, sourceEndId, count)) { - - // return; - // } - // } else { - // if (sourceStartId - sourceEndId > 1) - // if (!moveRows(sourceStartId - 1, sourceEndId, count)) { - - // return; - // } - // else - // if (!moveRows(sourceStartId, sourceEndId, count)) { - - // return; - // } - // } - if (!moveRows(sourceStartId, sourceEndId, count)) { - qDebug() << "Failed to move rows"; - return; - } - m_items[sourceEndId]->setServiceItemId(toIndex); - if (isMoveDown) { - for (int i = sourceStartId; i < sourceEndId; i++) { - m_items[i]->setServiceItemId(m_items[i]->serviceItemId() - 1); - } - } else { - for (int i = sourceStartId; i > sourceEndId; i--) { - m_items[i]->setServiceItemId(m_items[i]->serviceItemId() + 1); - } - } -} - -QString SlideModelCpp::thumbnailVideoRust(QString video, int serviceItemId, int index, SlideModel *slideModel) { - - QDir dir = writeDir.absolutePath() + "/librepresenter/thumbnails"; - QDir absDir = writeDir.absolutePath() + "/librepresenter"; - if (!dir.exists()) { - qDebug() << dir.path() << "does not exist"; - absDir.mkdir("thumbnails"); - } - - QFileInfo vid(video); - QString id; - id.setNum(serviceItemId); - QString vidName(vid.fileName() + "-" + id); - qDebug() << vidName; - QString thumbnail = dir.path() + "/" + vidName + ".webp"; - QFileInfo thumbnailInfo(dir.path() + "/" + vidName + ".jpg"); - qDebug() << thumbnailInfo.filePath() << "FOR" << index; - if (thumbnailInfo.exists()) { - // slideModel->addVideoThumbnail("file://" + thumbnailInfo.absoluteFilePath(), serviceItemId, index); - return thumbnailInfo.filePath(); - } - - - QImage image; - QString filename = video.right(video.size() - 7); - image = frameToImage(filename, 576); - if (image.isNull()) { - qDebug() << QStringLiteral("Failed to create thumbnail for file: %1").arg(video); - return "failed"; - } - - qDebug() << "dir location " << writeDir.absolutePath(); - if (!writeDir.mkpath(".")) { - qFatal("Failed to create writable location at %s", qPrintable(writeDir.absolutePath())); - } - - if (!image.save(thumbnailInfo.filePath())) { - qDebug() << QStringLiteral("Failed to save thumbnail for file: %1").arg(video); - } - - // slideModel->addVideoThumbnail("file://" + thumbnailInfo.absoluteFilePath(), serviceItemId, index); - - return thumbnailInfo.filePath(); -} - -QString SlideModelCpp::thumbnailVideo(QString video, int serviceItemId, int index) { - - QDir dir = writeDir.absolutePath() + "/librepresenter/thumbnails"; - QDir absDir = writeDir.absolutePath() + "/librepresenter"; - if (!dir.exists()) { - qDebug() << dir.path() << "does not exist"; - absDir.mkdir("thumbnails"); - } - - QFileInfo vid(video); - QString id; - id.setNum(serviceItemId); - QString vidName(vid.fileName() + "-" + id); - qDebug() << vidName; - QString thumbnail = dir.path() + "/" + vidName + ".webp"; - QFileInfo thumbnailInfo(dir.path() + "/" + vidName + ".jpg"); - qDebug() << thumbnailInfo.filePath() << "FOR" << index; - if (thumbnailInfo.exists()) { - for (int i = 0; i < rowCount(); i++) { - if (m_items[i]->serviceItemId() == serviceItemId) { - m_items[i]->setVidThumbnail("file://" + thumbnailInfo.absoluteFilePath()); - } - } - return thumbnailInfo.filePath(); - } - - - QImage image; - QString filename = video.right(video.size() - 7); - image = frameToImage(filename, 576); - if (image.isNull()) { - qDebug() << QStringLiteral("Failed to create thumbnail for file: %1").arg(video); - return "failed"; - } - - qDebug() << "dir location " << writeDir.absolutePath(); - if (!writeDir.mkpath(".")) { - qFatal("Failed to create writable location at %s", qPrintable(writeDir.absolutePath())); - } - - if (!image.save(thumbnailInfo.filePath())) { - qDebug() << QStringLiteral("Failed to save thumbnail for file: %1").arg(video); - } - - for (int i = 0; i < rowCount(); i++) { - if (m_items[i]->serviceItemId() == serviceItemId) { - m_items[i]->setVidThumbnail("file://" + thumbnailInfo.absoluteFilePath()); - } - } - // MpvObject mpv; - // mpv.loadFile(video); - // mpv.seek(5); - // mpv.screenshotToFile(thumbnail); - // mpv.quit(); - - return thumbnailInfo.filePath(); -} - -QImage SlideModelCpp::frameToImage(const QString &video, int width) -{ - QImage image; - FrameDecoder frameDecoder(video, nullptr); - if (!frameDecoder.getInitialized()) { - return image; - } - // before seeking, a frame has to be decoded - if (!frameDecoder.decodeVideoFrame()) { - return image; - } - - int secondToSeekTo = frameDecoder.getDuration() * 20 / 100; - frameDecoder.seek(secondToSeekTo); - frameDecoder.getScaledVideoFrame(width, true, image); - - return image; -} diff --git a/src/cpp/slidemodel.h b/src/cpp/slidemodel.h deleted file mode 100644 index 025d341..0000000 --- a/src/cpp/slidemodel.h +++ /dev/null @@ -1,107 +0,0 @@ -#ifndef SLIDEMODEL_H -#define SLIDEMODEL_H - -#include "serviceitem.h" -#include "slide.h" -#include -#include -#include -#include -#include -#include "cxx-qt-gen/slide_model.cxxqt.h" - -class SlideModelCpp : public QAbstractListModel { - Q_OBJECT - -public: - explicit SlideModelCpp(QObject *parent = nullptr); - - enum Roles { - TypeRole = Qt::UserRole, - TextRole, - AudioRole, - ImageBackgroundRole, - VideoBackgroundRole, - HorizontalTextAlignmentRole, - VerticalTextAlignmentRole, - FontRole, - FontSizeRole, - ServiceItemIdRole, - SlideIndexRole, - ImageCountRole, - ActiveRole, - SelectedRole, - LoopRole, - VidThumbnailRole - }; - - // Basic functionality: - int rowCount(const QModelIndex &parent = QModelIndex()) const override; - // int columnCount(const QModelIndex &parent = QModelIndex()) const override; - QVariant data(const QModelIndex &index, - int role = Qt::DisplayRole) const override; - QHash roleNames() const override; - - // Q_INVOKABLE int index(int row, int column, - // const QModelIndex &parent = QModelIndex()) const override; - // Q_INVOKABLE QModelIndex parent(const QModelIndex &index) const override; - - // Editable: - bool setData(const QModelIndex &index, const QVariant &value, - int role = Qt::EditRole) override; - Qt::ItemFlags flags(const QModelIndex &index) const override; - - // Helper methods - void addItem(Slide *item); - void insertItem(const int &index, Slide *item); - Q_INVOKABLE void addItem(const QString &text, const QString &type, - const QString &imageBackground, - const QString &videoBackground, - const QString &audio, - const QString &font, const int &fontSize, - const QString &horizontalTextAlignment, - const QString &verticalTextAlignment, - const int &serviceItemId, - const int &slideIndex, - const int &imageCount, - const bool &loop); - Q_INVOKABLE void insertItem(const int &index, const QString &text, - const QString &type, const QString &imageBackground, - const QString &videoBackground, - const QString &audio, const QString &font, - const int &fontSize, - const QString &horizontalTextAlignment, - const QString &verticalTextAlignment, - const int &serviceItemId, - const int &slideIndex, - const int &imageCount, - const bool &loop); - Q_INVOKABLE void removeItem(int index); - Q_INVOKABLE void removeItems(); - Q_INVOKABLE bool moveRows(int sourceIndex, int destIndex, int count); - Q_INVOKABLE bool moveDown(int index); - Q_INVOKABLE bool moveUp(int index); - Q_INVOKABLE QVariantMap getItem(int index) const; - Q_INVOKABLE QVariantMap getItemRust(int index, SlideModel *slidemodel) const; - Q_INVOKABLE QVariantList getItems(); - Q_INVOKABLE int findSlideIdFromServItm(int index); - Q_INVOKABLE QString thumbnailVideo(QString video, int serviceItemId, int index); - Q_INVOKABLE QString thumbnailVideoRust(QString video, int serviceItemId, int index, SlideModel *slideModel); - QImage frameToImage(const QString &video, int width); - - -public slots: - Q_INVOKABLE bool select(int id); - Q_INVOKABLE bool activate(int id); - Q_INVOKABLE bool deactivate(int id); - Q_INVOKABLE void removeServiceItem(const int &index, const ServiceItem &item); - Q_INVOKABLE void clearAll(); - void addItemFromService(const int &index, const ServiceItem &item); - void insertItemFromService(const int &index, const ServiceItem &item); - void moveRowFromService(const int &fromIndex, const int &toIndex, const ServiceItem &item); - -private: - QList m_items; -}; - -#endif // SLIDEMODEL_H diff --git a/src/cpp/songsqlmodel.cpp b/src/cpp/songsqlmodel.cpp deleted file mode 100644 index bcdef06..0000000 --- a/src/cpp/songsqlmodel.cpp +++ /dev/null @@ -1,778 +0,0 @@ -#include "songsqlmodel.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static const char *songsTableName = "songs"; - -static void createTable() -{ - if(QSqlDatabase::database().tables().contains(songsTableName)) { - return; - } - - QSqlQuery query; - if (!query.exec("CREATE TABLE IF NOT EXISTS 'songs' (" - " 'id' INTEGER NOT NULL," - " 'title' TEXT NOT NULL," - " 'lyrics' TEXT," - " 'author' TEXT," - " 'ccli' TEXT," - " 'audio' TEXT," - " 'vorder' TEXT," - " 'background' TEXT," - " 'backgroundType' TEXT," - " 'horizontalTextAlignment' TEXT," - " 'verticalTextAlignment' TEXT," - " 'font' TEXT," - " 'fontSize' INTEGER," - " PRIMARY KEY(id))")) { - qFatal("Failed to query database: %s", - qPrintable(query.lastError().text())); - } - // qDebug() << query.lastQuery(); - // qDebug() << "inserting into songs"; - - query.exec( - "INSERT INTO songs (title, lyrics, author, ccli, audio, vorder, " - "background, backgroundType, horizontalTextAlignment, verticalTextAlignment, font, fontSize) VALUES ('10,000 Reasons', '10,000 reasons " - "for my heart to sing', 'Matt Redman', '13470183', '', '', '', '', 'center', 'center', '', '')"); - // qDebug() << query.lastQuery(); - query.exec("INSERT INTO songs (title, lyrics, author, ccli, audio, vorder, " - "background, backgroundType, horizontalTextAlignment, verticalTextAlignment, font, fontSize) VALUES ('River', 'Im going down to " - "the river', 'Jordan Feliz', '13470183', '', '', '', '', 'center', 'center', '', '')"); - query.exec( - "INSERT INTO songs (title, lyrics, author, ccli, audio, vorder, " - "background, backgroundType, horizontalTextAlignment, verticalTextAlignment, font, fontSize) VALUES ('Marvelous Light', 'Into marvelous " - "light Im running', 'Chris Tomlin', '13470183', '', '', '', '', 'center', 'center', '', '')"); - - // qDebug() << query.lastQuery(); - query.exec("select * from songs"); - // qDebug() << query.lastQuery(); -} - -SongSqlModel::SongSqlModel(QObject *parent) - : QSqlTableModel(parent) -{ - // qDebug() << "creating table"; - createTable(); - setTable(songsTableName); - setEditStrategy(QSqlTableModel::OnManualSubmit); - // make sure to call select else the model won't fill - select(); -} - -QVariant SongSqlModel::data(const QModelIndex &index, int role) const { - if (role < Qt::UserRole) { - // qDebug() << role; - return QSqlTableModel::data(index, role); - } - - // qDebug() << role; - const QSqlRecord sqlRecord = record(index.row()); - return sqlRecord.value(role - Qt::UserRole); -} - -QHash SongSqlModel::roleNames() const -{ - QHash names; - names[Qt::UserRole] = "id"; - names[Qt::UserRole + 1] = "title"; - names[Qt::UserRole + 2] = "lyrics"; - names[Qt::UserRole + 3] = "author"; - names[Qt::UserRole + 4] = "ccli"; - names[Qt::UserRole + 5] = "audio"; - names[Qt::UserRole + 6] = "vorder"; - names[Qt::UserRole + 7] = "background"; - names[Qt::UserRole + 8] = "backgroundType"; - names[Qt::UserRole + 9] = "horizontalTextAlignment"; - names[Qt::UserRole + 10] = "verticalTextAlignment"; - names[Qt::UserRole + 11] = "font"; - names[Qt::UserRole + 12] = "fontSize"; - return names; -} - -void SongSqlModel::newSong() { - qDebug() << "starting to add new song"; - int rows = rowCount(); - - qDebug() << rows; - QSqlRecord recorddata = record(); - recorddata.setValue("title", "new song"); - qDebug() << recorddata; - - if (insertRecord(rows, recorddata)) { - submitAll(); - } else { - qDebug() << lastError(); - }; -} - -void SongSqlModel::deleteSong(const int &row) { - QSqlRecord recordData = record(row); - if (recordData.isEmpty()) - return; - - removeRow(row); - submitAll(); -} - -QVariantMap SongSqlModel::getSong(const int &row) { - // this whole function returns all data in the song - // regardless of it's length. When new things are added - // it will still work without refactoring. - const QModelIndex &parent = QModelIndex(); - QVariantMap data; - QSqlQuery query("select id from songs"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - const QModelIndex idx = this->index(row, 0, parent); - qDebug() << "%%%%%%%%%"; - qDebug() << row; - qDebug() << idx; - qDebug() << "%%%%%%%%%"; - if( !idx.isValid() ) - return data; - const QHash rn = roleNames(); - // qDebug() << rn; - QHashIterator it(rn); - while (it.hasNext()) { - it.next(); - qDebug() << it.key() << ":" << it.value(); - data[it.value()] = idx.data(it.key()); - } - return data; -} - -QStringList SongSqlModel::getLyricList(const int &row) { - QSqlQuery query("select id from songs"); - QList ids; - // qDebug() << row; - while (query.next()) { - ids.append(query.value(0).toInt()); - qDebug() << ids; - } - int id = ids.indexOf(row,0); - - qDebug() << "@@@@@@@@@@@@@@"; - qDebug() << id; - qDebug() << "@@@@@@@@@@@@@@"; - QSqlRecord recordData = record(row); - if (recordData.isEmpty()) { - qDebug() << "this is not a song"; - QStringList empty; - return empty; - } - - QStringList rawLyrics = recordData.value("lyrics").toString().split("\n"); - qDebug() << "HERE ARE RAW LYRICS: " << rawLyrics; - QStringList lyrics; - - QStringList vorder = recordData.value("vorder").toString().split(" "); - // qDebug() << vorder; - - QStringList keywords = {"Verse 1", "Verse 2", "Verse 3", "Verse 4", - "Verse 5", "Verse 6", "Verse 7", "Verse 8", - "Chorus 1", "Chorus 2", "Chorus 3", "Chorus 4", - "Bridge 1", "Bridge 2", "Bridge 3", "Bridge 4", - "Intro 1", "Intro 2", "Ending 1", "Ending 2", - "Other 1", "Other 2", "Other 3", "Other 4"}; - - bool firstItem = true; - QString verse; - QString vtitle; - QString line; - QMultiMap verses; - - //TODO make sure to split empty line in verse into two slides - - // This first function pulls out each verse into our verses map - // foreach (line, rawLyrics) { - for (int i = 0; i < rawLyrics.length(); ++i) { - // qDebug() << "##########################"; - // qDebug() << rawLyrics[i]; - // qDebug() << rawLyrics.length(); - // qDebug() << i; - // qDebug() << "##########################"; - if (firstItem) { - if (keywords.contains(rawLyrics[i])) { - // qDebug() << "!!!!THIS IS FIRST LINE!!!!!"; - // qDebug() << rawLyrics[i]; - firstItem = false; - vtitle = rawLyrics[i]; - continue; - } - } else if (keywords.contains(rawLyrics[i])) { - // qDebug() << "!!!!THIS IS A VTITLE!!!!!"; - // qDebug() << verse; - // qDebug() << rawLyrics[i]; - if (verse.contains("\n\n")) { - verse = verse.trimmed(); - // qDebug() << "THIS IS A EMPTY SLIDE!" << verse; - QStringList multiverses = verse.split("\n\n"); - foreach (verse, multiverses) { - verses.insert(vtitle, verse); - // qDebug() << verse; - } - verse.clear(); - multiverses.clear(); - vtitle = rawLyrics[i]; - continue; - } - verses.insert(vtitle, verse); - verse.clear(); - vtitle = rawLyrics[i]; - continue; - } else if (i + 1 == rawLyrics.length()) { - // qDebug() << "!!!!LAST LINE!!!!!"; - - verse.append(rawLyrics[i].trimmed() + "\n"); - if (verse.contains("\n\n")) { - verse = verse.trimmed(); - // qDebug() << "THIS IS A EMPTY SLIDE!" << verse; - QStringList multiverses = verse.split("\n\n"); - foreach (verse, multiverses) { - verses.insert(vtitle, verse); - // qDebug() << verse; - } - break; - } - - verses.insert(vtitle, verse); - // qDebug() << "&&&&&&&&&&&&"; - // qDebug() << "This is final line"; - // qDebug() << "and has been inserted"; - // qDebug() << verses.values(vtitle); - // qDebug() << "&&&&&&&&&&&&"; - break; - } - // qDebug() << "THIS RAWLYRICS[I]"; - // qDebug() << rawLyrics[i]; - // qDebug() << "THIS VTITLE"; - // qDebug() << vtitle; - verse.append(rawLyrics[i].trimmed() + "\n"); - // qDebug() << verse; - // qDebug() << "APPENDED VERSE"; - } - // qDebug() << verses; - - // let's check to see if there is a verse order, if not return the list given - if (vorder.first().isEmpty()) { - // qDebug() << "NO VORDER"; - foreach (verse, verses) { - // qDebug() << verse; - lyrics.append(verse); - } - // qDebug() << lyrics; - return lyrics; - } - - // this function appends the verse that matches the verse order from the map - // first we run through every line and check to see if the line matches - // an item in vorder, then we append lyrics from the verse that matches - // the verse map we created earlier. It's a multi map so we need to append - // them in reverse as they are added in last in first out order. - foreach (const QString &vstr, vorder) { - foreach (line, rawLyrics) { - if (line.startsWith(vstr.at(0)) && line.endsWith(vstr.at(1))) { - qDebug() << "**********************"; - qDebug() << vstr; - qDebug() << line; - qDebug() << "**********************"; - QList values = verses.values(line); - for (int i = values.size(); i > 0;) - lyrics.append(values.at(--i)); - } - } - } - - // qDebug() << lyrics; - - return lyrics; -} - -int SongSqlModel::id() const { - return m_id; -} - -QString SongSqlModel::title() const { - return m_title; -} - -void SongSqlModel::setTitle(const QString &title) { - if (title == m_title) - return; - - m_title = title; - - select(); - emit titleChanged(); -} - -// This function is for updating the lyrics from outside the delegate -void SongSqlModel::updateTitle(const int &row, const QString &title) { - qDebug() << "Row is " << row; - // QSqlQuery query("select id from songs"); - // QList ids; - // while (query.next()) { - // ids.append(query.value(0).toInt()); - // // qDebug() << ids; - // } - // int id = ids.indexOf(row,0); - - QSqlQuery query("select id from songs"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - qDebug() << rowdata; - rowdata.setValue("title", title); - setRecord(id, rowdata); - qDebug() << rowdata; - submitAll(); - emit titleChanged(); -} - -QString SongSqlModel::author() const { - return m_author; -} - -void SongSqlModel::setAuthor(const QString &author) { - if (author == m_author) - return; - - m_author = author; - - select(); - emit authorChanged(); -} - -// This function is for updating the lyrics from outside the delegate -void SongSqlModel::updateAuthor(const int &row, const QString &author) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from songs"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - rowdata.setValue("author", author); - setRecord(id, rowdata); - submitAll(); - emit authorChanged(); -} - -QString SongSqlModel::lyrics() const { - return m_lyrics; -} - -void SongSqlModel::setLyrics(const QString &lyrics) { - if (lyrics == m_lyrics) - return; - - m_lyrics = lyrics; - - select(); - emit lyricsChanged(); -} - -// This function is for updating the lyrics from outside the delegate -void SongSqlModel::updateLyrics(const int &row, const QString &lyrics) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from songs"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - qDebug() << lyrics; - rowdata.setValue("lyrics", lyrics); - qDebug() << rowdata.value("lyrics"); - setRecord(id, rowdata); - submitAll(); - emit lyricsChanged(); -} - -QString SongSqlModel::ccli() const { - return m_ccli; -} - -void SongSqlModel::setCcli(const QString &ccli) { - if (ccli == m_ccli) - return; - - m_ccli = ccli; - - select(); - emit ccliChanged(); -} - -// This function is for updating the lyrics from outside the delegate -void SongSqlModel::updateCcli(const int &row, const QString &ccli) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from songs"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - rowdata.setValue("ccli", ccli); - setRecord(id, rowdata); - submitAll(); - emit ccliChanged(); -} - -QString SongSqlModel::audio() const { - return m_audio; -} - -void SongSqlModel::setAudio(const QString &audio) { - if (audio == m_audio) - return; - - m_audio = audio; - - select(); - emit audioChanged(); -} - -// This function is for updating the lyrics from outside the delegate -void SongSqlModel::updateAudio(const int &row, const QString &audio) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from songs"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - rowdata.setValue("audio", audio); - setRecord(id, rowdata); - submitAll(); - emit audioChanged(); -} - -QString SongSqlModel::vorder() const { return m_vorder; } - -void SongSqlModel::setVerseOrder(const QString &vorder) { - if (vorder == m_vorder) - return; - - m_vorder = vorder; - - select(); - emit vorderChanged(); -} - -// This function is for updating the lyrics from outside the delegate -void SongSqlModel::updateVerseOrder(const int &row, const QString &vorder) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from songs"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - rowdata.setValue("vorder", vorder); - setRecord(id, rowdata); - submitAll(); - emit vorderChanged(); -} - -QString SongSqlModel::background() const { return m_background; } - -void SongSqlModel::setBackground(const QString &background) { - if (background == m_background) - return; - - m_background = background; - - select(); - emit backgroundChanged(); -} - -// This function is for updating the lyrics from outside the delegate -void SongSqlModel::updateBackground(const int &row, const QString &background) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from songs"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - rowdata.setValue("background", background); - setRecord(id, rowdata); - submitAll(); - emit backgroundChanged(); -} - -QString SongSqlModel::backgroundType() const { return m_backgroundType; } - -void SongSqlModel::setBackgroundType(const QString &backgroundType) { - if (backgroundType == m_backgroundType) - return; - - m_backgroundType = backgroundType; - - select(); - emit backgroundTypeChanged(); -} - -// This function is for updating the lyrics from outside the delegate -void SongSqlModel::updateBackgroundType(const int &row, const QString &backgroundType) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from songs"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - rowdata.setValue("backgroundType", backgroundType); - setRecord(id, rowdata); - submitAll(); - emit backgroundTypeChanged(); -} - -QString SongSqlModel::horizontalTextAlignment() const { - return m_horizontalTextAlignment; -} - -void SongSqlModel::setHorizontalTextAlignment(const QString &horizontalTextAlignment) { - if (horizontalTextAlignment == m_horizontalTextAlignment) - return; - - m_horizontalTextAlignment = horizontalTextAlignment; - - select(); - emit horizontalTextAlignmentChanged(); -} - -// This function is for updating the lyrics from outside the delegate -void SongSqlModel::updateHorizontalTextAlignment(const int &row, const QString &horizontalTextAlignment) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from songs"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - qDebug() << rowdata; - rowdata.setValue("horizontalTextAlignment", horizontalTextAlignment); - setRecord(id, rowdata); - qDebug() << rowdata; - submitAll(); - emit horizontalTextAlignmentChanged(); -} - -QString SongSqlModel::verticalTextAlignment() const { - return m_verticalTextAlignment; -} - -void SongSqlModel::setVerticalTextAlignment(const QString &verticalTextAlignment) { - if (verticalTextAlignment == m_verticalTextAlignment) - return; - - m_verticalTextAlignment = verticalTextAlignment; - - select(); - emit verticalTextAlignmentChanged(); -} - -// This function is for updating the lyrics from outside the delegate -void SongSqlModel::updateVerticalTextAlignment(const int &row, const QString &verticalTextAlignment) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from songs"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - qDebug() << rowdata; - rowdata.setValue("verticalTextAlignment", verticalTextAlignment); - setRecord(id, rowdata); - qDebug() << rowdata; - submitAll(); - emit verticalTextAlignmentChanged(); -} - -QString SongSqlModel::font() const { - return m_font; -} - -void SongSqlModel::setFont(const QString &font) { - if (font == m_font) - return; - - m_font = font; - - select(); - emit fontChanged(); -} - -// This function is for updating the lyrics from outside the delegate -void SongSqlModel::updateFont(const int &row, const QString &font) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from songs"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - qDebug() << rowdata; - rowdata.setValue("font", font); - setRecord(id, rowdata); - qDebug() << rowdata; - submitAll(); - emit fontChanged(); -} - -int SongSqlModel::fontSize() const { - return m_fontSize; -} - -void SongSqlModel::setFontSize(const int &fontSize) { - if (fontSize == m_fontSize) - return; - - m_fontSize = fontSize; - - select(); - emit fontSizeChanged(); -} - -// This function is for updating the lyrics from outside the delegate -void SongSqlModel::updateFontSize(const int &row, const int &fontSize) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from songs"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - qDebug() << rowdata; - rowdata.setValue("fontSize", fontSize); - setRecord(id, rowdata); - qDebug() << rowdata; - submitAll(); - emit fontSizeChanged(); -} - -QModelIndex SongSqlModel::idx(int row) { - QModelIndex idx = index(row, 0); - // qDebug() << idx; - return idx; -} - -// SongProxyModel - -SongProxyModel::SongProxyModel(QObject *parent) - :QSortFilterProxyModel(parent) -{ - m_songModel = new SongModel; - m_songModel->setup(); - // m_selectionModel = new QItemSelectionModel; - // m_selectionModel->setModel(this); - setSourceModel(m_songModel); - setDynamicSortFilter(true); - setFilterRole(Qt::UserRole + 1); - setFilterCaseSensitivity(Qt::CaseInsensitive); -} - -SongModel *SongProxyModel::songModel() { - return m_songModel; -} - -QModelIndex SongProxyModel::idx(int row) { - QModelIndex idx = index(row, 0); - // qDebug() << idx; - return idx; -} - -QModelIndex SongProxyModel::modelIndex(int row) { - QModelIndex idx = m_songModel->index(mapToSource(index(row, 0)).row()); - return idx; -} - -QStringList SongProxyModel::getLyricList(const int &row) { - QStringList lyrics = m_songModel->getLyricList(mapToSource(index(row, 0)).row()); - return lyrics; -} - -QVariantMap SongProxyModel::getSong(const int &row) { - QVariantMap song = m_songModel->getItem(mapToSource(index(row, 0)).row()); - qDebug() << song; - return song; -} - -void SongProxyModel::newSong() { - m_songModel->newSong(); -} - -void SongProxyModel::deleteSong(const int &row) { - auto model = qobject_cast(sourceModel()); - model->removeItem(row); -} - -void SongProxyModel::deleteSongs(const QVector &rows) { - auto model = qobject_cast(sourceModel()); - qDebug() << "DELETING!!!!!!!!!!!!!!!!!!!!!!!" << rows; - for (int i = rows.size() - 1; i >= 0; i--) { - qDebug() << "deleting" << rows.at(i); - model->removeItem(rows.at(i)); - } -} - diff --git a/src/cpp/songsqlmodel.h b/src/cpp/songsqlmodel.h deleted file mode 100644 index 929cb02..0000000 --- a/src/cpp/songsqlmodel.h +++ /dev/null @@ -1,152 +0,0 @@ -#ifndef SONGSQLMODEL_H -#define SONGSQLMODEL_H - -#include -#include -#include -#include -#include -#include -#include "cxx-qt-gen/song_model.cxxqt.h" - -class SongSqlModel : public QSqlTableModel -{ - Q_OBJECT - Q_PROPERTY(int id READ id) - Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) - Q_PROPERTY(QString lyrics READ lyrics WRITE setLyrics NOTIFY lyricsChanged) - Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged) - Q_PROPERTY(QString ccli READ ccli WRITE setCcli NOTIFY ccliChanged) - Q_PROPERTY(QString audio READ audio WRITE setAudio NOTIFY audioChanged) - Q_PROPERTY(QString vorder READ vorder WRITE setVerseOrder NOTIFY vorderChanged) - Q_PROPERTY(QString background READ background WRITE setBackground NOTIFY backgroundChanged) - Q_PROPERTY(QString backgroundType READ backgroundType WRITE setBackgroundType NOTIFY backgroundTypeChanged) - Q_PROPERTY(QString horizontalTextAlignment READ horizontalTextAlignment WRITE setHorizontalTextAlignment NOTIFY horizontalTextAlignmentChanged) - Q_PROPERTY(QString verticalTextAlignment READ verticalTextAlignment WRITE setVerticalTextAlignment NOTIFY verticalTextAlignmentChanged) - Q_PROPERTY(QString font READ font WRITE setFont NOTIFY fontChanged) - Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) - QML_ELEMENT - -public: - SongSqlModel(QObject *parent = 0); - - int id() const; - QString title() const; - QString lyrics() const; - QString author() const; - QString ccli() const; - QString audio() const; - QString vorder() const; - QString background() const; - QString backgroundType() const; - QString horizontalTextAlignment() const; - QString verticalTextAlignment() const; - QString font() const; - int fontSize() const; - - void setTitle(const QString &title); - void setLyrics(const QString &lyrics); - void setAuthor(const QString &author); - void setCcli(const QString &ccli); - void setAudio(const QString &audio); - void setVerseOrder(const QString &vorder); - void setBackground(const QString &background); - void setBackgroundType(const QString &backgroundType); - void setHorizontalTextAlignment(const QString &horizontalTextAlignment); - void setVerticalTextAlignment(const QString &verticalTextAlignment); - void setFont(const QString &font); - void setFontSize(const int &fontSize); - - Q_INVOKABLE void updateTitle(const int &row, const QString &title); - Q_INVOKABLE void updateLyrics(const int &row, const QString &lyrics); - Q_INVOKABLE void updateAuthor(const int &row, const QString &author); - Q_INVOKABLE void updateCcli(const int &row, const QString &ccli); - Q_INVOKABLE void updateAudio(const int &row, const QString &audio); - Q_INVOKABLE void updateVerseOrder(const int &row, const QString &vorder); - Q_INVOKABLE void updateBackground(const int &row, const QString &background); - Q_INVOKABLE void updateBackgroundType(const int &row, const QString &backgroundType); - Q_INVOKABLE void updateHorizontalTextAlignment(const int &row, - const QString &horizontalTextAlignment); - Q_INVOKABLE void updateVerticalTextAlignment(const int &row, - const QString &horizontalTextAlignment); - Q_INVOKABLE void updateFont(const int &row, const QString &font); - Q_INVOKABLE void updateFontSize(const int &row, const int &fontSize); - Q_INVOKABLE QModelIndex idx(int row); - - Q_INVOKABLE void newSong(); - Q_INVOKABLE void deleteSong(const int &row); - Q_INVOKABLE QVariantMap getSong(const int &row); - Q_INVOKABLE QStringList getLyricList(const int &row); - - QVariant data(const QModelIndex &index, int role) const override; - QHash roleNames() const override; - -signals: - void titleChanged(); - void lyricsChanged(); - void authorChanged(); - void ccliChanged(); - void audioChanged(); - void vorderChanged(); - void backgroundChanged(); - void backgroundTypeChanged(); - void horizontalTextAlignmentChanged(); - void verticalTextAlignmentChanged(); - void fontChanged(); - void fontSizeChanged(); - -private: - int m_id; - QString m_title; - QString m_lyrics; - QString m_author; - QString m_ccli; - QString m_audio; - QString m_vorder; - QString m_background; - QString m_backgroundType; - QString m_horizontalTextAlignment; - QString m_verticalTextAlignment; - QString m_font; - int m_fontSize; -}; - -class SongProxyModel : public QSortFilterProxyModel -{ - Q_OBJECT - Q_PROPERTY(SongModel *songModel READ songModel) - // Q_PROPERTY(bool hasSelection READ hasSelection NOTIFY selectedChanged) - -public: - explicit SongProxyModel(QObject *parent = nullptr); - ~SongProxyModel() = default; - - SongModel *songModel(); - Q_INVOKABLE QModelIndex idx(int row); - Q_INVOKABLE QModelIndex modelIndex(int row); - // Q_INVOKABLE bool selected(const int &row); - - // QVariant data(const QModelIndex &index, int role) const override; - // QHash roleNames() const override; - -public slots: - Q_INVOKABLE QVariantMap getSong(const int &row); - Q_INVOKABLE void newSong(); - Q_INVOKABLE void deleteSong(const int &row); - Q_INVOKABLE void deleteSongs(const QVector &rows); - Q_INVOKABLE QStringList getLyricList(const int &row); - // Q_INVOKABLE void select(int row); - // Q_INVOKABLE void selectSongs(int row); - // Q_INVOKABLE bool setSelected(const int &row, const bool &select); - // Q_INVOKABLE bool hasSelection(); - -signals: - // Q_INVOKABLE void selectedChanged(bool selected); - -private: - SongModel *m_songModel; - // QItemSelectionModel *m_selectionModel; - // bool m_selected; -}; - -#endif //SONGSQLMODEL_H diff --git a/src/cpp/thumbnail.cpp b/src/cpp/thumbnail.cpp deleted file mode 100644 index 3ec4f22..0000000 --- a/src/cpp/thumbnail.cpp +++ /dev/null @@ -1,159 +0,0 @@ -#include "thumbnail.h" -#include - -Thumbnail::Thumbnail(QObject *parent) - : QObject{parent} -{ - -} - -Thumbnail::Thumbnail(const QString &owner, const QString &type, QObject *parent) - : QObject(parent),m_owner(owner),m_type(type) -{ - -} - -Thumbnail::Thumbnail(const QString &owner, const QString &type, const QString &background, - const QString &backgroundType, QObject *parent) - : QObject(parent),m_owner(owner),m_type(type),m_background(background), - m_backgroundType(backgroundType) -{ - -} - -Thumbnail::Thumbnail(const QString &owner, const QString &type, const QString &background, - const QString &backgroundType, const QStringList &text, - QObject *parent) - : QObject(parent),m_owner(owner),m_type(type),m_background(background), - m_backgroundType(backgroundType),m_text(text) -{ - -} - -Thumbnail::Thumbnail(const QString &owner, const QString &type, const QString &background, - const QString &backgroundType, const QStringList &text, - const QString &songVerse, QObject *parent) - : QObject(parent),m_owner(owner),m_type(type),m_background(background), - m_backgroundType(backgroundType),m_text(text),m_songVerse(songVerse) -{ - -} - -Thumbnail::Thumbnail(const QString &owner, const QString &type, const QString &background, - const QString &backgroundType, const QStringList &text, - const QString &font, const int &fontSize, const QString &songVerse - QObject *parent) - : QObject(parent),m_owner(owner),m_type(type),m_background(background), - m_backgroundType(backgroundType),m_text(text),m_font(font),m_fontSize(fontSize), - m_songVerse(songVerse) -{ - -} - -QString Thumbnail::owner() const { - return m_owner; -} - -QString Thumbnail::type() const { - return m_type; -} - -QString Thumbnail::songVerse() const { - return m_songVerse; -} - -QString Thumbnail::background() const -{ - return m_background; -} - -QString Thumbnail::backgroundType() const -{ - return m_backgroundType; -} - -QStringList Thumbnail::text() const -{ - return m_text; -} - -QString Thumbnail::font() const { - return m_font; -} - -int Thumbnail::fontSize() const { - return m_fontSize; -} - -void Thumbnail::setOwner(QString owner) -{ - if (m_owner == owner) - return; - - m_owner = owner; - emit ownerChanged(m_owner); -} - -void Thumbnail::setType(QString type) -{ - if (m_type == type) - return; - - m_type = type; - emit typeChanged(m_type); -} - -void Thumbnail::setSongVerse(QString songVerse) -{ - if (m_songVerse == songVerse) - return; - - m_songVerse = songVerse; - emit songVerseChanged(m_songVerse); -} - -void Thumbnail::setBackground(QString background) -{ - if (m_background == background) - return; - - m_background = background; - emit backgroundChanged(m_background); -} - -void Thumbnail::setBackgroundType(QString backgroundType) -{ - if (m_backgroundType == backgroundType) - return; - - m_backgroundType = backgroundType; - emit backgroundTypeChanged(m_backgroundType); -} - -void Thumbnail::setText(QStringList text) -{ - if (m_text == text) - return; - - m_text = text; - emit textChanged(m_text); - -} - -void Thumbnail::setFont(QString font) -{ - if (m_font == font) - return; - - m_font = font; - emit fontChanged(m_font); -} - -void Thumbnail::setFontSize(int fontSize) -{ - if (m_fontSize == fontSize) - return; - - m_fontSize = fontSize; - emit fontSizeChanged(m_fontSize); -} diff --git a/src/cpp/thumbnail.h b/src/cpp/thumbnail.h deleted file mode 100644 index 859e77f..0000000 --- a/src/cpp/thumbnail.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef THUMBNAIL_H -#define THUMBNAIL_H - -#include -#include - -class Thumbnail : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString owner READ owner WRITE setOwner NOTIFY ownerChanged) - Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged) - Q_PROPERTY(QString songVerse READ songVerse WRITE setSongVerse NOTIFY songVerseChanged) - Q_PROPERTY(QString background READ background WRITE setBackground NOTIFY backgroundChanged) - Q_PROPERTY(QString backgroundType READ backgroundType WRITE setBackgroundType NOTIFY backgroundTypeChanged) - Q_PROPERTY(QStringList text READ text WRITE setText NOTIFY textChanged) - Q_PROPERTY(QString font READ font WRITE setFont NOTIFY fontChanged) - Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) - -public: - explicit Thumbnail(QObject *parent = nullptr); - Thumbnail(const QString &owner, const QString &type, QObject * parent = nullptr); - Thumbnail(const QString &owner, const QString &type, const QString &background, - const QString &backgroundType, QObject * parent = nullptr); - Thumbnail(const QString &owner, const QString &type, const QString &background, - const QString &backgroundType, const QStringList &text, - QObject * parent = nullptr); - Thumbnail(const QString &owner, const QString &type, const QString &background, - const QString &backgroundType, const QStringList &text, - const QString &songVerse, QObject * parent = nullptr); - Thumbnail(const QString &owner, const QString &type, const QString &background, - const QString &backgroundType, const QStringList &text, - const QString &songVerse, const QString &font, - const int &fontSize, QObject * parent = nullptr); - - QString owner() const; - QString type() const; - QString songVerse() const; - QString background() const; - QString backgroundType() const; - QStringList text() const; - QString font() const; - int fontSize() const; - - void setOwner(QString owner); - void setType(QString type); - void setSongVerse(QString songVerse); - void setBackground(QString background); - void setBackgroundType(QString backgroundType); - void setText(QStringList text); - void setFont(QString font); - void setFontSize(int fontSize); - -signals: - void ownerChanged(QString owner); - void typeChanged(QString type); - void songVerseChanged(QString songVerse); - void backgroundChanged(QString background); - void backgroundTypeChanged(QString backgroundType); - void textChanged(QStringList text); - void fontChanged(QString font); - void fontSizeChanged(int fontSize); - -private: - QString m_owner; - QString m_type; - QString m_songVerse; - QString m_background; - QString m_backgroundType; - QStringList m_text; - QString m_font; - int m_fontSize; -}; - -#endif // THUMBNAIL_H diff --git a/src/cpp/videosqlmodel.cpp b/src/cpp/videosqlmodel.cpp deleted file mode 100644 index b34abda..0000000 --- a/src/cpp/videosqlmodel.cpp +++ /dev/null @@ -1,394 +0,0 @@ -#include "videosqlmodel.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static const char *videosTableName = "videos"; - -static void createVideoTable() -{ - if(QSqlDatabase::database().tables().contains(videosTableName)) { - return; - } - - QSqlQuery query; - if (!query.exec("CREATE TABLE IF NOT EXISTS 'videos' (" - " 'id' INTEGER NOT NULL," - " 'title' TEXT NOT NULL," - " 'filePath' TEXT NOT NULL," - " 'startTime' REAL," - " 'endTime' REAL," - " 'loop' BOOLEAN NOT NULL DEFAULT 0," - " PRIMARY KEY(id))")) { - qFatal("Failed to query database: %s", - qPrintable(query.lastError().text())); - } - qDebug() << query.lastQuery(); - qDebug() << "inserting into videos"; - - query.exec("INSERT INTO videos (title, filePath) VALUES ('The Test', '/home/chris/nextcloud/tfc/openlp/videos/test.mp4')"); - qDebug() << query.lastQuery(); - query.exec("INSERT INTO videos (title, filePath) VALUES ('Sabbath', '/home/chris/nextcloud/tfc/openlp/videos/Sabbath.mp4')"); - - query.exec("select * from videos"); - qDebug() << query.lastQuery(); -} - -VideoSqlModel::VideoSqlModel(QObject *parent) : QSqlTableModel(parent) { - qDebug() << "creating video table"; - createVideoTable(); - - QSqlQuery query("PRAGMA table_info(videos)"); - while (query.next()) { - QString title = query.value(1).toString(); - qDebug() << title; - } - - setTable(videosTableName); - setEditStrategy(QSqlTableModel::OnManualSubmit); - // make sure to call select else the model won't fill - select(); -} - -QVariant VideoSqlModel::data(const QModelIndex &index, int role) const { - if (role < Qt::UserRole) { - return QSqlTableModel::data(index, role); - } - - // qDebug() << role; - const QSqlRecord sqlRecord = record(index.row()); - return sqlRecord.value(role - Qt::UserRole); -} - -QHash VideoSqlModel::roleNames() const -{ - QHash names; - names[Qt::UserRole] = "id"; - names[Qt::UserRole + 1] = "title"; - names[Qt::UserRole + 2] = "filePath"; - names[Qt::UserRole + 3] = "startTime"; - names[Qt::UserRole + 4] = "endTime"; - names[Qt::UserRole + 5] = "loop"; - return names; -} - -void VideoSqlModel::newVideo(const QUrl &filePath) { - qDebug() << "adding new video"; - int rows = rowCount(); - - qDebug() << rows; - QSqlRecord recordData = record(); - QFileInfo fileInfo = filePath.toString(); - QString title = fileInfo.baseName(); - recordData.setValue("title", title); - recordData.setValue("filePath", filePath); - recordData.setValue("loop", 0); - - if (insertRecord(rows, recordData)) { - submitAll(); - } else { - qDebug() << lastError(); - }; -} - -void VideoSqlModel::deleteVideo(const int &row) { - const QModelIndex parent = QModelIndex(); - QSqlRecord recordData = record(row); - if (recordData.isEmpty()) - return; - // emit beginRemoveRows(parent, row, row); - // emit beginResetModel(); - removeRow(row); - submitAll(); - // emit endRemoveRows(); - // emit endResetModel(); -} - -int VideoSqlModel::id() const { - return m_id; -} - -QString VideoSqlModel::title() const { - return m_title; -} - -void VideoSqlModel::setTitle(const QString &title) { - if (title == m_title) - return; - - m_title = title; - - select(); - emit titleChanged(); -} - -// This function is for updating the title from outside the delegate -void VideoSqlModel::updateTitle(const int &row, const QString &title) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from videos"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - qDebug() << rowdata; - rowdata.setValue("title", title); - setRecord(id, rowdata); - qDebug() << rowdata; - submitAll(); - emit titleChanged(); -} - -QUrl VideoSqlModel::filePath() const { - return m_filePath; -} - -void VideoSqlModel::setFilePath(const QUrl &filePath) { - if (filePath == m_filePath) - return; - - m_filePath = filePath; - - select(); - emit filePathChanged(); -} - -// This function is for updating the filepath from outside the delegate -void VideoSqlModel::updateFilePath(const int &row, const QUrl &filePath) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from videos"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - qDebug() << rowdata; - rowdata.setValue("filePath", filePath); - setRecord(id, rowdata); - qDebug() << rowdata; - submitAll(); - emit filePathChanged(); -} - - -int VideoSqlModel::startTime() const { - return m_startTime; -} - -void VideoSqlModel::setStartTime(const int &startTime) { - if (startTime == m_startTime) - return; - - m_startTime = startTime; - - select(); - emit startTimeChanged(); -} - -// This function is for updating the title from outside the delegate -void VideoSqlModel::updateStartTime(const int &row, const int &startTime) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from videos"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - qDebug() << rowdata; - rowdata.setValue("startTime", startTime); - setRecord(id, rowdata); - qDebug() << rowdata; - submitAll(); - emit startTimeChanged(); -} - -int VideoSqlModel::endTime() const { - return m_endTime; -} - -void VideoSqlModel::setEndTime(const int &endTime) { - if (endTime == m_endTime) - return; - - m_endTime = endTime; - - select(); - emit endTimeChanged(); -} - -// This function is for updating the title from outside the delegate -void VideoSqlModel::updateEndTime(const int &row, const int &endTime) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from videos"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - qDebug() << rowdata; - rowdata.setValue("endTime", endTime); - setRecord(id, rowdata); - qDebug() << rowdata; - submitAll(); - emit endTimeChanged(); -} - -bool VideoSqlModel::loop() const { - return m_loop; -} - -void VideoSqlModel::setLoop(const bool &loop) { - if (loop == m_loop) - return; - - m_loop = loop; - - select(); - emit loopChanged(); -} - -// This function is for updating looping from outside the delegate -void VideoSqlModel::updateLoop(const int &row, const bool &loop) { - qDebug() << "Row is " << row; - QSqlQuery query("select id from videos"); - QList ids; - while (query.next()) { - ids.append(query.value(0).toInt()); - // qDebug() << ids; - } - int id = ids.indexOf(row,0); - - QSqlRecord rowdata = record(id); - qDebug() << rowdata; - rowdata.setValue("loop", loop); - setRecord(id, rowdata); - qDebug() << rowdata; - submitAll(); - emit loopChanged(); -} - -QVariantMap VideoSqlModel::getVideo(const int &row) { - // qDebug() << "Row we are getting is " << row; - // QVariantList video; - // QSqlRecord rec = record(row); - // qDebug() << rec.value("title"); - // video.append(rec.value("title")); - // video.append(rec.value("filePath")); - // return video; - - QVariantMap data; - const QModelIndex idx = this->index(row,0); - // qDebug() << idx; - if( !idx.isValid() ) - return data; - const QHash rn = roleNames(); - // qDebug() << rn; - QHashIterator it(rn); - while (it.hasNext()) { - it.next(); - qDebug() << it.key() << ":" << it.value(); - data[it.value()] = idx.data(it.key()); - } - return data; - -} - -// VideoProxyModel - -VideoProxyModel::VideoProxyModel(QObject *parent) - :QSortFilterProxyModel(parent) -{ - m_videoModel = new VideoModel(); - m_videoModel->setup(); - setSourceModel(m_videoModel); - setDynamicSortFilter(true); - setFilterRole(Qt::UserRole + 1); - setFilterCaseSensitivity(Qt::CaseInsensitive); -} - -VideoModel *VideoProxyModel::videoModel() { - return m_videoModel; -} - -QModelIndex VideoProxyModel::idx(int row) { - QModelIndex idx = index(row, 0); - // qDebug() << idx; - return idx; -} - -QVariantMap VideoProxyModel::getVideo(const int &row) { - auto model = qobject_cast(sourceModel()); - QVariantMap video = model->getItem(mapToSource(index(row, 0)).row()); - return video; -} - -void VideoProxyModel::deleteVideo(const int &row) { - auto model = qobject_cast(sourceModel()); - model->removeItem(mapToSource(index(row,0)).row()); -} - -void VideoProxyModel::deleteVideos(const QVector &rows) { - auto model = qobject_cast(sourceModel()); - qDebug() << "DELETING!!!!!!!!!!!!!!!!!!!!!!!" << rows; - for (int i = rows.size() - 1; i >= 0; i--) { - qDebug() << "deleting" << rows.at(i); - model->removeItem(rows.at(i)); - } -} - -bool VideoProxyModel::updateLoop(int row, bool value) { - auto model = qobject_cast(sourceModel()); - qDebug() << "THIS:" << row; - bool ret = model->updateLoop(row, value); - return ret; -} - -bool VideoProxyModel::updateStartTime(int row, float value) { - auto model = qobject_cast(sourceModel()); - bool ret = model->updateStartTime(row, value); - return ret; -} - -bool VideoProxyModel::updateEndTime(int row, float value) { - auto model = qobject_cast(sourceModel()); - bool ret = model->updateEndTime(row, value); - return ret; -} - -bool VideoProxyModel::updateTitle(int row, QString value) { - auto model = qobject_cast(sourceModel()); - bool ret = model->updateTitle(row, value); - return ret; -} - -bool VideoProxyModel::updatePath(int row, QString value) { - auto model = qobject_cast(sourceModel()); - bool ret = model->updatePath(row, value); - return ret; -} diff --git a/src/cpp/videosqlmodel.h b/src/cpp/videosqlmodel.h deleted file mode 100644 index a39daa0..0000000 --- a/src/cpp/videosqlmodel.h +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef VIDEOSQLMODEL_H -#define VIDEOSQLMODEL_H - -#include -#include -#include -#include -#include -#include -#include -#include "cxx-qt-gen/video_model.cxxqt.h" - -class VideoSqlModel : public QSqlTableModel -{ - Q_OBJECT - Q_PROPERTY(int id READ id) - Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) - Q_PROPERTY(QUrl filePath READ filePath WRITE setFilePath NOTIFY filePathChanged) - Q_PROPERTY(int startTime READ startTime WRITE setStartTime NOTIFY startTimeChanged) - Q_PROPERTY(int endTime READ endTime WRITE setEndTime NOTIFY endTimeChanged) - Q_PROPERTY(bool loop READ loop WRITE setLoop NOTIFY loopChanged) - QML_ELEMENT - -public: - VideoSqlModel(QObject *parent = 0); - - int id() const; - QString title() const; - QUrl filePath() const; - int startTime() const; - int endTime() const; - bool loop() const; - - void setTitle(const QString &title); - void setFilePath(const QUrl &filePath); - void setStartTime(const int &startTime); - void setEndTime(const int &endTime); - void setLoop(const bool &loop); - - Q_INVOKABLE void updateTitle(const int &row, const QString &title); - Q_INVOKABLE void updateFilePath(const int &row, const QUrl &filePath); - Q_INVOKABLE void updateStartTime(const int &row, const int &startTime); - Q_INVOKABLE void updateEndTime(const int &row, const int &endTime); - Q_INVOKABLE void updateLoop(const int &row, const bool &loop); - - Q_INVOKABLE void newVideo(const QUrl &filePath); - Q_INVOKABLE void deleteVideo(const int &row); - Q_INVOKABLE QVariantMap getVideo(const int &row); - - QVariant data(const QModelIndex &index, int role) const override; - QHash roleNames() const override; - -signals: - void titleChanged(); - void filePathChanged(); - void loopChanged(); - void startTimeChanged(); - void endTimeChanged(); - -private: - int m_id; - QString m_title; - QUrl m_filePath; - int m_startTime; - int m_endTime; - bool m_loop; -}; - -class VideoProxyModel : public QSortFilterProxyModel -{ - Q_OBJECT - Q_PROPERTY(VideoModel *videoModel READ videoModel) - -public: - explicit VideoProxyModel(QObject *parent = nullptr); - ~VideoProxyModel() = default; - - VideoModel *videoModel(); - Q_INVOKABLE QModelIndex idx(int row); - -public slots: - Q_INVOKABLE QVariantMap getVideo(const int &row); - Q_INVOKABLE void deleteVideo(const int &row); - Q_INVOKABLE void deleteVideos(const QVector &row); - Q_INVOKABLE bool updateLoop(int row, bool value); - Q_INVOKABLE bool updateTitle(int row, QString value); - Q_INVOKABLE bool updatePath(int row, QString value); - Q_INVOKABLE bool updateStartTime(int row, float value); - Q_INVOKABLE bool updateEndTime(int row, float value); - -private: - VideoModel *m_videoModel; -}; - -#endif //VIDEOSQLMODEL_H diff --git a/src/main.cpp b/src/main.cpp index 98b2c56..767aeb2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,28 +3,19 @@ #include #include #include -#include #include #include #include #include -// #include #include #include -// #include -// #include -// #include #include - #include #include #include #include #include #include - -// #include - #include #include #include @@ -34,23 +25,12 @@ #include #include #include -#include -#include #include // #include // #include "cpp/mpv/mpvitem.h" // #include "cpp/mpv/mpvproperties.h" -// #include "cpp/serviceitemmodel.h" -// #include "cpp/slidemodel.h" -// #include "cpp/songsqlmodel.h" -// #include "cpp/videosqlmodel.h" -// #include "cpp/imagesqlmodel.h" -// #include "cpp/presentationsqlmodel.h" -// #include "cpp/filemanager.h" -// #include "cpp/slidehelper.h" // RUST -// #include "cxx-qt-gen/service_thing.cxxqt.h" #include "cxx-qt-gen/file_helper.cxxqt.h" #include "cxx-qt-gen/slide_object.cxxqt.h" #include "cxx-qt-gen/slide_model.cxxqt.h" @@ -116,13 +96,8 @@ int main(int argc, char *argv[]) qDebug() << QApplication::platformName(); //Need to instantiate our slide - // QScopedPointer utils(new Utils); QScopedPointer slideModel(new SlideModel); - // QScopedPointer slideMod(new SlideModelCpp); - // QScopedPointer filemanager(new File); - // QScopedPointer preswin(new QQuickView); QScopedPointer serviceItemModel(new ServiceItemModel); - // QScopedPointer serviceItemC(new ServiceItemModelCpp); QScopedPointer slideobject(new SlideObject); QScopedPointer obsModel(new ObsModel); obsModel.get()->getObs(); @@ -182,40 +157,23 @@ int main(int argc, char *argv[]) qDebug() << serviceItemModel.get()->rowCount(QModelIndex()); //register our models - // qmlRegisterType("org.presenter", 1, 0, "SongProxyModel"); - // qmlRegisterType("org.presenter", 1, 0, "VideoProxyModel"); - // qmlRegisterType("org.presenter", 1, 0, "ImageProxyModel"); - // qmlRegisterType("org.presenter", 1, 0, "PresentationProxyModel"); qmlRegisterType("org.presenter", 1, 0, "SongModel"); qmlRegisterType("org.presenter", 1, 0, "SongEditor"); qmlRegisterType("org.presenter", 1, 0, "VideoModel"); qmlRegisterType("org.presenter", 1, 0, "ImageModel"); qmlRegisterType("org.presenter", 1, 0, "PresentationModel"); - // qmlRegisterType("org.presenter", 1, 0, "SongSqlModel"); - // qmlRegisterType("org.presenter", 1, 0, "VideoSqlModel"); - // qmlRegisterType("org.presenter", 1, 0, "ImageSqlModel"); - // qmlRegisterType("org.presenter", 1, 0, "PresentationSqlModel"); qmlRegisterType("org.presenter", 1, 0, "FileHelper"); qmlRegisterType("org.presenter", 1, 0, "Ytdl"); - // qmlRegisterType("org.presenter", 1, 0, "ServiceThing"); - // qmlRegisterType("org.presenter", 1, 0, "SlideHelper"); // qmlRegisterType("mpv", 1, 0, "MpvItem"); // qmlRegisterSingletonInstance("mpv", 1, 0, "MpvProperties", MpvProperties::self()); - - qmlRegisterSingletonInstance("org.presenter", 1, 0, "ServiceItemModel", serviceItemModel.get()); - // qmlRegisterSingletonInstance("org.presenter", 1, 0, - // "ServiceItemC", serviceItemC.get()); qmlRegisterSingletonInstance("org.presenter", 1, 0, "SlideModel", slideModel.get()); - // qmlRegisterSingletonInstance("org.presenter", 1, 0, "SlideMod", slideMod.get()); qmlRegisterSingletonInstance("org.presenter", 1, 0, "Utils", utils); qmlRegisterSingletonInstance("org.presenter", 1, 0, "SlideObject", slideobject.get()); - // qmlRegisterSingletonInstance("org.presenter", 1, 0, "FileManager", filemanager.get()); qmlRegisterSingletonInstance("org.presenter", 1, 0, "PresWindow", PresWindow); qmlRegisterSingletonInstance("org.presenter", 1, 0, "RSettings", settings); qmlRegisterSingletonInstance("org.presenter", 1, 0, "ObsModel", obsModel.get()); - // qmlRegisterSingletonInstance("org.presenter", 1, 0, "PresWindow", preswin.get()); // This is the same slideobject, however to enusre that the PresWindow can have it // we need to set it as a separate context so that it can change it's slides too. @@ -224,8 +182,6 @@ int main(int argc, char *argv[]) PresWindow->rootContext()->setContextProperty(QStringLiteral("SlideObj"), slideobject.get()); PresWindow->setTitle(QStringLiteral("presentation-window")); - // connectToDatabase(); - qDebug() << "Starting engine"; QQmlApplicationEngine engine; qDebug() << app.allWindows(); @@ -233,13 +189,9 @@ int main(int argc, char *argv[]) engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); engine.load(QUrl(QStringLiteral("qrc:qml/main.qml"))); qDebug() << "Engine loaded"; - // engine.load(QUrl(QStringLiteral("qrc:qml/presenter/PresentationWindow.qml"))); qDebug() << app.topLevelWindows(); qDebug() << app.allWindows(); - // QQuickView *view = new QQuickView; - // view->setSource(QUrl(QStringLiteral("qrc:qml/main.qml"))); - // view->show(); #ifdef STATIC_KIRIGAMI KirigamiPlugin::getInstance().registerTypes(); #endif