File indexing completed on 2024-05-05 16:39:03

0001 /* This file is part of the KDE project
0002    Copyright (C) 2003,2009 Carsten Pfeiffer <pfeiffer@kde.org>
0003 
0004    This program is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU General Public
0006    License as published by the Free Software Foundation, version 2.
0007 
0008    This program is distributed in the hope that it will be useful,
0009    but WITHOUT ANY WARRANTY; without even the implied warranty of
0010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0011     General Public License for more details.
0012 
0013    You should have received a copy of the GNU General Public License
0014    along with this program; see the file COPYING.  If not, write to
0015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0016    Boston, MA 02110-1301, USA.
0017 */
0018 
0019 #ifndef KUICKFILE_H
0020 #define KUICKFILE_H
0021 
0022 #include <QObject>
0023 #include <QString>
0024 #include <QUrl>
0025 
0026 class KJob;
0027 class QProgressDialog;
0028 
0029 namespace KIO {
0030     class FileCopyJob;
0031 }
0032 
0033 
0034 class KuickFile : public QObject
0035 {
0036     Q_OBJECT
0037 
0038 public:
0039     enum DownloadStatus
0040     {
0041         OK = 1,
0042         CANCELED,
0043         ERROR
0044     };
0045 
0046     KuickFile(const QUrl& url);
0047 
0048     /**
0049      * Cleans up resources and removes any temporary file, if available.
0050      */
0051     ~KuickFile();
0052 
0053     const QUrl& url() const { return m_url; }
0054 
0055 
0056     QString localFile() const;
0057 
0058     bool download();
0059 
0060     /**
0061      * @return true if download is in progress
0062      */
0063     bool isDownloading() const { return m_job != 0L; }
0064 
0065     /**
0066      * @return true if a local file is available, that is,
0067      * @ref #localFile will return a non-empty name
0068      * ### HERE ADD mostlylocal thing!
0069      */
0070     bool isAvailable() const { return !localFile().isEmpty(); }
0071 
0072     /**
0073      * @return true if @ref #isAvailable() returns true AND @ref #url() is a remote URL,
0074      * i.e. the file really has been downloaded.
0075      */
0076     bool hasDownloaded() const;
0077 
0078     /**
0079      * Opens a modal dialog window, blocking user interaction until the download
0080      * has finished. If the file is already available, this function will return true
0081      * immediately.
0082      * @return true when the download has finished or false when the user aborted the dialog
0083      */
0084     KuickFile::DownloadStatus waitForDownload( QWidget *parent );
0085 
0086 //    bool needsDownload();
0087 
0088 signals:
0089     /**
0090      * Signals that download has finished for that file. Will only be emitted for non-local files!
0091      */
0092     void downloaded( KuickFile * );
0093 
0094 private slots:
0095     void slotResult( KJob *job );
0096     void slotProgress( KJob *job, unsigned long percent );
0097 
0098 private:
0099     QUrl m_url;
0100     QString m_localFile;
0101     KIO::FileCopyJob *m_job;
0102     QProgressDialog *m_progress;
0103     int m_currentProgress;
0104 
0105 };
0106 
0107 bool operator==( const KuickFile& first, const KuickFile& second );
0108 
0109 #endif // KUICKFILE_H