File indexing completed on 2024-04-14 04:46:50

0001 /*
0002     SPDX-FileCopyrightText: 2021 Julius Künzel <jk.kdedev@smartlab.uber.space>
0003     SPDX-FileCopyrightText: 2011 Jean-Baptiste Mardelle <jb@kdenlive.org>
0004     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include "providersrepository.hpp"
0010 #include "ui_resourcewidget_ui.h"
0011 
0012 #include <KJob>
0013 #include <QListWidgetItem>
0014 #include <QNetworkReply>
0015 #include <QProcess>
0016 #include <QSlider>
0017 #include <QTemporaryFile>
0018 #include <QUrl>
0019 #include <QWidget>
0020 #include <QtNetworkAuth>
0021 
0022 const int imageRole = Qt::UserRole;
0023 const int urlRole = Qt::UserRole + 1;
0024 const int downloadRole = Qt::UserRole + 2;
0025 const int durationRole = Qt::UserRole + 3;
0026 const int previewRole = Qt::UserRole + 4;
0027 const int authorRole = Qt::UserRole + 5;
0028 const int authorUrl = Qt::UserRole + 6;
0029 const int infoUrl = Qt::UserRole + 7;
0030 const int infoData = Qt::UserRole + 8;
0031 const int idRole = Qt::UserRole + 9;
0032 const int licenseRole = Qt::UserRole + 10;
0033 const int descriptionRole = Qt::UserRole + 11;
0034 const int widthRole = Qt::UserRole + 12;
0035 const int heightRole = Qt::UserRole + 13;
0036 const int nameRole = Qt::UserRole + 14;
0037 const int singleDownloadRole = Qt::UserRole + 15;
0038 const int filetypeRole = Qt::UserRole + 16;
0039 const int downloadLabelRole = Qt::UserRole + 17;
0040 
0041 class ResourceWidget : public QWidget, public Ui::ResourceWidget_UI
0042 {
0043     Q_OBJECT
0044 
0045 public:
0046     explicit ResourceWidget(QWidget *parent = nullptr);
0047     ~ResourceWidget() override;
0048 
0049 private Q_SLOTS:
0050     void slotChangeProvider();
0051     void slotOpenUrl(const QString &url);
0052     void slotStartSearch();
0053     void slotLoadImages();
0054     void slotShowPixmap(const QString &url, const QPixmap &pixmap);
0055     void slotSearchFinished(const QList<ResourceItemInfo> &list, const int pageCount);
0056     void slotDisplayError(const QString &message);
0057     void slotUpdateCurrentItem();
0058     void slotSetIconSize(int size);
0059     void slotPreviewItem();
0060     void slotChooseVersion(const QStringList &urls, const QStringList &labels, const QString &accessToken = QString());
0061     void slotSaveItem(const QString &originalUrl = QString(), const QString &accessToken = QString());
0062     void slotGotFile(KJob *job);
0063     void slotAccessTokenReceived(const QString &accessToken);
0064 
0065 private:
0066     std::unique_ptr<ProviderModel> *m_currentProvider{nullptr};
0067     QListWidgetItem *m_currentItem{nullptr};
0068     QTemporaryFile *m_tmpThumbFile;
0069     QStringList m_imagesUrl;
0070     QMutex m_imageLock;
0071     /** @brief Default icon size for the views. */
0072     QSize m_iconSize;
0073     int wheelAccumulatedDelta;
0074     bool m_showloadingWarning;
0075     ResourceItemInfo getItemById(const QString &id);
0076     void loadConfig();
0077     void saveConfig();
0078     void blockUI(bool block);
0079     QString licenseNameFromUrl(const QString &licenseUrl, const bool shortName);
0080 
0081 Q_SIGNALS:
0082     void addClip(const QUrl &, const QString &);
0083     void addLicenseInfo(const QString &);
0084     void previewClip(const QString &path, const QString &title);
0085     void gotPixmap(const QString &url, const QPixmap &pix);
0086 };