Changeset View
Changeset View
Standalone View
Standalone View
src/backends/python/pythonvariablemodel.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | This program is free software; you can redistribute it and/or | ||||
3 | modify it under the terms of the GNU General Public License | ||||
4 | as published by the Free Software Foundation; either version 2 | ||||
5 | of the License, or (at your option) any later version. | ||||
6 | | ||||
7 | This program is distributed in the hope that it will be useful, | ||||
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
10 | GNU General Public License for more details. | ||||
11 | | ||||
12 | You should have received a copy of the GNU General Public License | ||||
13 | along with this program; if not, write to the Free Software | ||||
14 | Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
15 | Boston, MA 02110-1301, USA. | ||||
16 | | ||||
17 | --- | ||||
18 | Copyright (C) 2018 Nikita Sirgienko <warquark@gmail.com> | ||||
19 | */ | ||||
20 | | ||||
21 | #include "pythonvariablemodel.h" | ||||
22 | #include "pythonsession.h" | ||||
23 | #include "textresult.h" | ||||
24 | | ||||
25 | #include <QDebug> | ||||
26 | #include <QDBusReply> | ||||
27 | #include <QDBusInterface> | ||||
28 | #include <QString> | ||||
29 | | ||||
30 | using namespace Cantor; | ||||
31 | | ||||
32 | PythonVariableModel::PythonVariableModel(PythonSession* session): | ||||
33 | DefaultVariableModel(session), | ||||
34 | m_pIface(nullptr) | ||||
35 | { | ||||
36 | } | ||||
37 | | ||||
38 | void PythonVariableModel::setPythonServer(QDBusInterface* pIface) | ||||
39 | { | ||||
40 | m_pIface = pIface; | ||||
41 | } | ||||
42 | | ||||
43 | void PythonVariableModel::update() | ||||
44 | { | ||||
45 | if (!m_pIface) | ||||
46 | return; | ||||
47 | | ||||
48 | bool variableManagement = static_cast<PythonSession*>(session())->variableManagement(); | ||||
49 | const QString& data = QDBusReply<QString>(m_pIface->call(QString::fromLatin1("variables"), variableManagement)).value(); | ||||
50 | const QStringList& records = data.split(QChar(30), QString::SkipEmptyParts); | ||||
51 | | ||||
52 | QList<Variable> variables; | ||||
53 | for (const QString& record : records) | ||||
54 | { | ||||
55 | const QString& name = record.section(QChar(31), 0, 0); | ||||
56 | const QString& value = record.section(QChar(31), 1, 1); | ||||
57 | | ||||
58 | variables << Variable{name, value}; | ||||
59 | } | ||||
60 | | ||||
61 | setVariables(variables); | ||||
62 | } |