File indexing completed on 2024-05-05 03:49:14

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2013 Utku Aydın <utkuaydin34@gmail.com>
0004 //
0005 
0006 #ifndef CLOUDROUTEMODEL_H
0007 #define CLOUDROUTEMODEL_H
0008 
0009 #include "marble_export.h"
0010 
0011 #include <QModelIndex>
0012 #include <QAbstractListModel>
0013 
0014 class QNetworkReply;
0015 
0016 namespace Marble
0017 {
0018 
0019 class RouteItem;
0020 
0021 class MARBLE_EXPORT CloudRouteModel : public QAbstractListModel
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     enum RouteRoles {
0027         Timestamp = Qt::UserRole + 1,
0028         Name,
0029         PreviewUrl,
0030         Distance,
0031         Duration,
0032         IsCached,
0033         IsDownloading,
0034         IsOnCloud
0035     };
0036 
0037     explicit CloudRouteModel( QObject *parent = nullptr );
0038     ~CloudRouteModel() override;
0039 
0040     QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const override;
0041     int rowCount( const QModelIndex& parent = QModelIndex() ) const override;
0042 
0043     /** Overload of QAbstractListModel */
0044     QHash<int, QByteArray> roleNames() const override;
0045 
0046     /**
0047      * Sets the list of routes that will show up in CloudRoutesDialog.
0048      * @param items List of routes.
0049      */
0050     void setItems( const QVector<RouteItem> &items );
0051 
0052     /**
0053      * Checks if specified route exists in the local cache.
0054      * @param index Index of the route.
0055      * @return true, if exists.
0056      */
0057     bool isCached( const QModelIndex &index ) const;
0058 
0059     /**
0060      * Getter for the item currently being downloaded.
0061      * @return Model for the item currently being downloaded
0062      */
0063     QPersistentModelIndex downloadingItem() const;
0064 
0065     /**
0066      * Marks the route at given index as being downloaded.
0067      * @param index Index of the route.
0068      */
0069     void setDownloadingItem( const QPersistentModelIndex &index );
0070 
0071     /**
0072      * Checks if route is being downloaded.
0073      * @param index Index of the route.
0074      * @return true, if downloading.
0075      */
0076     bool isDownloading( const QModelIndex &index ) const;
0077 
0078     /**
0079      * Total size of the item currently being downloaded.
0080      * @return Total size of the item, -1 if no route is being downloaded
0081      */
0082     qint64 totalSize() const;
0083 
0084     /**
0085      * Returns how much of the route are downloaded as bytes
0086      * @return Downloaded bytes
0087      */
0088     qint64 downloadedSize() const;
0089 
0090     /**
0091      * Checks whether a preview for the route available and
0092      * returns or downloads the preview
0093      * @param index Index of the item whose preview is requested
0094      * @return Route's preview as QIcon
0095      */
0096     QIcon preview( const QModelIndex &index ) const;
0097 
0098 public Q_SLOTS:
0099     void updateProgress( qint64 currentSize, qint64 totalSize );
0100     void setPreview( QNetworkReply *reply );
0101 
0102 private:
0103     class Private;
0104     Private *d;
0105 };
0106 }
0107 
0108 #endif // CLOUDROUTEMODEL_H