[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kross/core
From: Nickolai Shaforostoff <shafff () ukr ! net>
Date: 2009-05-07 17:19:23
Message-ID: 1241716763.135401.28613.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 964937 by shaforo:
use a better approach for having relative paths in xml:
pass searchpaths directly to toDomElement() and fromDomElement() methods.
this allows us to have different searchpaths on load and save
(useful for adding third-party .rc files and then properly saving info about them)
this way we don't need to store searchpaths in each action all their lifetime.
this commit removes a c'tor I added during 4.3 cycle -- KDE release schedule says, \
i'm free to do so.
CCMAIL:mail@dipe.org
M +28 -25 action.cpp
M +21 -13 action.h
M +16 -6 actioncollection.cpp
M +4 -0 actioncollection.h
--- trunk/KDE/kdelibs/kross/core/action.cpp #964936:964937
@@ -86,6 +86,8 @@
/**
* The path list where the \a Script may be located.
+ * \todo after BIC break: don't keep it all the time,
+ * as it is now passed to [to|from]DomElement
*/
QStringList searchpath;
@@ -96,14 +98,6 @@
QMap< QString, QVariant > options;
Private() : script(0), version(0) {}
-
- QString activesearchpath(){return \
searchpath.isEmpty()?QString():searchpath.first();}
- void setactivesearchpath(const QString& p)
- {
- searchpath.removeAll(p);
- searchpath.prepend(p);
- }
-
};
}
@@ -127,21 +121,9 @@
, d( new Private() )
{
init(this,name);
- d->setactivesearchpath(packagepath.absolutePath());
+ d->searchpath=QStringList(packagepath.absolutePath());
}
-Action::Action(QObject* parent, const QString& name, const QStringList& searchPath)
- : QAction(parent)
- , QScriptable()
- , ChildrenInterface()
- , ErrorInterface()
- , d( new Private() )
-{
- init(this,name);
- d->searchpath=searchPath;
-}
-
-
Action::Action(QObject* parent, const QUrl& url)
: QAction(parent)
, ChildrenInterface()
@@ -168,8 +150,14 @@
delete d;
}
+
void Action::fromDomElement(const QDomElement& element)
{
+ fromDomElement(element, d->searchpath);
+}
+
+void Action::fromDomElement(const QDomElement& element, const QStringList& \
searchPath) +{
if( element.isNull() )
return;
@@ -179,11 +167,10 @@
setFile(file);
}
else {
- foreach (const QString& packagepath, d->searchpath) {
+ foreach (const QString& packagepath, searchPath) {
QFileInfo fi(QDir(packagepath), file);
if( fi.exists() ) {
setFile( fi.absoluteFilePath() );
- d->setactivesearchpath(packagepath);
break;
}
}
@@ -225,6 +212,11 @@
QDomElement Action::toDomElement() const
{
+ toDomElement(QStringList());
+}
+
+QDomElement Action::toDomElement(const QStringList& searchPath) const
+{
QDomDocument doc;
QDomElement e = doc.createElement("script");
e.setAttribute("name", objectName());
@@ -241,9 +233,20 @@
if( ! interpreter().isNull() )
e.setAttribute("interpreter", interpreter());
- if( ! file().isNull() ) {
- e.setAttribute("file", \
QDir(d->activesearchpath()).relativeFilePath(file())); +
+ QString fileName=file();
+ if (!searchPath.isEmpty()) {
+ //fileName=QDir(searchPath.first()).relativeFilePath(fileName); //prefer \
absname if it is short? + foreach(const QString& packagepath, searchPath) {
+ QString nfn=QDir(packagepath).relativeFilePath(file());
+ if (nfn.length()<fileName.length())
+ fileName=nfn;
+ }
}
+
+ if( ! fileName.isNull() ) {
+ e.setAttribute("file", fileName);
+ }
QList<QByteArray> props=dynamicPropertyNames();
foreach(const QByteArray& prop, props) {
--- trunk/KDE/kdelibs/kross/core/action.h #964936:964937
@@ -108,22 +108,10 @@
* \param name The unique name this Action has. It's used
* e.g. at the \a Manager to identify the Action. The
* name is accessible via \a QObject::objectName .
+ * \deprecated since 4.3: pass search path to fromDomElement() and \
toDomElement()
*/
Action(QObject* parent, const QString& name, const QDir& packagepath = \
QDir()); //BIC may be removed in favour of the next c'tor
-
- /**
- * Constructor.
- *
- * \param parent The parent QObject this \a Action is a child of.
- * \param name The unique name this Action has. It's used
- * e.g. at the \a Manager to identify the Action. The
- * name is accessible via \a QObject::objectName .
- * \param searchPath List of directories where to search the script if \
it's path is relative
- * First item is given the highest priority.
- */
- Action(QObject* parent, const QString& name, const QStringList& \
searchPath/* = QStringList()*/);
-
/**
* Constructor.
*
@@ -146,10 +134,21 @@
* Method to read settings from the QDomElement \p element that
* contains details about e.g. the displayed text, the file to
* execute or the used interpreter.
+ * \todo BIC merge
*/
void fromDomElement(const QDomElement& element);
/**
+ * Method to read settings from the QDomElement \p element that
+ * contains details about e.g. the displayed text, the file to
+ * execute or the used interpreter.
+ *
+ * \param searchPath List of directories where to search the script if \
it's path is relative + * First item is given the highest priority.
+ */
+ void fromDomElement(const QDomElement& element, const QStringList& \
searchPath/* = QStringList()*/); +
+ /**
* \return a QDomElement that contains the settings like e.g. the
* displayed text, the file to execute or the used interpreter
* of this \a Action instance.
@@ -157,6 +156,15 @@
QDomElement toDomElement() const;
/**
+ * \return a QDomElement that contains the settings like e.g. the
+ * displayed text, the file to execute or the used interpreter
+ * of this \a Action instance.
+ * \param searchPath if given, find the closest directory containing the \
scriptfile + * and write relative filepath
+ */
+ QDomElement toDomElement(const QStringList& searchPath/* = \
QStringList()*/) const; +
+ /**
* Initialize the \a Script instance.
*
* Normally there is no need to call this function directly because
--- trunk/KDE/kdelibs/kross/core/actioncollection.cpp #964936:964937
@@ -320,12 +320,12 @@
krossdebug( QString(" ActionCollection::readXml Creating Action \
\"%1\"").arg(name) ); #endif
- a = new Action(this, name, searchPath);
+ a = new Action(this, name);
addAction(name, a);
connect(a, SIGNAL( started(Kross::Action*) ), &Manager::self(), \
SIGNAL( started(Kross::Action*)) );
connect(a, SIGNAL( finished(Kross::Action*) ), &Manager::self(), \
SIGNAL( finished(Kross::Action*) )); }
- a->fromDomElement(elem);
+ a->fromDomElement(elem, searchPath);
}
//else if( ! fromXml(elem) ) ok = false;
}
@@ -385,6 +385,11 @@
QDomElement ActionCollection::writeXml()
{
+ return writeXml(QStringList());
+}
+
+QDomElement ActionCollection::writeXml(const QStringList& searchPath)
+{
#ifdef KROSS_ACTIONCOLLECTION_DEBUG
krossdebug( QString("ActionCollection::writeXml \
collection.objectName=\"%1\"").arg(objectName()) ); #endif
@@ -407,7 +412,7 @@
#ifdef KROSS_ACTIONCOLLECTION_DEBUG
krossdebug( QString(" ActionCollection::writeXml \
action.objectName=\"%1\" action.file=\"%2\"").arg(a->objectName()).arg(a->file()) ); \
#endif
- QDomElement e = a->toDomElement();
+ QDomElement e = a->toDomElement(searchPath);
if( ! e.isNull() )
element.appendChild(e);
}
@@ -415,7 +420,7 @@
foreach(const QString &name, d->collectionnames) {
ActionCollection* c = d->collections[name];
if( ! c ) continue;
- QDomElement e = c->writeXml();
+ QDomElement e = c->writeXml(searchPath);
if( ! e.isNull() )
element.appendChild(e);
}
@@ -425,11 +430,16 @@
bool ActionCollection::writeXml(QIODevice* device, int indent)
{
+ return writeXml(device, indent, QStringList());
+}
+
+bool ActionCollection::writeXml(QIODevice* device, int indent, const QStringList& \
searchPath) +{
QDomDocument document;
QDomElement root = document.createElement("KrossScripting");
foreach(Action* a, actions()) {
- QDomElement e = a->toDomElement();
+ QDomElement e = a->toDomElement(searchPath);
if( ! e.isNull() )
root.appendChild(e);
}
@@ -437,7 +447,7 @@
foreach(const QString &name, d->collectionnames) {
ActionCollection* c = d->collections[name];
if( ! c ) continue;
- QDomElement e = c->writeXml();
+ QDomElement e = c->writeXml(searchPath);
if( ! e.isNull() )
root.appendChild(e);
}
--- trunk/KDE/kdelibs/kross/core/actioncollection.h #964936:964937
@@ -185,13 +185,17 @@
* and \a ActionCollection instances this collection has.
*/
QDomElement writeXml();
+ QDomElement writeXml(const QStringList& searchPath/* = QStringList()*/);
+
/**
* Write XML to the QIODevice \p device and use a space-idention
* of \p indent for the XML.
*/
bool writeXml(QIODevice* device, int indent = 2);
+ bool writeXml(QIODevice* device, int indent/* = 2*/, const QStringList& \
searchPath/* = QStringList()*/);
+
Q_SIGNALS:
/**
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic