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 2 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, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
21 * @file UpKpr1Dcop.cpp
22 * @brief DCOP interface using command line tool.
23 * @author James Hogan <james@albanarts.com>
26 #include "UpKpr1Dcop.h"
31 * Constructors + destructor
34 /// Default constructor.
35 UpKpr1Dcop::UpKpr1Dcop()
41 /// Primary constructor.
42 UpKpr1Dcop::UpKpr1Dcop(const UpKpr1Dcop
& parent
, QString interface
)
44 , m_reference(parent
.m_reference
)
46 m_reference
<< interface
;
49 /// Construct from dcop reference.
50 UpKpr1Dcop::UpKpr1Dcop(QStringList reference
)
52 , m_reference(reference
)
57 UpKpr1Dcop::~UpKpr1Dcop()
65 /// Find whether its valid.
66 bool UpKpr1Dcop::isValid() const
71 /// Get the dcop reference.
72 const QStringList
& UpKpr1Dcop::reference() const
81 /// Get the result of a dcop query on this interface.
82 QString
UpKpr1Dcop::eval(bool* const error
, QStringList tail
) const
84 QStringList args
= m_reference
;
88 dcop
.start("dcop", args
);
89 bool localError
= !dcop
.waitForFinished();
97 QString result
= QString::fromAscii(dcop
.readAll());
98 if (result
.endsWith('\n'))
100 result
= result
.left(result
.size()-1);
110 /// Get the resulting list of strings from a dcop query
111 QStringList
UpKpr1Dcop::evalList(bool* const err
, QStringList tail
) const
113 return eval(err
,tail
).split('\n');
116 /// Get the resulting integer from a dcop query
117 int UpKpr1Dcop::evalInt(bool* const err
, QStringList tail
) const
121 QString string
= eval(&evalErr
, tail
);
124 result
= string
.toInt(&evalErr
);
142 /// Get a dcop reference from a string.
143 UpKpr1Dcop
UpKpr1Dcop::dcopRefFromString(QString input
)
145 #define DCOPREF_START "DCOPRef("
146 #define DCOPREF_END ")"
147 #define DCOPREF_NULL DCOPREF_START "," DCOPREF_END
148 if (input
.startsWith(DCOPREF_START
) &&
149 input
.endsWith(DCOPREF_END
) &&
150 input
!= DCOPREF_NULL
)
152 return UpKpr1Dcop(input
.mid(sizeof(DCOPREF_START
)-1,
153 input
.size() - (sizeof(DCOPREF_START
)-1)
154 - (sizeof(DCOPREF_END
)-1) ).split(','));
162 /// Get a single dcop reference from a dcop query.
163 UpKpr1Dcop
UpKpr1Dcop::evalRef(QStringList tail
) const
166 QStringList items
= evalList(&error
, tail
);
167 if (!error
&& items
.size() == 1)
169 return dcopRefFromString(items
.first());