1 /***************************************************************************
2 rkpseudoobjects - description
3 -------------------
4 begin : Fri Mar 11 2011
5 copyright : (C) 2011-2013 by Thomas Friedrichsmeier
6 email : thomas.friedrichsmeier@kdemail.net
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 #include "rkpseudoobjects.h"
19
20 #include <KLocalizedString>
21
22 #include "../debug.h"
23
RSlotsPseudoObject(RObject * parent)24 RSlotsPseudoObject::RSlotsPseudoObject (RObject *parent) : RContainerObject (parent, "SLOTS") {
25 RK_TRACE (OBJECTS);
26 type |= PseudoObject;
27 pseudo_object_types.insert (this, SlotsObject);
28 }
29
~RSlotsPseudoObject()30 RSlotsPseudoObject::~RSlotsPseudoObject () {
31 RK_TRACE (OBJECTS);
32 pseudo_object_types.remove (this);
33 }
34
getFullName(int options) const35 QString RSlotsPseudoObject::getFullName (int options) const {
36 RK_TRACE (OBJECTS);
37
38 return (".rk.get.slots (" + parent->getFullName (options) + ')');
39 }
40
makeChildName(const QString & short_child_name,bool,int options) const41 QString RSlotsPseudoObject::makeChildName (const QString &short_child_name, bool, int options) const {
42 RK_TRACE (OBJECTS);
43
44 if (options & ExplicitSlotsExpansion) {
45 return (QStringLiteral("slot(") + parent->getFullName (options) + QStringLiteral(", ") + rQuote(short_child_name) + ')');
46 }
47 QString safe_name = short_child_name;
48 if (irregularShortName (safe_name)) safe_name = rQuote (short_child_name);
49 return (parent->getFullName (options) + '@' + safe_name);
50 }
51
RKNamespaceObject(REnvironmentObject * package,const QString name)52 RKNamespaceObject::RKNamespaceObject (REnvironmentObject* package, const QString name) : REnvironmentObject (package, name.isNull () ? "NAMESPACE" : name) {
53 RK_TRACE (OBJECTS);
54 type |= PseudoObject;
55 pseudo_object_types.insert (this, NamespaceObject);
56 if (name.isNull ()) namespace_name = package->packageName ();
57 else namespace_name = name;
58 }
59
~RKNamespaceObject()60 RKNamespaceObject::~RKNamespaceObject () {
61 RK_TRACE (OBJECTS);
62 pseudo_object_types.remove (this);
63 }
64
getFullName(int) const65 QString RKNamespaceObject::getFullName (int) const {
66 RK_TRACE (OBJECTS);
67 return ("asNamespace (" + rQuote (namespace_name) + ')');
68 }
69
makeChildName(const QString & short_child_name,bool,int) const70 QString RKNamespaceObject::makeChildName (const QString& short_child_name, bool, int) const {
71 RK_TRACE (OBJECTS);
72 QString safe_name = short_child_name;
73 if (irregularShortName (safe_name)) safe_name = rQuote (short_child_name);
74 return (namespace_name + ":::" + safe_name);
75 }
76
77 #include "robjectlist.h"
78 #include "rkmodificationtracker.h"
79 #include "../rkglobals.h"
80
RKOrphanNamespacesObject(RObjectList * parent)81 RKOrphanNamespacesObject::RKOrphanNamespacesObject (RObjectList* parent) : REnvironmentObject (parent, i18nc ("Note: 'namespace' is a technical term, should not be translated", "Orphan Namespaces")) {
82 RK_TRACE (OBJECTS);
83 type |= PseudoObject;
84 pseudo_object_types.insert (this, OrphanNamespacesObject);
85 }
86
~RKOrphanNamespacesObject()87 RKOrphanNamespacesObject::~RKOrphanNamespacesObject () {
88 RK_TRACE (OBJECTS);
89 pseudo_object_types.remove (this);
90 }
91
getFullName(int) const92 QString RKOrphanNamespacesObject::getFullName (int) const {
93 RK_TRACE (OBJECTS);
94 return ("loadedNamespaces ()");
95 }
96
makeChildName(const QString & short_child_name,bool,int) const97 QString RKOrphanNamespacesObject::makeChildName (const QString& short_child_name, bool, int) const {
98 RK_TRACE (OBJECTS);
99 return ("asNamespace (" + rQuote (short_child_name) + ')');
100 }
101
updateFromR(RCommandChain * chain)102 void RKOrphanNamespacesObject::updateFromR (RCommandChain* chain) {
103 RK_TRACE (OBJECTS);
104 Q_UNUSED (chain);
105 RK_ASSERT (false);
106 }
107
updateFromR(RCommandChain * chain,const QStringList & current_symbols)108 void RKOrphanNamespacesObject::updateFromR (RCommandChain* chain, const QStringList& current_symbols) {
109 RK_TRACE (OBJECTS);
110 Q_UNUSED (chain); // because the namespace objects themselves are not updated, only added as incomplete objects
111
112 // which former children are missing?
113 for (int i = childmap.size () - 1; i >= 0; --i) {
114 RObject *object = childmap[i];
115 if (!current_symbols.contains (object->getShortName ())) {
116 RKGlobals::tracker ()->removeObject (object, 0, true);
117 }
118 }
119
120 // which ones are new in the list?
121 for (int i = 0; i < current_symbols.size (); ++i) {
122 if (!findOrphanNamespace (current_symbols[i])) {
123 RKNamespaceObject *nso = new RKNamespaceObject (this, current_symbols[i]);
124 nso->type |= Incomplete;
125 RKGlobals::tracker ()->beginAddObject (nso, this, i);
126 childmap.insert (i, nso);
127 RKGlobals::tracker ()->endAddObject (nso, this, i);
128 }
129 }
130
131 RK_ASSERT (current_symbols.size () == childmap.size ());
132 }
133
findOrphanNamespace(const QString & name) const134 RKNamespaceObject* RKOrphanNamespacesObject::findOrphanNamespace (const QString& name) const {
135 RK_TRACE (OBJECTS);
136
137 for (int i = childmap.size () - 1; i >= 0; --i) {
138 RObject *obj = childmap[i];
139 if (obj->getShortName () == name) {
140 RK_ASSERT (obj->isPackageNamespace ());
141 return static_cast<RKNamespaceObject*> (obj);
142 }
143 }
144 return 0;
145 }
146
getObjectDescription() const147 QString RKOrphanNamespacesObject::getObjectDescription () const {
148 RK_TRACE (OBJECTS);
149
150 QString desc = RObject::getObjectDescription ();
151 desc.append (QString ("<p>%1</p>").arg (i18n ("This special object does not actually exist anywhere in R. It is used, here, to list namespaces which are loaded, but not attached to a package on the search path. These are typically 'imported' namespaces.")));
152 return desc;
153 }
154