summaryrefslogtreecommitdiff
path: root/core/applets/obex/obeximpl.cc
blob: 7331bbad1d5bfc1ae1ddb68fcf351cc77497de12 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

#include <qdatastream.h>
#include <qmessagebox.h>


#include <qpe/qcom.h>
#include <qpe/applnk.h>

#include <qlabel.h>

#include "obex.h"
#include "obeximpl.h"



using namespace OpieObex;

ObexImpl::ObexImpl( )
 :  QObject() {
  // register to a channel
  qWarning( "c'tor" );
  m_obex = new Obex(this, "obex");
  m_sendgui = new ObexDlg();
  m_recvgui = new ObexInc();
  m_chan = new QCopChannel("QPE/Obex" );
  connect(m_chan, SIGNAL(received(const QCString&,  const QByteArray& ) ),
	   this, SLOT(slotMessage(const QCString&, const QByteArray&) ) );
  connect(m_obex, SIGNAL(receivedFile(const QString& ) ),
          this,  SLOT(slotReceivedFile(const QString& ) ) );
  connect((QObject*) m_recvgui->InsertButton,  SIGNAL(clicked()),
          m_recvgui, SLOT( accept() ));
  connect((QObject*) m_recvgui->RejectButton,  SIGNAL(clicked()),
          m_recvgui, SLOT( reject() ));
}

ObexImpl::~ObexImpl() {
  delete m_obex;
  delete m_chan;
  delete m_sendgui;
  delete m_recvgui;
}

QRESULT ObexImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) {
  *iface = 0;
  if( uuid  ==  IID_QUnknown )
    *iface = this;
  else if( uuid == IID_ObexInterface )
    *iface = this;

  qWarning("query" );
  if(*iface )
    (*iface)->addRef();
  return QS_OK;
}

void ObexImpl::slotMessage( const QCString& msg, const QByteArray&data ) {
  QDataStream stream( data, IO_ReadOnly );
  qWarning("Message %s", msg.data() );
  if(msg == "send(QString,QString,QString)" ) {
    QString desc;
    stream >> desc;
    stream >> m_name;
    m_sendgui->raise(); // should be on top
    m_sendgui->showMaximized();
    m_sendgui->lblPath->setText(m_name);
    connect( (QObject*)m_sendgui->PushButton2, SIGNAL(clicked()),
             this, SLOT(slotCancelSend()));
    m_obex->send(m_name );
    connect( (QObject*)m_obex, SIGNAL( sent() ), this,
             SLOT( slotSent() ) );
    connect( (QObject*)m_obex, SIGNAL( error(int) ),  this,
             SLOT( slotSent() ) );
  }else if(msg == "receive(int)" ) { // open a GUI
      //m_recvgui->showMaximized();
      int receiveD = 0;
      stream >> receiveD;
      if ( receiveD == 1)
          m_obex->receive();
      else
          m_obex->setReceiveEnabled( false );

  } else if (msg =="done(QString)") {
      QString text;
      stream >> text;
      m_sendgui->lblPath->setText(tr("Done transfering " + text));

  }
}

void ObexImpl::slotCancelSend() {
    // cancel sync process too
    //m_obex->cancel(); // not ready yet
    m_sendgui->hide();
}

void ObexImpl::slotDone(bool) {
    QCopEnvelope e ("QPE/Obex", "done(QString)" ); //but this into a slot
    e << m_name;
}

void ObexImpl::slotSent() {
    m_sendgui->lblPath->setText("Done!");
    m_sendgui->hide();
}

void ObexImpl::slotError( int errorCode) {

    QString errorString = "";
    if (errorCode == -1) {
        errorString = "test";
    }
    qDebug("Error: " + errorString);
    m_sendgui->hide();
}

// Received a file via beam
// check for mime  type and then either
// add to App via setDocument
void ObexImpl::slotReceivedFile( const QString &fileName ) {
    qWarning("filename %s",  fileName.latin1() );
    DocLnk lnk( fileName );
    QString exec = lnk.exec();
    qWarning("executing %s", exec.latin1() );
    if ( exec.isEmpty() || exec == "" ) {
        qWarning("empty");
        if ( fileName.right(4) == ".vcf" )
            exec = "addressbook";
        else if ( fileName.right(4) == ".vcs" ) {
            exec = "datebook";
        }
    } // now prompt and then add it

    m_recvgui->PixmapLabel->setPixmap( lnk.pixmap() );
    m_recvgui->AppLabel->setText( "<b>" + exec + "<b>" );
    m_recvgui->FileLabel->setText( lnk.name() );
    m_recvgui->showMaximized();
    if( m_recvgui->exec() != -1 ) {
         QCString str= "QPE/Application/";
         str += exec.latin1();
         qWarning("channel %s", str.data() );
         QCopEnvelope e(str ,  "setDocument(QString)" );
         e << fileName;
    }
}



Q_EXPORT_INTERFACE() {
    Q_CREATE_INSTANCE( ObexImpl )
}