~ubuntu-branches/ubuntu/maverick/qgo/maverick

« back to all changes in this revision

Viewing changes to src/telnet.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin A. Godisch
  • Date: 2005-01-01 23:07:10 UTC
  • Revision ID: james.westby@ubuntu.com-20050101230710-fhng6yidm47xlb2i
Tags: upstream-1.0.0-r2
ImportĀ upstreamĀ versionĀ 1.0.0-r2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* telnet.cpp
 
3
*/
 
4
 
 
5
#include "telnet.h"
 
6
#include "gs_globals.h"
 
7
#include "mainwin.h"
 
8
#include "igsconnection.h"
 
9
#include <qapplication.h>
 
10
#include <qmessagebox.h>
 
11
#include <qlineedit.h>
 
12
#include <qmenubar.h>
 
13
#include <qaccel.h>
 
14
 
 
15
 
 
16
TelnetInterface *telnetIF;
 
17
 
 
18
 
 
19
TelnetConnection::TelnetConnection(QWidget* parent)
 
20
{
 
21
        host = DEFAULT_HOST;
 
22
        port = DEFAULT_PORT;
 
23
        loginName = "";
 
24
        password = "";
 
25
        
 
26
        // Create IGSConnection instance
 
27
        igsInterface = new IGSConnection();
 
28
        CHECK_PTR(igsInterface);
 
29
        void (*fp)(const char*, uint);
 
30
        fp = TelnetInterface::callback;
 
31
        igsInterface->registerCallback(fp);
 
32
        
 
33
        // Create TelnetInterface instance
 
34
        telnetIF = new TelnetInterface();
 
35
        CHECK_PTR(telnetIF);
 
36
        connect(telnetIF,
 
37
                SIGNAL(textRecieved(const QString&)),
 
38
                parent,
 
39
                SLOT(sendTextToApp(const QString&)));
 
40
}
 
41
 
 
42
TelnetConnection::~TelnetConnection()
 
43
{
 
44
        // qDebug("bfor deleting igsinterface addres: %x",igsInterface );
 
45
        // CHECK_PTR(igsInterface);
 
46
        delete igsInterface;
 
47
        // qDebug("after deleting igsinterface");
 
48
        
 
49
        delete telnetIF;
 
50
        telnetIF = NULL;
 
51
        
 
52
        qDebug("TelnetConnection::~TelnetConnection() DONE");
 
53
}
 
54
 
 
55
void TelnetConnection::slotHostConnect() 
 
56
{
 
57
        if (igsInterface->isConnected())
 
58
        {
 
59
                qDebug("Already connected!");
 
60
                return;
 
61
        }
 
62
        // igsInterface->openConnection(host, port);
 
63
        if (!igsInterface->openConnection(host.latin1(), port, loginName, password))
 
64
        {
 
65
                qDebug("Failed to connect to host!");
 
66
        }
 
67
        else
 
68
                qDebug("Connected");
 
69
}
 
70
 
 
71
void TelnetConnection::slotHostDisconnect()
 
72
{
 
73
        if (!igsInterface->closeConnection())
 
74
        {
 
75
                qDebug("Failed to disconnect from host!");
 
76
        }
 
77
}
 
78
 
 
79
// send text (from MainWindow) to host
 
80
void TelnetConnection::sendTextFromApp(const QString &txt)
 
81
{
 
82
        igsInterface->sendTextToHost(txt);
 
83
}
 
84
 
 
85
// connect host
 
86
void TelnetConnection::setHost(const QString h, const QString lg, const QString pw, unsigned int pt)
 
87
{
 
88
        // set variables for connection
 
89
        port = pt;
 
90
        host = h;
 
91
        loginName = lg;
 
92
        password = pw;
 
93
        
 
94
        qDebug("SELECTED %s %d, %s, %s", host.latin1(), port, loginName.latin1(), (password ? "***" : "NULL"));
 
95
}
 
96
 
 
97
void TelnetConnection::slotHostQuit()
 
98
{
 
99
        // TODO: Timeout for connection termination, if still data has to be written
 
100
        if (igsInterface->isConnected())
 
101
                slotHostDisconnect();
 
102
}
 
103
 
 
104
//------------------------------------------------------------
 
105
 
 
106
TelnetInterface::TelnetInterface()
 
107
{
 
108
}
 
109
 
 
110
TelnetInterface::~TelnetInterface()
 
111
{
 
112
}
 
113
 
 
114
void TelnetInterface::callback(const char *s, uint i)
 
115
{
 
116
        //      QString qstr = QString::fromLatin1(s, i);
 
117
        //      qDebug("GUI: Callback recieved: %s!", qstr.latin1());
 
118
        
 
119
        if (telnetIF != NULL)
 
120
                // emit telnetIF->textRecieved(qstr, i);
 
121
                emit telnetIF->textRecieved(QString::fromLatin1(s, i));
 
122
}