diff --git a/source/CPP/mainmanager.cpp b/source/CPP/mainmanager.cpp index 3bd11f1..fd79135 100755 --- a/source/CPP/mainmanager.cpp +++ b/source/CPP/mainmanager.cpp @@ -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, diff --git a/source/CPP/mainmanager.h b/source/CPP/mainmanager.h index 4099c12..21fc5e0 100755 --- a/source/CPP/mainmanager.h +++ b/source/CPP/mainmanager.h @@ -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; diff --git a/source/CPP/snapmanager.cpp b/source/CPP/snapmanager.cpp new file mode 100755 index 0000000..a43d74c --- /dev/null +++ b/source/CPP/snapmanager.cpp @@ -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) {} diff --git a/source/CPP/snapmanager.h b/source/CPP/snapmanager.h new file mode 100755 index 0000000..4877c82 --- /dev/null +++ b/source/CPP/snapmanager.h @@ -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 diff --git a/source/QML/ResultPage.qml b/source/QML/ResultPage.qml index fd8dbc9..4540d01 100755 --- a/source/QML/ResultPage.qml +++ b/source/QML/ResultPage.qml @@ -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 } } - } + } } diff --git a/source/QtDeployer.pro b/source/QtDeployer.pro index 76e7110..5189ab2 100755 --- a/source/QtDeployer.pro +++ b/source/QtDeployer.pro @@ -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 diff --git a/source/main.cpp b/source/main.cpp index e2982ee..a64f889 100755 --- a/source/main.cpp +++ b/source/main.cpp @@ -2,22 +2,24 @@ #include #include -#include -#include -#include -#include -#include +#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; diff --git a/source/main.qml b/source/main.qml new file mode 100644 index 0000000..188049d --- /dev/null +++ b/source/main.qml @@ -0,0 +1,9 @@ +import QtQuick 2.9 +import QtQuick.Window 2.2 + +Window { + visible: true + width: 640 + height: 480 + title: qsTr("Hello World") +}