repoindex/lib/alpm/manager.h

236 lines
6.4 KiB
C
Raw Normal View History

2015-08-10 22:46:01 +02:00
#ifndef ALPM_MANAGER_H
#define ALPM_MANAGER_H
#include "./upgradelookup.h"
#include "./alpmpackage.h"
2015-08-10 22:46:01 +02:00
#include <QJsonObject>
2015-08-10 22:46:01 +02:00
#include <QJsonArray>
#include <QMutex>
2016-02-25 22:53:33 +01:00
#include <QAtomicInteger>
#include <QObject>
2015-08-10 22:46:01 +02:00
#include <map>
2015-09-04 14:37:01 +02:00
#include <memory>
2015-08-10 22:46:01 +02:00
2016-01-18 20:34:29 +01:00
QT_FORWARD_DECLARE_CLASS(QTimer)
namespace RepoIndex {
2015-08-10 22:46:01 +02:00
class Config;
2015-09-04 14:37:01 +02:00
class UserRepository;
class AlpmDatabase;
2016-02-14 23:48:43 +01:00
enum class RepositoryUsage;
2015-08-10 22:46:01 +02:00
2016-02-25 22:53:33 +01:00
class Manager : public QObject
2015-08-10 22:46:01 +02:00
{
2016-02-25 22:53:33 +01:00
Q_OBJECT
2015-08-10 22:46:01 +02:00
public:
enum PackageInfoPart {
None = 0x0,
Basics = 0x1,
Details = 0x2,
};
Q_DECLARE_FLAGS(PackageInfoParts, PackageInfoPart)
2016-02-25 22:53:33 +01:00
explicit Manager(const Config &config, QObject *parent = nullptr);
2015-08-10 22:46:01 +02:00
~Manager();
// configuration, signature level, etc
const Config &config() const;
2016-02-14 23:48:43 +01:00
SignatureLevel sigLevel() const;
void setSigLevel(SignatureLevel sigLevel);
SignatureLevel localFileSigLevel() const;
void setLocalFileSigLevel(SignatureLevel sigLevel);
const QString &pacmanCacheDir() const;
2016-02-14 23:48:43 +01:00
static SignatureLevel parseSigLevel(const std::string &sigLevelStr = std::string());
static RepositoryUsage parseUsage(const std::string &usageStr);
void addLocalDatabase();
void removeAllDatabases();
void addDataBasesFromPacmanConfig();
void addDatabasesFromRepoIndexConfig();
2016-02-25 22:53:33 +01:00
void initAlpmDataBases();
void computeRequiredBy(Repository *repo);
2016-01-18 20:34:29 +01:00
// caching
bool writeCacheBeforeGone() const;
void setWriteCacheBeforeGone(bool writeCacheBeforeGone);
bool isAutoCacheMaintenanceEnabled() const;
void setAutoCacheMaintenanceEnabled(bool enabled);
2016-02-28 02:33:25 +01:00
Q_SLOT void writeCache();
Q_SLOT void restoreCache();
Q_SLOT void cleanCache();
Q_SLOT void wipeCache();
Q_SLOT void maintainCache();
2016-02-25 22:53:33 +01:00
// updating
bool isAutoUpdateEnabled() const;
void setAutoUpdateEnabled(bool enabled);
2016-02-28 02:33:25 +01:00
Q_SLOT void updateAlpmDatabases();
Q_SLOT void forceUpdateAlpmDatabases();
2015-08-10 22:46:01 +02:00
// 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;
2015-09-04 14:37:01 +02:00
// repository lookup
2016-02-25 22:53:33 +01:00
const AlpmDatabase *localDatabase() const;
AlpmDatabase *localDatabase();
2015-12-08 18:59:17 +01:00
const std::map<QString, AlpmDatabase *> &syncDatabases() const;
const AlpmDatabase *databaseByName(const QString &dbName) const;
AlpmDatabase *databaseByName(const QString &dbName);
2015-09-04 14:37:01 +02:00
const Repository *repositoryByName(const QString &name) const;
Repository *repositoryByName(const QString &name);
const UserRepository *userRepository() const;
UserRepository *userRepository();
2016-02-15 18:26:05 +01:00
QString findDatabasePath(const QString &name, bool updatesRequired, bool printError) const;
QString proposedDatabasePath(const QString &name, bool files) const;
2015-08-10 22:46:01 +02:00
// JSON serialization, handling JSON requests
const QJsonObject &basicRepoInfo() const;
2016-02-25 22:53:33 +01:00
QJsonArray packageInfo(const QJsonObject &pkgSelection, PackageInfoPart part) const;
2015-08-10 22:46:01 +02:00
const QJsonArray &groupInfo() const;
2020-03-09 18:45:47 +01:00
Q_SIGNALS:
2016-02-25 22:53:33 +01:00
void updatesAvailable();
2020-03-08 14:12:22 +01:00
private Q_SLOTS:
2016-02-25 22:53:33 +01:00
void invalidateCachedJsonSerialization();
void emitUpdatesAvailable();
private:
void connectRepository(Repository *repo);
2015-08-10 22:46:01 +02:00
private:
const Config &m_config;
bool m_writeCacheBeforeGone;
2016-01-18 20:34:29 +01:00
std::unique_ptr<QTimer> m_cacheTimer;
2016-02-25 22:53:33 +01:00
std::unique_ptr<QTimer> m_updateTimer;
2016-02-14 23:48:43 +01:00
SignatureLevel m_sigLevel;
SignatureLevel m_localFileSigLevel;
QString m_pacmanCacheDir;
2015-09-04 14:37:01 +02:00
std::unique_ptr<UserRepository> m_userRepo;
std::unique_ptr<AlpmDatabase> m_localDb;
2015-12-08 18:59:17 +01:00
std::list<std::unique_ptr<AlpmDatabase> > m_syncDbs;
std::map<QString, AlpmDatabase *> m_syncDbMap;
mutable QJsonObject m_basicRepoInfo;
mutable QMutex m_basicRepoInfoMutex;
2015-08-10 22:46:01 +02:00
mutable QJsonArray m_groupInfo;
mutable QMutex m_groupInfoMutex;
2015-08-10 22:46:01 +02:00
};
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;
}
2015-08-10 22:46:01 +02:00
/*!
* \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().
*/
2016-02-14 23:48:43 +01:00
inline SignatureLevel Manager::sigLevel() const
2015-08-10 22:46:01 +02:00
{
return m_sigLevel;
}
/*!
* \brief Sets the signature level.
*/
2016-02-14 23:48:43 +01:00
inline void Manager::setSigLevel(SignatureLevel sigLevel)
2015-08-10 22:46:01 +02:00
{
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().
*/
2016-02-14 23:48:43 +01:00
inline SignatureLevel Manager::localFileSigLevel() const
2015-08-10 22:46:01 +02:00
{
return m_localFileSigLevel;
}
/*!
* \brief Sets the signature level used when opening local files.
*/
2016-02-14 23:48:43 +01:00
inline void Manager::setLocalFileSigLevel(SignatureLevel sigLevel)
2015-08-10 22:46:01 +02:00
{
m_localFileSigLevel = sigLevel;
}
/*!
* \brief Returns the Pacman cache directory.
2015-08-10 22:46:01 +02:00
* \remarks This is read from the Pacman configuration.
*/
inline const QString &Manager::pacmanCacheDir() const
{
return m_pacmanCacheDir;
}
2015-09-04 14:37:01 +02:00
inline const UserRepository *Manager::userRepository() const
{
return m_userRepo.get();
}
inline UserRepository *Manager::userRepository()
{
return m_userRepo.get();
}
/*!
* \brief Returns the local data base.
*/
2016-02-25 22:53:33 +01:00
inline const AlpmDatabase *Manager::localDatabase() const
{
2015-09-04 14:37:01 +02:00
return m_localDb.get();
}
2015-09-04 14:37:01 +02:00
/*!
* \brief Returns the local data base.
*/
2016-02-25 22:53:33 +01:00
inline AlpmDatabase *Manager::localDatabase()
2015-08-10 22:46:01 +02:00
{
2015-09-04 14:37:01 +02:00
return m_localDb.get();
2015-08-10 22:46:01 +02:00
}
}
#endif // ALPM_MANAGER_H