summaryrefslogtreecommitdiffstats
path: root/kopete/plugins/smpppdcs/detectordcop.cpp
blob: 2536674d833f9261cf33c50262fc707c53b877a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
    detectordcop.cpp
 
    Copyright (c) 2004-2006 by Heiko Schaefer        <[email protected]>
 
    Kopete    (c) 2002-2006 by the Kopete developers <[email protected]>
 
    *************************************************************************
    *                                                                       *
    * This program is free software; you can redistribute it and/or modify  *
    * it under the terms of the GNU General Public License as published by  *
    * the Free Software Foundation; version 2 of the License.               *
    *                                                                       *
    *************************************************************************
*/

#include <kapplication.h>
#include <dcopclient.h>
#include <kdebug.h>

#include "kinternetiface_stub.h"

#include "detectordcop.h"
#include "iconnector.h"

QCString DetectorDCOP::m_kinternetApp = "";

DetectorDCOP::DetectorDCOP(IConnector * connector)
	: Detector(connector) {}

DetectorDCOP::~DetectorDCOP() {}

/*!
    \fn DetectorDCOP::getKInternetDCOP()
 */
QCString DetectorDCOP::getKInternetDCOP() const {
    DCOPClient * client = kapp->dcopClient();
    if(m_kinternetApp.isEmpty() && client && client->isAttached()) {
        // get all registered dcop apps and search for kinternet
        QCStringList apps = client->registeredApplications();
        QCStringList::iterator iter;
        for(iter = apps.begin(); iter != apps.end(); ++iter) {
            if((*iter).left(9) == "kinternet") {
                return *iter;
            }
        }
    }

    return m_kinternetApp;
}

/*!
    \fn DetectorDCOP::getConnectionStatusDCOP()
 */
DetectorDCOP::KInternetDCOPState DetectorDCOP::getConnectionStatusDCOP() const {
    kdDebug(14312) << k_funcinfo << "Start inquiring " << m_kinternetApp << " via DCOP" << endl;
	
	
	KInternetIface_stub stub = KInternetIface_stub(kapp->dcopClient(), m_kinternetApp, "KInternetIface");
	
	bool status = stub.isOnline();
	
	if(stub.ok()) {
		if(status) {
			kdDebug(14312) << k_funcinfo << "isOnline() returned true" << endl;
			return CONNECTED;
		} else {
			kdDebug(14312) << k_funcinfo << "isOnline() returned false" << endl;
			return DISCONNECTED;
		}
	} else {
		kdWarning(14312) << k_funcinfo << "DCOP call to " << m_kinternetApp << " failed!";
	}

	return ERROR;
}