#ifndef ALPM_MANAGER_H #define ALPM_MANAGER_H #include "./upgradelookup.h" #include "./alpmpackage.h" #include #include #include #include #include #include #include QT_FORWARD_DECLARE_CLASS(QTimer) namespace RepoIndex { class Config; class UserRepository; class AlpmDatabase; enum class RepositoryUsage; class Manager : public QObject { Q_OBJECT public: enum PackageInfoPart { None = 0x0, Basics = 0x1, Details = 0x2, }; Q_DECLARE_FLAGS(PackageInfoParts, PackageInfoPart) explicit Manager(const Config &config, QObject *parent = nullptr); ~Manager(); // configuration, signature level, etc const Config &config() const; SignatureLevel sigLevel() const; void setSigLevel(SignatureLevel sigLevel); SignatureLevel localFileSigLevel() const; void setLocalFileSigLevel(SignatureLevel sigLevel); const QString &pacmanCacheDir() const; static SignatureLevel parseSigLevel(const std::string &sigLevelStr = std::string()); static RepositoryUsage parseUsage(const std::string &usageStr); void addLocalDatabase(); void removeAllDatabases(); void addDataBasesFromPacmanConfig(); void addDatabasesFromRepoIndexConfig(); void initAlpmDataBases(); void computeRequiredBy(Repository *repo); // caching bool writeCacheBeforeGone() const; void setWriteCacheBeforeGone(bool writeCacheBeforeGone); bool isAutoCacheMaintenanceEnabled() const; void setAutoCacheMaintenanceEnabled(bool enabled); Q_SLOT void writeCache(); Q_SLOT void restoreCache(); Q_SLOT void cleanCache(); Q_SLOT void wipeCache(); Q_SLOT void maintainCache(); // updating bool isAutoUpdateEnabled() const; void setAutoUpdateEnabled(bool enabled); Q_SLOT void updateAlpmDatabases(); Q_SLOT void forceUpdateAlpmDatabases(); // package lookup AlpmPackage *packageFromDatabase(const QString &dbName, const QString &pkgName); const AlpmPackage *packageFromDatabase(const QString &dbName, const QString &pkgName) const; AlpmPackage *packageFromSyncDatabases(const QString &pkgName); const AlpmPackage *packageFromSyncDatabases(const QString &pkgName) const; Package *packageProviding(const Dependency &dependency); const Package *packageProviding(const Dependency &dependency) const; // repository lookup const AlpmDatabase *localDatabase() const; AlpmDatabase *localDatabase(); const std::map &syncDatabases() const; const AlpmDatabase *databaseByName(const QString &dbName) const; AlpmDatabase *databaseByName(const QString &dbName); const Repository *repositoryByName(const QString &name) const; Repository *repositoryByName(const QString &name); const UserRepository *userRepository() const; UserRepository *userRepository(); QString findDatabasePath(const QString &name, bool updatesRequired, bool printError) const; QString proposedDatabasePath(const QString &name, bool files) const; // JSON serialization, handling JSON requests const QJsonObject &basicRepoInfo() const; QJsonArray packageInfo(const QJsonObject &pkgSelection, PackageInfoPart part) const; const QJsonArray &groupInfo() const; Q_SIGNALS: void updatesAvailable(); private Q_SLOTS: void invalidateCachedJsonSerialization(); void emitUpdatesAvailable(); private: void connectRepository(Repository *repo); private: const Config &m_config; bool m_writeCacheBeforeGone; std::unique_ptr m_cacheTimer; std::unique_ptr m_updateTimer; SignatureLevel m_sigLevel; SignatureLevel m_localFileSigLevel; QString m_pacmanCacheDir; std::unique_ptr m_userRepo; std::unique_ptr m_localDb; std::list > m_syncDbs; std::map m_syncDbMap; mutable QJsonObject m_basicRepoInfo; mutable QMutex m_basicRepoInfoMutex; mutable QJsonArray m_groupInfo; mutable QMutex m_groupInfoMutex; }; Q_DECLARE_OPERATORS_FOR_FLAGS(Manager::PackageInfoParts) /*! * \brief Returns the configuration of the manager. * \remarks The configuration has been specified when constructing the manager. */ inline const Config &Manager::config() const { return m_config; } /*! * \brief Returns whether the manager writes cache files for all relevant repositories before the manager is * gone (out of scope, deleted, ...). * \sa setWriteCacheBeforeGone() */ inline bool Manager::writeCacheBeforeGone() const { return m_writeCacheBeforeGone; } /*! * \brief Sets whether the manager writes cache files for all relevant repositories before the manager is * gone (out of scope, deleted, ...). * \sa writeCacheBeforeGone() */ inline void Manager::setWriteCacheBeforeGone(bool writeCacheBeforeGone) { m_writeCacheBeforeGone = writeCacheBeforeGone; } /*! * \brief Returns the signature level. * * The signature level is read from the pacman config * when parsePacmanConfig() is called or can be set * manually using setSigLevel(). */ inline SignatureLevel Manager::sigLevel() const { return m_sigLevel; } /*! * \brief Sets the signature level. */ inline void Manager::setSigLevel(SignatureLevel sigLevel) { m_sigLevel = sigLevel; } /*! * \brief Returns the signature level used when opening local files. * * The signature level is read from the pacman config * when parsePacmanConfig() is called or can be set * manually using setSigLevel(). */ inline SignatureLevel Manager::localFileSigLevel() const { return m_localFileSigLevel; } /*! * \brief Sets the signature level used when opening local files. */ inline void Manager::setLocalFileSigLevel(SignatureLevel sigLevel) { m_localFileSigLevel = sigLevel; } /*! * \brief Returns the Pacman cache directory. * \remarks This is read from the Pacman configuration. */ inline const QString &Manager::pacmanCacheDir() const { return m_pacmanCacheDir; } inline const UserRepository *Manager::userRepository() const { return m_userRepo.get(); } inline UserRepository *Manager::userRepository() { return m_userRepo.get(); } /*! * \brief Returns the local data base. */ inline const AlpmDatabase *Manager::localDatabase() const { return m_localDb.get(); } /*! * \brief Returns the local data base. */ inline AlpmDatabase *Manager::localDatabase() { return m_localDb.get(); } } #endif // ALPM_MANAGER_H