fixed crash

This commit is contained in:
Patrick von Reth 2014-01-16 09:30:01 +01:00
parent 39ce837ae4
commit 39191c146b
1 changed files with 19 additions and 26 deletions

View File

@ -153,9 +153,8 @@ bool SnarlBackend::initialize(SnoreCore *snore)
return false; return false;
} }
m_eventLoop = new SnarlBackend::SnarlWidget(this); m_eventLoop = new SnarlBackend::SnarlWidget(this);
m_applications.insert(snore->d()->defaultApplication().name(),snarlInterface);
qDebug() << "Initiating Snarl Backend, Snarl version: " << snarlInterface->GetVersion(); qDebug() << "Initiating Snarl Backend, Snarl version: " << snarlInterface->GetVersion();
delete snarlInterface;
return SnoreBackend::initialize(snore); return SnoreBackend::initialize(snore);
} }
@ -168,23 +167,18 @@ bool SnarlBackend::deinitialize()
m_eventLoop->deleteLater(); m_eventLoop->deleteLater();
m_eventLoop = NULL; m_eventLoop = NULL;
} }
m_applications.clear();
return true; return true;
} }
return false; return false;
} }
void SnarlBackend::slotRegisterApplication(const Application &application){ void SnarlBackend::slotRegisterApplication(const Application &application){
SnarlInterface *snarlInterface = NULL;
if(m_applications.contains(application.name())) Q_ASSERT_X(!m_applications.contains(application.name()), Q_FUNC_INFO, "Application already registered");
{
snarlInterface = m_applications.value(application.name()); SnarlInterface *snarlInterface = new SnarlInterface();
}
else
{
snarlInterface = new SnarlInterface();
m_applications.insert(application.name(),snarlInterface); m_applications.insert(application.name(),snarlInterface);
}
QString appName = application.name().replace(" ","_");//app sig must not contain spaces QString appName = application.name().replace(" ","_");//app sig must not contain spaces
snarlInterface->Register(appName.toUtf8().constData(), snarlInterface->Register(appName.toUtf8().constData(),
application.name().toUtf8().constData(), application.name().toUtf8().constData(),
@ -200,25 +194,26 @@ void SnarlBackend::slotRegisterApplication(const Application &application){
} }
void SnarlBackend::slotDeregisterApplication(const Application &application){ void SnarlBackend::slotDeregisterApplication(const Application &application){
SnarlInterface *snarlInterface = m_applications.take(application.name()); if(!m_applications.contains(application.name()))
if(snarlInterface == NULL)
{ {
qDebug() << Q_FUNC_INFO << "Unknown apllication: " << application.name();
return; return;
} }
SnarlInterface *snarlInterface = m_applications.take(application.name());
QString appName = application.name().replace(" ","_");//app sig must not contain spaces QString appName = application.name().replace(" ","_");//app sig must not contain spaces
snarlInterface->Unregister(appName.toUtf8().constData()); snarlInterface->Unregister(appName.toUtf8().constData());
delete snarlInterface; delete snarlInterface;
} }
void SnarlBackend::slotNotify(Notification notification){ void SnarlBackend::slotNotify(Notification notification){
SnarlInterface *snarlInterface = m_applications.value(notification.application().name()); if(!m_applications.contains(notification.application().name()))
if(snarlInterface == NULL)
{ {
qDebug()<<notification.application()<<"not in snarl interfaces, defaulting"; qDebug() << Q_FUNC_INFO << "Unknown apllication: " << notification.application().name();
qDebug()<<m_applications.keys(); return;
snarlInterface = m_applications[snore()->d()->defaultApplication().name()];
} }
SnarlInterface *snarlInterface = m_applications.value(notification.application().name());
Snarl::V42::SnarlEnums::MessagePriority priority = Snarl::V42::SnarlEnums::PriorityUndefined; Snarl::V42::SnarlEnums::MessagePriority priority = Snarl::V42::SnarlEnums::PriorityUndefined;
switch(notification.priority()) switch(notification.priority())
{ {
@ -272,12 +267,10 @@ void SnarlBackend::slotNotify(Notification notification){
void SnarlBackend::slotCloseNotification(Notification notification) void SnarlBackend::slotCloseNotification(Notification notification)
{ {
SnarlInterface *snarlInterface = m_applications.value(notification.application().name()); if(!m_applications.contains(notification.application().name()))
if(snarlInterface == NULL)
{ {
qDebug()<<notification.application()<<"not in snarl interfaces, defaulting"; qDebug() << Q_FUNC_INFO << "Unknown apllication: " << notification.application().name();
qDebug()<<m_applications.keys(); return;
snarlInterface = m_applications[snore()->d()->defaultApplication().name()];
} }
snarlInterface->Hide(m_idMap.take(notification.id())); m_applications.value(notification.application().name())->Hide(m_idMap.take(notification.id()));
} }