migrate to Qt6
This commit is contained in:
		@@ -128,11 +128,7 @@ void AVDecoder::getVideoMetadata(metadata_t &metadata)
 | 
			
		||||
 | 
			
		||||
AVFrame *AVDecoder::getDecodedFrame(AVCodecContext *codec_ctx, int frame_stream_index)
 | 
			
		||||
{
 | 
			
		||||
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
 | 
			
		||||
    AVFrame *pFrame = av_frame_alloc();
 | 
			
		||||
#else
 | 
			
		||||
    AVFrame *pFrame = avcodec_alloc_frame();
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    AVPacket packet;
 | 
			
		||||
    int frame_finished = 0;
 | 
			
		||||
@@ -141,21 +137,13 @@ AVFrame *AVDecoder::getDecodedFrame(AVCodecContext *codec_ctx, int frame_stream_
 | 
			
		||||
        if(packet.stream_index == frame_stream_index) {
 | 
			
		||||
            avcodec_decode_video2(codec_ctx, pFrame, &frame_finished, &packet);
 | 
			
		||||
        }
 | 
			
		||||
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57,7,0)
 | 
			
		||||
        av_packet_unref(&packet);
 | 
			
		||||
#else
 | 
			
		||||
        av_free_packet(&packet);
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(frame_finished) {
 | 
			
		||||
        return pFrame;
 | 
			
		||||
    } else {
 | 
			
		||||
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
 | 
			
		||||
        av_frame_free(&pFrame);
 | 
			
		||||
#else
 | 
			
		||||
        avcodec_free_frame(&pFrame);
 | 
			
		||||
#endif
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -215,11 +203,7 @@ QByteArray AVDecoder::getThumbnail(int &width, int &height)
 | 
			
		||||
                                       width, height);
 | 
			
		||||
 | 
			
		||||
        data = WriteJPEG(pCodecCtx, pFrame, width, height);
 | 
			
		||||
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
 | 
			
		||||
        av_frame_free(&pFrame);
 | 
			
		||||
#else
 | 
			
		||||
        avcodec_free_frame(&pFrame);
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return data;
 | 
			
		||||
@@ -249,44 +233,24 @@ QByteArray AVDecoder::WriteJPEG(AVCodecContext *pCodecCtx, AVFrame *pFrame, int
 | 
			
		||||
        return data;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
 | 
			
		||||
    AVFrame *pFrameRGB = av_frame_alloc();
 | 
			
		||||
#else
 | 
			
		||||
    AVFrame *pFrameRGB = avcodec_alloc_frame();
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    if(pFrameRGB == NULL) {
 | 
			
		||||
        sws_freeContext(sws_ctx);
 | 
			
		||||
        return data;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // detect ffmpeg (>= 100) or libav (< 100)
 | 
			
		||||
#if (LIBAVUTIL_VERSION_MICRO >= 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,63,100)) || \
 | 
			
		||||
    (LIBAVUTIL_VERSION_MICRO < 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(54,6,0))
 | 
			
		||||
    int numBytes = av_image_get_buffer_size(AV_PIX_FMT_YUV420P, width, height, 16);
 | 
			
		||||
#else
 | 
			
		||||
    int numBytes = avpicture_get_size(PIX_FMT_YUVJ420P, width, height);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    uint8_t *buffer = (uint8_t *)av_malloc(numBytes);
 | 
			
		||||
 | 
			
		||||
    if(!buffer) {
 | 
			
		||||
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
 | 
			
		||||
        av_frame_free(&pFrameRGB);
 | 
			
		||||
#else
 | 
			
		||||
        avcodec_free_frame(&pFrameRGB);
 | 
			
		||||
#endif
 | 
			
		||||
        sws_freeContext(sws_ctx);
 | 
			
		||||
        return data;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // detect ffmpeg (>= 100) or libav (< 100)
 | 
			
		||||
#if (LIBAVUTIL_VERSION_MICRO >= 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,63,100)) || \
 | 
			
		||||
    (LIBAVUTIL_VERSION_MICRO < 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(54,6,0))
 | 
			
		||||
    av_image_fill_arrays(pFrameRGB->data, pFrameRGB->linesize, buffer, AV_PIX_FMT_YUV420P, width, height, 1);
 | 
			
		||||
#else
 | 
			
		||||
    avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_YUVJ420P, width, height);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    sws_scale(
 | 
			
		||||
        sws_ctx,
 | 
			
		||||
@@ -301,18 +265,9 @@ QByteArray AVDecoder::WriteJPEG(AVCodecContext *pCodecCtx, AVFrame *pFrame, int
 | 
			
		||||
    pOCodecCtx = avcodec_alloc_context3(pOCodec);
 | 
			
		||||
 | 
			
		||||
    if(pOCodecCtx == NULL) {
 | 
			
		||||
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,52,0)
 | 
			
		||||
        avcodec_free_context(&pOCodecCtx);
 | 
			
		||||
#else
 | 
			
		||||
        avcodec_close(pOCodecCtx);
 | 
			
		||||
        av_free(pOCodecCtx);
 | 
			
		||||
#endif
 | 
			
		||||
        av_free(buffer);
 | 
			
		||||
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
 | 
			
		||||
        av_frame_free(&pFrameRGB);
 | 
			
		||||
#else
 | 
			
		||||
        avcodec_free_frame(&pFrameRGB);
 | 
			
		||||
#endif
 | 
			
		||||
        sws_freeContext(sws_ctx);
 | 
			
		||||
        return  0;
 | 
			
		||||
    }
 | 
			
		||||
@@ -329,18 +284,9 @@ QByteArray AVDecoder::WriteJPEG(AVCodecContext *pCodecCtx, AVFrame *pFrame, int
 | 
			
		||||
 | 
			
		||||
    AVDictionary *opts = NULL;
 | 
			
		||||
    if(avcodec_open2(pOCodecCtx, pOCodec, &opts) < 0) {
 | 
			
		||||
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,52,0)
 | 
			
		||||
        avcodec_free_context(&pOCodecCtx);
 | 
			
		||||
#else
 | 
			
		||||
        avcodec_close(pOCodecCtx);
 | 
			
		||||
        av_free(pOCodecCtx);
 | 
			
		||||
#endif
 | 
			
		||||
        av_free(buffer);
 | 
			
		||||
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
 | 
			
		||||
        av_frame_free(&pFrameRGB);
 | 
			
		||||
#else
 | 
			
		||||
        avcodec_free_frame(&pFrameRGB);
 | 
			
		||||
#endif
 | 
			
		||||
        sws_freeContext(sws_ctx);
 | 
			
		||||
         return  0;
 | 
			
		||||
    }
 | 
			
		||||
@@ -367,18 +313,9 @@ QByteArray AVDecoder::WriteJPEG(AVCodecContext *pCodecCtx, AVFrame *pFrame, int
 | 
			
		||||
 | 
			
		||||
    QByteArray buffer2(reinterpret_cast<char *>(pkt.data), pkt.size);
 | 
			
		||||
 | 
			
		||||
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,52,0)
 | 
			
		||||
        avcodec_free_context(&pOCodecCtx);
 | 
			
		||||
#else
 | 
			
		||||
        avcodec_close(pOCodecCtx);
 | 
			
		||||
        av_free(pOCodecCtx);
 | 
			
		||||
#endif
 | 
			
		||||
    av_free(buffer);
 | 
			
		||||
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
 | 
			
		||||
    av_frame_free(&pFrameRGB);
 | 
			
		||||
#else
 | 
			
		||||
    avcodec_free_frame(&pFrameRGB);
 | 
			
		||||
#endif
 | 
			
		||||
    avcodec_close(pOCodecCtx);
 | 
			
		||||
    sws_freeContext(sws_ctx);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -72,7 +72,6 @@ public:
 | 
			
		||||
    {
 | 
			
		||||
    public:
 | 
			
		||||
        AvInit() {
 | 
			
		||||
            av_register_all();
 | 
			
		||||
            // hide warning logs
 | 
			
		||||
            av_log_set_level(AV_LOG_ERROR);
 | 
			
		||||
        }
 | 
			
		||||
@@ -87,7 +86,7 @@ private:
 | 
			
		||||
    AVFormatContext *pFormatCtx;
 | 
			
		||||
    AVCodecContext *pCodecCtx;
 | 
			
		||||
    AVStream *av_stream;
 | 
			
		||||
    AVCodec *av_codec;
 | 
			
		||||
    const AVCodec *av_codec;
 | 
			
		||||
    int stream_index;
 | 
			
		||||
    bool codec_loaded;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -62,11 +62,7 @@ CmaBroadcast::CmaBroadcast(QObject *obj_parent) :
 | 
			
		||||
    socket = new QUdpSocket(this);
 | 
			
		||||
    connect(socket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
 | 
			
		||||
 | 
			
		||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
 | 
			
		||||
    QHostAddress host_address(QHostAddress::Any);
 | 
			
		||||
#else
 | 
			
		||||
    QHostAddress host_address(QHostAddress::AnyIPv4);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    if(!socket->bind(host_address, QCMA_REQUEST_PORT, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint)) {
 | 
			
		||||
        qCritical() << "Failed to bind address for UDP broadcast";
 | 
			
		||||
@@ -88,7 +84,7 @@ void CmaBroadcast::readPendingDatagrams()
 | 
			
		||||
            QMutexLocker locker(&mutex);
 | 
			
		||||
            socket->writeDatagram(reply, cma_sender, senderPort);
 | 
			
		||||
        } else {
 | 
			
		||||
            qWarning("Unknown request: %.*s\n", datagram.length(), datagram.constData());
 | 
			
		||||
            qWarning() << "Unknown request, length: " << datagram.length() << "data: " << datagram.constData();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -103,7 +99,7 @@ void CmaBroadcast::setAvailable()
 | 
			
		||||
                 .arg(broadcast_ok, uuid, "win", hostname)
 | 
			
		||||
                 .arg(protocol_version, 8, 10, QChar('0'))
 | 
			
		||||
                 .arg(QCMA_REQUEST_PORT)
 | 
			
		||||
                 .arg(VITAMTP_WIRELESS_MAX_VERSION, 8, 10, QChar('0')));
 | 
			
		||||
                 .arg(VITAMTP_WIRELESS_MAX_VERSION, 8, 10, QChar('0')).toStdString());
 | 
			
		||||
    reply.append('\0');
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -117,6 +113,6 @@ void CmaBroadcast::setUnavailable()
 | 
			
		||||
                 .arg(broadcast_unavailable, uuid, "win", hostname)
 | 
			
		||||
                 .arg(protocol_version, 8, 10, QChar('0'))
 | 
			
		||||
                 .arg(QCMA_REQUEST_PORT)
 | 
			
		||||
                 .arg(VITAMTP_WIRELESS_MAX_VERSION, 8, 10, QChar('0')));
 | 
			
		||||
                 .arg(VITAMTP_WIRELESS_MAX_VERSION, 8, 10, QChar('0')).toStdString());
 | 
			
		||||
    reply.append('\0');
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -31,6 +31,8 @@
 | 
			
		||||
#include <QSettings>
 | 
			
		||||
#include <QUrl>
 | 
			
		||||
 | 
			
		||||
#include <random>
 | 
			
		||||
 | 
			
		||||
QMutex CmaClient::mutex;
 | 
			
		||||
QMutex CmaClient::runner;
 | 
			
		||||
QWaitCondition CmaClient::usbcondition;
 | 
			
		||||
@@ -92,9 +94,6 @@ void CmaClient::connectWireless()
 | 
			
		||||
    wireless_host_info_t host = {NULL, NULL, NULL, QCMA_REQUEST_PORT};
 | 
			
		||||
    typedef CmaClient CC;
 | 
			
		||||
 | 
			
		||||
    QTime now = QTime::currentTime();
 | 
			
		||||
    qsrand(now.msec());
 | 
			
		||||
 | 
			
		||||
    qDebug("Starting wireless_thread: 0x%016" PRIxPTR, (uintptr_t)QThread::currentThreadId());
 | 
			
		||||
 | 
			
		||||
    setActive(true);
 | 
			
		||||
@@ -132,7 +131,7 @@ void CmaClient::processNewConnection(vita_device_t *device)
 | 
			
		||||
    QMutexLocker locker(&mutex);
 | 
			
		||||
    in_progress = true;
 | 
			
		||||
 | 
			
		||||
    QTextStream(stdout) << "Vita connected, id: " << VitaMTP_Get_Identification(device) << endl;
 | 
			
		||||
    QTextStream(stdout) << "Vita connected, id: " << VitaMTP_Get_Identification(device) << Qt::endl;
 | 
			
		||||
    DeviceCapability vita_info;
 | 
			
		||||
 | 
			
		||||
    if(!vita_info.exchangeInfo(device)) {
 | 
			
		||||
@@ -189,6 +188,10 @@ int CmaClient::generatePin(wireless_vita_info_t *info, int *p_err)
 | 
			
		||||
 | 
			
		||||
    QString staticPin = QSettings().value("staticPin").toString();
 | 
			
		||||
 | 
			
		||||
    static std::mt19937 rng(std::random_device{}());
 | 
			
		||||
 | 
			
		||||
    std::uniform_int_distribution<int> dist(0, 99999999);
 | 
			
		||||
 | 
			
		||||
    int pin;
 | 
			
		||||
 | 
			
		||||
    if(!staticPin.isNull() && staticPin.length() == 8) {
 | 
			
		||||
@@ -196,17 +199,17 @@ int CmaClient::generatePin(wireless_vita_info_t *info, int *p_err)
 | 
			
		||||
        pin = staticPin.toInt(&ok);
 | 
			
		||||
 | 
			
		||||
        if(!ok) {
 | 
			
		||||
            pin = rand() % 10000 * 10000 | rand() % 10000;
 | 
			
		||||
            pin = dist(rng);
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        pin = rand() % 10000 * 10000 | rand() % 10000;
 | 
			
		||||
        pin = dist(rng);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    QTextStream out(stdout);
 | 
			
		||||
    out << "Your registration PIN for " << info->name << " is: ";
 | 
			
		||||
    out.setFieldWidth(8);
 | 
			
		||||
    out.setPadChar('0');
 | 
			
		||||
    out << pin << endl;
 | 
			
		||||
    out << pin << Qt::endl;
 | 
			
		||||
 | 
			
		||||
    qDebug("PIN: %08i", pin);
 | 
			
		||||
 | 
			
		||||
@@ -262,7 +265,7 @@ void CmaClient::enterEventLoop(vita_device_t *device)
 | 
			
		||||
 | 
			
		||||
int CmaClient::stop()
 | 
			
		||||
{
 | 
			
		||||
    QTextStream(stdout) << "Stopping Qcma" << endl;
 | 
			
		||||
    QTextStream(stdout) << "Stopping Qcma" << Qt::endl;
 | 
			
		||||
 | 
			
		||||
    if(!isActive()) {
 | 
			
		||||
        return -1;
 | 
			
		||||
 
 | 
			
		||||
@@ -649,7 +649,7 @@ void CmaEvent::vitaEventSendHttpObjectFromURL(vita_event_t *cma_event, int event
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    qDebug("Sending %i bytes of data for HTTP request %s", data.size(), url);
 | 
			
		||||
    qDebug() << "Sending " << data.size() << " bytes of data for HTTP request" << url;
 | 
			
		||||
 | 
			
		||||
    if(VitaMTP_SendHttpObjectFromURL(m_device, eventId, data.data(), data.size()) != PTP_RC_OK) {
 | 
			
		||||
        qWarning("Failed to send HTTP object");
 | 
			
		||||
 
 | 
			
		||||
@@ -99,7 +99,7 @@ void CMAObject::loadSfoMetadata(const QString &path)
 | 
			
		||||
            title.chop(1);
 | 
			
		||||
        }
 | 
			
		||||
        metadata.data.saveData.savedataTitle = strdup(title.toStdString().c_str());
 | 
			
		||||
        metadata.data.saveData.dateTimeUpdated = QFileInfo(sfo).created().toUTC().toTime_t();
 | 
			
		||||
        metadata.data.saveData.dateTimeUpdated = QFileInfo(sfo).birthTime().toUTC().toSecsSinceEpoch();
 | 
			
		||||
    } else {
 | 
			
		||||
        metadata.data.saveData.title = strdup(metadata.name);
 | 
			
		||||
        metadata.data.saveData.detail = strdup("");
 | 
			
		||||
@@ -115,7 +115,7 @@ void CMAObject::initObject(const QFileInfo &file, int obj_file_type)
 | 
			
		||||
    metadata.ohfi = ohfi_count++;
 | 
			
		||||
 | 
			
		||||
    metadata.type = VITA_DIR_TYPE_MASK_REGULAR; // ignored for files
 | 
			
		||||
    metadata.dateTimeCreated = file.created().toUTC().toTime_t();
 | 
			
		||||
    metadata.dateTimeCreated = file.birthTime().toUTC().toSecsSinceEpoch();
 | 
			
		||||
    metadata.size = 0;
 | 
			
		||||
    DataType type = file.isFile() ? File : Folder;
 | 
			
		||||
    metadata.dataType = (DataType)(type | (parent->metadata.dataType & ~Folder));
 | 
			
		||||
@@ -142,7 +142,7 @@ void CMAObject::initObject(const QFileInfo &file, int obj_file_type)
 | 
			
		||||
        Database::loadMusicMetadata(file.absoluteFilePath(), metadata);
 | 
			
		||||
    } else if(MASK_SET(metadata.dataType, Video | File)) {
 | 
			
		||||
        metadata.data.video.fileName = strdup(metadata.name);
 | 
			
		||||
        metadata.data.video.dateTimeUpdated = file.created().toUTC().toTime_t();
 | 
			
		||||
        metadata.data.video.dateTimeUpdated = file.birthTime().toUTC().toSecsSinceEpoch();
 | 
			
		||||
        metadata.data.video.statusType = 1;
 | 
			
		||||
        metadata.data.video.fileFormatType = FILE_FORMAT_MP4;
 | 
			
		||||
        metadata.data.video.parentalLevel = 0;
 | 
			
		||||
@@ -160,7 +160,7 @@ void CMAObject::initObject(const QFileInfo &file, int obj_file_type)
 | 
			
		||||
        metadata.data.photo.fileName = strdup(metadata.name);
 | 
			
		||||
        metadata.data.photo.fileFormatType = photo_list[obj_file_type].file_format;
 | 
			
		||||
        metadata.data.photo.statusType = 1;
 | 
			
		||||
        metadata.data.photo.dateTimeOriginal = file.created().toUTC().toTime_t();
 | 
			
		||||
        metadata.data.photo.dateTimeOriginal = file.birthTime().toUTC().toSecsSinceEpoch();
 | 
			
		||||
        metadata.data.photo.numTracks = 1;
 | 
			
		||||
        metadata.data.photo.tracks = new media_track();
 | 
			
		||||
        metadata.data.photo.tracks->type = VITA_TRACK_TYPE_PHOTO;
 | 
			
		||||
 
 | 
			
		||||
@@ -70,31 +70,7 @@ bool removeRecursively(const QString &path)
 | 
			
		||||
    QFileInfo file_info(path);
 | 
			
		||||
 | 
			
		||||
    if(file_info.isDir()) {
 | 
			
		||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
 | 
			
		||||
        return QDir(path).removeRecursively();
 | 
			
		||||
#else
 | 
			
		||||
        bool result = false;
 | 
			
		||||
        QDir dir(path);
 | 
			
		||||
 | 
			
		||||
        QDir::Filters filter = QDir::NoDotAndDotDot | QDir::System | QDir::Hidden  | QDir::AllDirs | QDir::Files;
 | 
			
		||||
 | 
			
		||||
        if(dir.exists(path)) {
 | 
			
		||||
            foreach(QFileInfo info, dir.entryInfoList(filter, QDir::DirsFirst)) {
 | 
			
		||||
                if(info.isDir()) {
 | 
			
		||||
                    result = removeRecursively(info.absoluteFilePath());
 | 
			
		||||
                } else {
 | 
			
		||||
                    result = QFile::remove(info.absoluteFilePath());
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if(!result) {
 | 
			
		||||
                    return result;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            result = dir.rmdir(path);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return result;
 | 
			
		||||
#endif
 | 
			
		||||
    } else {
 | 
			
		||||
        return QFile::remove(path);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -26,24 +26,7 @@
 | 
			
		||||
 | 
			
		||||
#include <vitamtp.h>
 | 
			
		||||
 | 
			
		||||
// Qt4 doesn't have public methods for Thread::*sleep
 | 
			
		||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
 | 
			
		||||
typedef QThread Sleeper;
 | 
			
		||||
#else
 | 
			
		||||
class Sleeper : QThread
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    static void sleep(unsigned long secs) {
 | 
			
		||||
        QThread::sleep(secs);
 | 
			
		||||
    }
 | 
			
		||||
    static void msleep(unsigned long msecs) {
 | 
			
		||||
        QThread::msleep(msecs);
 | 
			
		||||
    }
 | 
			
		||||
    static void usleep(unsigned long usecs) {
 | 
			
		||||
        QThread::usleep(usecs);
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
bool removeRecursively(const QString &path);
 | 
			
		||||
QString readable_size(qint64 size, bool use_gib = false);
 | 
			
		||||
 
 | 
			
		||||
@@ -52,7 +52,7 @@ const file_type video_list[] = {
 | 
			
		||||
 | 
			
		||||
Database::Database(QObject *obj_parent) :
 | 
			
		||||
    QObject(obj_parent),
 | 
			
		||||
    mutex(QMutex::Recursive)
 | 
			
		||||
    mutex()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -63,7 +63,7 @@ void Database::process()
 | 
			
		||||
    cancel_operation = false;
 | 
			
		||||
    int count = create();
 | 
			
		||||
    cancel_operation = false;
 | 
			
		||||
    QTextStream(stdout) << "Total entries added to the database: " << count << endl;
 | 
			
		||||
    QTextStream(stdout) << "Total entries added to the database: " << count << Qt::endl;
 | 
			
		||||
    if(count < 0) {
 | 
			
		||||
        clear();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -88,7 +88,7 @@ public:
 | 
			
		||||
    static void loadPhotoMetadata(const QString &path, metadata_t &metadata);
 | 
			
		||||
    static void loadVideoMetadata(const QString &path, metadata_t &metadata);
 | 
			
		||||
 | 
			
		||||
    QMutex mutex;
 | 
			
		||||
    QRecursiveMutex mutex;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    bool continueOperation();
 | 
			
		||||
 
 | 
			
		||||
@@ -253,7 +253,7 @@ int QListDB::recursiveScanRootDirectory(root_list &list, CMAObject *obj_parent,
 | 
			
		||||
    QFileInfoList qsl = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot, QDir::Time);
 | 
			
		||||
 | 
			
		||||
    if(obj_parent && !obj_parent->parent) {
 | 
			
		||||
        qSort(qsl.begin(), qsl.end(), nameLessThan);
 | 
			
		||||
        std::sort(qsl.begin(), qsl.end(), nameLessThan);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    foreach(const QFileInfo &info, qsl) {
 | 
			
		||||
@@ -325,7 +325,7 @@ bool QListDB::findInternal(const root_list &list, int ohfi, find_data &data)
 | 
			
		||||
    } else {
 | 
			
		||||
        CMAObject obj;
 | 
			
		||||
        obj.setOhfi(ohfi);
 | 
			
		||||
        data.it = qBinaryFind(list.begin(), list.end(), &obj, QListDB::lessThanComparator);
 | 
			
		||||
        data.it = std::lower_bound(list.begin(), list.end(), &obj, QListDB::lessThanComparator);
 | 
			
		||||
    }
 | 
			
		||||
    data.end = list.end();
 | 
			
		||||
    return data.it != data.end;
 | 
			
		||||
@@ -565,7 +565,7 @@ int QListDB::insertObjectEntry(const QString &path, const QString &name, int par
 | 
			
		||||
 | 
			
		||||
    for(map_list::iterator root = object_list.begin(); root != object_list.end(); ++root) {
 | 
			
		||||
        root_list *cat_list = &(*root);
 | 
			
		||||
        root_list::const_iterator it = qBinaryFind(cat_list->begin(), cat_list->end(), parent_obj, QListDB::lessThanComparator);
 | 
			
		||||
        root_list::iterator it = std::lower_bound(cat_list->begin(), cat_list->end(), parent_obj, QListDB::lessThanComparator);
 | 
			
		||||
 | 
			
		||||
        if(it != cat_list->end()) {
 | 
			
		||||
            CMAObject *newobj = new CMAObject(parent_obj);
 | 
			
		||||
 
 | 
			
		||||
@@ -29,15 +29,7 @@
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
#include <QDir>
 | 
			
		||||
#include <QFileInfo>
 | 
			
		||||
 | 
			
		||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
 | 
			
		||||
#include <QStandardPaths>
 | 
			
		||||
#else
 | 
			
		||||
#include <QDesktopServices>
 | 
			
		||||
#define QStandardPaths QDesktopServices
 | 
			
		||||
#define writableLocation storageLocation
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include <QSettings>
 | 
			
		||||
#include <QSqlQuery>
 | 
			
		||||
 | 
			
		||||
@@ -160,7 +152,7 @@ SQLiteDB::SQLiteDB(QObject *obj_parent) :
 | 
			
		||||
    connect(timer, SIGNAL(timeout()), this, SLOT(process()));
 | 
			
		||||
 | 
			
		||||
    // fetch a configured database path if it exists
 | 
			
		||||
    QString db_path = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
 | 
			
		||||
    QString db_path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
 | 
			
		||||
    db_path = QSettings().value("databasePath", db_path).toString();
 | 
			
		||||
    QDir(QDir::root()).mkpath(db_path);
 | 
			
		||||
 | 
			
		||||
@@ -226,7 +218,7 @@ void SQLiteDB::clear()
 | 
			
		||||
{
 | 
			
		||||
    db.close();
 | 
			
		||||
    //QSqlDatabase::removeDatabase("QSQLITE");
 | 
			
		||||
    QString db_path = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
 | 
			
		||||
    QString db_path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
 | 
			
		||||
    db_path = QSettings().value("databasePath", db_path).toString();
 | 
			
		||||
    QFile(db_path + QDir::separator() + "qcma.sqlite").remove();
 | 
			
		||||
    load();
 | 
			
		||||
@@ -529,13 +521,13 @@ bool SQLiteDB::insertSourceEntry(uint object_id, const QString &path, const QStr
 | 
			
		||||
    QFileInfo info(path, name);
 | 
			
		||||
    if(info.isFile()) {
 | 
			
		||||
        size = QVariant(info.size());
 | 
			
		||||
        date_created = QVariant(info.created().toUTC().toTime_t());
 | 
			
		||||
        date_created = QVariant(info.birthTime().toUTC().toSecsSinceEpoch());
 | 
			
		||||
    } else {
 | 
			
		||||
        size = QVariant(QVariant::LongLong);
 | 
			
		||||
        date_created = QVariant(QVariant::UInt);
 | 
			
		||||
        size = QVariant(static_cast<qint64>(0));
 | 
			
		||||
        date_created = QVariant(static_cast<qint64>(0));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    date_modified = QVariant(info.lastModified().toUTC().toTime_t());
 | 
			
		||||
    date_modified = QVariant(info.lastModified().toUTC().toSecsSinceEpoch());
 | 
			
		||||
 | 
			
		||||
    QSqlQuery query;
 | 
			
		||||
    query.prepare("REPLACE INTO sources (object_id, path, size, date_created, date_modified)"
 | 
			
		||||
@@ -662,10 +654,10 @@ uint SQLiteDB::insertMusicEntry(const QString &path, const QString &name, int id
 | 
			
		||||
    query.bindValue(2, audio_codec);
 | 
			
		||||
    query.bindValue(3, audio_bitrate);
 | 
			
		||||
    query.bindValue(4, duration);
 | 
			
		||||
    query.bindValue(5, genre_id ? genre_id : QVariant(QVariant::Int));
 | 
			
		||||
    query.bindValue(6, artist_id ? artist_id : QVariant(QVariant::Int));
 | 
			
		||||
    query.bindValue(7, album_id ? album_id : QVariant(QVariant::Int));
 | 
			
		||||
    query.bindValue(8, track_id ? track_id : QVariant(QVariant::Int));
 | 
			
		||||
    query.bindValue(5, genre_id ? genre_id : QVariant(static_cast<int>(0)));
 | 
			
		||||
    query.bindValue(6, artist_id ? artist_id : QVariant(static_cast<int>(0)));
 | 
			
		||||
    query.bindValue(7, album_id ? album_id : QVariant(static_cast<int>(0)));
 | 
			
		||||
    query.bindValue(8, track_id ? track_id : QVariant(static_cast<int>(0)));
 | 
			
		||||
    query.bindValue(9, artist);
 | 
			
		||||
    query.bindValue(10, album);
 | 
			
		||||
    query.bindValue(11, track_number);
 | 
			
		||||
@@ -775,8 +767,8 @@ uint SQLiteDB::insertPhotoEntry(const QString &path, const QString &name, int id
 | 
			
		||||
    //    return 0;
 | 
			
		||||
    //}
 | 
			
		||||
 | 
			
		||||
    QDateTime date = QFileInfo(path + "/" + name).created();
 | 
			
		||||
    date_created = date.toUTC().toTime_t();
 | 
			
		||||
    QDateTime date = QFileInfo(path + "/" + name).birthTime();
 | 
			
		||||
    date_created = date.toUTC().toSecsSinceEpoch();
 | 
			
		||||
    QString month_created = date.toString("yyyy/MM");
 | 
			
		||||
 | 
			
		||||
    width = 0; //img.width();
 | 
			
		||||
@@ -826,7 +818,7 @@ uint SQLiteDB::insertSavedataEntry(const QString &path, const QString &name, int
 | 
			
		||||
        title = reader.value("TITLE", utf8name.constData());
 | 
			
		||||
        savedata_detail = reader.value("SAVEDATA_DETAIL", "");
 | 
			
		||||
        savedata_directory = reader.value("SAVEDATA_DIRECTORY", utf8name.constData());
 | 
			
		||||
        date_updated = QFileInfo(path + "/" + name).lastModified().toUTC().toTime_t();
 | 
			
		||||
        date_updated = QFileInfo(path + "/" + name).lastModified().toUTC().toSecsSinceEpoch();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if((ohfi = insertDefaultEntry(path, name, title, id_parent, type)) == 0) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user