File indexing completed on 2024-05-12 04:45:58

0001 #include "clip.h"
0002 #include <QDesktopServices>
0003 #include <QSettings>
0004 #include <MauiKit3/FileBrowsing/fmstatic.h>
0005 
0006 Clip::Clip(QObject *parent) : QObject(parent)
0007 {
0008     //create a screenshots folder
0009 #ifdef MPV_AVAILABLE
0010     FMStatic::createDir(FMStatic::PicturesPath, "screenshots");
0011 #endif
0012 }
0013 
0014 const QStringList Clip::getSourcePaths()
0015 {
0016     static const QStringList defaultSources  = {FMStatic::VideosPath, FMStatic::DownloadsPath};
0017 
0018     QSettings settings;
0019     settings.beginGroup("Settings");
0020     const auto sources  = settings.value("Sources", defaultSources).toStringList();
0021     settings.endGroup();
0022 
0023     qDebug()<< "SOURCES" << sources;
0024     return sources;
0025 }
0026 
0027 void Clip::saveSourcePath(const QStringList &paths)
0028 {
0029     auto sources = getSourcePaths();
0030 
0031     sources << paths;
0032     sources.removeDuplicates();
0033 
0034     qDebug()<< "Saving new sources" << sources;
0035     QSettings settings;
0036     settings.beginGroup("Settings");
0037     settings.setValue("Sources", sources);
0038     settings.endGroup();
0039 
0040 }
0041 
0042 void Clip::removeSourcePath(const QString &path)
0043 {
0044     auto sources = getSourcePaths();
0045     sources.removeOne(path);
0046 
0047     QSettings settings;
0048     settings.beginGroup("Settings");
0049     settings.setValue("Sources", sources);
0050     settings.endGroup();
0051 }
0052 
0053 bool Clip::mpvAvailable() const
0054 {
0055 #ifdef MPV_AVAILABLE
0056     return true;
0057 #else
0058     return false;
0059 #endif
0060 }
0061 
0062 QVariantList Clip::sourcesModel() const
0063 {
0064     QVariantList res;
0065     const auto sources = getSourcePaths();
0066     return std::accumulate(sources.constBegin(), sources.constEnd(), res, [](QVariantList &res, const QString &url)
0067     {
0068         res << FMStatic::getFileInfo(url);
0069         return res;
0070     });
0071 }
0072 
0073 QStringList Clip::sources() const
0074 {
0075     return getSourcePaths();
0076 }
0077 
0078 void Clip::openVideos(const QList<QUrl> &urls)
0079 {
0080     Q_EMIT this->openUrls(QUrl::toStringList(urls));
0081 }
0082 
0083 void Clip::refreshCollection()
0084 {
0085     const auto sources = getSourcePaths();
0086     qDebug()<< "getting default sources to look up" << sources;
0087 }
0088 
0089 void Clip::showInFolder(const QStringList &urls)
0090 {
0091     for(const auto &url : urls)
0092         QDesktopServices::openUrl(FMStatic::fileDir(url));
0093 }
0094 
0095 void Clip::addSources(const QStringList &paths)
0096 {
0097     saveSourcePath(paths);
0098     Q_EMIT sourcesChanged();
0099 }
0100 
0101 void Clip::removeSources(const QString &path)
0102 {
0103     removeSourcePath(path);
0104     Q_EMIT sourcesChanged();
0105 }