1 // -*- indent-tabs-mode: t; tab-width: 4; c-basic-offset: 4; -*-
3 This file is part of the KDE libraries
5 Copyright (c) 2008 Michael Leupold <lemma@confuego.org>
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
24 #include <QTextStream>
26 #include <KApplication>
27 #include <KCmdLineArgs>
31 static QTextStream
_out(stdout
, QIODevice::WriteOnly
);
32 static QString _kdewallet
;
36 QDBusInterface
service("org.kde.kwalletd", "/modules/kwalletd");
37 if (!service
.isValid()) {
38 _out
<< "Constructed service is invalid!" << endl
;
42 QDBusReply
<int> h
= service
.call(QDBus::Block
, "open", _kdewallet
, (qlonglong
)0, "kwalletnoautoclose");
43 if (!h
.isValid() || h
.value() < 0) {
44 _out
<< "Opening the wallet failed!" << endl
;
45 _out
<< "Error: " << h
.error().message() << endl
;
48 _out
<< "Wallet opened." << endl
;
51 _out
<< "closing the wallet" << endl
;
52 QDBusReply
<int> r
= service
.call(QDBus::Block
, "close", h
.value(), false, "kwalletnoautoclose");
57 int main(int argc
, char *argv
[])
59 KAboutData
aboutData("kwalletnoautoclose", 0, ki18n("kwalletnoautoclose"), "version");
60 KCmdLineArgs::init(argc
, argv
, &aboutData
);
63 QDBusInterface
service("org.kde.kwalletd", "/modules/kwalletd");
64 if (!service
.isValid()) {
65 _out
<< "Constructed service is invalid!" << endl
;
69 QDBusReply
<bool> r
= service
.call(QDBus::Block
, "isEnabled");
70 if (!r
.isValid() || !r
) {
71 _out
<< "kwalletd is disabled or not running!" << endl
;
75 QDBusReply
<QString
> kdewallet
= service
.call(QDBus::Block
, "localWallet");
76 _kdewallet
= kdewallet
;
77 _out
<< "local wallet is " << _kdewallet
<< endl
;
79 QDBusReply
<bool> open
= service
.call(QDBus::Block
, "isOpen", _kdewallet
);
81 _out
<< "wallet is already open. Please close to run this test." << endl
;
87 _out
<< "Opening and closing the wallet properly." << endl
;
90 _out
<< "FAILED!" << endl
;
94 _out
<< "Opening and exiting." << endl
;
95 QDBusReply
<int> h
= service
.call(QDBus::Block
, "open", _kdewallet
, (qlonglong
)0, "kwalletnoautoclose");
97 _out
<< "Opening the wallet failed!" << endl
;
100 _out
<< "Wallet opened." << endl
;
103 _out
<< "Exiting. Wallet should stay open." << endl
;