|
|
|
@ -22,6 +22,7 @@
|
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
#include <dcopclient.h>
|
|
|
|
|
|
|
|
|
|
#include "trayicon.h"
|
|
|
|
|
#include "application.h"
|
|
|
|
@ -29,15 +30,15 @@
|
|
|
|
|
TDEBluetoothApp::TDEBluetoothApp() :
|
|
|
|
|
KUniqueApplication()
|
|
|
|
|
{
|
|
|
|
|
m_config = new TDEConfig("tdebluezrc");
|
|
|
|
|
// Enable autostart
|
|
|
|
|
m_config->setGroup("General");
|
|
|
|
|
m_config->readBoolEntry("AutoStart", true);
|
|
|
|
|
bool authAgentStart = m_config->readBoolEntry("authAgent", true);
|
|
|
|
|
bool obexServerStart = m_config->readBoolEntry("obexSrv", true);
|
|
|
|
|
|
|
|
|
|
authAgent = 0;
|
|
|
|
|
obexServer = 0;
|
|
|
|
|
// m_config = new TDEConfig("tdebluezrc");
|
|
|
|
|
// // Enable autostart
|
|
|
|
|
// m_config->setGroup("General");
|
|
|
|
|
// m_config->readBoolEntry("AutoStart", true);
|
|
|
|
|
// bool authAgentStart = m_config->readBoolEntry("authAgent", true);
|
|
|
|
|
// bool obexServerStart = m_config->readBoolEntry("obexSrv", true);
|
|
|
|
|
//
|
|
|
|
|
// authAgent = 0;
|
|
|
|
|
// obexServer = 0;
|
|
|
|
|
|
|
|
|
|
manager = new ObjectManagerImpl("org.bluez", "/", this, "ObjectManager");
|
|
|
|
|
if (!manager->isConnectedToDBUS())
|
|
|
|
@ -77,33 +78,14 @@ TDEBluetoothApp::TDEBluetoothApp() :
|
|
|
|
|
|
|
|
|
|
trayIcon = new TrayIcon(this);
|
|
|
|
|
setMainWidget(trayIcon);
|
|
|
|
|
|
|
|
|
|
if (authAgentStart)
|
|
|
|
|
{
|
|
|
|
|
if (!startAuthAgent())
|
|
|
|
|
tqWarning("TDEBluezAuth failed to start.");
|
|
|
|
|
}
|
|
|
|
|
if (obexServerStart)
|
|
|
|
|
{
|
|
|
|
|
if (!startObexSrv())
|
|
|
|
|
{
|
|
|
|
|
tqWarning("TDEBluezOBEX failed to start.");
|
|
|
|
|
}
|
|
|
|
|
// else
|
|
|
|
|
// connect(trayIcon, SIGNAL(setObexSrv(bool)), this, SLOT(slotObexSrv(bool)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TDEBluetoothApp::~TDEBluetoothApp()
|
|
|
|
|
{
|
|
|
|
|
delete trayIcon;
|
|
|
|
|
if (!stopAuthAgent())
|
|
|
|
|
authAgent->kill();
|
|
|
|
|
delete authAgent;
|
|
|
|
|
stopAuthAgent();
|
|
|
|
|
stopObexSrv();
|
|
|
|
|
|
|
|
|
|
if (!stopObexSrv())
|
|
|
|
|
obexServer->kill();
|
|
|
|
|
delete obexServer;
|
|
|
|
|
delete trayIcon;
|
|
|
|
|
|
|
|
|
|
if (manager->isConnectedToDBUS())
|
|
|
|
|
{
|
|
|
|
@ -125,114 +107,109 @@ TDEBluetoothApp::~TDEBluetoothApp()
|
|
|
|
|
adapters.clear();
|
|
|
|
|
}
|
|
|
|
|
delete manager;
|
|
|
|
|
|
|
|
|
|
if (m_config->isDirty())
|
|
|
|
|
m_config->sync();
|
|
|
|
|
|
|
|
|
|
delete m_config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDEBluetoothApp::startAuthAgent()
|
|
|
|
|
{
|
|
|
|
|
authAgent = new TQProcess();
|
|
|
|
|
authAgent->addArgument("tdebluezauth");
|
|
|
|
|
authAgent->addArgument("--nofork");
|
|
|
|
|
if (!authAgent->start())
|
|
|
|
|
kdDebug() << k_funcinfo << endl;
|
|
|
|
|
|
|
|
|
|
if (findPidOf("tdebluezauth") > 0)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
TQProcess authAgent(TQString("tdebluezauth"), this);
|
|
|
|
|
if (!authAgent.start())
|
|
|
|
|
return false;
|
|
|
|
|
TQObject::connect(authAgent, TQT_SIGNAL(processExited()), this,
|
|
|
|
|
TQT_SLOT(slotprocresult()));
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDEBluetoothApp::stopAuthAgent()
|
|
|
|
|
{
|
|
|
|
|
if (authAgent)
|
|
|
|
|
{
|
|
|
|
|
TQObject::disconnect(authAgent, 0, 0, 0);
|
|
|
|
|
int pid = authAgent->processIdentifier();
|
|
|
|
|
if (authAgent->isRunning())
|
|
|
|
|
{
|
|
|
|
|
authAgent->tryTerminate();
|
|
|
|
|
wait(&pid);
|
|
|
|
|
}
|
|
|
|
|
if (authAgent->isRunning())
|
|
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
authAgent = 0;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
kdDebug() << k_funcinfo << endl;
|
|
|
|
|
|
|
|
|
|
if (findPidOf("tdebluezauth") == 0)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
DCOPClient *client = kapp->dcopClient();
|
|
|
|
|
if (client>0)
|
|
|
|
|
{
|
|
|
|
|
TQByteArray data;
|
|
|
|
|
return client->send("tdebluezauth","MainApplication-Interface","quit()",data);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDEBluetoothApp::startObexSrv()
|
|
|
|
|
{
|
|
|
|
|
obexServer = new TQProcess();
|
|
|
|
|
obexServer->addArgument("/usr/lib/bluetooth/obexd");
|
|
|
|
|
// obexServer->addArgument("--nofork");
|
|
|
|
|
if (!obexServer->start())
|
|
|
|
|
kdDebug() << k_funcinfo << endl;
|
|
|
|
|
|
|
|
|
|
if (findPidOf("obexd") > 0)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
TQProcess obexServer(TQString("/usr/lib/bluetooth/obexd"));
|
|
|
|
|
if (!obexServer.start())
|
|
|
|
|
return false;
|
|
|
|
|
TQObject::connect(obexServer, TQT_SIGNAL(processExited()), this,
|
|
|
|
|
TQT_SLOT(slotprocresult()));
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TDEBluetoothApp::stopObexSrv()
|
|
|
|
|
{
|
|
|
|
|
if (obexServer)
|
|
|
|
|
{
|
|
|
|
|
TQObject::disconnect(obexServer, 0, 0, 0);
|
|
|
|
|
int pid = obexServer->processIdentifier();
|
|
|
|
|
if (obexServer->isRunning())
|
|
|
|
|
{
|
|
|
|
|
obexServer->tryTerminate();
|
|
|
|
|
wait(&pid);
|
|
|
|
|
}
|
|
|
|
|
if (obexServer->isRunning())
|
|
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
obexServer = 0;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
kdDebug() << k_funcinfo << endl;
|
|
|
|
|
|
|
|
|
|
TQ_UINT32 pid = findPidOf("obexd");
|
|
|
|
|
|
|
|
|
|
if (pid == 0)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
FILE *fp;
|
|
|
|
|
fp = popen(TQFile::encodeName(TQString("kill %1").arg(pid)), "r");
|
|
|
|
|
if(!fp){
|
|
|
|
|
tqDebug("Could not open pipe for output.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (pclose(fp) == -1)
|
|
|
|
|
tqDebug("Error: Failed to close kill stream");
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TDEBluetoothApp::slotprocresult() {
|
|
|
|
|
TQ_UINT32 TDEBluetoothApp::findPidOf(TQString name) {
|
|
|
|
|
kdDebug() << k_funcinfo << endl;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
char buffer[6];
|
|
|
|
|
fp = popen(TQFile::encodeName("pidof " + name), "r");
|
|
|
|
|
if(!fp){
|
|
|
|
|
tqDebug("Could not open pipe for output.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
TQString readResult;
|
|
|
|
|
while (fgets(buffer, sizeof(buffer), fp) != NULL) {
|
|
|
|
|
readResult.append(buffer);
|
|
|
|
|
}
|
|
|
|
|
if (pclose(fp) == -1)
|
|
|
|
|
tqDebug("Error: Failed to close pidof stream");
|
|
|
|
|
|
|
|
|
|
kdDebug() << "PID: " << readResult.toUInt() << endl;
|
|
|
|
|
return readResult.toUInt();
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
//void TDEBluetoothApp::slotprocresult() {
|
|
|
|
|
// kdDebug() << k_funcinfo << endl;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
void TDEBluetoothApp::slotAdapterAdded(const TQString &adapter)
|
|
|
|
|
{
|
|
|
|
|
AdapterImpl *a = new AdapterImpl("org.bluez", adapter);
|
|
|
|
|
a->setConnection((*(manager->getConnection())));
|
|
|
|
|
adapters.insert(adapter, a);
|
|
|
|
|
if (!authAgent || !authAgent->isRunning())
|
|
|
|
|
startAuthAgent();
|
|
|
|
|
if (!obexServer || !obexServer->isRunning())
|
|
|
|
|
startObexSrv();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TDEBluetoothApp::slotAdapterRemoved(const TQString &adapter)
|
|
|
|
|
{
|
|
|
|
|
adapters.remove(adapter);
|
|
|
|
|
if (adapters.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
if (authAgent->isRunning())
|
|
|
|
|
stopAuthAgent();
|
|
|
|
|
if (obexServer->isRunning())
|
|
|
|
|
stopObexSrv();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: run agents only if enabled in config
|
|
|
|
|
//void TDEBluetoothApp::slotPowerOnChanged(const TQString &adapter, bool state) {
|
|
|
|
|
// kdDebug() << k_funcinfo << endl;
|
|
|
|
|
// if(state) {
|
|
|
|
|
// if (!authAgent->isRunning())
|
|
|
|
|
// startAuthAgent();
|
|
|
|
|
// }
|
|
|
|
|
// else {
|
|
|
|
|
// if (authAgent->isRunning())
|
|
|
|
|
// stopAuthAgent();
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
void TDEBluetoothApp::slotDeviceAdded(const TQString &device)
|
|
|
|
|
{
|
|
|
|
|
DeviceImpl *d = new DeviceImpl("org.bluez", device);
|
|
|
|
|