Adding codes to handle no ndnd exception
diff --git a/src/chatdialog.cpp b/src/chatdialog.cpp
index 9046f2c..10d97f2 100644
--- a/src/chatdialog.cpp
+++ b/src/chatdialog.cpp
@@ -136,7 +136,12 @@
m_keychain = ndn::Ptr<ndn::security::Keychain>(new ndn::security::Keychain(m_identityManager, m_invitationPolicyManager, NULL));
- m_handler = ndn::Ptr<ndn::Wrapper>(new ndn::Wrapper(m_keychain));
+ try{
+ m_handler = ndn::Ptr<ndn::Wrapper>(new ndn::Wrapper(m_keychain));
+ }catch(ndn::Error::ndnOperation& e){
+ emit noNdnConnection(QString::fromStdString("Cannot conect to ndnd!\n Have you started your ndnd?"));
+ }
+
if(trial == true)
{
diff --git a/src/chatdialog.h b/src/chatdialog.h
index 4e7ab59..2e6ea1c 100644
--- a/src/chatdialog.h
+++ b/src/chatdialog.h
@@ -195,6 +195,9 @@
void
closeChatDialog(const ndn::Name& chatroomPrefix);
+ void
+ noNdnConnection(const QString& msg);
+
public slots:
void
processTreeUpdate(const std::vector<Sync::MissingDataInfo>);
diff --git a/src/contact-manager.cpp b/src/contact-manager.cpp
index 371a317..eac5c51 100644
--- a/src/contact-manager.cpp
+++ b/src/contact-manager.cpp
@@ -26,16 +26,13 @@
INIT_LOGGER("ContactManager");
-ContactManager::ContactManager(Ptr<ContactStorage> contactStorage,
- Ptr<DnsStorage> dnsStorage,
- QObject* parent)
+ContactManager::ContactManager(QObject* parent)
: QObject(parent)
- , m_contactStorage(contactStorage)
- , m_dnsStorage(dnsStorage)
{
- setKeychain();
+ m_contactStorage = Ptr<ContactStorage>::Create();
+ m_dnsStorage = Ptr<DnsStorage>::Create();
- m_wrapper = Ptr<Wrapper>(new Wrapper(m_keychain));
+ setKeychain();
}
ContactManager::~ContactManager()
@@ -43,6 +40,16 @@
}
void
+ContactManager::setWrapper()
+{
+ try{
+ m_wrapper = Ptr<Wrapper>(new Wrapper(m_keychain));
+ }catch(ndn::Error::ndnOperation& e){
+ emit noNdnConnection(QString::fromStdString("Cannot conect to ndnd!\n Have you started your ndnd?"));
+ }
+}
+
+void
ContactManager::setKeychain()
{
Ptr<IdentityManager> identityManager = Ptr<IdentityManager>::Create();
diff --git a/src/contact-manager.h b/src/contact-manager.h
index 26a2a63..6de23d4 100644
--- a/src/contact-manager.h
+++ b/src/contact-manager.h
@@ -27,13 +27,14 @@
Q_OBJECT
public:
- ContactManager(ndn::Ptr<ContactStorage> contactStorage,
- ndn::Ptr<DnsStorage> dnsStorage,
- QObject* parent = 0);
+ ContactManager(QObject* parent = 0);
~ContactManager();
void
+ setWrapper();
+
+ void
fetchSelfEndorseCertificate(const ndn::Name& identity);
void
@@ -137,6 +138,9 @@
signals:
+ void
+ noNdnConnection(const QString& msg);
+
void
contactFetched(const EndorseCertificate& endorseCertificate);
diff --git a/src/contactpanel.cpp b/src/contactpanel.cpp
index 56db0a7..a63f9f9 100644
--- a/src/contactpanel.cpp
+++ b/src/contactpanel.cpp
@@ -42,9 +42,10 @@
Q_DECLARE_METATYPE(ndn::security::IdentityCertificate)
Q_DECLARE_METATYPE(ChronosInvitation)
-ContactPanel::ContactPanel(Ptr<ContactManager> contactManager, QWidget *parent)
+ContactPanel::ContactPanel(QWidget *parent)
: QDialog(parent)
, ui(new Ui::ContactPanel)
+ , m_warningDialog(new WarningDialog)
, m_contactListModel(new QStringListModel)
, m_startChatDialog(new StartChatDialog)
, m_invitationDialog(new InvitationDialog)
@@ -55,8 +56,13 @@
createAction();
- m_contactManager = contactManager;
+ m_contactManager = Ptr<ContactManager>::Create();
+ connect(&*m_contactManager, SIGNAL(noNdnConnection(const QString&)),
+ this, SLOT(showError(const QString&)));
+
+ m_contactManager->setWrapper();
+
openDB();
refreshContactList();
@@ -71,13 +77,18 @@
m_profileEditor = new ProfileEditor(m_contactManager);
m_profileEditor->setCurrentIdentity(m_defaultIdentity);
- m_addContactPanel = new AddContactPanel(contactManager);
- m_browseContactDialog = new BrowseContactDialog(contactManager);
- m_setAliasDialog = new SetAliasDialog(contactManager);
+ m_addContactPanel = new AddContactPanel(m_contactManager);
+ m_browseContactDialog = new BrowseContactDialog(m_contactManager);
+ m_setAliasDialog = new SetAliasDialog(m_contactManager);
ui->setupUi(this);
- m_handler = Ptr<Wrapper>(new Wrapper(m_keychain));
+ try{
+ m_handler = Ptr<Wrapper>(new Wrapper(m_keychain));
+ }catch(ndn::Error::ndnOperation& e){
+ showError(QString::fromStdString("Cannot conect to ndnd!\n Have you started your ndnd?"));
+ }
+
setLocalPrefix();
@@ -415,6 +426,12 @@
}
void
+ContactPanel::showError(const QString& msg){
+ QMessageBox::critical(this, tr("Chronos"), msg, QMessageBox::Ok);
+ exit(1);
+}
+
+void
ContactPanel::updateSelection(const QItemSelection &selected,
const QItemSelection &deselected)
{
@@ -621,6 +638,8 @@
connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)),
this, SLOT(removeChatDialog(const ndn::Name&)));
+ connect(chatDialog, SIGNAL(noNdnConnection(const QString&)),
+ this, SLOT(showError(const QString&)));
// send invitation
chatDialog->sendInvitation(inviteeItem, isIntroducer);
@@ -642,6 +661,8 @@
connect(chatDialog, SIGNAL(closeChatDialog(const ndn::Name&)),
this, SLOT(removeChatDialog(const ndn::Name&)));
+ connect(chatDialog, SIGNAL(noNdnConnection(const QString&)),
+ this, SLOT(showError(const QString&)));
chatDialog->addChatDataRule(invitation.getInviterPrefix(), identityCertificate, true);
chatDialog->publishIntroCert(identityCertificate, true);
diff --git a/src/contactpanel.h b/src/contactpanel.h
index 55f9daf..92bccf3 100644
--- a/src/contactpanel.h
+++ b/src/contactpanel.h
@@ -15,6 +15,7 @@
#include <QStringListModel>
#include <QtSql/QSqlDatabase>
#include <QMenu>
+#include <QMessageBox>
#include "profileeditor.h"
#include "addcontactpanel.h"
@@ -25,6 +26,7 @@
#include "chatdialog.h"
#include "endorse-combobox-delegate.h"
#include "browsecontactdialog.h"
+#include "warningDialog.h"
#ifndef Q_MOC_RUN
#include "contact-manager.h"
@@ -42,8 +44,7 @@
Q_OBJECT
public:
- explicit ContactPanel(ndn::Ptr<ContactManager> contactManager,
- QWidget *parent = 0);
+ explicit ContactPanel(QWidget *parent = 0);
~ContactPanel();
@@ -118,6 +119,9 @@
private slots:
void
+ showError(const QString& msg);
+
+ void
updateSelection(const QItemSelection &selected,
const QItemSelection &deselected);
@@ -193,6 +197,7 @@
private:
Ui::ContactPanel *ui;
+ WarningDialog* m_warningDialog;
ndn::Ptr<ContactManager> m_contactManager;
QStringListModel* m_contactListModel;
ProfileEditor* m_profileEditor;
diff --git a/src/main.cpp b/src/main.cpp
index 0ed7fc2..df4511b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -16,9 +16,7 @@
#include "dns-storage.h"
#include "contact-manager.h"
#include "logging.h"
-#include <ndn.cxx/security/identity/identity-manager.h>
-#include <ndn.cxx/security/identity/osx-privatekey-storage.h>
-#include <ndn.cxx/security/identity/basic-identity-storage.h>
+#include <ndn.cxx/wrapper/wrapper.h>
INIT_LOGGER("MAIN");
@@ -33,15 +31,17 @@
bool notify(QObject * receiver, QEvent * event)
{
- try
- {
+ try {
return QApplication::notify(receiver, event);
- }
- catch(std::exception& e)
- {
- std::cerr << "Exception thrown:" << e.what() << endl;
- return false;
- }
+ }
+ catch(ndn::Error::ndnOperation& e){
+ std::cerr << "Canno connect to ndnd!" << endl;
+ return false;
+ }
+ catch(std::exception& e){
+ std::cerr << "Exception thrown:" << e.what() << endl;
+ return false;
+ }
}
};
@@ -50,21 +50,7 @@
{
NewApp app(argc, argv);
- // app.setWindowIcon(QIcon(":/demo.icns"));
-
- Ptr<ContactStorage> contactStorage = NULL;
- Ptr<DnsStorage> dnsStorage = NULL;
- try{
- contactStorage = Ptr<ContactStorage>::Create();
- dnsStorage = Ptr<DnsStorage>::Create();
- }catch(std::exception& e){
- std::cerr << e.what() << std::endl;
- exit(1);
- }
-
- Ptr<ContactManager> contactManager = Ptr<ContactManager>(new ContactManager(contactStorage, dnsStorage));
-
- ContactPanel contactPanel(contactManager);
+ ContactPanel contactPanel;
contactPanel.show ();
contactPanel.activateWindow ();