File: ClientManagerScript.cpp

package info (click to toggle)
eiskaltdcpp 2.2.9-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 20,372 kB
  • ctags: 12,362
  • sloc: cpp: 94,068; ansic: 8,832; perl: 1,523; xml: 1,378; sh: 685; php: 661; makefile: 101
file content (127 lines) | stat: -rw-r--r-- 3,576 bytes parent folder | download | duplicates (5)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/***************************************************************************
*                                                                         *
*   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; either version 3 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************/

#include "ClientManagerScript.h"
#include "WulforUtil.h"

#include "dcpp/CID.h"
#include "dcpp/User.h"

static QStringList toQStringList(const dcpp::StringList &list){
    QStringList ret;
    for (auto it = list.begin(); it != list.end(); ++it){
        ret.push_back(_q(*it));
    }

    return ret;
}

ClientManagerScript::ClientManagerScript(QObject *parent) :
    QObject(parent)
{
    CM = dcpp::ClientManager::getInstance();

    CM->addListener(this);
}

ClientManagerScript::~ClientManagerScript(){
    CM->removeListener(this);
}


void ClientManagerScript::sendPM(const QString& cid, const QString& hubUrl, const QString& msg){
    dcpp::UserPtr user = CM->findUser(CID(_tq(cid)));

    if (user && user->isOnline()){
        if (msg.isEmpty() || msg == "\n")
            return;

        CM->privateMessage(HintedUser(user, _tq(hubUrl)), _tq(msg), false);
    }
}


quint64 ClientManagerScript::getUserCount() const{
    return CM->getUserCount();
}

quint64 ClientManagerScript::getAvailable() const{
    return CM->getAvailable();
}

QStringList ClientManagerScript::getHubs(const QString& cid) const{
    return toQStringList(CM->getHubs(dcpp::CID(_tq(cid)), ""));
}

QStringList ClientManagerScript::getHubNames(const QString& cid) const{
    return getHubNames(cid, "");
}

QStringList ClientManagerScript::getHubNames(const QString& cid, const QString& hubUrl) const{
    StringList hubs = ClientManager::getInstance()->getHubNames(dcpp::CID(_tq(cid)), _tq(hubUrl));
    
    if (hubs.empty())
        return QStringList();
    else
        return toQStringList(hubs);
}


QStringList ClientManagerScript::getNicks(const QString& cid) const{
    const dcpp::Identity &user = CM->getOnlineUserIdentity(CM->getUser(dcpp::CID(_tq(cid))));
    QStringList lst;
    lst.push_back(_q(user.getNick()));

    return lst;
}

QStringList ClientManagerScript::getConnectedHubs() const {
    QStringList ret;
    CM->lock();
    dcpp::Client::List& clients = CM->getClients();

    for(auto it = clients.begin(); it != clients.end(); ++it) {
        Client* client = *it;

        if(!client->isConnected())
            continue;

        ret.push_back(_q(client->getHubUrl()));
    }

    return ret;
}

QString ClientManagerScript::getConnection(const QString& cid) const{
    return _q(CM->getConnection(dcpp::CID(_tq(cid))));
}

bool ClientManagerScript::isConnected(const QString& aUrl) const{
    return CM->isConnected(_tq(aUrl));
}

bool ClientManagerScript::isActive() const{
    return CM->isActive();
}

QString ClientManagerScript::getMyCID() const{
    return _q(CM->getMyCID().toBase32());
}

void ClientManagerScript::on(ClientConnected, dcpp::Client *cl) throw(){
    emit connected(_q(cl->getHubUrl()));
}

void ClientManagerScript::on(ClientUpdated, dcpp::Client *cl) throw(){
    emit updated(_q(cl->getHubUrl()));
}

void ClientManagerScript::on(ClientDisconnected, dcpp::Client *cl) throw(){
    emit disconnected(_q(cl->getHubUrl()));
}