swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 1 | #include "Notebook.h" |
| 2 | #include "CellModel.h" |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 3 | #include "../PPrint.h" |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 4 | |
swissChili | 5d3e556 | 2022-02-24 16:49:19 -0800 | [diff] [blame^] | 5 | // TODO: avoid potential race condition if Cell is deleted, pass by value with same UUID instead |
| 6 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 7 | Notebook::Notebook(QObject *parent) |
| 8 | : QObject(parent) |
| 9 | , _cellModel(new CellModel(this)) |
| 10 | { |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 11 | connect(&_rt, &NbRuntime::cellFailedToParse, this, &Notebook::cellFailedToParse); |
| 12 | connect(&_rt, &NbRuntime::cellFinishedRunning, this, &Notebook::cellFinishedRunning); |
| 13 | connect(&_rt, &NbRuntime::cellQuit, this, &Notebook::cellQuit); |
| 14 | connect(&_rt, &NbRuntime::cellRunning, this, &Notebook::cellRunning); |
| 15 | connect(&_rt, &NbRuntime::cellWaiting, this, &Notebook::cellWaiting); |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 16 | |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 17 | _rt.start(); |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | Notebook::Notebook(const Notebook &other, QObject *parent) |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 21 | : Notebook(parent) |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 22 | { |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 23 | for (const Cell *cell : other._cells) |
| 24 | { |
| 25 | _cells.append(new Cell(*cell, this)); |
| 26 | } |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | CellModel *Notebook::cellModel() |
| 30 | { |
| 31 | return _cellModel; |
| 32 | } |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 33 | |
| 34 | void Notebook::runCell(QUuid uuid) |
| 35 | { |
| 36 | qInfo() << "Running cell" << uuid; |
| 37 | _rt.queueCell(Cell::cellFromUuid(uuid)); |
| 38 | } |
| 39 | |
| 40 | void Notebook::quitCell(QUuid uuid) |
| 41 | { |
| 42 | _rt.unqueueCell(Cell::cellFromUuid(uuid)); |
| 43 | } |
| 44 | |
| 45 | void Notebook::cellFinishedRunning(Cell *cell, RuntimeResult result) |
| 46 | { |
| 47 | qInfo() << "cellFinishedRunning" << cell->uuid() << pprint(result); |
| 48 | cell->setResult(pprint(result)); |
| 49 | cell->setStatus(Cell::IDLE); |
| 50 | } |
| 51 | |
| 52 | void Notebook::cellFailedToParse(Cell *cell, ParseResult result) |
| 53 | { |
| 54 | qInfo() << "cellFailedToParse" << cell->uuid() << pprint(result); |
| 55 | cell->setResult(pprint(result)); |
| 56 | cell->setStatus(Cell::IDLE); |
| 57 | } |
| 58 | |
| 59 | void Notebook::cellWaiting(Cell *cell) |
| 60 | { |
| 61 | qInfo() << "cellWaiting" << cell->uuid(); |
| 62 | cell->setStatus(Cell::WAITING); |
| 63 | } |
| 64 | |
| 65 | void Notebook::cellRunning(Cell *cell) |
| 66 | { |
| 67 | qInfo() << "cellRunning" << cell->uuid(); |
| 68 | cell->setStatus(Cell::RUNNING); |
| 69 | } |
| 70 | |
| 71 | void Notebook::cellQuit(Cell *cell) |
| 72 | { |
| 73 | qInfo() << "cellQuit" << cell->uuid(); |
| 74 | cell->setResult(""); |
| 75 | cell->setStatus(Cell::IDLE); |
| 76 | } |