summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVyacheslav Matyushin <[email protected]>2015-08-08 23:04:24 +0300
committerVyacheslav Matyushin <[email protected]>2015-08-08 23:04:24 +0300
commit477cdc7a8e348ac7f10b6ea3b6c624ca5ae6abe9 (patch)
treeae25c67895ced71810f6e5df9aeb1604b322bade
parent8134ad92601dba6c76f88d395a7a2cf4c1a36e5d (diff)
Journald submenu actions are now connected to main window menu click
handler.
-rw-r--r--src/lib/logMode.cpp2
-rw-r--r--src/lib/logMode.h6
-rw-r--r--src/lib/multipleActions.cpp9
-rw-r--r--src/lib/multipleActions.h2
-rw-r--r--src/mainWindow.cpp26
-rw-r--r--src/modes/journald/journaldFactory.cpp23
6 files changed, 43 insertions, 25 deletions
diff --git a/src/lib/logMode.cpp b/src/lib/logMode.cpp
index 5868715..ec8e873 100644
--- a/src/lib/logMode.cpp
+++ b/src/lib/logMode.cpp
@@ -93,7 +93,7 @@ QAction *LogMode::createDefaultAction()
{
QAction *action = new QAction(d->icon, d->name, this);
ActionData data;
- data.first = d->id;
+ data.id = d->id;
action->setData(QVariant::fromValue(data));
return action;
diff --git a/src/lib/logMode.h b/src/lib/logMode.h
index 59543eb..99b12f5 100644
--- a/src/lib/logMode.h
+++ b/src/lib/logMode.h
@@ -36,7 +36,11 @@ class LogModeConfigurationWidget;
class QAction;
-typedef QPair<QString, QVariant> ActionData;
+struct ActionData {
+ QString id;
+ bool addToActionCollection = true;
+ QVariant analyzerOptions;
+};
Q_DECLARE_METATYPE(ActionData)
// TODO Do not let this class visible to other classes (except sub-classes)
diff --git a/src/lib/multipleActions.cpp b/src/lib/multipleActions.cpp
index fadf35a..2b1ff2b 100644
--- a/src/lib/multipleActions.cpp
+++ b/src/lib/multipleActions.cpp
@@ -45,8 +45,11 @@ QAction *MultipleActions::actionMenu()
return action;
}
-void MultipleActions::addInnerAction(QAction *innerAction)
+void MultipleActions::addInnerAction(QAction *innerAction, bool addToMenu, bool addToInnerActionsList)
{
- action->addAction(innerAction);
- actions.append(innerAction);
+ if (addToMenu)
+ action->addAction(innerAction);
+
+ if (addToInnerActionsList)
+ actions.append(innerAction);
}
diff --git a/src/lib/multipleActions.h b/src/lib/multipleActions.h
index f2a591f..863fa50 100644
--- a/src/lib/multipleActions.h
+++ b/src/lib/multipleActions.h
@@ -56,7 +56,7 @@ public:
* This method is not called addAction() to avoid name collision with
* parent class
*/
- void addInnerAction(QAction *action);
+ void addInnerAction(QAction *action, bool addToMenu = true, bool addToInnerActionsList = true);
private:
QList<QAction *> actions;
diff --git a/src/mainWindow.cpp b/src/mainWindow.cpp
index 22add6f..ab54976 100644
--- a/src/mainWindow.cpp
+++ b/src/mainWindow.cpp
@@ -798,12 +798,13 @@ void MainWindow::setupActions()
void MainWindow::selectLogModeAction(bool)
{
- // qDebug() << "action selected" << action->data().toString();
+ // ActionData actionData
+ // = actionCollection()->action(QObject::sender()->objectName())->data().value<ActionData>();
+ QAction *action = qobject_cast<QAction *>(sender());
+ ActionData actionData = action->data().value<ActionData>();
+ QString selectedModeId = actionData.id;
- ActionData actionData = actionCollection()->action(QObject::sender()->objectName())->data().value<ActionData>();
- QString selectedModeId = actionData.first;
-
- logDebug() << "selectLogModeAction() called by" << selectedModeId;
+ logDebug() << "Selected action" << selectedModeId;
LogMode *currentMode = NULL;
foreach (LogMode *logMode, Globals::instance().logModes()) {
@@ -820,13 +821,12 @@ void MainWindow::selectLogModeAction(bool)
logDebug() << "Selecting " << currentMode->name() << " (" << currentMode->id() << ")";
- d->tabs->load(currentMode, d->tabs->activeLogManager(), actionData.second);
+ d->tabs->load(currentMode, d->tabs->activeLogManager(), actionData.analyzerOptions);
}
void MainWindow::setupLogModeMenu()
{
- // Sets up the Logs menu
-
+ // Sets up the Logs menu.
QList<QAction *> menuLogModeActions;
int serviceItems = 0;
int othersItems = 0;
@@ -861,13 +861,13 @@ void MainWindow::setupLogModeMenu()
void MainWindow::setupLogActions()
{
- // Sets up the log actions
-
+ // Sets up log mode actions.
foreach (LogModeAction *logModeAction, Globals::instance().logModeActions()) {
foreach (QAction *action, logModeAction->innerActions()) {
- logDebug() << "adding action" << action->data().toString();
-
- action = actionCollection()->addAction(action->data().toString(), action);
+ ActionData actionData = action->data().value<ActionData>();
+ logDebug() << "Adding action" << actionData.id;
+ if (actionData.addToActionCollection)
+ action = actionCollection()->addAction(actionData.id, action);
connect(action, SIGNAL(triggered(bool)), this, SLOT(selectLogModeAction(bool)));
}
}
diff --git a/src/modes/journald/journaldFactory.cpp b/src/modes/journald/journaldFactory.cpp
index 356bffe..a7a5997 100644
--- a/src/modes/journald/journaldFactory.cpp
+++ b/src/modes/journald/journaldFactory.cpp
@@ -43,13 +43,16 @@ LogModeAction *JournaldModeFactory::createLogModeAction() const
MultipleActions *multipleActions = new MultipleActions(
QIcon::fromTheme(QLatin1String(JOURNALD_LOG_MODE_ID)), i18n("Journald"), logMode);
+ // Do not add journald submenu actions into action collection.
+ // There are too many of them and submenu contents sometimes gets changed.
ActionData actionData;
- actionData.first = logMode->id();
+ actionData.id = logMode->id();
+ actionData.addToActionCollection = false;
JournaldAnalyzerOptions options;
options.analyzerType = JournaldAnalyzerType::Local;
- actionData.second = QVariant::fromValue(options);
+ actionData.analyzerOptions = QVariant::fromValue(options);
KActionMenu *actionMenu = new KActionMenu(i18n("Local journal"), multipleActions);
@@ -57,6 +60,7 @@ LogModeAction *JournaldModeFactory::createLogModeAction() const
QAction *action = new QAction(i18n("All messages"), actionMenu);
action->setData(QVariant::fromValue(actionData));
actionMenu->addAction(action);
+ multipleActions->addInnerAction(action, false, true);
// Add separator.
action = new QAction(actionMenu);
@@ -70,10 +74,11 @@ LogModeAction *JournaldModeFactory::createLogModeAction() const
action = new QAction(unit, filterActionMenu);
options.filter = QString("_SYSTEMD_UNIT=%1").arg(unit);
- actionData.second = QVariant::fromValue(options);
+ actionData.analyzerOptions = QVariant::fromValue(options);
action->setData(QVariant::fromValue(actionData));
filterActionMenu->addAction(action);
+ multipleActions->addInnerAction(action, false, true);
}
actionMenu->addAction(filterActionMenu);
@@ -84,14 +89,15 @@ LogModeAction *JournaldModeFactory::createLogModeAction() const
action = new QAction(id, filterActionMenu);
options.filter = QString("SYSLOG_IDENTIFIER=%1").arg(id);
- actionData.second = QVariant::fromValue(options);
+ actionData.analyzerOptions = QVariant::fromValue(options);
action->setData(QVariant::fromValue(actionData));
filterActionMenu->addAction(action);
+ multipleActions->addInnerAction(action, false, true);
}
actionMenu->addAction(filterActionMenu);
- multipleActions->addInnerAction(actionMenu);
+ multipleActions->addInnerAction(actionMenu, true, false);
options.analyzerType = JournaldAnalyzerType::Network;
@@ -106,9 +112,14 @@ LogModeAction *JournaldModeFactory::createLogModeAction() const
options.port = addressInfo.port;
action->setData(QVariant::fromValue(actionData));
actionMenu->addAction(action);
+ multipleActions->addInnerAction(action, false, true);
- multipleActions->addInnerAction(actionMenu);
+ multipleActions->addInnerAction(actionMenu, true, false);
}
+ // Add default log action with icon.
+ // Don't put in into the menu, but allow it to be added into action collection and placed on the toolbar.
+ multipleActions->addInnerAction(logMode->action(), false, true);
+
return multipleActions;
}