• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kalarm

  • sources
  • kde-4.14
  • kdepim
  • kalarm
templatedlg.cpp
Go to the documentation of this file.
1 /*
2  * templatedlg.cpp - dialog to create, edit and delete alarm templates
3  * Program: kalarm
4  * Copyright © 2004-2011 by David Jarvie <djarvie@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "kalarm.h"
22 #include "templatedlg.h"
23 
24 #include "editdlg.h"
25 #include "alarmcalendar.h"
26 #ifndef USE_AKONADI
27 #include "alarmresources.h"
28 #include "eventlistmodel.h"
29 #include "templatelistfiltermodel.h"
30 #endif
31 #include "functions.h"
32 #include "messagebox.h"
33 #include "newalarmaction.h"
34 #include "shellprocess.h"
35 #include "templatelistview.h"
36 #include "undo.h"
37 
38 #include <klocale.h>
39 #include <kguiitem.h>
40 #include <kdebug.h>
41 #include <kstandardaction.h>
42 #include <kactioncollection.h>
43 #include <kaction.h>
44 #include <kmenu.h>
45 
46 #include <QPushButton>
47 #include <QVBoxLayout>
48 #include <QHBoxLayout>
49 #include <QBoxLayout>
50 #include <QResizeEvent>
51 
52 using namespace KCal;
53 
54 static const char TMPL_DIALOG_NAME[] = "TemplateDialog";
55 
56 
57 TemplateDlg* TemplateDlg::mInstance = 0;
58 
59 
60 TemplateDlg::TemplateDlg(QWidget* parent)
61  : KDialog(parent)
62 {
63  QWidget* topWidget = new QWidget(this);
64  setMainWidget(topWidget);
65  setButtons(Close);
66  setDefaultButton(Close);
67  setModal(false);
68  setCaption(i18nc("@title:window", "Alarm Templates"));
69  showButtonSeparator(true);
70  QBoxLayout* topLayout = new QHBoxLayout(topWidget);
71  topLayout->setMargin(0);
72  topLayout->setSpacing(spacingHint());
73 
74  QBoxLayout* layout = new QVBoxLayout();
75  layout->setMargin(0);
76  topLayout->addLayout(layout);
77 #ifdef USE_AKONADI
78  mListFilterModel = new TemplateListModel(this);
79  if (!ShellProcess::authorised())
80  mListFilterModel->setAlarmActionFilter(static_cast<KAEvent::Actions>(KAEvent::ACT_ALL & ~KAEvent::ACT_COMMAND));
81 #else
82  mListFilterModel = new TemplateListFilterModel(EventListModel::templates());
83  if (!ShellProcess::authorised())
84  mListFilterModel->setTypeFilter(static_cast<KAEvent::Actions>(KAEvent::ACT_ALL & ~KAEvent::ACT_COMMAND));
85 #endif
86  mListView = new TemplateListView(topWidget);
87  mListView->setModel(mListFilterModel);
88 #ifdef USE_AKONADI
89  mListView->sortByColumn(TemplateListModel::TemplateNameColumn, Qt::AscendingOrder);
90 #else
91  mListView->sortByColumn(TemplateListFilterModel::TemplateNameColumn, Qt::AscendingOrder);
92 #endif
93  mListView->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
94  mListView->setWhatsThis(i18nc("@info:whatsthis", "The list of alarm templates"));
95  mListView->setItemDelegate(new TemplateListDelegate(mListView));
96  connect(mListView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(slotSelectionChanged()));
97  layout->addWidget(mListView);
98 
99  layout = new QVBoxLayout();
100  layout->setMargin(0);
101  topLayout->addLayout(layout);
102  QPushButton* button = new QPushButton(i18nc("@action:button", "New"), topWidget);
103  mNewAction = new NewAlarmAction(true, i18nc("@action", "New"), this);
104  button->setMenu(mNewAction->menu());
105  connect(mNewAction, SIGNAL(selected(EditAlarmDlg::Type)), SLOT(slotNew(EditAlarmDlg::Type)));
106  button->setWhatsThis(i18nc("@info:whatsthis", "Create a new alarm template"));
107  layout->addWidget(button);
108 
109  mEditButton = new QPushButton(i18nc("@action:button", "Edit..."), topWidget);
110  connect(mEditButton, SIGNAL(clicked()), SLOT(slotEdit()));
111  mEditButton->setWhatsThis(i18nc("@info:whatsthis", "Edit the currently highlighted alarm template"));
112  layout->addWidget(mEditButton);
113 
114  mCopyButton = new QPushButton(i18nc("@action:button", "Copy"), topWidget);
115  connect(mCopyButton, SIGNAL(clicked()), SLOT(slotCopy()));
116  mCopyButton->setWhatsThis(i18nc("@info:whatsthis", "Create a new alarm template based on a copy of the currently highlighted template"));
117  layout->addWidget(mCopyButton);
118 
119  mDeleteButton = new QPushButton(i18nc("@action:button", "Delete"), topWidget);
120  connect(mDeleteButton, SIGNAL(clicked()), SLOT(slotDelete()));
121  mDeleteButton->setWhatsThis(i18nc("@info:whatsthis", "Delete the currently highlighted alarm template"));
122  layout->addWidget(mDeleteButton);
123 
124  KActionCollection* actions = new KActionCollection(this);
125  KAction* act = KStandardAction::selectAll(mListView, SLOT(selectAll()), actions);
126  topLevelWidget()->addAction(act);
127  act = KStandardAction::deselect(mListView, SLOT(clearSelection()), actions);
128  topLevelWidget()->addAction(act);
129 
130  slotSelectionChanged(); // enable/disable buttons as appropriate
131 
132  QSize s;
133  if (KAlarm::readConfigWindowSize(TMPL_DIALOG_NAME, s))
134  resize(s);
135 }
136 
137 /******************************************************************************
138 * Destructor.
139 */
140 TemplateDlg::~TemplateDlg()
141 {
142  mInstance = 0;
143 }
144 
145 /******************************************************************************
146 * Create an instance, if none already exists.
147 */
148 TemplateDlg* TemplateDlg::create(QWidget* parent)
149 {
150  if (mInstance)
151  return 0;
152  mInstance = new TemplateDlg(parent);
153  return mInstance;
154 }
155 
156 /******************************************************************************
157 * Called when the New Template button is clicked to create a new template.
158 */
159 void TemplateDlg::slotNew(EditAlarmDlg::Type type)
160 {
161  KAlarm::editNewTemplate(type, mListView);
162 }
163 
164 /******************************************************************************
165 * Called when the Copy button is clicked to edit a copy of an existing alarm,
166 * to add to the list.
167 */
168 void TemplateDlg::slotCopy()
169 {
170 #ifdef USE_AKONADI
171  KAEvent event = mListView->selectedEvent();
172  if (event.isValid())
173  KAlarm::editNewTemplate(&event, mListView);
174 #else
175  KAEvent* event = mListView->selectedEvent();
176  if (event)
177  KAlarm::editNewTemplate(event, mListView);
178 #endif
179 }
180 
181 /******************************************************************************
182 * Called when the Modify button is clicked to edit the currently highlighted
183 * alarm in the list.
184 */
185 void TemplateDlg::slotEdit()
186 {
187 #ifdef USE_AKONADI
188  KAEvent event = mListView->selectedEvent();
189  if (event.isValid())
190  KAlarm::editTemplate(&event, mListView);
191 #else
192  KAEvent* event = mListView->selectedEvent();
193  if (event)
194  KAlarm::editTemplate(event, mListView);
195 #endif
196 }
197 
198 /******************************************************************************
199 * Called when the Delete button is clicked to delete the currently highlighted
200 * alarms in the list.
201 */
202 void TemplateDlg::slotDelete()
203 {
204 #ifdef USE_AKONADI
205  QVector<KAEvent> events = mListView->selectedEvents();
206 #else
207  KAEvent::List events = mListView->selectedEvents();
208 #endif
209  int n = events.count();
210  if (KAMessageBox::warningContinueCancel(this, i18ncp("@info", "Do you really want to delete the selected alarm template?",
211  "Do you really want to delete the %1 selected alarm templates?", n),
212  i18ncp("@title:window", "Delete Alarm Template", "Delete Alarm Templates", n),
213  KGuiItem(i18nc("@action:button", "&Delete"), QLatin1String("edit-delete")))
214  != KMessageBox::Continue)
215  return;
216 
217 #ifdef USE_AKONADI
218  KAEvent::List delEvents;
219 #else
220  QStringList delEvents;
221 #endif
222  Undo::EventList undos;
223  AlarmCalendar* resources = AlarmCalendar::resources();
224  for (int i = 0; i < n; ++i)
225  {
226 #ifdef USE_AKONADI
227  KAEvent* event = &events[i];
228  delEvents.append(event);
229  Akonadi::Collection c = resources->collectionForEvent(event->itemId());
230  undos.append(*event, c);
231 #else
232  const KAEvent* event = events[i];
233  delEvents.append(event->id());
234  undos.append(*event, resources->resourceForEvent(event->id()));
235 #endif
236  }
237  KAlarm::deleteTemplates(delEvents, this);
238  Undo::saveDeletes(undos);
239 }
240 
241 /******************************************************************************
242 * Called when the group of items selected changes.
243 * Enable/disable the buttons depending on whether/how many templates are
244 * currently highlighted.
245 */
246 void TemplateDlg::slotSelectionChanged()
247 {
248  AlarmCalendar* resources = AlarmCalendar::resources();
249 #ifdef USE_AKONADI
250  QVector<KAEvent> events = mListView->selectedEvents();
251 #else
252  KAEvent::List events = mListView->selectedEvents();
253 #endif
254  int count = events.count();
255  bool readOnly = false;
256  for (int i = 0; i < count; ++i)
257  {
258 #ifdef USE_AKONADI
259  const KAEvent* event = &events[i];
260  if (resources->eventReadOnly(event->itemId()))
261 #else
262  const KAEvent* event = events[i];
263  if (resources->eventReadOnly(event->id()))
264 #endif
265  {
266  readOnly = true;
267  break;
268  }
269  }
270  mEditButton->setEnabled(count == 1);
271  mCopyButton->setEnabled(count == 1);
272  mDeleteButton->setEnabled(count && !readOnly);
273 }
274 
275 /******************************************************************************
276 * Called when the dialog's size has changed.
277 * Records the new size in the config file.
278 */
279 void TemplateDlg::resizeEvent(QResizeEvent* re)
280 {
281  if (isVisible())
282  KAlarm::writeConfigWindowSize(TMPL_DIALOG_NAME, re->size());
283  KDialog::resizeEvent(re);
284 }
285 
286 // vim: et sw=4:
QPushButton::setMenu
void setMenu(QMenu *menu)
QResizeEvent
QWidget
templatedlg.h
EventListView::selectedEvent
KAEvent * selectedEvent() const
Definition: eventlistview.cpp:133
undo.h
undo/redo facility
TemplateListFilterModel::TemplateNameColumn
Definition: templatelistfiltermodel.h:34
templatelistfiltermodel.h
AlarmCalendar::eventReadOnly
bool eventReadOnly(const QString &uniqueID) const
Definition: alarmcalendar.cpp:2090
newalarmaction.h
QSizePolicy
AlarmCalendar::resources
static AlarmCalendar * resources()
Definition: alarmcalendar.h:130
ShellProcess::authorised
static bool authorised()
QHBoxLayout
editdlg.h
alarmcalendar.h
KDialog
AlarmCalendar::resourceForEvent
AlarmResource * resourceForEvent(const QString &eventID) const
Definition: alarmcalendar.cpp:2117
TemplateListModel
Definition: itemlistmodel.h:133
TemplateDlg::create
static TemplateDlg * create(QWidget *parent=0)
Definition: templatedlg.cpp:148
Undo::saveDeletes
static void saveDeletes(const EventList &, const QString &name=QString())
Definition: undo.cpp:341
EventListView::selectedEvents
KAEvent::List selectedEvents() const
Definition: eventlistview.cpp:151
TMPL_DIALOG_NAME
static const char TMPL_DIALOG_NAME[]
Definition: templatedlg.cpp:54
Undo::EventList
Definition: undo.h:67
QWidget::setEnabled
void setEnabled(bool)
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
TemplateListView
Definition: templatelistview.h:29
QList::append
void append(const T &value)
TemplateListDelegate
Definition: templatelistview.h:37
eventlistmodel.h
QVBoxLayout
TemplateListModel::TemplateNameColumn
Definition: itemlistmodel.h:138
TemplateDlg::resizeEvent
virtual void resizeEvent(QResizeEvent *)
Definition: templatedlg.cpp:279
messagebox.h
TemplateDlg
Definition: templatedlg.h:37
QLayout::setMargin
void setMargin(int margin)
QStringList
QResizeEvent::size
const QSize & size() const
QSize
EventListModel::templates
static EventListModel * templates()
Definition: eventlistmodel.cpp:68
QItemSelection
QWidget::setWhatsThis
void setWhatsThis(const QString &)
QVector
EditAlarmDlg::Type
Type
Definition: editdlg.h:64
QLatin1String
functions.h
miscellaneous functions
kalarm.h
KAMessageBox::warningContinueCancel
static int warningContinueCancel(QWidget *parent, const QString &text, const QString &caption=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel(), const QString &dontAskAgainName=QString(), Options options=Options(Notify|WindowModal))
AlarmCalendar
Provides read and write access to calendar files and resources.
Definition: alarmcalendar.h:58
QPushButton
NewAlarmAction
Definition: newalarmaction.h:31
shellprocess.h
TemplateListFilterModel
Definition: templatelistfiltermodel.h:29
TemplateDlg::~TemplateDlg
~TemplateDlg()
Definition: templatedlg.cpp:140
Undo::EventList::append
void append(const KAEvent &e, AlarmResource *r)
Definition: undo.h:73
QBoxLayout
QBoxLayout::setSpacing
void setSpacing(int spacing)
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
templatelistview.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm

Skip menu "kalarm"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal