File indexing completed on 2024-05-19 11:30:15
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2013 Utku Aydın <utkuaydin34@gmail.com> 0004 // 0005 0006 #ifndef ROUTESYNCMANAGER_H 0007 #define ROUTESYNCMANAGER_H 0008 0009 #include "marble_export.h" 0010 0011 #include <QObject> 0012 0013 namespace Marble { 0014 0015 class CloudSyncManager; 0016 class RoutingManager; 0017 class CloudRouteModel; 0018 class RouteItem; 0019 0020 class MARBLE_EXPORT RouteSyncManager : public QObject 0021 { 0022 Q_OBJECT 0023 0024 Q_PROPERTY( bool routeSyncEnabled READ isRouteSyncEnabled WRITE setRouteSyncEnabled NOTIFY routeSyncEnabledChanged ) 0025 0026 public: 0027 explicit RouteSyncManager( CloudSyncManager *cloudSyncManager ); 0028 ~RouteSyncManager() override; 0029 0030 void setRoutingManager( RoutingManager *routingManager ); 0031 0032 /** 0033 * Checks if the user enabled route synchronization. 0034 * @return true if route synchronization enabled 0035 */ 0036 bool isRouteSyncEnabled() const; 0037 0038 /** 0039 * Setter for enabling/disabling route synchronization. 0040 * @param enabled Status of route synchronization 0041 */ 0042 void setRouteSyncEnabled( bool enabled ); 0043 0044 /** 0045 * Returns CloudRouteModel associated with RouteSyncManager instance 0046 * @return CloudRouteModel associated with RouteSyncManager instance 0047 */ 0048 CloudRouteModel *model(); 0049 0050 /** 0051 * Generates a timestamp which will be used as an unique identifier. 0052 * @return A timestamp. 0053 */ 0054 QString generateTimestamp() const; 0055 0056 /** 0057 * Saves the route displayed in Marble's routing widget to local cache directory. 0058 * Uses the RoutingManager passed as a parameter to the constructor. 0059 * @return Filename of saved file. 0060 */ 0061 QString saveDisplayedToCache() const; 0062 0063 /** 0064 * Uploads currently displayed route to cloud. 0065 * Initiates necessary methods of backends. 0066 * Note that, this also runs saveDisplayedToCache() method. 0067 */ 0068 void uploadRoute(); 0069 0070 /** 0071 * Gathers data from local cache directory and returns a route list. 0072 * @return Routes stored in local cache 0073 */ 0074 QVector<RouteItem> cachedRouteList() const; 0075 0076 public Q_SLOTS: 0077 /** 0078 * Uploads the route with given timestamp. 0079 * @param timestamp Timestamp of the route which will be uploaded. 0080 */ 0081 void uploadRoute( const QString ×tamp ); 0082 0083 /** 0084 * Starts preparing a route list by downloading 0085 * a list of the routes on the cloud and adding 0086 * the ones on the 0087 */ 0088 void prepareRouteList(); 0089 0090 /** 0091 * Starts the download of specified route. 0092 * @param timestamp Timestamp of the route that will be downloaded. 0093 * @see RouteSyncManager::saveDownloadedToCache() 0094 */ 0095 void downloadRoute( const QString ×tamp ); 0096 0097 /** 0098 * Opens route. 0099 * @param timestamp Timestamp of the route that will be opened. 0100 */ 0101 void openRoute( const QString ×tamp ); 0102 0103 /** 0104 * Deletes route from cloud. 0105 * @param timestamp Timestamp of the route that will be deleted. 0106 */ 0107 void deleteRoute( const QString ×tamp ); 0108 0109 /** 0110 * Removes route from cache. 0111 * @param timestamp Timestamp of the route that will be removed. 0112 */ 0113 void removeRouteFromCache( const QString ×tamp ); 0114 0115 /** 0116 * Updates upload progressbar. 0117 * @param sent Bytes sent. 0118 * @param total Total bytes. 0119 */ 0120 void updateUploadProgressbar( qint64 sent, qint64 total ); 0121 0122 private Q_SLOTS: 0123 /** 0124 * Appends downloaded route list to RouteSyncManager's private list 0125 * and then forwards the list to CloudRouteModel 0126 * @param routeList Downloaded route list 0127 */ 0128 void setRouteModelItems( const QVector<RouteItem> &routeList ); 0129 0130 0131 Q_SIGNALS: 0132 void routeSyncEnabledChanged(bool enabled); 0133 void routeListDownloadProgress( qint64 received, qint64 total ); 0134 void routeUploadProgress( qint64 sent, qint64 total ); 0135 0136 private: 0137 class Private; 0138 Private *d; 0139 }; 0140 0141 } 0142 0143 #endif // ROUTESYNCMANAGER_H