blob: 82bee7ec402d1d8e5c5c7b0568142877933023ec [file] [log] [blame]
swissChili25620b02022-02-23 17:15:16 -08001#include "Notebook.h"
2#include "CellModel.h"
swissChilid85daa92022-02-24 15:29:02 -08003#include "../PPrint.h"
swissChili25620b02022-02-23 17:15:16 -08004
5Notebook::Notebook(QObject *parent)
6 : QObject(parent)
7 , _cellModel(new CellModel(this))
8{
swissChilid85daa92022-02-24 15:29:02 -08009 connect(&_rt, &NbRuntime::cellFailedToParse, this, &Notebook::cellFailedToParse);
10 connect(&_rt, &NbRuntime::cellFinishedRunning, this, &Notebook::cellFinishedRunning);
11 connect(&_rt, &NbRuntime::cellQuit, this, &Notebook::cellQuit);
12 connect(&_rt, &NbRuntime::cellRunning, this, &Notebook::cellRunning);
13 connect(&_rt, &NbRuntime::cellWaiting, this, &Notebook::cellWaiting);
swissChili25620b02022-02-23 17:15:16 -080014
swissChilid85daa92022-02-24 15:29:02 -080015 _rt.start();
swissChili25620b02022-02-23 17:15:16 -080016}
17
18Notebook::Notebook(const Notebook &other, QObject *parent)
swissChilid85daa92022-02-24 15:29:02 -080019 : Notebook(parent)
swissChili25620b02022-02-23 17:15:16 -080020{
swissChilid85daa92022-02-24 15:29:02 -080021 for (const Cell *cell : other._cells)
22 {
23 _cells.append(new Cell(*cell, this));
24 }
swissChili25620b02022-02-23 17:15:16 -080025}
26
27CellModel *Notebook::cellModel()
28{
29 return _cellModel;
30}
swissChilid85daa92022-02-24 15:29:02 -080031
32void Notebook::runCell(QUuid uuid)
33{
34 qInfo() << "Running cell" << uuid;
35 _rt.queueCell(Cell::cellFromUuid(uuid));
36}
37
38void Notebook::quitCell(QUuid uuid)
39{
40 _rt.unqueueCell(Cell::cellFromUuid(uuid));
41}
42
43void Notebook::cellFinishedRunning(Cell *cell, RuntimeResult result)
44{
45 qInfo() << "cellFinishedRunning" << cell->uuid() << pprint(result);
46 cell->setResult(pprint(result));
47 cell->setStatus(Cell::IDLE);
48}
49
50void Notebook::cellFailedToParse(Cell *cell, ParseResult result)
51{
52 qInfo() << "cellFailedToParse" << cell->uuid() << pprint(result);
53 cell->setResult(pprint(result));
54 cell->setStatus(Cell::IDLE);
55}
56
57void Notebook::cellWaiting(Cell *cell)
58{
59 qInfo() << "cellWaiting" << cell->uuid();
60 cell->setStatus(Cell::WAITING);
61}
62
63void Notebook::cellRunning(Cell *cell)
64{
65 qInfo() << "cellRunning" << cell->uuid();
66 cell->setStatus(Cell::RUNNING);
67}
68
69void Notebook::cellQuit(Cell *cell)
70{
71 qInfo() << "cellQuit" << cell->uuid();
72 cell->setResult("");
73 cell->setStatus(Cell::IDLE);
74}