summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/manager/hidpopup.cpp
Unidiff
Diffstat (limited to 'noncore/net/opietooth/manager/hidpopup.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/manager/hidpopup.cpp105
1 files changed, 105 insertions, 0 deletions
diff --git a/noncore/net/opietooth/manager/hidpopup.cpp b/noncore/net/opietooth/manager/hidpopup.cpp
new file mode 100644
index 0000000..98a2fb4
--- a/dev/null
+++ b/noncore/net/opietooth/manager/hidpopup.cpp
@@ -0,0 +1,105 @@
1/* $Id$ */
2/* PAN context menu */
3/***************************************************************************
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 ***************************************************************************/
11#include <qpe/qcopenvelope_qws.h>
12#include <qmessagebox.h>
13#include <opie2/odebug.h>
14#include <opie2/oprocess.h>
15#include <qpe/qpeapplication.h>
16using namespace Opie::Core;
17
18#include <qtimer.h>
19#include "hidpopup.h"
20
21using namespace OpieTooth;
22
23/*
24 * c'tor init the QAction
25 */
26HidPopup::HidPopup(const OpieTooth::Services&, OpieTooth::BTDeviceItem* item) :
27 QPopupMenu() {
28
29 owarn << "HidPopup c'tor" << oendl;
30
31 m_item = item;
32 QAction* a;
33 QAction* c;
34
35 m_hidConnect = 0l;
36 /* connect action */
37
38 a = new QAction(); // so it's get deleted
39 a->setText( tr("connect") );
40 a->addTo( this );
41 connect( a, SIGNAL( activated() ), this, SLOT( slotConnect() ) );
42
43 c = new QAction();
44 c->setText( tr( "disconnect" ) );
45 c->addTo( this );
46 connect( c, SIGNAL( activated() ), this, SLOT( slotDisconnect() ) );
47
48};
49
50HidPopup::~HidPopup() {
51 delete m_hidConnect;
52}
53
54void HidPopup::slotConnect() {
55 odebug << "connect" << oendl;
56 m_hidConnect = new OProcess();
57 *m_hidConnect << "hidd" << "--connect" << m_item->mac();
58 connect(m_hidConnect,
59 SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int)),
60 this, SLOT(fillOutPut(Opie::Core::OProcess*, char*, int)));
61 connect(m_hidConnect,
62 SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int)),
63 this, SLOT(fillErr(Opie::Core::OProcess*, char*, int)));
64 connect(m_hidConnect,
65 SIGNAL(processExited(Opie::Core::OProcess*)),
66 this, SLOT(slotProcessExited(Opie::Core::OProcess*)));
67 if (!m_hidConnect->start(OProcess::Block, OProcess::AllOutput)) {
68 QMessageBox::critical(this, tr("HID Connection"),
69 tr("HID Connection\nto device ") + m_item->mac() + tr("\nfailed"));
70 delete m_hidConnect;
71 m_hidConnect = 0l;
72 }
73}
74
75void HidPopup::slotDisconnect() {
76 OProcess hidKill;
77 hidKill << "hidd" << "--kill" << m_item->mac();
78 hidKill.start(OProcess::DontCare, OProcess::NoCommunication);
79 sleep(1);
80 QMessageBox::information(this, tr("HID Disconnect"), tr("HID Disconnected"));
81}
82
83void HidPopup::fillOutPut( OProcess*, char* cha, int len ) {
84 QCString str(cha, len);
85 odebug << str << oendl;
86}
87
88void HidPopup::fillErr(OProcess*, char* buf, int len)
89{
90 QCString str(buf, len);
91 odebug << str << oendl;
92}
93
94void HidPopup::slotProcessExited(OProcess* proc) {
95 if (m_hidConnect->normalExit())
96 QMessageBox::information(this, tr("HID Connection"),
97 tr("HID Connect\nstarted"));
98 else
99 QMessageBox::critical(this, tr("HID Connection"),
100 tr("HID Connection\nto device ") + m_item->mac() + tr("\nfailed"));
101 delete m_hidConnect;
102 m_hidConnect = 0l;
103}
104
105//eof