diff --git a/fscomm/FSComm.pro b/fscomm/FSComm.pro index 8542f54123..c435cfca73 100644 --- a/fscomm/FSComm.pro +++ b/fscomm/FSComm.pro @@ -33,7 +33,10 @@ SOURCES += main.cpp \ preferences/prefaccounts.cpp \ account.cpp \ widgets/codecwidget.cpp \ - channel.cpp + channel.cpp \ + debugtools/consolewindow.cpp \ + debugtools/sortfilterproxymodel.cpp \ + debugtools/statedebugdialog.cpp HEADERS += mainwindow.h \ fshost.h \ call.h \ @@ -45,10 +48,15 @@ HEADERS += mainwindow.h \ preferences/prefaccounts.h \ account.h \ widgets/codecwidget.h \ - channel.h + channel.h \ + debugtools/consolewindow.h \ + debugtools/sortfilterproxymodel.h \ + debugtools/statedebugdialog.h FORMS += mainwindow.ui \ preferences/prefdialog.ui \ preferences/accountdialog.ui \ - widgets/codecwidget.ui + widgets/codecwidget.ui \ + debugtools/consolewindow.ui \ + debugtools/statedebugdialog.ui RESOURCES += resources.qrc OTHER_FILES += conf/freeswitch.xml diff --git a/fscomm/debugtools/consolewindow.cpp b/fscomm/debugtools/consolewindow.cpp new file mode 100644 index 0000000000..aa3b4faa42 --- /dev/null +++ b/fscomm/debugtools/consolewindow.cpp @@ -0,0 +1,158 @@ +#include "consolewindow.h" +#include "ui_consolewindow.h" + +ConsoleWindow::ConsoleWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::ConsoleWindow), + findNext(false) +{ + ui->setupUi(this); + sourceModel = new ConsoleModel(this); + model = new SortFilterProxyModel(this); + model->setSourceModel(sourceModel); + model->setFilterKeyColumn(0); + ui->consoleListView->setModel(model); + ui->consoleListView->setColumnWidth(0, 2000); + + connect(sourceModel, SIGNAL(beforeInserting()), + this, SLOT(setConditionalScroll())); + connect(sourceModel, SIGNAL(afterInserting()), + this, SLOT(conditionalScroll())); + + connect(ui->btnSend, SIGNAL(clicked()), + this, SLOT(cmdSendClicked())); + connect(ui->lineCmd, SIGNAL(textChanged(QString)), + this, SLOT(lineCmdChanged(QString))); + + _levelFilter = new QSignalMapper(this); + connect(ui->checkEmerg, SIGNAL(clicked()), _levelFilter, SLOT(map())); + connect(ui->checkAlert, SIGNAL(clicked()), _levelFilter, SLOT(map())); + connect(ui->checkCrit, SIGNAL(clicked()), _levelFilter, SLOT(map())); + connect(ui->checkDebug, SIGNAL(clicked()), _levelFilter, SLOT(map())); + connect(ui->checkError, SIGNAL(clicked()), _levelFilter, SLOT(map())); + connect(ui->checkInfo, SIGNAL(clicked()), _levelFilter, SLOT(map())); + connect(ui->checkNotice, SIGNAL(clicked()), _levelFilter, SLOT(map())); + connect(ui->checkWarn, SIGNAL(clicked()), _levelFilter, SLOT(map())); + _levelFilter->setMapping(ui->checkEmerg, SWITCH_LOG_CONSOLE); + _levelFilter->setMapping(ui->checkAlert, SWITCH_LOG_ALERT); + _levelFilter->setMapping(ui->checkCrit, SWITCH_LOG_CRIT); + _levelFilter->setMapping(ui->checkDebug, SWITCH_LOG_DEBUG); + _levelFilter->setMapping(ui->checkError, SWITCH_LOG_ERROR); + _levelFilter->setMapping(ui->checkInfo, SWITCH_LOG_INFO); + _levelFilter->setMapping(ui->checkNotice, SWITCH_LOG_NOTICE); + _levelFilter->setMapping(ui->checkWarn, SWITCH_LOG_WARNING); + connect(_levelFilter, SIGNAL(mapped(int)), this, SLOT(filterModelLogLevel(int))); + + connect(ui->btnFilterClear, SIGNAL(clicked()), + this, SLOT(filterClear())); + connect(ui->lineFilter, SIGNAL(textChanged(QString)), + this, SLOT(filterStringChanged())); + connect(ui->filterCaseSensitivityCheckBox, SIGNAL(toggled(bool)), + this, SLOT(filterStringChanged())); + connect(ui->filterSyntaxComboBox, SIGNAL(currentIndexChanged(int)), + this, SLOT(filterStringChanged())); + connect(ui->filterReverseCheckBox, SIGNAL(toggled(bool)), + this, SLOT(reverseFilterChecked())); + + connect(&g_FSHost, SIGNAL(eventLog(QSharedPointer,switch_log_level_t)), this, SLOT(loggerHandler(QSharedPointer,switch_log_level_t))); + +} + +ConsoleWindow::~ConsoleWindow() +{ + delete ui; +} + +void ConsoleWindow::changeEvent(QEvent *e) +{ + QMainWindow::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + +void ConsoleWindow::setConditionalScroll() +{ + autoScroll = (ui->consoleListView->verticalScrollBar()->maximum() == ui->consoleListView->verticalScrollBar()->value()); +} + +void ConsoleWindow::conditionalScroll() +{ + if (autoScroll) + ui->consoleListView->scrollToBottom(); +} + +void ConsoleWindow::cmdSendClicked() +{ + if (ui->lineCmd->text().isEmpty()) return; + + QString cmd = ui->lineCmd->text().split(" ", QString::SkipEmptyParts)[0]; + if (cmd.isEmpty()) return; + + QStringList split = ui->lineCmd->text().split(" ", QString::SkipEmptyParts); + if (split.isEmpty()) return; + QString args; + for (int i=1; isetData(SWITCH_LOG_CONSOLE, ConsoleModel::LogLevelRole); + addNewConsoleItem(item); + ui->lineCmd->clear(); +} + +void ConsoleWindow::lineCmdChanged(QString text) +{ + ui->btnSend->setDisabled(text.isEmpty()); +} + +void ConsoleWindow::filterModelLogLevel(int level) +{ + model->setLogLevelFilter(level); +} + +void ConsoleWindow::loggerHandler(QSharedPointer node, switch_log_level_t level) +{ + if (level > ui->comboLogLevel->currentIndex()) return; + QString text(node.data()->data); + if (!text.isEmpty()) + { + /* Remove \r\n */ + QStringList textList = text.split(QRegExp("(\r+)"), QString::SkipEmptyParts); + QString final_str; + for (int line = 0; linesetData(level, ConsoleModel::LogLevelRole); + item->setData(node.data()->userdata, ConsoleModel::UUIDRole); + addNewConsoleItem(item); + } + } +} + +void ConsoleWindow::addNewConsoleItem(QStandardItem *item) +{ + QSettings settings; + settings.beginGroup("Console"); + QPalette palette = settings.value(QString("log-level-%1-palette").arg(item->data(Qt::UserRole).toInt())).value(); + QFont font = settings.value(QString("log-level-%1-font").arg(item->data(Qt::UserRole).toInt())).value(); + item->setBackground(palette.base()); + item->setForeground(palette.text()); + item->setFont(font); + sourceModel->appendRow(item); +} diff --git a/fscomm/debugtools/consolewindow.h b/fscomm/debugtools/consolewindow.h new file mode 100644 index 0000000000..eff6fddc63 --- /dev/null +++ b/fscomm/debugtools/consolewindow.h @@ -0,0 +1,56 @@ +#ifndef CONSOLEWINDOW_H +#define CONSOLEWINDOW_H + +#include +#include "fshost.h" +#include "sortfilterproxymodel.h" + +namespace Ui { + class ConsoleWindow; +} + +class ConsoleWindow : public QMainWindow { + Q_OBJECT +public: + ConsoleWindow(QWidget *parent = 0); + ~ConsoleWindow(); + +protected: + void changeEvent(QEvent *e); + +/*public slots: + void clearConsoleContents(); + void saveLogToFile(); + void pastebinLog(); + void filterLogUUID(QString); + void findText();*/ + +private slots: + void setConditionalScroll(); + void conditionalScroll(); + /*void filterClear(); + void filterStringChanged();*/ + void loggerHandler(QSharedPointer node, switch_log_level_t level); + void addNewConsoleItem(QStandardItem *item); + void cmdSendClicked(); + void lineCmdChanged(QString); + /*void reverseFilterChecked();*/ + void filterModelLogLevel(int); + + +private: + Ui::ConsoleWindow *ui; + ConsoleModel *sourceModel; + QModelIndexList foundItems; + SortFilterProxyModel *model; + /*pastebinDialog *_pastebinDlg; + FindDialog *_findDialog;*/ + bool findNext; + bool autoScroll; + QSignalMapper *_levelFilter; + + /*void readSettings(); + void writeSettings();*/ +}; + +#endif // CONSOLEWINDOW_H diff --git a/fscomm/debugtools/consolewindow.ui b/fscomm/debugtools/consolewindow.ui new file mode 100644 index 0000000000..805acf42b2 --- /dev/null +++ b/fscomm/debugtools/consolewindow.ui @@ -0,0 +1,466 @@ + + + ConsoleWindow + + + + 0 + 0 + 696 + 559 + + + + MainWindow + + + + + + + + 16777215 + 118 + + + + Filter + + + + + + + + false + + + + + + + false + + + QComboBox::AdjustToContentsOnFirstShow + + + + Regular Expression + + + + + Wildcard + + + + + Fixed String + + + + + UUID + + + + + + + + false + + + &Clear + + + + + + + + + + + false + + + Case sensitive filter + + + false + + + + + + + false + + + Reverse filter + + + false + + + + + + + + + + + + + + Qt::Horizontal + + + + 358 + 20 + + + + + + + + + + + + + Qt::Horizontal + + + + + QLayout::SetMaximumSize + + + + + + 120 + 16777215 + + + + Log Level Filter + + + + + + Console + + + true + + + + + + + Alert + + + true + + + + + + + Critical + + + true + + + + + + + Error + + + true + + + + + + + Warning + + + true + + + + + + + Notice + + + true + + + + + + + Info + + + true + + + + + + + Debug + + + true + + + + + + + Qt::Vertical + + + + 20 + 18 + + + + + + + + + + + Qt::Horizontal + + + + + + + + 120 + 16777215 + + + + Loglevel + + + + + + true + + + + 0 + 0 + + + + Qt::LeftToRight + + + 7 + + + + Console + + + + + Alert + + + + + Critical + + + + + Error + + + + + Warning + + + + + Notice + + + + + Info + + + + + Debug + + + + + + + + + + + + false + + + QAbstractItemView::NoEditTriggers + + + false + + + false + + + false + + + QAbstractItemView::ExtendedSelection + + + QAbstractItemView::ScrollPerPixel + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + false + + + 20 + + + false + + + false + + + false + + + + + + + + + + true + + + + 16777215 + 26 + + + + + + + + false + + + + 0 + 28 + + + + + 85 + 28 + + + + Send + + + Return + + + true + + + true + + + + + + + + + + + 0 + 0 + 696 + 24 + + + + + + + + diff --git a/fscomm/debugtools/sortfilterproxymodel.cpp b/fscomm/debugtools/sortfilterproxymodel.cpp new file mode 100644 index 0000000000..55a4992970 --- /dev/null +++ b/fscomm/debugtools/sortfilterproxymodel.cpp @@ -0,0 +1,116 @@ +#include +#include "sortfilterproxymodel.h" + +ConsoleModel::ConsoleModel (QObject *parent) + : QAbstractTableModel(parent) +{ + QSettings settings; + batchSize = settings.value("Console/batchSize", 200).toInt(); + insertionTimer = new QBasicTimer; + insertionTimer->start(0, this); +} + +int ConsoleModel::rowCount ( const QModelIndex & parent ) const +{ + if (parent.isValid()) + return 0; + return _listDisplayModel.count(); +} + +int ConsoleModel::columnCount ( const QModelIndex & /*parent*/ ) const +{ + return 1; +} + +QVariant ConsoleModel::data ( const QModelIndex & index, int role ) const +{ + if (!index.isValid()) + return QVariant(); + return _listDisplayModel.at(index.row())->data(role); +} + +void ConsoleModel::clear() +{ + _listDisplayModel.clear(); + reset(); +} + +void ConsoleModel::appendRow ( QStandardItem* item ) +{ + _listInsertModel.append(item); + insertionTimer->start(0, this); +} + +void ConsoleModel::timerEvent(QTimerEvent *e) +{ + + if (e->timerId() == insertionTimer->timerId()) + { + if (!_listInsertModel.isEmpty()) + { + int inserted_items = 0; + int toBeInserted = 0; + if (_listInsertModel.size() < batchSize) + { + toBeInserted = _listInsertModel.size() - 1; + } else { + toBeInserted = batchSize - 1; + } + emit beforeInserting(); + beginInsertRows( QModelIndex(), _listDisplayModel.size(), _listDisplayModel.size() + toBeInserted ); + while( !_listInsertModel.isEmpty() && inserted_items <= batchSize) + { + _listDisplayModel.append(_listInsertModel.takeFirst()); + inserted_items++; + } + endInsertRows(); + emit afterInserting(); + } else { + insertionTimer->stop(); + } + } +} + +SortFilterProxyModel::SortFilterProxyModel(QObject *parent) + : QSortFilterProxyModel(parent) +{ + reverseFlag = false; + for(int i = 0; i < 8; i++) + loglevels.insert(i, true); +} + +void SortFilterProxyModel::toggleReverseFlag() +{ + reverseFlag = !reverseFlag; + invalidateFilter(); +} + +void SortFilterProxyModel::setLogLevelFilter(int level) +{ + loglevels.replace(level, loglevels.value(level) == false); + // Let us filter + invalidateFilter(); +} + +void SortFilterProxyModel::setUUIDFilterLog(QString uuid) +{ + _uuid = uuid; + invalidateFilter(); +} + +bool SortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const +{ + QModelIndex index0 = sourceModel()->index(source_row, 0, source_parent); + bool uuidMatch = true; + + if (!_uuid.isEmpty()) + uuidMatch = (sourceModel()->data(index0, ConsoleModel::UUIDRole).toString() == _uuid); + + bool res = (loglevels.value(sourceModel()->data(index0, Qt::UserRole).toInt()) == true + && sourceModel()->data(index0).toString().contains(filterRegExp()) + && uuidMatch); + if (reverseFlag) + return !res; + else + return res; +} diff --git a/fscomm/debugtools/sortfilterproxymodel.h b/fscomm/debugtools/sortfilterproxymodel.h new file mode 100644 index 0000000000..c0b1c53890 --- /dev/null +++ b/fscomm/debugtools/sortfilterproxymodel.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Contributor(s): + * + * Joao Mesquita + * + */ +#ifndef SORTFILTERPROXYMODEL_H +#define SORTFILTERPROXYMODEL_H + +#include +#include +#include +#include + +class QBasicTimer; +class QStandardItem; +class QScrollBar; + +class ConsoleModel : public QAbstractTableModel +{ + Q_OBJECT +public: + ConsoleModel (QObject *parent = 0); + int rowCount ( const QModelIndex & parent = QModelIndex() ) const; + int columnCount ( const QModelIndex & parent = QModelIndex() ) const; + QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const; + void appendRow ( QStandardItem* item ); + void clear(); + QList modelData() { return _listDisplayModel; } + + enum { + LogLevelRole = Qt::UserRole, + UUIDRole + }; +signals: + void beforeInserting(); + void afterInserting(); +protected: + void timerEvent(QTimerEvent *); +private: + QList _listDisplayModel; + QList _listInsertModel; + int batchSize; + QBasicTimer *insertionTimer; +}; + +class SortFilterProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT + +public: + SortFilterProxyModel(QObject *parent = 0); + void setLogLevelFilter(int level); + void setUUIDFilterLog(QString uuid); + void toggleReverseFlag(); + +protected: + bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; + +private: + QVector loglevels; + QString _uuid; + bool reverseFlag; +}; + +#endif // SORTFILTERPROXYMODEL_H diff --git a/fscomm/debugtools/statedebugdialog.cpp b/fscomm/debugtools/statedebugdialog.cpp new file mode 100644 index 0000000000..c287b564f4 --- /dev/null +++ b/fscomm/debugtools/statedebugdialog.cpp @@ -0,0 +1,76 @@ +#include "statedebugdialog.h" +#include "ui_statedebugdialog.h" + +StateDebugDialog::StateDebugDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::StateDebugDialog) +{ + ui->setupUi(this); + connect(&g_FSHost, SIGNAL(newEvent(QSharedPointer)), this, SLOT(newEvent(QSharedPointer))); + connect(ui->listUUID, SIGNAL(itemSelectionChanged()), this, SLOT(currentUuidChanged())); + connect(ui->listEvents, SIGNAL(itemSelectionChanged()), this, SLOT(currentEventsChanged())); +} + +StateDebugDialog::~StateDebugDialog() +{ + delete ui; +} + +void StateDebugDialog::changeEvent(QEvent *e) +{ + QDialog::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + +void StateDebugDialog::newEvent(QSharedPointerevent) +{ + /* We don't want to keep track of events that are not calls at this moment */ + if (QString(switch_event_get_header_nil(event.data(), "Unique-ID")).isEmpty()) + return; + + QString uuid(switch_event_get_header_nil(event.data(), "Unique-ID")); + + if (!_events.contains(uuid)) + { + QList > tmpListEvents; + tmpListEvents.append(event); + _events.insert(uuid, tmpListEvents); + ui->listUUID->addItem(new QListWidgetItem(uuid)); + } + else + { + QList > tmpListEvents = _events.value(uuid); + tmpListEvents.append(event); + _events.insert(uuid, tmpListEvents); + } +} + +void StateDebugDialog::currentUuidChanged() +{; + ui->listEvents->clear(); + ui->listDetails->clear(); + QString uuid = ui->listUUID->currentItem()->text(); + foreach(QSharedPointer e, _events.value(uuid)) + { + ui->listEvents->addItem(new QListWidgetItem(switch_event_name(e.data()->event_id))); + } +} + +void StateDebugDialog::currentEventsChanged() +{ + ui->listDetails->clear(); + int r = ui->listEvents->currentRow(); + QString uuid = ui->listUUID->currentItem()->text(); + QList > tmpListEvents = _events.value(uuid); + QSharedPointer e = tmpListEvents.at(r); + for(switch_event_header_t* h = e.data()->headers; h != e.data()->last_header; h = h->next) + { + ui->listDetails->addItem(new QListWidgetItem(QString("%1 = %2").arg(h->name, h->value))); + } +} diff --git a/fscomm/debugtools/statedebugdialog.h b/fscomm/debugtools/statedebugdialog.h new file mode 100644 index 0000000000..0b2930452a --- /dev/null +++ b/fscomm/debugtools/statedebugdialog.h @@ -0,0 +1,30 @@ +#ifndef STATEDEBUGDIALOG_H +#define STATEDEBUGDIALOG_H + +#include +#include "fshost.h" + +namespace Ui { + class StateDebugDialog; +} + +class StateDebugDialog : public QDialog { + Q_OBJECT +public: + StateDebugDialog(QWidget *parent = 0); + ~StateDebugDialog(); + +private slots: + void newEvent(QSharedPointer event); + void currentUuidChanged(); + void currentEventsChanged(); + +protected: + void changeEvent(QEvent *e); + +private: + Ui::StateDebugDialog *ui; + QHash > > _events; +}; + +#endif // STATEDEBUGDIALOG_H diff --git a/fscomm/debugtools/statedebugdialog.ui b/fscomm/debugtools/statedebugdialog.ui new file mode 100644 index 0000000000..e9c5fb864e --- /dev/null +++ b/fscomm/debugtools/statedebugdialog.ui @@ -0,0 +1,79 @@ + + + StateDebugDialog + + + + 0 + 0 + 804 + 235 + + + + Debug Events + + + + + + Qt::Horizontal + + + + + + + UUID + + + Qt::AlignCenter + + + + + + + + + + + + + + EVENTS + + + Qt::AlignCenter + + + + + + + + + + + + + + DETAILS + + + Qt::AlignCenter + + + + + + + + + + + + + + + diff --git a/fscomm/fshost.cpp b/fscomm/fshost.cpp index 3d7984fcdc..fda22b59d6 100644 --- a/fscomm/fshost.cpp +++ b/fscomm/fshost.cpp @@ -43,7 +43,10 @@ FSHost::FSHost(QObject *parent) : switch_core_set_globals(); qRegisterMetaType >("QSharedPointer"); - qRegisterMetaType >("QSharedPointer"); + qRegisterMetaType >("QSharedPointer"); + qRegisterMetaType >("QSharedPointer"); + qRegisterMetaType("switch_log_level_t"); + qRegisterMetaType >("QSharedPointer"); qRegisterMetaType >("QSharedPointer"); connect(this, SIGNAL(loadedModule(QString,QString)), this, SLOT(minimalModuleLoaded(QString,QString))); @@ -115,6 +118,11 @@ void FSHost::createFolders() } } +void FSHost::generalLoggerHandler(QSharedPointernode, switch_log_level_t level) +{ + emit eventLog(node, level); +} + void FSHost::run(void) { switch_core_flag_t flags = SCF_USE_SQL | SCF_USE_AUTO_NAT; @@ -150,6 +158,7 @@ void FSHost::run(void) emit coreLoadingError(err); } + switch_log_bind_logger(loggerHandler, SWITCH_LOG_DEBUG, SWITCH_FALSE); emit ready(); /* Go into the runtime loop. If the argument is true, this basically sets runtime.running = 1 and loops while that is set @@ -172,6 +181,8 @@ void FSHost::generalEventHandler(QSharedPointerevent) { QString uuid = switch_event_get_header_nil(event.data(), "Unique-ID"); + emit newEvent(event); + switch(event.data()->event_id) { case SWITCH_EVENT_CHANNEL_CREATE: /*1A - 17B*/ { diff --git a/fscomm/fshost.h b/fscomm/fshost.h index 980ed092d4..888dad3f30 100644 --- a/fscomm/fshost.h +++ b/fscomm/fshost.h @@ -45,6 +45,7 @@ public: explicit FSHost(QObject *parent = 0); switch_status_t sendCmd(const char *cmd, const char *args, QString *res); void generalEventHandler(QSharedPointerevent); + void generalLoggerHandler(QSharedPointernode, switch_log_level_t level); QSharedPointer getCallByUUID(QString uuid) { return _active_calls.value(uuid); } QSharedPointer getCurrentActiveCall(); QList > getAccounts() { return _accounts.values(); } @@ -64,6 +65,11 @@ signals: void loadedModule(QString, QString); void ready(void); + + /* Logging signals */ + void eventLog(QSharedPointer, switch_log_level_t); + void newEvent(QSharedPointer); + /* Call signals */ void ringing(QSharedPointer); void answered(QSharedPointer); @@ -121,7 +127,7 @@ extern FSHost g_FSHost; /* Used to match callback from fs core. We dup the event and call the class method callback to make use of the signal/slot infrastructure. -*/ + */ static void eventHandlerCallback(switch_event_t *event) { switch_event_t *clone = NULL; @@ -131,4 +137,15 @@ static void eventHandlerCallback(switch_event_t *event) } } +/* + Used to propagate logs on the application + */ +static switch_status_t loggerHandler(const switch_log_node_t *node, switch_log_level_t level) +{ + switch_log_node_t *clone = switch_log_node_dup(node); + QSharedPointer l(clone); + g_FSHost.generalLoggerHandler(l, level); + return SWITCH_STATUS_SUCCESS; +} + #endif // FSHOST_H diff --git a/fscomm/mainwindow.cpp b/fscomm/mainwindow.cpp index 38892c6add..6a99a4bb50 100644 --- a/fscomm/mainwindow.cpp +++ b/fscomm/mainwindow.cpp @@ -36,7 +36,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), - preferences(NULL) + preferences(NULL), + _consoleWindow(NULL), + _stateDebugDialog(NULL) + { ui->setupUi(this); @@ -100,6 +103,8 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->tableCalls, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this, SLOT(callTableDoubleClick(QTableWidgetItem*))); connect(ui->action_Preferences, SIGNAL(triggered()), this, SLOT(prefTriggered())); connect(ui->action_Exit, SIGNAL(triggered()), this, SLOT(close())); + connect(ui->actionConsole, SIGNAL(triggered()), this, SLOT(debugConsoleTriggered())); + connect(ui->actionEvents, SIGNAL(triggered()), this, SLOT(debugEventsTriggered())); connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAbout())); connect(ui->actionSetDefaultAccount, SIGNAL(triggered(bool)), this, SLOT(setDefaultAccount())); connect(sysTray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(sysTrayActivated(QSystemTrayIcon::ActivationReason))); @@ -151,6 +156,28 @@ void MainWindow::setDefaultAccount() settings.endGroup(); } +void MainWindow::debugEventsTriggered() +{ + if (!_stateDebugDialog) + _stateDebugDialog = new StateDebugDialog(); + + _stateDebugDialog->raise(); + _stateDebugDialog->show(); + _stateDebugDialog->activateWindow(); +} + +void MainWindow::debugConsoleTriggered() +{ + + if (!_consoleWindow) + _consoleWindow = new ConsoleWindow(); + + _consoleWindow->raise(); + _consoleWindow->show(); + _consoleWindow->activateWindow(); + +} + void MainWindow::prefTriggered() { if (!preferences) diff --git a/fscomm/mainwindow.h b/fscomm/mainwindow.h index 7d8c38b0f2..46031b3723 100644 --- a/fscomm/mainwindow.h +++ b/fscomm/mainwindow.h @@ -40,6 +40,8 @@ #include #include #include "preferences/prefdialog.h" +#include "debugtools/consolewindow.h" +#include "debugtools/statedebugdialog.h" namespace Ui { class MainWindow; @@ -80,11 +82,15 @@ private slots: void accountStateChanged(QSharedPointer); void sysTrayActivated(QSystemTrayIcon::ActivationReason reason); void updateCallTimers(); + void debugConsoleTriggered(); + void debugEventsTriggered(); private: Ui::MainWindow *ui; QSignalMapper *dialpadMapper; PrefDialog *preferences; + ConsoleWindow *_consoleWindow; + StateDebugDialog * _stateDebugDialog; QSystemTrayIcon *sysTray; QTimer *callTimer; }; diff --git a/fscomm/mainwindow.ui b/fscomm/mainwindow.ui index b8707f6d06..9950b7d088 100644 --- a/fscomm/mainwindow.ui +++ b/fscomm/mainwindow.ui @@ -375,7 +375,21 @@ + + + &Tools + + + + &Debug + + + + + + + @@ -410,6 +424,16 @@ Set the default account for dialing out. + + + Console + + + + + Events + +