1 // SPDX-License-Identifier: LGPL-2.1-or-later 2 // 3 // SPDX-FileCopyrightText: 2013 Utku Aydın <utkuaydin34@gmail.com> 4 // 5 6 #ifndef ROUTESYNCMANAGER_H 7 #define ROUTESYNCMANAGER_H 8 9 #include "marble_export.h" 10 11 #include <QObject> 12 13 namespace Marble { 14 15 class CloudSyncManager; 16 class RoutingManager; 17 class CloudRouteModel; 18 class RouteItem; 19 20 class MARBLE_EXPORT RouteSyncManager : public QObject 21 { 22 Q_OBJECT 23 24 Q_PROPERTY( bool routeSyncEnabled READ isRouteSyncEnabled WRITE setRouteSyncEnabled NOTIFY routeSyncEnabledChanged ) 25 26 public: 27 explicit RouteSyncManager( CloudSyncManager *cloudSyncManager ); 28 ~RouteSyncManager() override; 29 30 void setRoutingManager( RoutingManager *routingManager ); 31 32 /** 33 * Checks if the user enabled route synchronization. 34 * @return true if route synchronization enabled 35 */ 36 bool isRouteSyncEnabled() const; 37 38 /** 39 * Setter for enabling/disabling route synchronization. 40 * @param enabled Status of route synchronization 41 */ 42 void setRouteSyncEnabled( bool enabled ); 43 44 /** 45 * Returns CloudRouteModel associated with RouteSyncManager instance 46 * @return CloudRouteModel associated with RouteSyncManager instance 47 */ 48 CloudRouteModel *model(); 49 50 /** 51 * Generates a timestamp which will be used as an unique identifier. 52 * @return A timestamp. 53 */ 54 QString generateTimestamp() const; 55 56 /** 57 * Saves the route displayed in Marble's routing widget to local cache directory. 58 * Uses the RoutingManager passed as a parameter to the constructor. 59 * @return Filename of saved file. 60 */ 61 QString saveDisplayedToCache() const; 62 63 /** 64 * Uploads currently displayed route to cloud. 65 * Initiates necessary methods of backends. 66 * Note that, this also runs saveDisplayedToCache() method. 67 */ 68 void uploadRoute(); 69 70 /** 71 * Gathers data from local cache directory and returns a route list. 72 * @return Routes stored in local cache 73 */ 74 QVector<RouteItem> cachedRouteList() const; 75 76 public Q_SLOTS: 77 /** 78 * Uploads the route with given timestamp. 79 * @param timestamp Timestamp of the route which will be uploaded. 80 */ 81 void uploadRoute( const QString ×tamp ); 82 83 /** 84 * Starts preparing a route list by downloading 85 * a list of the routes on the cloud and adding 86 * the ones on the 87 */ 88 void prepareRouteList(); 89 90 /** 91 * Starts the download of specified route. 92 * @param timestamp Timestamp of the route that will be downloaded. 93 * @see RouteSyncManager::saveDownloadedToCache() 94 */ 95 void downloadRoute( const QString ×tamp ); 96 97 /** 98 * Opens route. 99 * @param timestamp Timestamp of the route that will be opened. 100 */ 101 void openRoute( const QString ×tamp ); 102 103 /** 104 * Deletes route from cloud. 105 * @param timestamp Timestamp of the route that will be deleted. 106 */ 107 void deleteRoute( const QString ×tamp ); 108 109 /** 110 * Removes route from cache. 111 * @param timestamp Timestamp of the route that will be removed. 112 */ 113 void removeRouteFromCache( const QString ×tamp ); 114 115 /** 116 * Updates upload progressbar. 117 * @param sent Bytes sent. 118 * @param total Total bytes. 119 */ 120 void updateUploadProgressbar( qint64 sent, qint64 total ); 121 122 private Q_SLOTS: 123 /** 124 * Appends downloaded route list to RouteSyncManager's private list 125 * and then forwards the list to CloudRouteModel 126 * @param routeList Downloaded route list 127 */ 128 void setRouteModelItems( const QVector<RouteItem> &routeList ); 129 130 131 Q_SIGNALS: 132 void routeSyncEnabledChanged(bool enabled); 133 void routeListDownloadProgress( qint64 received, qint64 total ); 134 void routeUploadProgress( qint64 sent, qint64 total ); 135 136 private: 137 class Private; 138 Private *d; 139 }; 140 141 } 142 143 #endif // ROUTESYNCMANAGER_H 144