Skip to content

Commit

Permalink
Add url button for loading remote yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
afbjorklund committed Feb 13, 2022
1 parent cbc0c79 commit fb4c5d6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lima.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ QString defaultYAML()
return "examples/default.yaml";
}

QString defaultURL()
{
return "https:/lima-vm/lima/blob/master/examples/default.yaml";
}

QString limactlPath()
{
QString program = QStandardPaths::findExecutable("limactl");
Expand Down
1 change: 1 addition & 0 deletions lima.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define LIMA_H

extern QString defaultYAML();
extern QString defaultURL();

extern QString limactlPath();

Expand Down
30 changes: 30 additions & 0 deletions window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,12 @@ void Window::quickCreate()
}
}

void Window::urlCreate()
{
quickDialog->close();
createInstanceURL();
}

void Window::advancedCreate()
{
quickDialog->close();
Expand All @@ -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:")));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -814,6 +830,20 @@ void Window::createInstance()
updateInstances();
}

void Window::createInstanceURL()
{
QString url = createURL->text();
if (url.startsWith("https:")) {
// 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();
Expand Down
3 changes: 3 additions & 0 deletions window.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ private slots:
void createEditor();
QWidget *newExampleButton(QString name);
void quickCreate();
void urlCreate();
void advancedCreate();
void quickInstance();
void sendCommand(QString cmd);
Expand All @@ -128,6 +129,7 @@ private slots:
void writeYAML(QString fileName);
QFile *validateYAML(QString name);
void createInstance();
void createInstanceURL();
void updateInstance();
void startInstance();
void stopInstance();
Expand All @@ -144,6 +146,7 @@ private slots:
QFile *editFile;
QLineEdit *createName;
QTextEdit *createYAML;
QLineEdit *createURL;

QGroupBox *instanceGroupBox;
InstanceModel *instanceModel;
Expand Down

0 comments on commit fb4c5d6

Please sign in to comment.