File indexing completed on 2024-05-19 04:29:08

0001 /*
0002  * SPDX-FileCopyrightText: 2023 Sharaf Zaman <shzam@sdf.org>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #include "KisAndroidFileProxy.h"
0008 
0009 #include <QDebug>
0010 #include <QDir>
0011 #include <QFile>
0012 #include <QStandardPaths>
0013 
0014 QString KisAndroidFileProxy::getFileFromContentUri(QString contentUri)
0015 {
0016     QFile file = contentUri;
0017     const QString savePath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
0018 
0019     QDir dirPath = savePath;
0020 
0021     QString filename = file.fileName();
0022     if (dirPath.exists(filename)) {
0023         // if the file already exists, delete it
0024         dirPath.remove(filename);
0025     }
0026 
0027     bool copyResult = file.copy(contentUri, savePath + "/" + filename);
0028     if (!copyResult) {
0029         qWarning() << "Failed to copy file from content uri" << contentUri << "to" << savePath + "/" + filename;
0030         return "";
0031     }
0032     return savePath + "/" + filename;
0033 }