Code

Translations. French translation minor update.
[inkscape.git] / work / filerec.cpp
3 #include <stdio.h>
5 #include "pedroxmpp.h"
7 //########################################################################
8 //# T E S T
9 //########################################################################
12 class TestListener : public Pedro::XmppEventListener
13 {
14 public:
15     TestListener()
16         {
17         incoming = false;
18         }
20     virtual ~TestListener(){}
22     virtual void processXmppEvent(const Pedro::XmppEvent &evt)
23         {
24         int typ = evt.getType();
25         switch (typ)
26             {
27             case Pedro::XmppEvent::EVENT_STATUS:
28                 {
29                 printf("STATUS: %s\n", evt.getData().c_str());
30                 break;
31                 }
32             case Pedro::XmppEvent::EVENT_ERROR:
33                 {
34                 printf("ERROR: %s\n", evt.getData().c_str());
35                 break;
36                 }
37             case Pedro::XmppEvent::EVENT_CONNECTED:
38                 {
39                 printf("CONNECTED\n");
40                 break;
41                 }
42             case Pedro::XmppEvent::EVENT_DISCONNECTED:
43                 {
44                 printf("DISCONNECTED\n");
45                 break;
46                 }
47              case Pedro::XmppEvent::EVENT_MUC_PRESENCE:
48                 {
49                 printf("MUC PRESENCE\n");
50                 printf("group   : %s\n", evt.getGroup().c_str());
51                 printf("from    : %s\n", evt.getFrom().c_str());
52                 printf("presence: %d\n", evt.getPresence());
53                 break;
54                 }
55             case Pedro::XmppEvent::EVENT_FILE_RECEIVE:
56                 {
57                 printf("FILE RECEIVE\n");
58                 from     = evt.getFrom();
59                 streamId = evt.getStreamId();
60                 iqId     = evt.getIqId();
61                 fileName = evt.getFileName();
62                 fileHash = evt.getFileHash();
63                 fileSize = evt.getFileSize();
64                 incoming = true;
65                 break;
66                 }
68             }
69         }
70         
71     Pedro::DOMString from;
72     Pedro::DOMString streamId;
73     Pedro::DOMString iqId;
74     Pedro::DOMString fileName;
75     Pedro::DOMString fileHash;
76     long      fileSize;
77     bool incoming;
78 };
81 bool doTest()
82 {
83     printf("############ RECEIVING FILE\n");
85     Pedro::XmppClient client;
86     TestListener listener;
87     client.addXmppEventListener(listener);
89     //Host, port, user, pass, resource
90     if (!client.connect("jabber.org.uk", 443, "ishmal", "PASSWORD", "filerec"))
91        {
92        printf("Connect failed\n");
93        return false;
94        }
96     while (true)
97         {
98         printf("####Waiting for file\n");
99         if (listener.incoming)
100             break;
101         client.pause(2000);
102         }
104     printf("#####GOT A FILE\n");
105 /*
106 TODO: Just Commented out to compile
107     if (!client.fileReceive(listener.from, 
108                             listener.iqId,
109                             listener.streamId, 
110                             listener.fileName,
111                             "text.sav",
112                             listener.fileHash))
113         {
114         return false;
115         }   
116 */
117     client.pause(1000000);
119     client.disconnect();
121     return true;
124 int main(int argc, char **argv)
126     if (!doTest())
127         return 1;
128     return 0;