blob: 953e98bee8cde832b39ce40d7f5748a136806658 [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
swissChili5d3e5562022-02-24 16:49:19 -08005// TODO: avoid potential race condition if Cell is deleted, pass by value with same UUID instead
6
swissChili25620b02022-02-23 17:15:16 -08007Notebook::Notebook(QObject *parent)
8 : QObject(parent)
9 , _cellModel(new CellModel(this))
10{
swissChilid85daa92022-02-24 15:29:02 -080011 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);
swissChili25620b02022-02-23 17:15:16 -080016
swissChilid85daa92022-02-24 15:29:02 -080017 _rt.start();
swissChili25620b02022-02-23 17:15:16 -080018}
19
20Notebook::Notebook(const Notebook &other, QObject *parent)
swissChilid85daa92022-02-24 15:29:02 -080021 : Notebook(parent)
swissChili25620b02022-02-23 17:15:16 -080022{
swissChilid85daa92022-02-24 15:29:02 -080023 for (const Cell *cell : other._cells)
24 {
25 _cells.append(new Cell(*cell, this));
26 }
swissChili25620b02022-02-23 17:15:16 -080027}
28
29CellModel *Notebook::cellModel()
30{
31 return _cellModel;
32}
swissChilid85daa92022-02-24 15:29:02 -080033
34void Notebook::runCell(QUuid uuid)
35{
36 qInfo() << "Running cell" << uuid;
37 _rt.queueCell(Cell::cellFromUuid(uuid));
38}
39
40void Notebook::quitCell(QUuid uuid)
41{
42 _rt.unqueueCell(Cell::cellFromUuid(uuid));
43}
44
45void 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
52void 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
59void Notebook::cellWaiting(Cell *cell)
60{
61 qInfo() << "cellWaiting" << cell->uuid();
62 cell->setStatus(Cell::WAITING);
63}
64
65void Notebook::cellRunning(Cell *cell)
66{
67 qInfo() << "cellRunning" << cell->uuid();
68 cell->setStatus(Cell::RUNNING);
69}
70
71void Notebook::cellQuit(Cell *cell)
72{
73 qInfo() << "cellQuit" << cell->uuid();
74 cell->setResult("");
75 cell->setStatus(Cell::IDLE);
76}