加入包管理器模块雏形

This commit is contained in:
RigoLigoRLC 2022-02-13 21:18:48 +08:00
parent f2e417e02a
commit 2221d5c816
10 changed files with 242 additions and 2 deletions

@ -87,6 +87,10 @@ set(SOURCE_FILES
inc/page/spkpagedownloads.h gui/page/spkpagedownloads.cpp
inc/page/spkpagesettings.h gui/page/spkpagesettings.cpp
inc/pkgs/spkpkgmgrbase.h
inc/pkgs/spkpkgmgrpacman.h src/pkgs/spkpkgmgrpacman.cpp
inc/pkgs/spkpkgmgrapt.h src/pkgs/spkpkgmgrapt.cpp
inc/spkstore.h src/spkstore.cpp
inc/spkuimsg.h src/spkuimsg.cpp
inc/spklogging.h src/spklogging.cpp

@ -4,6 +4,7 @@
#include "inc/page/spkpageuitest.h"
#include "spkpopup.h"
#include "spkui_general.h"
#include "pkgs/spkpkgmgrbase.h"
SpkUi::SpkPageUiTest::SpkPageUiTest(QWidget *parent) : QSplitter(parent)
{
@ -80,6 +81,10 @@ SpkUi::SpkPageUiTest::SpkPageUiTest(QWidget *parent) : QSplitter(parent)
ShowAbout->setText("Show About Dialog");
connect(ShowAbout, &QPushButton::clicked, [](){ SpkAbout::Show(); });
ShowPkgmgr = new QPushButton(this);
ShowPkgmgr->setText("Show Install Menu");
connect(ShowPkgmgr, &QPushButton::clicked, [](){ SpkPkgMgrBase::Instance()->ExecuteInstallation("", 0); });
SlideV = new QSlider(this);
SlideV->setObjectName("spk_pg_qsstest_slider_v");
SlideV->setOrientation(Qt::Vertical);
@ -106,6 +111,7 @@ SpkUi::SpkPageUiTest::SpkPageUiTest(QWidget *parent) : QSplitter(parent)
VLayTestWidgets->addWidget(PopupText);
VLayTestWidgets->addWidget(ShowPopup);
VLayTestWidgets->addWidget(ShowAbout);
VLayTestWidgets->addWidget(ShowPkgmgr);
VLayTestWidgets->addWidget(AppItem);
VLayTestWidgets->addWidget(DetailsWidget);

@ -52,7 +52,8 @@ namespace SpkUi
QLineEdit *PopupText;
QPushButton *ShowPopup,
*ShowAbout;
*ShowAbout,
*ShowPkgmgr;
public slots:
void SetStylesheet();

27
inc/pkgs/spkpkgmgrapt.h Normal file

@ -0,0 +1,27 @@
#pragma once
#include "spkpkgmgrbase.h"
class SpkPkgMgrApt : public SpkPkgMgrBase
{
Q_OBJECT
public:
SpkPkgMgrApt(QObject *parent = nullptr);
static bool DetectRequirements();
virtual PkgInstallResult ExecuteInstallation(QString pkgPath,
int entryId) override;
// APT backend specific
bool ChangeServerRepository(QString content);
private:
QAction *mActAptitudeTerm,
*mActAptTerm,
*mActGdebi,
*mActDeepinPkgInst;
};

82
inc/pkgs/spkpkgmgrbase.h Normal file

@ -0,0 +1,82 @@
#pragma once
#include <QObject>
#include <QMenu>
#include <QAction>
#include <QCursor>
#include <QUrl>
#include <QDesktopServices>
#include "spkutils.h"
class SpkPkgMgrBase : public QObject
{
Q_OBJECT
public:
SpkPkgMgrBase(QObject *parent = nullptr) : QObject(parent)
{
Q_ASSERT(mInstance == nullptr);
mInstance = this;
mActOpenDir = new QAction(tr("Open containing directory"), this);
mMenu = new QMenu(tr("Package Actions"));
mMenu->addAction(mActOpenDir);
mMenu->setAttribute(Qt::WA_TranslucentBackground);
mMenu->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint);
}
enum PkgInstallResult
{
Failed,
Succeeded,
Ignored ///< No installation action is taken, no messages be displayed
};
/**
* @brief Detects if this system qualified to use this kind of packaging
*/
static bool DetectRequirements() { return true; }
/**
* @brief Popup a menu at cursor to select installation methods
* and do installation accordingly
* @param pkgPath Path to the package file
* @param entryId ID of the download entry
*/
virtual PkgInstallResult ExecuteInstallation(QString pkgPath, int entryId)
{
auto item = mMenu->exec(QCursor::pos());
if(item == mActOpenDir)
QDesktopServices::openUrl(QUrl(SpkUtils::CutPath(pkgPath)));
return Ignored;
}
/**
* @brief Called when Spark Store installs a software when it's running
* in CLI mode
* @param pkgPath Path to the package file
*/
virtual PkgInstallResult CliInstall(QString pkgPath)
{
// TODO: print message
return Ignored;
}
public:
static SpkPkgMgrBase *Instance() { return mInstance; }
protected:
QAction *mActOpenDir, *mActDesc;
QMenu *mMenu;
private:
static SpkPkgMgrBase *mInstance;
signals:
void InstallationEnded(int entryId,
SpkPkgMgrBase::PkgInstallResult success,
QString message);
};

@ -0,0 +1,20 @@
#pragma once
#include "spkpkgmgrbase.h"
class SpkPkgMgrPacman : public SpkPkgMgrBase
{
Q_OBJECT
public:
SpkPkgMgrPacman(QObject *parent = nullptr);
static bool DetectRequirements();
virtual PkgInstallResult ExecuteInstallation(QString pkgPath,
int entryId) override;
};

@ -166,6 +166,44 @@ QProgressBar::chunk
background-color: ACC_;
}
QMenu
{
background-color: CBG_;
padding: 6px 0px;
border-radius: 6px;
}
QMenu::item
{
background-color: CBG_;
}
QMenu::item:disabled
{
color: TXD;
}
QMenu::item:selected
{
background-color: ACC_;
color: TXACC;
}
QMenu::item:pressed
{
background-color: ACCH;
color: TXACC;
}
QMenu::separator
{
background: DCTLD;
height: 1px;
margin: 2px;
margin-left: 8px;
margin-right: 8px;
}
/* Custom widgets */
ElidedLabel
@ -191,7 +229,7 @@ SpkAppItem::hover
/* homepage*/
#lblTitle
{
font-weiget: 700;
font-weight: 600;
font-size: 40px;
}

23
src/pkgs/spkpkgmgrapt.cpp Normal file

@ -0,0 +1,23 @@
#include <QFile>
#include "pkgs/spkpkgmgrapt.h"
SpkPkgMgrApt::SpkPkgMgrApt(QObject *parent) :
SpkPkgMgrBase(parent)
{
}
bool SpkPkgMgrApt::DetectRequirements()
{
return QFile::exists("/usr/bin/apt") &&
QFile::exists("/etc/apt/apt.conf");
}
SpkPkgMgrBase::PkgInstallResult
SpkPkgMgrApt::ExecuteInstallation(QString pkgPath, int entryId)
{
}

@ -0,0 +1,28 @@
#include "pkgs/spkpkgmgrpacman.h"
#include <QFile>
SpkPkgMgrBase *SpkPkgMgrBase::mInstance = nullptr;
SpkPkgMgrPacman::SpkPkgMgrPacman(QObject *parent) :
SpkPkgMgrBase(parent)
{
mActDesc = new QAction(tr("ArchLinux Pacman"), this);
mActDesc->setEnabled(false);
mMenu->addSeparator();
mMenu->addAction(mActDesc);
}
bool SpkPkgMgrPacman::DetectRequirements()
{
return QFile::exists("/usr/bin/pacman") &&
QFile::exists("/etc/pacman.conf");
}
SpkPkgMgrBase::PkgInstallResult
SpkPkgMgrPacman::ExecuteInstallation(QString pkgPath, int entryId)
{
SpkPkgMgrBase::ExecuteInstallation(pkgPath, entryId);
}

@ -11,6 +11,8 @@
#include "spkpopup.h"
#include "spkstore.h"
#include "spkutils.h"
#include "pkgs/spkpkgmgrpacman.h"
#include "pkgs/spkpkgmgrapt.h"
SpkStore *SpkStore::Instance = nullptr;
static bool InstallDefaultConfigs(QString configPath);
@ -54,6 +56,15 @@ SpkStore::SpkStore(bool aCli, QString &aLogPath)
.arg(mDistroName + " @SparkDeveloper");
#endif
// Initialize package management backend
// Test for which backend fits
if(SpkPkgMgrApt::DetectRequirements())
new SpkPkgMgrApt(this);
else if(SpkPkgMgrPacman::DetectRequirements())
new SpkPkgMgrPacman(this);
else
new SpkPkgMgrBase(this);
// Finish all essential initialization before this.
if(aCli)
return;