20 #include "agentactionmanager.h" 22 #include "agentfilterproxymodel.h" 23 #include "agentinstancecreatejob.h" 24 #include "agentinstancemodel.h" 25 #include "agentmanager.h" 26 #include "agenttypedialog.h" 27 #include "metatypes.h" 31 #include <KActionCollection> 33 #include <KLocalizedString> 34 #include <KMessageBox> 36 #include <QItemSelectionModel> 39 #include <boost/static_assert.hpp> 51 } agentActionData[] = {
52 {
"akonadi_agentinstance_create", I18N_NOOP(
"&New Agent Instance..."),
53 "folder-new", 0, SLOT(slotCreateAgentInstance())
55 {
"akonadi_agentinstance_delete", I18N_NOOP(
"&Delete Agent Instance"),
56 "edit-delete", 0, SLOT(slotDeleteAgentInstance())
58 {
"akonadi_agentinstance_configure", I18N_NOOP(
"&Configure Agent Instance"),
59 "configure", 0, SLOT(slotConfigureAgentInstance())
62 static const int numAgentActionData =
sizeof agentActionData /
sizeof * agentActionData;
69 class AgentActionManager::Private
80 i18nc(
"@title:window",
"New Agent Instance"));
84 ki18n(
"Could not create agent instance: %1"));
88 i18n(
"Agent instance creation failed"));
92 i18nc(
"@title:window",
"Delete Agent Instance?"));
96 i18n(
"Do you really want to delete the selected agent instance?"));
102 if (mActions[type]) {
103 mActions[type]->setEnabled(enable);
111 const bool createActionEnabled =
true;
112 bool deleteActionEnabled =
true;
113 bool configureActionEnabled =
true;
115 if (instances.isEmpty()) {
116 deleteActionEnabled =
false;
117 configureActionEnabled =
false;
120 if (instances.count() == 1) {
123 configureActionEnabled =
false;
131 emit q->actionStateUpdated();
138 if (!mSelectionModel) {
142 foreach (
const QModelIndex &index, mSelectionModel->selectedRows()) {
146 instances << instance;
153 void slotCreateAgentInstance()
159 foreach (
const QString &mimeType, mMimeTypeFilter) {
160 dlg->agentFilterProxyModel()->addMimeTypeFilter(mimeType);
163 foreach (
const QString &capability, mCapabilityFilter) {
164 dlg->agentFilterProxyModel()->addCapabilityFilter(capability);
167 if (dlg->exec() == QDialog::Accepted && dlg != 0) {
168 const AgentType agentType = dlg->agentType();
172 q->connect(job, SIGNAL(result(KJob*)), SLOT(slotAgentInstanceCreationResult(KJob*)));
180 void slotDeleteAgentInstance()
183 if (!instances.isEmpty()) {
184 if (KMessageBox::questionYesNo(
190 KStandardGuiItem::del(),
191 KStandardGuiItem::cancel(),
193 KMessageBox::Dangerous) == KMessageBox::Yes) {
202 void slotConfigureAgentInstance()
205 if (instances.isEmpty()) {
209 instances.first().configure(mParentWidget);
212 void slotAgentInstanceCreationResult(KJob *job)
227 mContextTexts[type].insert(context, data);
234 mContextTexts[type].insert(context, data.toString());
240 return mContextTexts[type].value(context);
244 KActionCollection *mActionCollection;
245 QWidget *mParentWidget;
246 QItemSelectionModel *mSelectionModel;
247 QVector<KAction *> mActions;
248 QStringList mMimeTypeFilter;
249 QStringList mCapabilityFilter;
251 typedef QHash<AgentActionManager::TextContext, QString> ContextTexts;
252 QHash<AgentActionManager::Type, ContextTexts> mContextTexts;
259 , d(new Private(this))
261 d->mParentWidget = parent;
262 d->mActionCollection = actionCollection;
265 AgentActionManager::~AgentActionManager()
272 d->mSelectionModel = selectionModel;
273 connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
274 SLOT(updateActions()));
279 d->mMimeTypeFilter = mimeTypes;
284 d->mCapabilityFilter = capabilities;
289 Q_ASSERT(type >= 0 && type <
LastType);
290 Q_ASSERT(agentActionData[type].name);
291 if (d->mActions[type]) {
292 return d->mActions[type];
295 KAction *
action =
new KAction(d->mParentWidget);
296 action->setText(i18n(agentActionData[type].label));
298 if (agentActionData[type].icon) {
299 action->setIcon(KIcon(QString::fromLatin1(agentActionData[type].icon)));
302 action->setShortcut(agentActionData[type].shortcut);
304 if (agentActionData[type].slot) {
305 connect(
action, SIGNAL(triggered()), agentActionData[type].slot);
308 d->mActionCollection->addAction(QString::fromLatin1(agentActionData[type].name),
action);
309 d->mActions[type] =
action;
317 for (
int type = 0; type <
LastType; ++type) {
324 Q_ASSERT(type >= 0 && type <
LastType);
325 return d->mActions[type];
330 Q_ASSERT(type >= 0 && type <
LastType);
332 const KAction *
action = d->mActions[type];
339 disconnect(
action, SIGNAL(triggered()),
this, agentActionData[type].slot);
341 connect(
action, SIGNAL(triggered()), agentActionData[type].slot);
347 return d->selectedAgentInstances();
352 d->setContextText(type, context, text);
356 const KLocalizedString &text)
358 d->setContextText(type, context, text);
361 #include "moc_agentactionmanager.cpp" The agent instance itself.
AgentType type() const
Returns the agent type of this instance.
Configures the selected agent instance.
QList< AgentInstance > List
Describes a list of agent instances.
Manages generic actions for agent and agent instance views.
void createAllActions()
Convenience method to create all standard actions.
The text of an error message.
bool isValid() const
Returns whether the agent type is valid.
void configure(QWidget *parent=0)
Setup the job to show agent configuration dialog once the agent instance has been successfully starte...
The window title of a dialog.
Type
Describes the supported actions.
void removeInstance(const AgentInstance &instance)
Removes the given agent instance.
KAction * action(Type type) const
Returns the action of the given type, 0 if it has not been created (yet).
The window title of an error message.
The window title of a message box.
KAction * createAction(Type type)
Creates the action of the given type and adds it to the action collection specified in the constructo...
Creates an agent instance.
A representation of an agent type.
Akonadi::AgentInstance::List selectedAgentInstances() const
Returns the list of agent instances that are currently selected.
TextContext
Describes the text context that can be customized.
QStringList capabilities() const
Returns the list of supported capabilities of the agent type.
void setCapabilityFilter(const QStringList &capabilities)
Sets the capability filter that will be used when creating new agent instances.
void setMimeTypeFilter(const QStringList &mimeTypes)
Sets the mime type filter that will be used when creating new agent instances.
void interceptAction(Type type, bool intercept=true)
Sets whether the default implementation for the given action type shall be executed when the action i...
Job for creating new agent instances.
void setSelectionModel(QItemSelectionModel *model)
Sets the agent selection model based on which the actions should operate.
Deletes the selected agent instance.
FreeBusyManager::Singleton.
bool isValid() const
Returns whether the agent instance object is valid.
void setContextText(Type type, TextContext context, const QString &text)
Sets the text of the action type for the given context.
A dialog to select an available agent type.
static AgentManager * self()
Returns the global instance of the agent manager.
A representation of an agent instance.
AgentActionManager(KActionCollection *actionCollection, QWidget *parent=0)
Creates a new agent action manager.
The text of a message box.
void start()
Starts the instance creation.