File indexing completed on 2024-05-12 16:28:12

0001 // SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: LGPL-2.0-or-later
0003 
0004 #include "filehelper.h"
0005 #include "filetransferjob.h"
0006 #ifdef HAVE_KIO
0007 #include <KIO/Job>
0008 #include <KJobTrackerInterface>
0009 #endif
0010 #include "account/abstractaccount.h"
0011 
0012 FileHelper::FileHelper(QObject *parent)
0013     : QObject(parent)
0014 {
0015 }
0016 
0017 FileHelper::~FileHelper() = default;
0018 
0019 void FileHelper::downloadFile(AbstractAccount *account, const QString &url, const QString &destination) const
0020 {
0021     auto job = new FileTransferJob(account, url, destination);
0022 #ifdef HAVE_KIO
0023     KIO::getJobTracker()->registerJob(job);
0024 #endif
0025     job->start();
0026 }
0027 
0028 QString FileHelper::url(const QUrl &url) const
0029 {
0030     return url.fileName().split(QLatin1Char('.')).last();
0031 }
0032 
0033 QString FileHelper::fileName(const QUrl &url) const
0034 {
0035     return url.fileName();
0036 }