blob: 3dd006a917568a85e9922c6f77f3da4efee2ef3a [file] [log] [blame]
Ilya Moiseenko18c8a132013-10-24 01:52:52 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * @copyright See LICENCE for copyright and license information.
4 *
5 * @author Ilya Moiseenko <iliamo@ucla.edu>
6 */
7
Alexander Afanasyev669ea1a2013-11-08 22:25:23 -08008#include "config.h"
9
Ilya Moiseenko18c8a132013-10-24 01:52:52 -070010#include "tray-menu.h"
11#include "ui_traymenu.h" //generated from traymenu.ui
12#include "quit-dialog.h"
13#include "fib-input-dialog.h"
Ilya Moiseenko656d52d2013-10-25 14:19:10 -070014#include "network-manager.h"
Ilya Moiseenko18c8a132013-10-24 01:52:52 -070015
16#include <QMenu>
17#include <QCloseEvent>
18#include <QDesktopServices>
Ilya Moiseenko18c8a132013-10-24 01:52:52 -070019#include <QUrl>
20#include <QCheckBox>
21#include <QLabel>
22#include <QHBoxLayout>
23#include <QLineEdit>
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -070024#include <QDir>
Ilya Moiseenko69abb972013-11-04 16:02:20 -080025#include <QScrollBar>
Ilya Moiseenkoa439f3d2013-11-09 18:41:46 -080026#include <QHBoxLayout>
27#include <QVBoxLayout>
Ilya Moiseenko18c8a132013-10-24 01:52:52 -070028
29TrayMenu::TrayMenu(QWidget *parent) :
30 QMainWindow(parent),
31 ui(new Ui::TrayMenu)
32{
Ilya Moiseenko5a4e4242013-11-10 12:54:50 -080033 processLookup = new QProcess(this);
34 QStringList arguments;
35 arguments << "-al";
36 connect(processLookup,SIGNAL(finished(int)), this, SLOT(parseProcessLookup()));
37 processLookup->start("ps",arguments);
38
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -070039 networkManager = new NetworkManager();
40
41 QCoreApplication::setOrganizationName("UCLA");
42 QCoreApplication::setOrganizationDomain("named-data.net");
43 QCoreApplication::setApplicationName("NDNx Control Center");
44
45 persistentSettings = new QSettings();
46
Ilya Moiseenko18c8a132013-10-24 01:52:52 -070047 ui->setupUi(this);
48
49 createTrayIcon();
50 setIcon(true);
51 createToolbar();
52 createTableView();
53
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -070054 loadSettings();
Ilya Moiseenko656d52d2013-10-25 14:19:10 -070055
Ilya Moiseenko18c8a132013-10-24 01:52:52 -070056 connect(ui->openTrafficMapButton, SIGNAL(pressed()), this, SLOT(openTrafficMap()));
57 connect(ui->openRoutingStatusButton, SIGNAL(pressed()), this, SLOT(openRoutingStatus()));
58 connect(ui->addFibButton, SIGNAL(pressed()), this, SLOT(showFibInputDialog()));
59 connect(ui->deleteFibButton, SIGNAL(released()), this, SLOT(deleteFibEntry()));
Ilya Moiseenko18c8a132013-10-24 01:52:52 -070060 connect(ui->hubDiscoveryCheckbox, SIGNAL(stateChanged(int)), this, SLOT(changeHubDiscovery()));
61 connect(ui->loginStartCheckbox, SIGNAL(stateChanged(int)), this, SLOT(changeLoginStart()));
Ilya Moiseenko18c8a132013-10-24 01:52:52 -070062 connect(ui->tableView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectTableRow()));
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -070063 connect(ui->openNdnCertificationButton, SIGNAL(released()), this, SLOT(openCertificationPage()));
Ilya Moiseenko18c8a132013-10-24 01:52:52 -070064
65 statusUpdateThread = new QThread();
66 statusUpdateThread->start();
67
68 daemonStatusTimer = new QTimer(statusUpdateThread);
69 connect(daemonStatusTimer, SIGNAL(timeout()), this, SLOT(daemonStatusUpdate()));
Ilya Moiseenko69abb972013-11-04 16:02:20 -080070 daemonStatusTimer->start(2000);
Ilya Moiseenko18c8a132013-10-24 01:52:52 -070071
72 trayIcon->show();
Ilya Moiseenko69abb972013-11-04 16:02:20 -080073 model = NULL;
74 dialog = new FibInputDialog(this);
75
76 urlManager = new QNetworkAccessManager(this);
77 connect(urlManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(runXmlProc(QNetworkReply*)));
Ilya Moiseenko18c8a132013-10-24 01:52:52 -070078}
79
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -070080void TrayMenu::loadSettings()
81{
82 QVariant value;
83
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -070084 value = persistentSettings->value(ENABLE_HUB_DISCOVERY);
85 if(!value.isNull())
86 {
87 enableHubDiscovery = value.toBool();
88 ui->hubDiscoveryCheckbox->setChecked(enableHubDiscovery);
89 }
90 else
91 {
92 ui->hubDiscoveryCheckbox->setChecked(true);
93 changeHubDiscovery();
94 }
95
96 value = persistentSettings->value(ENABLE_START_ON_LOGIN);
97 if(!value.isNull())
98 {
99 enableStartOnLogin = value.toBool();
100 ui->loginStartCheckbox->setChecked(enableStartOnLogin);
101 }
102 else
103 {
104 ui->loginStartCheckbox->setChecked(false);
105 changeLoginStart();
106 }
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700107}
108
109void TrayMenu::changeHubDiscovery()
110{
111 if(ui->hubDiscoveryCheckbox->isChecked())
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700112 {
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700113 enableHubDiscovery = true;
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700114 persistentSettings->setValue(ENABLE_HUB_DISCOVERY, true);
115 }
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700116 else
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700117 {
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700118 enableHubDiscovery = false;
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700119 persistentSettings->setValue(ENABLE_HUB_DISCOVERY, false);
120 }
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700121}
122
123void TrayMenu::changeLoginStart()
124{
125 if(ui->loginStartCheckbox->isChecked())
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700126 {
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700127 enableStartOnLogin = true;
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700128 persistentSettings->setValue(ENABLE_START_ON_LOGIN, true);
129 makeAutostartDirectory();
130 }
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700131 else
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700132 {
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700133 enableStartOnLogin = false;
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700134 persistentSettings->setValue(ENABLE_START_ON_LOGIN, false);
135
136 QProcess *process = new QProcess();
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800137 connect(process,SIGNAL(finished(int)),process, SLOT(deleteLater()));
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700138 QStringList arguments;
139 arguments << QDir::homePath() + AUTOSTART_DIRECTORY + SHORTCUT_FILE;
140 process->start("rm", arguments);
141 }
142}
143
144void TrayMenu::makeAutostartDirectory()
145{
146 QProcess *process = new QProcess();
147 connect(process, SIGNAL(finished(int)), this, SLOT(copyFile()));
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800148 connect(process,SIGNAL(finished(int)),process, SLOT(deleteLater()));
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700149 QStringList arguments;
150 arguments << QDir::homePath() + AUTOSTART_DIRECTORY;
151 process->start("mkdir", arguments);
152}
153
154void TrayMenu::copyFile()
155{
156 QProcess *process = new QProcess();
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800157 connect(process,SIGNAL(finished(int)),process, SLOT(deleteLater()));
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700158 QStringList arguments;
Alexander Afanasyeveb111572013-11-08 22:59:43 -0800159 arguments << QString(RESOURCES_DIR) + "/" + SHORTCUT_FILE << QDir::homePath() + AUTOSTART_DIRECTORY;
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700160 process->start("cp",arguments);
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700161}
162
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700163void TrayMenu::showFibInputDialog()
164{
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800165 dialog->clear();
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700166 dialog->exec();
167}
168
169void TrayMenu::openTrafficMap()
170{
171 QDesktopServices::openUrl(QUrl("http://ndnmap.arl.wustl.edu/", QUrl::TolerantMode));
172}
173
174void TrayMenu::openRoutingStatus()
175{
176 QDesktopServices::openUrl(QUrl("http://netlab.cs.memphis.edu/script/htm/status.htm", QUrl::TolerantMode));
177}
178
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700179void TrayMenu::openCertificationPage()
180{
181 QDesktopServices::openUrl(QUrl("http://ndncert.named-data.net", QUrl::TolerantMode));
182}
183
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700184void TrayMenu::createTrayIcon()
185{
186 trayIconMenu = new QMenu(this);
187
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800188 statusIndicator = new QAction("Inactive", this);
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700189 trayIconMenu->addAction(statusIndicator);
190
191 trayIconMenu->addSeparator();
192
Ilya Moiseenko3adef432013-11-01 03:42:40 -0700193 displayStatus = new QAction(" Sent / Recv ", this);
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700194 trayIconMenu->addAction(displayStatus);
Ilya Moiseenko3adef432013-11-01 03:42:40 -0700195 interestSentRecv = new QAction("Interests 0 / 0", this);
196 trayIconMenu->addAction(interestSentRecv);
197 dataSentRecv = new QAction("Data 0 / 0", this);
198 trayIconMenu->addAction(dataSentRecv);
199
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700200 trayIconMenu->addSeparator();
201
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800202 open = new QAction("Preferences...", this);
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700203 connect(open, SIGNAL(triggered()), this, SLOT(show()));
204 trayIconMenu->addAction(open);
205
Ilya Moiseenkoa439f3d2013-11-09 18:41:46 -0800206 close = new QAction("Quit", this);
Alexander Afanasyev86240d02013-11-08 23:32:53 -0800207 // connect(close, SIGNAL(triggered()), this, SLOT(confirmQuit()));
208 connect(close, SIGNAL(triggered()), qApp, SLOT(quit()));
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700209 trayIconMenu->addAction(close);
210
211 trayIcon = new QSystemTrayIcon(this);
212 trayIcon->setContextMenu(trayIconMenu);
213
214 connect(
215 trayIcon,
216 SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
217 this,
218 SLOT(trayIconClicked(QSystemTrayIcon::ActivationReason))
219 );
220}
221
222void TrayMenu::createToolbar()
223{
Ilya Moiseenkoa439f3d2013-11-09 18:41:46 -0800224 ui->toolBar->setFloatable(false);
225 ui->toolBar->setMovable(false);
226 ui->toolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
227 ui->toolBar->setAllowedAreas(Qt::TopToolBarArea);
228 ui->toolBar->setOrientation(Qt::Horizontal);
229 ui->toolBar->setIconSize(QSize(32,32));
230 ui->toolBar->resize(this->width(), 64);
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700231
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800232 openGeneralSettings = new QAction("General", this);
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700233 openGeneralSettings->setIcon(QIcon(":/resource/Resources/preferences-desktop.png"));
234 connect(openGeneralSettings,SIGNAL(triggered()),this, SLOT(generalSettingsClicked()));
235
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800236 openForwardingSettings = new QAction("Forwarding", this);
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700237 openForwardingSettings->setIcon(QIcon(":/resource/Resources/emblem-web.png"));
238 connect(openForwardingSettings,SIGNAL(triggered()),this, SLOT(forwardingSettingsClicked()));
239
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800240 openSecuritySettings = new QAction("Security", this);
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700241 openSecuritySettings->setIcon(QIcon(":/resource/Resources/emblem-system.png"));
242 connect(openSecuritySettings,SIGNAL(triggered()),this, SLOT(securitySettingsClicked()));
243
Ilya Moiseenkoa439f3d2013-11-09 18:41:46 -0800244 ui->toolBar->addAction(openGeneralSettings);
245 ui->toolBar->addAction(openForwardingSettings);
246 ui->toolBar->addAction(openSecuritySettings);
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700247}
248
249void TrayMenu::generalSettingsClicked()
250{
251 ui->generalSettingsWidget->show();
252 ui->forwardingSettingsWidget->hide();
253 ui->securitySettingsWidget->hide();
254}
255
256void TrayMenu::forwardingSettingsClicked()
257{
258 ui->generalSettingsWidget->hide();
259 ui->forwardingSettingsWidget->show();
260 ui->securitySettingsWidget->hide();
261}
262
263void TrayMenu::securitySettingsClicked()
264{
265 ui->generalSettingsWidget->hide();
266 ui->forwardingSettingsWidget->hide();
267 ui->securitySettingsWidget->show();
268}
269
270void TrayMenu::displayPopup()
271{
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800272 trayIcon->showMessage("NDNx Status", statusXml);
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700273}
274
275void TrayMenu::addFibEntry()
276{
277 QString name = dialog->getPrefixName();
278 QString tunnelType = dialog->getTunnelType();
279 QString endpoint = dialog->getEndpoint();
280
281 QStringList arguments;
282 arguments << "add" << name << tunnelType << endpoint;
283
284 dialog->hide();
285
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700286 QProcess *process = new QProcess();
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800287 connect(process,SIGNAL(finished(int)),process, SLOT(deleteLater()));
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700288 process->start(NDND_FIB_COMMAND, arguments);
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700289}
290
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700291void TrayMenu::closeEvent(QCloseEvent *event)
292{
293 if (trayIcon->isVisible())
294 {
295 hide();
296 event->ignore();
297 }
298}
299
300void TrayMenu::showEvent(QShowEvent * event)
301{
302 ui->generalSettingsWidget->show();
303 ui->forwardingSettingsWidget->hide();
304 ui->securitySettingsWidget->hide();
305}
306
307void TrayMenu::trayIconClicked(QSystemTrayIcon::ActivationReason reason)
308{
309 if(reason == QSystemTrayIcon::Trigger)
310 this->show();
311}
312
313void TrayMenu::setIcon(bool isConnected)
314{
315 if(isConnected)
316 trayIcon->setIcon(QIcon(":/resource/Resources/icon-connected-white.png"));
317 else
318 trayIcon->setIcon(QIcon(":/resource/Resources/icon-disconnected-white.png"));
319}
320
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700321void TrayMenu::daemonStatusUpdate()
322{
Alexander Afanasyev669ea1a2013-11-08 22:25:23 -0800323 urlManager->get(QNetworkRequest(QUrl("http://localhost:6363/?f=xml")));
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800324}
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700325
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800326void TrayMenu::runXmlProc(QNetworkReply *reply)
327{
328 QByteArray buffer = reply->readAll();
329 applyStatusXslt = new QProcess();
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700330
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800331 QStringList arguments;
Alexander Afanasyeveb111572013-11-08 22:59:43 -0800332 arguments << QString(RESOURCES_DIR) + "/" + STATUS_XSLT_FILE << "-";
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800333 connect(applyStatusXslt,SIGNAL(finished(int)), this, SLOT(parseStatusXml()));
334 //connect(applyStatusXslt,SIGNAL(finished(int)), applyStatusXslt, SLOT(deleteLater()));
Alexander Afanasyev669ea1a2013-11-08 22:25:23 -0800335 applyStatusXslt->start(XSLTPROC,arguments);
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800336 applyStatusXslt->write(buffer);
337 applyStatusXslt->closeWriteChannel();
338
339 applyFibXslt = new QProcess();
340 QStringList args;
Alexander Afanasyeveb111572013-11-08 22:59:43 -0800341 args << QString(RESOURCES_DIR) + "/" + FIB_XSLT_FILE << "-";
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800342 connect(applyFibXslt,SIGNAL(finished(int)), this, SLOT(parseFibXml()));
343 //connect(applyFibXslt,SIGNAL(finished(int)), applyFibXslt, SLOT(deleteLater()));
Alexander Afanasyev669ea1a2013-11-08 22:25:23 -0800344 applyFibXslt->start(XSLTPROC,args);
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800345 applyFibXslt->write(buffer);
346 applyFibXslt->closeWriteChannel();
347}
348
349void TrayMenu::parseStatusXml()
350{
351 QByteArray stdout = applyStatusXslt->readAllStandardOutput();
352 QByteArray stderr = applyStatusXslt->readAllStandardError();
353 applyStatusXslt->deleteLater();
354
355 statusXml = QString(stdout);
356
357 if((statusXml == "") || (stderr.length()>0)) // there was an error during Query evaluation
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700358 {
359 daemonStarted = false;
360 setIcon(false);
Alexander Afanasyev86240d02013-11-08 23:32:53 -0800361 statusIndicator->setText("Inactive");
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700362
Alexander Afanasyev86240d02013-11-08 23:32:53 -0800363 // QProcess *process = new QProcess();
364 // if(enableHubDiscovery)
365 // connect(process, SIGNAL(finished(int)), networkManager, SLOT(autoconfigDaemon()));
366 //
367 // connect(process,SIGNAL(finished(int)), process, SLOT(deleteLater()));
368 // process->start(NDND_START_COMMAND);
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700369 }
370 else
371 {
372 daemonStarted = true;
373 setIcon(true);
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800374 statusIndicator->setText("Active");
375
Ilya Moiseenko3adef432013-11-01 03:42:40 -0700376 QString interestIn = statusXml.mid(statusXml.indexOf("<in>")+4, statusXml.indexOf("</in>") - (statusXml.indexOf("<in>")+4));
377 QString interestOut = statusXml.mid(statusXml.indexOf("<out>")+5, statusXml.indexOf("</out>") - (statusXml.indexOf("<out>")+5));
378 QString dataIn = statusXml.mid(statusXml.lastIndexOf("<in>")+4, statusXml.lastIndexOf("</in>") - (statusXml.lastIndexOf("<in>")+4));
379 QString dataOut = statusXml.mid(statusXml.lastIndexOf("<out>")+5, statusXml.lastIndexOf("</out>") - (statusXml.lastIndexOf("<out>")+5));
380
381 int i = 0;
382 int k = 0;
383 if((dataOut.length() - interestOut.length()) > 0)
384 {
385 i = dataOut.length() - interestOut.length();
386 i*=2; //because space takes less space than a letter
387 }
388
389 if((interestOut.length() - dataOut.length()) > 0)
390 {
391 k = interestOut.length() - dataOut.length();
392 k*=2; //because space takes less space than a letter
393 }
394
395 QString interestStats = QString("%1%2%3%4").arg("Interests",-16,' ').arg(interestOut,6+i,' ').arg(" / ",3).arg(interestIn,-6,' ');
396 QString dataStats = QString("%1%2%3%4").arg("Data",-20,' ').arg(dataOut,6+k,' ').arg(" / ",3).arg(dataIn,-6,' ');
397
398 //Now I try to align header "Sent / Recv" centrally with the upper line
399 QString padding;
400 for(int j = 0; j < interestStats.indexOf(interestOut); j++)
401 {
402 if(interestStats.at(j)==' ')
403 padding +=" ";
404 else
405 padding += " "; //because space takes less space than a letter
406 }
407
408 QString header;
409 int m = 0;
410 if(interestOut.length() - QString("Sent").length() > 0)
411 {
412 m = interestOut.length() - QString("Sent").length();
413 m *=3;
Ilya Moiseenko3adef432013-11-01 03:42:40 -0700414 header = QString("%1%2").arg(padding).arg(" Sent / Recv",QString(" Sent / Recv").length() + m,' ');
415 }
416 else if(interestOut.length() - QString("Sent").length() < 0)
417 {
Ilya Moiseenko3adef432013-11-01 03:42:40 -0700418 padding.truncate(padding.length()-(QString("Sent").length() - interestOut.length()));
419 header = padding + "Sent / Recv";
420 }
421 else
422 {
423 header = padding + " Sent / Recv";
424 }
425
426 interestSentRecv->setText(interestStats);
427 dataSentRecv->setText(dataStats);
428 displayStatus->setText(header);
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700429 }
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800430}
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700431
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800432void TrayMenu::parseFibXml()
433{
434 QByteArray stdout = applyFibXslt->readAllStandardOutput();
435 QByteArray stderr = applyFibXslt->readAllStandardError();
436 applyFibXslt->deleteLater();
437
438 fibContentsXml = QString(stdout);
439
440 if((stdout == "") || (stderr.length()>0))
441 return;
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700442
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700443 if ((enableHubDiscovery) && (fibContentsXml.indexOf("ndn:/autoconf-route",0,Qt::CaseInsensitive) == -1))
444 {
445 networkManager->autoconfigDaemon();
446 }
447
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700448 QDomDocument xmldoc;
449 QDomElement root;
450
451 xmldoc.setContent(fibContentsXml);
452 root=xmldoc.documentElement();
453
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800454 if(model != NULL)
455 {
456 scrollPosition = ui->tableView->verticalScrollBar()->value();
457 model->clear();
458 delete model;
459 }
460
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700461 model = new QStandardItemModel(root.childNodes().count(),3);
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800462 model->setHorizontalHeaderItem(0, new QStandardItem("NDN prefix"));
463 model->setHorizontalHeaderItem(1, new QStandardItem("Face ID"));
464 model->setHorizontalHeaderItem(2, new QStandardItem("Endpoint"));
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700465
466 int row = 0;
467 QDomNode fibEntry=root.firstChild();
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800468
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700469 while (!fibEntry.isNull())
470 {
471 QDomNodeList properties = fibEntry.childNodes();
472
473 QDomNode faceID = properties.at(0);
474 QDomNode ip = properties.at(1);
475 QDomNode prefix = properties.at(2);
476
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700477 model->setItem(row, 0, new QStandardItem(prefix.toElement().text()));
478 model->setItem(row, 1, new QStandardItem(faceID.toElement().text()));
479 model->setItem(row, 2, new QStandardItem(ip.toElement().text()));
480
481 fibEntry = fibEntry.nextSibling();
482 row++;
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800483 }
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700484
485 ui->tableView->setModel(model);
486
Ilya Moiseenkoa439f3d2013-11-09 18:41:46 -0800487 ui->tableView->setColumnWidth(0, ui->tableView->size().width() / 2 );
488 ui->tableView->setColumnWidth(1, ui->tableView->size().width() / 6 );
489
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700490 if(selectedRow >= 0)
491 ui->tableView->selectRow(selectedRow);
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800492
493 if(scrollPosition >= 0)
494 ui->tableView->verticalScrollBar()->setValue(scrollPosition);
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700495}
496
497void TrayMenu::createTableView()
498{
Ilya Moiseenkoa439f3d2013-11-09 18:41:46 -0800499 ui->tableView->horizontalHeader()->setResizeMode(QHeaderView::Fixed);
500 ui->tableView->horizontalHeader()->setStretchLastSection(true);
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700501 ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
502 ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
503
504 selectedRow = -1;
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800505 scrollPosition = -1;
Ilya Moiseenkoa439f3d2013-11-09 18:41:46 -0800506
507 QHBoxLayout *hlayout = new QHBoxLayout();
508 hlayout->addWidget(ui->addFibButton,0, Qt::AlignLeft);
509 hlayout->addWidget(ui->deleteFibButton, 20, Qt::AlignLeft);
510
511 QVBoxLayout *vlayout = new QVBoxLayout();
512 vlayout->addWidget(ui->label);
513 vlayout->addWidget(ui->tableView);
514 vlayout->addLayout(hlayout);
515
516 ui->forwardingSettingsWidget->setLayout(vlayout);
517
518 QVBoxLayout *expanding = new QVBoxLayout();
519 expanding->addWidget(ui->forwardingSettingsWidget);
520 ui->centralWidget->setLayout(expanding);
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700521}
522
523void TrayMenu::selectTableRow()
524{
525 selectedRow = ui->tableView->selectionModel()->selection().indexes().at(0).row();
526}
527
528void TrayMenu::deleteFibEntry()
529{
530 if(selectedRow < 0)
531 return;
532
533 QStandardItem *prefix = model->item(selectedRow,0);
534 if(prefix == NULL)
535 return;
536
537 QStandardItem *faceID = model->item(selectedRow,1);
538 if(faceID == NULL)
539 return;
540
541 QStringList arguments;
542 arguments << "del" << prefix->text() << "face" << faceID->text();
543
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700544 QProcess *process = new QProcess();
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800545 connect(process,SIGNAL(finished(int)), process, SLOT(deleteLater()));
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -0700546 process->start(NDND_FIB_COMMAND, arguments);
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700547}
548
Ilya Moiseenkoa439f3d2013-11-09 18:41:46 -0800549void TrayMenu::resizeEvent(QResizeEvent * event)
550{
551 ui->tableView->setColumnWidth(0, ui->tableView->size().width() / 2);
552 ui->tableView->setColumnWidth(1, ui->tableView->size().width() / 6);
553}
554
555
Ilya Moiseenko5a4e4242013-11-10 12:54:50 -0800556void TrayMenu::parseProcessLookup()
557{
558 QByteArray stdout = processLookup->readAllStandardOutput();
559 processLookup->deleteLater();
560
561 QString s = QString(stdout);
Ilya Moiseenkoa439f3d2013-11-09 18:41:46 -0800562
Ilya Moiseenko5a4e4242013-11-10 12:54:50 -0800563 if(s == "")
564 return;
565 else if(s.indexOf("ndnx-control") != s.lastIndexOf("ndnx-control"))
566 qApp->quit();
567}
Ilya Moiseenkoa439f3d2013-11-09 18:41:46 -0800568
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700569TrayMenu::~TrayMenu()
570{
571 daemonStatusTimer->stop();
Alexander Afanasyev5cce3ba2013-11-08 23:35:24 -0800572 statusUpdateThread->exit(0);
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700573 delete ui;
574 delete trayIcon;
575 delete trayIconMenu;
576 delete open;
577 delete close;
578 delete openGeneralSettings;
579 delete openForwardingSettings;
580 delete openSecuritySettings;
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700581 delete statusUpdateThread;
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700582 delete dialog;
Ilya Moiseenko69abb972013-11-04 16:02:20 -0800583 delete networkManager;
584 delete persistentSettings;
Ilya Moiseenko18c8a132013-10-24 01:52:52 -0700585}
Alexander Afanasyeva822b572013-11-04 12:36:34 -0800586
587#if WAF
588#include "tray-menu.moc"
589#include "tray-menu.cpp.moc"
590#endif