From fb4c5d6da7d4ff48e4202347beb442b79fa97dca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sun, 13 Feb 2022 18:24:30 +0100 Subject: [PATCH] Add url button for loading remote yaml --- lima.cpp | 5 +++++ lima.h | 1 + window.cpp | 30 ++++++++++++++++++++++++++++++ window.h | 3 +++ 4 files changed, 39 insertions(+) diff --git a/lima.cpp b/lima.cpp index 275c8ef..02485c3 100644 --- a/lima.cpp +++ b/lima.cpp @@ -11,6 +11,11 @@ QString defaultYAML() return "examples/default.yaml"; } +QString defaultURL() +{ + return "https://github.com/lima-vm/lima/blob/master/examples/default.yaml"; +} + QString limactlPath() { QString program = QStandardPaths::findExecutable("limactl"); diff --git a/lima.h b/lima.h index 923dbf0..97c28f4 100644 --- a/lima.h +++ b/lima.h @@ -2,6 +2,7 @@ #define LIMA_H extern QString defaultYAML(); +extern QString defaultURL(); extern QString limactlPath(); diff --git a/window.cpp b/window.cpp index 11be93e..44da07d 100644 --- a/window.cpp +++ b/window.cpp @@ -372,6 +372,12 @@ void Window::quickCreate() } } +void Window::urlCreate() +{ + quickDialog->close(); + createInstanceURL(); +} + void Window::advancedCreate() { quickDialog->close(); @@ -386,9 +392,17 @@ void Window::quickInstance() QPushButton *cancelButton = new QPushButton(tr("Cancel")); connect(cancelButton, SIGNAL(clicked()), quickDialog, SLOT(close())); + QPushButton *urlButton = new QPushButton(tr("URL...")); + connect(urlButton, &QAbstractButton::clicked, this, &Window::urlCreate); QPushButton *advancedButton = new QPushButton(tr("Advanced...")); connect(advancedButton, &QAbstractButton::clicked, this, &Window::advancedCreate); + createURL = new QLineEdit(defaultURL()); + createURL->setFixedWidth(400); + QFont font; + font.setPointSize(9); + createURL->setFont(font); + QWidget *machineGroupBox = new QWidget(); QHBoxLayout *machineLayout = new QHBoxLayout; machineLayout->addWidget(new QLabel(tr("Arch:"))); @@ -452,6 +466,8 @@ void Window::quickInstance() QHBoxLayout *bottomLayout = new QHBoxLayout; bottomLayout->addWidget(cancelButton); bottomLayout->addStretch(); + bottomLayout->addWidget(urlButton); + bottomLayout->addWidget(createURL); bottomLayout->addWidget(advancedButton); QVBoxLayout *layout = new QVBoxLayout; @@ -814,6 +830,20 @@ void Window::createInstance() updateInstances(); } +void Window::createInstanceURL() +{ + QString url = createURL->text(); + if (url.startsWith("https://github.com")) { + // Get the "raw" YAML, and not the prettified HTTP + url = url.replace("github.com", "raw.githubusercontent.com"); + url = url.replace("blob/", ""); + } + QStringList args = { "start", "--tty=false", url }; + sendCommand(args); + + updateInstances(); +} + void Window::updateInstance() { QString name = createName->text(); diff --git a/window.h b/window.h index 01b969f..d2a68ec 100644 --- a/window.h +++ b/window.h @@ -118,6 +118,7 @@ private slots: void createEditor(); QWidget *newExampleButton(QString name); void quickCreate(); + void urlCreate(); void advancedCreate(); void quickInstance(); void sendCommand(QString cmd); @@ -128,6 +129,7 @@ private slots: void writeYAML(QString fileName); QFile *validateYAML(QString name); void createInstance(); + void createInstanceURL(); void updateInstance(); void startInstance(); void stopInstance(); @@ -144,6 +146,7 @@ private slots: QFile *editFile; QLineEdit *createName; QTextEdit *createYAML; + QLineEdit *createURL; QGroupBox *instanceGroupBox; InstanceModel *instanceModel;