mirror of
https://github.com/QuasarApp/QtDeployer.git
synced 2025-04-27 05:54:31 +00:00
base snap
This commit is contained in:
parent
f3267e4fbe
commit
8b2cf4c39b
@ -10,7 +10,7 @@ QStringList MainManager::getAllExecutables()
|
||||
}
|
||||
|
||||
MainManager::MainManager(CppManager *cpp, QmlManager *qml, OutputManager *out,
|
||||
PluginManager *plg, QObject *parent)
|
||||
PluginManager *plg, SnapManager *snp, QObject *parent)
|
||||
: BaseClass(parent)
|
||||
{
|
||||
setState(0);
|
||||
@ -19,6 +19,8 @@ MainManager::MainManager(CppManager *cpp, QmlManager *qml, OutputManager *out,
|
||||
m_qml = qml;
|
||||
m_out = out;
|
||||
m_plg = plg;
|
||||
m_snp = snp;
|
||||
|
||||
}
|
||||
|
||||
void MainManager::prepare(const QString &qtdir, const QString &execpath,
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "outputmanager.h"
|
||||
#include "pluginmanager.h"
|
||||
#include "qmlmanager.h"
|
||||
#include "snapmanager.h"
|
||||
|
||||
class MainManager : public BaseClass
|
||||
{
|
||||
@ -17,6 +18,7 @@ class MainManager : public BaseClass
|
||||
QmlManager *m_qml;
|
||||
PluginManager *m_plg;
|
||||
OutputManager *m_out;
|
||||
SnapManager *m_snp;
|
||||
|
||||
int m_state;
|
||||
|
||||
@ -24,7 +26,7 @@ class MainManager : public BaseClass
|
||||
|
||||
public:
|
||||
explicit MainManager(CppManager *cpp, QmlManager *qml, OutputManager *out,
|
||||
PluginManager *plg, QObject *parent = nullptr);
|
||||
PluginManager *plg, SnapManager *snp, QObject *parent = nullptr);
|
||||
|
||||
int state() const;
|
||||
|
||||
|
76
source/CPP/snapmanager.cpp
Executable file
76
source/CPP/snapmanager.cpp
Executable file
@ -0,0 +1,76 @@
|
||||
#include "snapmanager.h"
|
||||
|
||||
bool SnapManager::checkSnapDirs()const{
|
||||
QDir dir(m_projectdir);
|
||||
|
||||
if(!dir.cd("snap")){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(dir.entryList(QStringList() << "*.desktop" << "snapcraft.yaml").length() < 2){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool copyRecursively(const QString &srcFilePath,
|
||||
const QString &tgtFilePath)
|
||||
{
|
||||
QFileInfo srcFileInfo(srcFilePath);
|
||||
if (srcFileInfo.isDir()) {
|
||||
|
||||
QDir targetDir(tgtFilePath);
|
||||
targetDir.cdUp();
|
||||
|
||||
if (!targetDir.mkdir(QFileInfo(tgtFilePath).fileName()))
|
||||
return false;
|
||||
|
||||
QDir sourceDir(srcFilePath);
|
||||
QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
|
||||
|
||||
foreach (const QString &fileName, fileNames) {
|
||||
const QString newSrcFilePath
|
||||
= srcFilePath + QLatin1Char('/') + fileName;
|
||||
|
||||
const QString newTgtFilePath
|
||||
= tgtFilePath + QLatin1Char('/') + fileName;
|
||||
|
||||
if (!copyRecursively(newSrcFilePath, newTgtFilePath))
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (!QFile::copy(srcFilePath, tgtFilePath))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SnapManager::copySnap()const {
|
||||
return copyRecursively(m_projectdir + "/snap", m_outputdir);
|
||||
}
|
||||
|
||||
void SnapManager::start()
|
||||
{
|
||||
if(!copySnap()){
|
||||
emit fail(tr("copy snapcraft error!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if(!checkSnapDirs()){
|
||||
emit fail(tr("create a snapcraft.yaml and desktop file!"));
|
||||
} else {
|
||||
QProcess P;
|
||||
P.setArguments(QStringList() << "snapcraft");
|
||||
P.start("gnome-terminal", QProcess::ReadOnly);
|
||||
|
||||
if (!P.waitForStarted() || !P.waitForFinished()){
|
||||
emit fail(tr("gnome-terminal not found, if you need a create snap package."
|
||||
"you need call \'snapcraft\' in final build directory"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SnapManager::SnapManager(QObject *parent) : BaseClass(parent) {}
|
26
source/CPP/snapmanager.h
Executable file
26
source/CPP/snapmanager.h
Executable file
@ -0,0 +1,26 @@
|
||||
#ifndef SNAPMANAGER_H
|
||||
#define SNAPMANAGER_H
|
||||
|
||||
#include "baseclass.h"
|
||||
|
||||
class SnapManager : public BaseClass
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
bool checkSnapDirs()const;
|
||||
|
||||
bool copySnap()const;
|
||||
|
||||
public:
|
||||
explicit SnapManager(QObject *parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void start();
|
||||
|
||||
|
||||
signals:
|
||||
void done(QString snap);
|
||||
void fail(QString error);
|
||||
};
|
||||
|
||||
#endif // CPPMANAGER_H
|
@ -1,5 +1,7 @@
|
||||
import QtQuick 2.7
|
||||
import QtQuick.Controls 2.0
|
||||
import QtQuick.Controls.Material 2.0
|
||||
import QtQuick.Layouts 1.3
|
||||
|
||||
Page {
|
||||
clip: true
|
||||
@ -17,9 +19,23 @@ Page {
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
id: createSnap
|
||||
text: "Create a snap package"
|
||||
Material.background: buttonColor
|
||||
Layout.alignment: Qt.AlignRight
|
||||
anchors.top: parent.top;
|
||||
onClicked: {
|
||||
SnapManager.start();
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: listview
|
||||
anchors.fill: parent
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: createSnap.bottom
|
||||
anchors.bottom: parent.bottom
|
||||
ScrollBar.vertical: ScrollBar {}
|
||||
|
||||
model: VisualItemModel {
|
||||
@ -59,5 +75,5 @@ Page {
|
||||
model: OutputManager.pathsToCopy
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
TEMPLATE = app
|
||||
|
||||
QT += qml quick
|
||||
|
||||
CONFIG += c++14
|
||||
@ -20,18 +22,13 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
TARGET = QtDeployer
|
||||
|
||||
# Default rules for deployment.
|
||||
qnx: target.path = /tmp/$${TARGET}/bin
|
||||
else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||
!isEmpty(target.path): INSTALLS += target
|
||||
|
||||
|
||||
VERSION = 1.0.0.0
|
||||
TARGET = QtDeployer
|
||||
TEMPLATE = app
|
||||
RC_ICONS = res/QtDeployr.ico
|
||||
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
CPP/baseclass.cpp \
|
||||
@ -39,7 +36,8 @@ SOURCES += \
|
||||
CPP/mainmanager.cpp \
|
||||
CPP/outputmanager.cpp \
|
||||
CPP/pluginmanager.cpp \
|
||||
CPP/qmlmanager.cpp
|
||||
CPP/qmlmanager.cpp \
|
||||
CPP/snapmanager.cpp
|
||||
|
||||
HEADERS += \
|
||||
CPP/baseclass.h \
|
||||
@ -47,4 +45,10 @@ HEADERS += \
|
||||
CPP/mainmanager.h \
|
||||
CPP/outputmanager.h \
|
||||
CPP/pluginmanager.h \
|
||||
CPP/qmlmanager.h
|
||||
CPP/qmlmanager.h \
|
||||
CPP/snapmanager.h
|
||||
|
||||
|
||||
VERSION = 1.0.0.0
|
||||
TEMPLATE = app
|
||||
RC_ICONS = res/QtDeployr.ico
|
||||
|
@ -2,22 +2,24 @@
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
|
||||
#include <CPP/cppmanager.h>
|
||||
#include <CPP/mainmanager.h>
|
||||
#include <CPP/outputmanager.h>
|
||||
#include <CPP/pluginmanager.h>
|
||||
#include <CPP/qmlmanager.h>
|
||||
#include "CPP/cppmanager.h"
|
||||
#include "CPP/mainmanager.h"
|
||||
#include "CPP/outputmanager.h"
|
||||
#include "CPP/pluginmanager.h"
|
||||
#include "CPP/qmlmanager.h"
|
||||
#include "CPP/snapmanager.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
CppManager C;
|
||||
QmlManager Q;
|
||||
PluginManager P;
|
||||
OutputManager O;
|
||||
MainManager M(&C, &Q, &O, &P);
|
||||
SnapManager S;
|
||||
|
||||
MainManager M(&C, &Q, &O, &P, &S);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
|
||||
@ -27,6 +29,8 @@ int main(int argc, char *argv[])
|
||||
R->setContextProperty("PluginManager", &P);
|
||||
R->setContextProperty("MainManager", &M);
|
||||
R->setContextProperty("OutputManager", &O);
|
||||
R->setContextProperty("SnapManager", &S);
|
||||
|
||||
|
||||
engine.load(QUrl(QLatin1String("qrc:/QML/main.qml")));
|
||||
if (engine.rootObjects().isEmpty()) return -1;
|
||||
|
9
source/main.qml
Normal file
9
source/main.qml
Normal file
@ -0,0 +1,9 @@
|
||||
import QtQuick 2.9
|
||||
import QtQuick.Window 2.2
|
||||
|
||||
Window {
|
||||
visible: true
|
||||
width: 640
|
||||
height: 480
|
||||
title: qsTr("Hello World")
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user