File indexing completed on 2024-04-14 04:51:58

0001 /***************************************************************************
0002  *   Copyright (C) 2011 Matthias Fuchs <mat69@gmx.net>                     *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU General Public License as published by  *
0006  *   the Free Software Foundation; either version 2 of the License, or     *
0007  *   (at your option) any later version.                                   *
0008  *                                                                         *
0009  *   This program is distributed in the hope that it will be useful,       *
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0012  *   GNU General Public License for more details.                          *
0013  *                                                                         *
0014  *   You should have received a copy of the GNU General Public License     *
0015  *   along with this program; if not, write to the                         *
0016  *   Free Software Foundation, Inc.,                                       *
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
0018  ***************************************************************************/
0019 
0020 #ifndef KGET_MOSTLOCALURL_H
0021 #define KGET_MOSTLOCALURL_H
0022 
0023 #include "kget_export.h"
0024 #include <KIO/Job>
0025 #include <QUrl>
0026 
0027 /**
0028  * NOTE this implementation does KIO::mostLocalUrl on any url whose protocol
0029  * is not supported by a TransferFactory.
0030  * I.e. it is assumed that an e.g. ftp url does _not_ point to a local file.
0031  *
0032  * The reason for that is to avoid connecting to external urls, which could
0033  * cause problems with websites that only allow one connection, or with
0034  * servers you connected already, reaching their maximum connections.
0035  * See #264452
0036  */
0037 
0038 class MostLocalUrlJob;
0039 
0040 /**
0041  * Synchronous
0042  */
0043 KGET_EXPORT QUrl mostLocalUrl(const QUrl &url);
0044 
0045 /**
0046  * Asynchronous
0047  */
0048 KGET_EXPORT MostLocalUrlJob *mostLocalUrlJob(const QUrl &url);
0049 
0050 /**
0051  * Job for asynchronously getting the most local url, do not use directly, but use
0052  * mostLocalUrlJob instead
0053  */
0054 class KGET_EXPORT MostLocalUrlJob : public KIO::Job
0055 {
0056     Q_OBJECT
0057 public:
0058     MostLocalUrlJob(const QUrl &url);
0059 
0060     void start() override;
0061     QUrl url();
0062 
0063     /**
0064      * Call this in the slot connected to result.
0065      */
0066     QUrl mostLocalUrl() const;
0067 
0068 protected:
0069     void slotResult(KJob *job) override;
0070 
0071 private:
0072     QUrl m_url;
0073     QUrl m_mostLocalUrl;
0074 };
0075 
0076 #endif