1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
5 * KWorship is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 3 of the License, or *
8 * (at your option) any later version. *
10 * KWorship is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with KWorship. If not, see <http://www.gnu.org/licenses/>. *
17 ***************************************************************************/
20 * @file UpKpr1Dcop.cpp
21 * @brief DCOP interface using command line tool.
22 * @author James Hogan <james@albanarts.com>
25 #include "UpKpr1Dcop.h"
30 * Constructors + destructor
33 /// Default constructor.
34 UpKpr1Dcop::UpKpr1Dcop()
40 /// Primary constructor.
41 UpKpr1Dcop::UpKpr1Dcop(const UpKpr1Dcop
& parent
, QString interface
)
43 , m_reference(parent
.m_reference
)
45 m_reference
<< interface
;
48 /// Construct from dcop reference.
49 UpKpr1Dcop::UpKpr1Dcop(QStringList reference
)
51 , m_reference(reference
)
56 UpKpr1Dcop::~UpKpr1Dcop()
64 /// Find whether its valid.
65 bool UpKpr1Dcop::isValid() const
74 /// Get the result of a dcop query on this interface.
75 QString
UpKpr1Dcop::eval(bool* const error
, QStringList tail
) const
77 QStringList args
= m_reference
;
81 dcop
.start("dcop", args
);
82 bool localError
= !dcop
.waitForFinished();
90 QString result
= QString::fromAscii(dcop
.readAll());
91 if (result
.endsWith('\n'))
93 result
= result
.left(result
.size()-1);
103 /// Get the resulting list of strings from a dcop query
104 QStringList
UpKpr1Dcop::evalList(bool* const err
, QStringList tail
) const
106 return eval(err
,tail
).split('\n');
109 /// Get the resulting integer from a dcop query
110 int UpKpr1Dcop::evalInt(bool* const err
, QStringList tail
) const
114 QString string
= eval(&evalErr
, tail
);
117 result
= string
.toInt(&evalErr
);
135 /// Get a dcop reference from a string.
136 UpKpr1Dcop
UpKpr1Dcop::dcopRefFromString(QString input
)
138 #define DCOPREF_START "DCOPRef("
139 #define DCOPREF_END ")"
140 #define DCOPREF_NULL DCOPREF_START "," DCOPREF_END
141 if (input
.startsWith(DCOPREF_START
) &&
142 input
.endsWith(DCOPREF_END
) &&
143 input
!= DCOPREF_NULL
)
145 return UpKpr1Dcop(input
.mid(sizeof(DCOPREF_START
)-1,
146 input
.size() - (sizeof(DCOPREF_START
)-1)
147 - (sizeof(DCOPREF_END
)-1) ).split(','));
155 /// Get a single dcop reference from a dcop query.
156 UpKpr1Dcop
UpKpr1Dcop::evalRef(QStringList tail
) const
159 QStringList items
= evalList(&error
, tail
);
160 if (!error
&& items
.size() == 1)
162 return dcopRefFromString(items
.first());