mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-14 12:52:04 +08:00
加入包管理器模块雏形
This commit is contained in:
@@ -87,6 +87,10 @@ set(SOURCE_FILES
|
|||||||
inc/page/spkpagedownloads.h gui/page/spkpagedownloads.cpp
|
inc/page/spkpagedownloads.h gui/page/spkpagedownloads.cpp
|
||||||
inc/page/spkpagesettings.h gui/page/spkpagesettings.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/spkstore.h src/spkstore.cpp
|
||||||
inc/spkuimsg.h src/spkuimsg.cpp
|
inc/spkuimsg.h src/spkuimsg.cpp
|
||||||
inc/spklogging.h src/spklogging.cpp
|
inc/spklogging.h src/spklogging.cpp
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "inc/page/spkpageuitest.h"
|
#include "inc/page/spkpageuitest.h"
|
||||||
#include "spkpopup.h"
|
#include "spkpopup.h"
|
||||||
#include "spkui_general.h"
|
#include "spkui_general.h"
|
||||||
|
#include "pkgs/spkpkgmgrbase.h"
|
||||||
|
|
||||||
SpkUi::SpkPageUiTest::SpkPageUiTest(QWidget *parent) : QSplitter(parent)
|
SpkUi::SpkPageUiTest::SpkPageUiTest(QWidget *parent) : QSplitter(parent)
|
||||||
{
|
{
|
||||||
@@ -80,6 +81,10 @@ SpkUi::SpkPageUiTest::SpkPageUiTest(QWidget *parent) : QSplitter(parent)
|
|||||||
ShowAbout->setText("Show About Dialog");
|
ShowAbout->setText("Show About Dialog");
|
||||||
connect(ShowAbout, &QPushButton::clicked, [](){ SpkAbout::Show(); });
|
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 = new QSlider(this);
|
||||||
SlideV->setObjectName("spk_pg_qsstest_slider_v");
|
SlideV->setObjectName("spk_pg_qsstest_slider_v");
|
||||||
SlideV->setOrientation(Qt::Vertical);
|
SlideV->setOrientation(Qt::Vertical);
|
||||||
@@ -106,6 +111,7 @@ SpkUi::SpkPageUiTest::SpkPageUiTest(QWidget *parent) : QSplitter(parent)
|
|||||||
VLayTestWidgets->addWidget(PopupText);
|
VLayTestWidgets->addWidget(PopupText);
|
||||||
VLayTestWidgets->addWidget(ShowPopup);
|
VLayTestWidgets->addWidget(ShowPopup);
|
||||||
VLayTestWidgets->addWidget(ShowAbout);
|
VLayTestWidgets->addWidget(ShowAbout);
|
||||||
|
VLayTestWidgets->addWidget(ShowPkgmgr);
|
||||||
VLayTestWidgets->addWidget(AppItem);
|
VLayTestWidgets->addWidget(AppItem);
|
||||||
VLayTestWidgets->addWidget(DetailsWidget);
|
VLayTestWidgets->addWidget(DetailsWidget);
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,8 @@ namespace SpkUi
|
|||||||
|
|
||||||
QLineEdit *PopupText;
|
QLineEdit *PopupText;
|
||||||
QPushButton *ShowPopup,
|
QPushButton *ShowPopup,
|
||||||
*ShowAbout;
|
*ShowAbout,
|
||||||
|
*ShowPkgmgr;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void SetStylesheet();
|
void SetStylesheet();
|
||||||
|
|||||||
27
inc/pkgs/spkpkgmgrapt.h
Normal file
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
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);
|
||||||
|
|
||||||
|
};
|
||||||
20
inc/pkgs/spkpkgmgrpacman.h
Normal file
20
inc/pkgs/spkpkgmgrpacman.h
Normal file
@@ -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_;
|
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 */
|
/* Custom widgets */
|
||||||
|
|
||||||
ElidedLabel
|
ElidedLabel
|
||||||
@@ -191,7 +229,7 @@ SpkAppItem::hover
|
|||||||
/* homepage*/
|
/* homepage*/
|
||||||
#lblTitle
|
#lblTitle
|
||||||
{
|
{
|
||||||
font-weiget: 700;
|
font-weight: 600;
|
||||||
font-size: 40px;
|
font-size: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
23
src/pkgs/spkpkgmgrapt.cpp
Normal file
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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
28
src/pkgs/spkpkgmgrpacman.cpp
Normal file
28
src/pkgs/spkpkgmgrpacman.cpp
Normal file
@@ -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 "spkpopup.h"
|
||||||
#include "spkstore.h"
|
#include "spkstore.h"
|
||||||
#include "spkutils.h"
|
#include "spkutils.h"
|
||||||
|
#include "pkgs/spkpkgmgrpacman.h"
|
||||||
|
#include "pkgs/spkpkgmgrapt.h"
|
||||||
|
|
||||||
SpkStore *SpkStore::Instance = nullptr;
|
SpkStore *SpkStore::Instance = nullptr;
|
||||||
static bool InstallDefaultConfigs(QString configPath);
|
static bool InstallDefaultConfigs(QString configPath);
|
||||||
@@ -54,6 +56,15 @@ SpkStore::SpkStore(bool aCli, QString &aLogPath)
|
|||||||
.arg(mDistroName + " @SparkDeveloper");
|
.arg(mDistroName + " @SparkDeveloper");
|
||||||
#endif
|
#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.
|
// Finish all essential initialization before this.
|
||||||
if(aCli)
|
if(aCli)
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user