Use qtpaths directly
[kdepim.git] / kalarm / resourceselector.cpp
blob74feae84c1db8a2d9965bb525713258b17f999e7
1 /*
2 * resourceselector.cpp - calendar resource selection widget
3 * Program: kalarm
4 * Copyright © 2006-2013 by David Jarvie <djarvie@kde.org>
5 * Based on KOrganizer's ResourceView class and KAddressBook's ResourceSelection class,
6 * Copyright (C) 2003,2004 Cornelius Schumacher <schumacher@kde.org>
7 * Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
8 * Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "resourceselector.h"
27 #include "kalarm.h"
28 #include "alarmcalendar.h"
29 #include "autoqpointer.h"
30 #include "akonadiresourcecreator.h"
31 #include "calendarmigrator.h"
32 #include "kalarmapp.h"
33 #include "messagebox.h"
34 #include "packedlayout.h"
35 #include "preferences.h"
36 #include <AkonadiCore/agentmanager.h>
37 #include <AkonadiCore/agentinstancecreatejob.h>
38 #include <AkonadiCore/agenttype.h>
39 #include <AkonadiCore/entitydisplayattribute.h>
40 #include <AkonadiWidgets/collectionpropertiesdialog.h>
42 #include <KLocalizedString>
43 #include <kactioncollection.h>
44 #include <ktoggleaction.h>
46 #include <QAction>
47 #include <QLabel>
48 #include <QPushButton>
49 #include <QTimer>
50 #include <QResizeEvent>
51 #include <QApplication>
52 #include <qinputdialog.h>
53 #include <QColorDialog>
54 #include <QComboBox>
55 #include <QMenu>
56 #include "kalarm_debug.h"
58 using namespace KCalCore;
59 using namespace Akonadi;
62 ResourceSelector::ResourceSelector(QWidget* parent)
63 : QFrame(parent),
64 mContextMenu(Q_NULLPTR),
65 mActionReload(Q_NULLPTR),
66 mActionShowDetails(Q_NULLPTR),
67 mActionSetColour(Q_NULLPTR),
68 mActionClearColour(Q_NULLPTR),
69 mActionEdit(Q_NULLPTR),
70 mActionUpdate(Q_NULLPTR),
71 mActionRemove(Q_NULLPTR),
72 mActionImport(Q_NULLPTR),
73 mActionExport(Q_NULLPTR),
74 mActionSetDefault(Q_NULLPTR)
76 QBoxLayout* topLayout = new QVBoxLayout(this);
78 QLabel* label = new QLabel(i18nc("@title:group", "Calendars"), this);
79 topLayout->addWidget(label, 0, Qt::AlignHCenter);
81 mAlarmType = new QComboBox(this);
82 mAlarmType->addItem(i18nc("@item:inlistbox", "Active Alarms"));
83 mAlarmType->addItem(i18nc("@item:inlistbox", "Archived Alarms"));
84 mAlarmType->addItem(i18nc("@item:inlistbox", "Alarm Templates"));
85 mAlarmType->setFixedHeight(mAlarmType->sizeHint().height());
86 mAlarmType->setWhatsThis(i18nc("@info:whatsthis", "Choose which type of data to show alarm calendars for"));
87 topLayout->addWidget(mAlarmType);
88 // No spacing between combo box and listview.
90 CollectionFilterCheckListModel* model = new CollectionFilterCheckListModel(this);
91 mListView = new CollectionView(model, this);
92 connect(mListView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ResourceSelector::selectionChanged);
93 mListView->setContextMenuPolicy(Qt::CustomContextMenu);
94 connect(mListView, &CollectionView::customContextMenuRequested, this, &ResourceSelector::contextMenuRequested);
95 mListView->setWhatsThis(i18nc("@info:whatsthis",
96 "List of available calendars of the selected type. The checked state shows whether a calendar "
97 "is enabled (checked) or disabled (unchecked). The default calendar is shown in bold."));
98 topLayout->addWidget(mListView, 1);
100 PackedLayout* blayout = new PackedLayout(Qt::AlignHCenter);
101 blayout->setMargin(0);
102 topLayout->addLayout(blayout);
104 mAddButton = new QPushButton(i18nc("@action:button", "Add..."), this);
105 mEditButton = new QPushButton(i18nc("@action:button", "Edit..."), this);
106 mDeleteButton = new QPushButton(i18nc("@action:button", "Remove"), this);
107 blayout->addWidget(mAddButton);
108 blayout->addWidget(mEditButton);
109 blayout->addWidget(mDeleteButton);
110 mEditButton->setWhatsThis(i18nc("@info:whatsthis", "Edit the highlighted calendar"));
111 mDeleteButton->setWhatsThis(xi18nc("@info:whatsthis", "<para>Remove the highlighted calendar from the list.</para>"
112 "<para>The calendar itself is left intact, and may subsequently be reinstated in the list if desired.</para>"));
113 mEditButton->setDisabled(true);
114 mDeleteButton->setDisabled(true);
115 connect(mAddButton, &QPushButton::clicked, this, &ResourceSelector::addResource);
116 connect(mEditButton, &QPushButton::clicked, this, &ResourceSelector::editResource);
117 connect(mDeleteButton, &QPushButton::clicked, this, &ResourceSelector::removeResource);
119 connect(AkonadiModel::instance(), &AkonadiModel::collectionAdded,
120 this, &ResourceSelector::slotCollectionAdded);
122 connect(mAlarmType, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &ResourceSelector::alarmTypeSelected);
123 QTimer::singleShot(0, this, SLOT(alarmTypeSelected()));
125 Preferences::connect(SIGNAL(archivedKeepDaysChanged(int)), this, SLOT(archiveDaysChanged(int)));
128 /******************************************************************************
129 * Called when an alarm type has been selected.
130 * Filter the resource list to show resources of the selected alarm type, and
131 * add appropriate whatsThis texts to the list and to the Add button.
133 void ResourceSelector::alarmTypeSelected()
135 QString addTip;
136 switch (mAlarmType->currentIndex())
138 case 0:
139 mCurrentAlarmType = CalEvent::ACTIVE;
140 addTip = i18nc("@info:tooltip", "Add a new active alarm calendar");
141 break;
142 case 1:
143 mCurrentAlarmType = CalEvent::ARCHIVED;
144 addTip = i18nc("@info:tooltip", "Add a new archived alarm calendar");
145 break;
146 case 2:
147 mCurrentAlarmType = CalEvent::TEMPLATE;
148 addTip = i18nc("@info:tooltip", "Add a new alarm template calendar");
149 break;
151 // WORKAROUND: Switch scroll bars off to avoid crash (see explanation
152 // in reinstateAlarmTypeScrollBars() description).
153 mListView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
154 mListView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
155 mListView->collectionModel()->setEventTypeFilter(mCurrentAlarmType);
156 mAddButton->setWhatsThis(addTip);
157 mAddButton->setToolTip(addTip);
158 // WORKAROUND: Switch scroll bars back on after allowing geometry to update ...
159 QTimer::singleShot(0, this, &ResourceSelector::reinstateAlarmTypeScrollBars);
161 selectionChanged(); // enable/disable buttons
164 /******************************************************************************
165 * WORKAROUND for crash due to presumed Qt bug.
166 * Switch scroll bars off. This is to avoid a crash which can very occasionally
167 * happen when changing from a list of calendars which requires vertical scroll
168 * bars, to a list whose text is very slightly wider but which doesn't require
169 * scroll bars at all. (The suspicion is that the width is such that it would
170 * require horizontal scroll bars if the vertical scroll bars were still
171 * present.) Presumably due to a Qt bug, this can result in a recursive call to
172 * ResourceView::viewportEvent() with a Resize event.
174 * The crash only occurs if the ResourceSelector happens to have exactly (within
175 * one pixel) the "right" width to create the crash.
177 void ResourceSelector::reinstateAlarmTypeScrollBars()
179 mListView->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
180 mListView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
183 /******************************************************************************
184 * Prompt the user for a new resource to add to the list.
186 void ResourceSelector::addResource()
188 AkonadiResourceCreator* creator = new AkonadiResourceCreator(mCurrentAlarmType, this);
189 connect(creator, &AkonadiResourceCreator::finished, this, &ResourceSelector::resourceAdded);
190 creator->createResource();
193 /******************************************************************************
194 * Called when the job started by AkonadiModel::addCollection() has completed.
196 void ResourceSelector::resourceAdded(AkonadiResourceCreator* creator, bool success)
198 if (success)
200 AgentInstance agent = creator->agentInstance();
201 if (agent.isValid())
203 // Note that we're expecting the agent's Collection to be added
204 mAddAgents += agent;
207 delete creator;
210 /******************************************************************************
211 * Called when a collection is added to the AkonadiModel.
213 void ResourceSelector::slotCollectionAdded(const Collection& collection)
215 if (collection.isValid())
217 AgentInstance agent = AgentManager::self()->instance(collection.resource());
218 if (agent.isValid())
220 int i = mAddAgents.indexOf(agent);
221 if (i >= 0)
223 // The collection belongs to an agent created by addResource()
224 CalEvent::Types types = CalEvent::types(collection.contentMimeTypes());
225 CollectionControlModel::setEnabled(collection, types, true);
226 if (!(types & mCurrentAlarmType))
228 // The user has selected alarm types for the resource
229 // which don't include the currently displayed type.
230 // Show a collection list which includes a selected type.
231 int index = -1;
232 if (types & CalEvent::ACTIVE)
233 index = 0;
234 else if (types & CalEvent::ARCHIVED)
235 index = 1;
236 else if (types & CalEvent::TEMPLATE)
237 index = 2;
238 if (index >= 0)
240 mAlarmType->setCurrentIndex(index);
241 alarmTypeSelected();
244 mAddAgents.removeAt(i);
250 /******************************************************************************
251 * Edit the currently selected resource.
253 void ResourceSelector::editResource()
255 Collection collection = currentResource();
256 if (collection.isValid())
258 AgentInstance instance = AgentManager::self()->instance(collection.resource());
259 if (instance.isValid())
260 instance.configure(this);
264 /******************************************************************************
265 * Update the backend storage format for the currently selected resource in the
266 * displayed list.
268 void ResourceSelector::updateResource()
270 Collection collection = currentResource();
271 if (!collection.isValid())
272 return;
273 AkonadiModel::instance()->refresh(collection); // update with latest data
274 CalendarMigrator::updateToCurrentFormat(collection, true, this);
277 /******************************************************************************
278 * Remove the currently selected resource from the displayed list.
280 void ResourceSelector::removeResource()
282 Collection collection = currentResource();
283 if (!collection.isValid())
284 return;
285 QString name = collection.name();
286 // Check if it's the standard or only resource for at least one type.
287 CalEvent::Types allTypes = AkonadiModel::types(collection);
288 CalEvent::Types standardTypes = CollectionControlModel::standardTypes(collection, true);
289 CalEvent::Type currentType = currentResourceType();
290 CalEvent::Type stdType = (standardTypes & CalEvent::ACTIVE) ? CalEvent::ACTIVE
291 : (standardTypes & CalEvent::ARCHIVED) ? CalEvent::ARCHIVED
292 : CalEvent::EMPTY;
293 if (stdType == CalEvent::ACTIVE)
295 KAMessageBox::sorry(this, i18nc("@info", "You cannot remove your default active alarm calendar."));
296 return;
298 if (stdType == CalEvent::ARCHIVED && Preferences::archivedKeepDays())
300 // Only allow the archived alarms standard resource to be removed if
301 // we're not saving archived alarms.
302 KAMessageBox::sorry(this, i18nc("@info", "You cannot remove your default archived alarm calendar "
303 "while expired alarms are configured to be kept."));
304 return;
306 QString text;
307 if (standardTypes)
309 // It's a standard resource for at least one alarm type
310 if (allTypes != currentType)
312 // It also contains alarm types other than the currently displayed type
313 QString stdTypes = CollectionControlModel::typeListForDisplay(standardTypes);
314 QString otherTypes;
315 CalEvent::Types nonStandardTypes(allTypes & ~standardTypes);
316 if (nonStandardTypes != currentType)
317 otherTypes = xi18nc("@info", "<para>It also contains:%1</para>", CollectionControlModel::typeListForDisplay(nonStandardTypes));
318 text = xi18nc("@info", "<para><resource>%1</resource> is the default calendar for:%2</para>%3"
319 "<para>Do you really want to remove it from all calendar lists?</para>", name, stdTypes, otherTypes);
321 else
322 text = xi18nc("@info", "Do you really want to remove your default calendar (<resource>%1</resource>) from the list?", name);
324 else if (allTypes != currentType)
325 text = xi18nc("@info", "<para><resource>%1</resource> contains:%2</para><para>Do you really want to remove it from all calendar lists?</para>",
326 name, CollectionControlModel::typeListForDisplay(allTypes));
327 else
328 text = xi18nc("@info", "Do you really want to remove the calendar <resource>%1</resource> from the list?", name);
329 if (KAMessageBox::warningContinueCancel(this, text, QString(), KStandardGuiItem::remove()) == KMessageBox::Cancel)
330 return;
332 AkonadiModel::instance()->removeCollection(collection);
335 /******************************************************************************
336 * Called when the current selection changes, to enable/disable the
337 * Delete and Edit buttons accordingly.
339 void ResourceSelector::selectionChanged()
341 bool state = mListView->selectionModel()->selectedRows().count();
342 mDeleteButton->setEnabled(state);
343 mEditButton->setEnabled(state);
346 /******************************************************************************
347 * Initialise the button and context menu actions.
349 void ResourceSelector::initActions(KActionCollection* actions)
351 mActionReload = new QAction(QIcon::fromTheme(QStringLiteral("view-refresh")), i18nc("@action Reload calendar", "Re&load"), this);
352 actions->addAction(QStringLiteral("resReload"), mActionReload);
353 connect(mActionReload, &QAction::triggered, this, &ResourceSelector::reloadResource);
354 mActionShowDetails = new QAction(QIcon::fromTheme(QStringLiteral("help-about")), i18nc("@action", "Show &Details"), this);
355 actions->addAction(QStringLiteral("resDetails"), mActionShowDetails);
356 connect(mActionShowDetails, &QAction::triggered, this, &ResourceSelector::showInfo);
357 mActionSetColour = new QAction(QIcon::fromTheme(QStringLiteral("color-picker")), i18nc("@action", "Set &Color..."), this);
358 actions->addAction(QStringLiteral("resSetColour"), mActionSetColour);
359 connect(mActionSetColour, &QAction::triggered, this, &ResourceSelector::setColour);
360 mActionClearColour = new QAction(i18nc("@action", "Clear C&olor"), this);
361 actions->addAction(QStringLiteral("resClearColour"), mActionClearColour);
362 connect(mActionClearColour, &QAction::triggered, this, &ResourceSelector::clearColour);
363 mActionEdit = new QAction(QIcon::fromTheme(QStringLiteral("document-properties")), i18nc("@action", "&Edit..."), this);
364 actions->addAction(QStringLiteral("resEdit"), mActionEdit);
365 connect(mActionEdit, &QAction::triggered, this, &ResourceSelector::editResource);
366 mActionUpdate = new QAction(i18nc("@action", "&Update Calendar Format"), this);
367 actions->addAction(QStringLiteral("resUpdate"), mActionUpdate);
368 connect(mActionUpdate, &QAction::triggered, this, &ResourceSelector::updateResource);
369 mActionRemove = new QAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18nc("@action", "&Remove"), this);
370 actions->addAction(QStringLiteral("resRemove"), mActionRemove);
371 connect(mActionRemove, &QAction::triggered, this, &ResourceSelector::removeResource);
372 mActionSetDefault = new KToggleAction(this);
373 actions->addAction(QStringLiteral("resDefault"), mActionSetDefault);
374 connect(mActionSetDefault, &KToggleAction::triggered, this, &ResourceSelector::setStandard);
375 QAction* action = new QAction(QIcon::fromTheme(QStringLiteral("document-new")), i18nc("@action", "&Add..."), this);
376 actions->addAction(QStringLiteral("resAdd"), action);
377 connect(action, &QAction::triggered, this, &ResourceSelector::addResource);
378 mActionImport = new QAction(i18nc("@action", "Im&port..."), this);
379 actions->addAction(QStringLiteral("resImport"), mActionImport);
380 connect(mActionImport, &QAction::triggered, this, &ResourceSelector::importCalendar);
381 mActionExport = new QAction(i18nc("@action", "E&xport..."), this);
382 actions->addAction(QStringLiteral("resExport"), mActionExport);
383 connect(mActionExport, &QAction::triggered, this, &ResourceSelector::exportCalendar);
386 void ResourceSelector::setContextMenu(QMenu* menu)
388 mContextMenu = menu;
391 /******************************************************************************
392 * Display the context menu for the selected calendar.
394 void ResourceSelector::contextMenuRequested(const QPoint& viewportPos)
396 if (!mContextMenu)
397 return;
398 bool active = false;
399 bool writable = false;
400 bool updatable = false;
401 Collection collection;
402 if (mListView->selectionModel()->hasSelection())
404 QModelIndex index = mListView->indexAt(viewportPos);
405 if (index.isValid())
406 collection = mListView->collectionModel()->collection(index);
407 else
408 mListView->clearSelection();
410 CalEvent::Type type = currentResourceType();
411 bool haveCalendar = collection.isValid();
412 if (haveCalendar)
414 // Note: the CollectionControlModel functions call AkonadiModel::refresh(collection)
415 active = CollectionControlModel::isEnabled(collection, type);
416 KACalendar::Compat compatibility;
417 int rw = CollectionControlModel::isWritableEnabled(collection, type, compatibility);
418 writable = (rw > 0);
419 if (!rw
420 && (compatibility & ~KACalendar::Converted)
421 && !(compatibility & ~(KACalendar::Convertible | KACalendar::Converted)))
422 updatable = true; // the calendar format is convertible to the current KAlarm format
423 if (!(AkonadiModel::instance()->types(collection) & type))
424 type = CalEvent::EMPTY;
426 mActionReload->setEnabled(active);
427 mActionShowDetails->setEnabled(haveCalendar);
428 mActionSetColour->setEnabled(haveCalendar);
429 mActionClearColour->setEnabled(haveCalendar);
430 mActionClearColour->setVisible(AkonadiModel::instance()->backgroundColor(collection).isValid());
431 mActionEdit->setEnabled(haveCalendar);
432 mActionUpdate->setEnabled(updatable);
433 mActionRemove->setEnabled(haveCalendar);
434 mActionImport->setEnabled(active && writable);
435 mActionExport->setEnabled(active);
436 QString text;
437 switch (type)
439 case CalEvent::ACTIVE: text = i18nc("@action", "Use as &Default for Active Alarms"); break;
440 case CalEvent::ARCHIVED: text = i18nc("@action", "Use as &Default for Archived Alarms"); break;
441 case CalEvent::TEMPLATE: text = i18nc("@action", "Use as &Default for Alarm Templates"); break;
442 default: break;
444 mActionSetDefault->setText(text);
445 bool standard = CollectionControlModel::isStandard(collection, type);
446 mActionSetDefault->setChecked(active && writable && standard);
447 mActionSetDefault->setEnabled(active && writable);
448 mContextMenu->popup(mListView->viewport()->mapToGlobal(viewportPos));
451 /******************************************************************************
452 * Called from the context menu to reload the selected resource.
454 void ResourceSelector::reloadResource()
456 Collection collection = currentResource();
457 if (collection.isValid())
458 AkonadiModel::instance()->reloadCollection(collection);
461 /******************************************************************************
462 * Called from the context menu to save the selected resource.
464 void ResourceSelector::saveResource()
466 // Save resource is not applicable to Akonadi
469 /******************************************************************************
470 * Called when the length of time archived alarms are to be stored changes.
471 * If expired alarms are now to be stored, set any single archived alarm
472 * resource to be the default.
474 void ResourceSelector::archiveDaysChanged(int days)
476 if (days)
478 if (!CollectionControlModel::getStandard(CalEvent::ARCHIVED).isValid())
480 Collection::List cols = CollectionControlModel::enabledCollections(CalEvent::ARCHIVED, true);
481 if (cols.count() == 1)
483 CollectionControlModel::setStandard(cols[0], CalEvent::ARCHIVED);
484 theApp()->purgeNewArchivedDefault(cols[0]);
490 /******************************************************************************
491 * Called from the context menu to set the selected resource as the default
492 * for its alarm type. The resource is automatically made active.
494 void ResourceSelector::setStandard()
496 Collection collection = currentResource();
497 if (collection.isValid())
499 CalEvent::Type alarmType = currentResourceType();
500 bool standard = mActionSetDefault->isChecked();
501 if (standard)
502 CollectionControlModel::setEnabled(collection, alarmType, true);
503 CollectionControlModel::setStandard(collection, alarmType, standard);
504 if (alarmType == CalEvent::ARCHIVED)
505 theApp()->purgeNewArchivedDefault(collection);
510 /******************************************************************************
511 * Called from the context menu to merge alarms from an external calendar into
512 * the selected resource (if any).
514 void ResourceSelector::importCalendar()
516 Collection collection = currentResource();
517 AlarmCalendar::importAlarms(this, (collection.isValid() ? &collection : Q_NULLPTR));
520 /******************************************************************************
521 * Called from the context menu to copy the selected resource's alarms to an
522 * external calendar.
524 void ResourceSelector::exportCalendar()
526 Collection calendar = currentResource();
527 if (calendar.isValid())
528 AlarmCalendar::exportAlarms(AlarmCalendar::resources()->events(calendar), this);
531 /******************************************************************************
532 * Called from the context menu to set a colour for the selected resource.
534 void ResourceSelector::setColour()
536 Collection collection = currentResource();
537 if (collection.isValid())
539 QColor colour = AkonadiModel::instance()->backgroundColor(collection);
540 if (!colour.isValid())
541 colour = QApplication::palette().color(QPalette::Base);
542 colour = QColorDialog::getColor(colour, this);
543 if (colour.isValid())
544 AkonadiModel::instance()->setBackgroundColor(collection, colour);
548 /******************************************************************************
549 * Called from the context menu to clear the display colour for the selected
550 * resource.
552 void ResourceSelector::clearColour()
554 Collection collection = currentResource();
555 if (collection.isValid())
556 AkonadiModel::instance()->setBackgroundColor(collection, QColor());
559 /******************************************************************************
560 * Called from the context menu to display information for the selected resource.
562 void ResourceSelector::showInfo()
564 Collection collection = currentResource();
565 if (collection.isValid())
567 const QString name = collection.displayName();
568 QString id = collection.resource(); // resource name
569 CalEvent::Type alarmType = currentResourceType();
570 QString calType = AgentManager::self()->instance(id).type().name();
571 QString storage = AkonadiModel::instance()->storageType(collection);
572 QString location = collection.remoteId();
573 QUrl url = QUrl::fromUserInput(location, QString(), QUrl::AssumeLocalFile);
574 if (url.isLocalFile())
575 location = url.path();
576 CalEvent::Types altypes = AkonadiModel::instance()->types(collection);
577 QStringList alarmTypes;
578 if (altypes & CalEvent::ACTIVE)
579 alarmTypes << i18nc("@info", "Active alarms");
580 if (altypes & CalEvent::ARCHIVED)
581 alarmTypes << i18nc("@info", "Archived alarms");
582 if (altypes & CalEvent::TEMPLATE)
583 alarmTypes << i18nc("@info", "Alarm templates");
584 QString alarmTypeString = alarmTypes.join(i18nc("@info List separator", ", "));
585 KACalendar::Compat compat;
586 QString perms = AkonadiModel::readOnlyTooltip(collection);
587 if (perms.isEmpty())
588 perms = i18nc("@info", "Read-write");
589 QString enabled = CollectionControlModel::isEnabled(collection, alarmType)
590 ? i18nc("@info", "Enabled")
591 : i18nc("@info", "Disabled");
592 QString std = CollectionControlModel::isStandard(collection, alarmType)
593 ? i18nc("@info Parameter in 'Default calendar: Yes/No'", "Yes")
594 : i18nc("@info Parameter in 'Default calendar: Yes/No'", "No");
595 QString text = xi18nc("@info",
596 "<title>%1</title>"
597 "<para>ID: %2<nl/>"
598 "Calendar type: %3<nl/>"
599 "Contents: %4<nl/>"
600 "%5: <filename>%6</filename><nl/>"
601 "Permissions: %7<nl/>"
602 "Status: %8<nl/>"
603 "Default calendar: %9</para>",
604 name, id, calType, alarmTypeString, storage, location, perms, enabled, std);
605 // Display the collection information. Because the user requested
606 // the information, don't raise a KNotify event.
607 KAMessageBox::information(this, text, QString(), QString(), 0);
611 /******************************************************************************
612 * Return the currently selected resource in the list.
614 Collection ResourceSelector::currentResource() const
616 return mListView->collection(mListView->selectionModel()->currentIndex());
619 /******************************************************************************
620 * Return the currently selected resource type.
622 CalEvent::Type ResourceSelector::currentResourceType() const
624 switch (mAlarmType->currentIndex())
626 case 0: return CalEvent::ACTIVE;
627 case 1: return CalEvent::ARCHIVED;
628 case 2: return CalEvent::TEMPLATE;
629 default: return CalEvent::EMPTY;
633 void ResourceSelector::resizeEvent(QResizeEvent* re)
635 Q_EMIT resized(re->oldSize(), re->size());
638 // vim: et sw=4: