summaryrefslogtreecommitdiff
path: root/plugins/Listener/catchcopy-v0002/listener.cpp
blob: 55c254ba450b65cb80ed50d18951eaba1fd3967d (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
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
#include "listener.h"
#include "catchcopy-api-0002/ExtraSocketCatchcopy.h"

Listener::Listener()
{
    server.setName(tr("Ultracopier"));
    connect(&server,&ServerCatchcopy::newCopyWithoutDestination,		this,&Listener::copyWithoutDestination);
    connect(&server,&ServerCatchcopy::newCopy,                          this,&Listener::copy);
    connect(&server,&ServerCatchcopy::newMoveWithoutDestination,		this,&Listener::moveWithoutDestination);
    connect(&server,&ServerCatchcopy::newMove,                          this,&Listener::move);
    connect(&server,&ServerCatchcopy::error,                            this,&Listener::errorInternal);
    connect(&server,&ServerCatchcopy::communicationError,               this,&Listener::communicationErrorInternal);
    connect(&server,&ServerCatchcopy::clientName,                       this,&Listener::clientName);
    connect(&server,&ServerCatchcopy::clientName,                       this,&Listener::newClientList);
    connect(&server,&ServerCatchcopy::connectedClient,                  this,&Listener::newClientList);
    connect(&server,&ServerCatchcopy::disconnectedClient,               this,&Listener::newClientList);

}

void Listener::listen()
{
    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start: %1").arg(ExtraSocketCatchcopy::pathSocket()));
    if(server.listen())
        emit newState(Ultracopier::FullListening);
    else
        emit newState(Ultracopier::NotListening);
}

void Listener::close()
{
    server.close();
    emit newState(Ultracopier::NotListening);
}

const QString Listener::errorString() const
{
    return server.errorString();
}

void Listener::setResources(OptionInterface * options,const QString &writePath,const QString &pluginPath,const bool &portableVersion)
{
    Q_UNUSED(options);
    Q_UNUSED(writePath);
    Q_UNUSED(pluginPath);
    Q_UNUSED(portableVersion);
}

/// \brief to get the options widget, NULL if not have
QWidget * Listener::options()
{
    return NULL;
}

/// \brief to get a client list
QStringList Listener::clientsList() const
{
    return server.clientsList();
}

void Listener::transferFinished(const quint32 &orderId,const bool &withError)
{
    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start, orderId: "+QString::number(orderId)+", withError: "+QString::number(withError));
    server.copyFinished(orderId,withError);
}

void Listener::transferCanceled(const quint32 &orderId)
{
    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start, orderId: "+QString::number(orderId));
    server.copyCanceled(orderId);
}

/// \brief to reload the translation, because the new language have been loaded
void Listener::newLanguageLoaded()
{
}

void Listener::errorInternal(const QString &string)
{
    Q_UNUSED(string);
    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"warning emited from Catchcopy lib: "+string);
}

void Listener::communicationErrorInternal(const QString &string)
{
    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"warning emited from Catchcopy lib: "+string);
    emit error(string);
}

void Listener::clientName(quint32 client,QString name)
{
    Q_UNUSED(client);
    Q_UNUSED(name);
    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Information,QStringLiteral("clientName: %1, for the id: %2").arg(name).arg(client));
}

void Listener::copyWithoutDestination(const quint32 &orderId,const QStringList &sources)
{
    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Information,QStringLiteral("copyWithoutDestination(%1,%2)").arg(orderId).arg(sources.join(";")));
    emit newCopyWithoutDestination(orderId,sources);
}

void Listener::copy(const quint32 &orderId,const QStringList &sources,const QString &destination)
{
    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Information,QStringLiteral("copy(%1,%2,%3)").arg(orderId).arg(sources.join(";")).arg(destination));
    emit newCopy(orderId,sources,destination);
}

void Listener::moveWithoutDestination(const quint32 &orderId,const QStringList &sources)
{
    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Information,QStringLiteral("moveWithoutDestination(%1,%2)").arg(orderId).arg(sources.join(";")));
    emit newMoveWithoutDestination(orderId,sources);
}

void Listener::move(const quint32 &orderId,const QStringList &sources,const QString &destination)
{
    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Information,QStringLiteral("move(%1,%2,%3)").arg(orderId).arg(sources.join(";")).arg(destination));
    emit newMove(orderId,sources,destination);
}