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()
270 void AgentActionManager::setSelectionModel(QItemSelectionModel *selectionModel)
272 d->mSelectionModel = selectionModel;
273 connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
274 SLOT(updateActions()));
277 void AgentActionManager::setMimeTypeFilter(
const QStringList &mimeTypes)
279 d->mMimeTypeFilter = mimeTypes;
282 void AgentActionManager::setCapabilityFilter(
const QStringList &capabilities)
284 d->mCapabilityFilter = capabilities;
287 KAction *AgentActionManager::createAction(Type type)
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;
315 void AgentActionManager::createAllActions()
317 for (
int type = 0; type < LastType; ++type) {
318 createAction((Type)type);
322 KAction *AgentActionManager::action(Type type)
const 324 Q_ASSERT(type >= 0 && type < LastType);
325 return d->mActions[type];
328 void AgentActionManager::interceptAction(Type type,
bool intercept)
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();
350 void AgentActionManager::setContextText(Type type, TextContext context,
const QString &text)
352 d->setContextText(type, context, text);
355 void AgentActionManager::setContextText(Type type, TextContext context,
356 const KLocalizedString &text)
358 d->setContextText(type, context, text);
361 #include "moc_agentactionmanager.cpp" The agent instance itself.
Configures the selected agent instance.
QList< AgentInstance > List
Describes a list of agent instances.
Manages generic actions for agent and agent instance views.
The text of an error message.
void configure(QWidget *parent=0)
Setup the job to show agent configuration dialog once the agent instance has been successfully starte...
AgentType type() const
Returns the agent type of this instance.
The window title of a dialog.
bool isValid() const
Returns whether the agent type is valid.
Type
Describes the supported actions.
void removeInstance(const AgentInstance &instance)
Removes the given agent instance.
The window title of an error message.
The window title of a message box.
Creates an agent instance.
A representation of an agent type.
TextContext
Describes the text context that can be customized.
bool isValid() const
Returns whether the agent instance object is valid.
QStringList capabilities() const
Returns the list of supported capabilities of the agent type.
Akonadi::AgentInstance::List selectedAgentInstances() const
Returns the list of agent instances that are currently selected.
Job for creating new agent instances.
Deletes the selected agent instance.
FreeBusyManager::Singleton.
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.