add install adn remove completed
This commit is contained in:
@@ -45,8 +45,10 @@ qt_add_qml_module(apparchpack
|
|||||||
qml/console/ConsolePanel.qml
|
qml/console/ConsolePanel.qml
|
||||||
qml/lists/UpdateList.qml
|
qml/lists/UpdateList.qml
|
||||||
qml/lists/SearchList.qml
|
qml/lists/SearchList.qml
|
||||||
|
qml/lists/InstalledList.qml
|
||||||
qml/lists/ConsoleList.qml
|
qml/lists/ConsoleList.qml
|
||||||
qml/dialogs/PasswordDialog.qml
|
qml/dialogs/PasswordDialog.qml
|
||||||
|
qml/dialogs/RemoveDialog.qml
|
||||||
SOURCES
|
SOURCES
|
||||||
cpp/utils/utils.hpp
|
cpp/utils/utils.hpp
|
||||||
cpp/utils/utils.cpp
|
cpp/utils/utils.cpp
|
||||||
@@ -62,6 +64,8 @@ qt_add_qml_module(apparchpack
|
|||||||
cpp/managers/searchmanager/searchmanager.cpp
|
cpp/managers/searchmanager/searchmanager.cpp
|
||||||
cpp/managers/installmanager/installmanager.hpp
|
cpp/managers/installmanager/installmanager.hpp
|
||||||
cpp/managers/installmanager/installmanager.cpp
|
cpp/managers/installmanager/installmanager.cpp
|
||||||
|
cpp/managers/removemanager/removemanager.hpp
|
||||||
|
cpp/managers/removemanager/removemanager.cpp
|
||||||
cpp/managers/updatemanager/updatemanager.hpp
|
cpp/managers/updatemanager/updatemanager.hpp
|
||||||
cpp/managers/updatemanager/updatemanager.cpp
|
cpp/managers/updatemanager/updatemanager.cpp
|
||||||
)
|
)
|
||||||
@@ -74,6 +78,7 @@ target_include_directories(apparchpack PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/cpp/m
|
|||||||
target_include_directories(apparchpack PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/cpp/managers/passwordmanager)
|
target_include_directories(apparchpack PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/cpp/managers/passwordmanager)
|
||||||
target_include_directories(apparchpack PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/cpp/managers/searchmanager)
|
target_include_directories(apparchpack PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/cpp/managers/searchmanager)
|
||||||
target_include_directories(apparchpack PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/cpp/managers/installmanager)
|
target_include_directories(apparchpack PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/cpp/managers/installmanager)
|
||||||
|
target_include_directories(apparchpack PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/cpp/managers/removemanager)
|
||||||
|
|
||||||
target_link_libraries(apparchpack PRIVATE Qt6::Quick)
|
target_link_libraries(apparchpack PRIVATE Qt6::Quick)
|
||||||
|
|
||||||
|
|||||||
33
Main.qml
33
Main.qml
@@ -46,11 +46,23 @@ ApplicationWindow {
|
|||||||
ProcessManager.install(name)
|
ProcessManager.install(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function requestRemove(name) {
|
||||||
|
if (ProcessManager.passwordEmpty())
|
||||||
|
{
|
||||||
|
passwordDialog.action = "remove"
|
||||||
|
passwordDialog.packageName = name
|
||||||
|
passwordDialog.open()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ProcessManager.removePackage(name)
|
||||||
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: ProcessManager
|
target: ProcessManager
|
||||||
function onStatus_changed() {
|
function onStatus_changed() {
|
||||||
if (ProcessManager.status === ProcessManager.Status.Updating
|
if (ProcessManager.status === ProcessManager.Status.Updating
|
||||||
|| ProcessManager.status === ProcessManager.Status.Installing)
|
|| ProcessManager.status === ProcessManager.Status.Installing
|
||||||
|
|| ProcessManager.status === ProcessManager.Status.Removing)
|
||||||
root.consoleOpen = true
|
root.consoleOpen = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,6 +72,8 @@ ApplicationWindow {
|
|||||||
passwordDialog.accept();
|
passwordDialog.accept();
|
||||||
if (passwordDialog.action === "install")
|
if (passwordDialog.action === "install")
|
||||||
ProcessManager.install(passwordDialog.packageName)
|
ProcessManager.install(passwordDialog.packageName)
|
||||||
|
else if (passwordDialog.action === "remove")
|
||||||
|
ProcessManager.removePackage(passwordDialog.packageName)
|
||||||
else
|
else
|
||||||
ProcessManager.update()
|
ProcessManager.update()
|
||||||
}
|
}
|
||||||
@@ -132,6 +146,18 @@ ApplicationWindow {
|
|||||||
|
|
||||||
Pages.DeletePg {
|
Pages.DeletePg {
|
||||||
id: pgDelete
|
id: pgDelete
|
||||||
|
installedPackages: ProcessManager.installedPackages
|
||||||
|
loadingInstalled: ProcessManager.loadingInstalled
|
||||||
|
installedError: ProcessManager.installedError
|
||||||
|
busy: ProcessManager.status !== ProcessManager.Status.Null
|
||||||
|
removing: ProcessManager.status === ProcessManager.Status.Removing
|
||||||
|
removingPackage: ProcessManager.removingPackage
|
||||||
|
onReloadRequested: ProcessManager.loadInstalledPackages()
|
||||||
|
onFilterRequested: (query) => ProcessManager.filterInstalledPackages(query)
|
||||||
|
onRemoveRequested: (name) => {
|
||||||
|
removeDialog.packageName = name
|
||||||
|
removeDialog.open()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,4 +187,9 @@ ApplicationWindow {
|
|||||||
id: passwordDialog
|
id: passwordDialog
|
||||||
onPasswordSubmitted: (password) => ProcessManager.checkPassword(password)
|
onPasswordSubmitted: (password) => ProcessManager.checkPassword(password)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dialogs.RemoveDialog {
|
||||||
|
id: removeDialog
|
||||||
|
onConfirmed: root.requestRemove(removeDialog.packageName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,15 @@ ProcessManager::ProcessManager(QObject* parent) : QObject{ parent }
|
|||||||
connect(&m_install_manager, &InstallManager::add_log_line, &m_console_manager, &ConsoleManager::add_log_line);
|
connect(&m_install_manager, &InstallManager::add_log_line, &m_console_manager, &ConsoleManager::add_log_line);
|
||||||
connect(&m_install_manager, &InstallManager::append_update_log, &m_console_manager, &ConsoleManager::append_update_log);
|
connect(&m_install_manager, &InstallManager::append_update_log, &m_console_manager, &ConsoleManager::append_update_log);
|
||||||
connect(&m_install_manager, &InstallManager::finished, this, &ProcessManager::finished);
|
connect(&m_install_manager, &InstallManager::finished, this, &ProcessManager::finished);
|
||||||
|
|
||||||
|
// удаление: список установленных и сам процесс
|
||||||
|
connect(&m_remove_manager, &RemoveManager::installed_changed, this, &ProcessManager::installedPackagesChanged);
|
||||||
|
connect(&m_remove_manager, &RemoveManager::loading_changed, this, &ProcessManager::loadingInstalledChanged);
|
||||||
|
connect(&m_remove_manager, &RemoveManager::error_changed, this, &ProcessManager::installedErrorChanged);
|
||||||
|
connect(&m_remove_manager, &RemoveManager::console_clear, &m_console_manager, &ConsoleManager::clear);
|
||||||
|
connect(&m_remove_manager, &RemoveManager::add_log_line, &m_console_manager, &ConsoleManager::add_log_line);
|
||||||
|
connect(&m_remove_manager, &RemoveManager::append_update_log, &m_console_manager, &ConsoleManager::append_update_log);
|
||||||
|
connect(&m_remove_manager, &RemoveManager::finished, this, &ProcessManager::finished);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessManager::checkUpdates()
|
void ProcessManager::checkUpdates()
|
||||||
@@ -88,6 +97,7 @@ void ProcessManager::finished()
|
|||||||
{
|
{
|
||||||
m_password_manager.clear_askpass();
|
m_password_manager.clear_askpass();
|
||||||
set_installing_package({});
|
set_installing_package({});
|
||||||
|
set_removing_package({});
|
||||||
set_status(Status::Null);
|
set_status(Status::Null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +108,13 @@ void ProcessManager::set_installing_package(const QString& name)
|
|||||||
emit installingPackageChanged();
|
emit installingPackageChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProcessManager::set_removing_package(const QString& name)
|
||||||
|
{
|
||||||
|
if (m_removing_package == name) return;
|
||||||
|
m_removing_package = name;
|
||||||
|
emit removingPackageChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void ProcessManager::setPackageManager(int v)
|
void ProcessManager::setPackageManager(int v)
|
||||||
{
|
{
|
||||||
auto package_manager = static_cast<PackageManager>(v);
|
auto package_manager = static_cast<PackageManager>(v);
|
||||||
@@ -139,7 +156,13 @@ void ProcessManager::update()
|
|||||||
{
|
{
|
||||||
if (m_status != Status::Null || m_password_manager.check_running()) return;
|
if (m_status != Status::Null || m_password_manager.check_running()) return;
|
||||||
|
|
||||||
const auto res = check_askpas();
|
if (m_packages.isEmpty())
|
||||||
|
{
|
||||||
|
m_console_manager.add_log_line(QStringLiteral("обновление отменено: нечего обновлять, список пакетов пуст"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto res = prepare_askpass();
|
||||||
if (!res)
|
if (!res)
|
||||||
{
|
{
|
||||||
m_console_manager.add_log_line(QStringLiteral("обновление отменено: ") + res.error());
|
m_console_manager.add_log_line(QStringLiteral("обновление отменено: ") + res.error());
|
||||||
@@ -158,11 +181,16 @@ void ProcessManager::install(const QString& name)
|
|||||||
if (m_status != Status::Null || m_password_manager.check_running()) return;
|
if (m_status != Status::Null || m_password_manager.check_running()) return;
|
||||||
|
|
||||||
const QString package = name.trimmed();
|
const QString package = name.trimmed();
|
||||||
|
if (package.isEmpty())
|
||||||
|
{
|
||||||
|
m_console_manager.add_log_line(QStringLiteral("установка отменена: пустое имя пакета"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto res = check_askpas();
|
const auto res = prepare_askpass();
|
||||||
if (!res)
|
if (!res)
|
||||||
{
|
{
|
||||||
m_console_manager.add_log_line(QStringLiteral("обновление отменено: ") + res.error());
|
m_console_manager.add_log_line(QStringLiteral("установка отменена: ") + res.error());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,18 +202,54 @@ void ProcessManager::install(const QString& name)
|
|||||||
if (m_package_manager == PackageManager::Pacman) m_install_manager.pacman(package, askpass);
|
if (m_package_manager == PackageManager::Pacman) m_install_manager.pacman(package, askpass);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::expected<QString, QString> ProcessManager::check_askpas()
|
void ProcessManager::loadInstalledPackages()
|
||||||
|
{
|
||||||
|
if (m_status != Status::Null) return;
|
||||||
|
m_remove_manager.load_installed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProcessManager::filterInstalledPackages(const QString& query)
|
||||||
|
{
|
||||||
|
m_remove_manager.filter_installed(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProcessManager::removePackage(const QString& name)
|
||||||
|
{
|
||||||
|
if (m_status != Status::Null || m_password_manager.check_running()) return;
|
||||||
|
|
||||||
|
const QString package = name.trimmed();
|
||||||
|
if (package.isEmpty())
|
||||||
|
{
|
||||||
|
m_console_manager.add_log_line(QStringLiteral("удаление отменено: пустое имя пакета"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto res = prepare_askpass();
|
||||||
|
if (!res)
|
||||||
|
{
|
||||||
|
m_console_manager.add_log_line(QStringLiteral("удаление отменено: ") + res.error());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
set_removing_package(package);
|
||||||
|
set_status(Status::Removing);
|
||||||
|
|
||||||
|
if (m_package_manager == PackageManager::Yay) m_remove_manager.yay(package, *res);
|
||||||
|
if (m_package_manager == PackageManager::Pacman) m_remove_manager.pacman(package, *res);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::expected<QString, QString> ProcessManager::prepare_askpass()
|
||||||
{
|
{
|
||||||
if (QFileInfo::exists(QString::fromLatin1(m_db_lck)))
|
if (QFileInfo::exists(QString::fromLatin1(m_db_lck)))
|
||||||
return std::unexpected(QStringLiteral("занят %1: возможно, работает другой pacman или остался stale lock").arg(QString::fromLatin1(m_db_lck)));
|
return std::unexpected(QStringLiteral("занят %1: возможно, работает другой pacman или остался stale lock")
|
||||||
|
.arg(QString::fromLatin1(m_db_lck)));
|
||||||
|
|
||||||
QString askpass;
|
if (m_password_manager.password_empty())
|
||||||
if (m_packages.isEmpty()) return std::unexpected(QStringLiteral("нечего обновлять: package list пустой"));
|
return std::unexpected(QStringLiteral("пароль не введён"));
|
||||||
|
|
||||||
if (m_password_manager.password_empty()) return std::unexpected(QStringLiteral("пароль пустой, обновление остановлено"));
|
const QString askpass = m_password_manager.askpass_path();
|
||||||
|
if (askpass.isEmpty())
|
||||||
askpass = m_password_manager.askpass_path();
|
return std::unexpected(QStringLiteral("не удалось подготовить askpass-хелпер"));
|
||||||
if (askpass.isEmpty()) return std::unexpected(QStringLiteral("не могу создать askpass helper для товего менеджера"));
|
|
||||||
|
|
||||||
return askpass;
|
return askpass;
|
||||||
}
|
}
|
||||||
@@ -212,6 +276,10 @@ QVariantList ProcessManager::searchResults() const { return m_search_manager.res
|
|||||||
bool ProcessManager::searching() const { return m_search_manager.searching(); }
|
bool ProcessManager::searching() const { return m_search_manager.searching(); }
|
||||||
QString ProcessManager::searchError() const { return m_search_manager.error(); }
|
QString ProcessManager::searchError() const { return m_search_manager.error(); }
|
||||||
QString ProcessManager::installingPackage() const { return m_installing_package; }
|
QString ProcessManager::installingPackage() const { return m_installing_package; }
|
||||||
|
QVariantList ProcessManager::installedPackages() const { return m_remove_manager.installed_packages(); }
|
||||||
|
bool ProcessManager::loadingInstalled() const { return m_remove_manager.loading(); }
|
||||||
|
QString ProcessManager::installedError() const { return m_remove_manager.error(); }
|
||||||
|
QString ProcessManager::removingPackage() const { return m_removing_package; }
|
||||||
QVariantList ProcessManager::packages() const { return m_packages; }
|
QVariantList ProcessManager::packages() const { return m_packages; }
|
||||||
ProcessManager::Status ProcessManager::status() const { return m_status; }
|
ProcessManager::Status ProcessManager::status() const { return m_status; }
|
||||||
bool ProcessManager::passwordEmpty() const { return m_password_manager.password_empty(); }
|
bool ProcessManager::passwordEmpty() const { return m_password_manager.password_empty(); }
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "passwordmanager.hpp"
|
#include "passwordmanager.hpp"
|
||||||
#include "searchmanager.hpp"
|
#include "searchmanager.hpp"
|
||||||
#include "installmanager.hpp"
|
#include "installmanager.hpp"
|
||||||
|
#include "removemanager.hpp"
|
||||||
|
|
||||||
class ProcessManager : public QObject
|
class ProcessManager : public QObject
|
||||||
{
|
{
|
||||||
@@ -26,6 +27,10 @@ class ProcessManager : public QObject
|
|||||||
Q_PROPERTY(bool searching READ searching NOTIFY searchingChanged)
|
Q_PROPERTY(bool searching READ searching NOTIFY searchingChanged)
|
||||||
Q_PROPERTY(QString searchError READ searchError NOTIFY searchErrorChanged)
|
Q_PROPERTY(QString searchError READ searchError NOTIFY searchErrorChanged)
|
||||||
Q_PROPERTY(QString installingPackage READ installingPackage NOTIFY installingPackageChanged)
|
Q_PROPERTY(QString installingPackage READ installingPackage NOTIFY installingPackageChanged)
|
||||||
|
Q_PROPERTY(QVariantList installedPackages READ installedPackages NOTIFY installedPackagesChanged)
|
||||||
|
Q_PROPERTY(bool loadingInstalled READ loadingInstalled NOTIFY loadingInstalledChanged)
|
||||||
|
Q_PROPERTY(QString installedError READ installedError NOTIFY installedErrorChanged)
|
||||||
|
Q_PROPERTY(QString removingPackage READ removingPackage NOTIFY removingPackageChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ProcessManager(QObject* parent = nullptr);
|
explicit ProcessManager(QObject* parent = nullptr);
|
||||||
@@ -43,6 +48,9 @@ class ProcessManager : public QObject
|
|||||||
Q_INVOKABLE void searchPackages(const QString& query);
|
Q_INVOKABLE void searchPackages(const QString& query);
|
||||||
Q_INVOKABLE void clearSearchResults();
|
Q_INVOKABLE void clearSearchResults();
|
||||||
Q_INVOKABLE void install(const QString& name);
|
Q_INVOKABLE void install(const QString& name);
|
||||||
|
Q_INVOKABLE void loadInstalledPackages();
|
||||||
|
Q_INVOKABLE void filterInstalledPackages(const QString& query);
|
||||||
|
Q_INVOKABLE void removePackage(const QString& name);
|
||||||
Q_INVOKABLE void setPackageManager(int v);
|
Q_INVOKABLE void setPackageManager(int v);
|
||||||
Q_INVOKABLE bool passwordEmpty() const;
|
Q_INVOKABLE bool passwordEmpty() const;
|
||||||
Q_INVOKABLE void update();
|
Q_INVOKABLE void update();
|
||||||
@@ -54,6 +62,10 @@ class ProcessManager : public QObject
|
|||||||
bool searching() const;
|
bool searching() const;
|
||||||
QString searchError() const;
|
QString searchError() const;
|
||||||
QString installingPackage() const;
|
QString installingPackage() const;
|
||||||
|
QVariantList installedPackages() const;
|
||||||
|
bool loadingInstalled() const;
|
||||||
|
QString installedError() const;
|
||||||
|
QString removingPackage() const;
|
||||||
QVariantList packages() const;
|
QVariantList packages() const;
|
||||||
Status status() const;
|
Status status() const;
|
||||||
|
|
||||||
@@ -64,6 +76,7 @@ class ProcessManager : public QObject
|
|||||||
PasswordManager m_password_manager;
|
PasswordManager m_password_manager;
|
||||||
SearchManager m_search_manager;
|
SearchManager m_search_manager;
|
||||||
InstallManager m_install_manager;
|
InstallManager m_install_manager;
|
||||||
|
RemoveManager m_remove_manager;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PackageManager m_package_manager = PackageManager::Yay;
|
PackageManager m_package_manager = PackageManager::Yay;
|
||||||
@@ -71,12 +84,14 @@ class ProcessManager : public QObject
|
|||||||
QVariantList m_packages;
|
QVariantList m_packages;
|
||||||
int m_package_count = 0;
|
int m_package_count = 0;
|
||||||
QString m_installing_package;
|
QString m_installing_package;
|
||||||
|
QString m_removing_package;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void set_packages(const QVariantList& v);
|
void set_packages(const QVariantList& v);
|
||||||
void set_status(Status s);
|
void set_status(Status s);
|
||||||
std::expected<QString, QString> check_askpas();
|
std::expected<QString, QString> prepare_askpass();
|
||||||
void set_installing_package(const QString& name);
|
void set_installing_package(const QString& name);
|
||||||
|
void set_removing_package(const QString& name);
|
||||||
void finished();
|
void finished();
|
||||||
void set_updating_flag(bool updated, bool updating);
|
void set_updating_flag(bool updated, bool updating);
|
||||||
|
|
||||||
@@ -89,6 +104,10 @@ class ProcessManager : public QObject
|
|||||||
void searchingChanged();
|
void searchingChanged();
|
||||||
void searchErrorChanged();
|
void searchErrorChanged();
|
||||||
void installingPackageChanged();
|
void installingPackageChanged();
|
||||||
|
void installedPackagesChanged();
|
||||||
|
void loadingInstalledChanged();
|
||||||
|
void installedErrorChanged();
|
||||||
|
void removingPackageChanged();
|
||||||
void passwordAccepted();
|
void passwordAccepted();
|
||||||
void passwordRejected(const QString& reason);
|
void passwordRejected(const QString& reason);
|
||||||
};
|
};
|
||||||
|
|||||||
347
cpp/managers/removemanager/removemanager.cpp
Normal file
347
cpp/managers/removemanager/removemanager.cpp
Normal file
@@ -0,0 +1,347 @@
|
|||||||
|
#include "removemanager.hpp"
|
||||||
|
#include <QDate>
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
#include <QTime>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
// "Wed Nov 11 22:50:08 2026" из pacman -Qi (при LC_ALL=C) -> секунды.
|
||||||
|
qint64 install_date_epoch(const QString& text)
|
||||||
|
{
|
||||||
|
const QStringList parts = text.split(QLatin1Char(' '), Qt::SkipEmptyParts);
|
||||||
|
if (parts.size() != 5) return 0;
|
||||||
|
|
||||||
|
static const QStringList months = {
|
||||||
|
QStringLiteral("Jan"), QStringLiteral("Feb"), QStringLiteral("Mar"),
|
||||||
|
QStringLiteral("Apr"), QStringLiteral("May"), QStringLiteral("Jun"),
|
||||||
|
QStringLiteral("Jul"), QStringLiteral("Aug"), QStringLiteral("Sep"),
|
||||||
|
QStringLiteral("Oct"), QStringLiteral("Nov"), QStringLiteral("Dec"),
|
||||||
|
};
|
||||||
|
|
||||||
|
const int month = months.indexOf(parts.at(1)) + 1;
|
||||||
|
if (month == 0) return 0;
|
||||||
|
|
||||||
|
const QDate date(parts.at(4).toInt(), month, parts.at(2).toInt());
|
||||||
|
const QTime time = QTime::fromString(parts.at(3), QStringLiteral("HH:mm:ss"));
|
||||||
|
if (!date.isValid() || !time.isValid()) return 0;
|
||||||
|
|
||||||
|
return QDateTime(date, time).toSecsSinceEpoch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RemoveManager::RemoveManager(QObject* parent) : QObject{ parent }
|
||||||
|
{
|
||||||
|
connect(&m_installed_process, &QProcess::finished, this, &RemoveManager::on_installed_finished);
|
||||||
|
connect(&m_installed_process, &QProcess::errorOccurred, this, &RemoveManager::on_installed_error);
|
||||||
|
|
||||||
|
m_remove_process.setProcessChannelMode(QProcess::MergedChannels);
|
||||||
|
connect(&m_remove_process, &QProcess::readyReadStandardOutput, this, &RemoveManager::on_ready_read);
|
||||||
|
connect(&m_remove_process, &QProcess::finished, this, &RemoveManager::on_process_finished);
|
||||||
|
connect(&m_remove_process, &QProcess::errorOccurred, this, &RemoveManager::on_process_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveManager::load_installed()
|
||||||
|
{
|
||||||
|
if (m_remove_process.state() != QProcess::NotRunning) return;
|
||||||
|
if (m_installed_process.state() != QProcess::NotRunning) return;
|
||||||
|
|
||||||
|
const QString pacman = QStandardPaths::findExecutable(QStringLiteral("pacman"));
|
||||||
|
if (pacman.isEmpty())
|
||||||
|
{
|
||||||
|
set_loading(false);
|
||||||
|
set_error(QStringLiteral("pacman не найден"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||||
|
env.insert(QStringLiteral("LC_ALL"), QStringLiteral("C"));
|
||||||
|
env.insert(QStringLiteral("COLUMNS"), QStringLiteral("300"));
|
||||||
|
m_installed_process.setProcessEnvironment(env);
|
||||||
|
|
||||||
|
set_error({});
|
||||||
|
set_loading(true);
|
||||||
|
m_installed_process.start(pacman, {QStringLiteral("-Qi")});
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveManager::filter_installed(const QString& query)
|
||||||
|
{
|
||||||
|
m_filter = query.trimmed();
|
||||||
|
apply_filter();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantList RemoveManager::installed_packages() const { return m_installed; }
|
||||||
|
|
||||||
|
bool RemoveManager::loading() const { return m_loading; }
|
||||||
|
|
||||||
|
QString RemoveManager::error() const { return m_error; }
|
||||||
|
|
||||||
|
void RemoveManager::on_installed_finished(int exit_code, QProcess::ExitStatus status)
|
||||||
|
{
|
||||||
|
const QByteArray output = m_installed_process.readAllStandardOutput();
|
||||||
|
const QString errors = QString::fromUtf8(m_installed_process.readAllStandardError()).trimmed();
|
||||||
|
|
||||||
|
set_loading(false);
|
||||||
|
|
||||||
|
if (status == QProcess::CrashExit)
|
||||||
|
{
|
||||||
|
set_error(QStringLiteral("не удалось получить список установленных пакетов"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exit_code != 0 && output.trimmed().isEmpty())
|
||||||
|
{
|
||||||
|
set_error(errors.isEmpty()
|
||||||
|
? QStringLiteral("не удалось получить список установленных пакетов")
|
||||||
|
: errors.section(QLatin1Char('\n'), -1).trimmed());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
parse_installed(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveManager::on_installed_error(QProcess::ProcessError error)
|
||||||
|
{
|
||||||
|
if (error != QProcess::FailedToStart) return;
|
||||||
|
|
||||||
|
set_loading(false);
|
||||||
|
set_error(QStringLiteral("не удалось запустить запрос установленных пакетов: ")
|
||||||
|
+ m_installed_process.errorString());
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveManager::parse_installed(const QByteArray& output)
|
||||||
|
{
|
||||||
|
QVariantList packages;
|
||||||
|
QVariantMap current;
|
||||||
|
|
||||||
|
auto flush = [&]() {
|
||||||
|
if (current.contains(QStringLiteral("name"))) packages.append(current);
|
||||||
|
current.clear();
|
||||||
|
};
|
||||||
|
|
||||||
|
const QStringList lines = QString::fromUtf8(output).split(QLatin1Char('\n'));
|
||||||
|
for (QString line : lines)
|
||||||
|
{
|
||||||
|
if (line.endsWith(QLatin1Char('\r'))) line.chop(1);
|
||||||
|
|
||||||
|
if (line.trimmed().isEmpty())
|
||||||
|
{
|
||||||
|
flush();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const qsizetype colon = line.indexOf(QLatin1Char(':'));
|
||||||
|
if (colon < 0) continue;
|
||||||
|
|
||||||
|
const QString key = line.left(colon).trimmed();
|
||||||
|
const QString value = line.mid(colon + 1).trimmed();
|
||||||
|
|
||||||
|
if (key == QStringLiteral("Name"))
|
||||||
|
{
|
||||||
|
if (current.contains(QStringLiteral("name"))) flush();
|
||||||
|
current.insert(QStringLiteral("name"), value);
|
||||||
|
}
|
||||||
|
else if (key == QStringLiteral("Version"))
|
||||||
|
{
|
||||||
|
current.insert(QStringLiteral("version"), value);
|
||||||
|
}
|
||||||
|
else if (key == QStringLiteral("Install Date"))
|
||||||
|
{
|
||||||
|
current.insert(QStringLiteral("installedAt"), install_date_epoch(value));
|
||||||
|
current.insert(QStringLiteral("installedAtText"), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
flush();
|
||||||
|
|
||||||
|
// Свежеустановленные пакеты — первыми.
|
||||||
|
std::sort(packages.begin(), packages.end(),
|
||||||
|
[](const QVariant &left, const QVariant &right) {
|
||||||
|
const QVariantMap left_package = left.toMap();
|
||||||
|
const QVariantMap right_package = right.toMap();
|
||||||
|
|
||||||
|
const qint64 left_date = left_package.value(QStringLiteral("installedAt")).toLongLong();
|
||||||
|
const qint64 right_date = right_package.value(QStringLiteral("installedAt")).toLongLong();
|
||||||
|
if (left_date != right_date) return left_date > right_date;
|
||||||
|
|
||||||
|
return left_package.value(QStringLiteral("name")).toString()
|
||||||
|
.compare(right_package.value(QStringLiteral("name")).toString(),
|
||||||
|
Qt::CaseInsensitive) < 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
m_all_installed = packages;
|
||||||
|
apply_filter();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveManager::apply_filter()
|
||||||
|
{
|
||||||
|
QVariantList filtered;
|
||||||
|
filtered.reserve(m_all_installed.size());
|
||||||
|
|
||||||
|
for (const QVariant &item : m_all_installed)
|
||||||
|
{
|
||||||
|
const QVariantMap package = item.toMap();
|
||||||
|
if (m_filter.isEmpty()
|
||||||
|
|| package.value(QStringLiteral("name")).toString()
|
||||||
|
.contains(m_filter, Qt::CaseInsensitive))
|
||||||
|
filtered.append(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_installed = filtered;
|
||||||
|
emit installed_changed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveManager::yay(const QString& name, const QString& askpass)
|
||||||
|
{
|
||||||
|
if (m_remove_process.state() != QProcess::NotRunning) return;
|
||||||
|
|
||||||
|
const QString yay = QStandardPaths::findExecutable(QStringLiteral("yay"));
|
||||||
|
if (yay.isEmpty())
|
||||||
|
{
|
||||||
|
fail(QStringLiteral("yay не найден"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QStringList args = {
|
||||||
|
QStringLiteral("--sudoflags=-A"),
|
||||||
|
QStringLiteral("--noconfirm"),
|
||||||
|
QStringLiteral("-R"),
|
||||||
|
name,
|
||||||
|
};
|
||||||
|
|
||||||
|
start_process(yay, args, name, askpass);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveManager::pacman(const QString& name, const QString& askpass)
|
||||||
|
{
|
||||||
|
if (m_remove_process.state() != QProcess::NotRunning) return;
|
||||||
|
|
||||||
|
const QString pacman = QStandardPaths::findExecutable(QStringLiteral("pacman"));
|
||||||
|
if (pacman.isEmpty())
|
||||||
|
{
|
||||||
|
fail(QStringLiteral("pacman не найден"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString sudo = QStandardPaths::findExecutable(QStringLiteral("sudo"));
|
||||||
|
if (sudo.isEmpty())
|
||||||
|
{
|
||||||
|
fail(QStringLiteral("sudo не найден"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QStringList args = {
|
||||||
|
QStringLiteral("-A"),
|
||||||
|
pacman,
|
||||||
|
QStringLiteral("-R"),
|
||||||
|
QStringLiteral("--noconfirm"),
|
||||||
|
name,
|
||||||
|
};
|
||||||
|
|
||||||
|
start_process(sudo, args, name, askpass);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveManager::start_process(const QString& program, const QStringList& args,
|
||||||
|
const QString& name, const QString& askpass)
|
||||||
|
{
|
||||||
|
if (m_remove_process.state() != QProcess::NotRunning) return;
|
||||||
|
|
||||||
|
m_removing_name = name;
|
||||||
|
|
||||||
|
emit console_clear();
|
||||||
|
emit add_log_line(QStringLiteral("remove: started ") + name);
|
||||||
|
|
||||||
|
m_remove_process.setProcessEnvironment(remove_environment(askpass));
|
||||||
|
m_remove_process.start(program, args);
|
||||||
|
m_remove_process.closeWriteChannel();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveManager::on_ready_read()
|
||||||
|
{
|
||||||
|
const QByteArray chunk = m_remove_process.readAllStandardOutput();
|
||||||
|
emit append_update_log(chunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveManager::on_process_finished(int exit_code, QProcess::ExitStatus status)
|
||||||
|
{
|
||||||
|
const QByteArray tail = m_remove_process.readAllStandardOutput();
|
||||||
|
emit append_update_log(tail);
|
||||||
|
|
||||||
|
if (status != QProcess::CrashExit && exit_code == 0)
|
||||||
|
{
|
||||||
|
stop_remove(true, {});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString reason = status == QProcess::CrashExit
|
||||||
|
? QStringLiteral("crashed")
|
||||||
|
: QStringLiteral("exit code %1").arg(exit_code);
|
||||||
|
stop_remove(false, reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveManager::on_process_error(QProcess::ProcessError error)
|
||||||
|
{
|
||||||
|
if (error != QProcess::FailedToStart) return;
|
||||||
|
|
||||||
|
emit add_log_line(QStringLiteral("remove: failed to start: ") + m_remove_process.errorString());
|
||||||
|
emit finished();
|
||||||
|
}
|
||||||
|
|
||||||
|
QProcessEnvironment RemoveManager::remove_environment(const QString& askpass) const
|
||||||
|
{
|
||||||
|
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||||
|
env.insert(QStringLiteral("SUDO_ASKPASS"), askpass);
|
||||||
|
env.insert(QStringLiteral("SUDO_ASKPASS_REQUIRE"), QStringLiteral("force"));
|
||||||
|
env.insert(QStringLiteral("LC_ALL"), QStringLiteral("C"));
|
||||||
|
env.insert(QStringLiteral("COLUMNS"), QStringLiteral("300"));
|
||||||
|
return env;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveManager::fail(const QString& reason)
|
||||||
|
{
|
||||||
|
emit console_clear();
|
||||||
|
emit add_log_line(QStringLiteral("remove: failed: ") + reason);
|
||||||
|
emit finished();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveManager::stop_remove(bool success, const QString& reason)
|
||||||
|
{
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
emit add_log_line(QStringLiteral("remove: finished"));
|
||||||
|
remove_from_installed(m_removing_name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
emit add_log_line(QStringLiteral("remove: failed: ") + reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
emit finished();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveManager::remove_from_installed(const QString& name)
|
||||||
|
{
|
||||||
|
for (qsizetype i = 0; i < m_all_installed.size(); ++i)
|
||||||
|
{
|
||||||
|
if (m_all_installed.at(i).toMap().value(QStringLiteral("name")).toString() == name)
|
||||||
|
{
|
||||||
|
m_all_installed.removeAt(i);
|
||||||
|
apply_filter();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveManager::set_loading(bool value)
|
||||||
|
{
|
||||||
|
if (m_loading == value) return;
|
||||||
|
m_loading = value;
|
||||||
|
emit loading_changed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveManager::set_error(const QString& error)
|
||||||
|
{
|
||||||
|
if (m_error == error) return;
|
||||||
|
m_error = error;
|
||||||
|
emit error_changed();
|
||||||
|
}
|
||||||
61
cpp/managers/removemanager/removemanager.hpp
Normal file
61
cpp/managers/removemanager/removemanager.hpp
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QProcess>
|
||||||
|
#include <QProcessEnvironment>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QVariantList>
|
||||||
|
|
||||||
|
class RemoveManager : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit RemoveManager(QObject* parent = nullptr);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void load_installed();
|
||||||
|
void filter_installed(const QString& query);
|
||||||
|
QVariantList installed_packages() const;
|
||||||
|
bool loading() const;
|
||||||
|
QString error() const;
|
||||||
|
void yay(const QString& name, const QString& askpass);
|
||||||
|
void pacman(const QString& name, const QString& askpass);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void start_process(const QString& program, const QStringList& args,
|
||||||
|
const QString& name, const QString& askpass);
|
||||||
|
void on_installed_finished(int exit_code, QProcess::ExitStatus status);
|
||||||
|
void on_installed_error(QProcess::ProcessError error);
|
||||||
|
void parse_installed(const QByteArray& output);
|
||||||
|
void apply_filter();
|
||||||
|
void remove_from_installed(const QString& name);
|
||||||
|
|
||||||
|
void on_ready_read();
|
||||||
|
void on_process_finished(int exit_code, QProcess::ExitStatus status);
|
||||||
|
void on_process_error(QProcess::ProcessError error);
|
||||||
|
QProcessEnvironment remove_environment(const QString& askpass) const;
|
||||||
|
void fail(const QString& reason);
|
||||||
|
void stop_remove(bool success, const QString& reason);
|
||||||
|
void set_loading(bool value);
|
||||||
|
void set_error(const QString& error);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QProcess m_installed_process;
|
||||||
|
QProcess m_remove_process;
|
||||||
|
QVariantList m_all_installed;
|
||||||
|
QVariantList m_installed;
|
||||||
|
QString m_filter;
|
||||||
|
QString m_error;
|
||||||
|
QString m_removing_name;
|
||||||
|
bool m_loading = false;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void installed_changed();
|
||||||
|
void loading_changed();
|
||||||
|
void error_changed();
|
||||||
|
void append_update_log(const QByteArray& chunk);
|
||||||
|
void add_log_line(const QString& line);
|
||||||
|
void console_clear();
|
||||||
|
void finished();
|
||||||
|
};
|
||||||
@@ -13,6 +13,7 @@ Button {
|
|||||||
enabled: status === ProcessManager.Status.Null && root.packageCount > 0
|
enabled: status === ProcessManager.Status.Null && root.packageCount > 0
|
||||||
visible: status !== ProcessManager.Status.Updating
|
visible: status !== ProcessManager.Status.Updating
|
||||||
&& status !== ProcessManager.Status.Installing
|
&& status !== ProcessManager.Status.Installing
|
||||||
|
&& status !== ProcessManager.Status.Removing
|
||||||
text: status === ProcessManager.Status.Updating ? "Обновление..." : status === ProcessManager.Status.Checking ? "Проверка..." : root.packageCount > 0 ? "Обновить систему" : "✓ Всё обновлено"
|
text: status === ProcessManager.Status.Updating ? "Обновление..." : status === ProcessManager.Status.Checking ? "Проверка..." : root.packageCount > 0 ? "Обновить систему" : "✓ Всё обновлено"
|
||||||
|
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
|
|||||||
@@ -79,40 +79,6 @@ Popup {
|
|||||||
onClicked: root.pick(ProcessManager.PackageManager.Pacman)
|
onClicked: root.pick(ProcessManager.PackageManager.Pacman)
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.topMargin: 2
|
|
||||||
Layout.preferredHeight: 1
|
|
||||||
color: Theme.color4
|
|
||||||
}
|
|
||||||
|
|
||||||
// Пункт меню «История»: открывает список завершённых заданий.
|
|
||||||
Button {
|
|
||||||
id: historyButton
|
|
||||||
text: "История"
|
|
||||||
Layout.fillWidth: true
|
|
||||||
leftPadding: 8
|
|
||||||
rightPadding: 8
|
|
||||||
topPadding: 8
|
|
||||||
bottomPadding: 8
|
|
||||||
|
|
||||||
onClicked: {
|
|
||||||
root.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
background: Rectangle {
|
|
||||||
radius: 3
|
|
||||||
color: historyButton.down ? Theme.color4 : historyButton.hovered ? Theme.color5 : Theme.colorTransparent
|
|
||||||
}
|
|
||||||
|
|
||||||
contentItem: Text {
|
|
||||||
text: historyButton.text
|
|
||||||
font.pixelSize: 13
|
|
||||||
color: Theme.color2
|
|
||||||
horizontalAlignment: Text.AlignLeft
|
|
||||||
verticalAlignment: Text.AlignVCenter
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onOpened: {
|
onOpened: {
|
||||||
|
|||||||
121
qml/dialogs/RemoveDialog.qml
Normal file
121
qml/dialogs/RemoveDialog.qml
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
import QtQuick
|
||||||
|
import QtQuick.Controls
|
||||||
|
import QtQuick.Layouts
|
||||||
|
|
||||||
|
Dialog {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
x: (parent.width - width) / 2
|
||||||
|
y: (parent.height - height) / 2
|
||||||
|
width: 380
|
||||||
|
padding: 16
|
||||||
|
modal: true
|
||||||
|
parent: Overlay.overlay
|
||||||
|
closePolicy: Popup.CloseOnEscape
|
||||||
|
|
||||||
|
property string packageName: ""
|
||||||
|
|
||||||
|
signal confirmed()
|
||||||
|
|
||||||
|
onAccepted: root.confirmed()
|
||||||
|
|
||||||
|
background: Rectangle {
|
||||||
|
color: Theme.color1
|
||||||
|
radius: 3
|
||||||
|
border.width: 1
|
||||||
|
border.color: Theme.color4
|
||||||
|
}
|
||||||
|
|
||||||
|
contentItem: ColumnLayout {
|
||||||
|
spacing: 10
|
||||||
|
|
||||||
|
Label {
|
||||||
|
text: "Удалить пакет?"
|
||||||
|
color: Theme.color2
|
||||||
|
font.pixelSize: 15
|
||||||
|
font.bold: true
|
||||||
|
Layout.fillWidth: true
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
text: root.packageName
|
||||||
|
color: Theme.color7
|
||||||
|
font.pixelSize: 13
|
||||||
|
font.family: "monospace"
|
||||||
|
wrapMode: Text.WordWrap
|
||||||
|
Layout.fillWidth: true
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
text: "Пакет и его файлы будут удалены. Зависимости останутся."
|
||||||
|
color: Theme.color14
|
||||||
|
font.pixelSize: 12
|
||||||
|
wrapMode: Text.WordWrap
|
||||||
|
Layout.fillWidth: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
footer: Item {
|
||||||
|
implicitHeight: footerRow.implicitHeight + 22
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
id: footerRow
|
||||||
|
anchors.fill: parent
|
||||||
|
anchors.rightMargin: 18
|
||||||
|
spacing: 8
|
||||||
|
|
||||||
|
Item { Layout.fillWidth: true }
|
||||||
|
|
||||||
|
Button {
|
||||||
|
id: cancelButton
|
||||||
|
text: "✕ Отмена"
|
||||||
|
leftPadding: 14
|
||||||
|
rightPadding: 14
|
||||||
|
topPadding: 8
|
||||||
|
bottomPadding: 8
|
||||||
|
|
||||||
|
onClicked: root.reject()
|
||||||
|
|
||||||
|
background: Rectangle {
|
||||||
|
radius: 4
|
||||||
|
color: cancelButton.down ? Theme.color4 : cancelButton.hovered ? Theme.color4 : Theme.colorTransparent
|
||||||
|
border.width: 1
|
||||||
|
border.color: Theme.color4
|
||||||
|
}
|
||||||
|
|
||||||
|
contentItem: Text {
|
||||||
|
text: cancelButton.text
|
||||||
|
font.pixelSize: 13
|
||||||
|
color: Theme.color2
|
||||||
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
id: removeButton
|
||||||
|
text: "✓ Удалить"
|
||||||
|
leftPadding: 14
|
||||||
|
rightPadding: 14
|
||||||
|
topPadding: 8
|
||||||
|
bottomPadding: 8
|
||||||
|
|
||||||
|
onClicked: root.accept()
|
||||||
|
|
||||||
|
background: Rectangle {
|
||||||
|
radius: 4
|
||||||
|
color: removeButton.down ? Theme.color11 : removeButton.hovered ? Theme.color6 : Theme.color10
|
||||||
|
}
|
||||||
|
|
||||||
|
contentItem: Text {
|
||||||
|
text: removeButton.text
|
||||||
|
font.pixelSize: 13
|
||||||
|
font.bold: true
|
||||||
|
color: Theme.color8
|
||||||
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
112
qml/lists/InstalledList.qml
Normal file
112
qml/lists/InstalledList.qml
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
pragma ComponentBehavior: Bound
|
||||||
|
|
||||||
|
import QtQuick
|
||||||
|
import QtQuick.Controls
|
||||||
|
import archpack
|
||||||
|
|
||||||
|
ListView {
|
||||||
|
id: root
|
||||||
|
clip: true
|
||||||
|
spacing: 2
|
||||||
|
model: root.packages
|
||||||
|
visible: count > 0
|
||||||
|
|
||||||
|
property var packages: []
|
||||||
|
property bool busy: false
|
||||||
|
property bool removing: false
|
||||||
|
property string removingPackage: ""
|
||||||
|
|
||||||
|
signal removeRequested(string name)
|
||||||
|
|
||||||
|
ScrollBar.vertical: ScrollBar {
|
||||||
|
policy: ScrollBar.AsNeeded
|
||||||
|
width: 6
|
||||||
|
}
|
||||||
|
|
||||||
|
delegate: Rectangle {
|
||||||
|
id: delegate
|
||||||
|
required property var modelData
|
||||||
|
|
||||||
|
width: root.width
|
||||||
|
height: 48
|
||||||
|
radius: 7
|
||||||
|
color: "transparent"
|
||||||
|
|
||||||
|
Text {
|
||||||
|
id: nameText
|
||||||
|
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.leftMargin: 8
|
||||||
|
anchors.right: dateText.left
|
||||||
|
anchors.rightMargin: 8
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.topMargin: 6
|
||||||
|
text: delegate.modelData.name
|
||||||
|
font.pixelSize: 13
|
||||||
|
font.family: "monospace"
|
||||||
|
color: Theme.color2
|
||||||
|
elide: Text.ElideRight
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
id: versionText
|
||||||
|
|
||||||
|
anchors.left: nameText.left
|
||||||
|
anchors.right: nameText.right
|
||||||
|
anchors.top: nameText.bottom
|
||||||
|
anchors.topMargin: 1
|
||||||
|
text: delegate.modelData.version
|
||||||
|
font.pixelSize: 10
|
||||||
|
color: Theme.color3
|
||||||
|
elide: Text.ElideRight
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
id: dateText
|
||||||
|
|
||||||
|
anchors.right: removeButton.left
|
||||||
|
anchors.rightMargin: 8
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
width: 170
|
||||||
|
horizontalAlignment: Text.AlignRight
|
||||||
|
text: delegate.modelData.installedAtText
|
||||||
|
font.pixelSize: 10
|
||||||
|
color: Theme.color12
|
||||||
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
id: removeButton
|
||||||
|
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.rightMargin: 8
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
width: 100
|
||||||
|
text: root.removing && root.removingPackage === delegate.modelData.name
|
||||||
|
? "Удаление..."
|
||||||
|
: "Удалить"
|
||||||
|
enabled: !root.busy
|
||||||
|
implicitHeight: 28
|
||||||
|
leftPadding: 10
|
||||||
|
rightPadding: 10
|
||||||
|
font.pixelSize: 11
|
||||||
|
|
||||||
|
onClicked: root.removeRequested(delegate.modelData.name)
|
||||||
|
|
||||||
|
background: Rectangle {
|
||||||
|
radius: 4
|
||||||
|
color: !removeButton.enabled ? Theme.color5
|
||||||
|
: removeButton.down ? Theme.color11
|
||||||
|
: removeButton.hovered ? Theme.color6
|
||||||
|
: Theme.color10
|
||||||
|
}
|
||||||
|
|
||||||
|
contentItem: Text {
|
||||||
|
text: removeButton.text
|
||||||
|
font: removeButton.font
|
||||||
|
color: removeButton.enabled ? Theme.color8 : Theme.color12
|
||||||
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,37 +1,92 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Layouts
|
|
||||||
import QtQuick.Window
|
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
|
import QtQuick.Layouts
|
||||||
|
import archpack
|
||||||
|
import "../lists" as Lists
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
|
property var installedPackages: []
|
||||||
|
property bool loadingInstalled: false
|
||||||
|
property string installedError: ""
|
||||||
|
property bool busy: false
|
||||||
|
property bool removing: false
|
||||||
|
property string removingPackage: ""
|
||||||
|
|
||||||
|
signal reloadRequested()
|
||||||
|
signal filterRequested(string query)
|
||||||
|
signal removeRequested(string name)
|
||||||
|
|
||||||
|
// Загружаем список при каждом входе на вкладку и после завершения операции.
|
||||||
|
onVisibleChanged: if (visible) root.reloadRequested()
|
||||||
|
onBusyChanged: if (!root.busy && root.visible) root.reloadRequested()
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
spacing: 8
|
spacing: 8
|
||||||
|
|
||||||
TextField {
|
TextField {
|
||||||
id: packageSearchField
|
id: filterField
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
placeholderText: "название установленного пакета"
|
placeholderText: "название установленного пакета"
|
||||||
placeholderTextColor: Theme.color3
|
placeholderTextColor: Theme.color3
|
||||||
selectByMouse: true
|
selectByMouse: true
|
||||||
color: Theme.color2
|
color: Theme.color2
|
||||||
font.pixelSize: 14
|
font.pixelSize: 14
|
||||||
|
enabled: !root.busy
|
||||||
|
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
color: "#313244"
|
color: Theme.color5
|
||||||
radius: 3
|
radius: 3
|
||||||
border.width: 1
|
border.width: 1
|
||||||
border.color: packageSearchField.activeFocus ? Theme.color6 : Theme.color4
|
border.color: filterField.activeFocus ? Theme.color6 : Theme.color4
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onTextChanged: root.filterRequested(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
|
|
||||||
|
Lists.InstalledList {
|
||||||
|
anchors.fill: parent
|
||||||
|
packages: root.installedPackages
|
||||||
|
busy: root.busy
|
||||||
|
removing: root.removing
|
||||||
|
removingPackage: root.removingPackage
|
||||||
|
onRemoveRequested: (name) => root.removeRequested(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
ColumnLayout {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
spacing: 8
|
||||||
|
visible: root.installedPackages.length === 0
|
||||||
|
|
||||||
|
BusyIndicator {
|
||||||
|
running: root.loadingInstalled
|
||||||
|
visible: root.loadingInstalled
|
||||||
|
Layout.alignment: Qt.AlignHCenter
|
||||||
|
implicitWidth: 24
|
||||||
|
implicitHeight: 24
|
||||||
|
|
||||||
|
palette.dark: Theme.color2
|
||||||
|
palette.text: Theme.color2
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
Layout.alignment: Qt.AlignHCenter
|
||||||
|
Layout.maximumWidth: Math.max(0, root.width - 40)
|
||||||
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
wrapMode: Text.WordWrap
|
||||||
|
text: root.loadingInstalled ? "загрузка списка..."
|
||||||
|
: root.installedError !== "" ? root.installedError
|
||||||
|
: "Ничего не найдено"
|
||||||
|
font.pixelSize: 13
|
||||||
|
color: root.installedError !== "" ? Theme.color7 : Theme.color3
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user