diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginconfiguration.cpp b/ground/openpilotgcs/src/plugins/notify/notificationitem.cpp similarity index 100% rename from ground/openpilotgcs/src/plugins/notify/notifypluginconfiguration.cpp rename to ground/openpilotgcs/src/plugins/notify/notificationitem.cpp diff --git a/ground/openpilotgcs/src/plugins/notify/notify.pro b/ground/openpilotgcs/src/plugins/notify/notify.pro index e70392a6a..b8eeb35fd 100644 --- a/ground/openpilotgcs/src/plugins/notify/notify.pro +++ b/ground/openpilotgcs/src/plugins/notify/notify.pro @@ -12,13 +12,13 @@ HEADERS += notifyplugin.h \ notifypluginoptionspage.h \ notifyitemdelegate.h \ notifytablemodel.h \ - NotificationItem.h + notificationitem.h SOURCES += notifyplugin.cpp \ notifypluginoptionspage.cpp \ - notifypluginconfiguration.cpp \ notifyitemdelegate.cpp \ - notifytablemodel.cpp + notifytablemodel.cpp \ + notificationitem.cpp OTHER_FILES += NotifyPlugin.pluginspec diff --git a/ground/openpilotgcs/src/plugins/notify/notifyplugin.h b/ground/openpilotgcs/src/plugins/notify/notifyplugin.h index afd68fecc..c1e0ce620 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifyplugin.h +++ b/ground/openpilotgcs/src/plugins/notify/notifyplugin.h @@ -71,6 +71,26 @@ public: void setEnableSound(bool value) {enableSound = value; } private: + SoundNotifyPlugin(const SoundNotifyPlugin& rhs); + SoundNotifyPlugin& operator= (const SoundNotifyPlugin& rhs); + + bool playNotification(NotificationItem* notification); + void checkNotificationRule(NotificationItem* notification, UAVObject* object); + void readConfig_0_0_0(); + +private slots: + void onTelemetryManagerAdded(QObject* obj); + void onAutopilotDisconnect(); + void connectNotifications(); + void updateNotificationList(QList list); + void resetNotification(void); + void appendNotification(UAVObject *object); + void repeatTimerHandler(void); + void expireTimerHandler(void); + void stateChanged(Phonon::State newstate, Phonon::State oldstate); + +private: + bool configured; // just for migration,delete later bool enableSound; QList< QList* > lstMediaSource; @@ -90,21 +110,6 @@ private: PhononObject phonon; NotifyPluginOptionsPage *mop; TelemetryManager* telMngr; - - bool playNotification(NotificationItem* notification); - void checkNotificationRule(NotificationItem* notification, UAVObject* object); - void readConfig_0_0_0(); - -private slots: - void onTelemetryManagerAdded(QObject* obj); - void onAutopilotDisconnect(); - void connectNotifications(); - void updateNotificationList(QList list); - void resetNotification(void); - void appendNotification(UAVObject *object); - void repeatTimerHandler(void); - void expireTimerHandler(void); - void stateChanged(Phonon::State newstate, Phonon::State oldstate); }; #endif // SOUNDNOTIFYPLUGIN_H diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp index 686c59c3b..cee9a4027 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.cpp @@ -44,24 +44,26 @@ #include "notifyitemdelegate.h" #include "notifytablemodel.h" -NotifyPluginOptionsPage::NotifyPluginOptionsPage(/*NotificationItem *config,*/ QObject *parent) : - IOptionsPage(parent), - owner((SoundNotifyPlugin*)parent), - currentCollectionPath(""), - privListNotifications(((SoundNotifyPlugin*)parent)->getListNotifications()) +NotifyPluginOptionsPage::NotifyPluginOptionsPage(/*NotificationItem *config,*/ QObject *parent) + : IOptionsPage(parent) + , objManager(*ExtensionSystem::PluginManager::instance()->getObject()) + , owner(qobject_cast(parent)) + , currentCollectionPath("") + , privListNotifications((qobject_cast(parent))->getListNotifications()) { - } +NotifyPluginOptionsPage::~NotifyPluginOptionsPage() +{ +} //creates options page widget (uses the UI file) QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) { - - options_page = new Ui::NotifyPluginOptionsPage(); - //main widget - QWidget *optionsPageWidget = new QWidget; - //main layout + options_page.reset(new Ui::NotifyPluginOptionsPage()); + //main widget + QWidget *optionsPageWidget = new QWidget; + //main layout options_page->setupUi(optionsPageWidget); delegateItems.clear(); @@ -73,17 +75,11 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) << "Repeat 30 seconds" << "Repeat 1 minute"; - options_page->chkEnableSound->setChecked(owner->getEnableSound()); options_page->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory); options_page->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory")); - - - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - objManager = pm->getObject(); - // Fills the combo boxes for the UAVObjects - QList< QList > objList = objManager->getDataObjects(); + QList< QList > objList = objManager.getDataObjects(); foreach (QList list, objList) { foreach (UAVDataObject* obj, list) { options_page->UAVObject->addItem(obj->getName()); @@ -92,13 +88,8 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) connect(options_page->SoundDirectoryPathChooser, SIGNAL(changed(const QString&)), this, SLOT(on_buttonSoundFolder_clicked(const QString&))); connect(options_page->SoundCollectionList, SIGNAL(currentIndexChanged (int)), this, SLOT(on_soundLanguage_indexChanged(int))); - connect(options_page->buttonAdd, SIGNAL(pressed()), this, SLOT(on_buttonAddNotification_clicked())); - connect(options_page->buttonDelete, SIGNAL(pressed()), this, SLOT(on_buttonDeleteNotification_clicked())); - connect(options_page->buttonModify, SIGNAL(pressed()), this, SLOT(on_buttonModifyNotification_clicked())); - connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked())); - connect(options_page->chkEnableSound, SIGNAL(toggled(bool)), this, SLOT(on_chkEnableSound_toggled(bool))); - connect(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVObject_indexChanged(QString))); + connect(this, SIGNAL(updateNotifications(QList)), owner, SLOT(updateNotificationList(QList))); connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification())); @@ -115,20 +106,52 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) updateConfigView(owner->getCurrentNotification()); + initButtons(); + initRulesTableModel(); + initRulesTableView(); + initPhononPlayer(); + + return optionsPageWidget; +} + +void NotifyPluginOptionsPage::initButtons() +{ options_page->chkEnableSound->setChecked(owner->getEnableSound()); + connect(options_page->chkEnableSound, SIGNAL(toggled(bool)), this, SLOT(on_chkEnableSound_toggled(bool))); - notifyRulesModel = new NotifyTableModel(&privListNotifications); - options_page->notifyRulesView->setModel(notifyRulesModel); + options_page->buttonModify->setEnabled(false); + options_page->buttonDelete->setEnabled(false); + options_page->buttonPlayNotification->setEnabled(false); + connect(options_page->buttonAdd, SIGNAL(pressed()), this, SLOT(on_buttonAddNotification_clicked())); + connect(options_page->buttonDelete, SIGNAL(pressed()), this, SLOT(on_buttonDeleteNotification_clicked())); + connect(options_page->buttonModify, SIGNAL(pressed()), this, SLOT(on_buttonModifyNotification_clicked())); + connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked())); +} + +void NotifyPluginOptionsPage::initPhononPlayer() +{ + notifySound = Phonon::createPlayer(Phonon::NotificationCategory); + connect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)), + this,SLOT(changeButtonText(Phonon::State,Phonon::State))); + connect(notifySound, SIGNAL(finished(void)), this, SLOT(onFinishedPlaying(void))); +} + +void NotifyPluginOptionsPage::initRulesTableModel() +{ + notifyRulesModel.reset(new NotifyTableModel(&privListNotifications)); + notifyRulesSelection = new QItemSelectionModel(notifyRulesModel.data()); + connect(notifyRulesSelection, SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )), + this, SLOT(on_tableNotification_changeSelection( const QItemSelection & , const QItemSelection & ))); + connect(this, SIGNAL(entryUpdated(int)), + notifyRulesModel.data(), SLOT(entryUpdated(int))); + connect(this, SIGNAL(entryAdded(int)), + notifyRulesModel.data(), SLOT(entryAdded(int))); +} + +void NotifyPluginOptionsPage::initRulesTableView() +{ + options_page->notifyRulesView->setModel(notifyRulesModel.data()); options_page->notifyRulesView->resizeRowsToContents(); - notifyRulesSelection = new QItemSelectionModel(notifyRulesModel); - connect(notifyRulesSelection, SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )), - this, SLOT(on_tableNotification_changeSelection( const QItemSelection & , const QItemSelection & ))); - connect(this, SIGNAL(entryUpdated(int)), - notifyRulesModel, SLOT(entryUpdated(int))); - connect(this, SIGNAL(entryAdded(int)), - notifyRulesModel, SLOT(entryAdded(int))); - - options_page->notifyRulesView->setSelectionModel(notifyRulesSelection); options_page->notifyRulesView->setItemDelegate(new NotifyItemDelegate(delegateItems,this)); @@ -136,17 +159,9 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) options_page->notifyRulesView->setColumnWidth(eREPEAT_VALUE,120); options_page->notifyRulesView->setColumnWidth(eEXPIRE_TIME,100); options_page->notifyRulesView->setColumnWidth(eENABLE_NOTIFICATION,60); - - options_page->buttonModify->setEnabled(false); - options_page->buttonDelete->setEnabled(false); - options_page->buttonPlayNotification->setEnabled(false); - - notifySound = Phonon::createPlayer(Phonon::NotificationCategory); - connect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)), - this,SLOT(changeButtonText(Phonon::State,Phonon::State))); - connect(notifySound, SIGNAL(finished(void)), this, SLOT(onFinishedPlaying(void))); - - return optionsPageWidget; + options_page->notifyRulesView->setDragEnabled(true); + options_page->notifyRulesView->setAcceptDrops(true); + options_page->notifyRulesView->setDropIndicatorShown(true); } void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notification) @@ -183,8 +198,6 @@ void NotifyPluginOptionsPage::finish() notifySound->stop(); notifySound->clear(); } - if (options_page) - delete options_page; } ////////////////////////////////////////////////////////////////////////////// @@ -306,7 +319,7 @@ void NotifyPluginOptionsPage::updateConfigView(NotificationItem* notification) // Now load the object field values: options_page->UAVObjectField->clear(); QString uavDataObject = notification->getDataObject(); - UAVDataObject* obj = dynamic_cast( objManager->getObject(uavDataObject/*objList.at(0).at(0)->getName()*/) ); + UAVDataObject* obj = dynamic_cast(objManager.getObject(uavDataObject)); if (obj != NULL ) { QList fieldList = obj->getFields(); foreach (UAVObjectField* field, fieldList) { diff --git a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h index 31da8373f..521cf9874 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h +++ b/ground/openpilotgcs/src/plugins/notify/notifypluginoptionspage.h @@ -42,16 +42,13 @@ #include #include #include +#include "ui_notifypluginoptionspage.h" +//#include "notifytablemodel.h" class NotifyTableModel; - class NotificationItem; class SoundNotifyPlugin; -namespace Ui { - class NotifyPluginOptionsPage; -} - using namespace Core; @@ -60,7 +57,7 @@ class NotifyPluginOptionsPage : public IOptionsPage Q_OBJECT public: explicit NotifyPluginOptionsPage(/*NotificationItem *config, */QObject *parent = 0); - + ~NotifyPluginOptionsPage(); QString id() const { return QLatin1String("settings"); } QString trName() const { return tr("settings"); } QString category() const { return QLatin1String("Notify Plugin");} @@ -77,7 +74,14 @@ public: void getOptionsPageValues(NotificationItem* notification); private: - UAVObjectManager *objManager; + //Q_DISABLE_COPY(NotifyPluginOptionsPage) + void initButtons(); + void initPhononPlayer(); + void initRulesTableModel(); + void initRulesTableView(); + +private: + UAVObjectManager& objManager; SoundNotifyPlugin* owner; QStringList listDirCollections; QStringList listSoundFiles; @@ -88,11 +92,11 @@ private: Phonon::MediaObject *notifySound; Phonon::AudioOutput *audioOutput; QStringList delegateItems; - NotifyTableModel* notifyRulesModel; + QScopedPointer notifyRulesModel; QItemSelectionModel *notifyRulesSelection; QList privListNotifications; - Ui::NotifyPluginOptionsPage *options_page; + QScopedPointer options_page; signals: void updateNotifications(QList list); diff --git a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp index 6e503cbd8..f3c89b5b7 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp +++ b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.cpp @@ -109,26 +109,26 @@ QVariant NotifyTableModel::headerData(int section, Qt::Orientation orientation, return QVariant(); } -bool NotifyTableModel::insertRows(int position, int rows, const QModelIndex &index) +bool NotifyTableModel::insertRows(int position, int rows, const QModelIndex& index) { - Q_UNUSED(index); - beginInsertRows(QModelIndex(), position, position+rows-1); - endInsertRows(); - return true; + Q_UNUSED(index); + beginInsertRows(QModelIndex(), position, position+rows-1); + endInsertRows(); + return true; } - bool NotifyTableModel::removeRows(int position, int rows, const QModelIndex &index) - { - Q_UNUSED(index); - beginRemoveRows(QModelIndex(), position, position+rows-1); +bool NotifyTableModel::removeRows(int position, int rows, const QModelIndex& index) +{ + Q_UNUSED(index); + beginRemoveRows(QModelIndex(), position, position+rows-1); - for (int row=0; row < rows; ++row) { - _list->removeAt(position); - } + for (int row=0; row < rows; ++row) { + _list->removeAt(position); + } - endRemoveRows(); - return true; - } + endRemoveRows(); + return true; +} void NotifyTableModel::entryUpdated(int offset) { diff --git a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h index 978605fbe..affae25da 100644 --- a/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h +++ b/ground/openpilotgcs/src/plugins/notify/notifytablemodel.h @@ -58,11 +58,16 @@ public: Qt::ItemFlags flags(const QModelIndex &index) const { if (!index.isValid()) - return Qt::ItemIsEnabled; + return Qt::ItemIsEnabled | Qt::ItemIsDropEnabled; - return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; + return QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; } + Qt::DropActions supportedDropActions() const + { + return Qt::MoveAction; + } + bool setData(const QModelIndex &index, const QVariant &value, int role); QVariant data(const QModelIndex &index, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const;