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

kalarm

  • sources
  • kde-4.12
  • 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.moc"
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 <QList>
48 #include <QVBoxLayout>
49 #include <QHBoxLayout>
50 #include <QBoxLayout>
51 #include <QResizeEvent>
52 
53 using namespace KCal;
54 
55 static const char TMPL_DIALOG_NAME[] = "TemplateDialog";
56 
57 
58 TemplateDlg* TemplateDlg::mInstance = 0;
59 
60 
61 TemplateDlg::TemplateDlg(QWidget* parent)
62  : KDialog(parent)
63 {
64  QWidget* topWidget = new QWidget(this);
65  setMainWidget(topWidget);
66  setButtons(Close);
67  setDefaultButton(Close);
68  setModal(false);
69  setCaption(i18nc("@title:window", "Alarm Templates"));
70  showButtonSeparator(true);
71  QBoxLayout* topLayout = new QHBoxLayout(topWidget);
72  topLayout->setMargin(0);
73  topLayout->setSpacing(spacingHint());
74 
75  QBoxLayout* layout = new QVBoxLayout();
76  layout->setMargin(0);
77  topLayout->addLayout(layout);
78 #ifdef USE_AKONADI
79  mListFilterModel = new TemplateListModel(this);
80  if (!ShellProcess::authorised())
81  mListFilterModel->setAlarmActionFilter(static_cast<KAEvent::Actions>(KAEvent::ACT_ALL & ~KAEvent::ACT_COMMAND));
82 #else
83  mListFilterModel = new TemplateListFilterModel(EventListModel::templates());
84  if (!ShellProcess::authorised())
85  mListFilterModel->setTypeFilter(static_cast<KAEvent::Actions>(KAEvent::ACT_ALL & ~KAEvent::ACT_COMMAND));
86 #endif
87  mListView = new TemplateListView(topWidget);
88  mListView->setModel(mListFilterModel);
89 #ifdef USE_AKONADI
90  mListView->sortByColumn(TemplateListModel::TemplateNameColumn, Qt::AscendingOrder);
91 #else
92  mListView->sortByColumn(TemplateListFilterModel::TemplateNameColumn, Qt::AscendingOrder);
93 #endif
94  mListView->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
95  mListView->setWhatsThis(i18nc("@info:whatsthis", "The list of alarm templates"));
96  mListView->setItemDelegate(new TemplateListDelegate(mListView));
97  connect(mListView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(slotSelectionChanged()));
98  layout->addWidget(mListView);
99 
100  layout = new QVBoxLayout();
101  layout->setMargin(0);
102  topLayout->addLayout(layout);
103  QPushButton* button = new QPushButton(i18nc("@action:button", "New"), topWidget);
104  mNewAction = new NewAlarmAction(true, i18nc("@action", "New"), this);
105  button->setMenu(mNewAction->menu());
106  connect(mNewAction, SIGNAL(selected(EditAlarmDlg::Type)), SLOT(slotNew(EditAlarmDlg::Type)));
107  button->setWhatsThis(i18nc("@info:whatsthis", "Create a new alarm template"));
108  layout->addWidget(button);
109 
110  mEditButton = new QPushButton(i18nc("@action:button", "Edit..."), topWidget);
111  connect(mEditButton, SIGNAL(clicked()), SLOT(slotEdit()));
112  mEditButton->setWhatsThis(i18nc("@info:whatsthis", "Edit the currently highlighted alarm template"));
113  layout->addWidget(mEditButton);
114 
115  mCopyButton = new QPushButton(i18nc("@action:button", "Copy"), topWidget);
116  connect(mCopyButton, SIGNAL(clicked()), SLOT(slotCopy()));
117  mCopyButton->setWhatsThis(i18nc("@info:whatsthis", "Create a new alarm template based on a copy of the currently highlighted template"));
118  layout->addWidget(mCopyButton);
119 
120  mDeleteButton = new QPushButton(i18nc("@action:button", "Delete"), topWidget);
121  connect(mDeleteButton, SIGNAL(clicked()), SLOT(slotDelete()));
122  mDeleteButton->setWhatsThis(i18nc("@info:whatsthis", "Delete the currently highlighted alarm template"));
123  layout->addWidget(mDeleteButton);
124 
125  KActionCollection* actions = new KActionCollection(this);
126  KAction* act = KStandardAction::selectAll(mListView, SLOT(selectAll()), actions);
127  topLevelWidget()->addAction(act);
128  act = KStandardAction::deselect(mListView, SLOT(clearSelection()), actions);
129  topLevelWidget()->addAction(act);
130 
131  slotSelectionChanged(); // enable/disable buttons as appropriate
132 
133  QSize s;
134  if (KAlarm::readConfigWindowSize(TMPL_DIALOG_NAME, s))
135  resize(s);
136 }
137 
138 /******************************************************************************
139 * Destructor.
140 */
141 TemplateDlg::~TemplateDlg()
142 {
143  mInstance = 0;
144 }
145 
146 /******************************************************************************
147 * Create an instance, if none already exists.
148 */
149 TemplateDlg* TemplateDlg::create(QWidget* parent)
150 {
151  if (mInstance)
152  return 0;
153  mInstance = new TemplateDlg(parent);
154  return mInstance;
155 }
156 
157 /******************************************************************************
158 * Called when the New Template button is clicked to create a new template.
159 */
160 void TemplateDlg::slotNew(EditAlarmDlg::Type type)
161 {
162  KAlarm::editNewTemplate(type, mListView);
163 }
164 
165 /******************************************************************************
166 * Called when the Copy button is clicked to edit a copy of an existing alarm,
167 * to add to the list.
168 */
169 void TemplateDlg::slotCopy()
170 {
171 #ifdef USE_AKONADI
172  KAEvent event = mListView->selectedEvent();
173  if (event.isValid())
174  KAlarm::editNewTemplate(&event, mListView);
175 #else
176  KAEvent* event = mListView->selectedEvent();
177  if (event)
178  KAlarm::editNewTemplate(event, mListView);
179 #endif
180 }
181 
182 /******************************************************************************
183 * Called when the Modify button is clicked to edit the currently highlighted
184 * alarm in the list.
185 */
186 void TemplateDlg::slotEdit()
187 {
188 #ifdef USE_AKONADI
189  KAEvent event = mListView->selectedEvent();
190  if (event.isValid())
191  KAlarm::editTemplate(&event, mListView);
192 #else
193  KAEvent* event = mListView->selectedEvent();
194  if (event)
195  KAlarm::editTemplate(event, mListView);
196 #endif
197 }
198 
199 /******************************************************************************
200 * Called when the Delete button is clicked to delete the currently highlighted
201 * alarms in the list.
202 */
203 void TemplateDlg::slotDelete()
204 {
205 #ifdef USE_AKONADI
206  QVector<KAEvent> events = mListView->selectedEvents();
207 #else
208  KAEvent::List events = mListView->selectedEvents();
209 #endif
210  int n = events.count();
211  if (KAMessageBox::warningContinueCancel(this, i18ncp("@info", "Do you really want to delete the selected alarm template?",
212  "Do you really want to delete the %1 selected alarm templates?", n),
213  i18ncp("@title:window", "Delete Alarm Template", "Delete Alarm Templates", n),
214  KGuiItem(i18nc("@action:button", "&Delete"), QLatin1String("edit-delete")))
215  != KMessageBox::Continue)
216  return;
217 
218 #ifdef USE_AKONADI
219  KAEvent::List delEvents;
220 #else
221  QStringList delEvents;
222 #endif
223  Undo::EventList undos;
224  AlarmCalendar* resources = AlarmCalendar::resources();
225  for (int i = 0; i < n; ++i)
226  {
227 #ifdef USE_AKONADI
228  KAEvent* event = &events[i];
229  delEvents.append(event);
230  Akonadi::Collection c = resources->collectionForEvent(event->itemId());
231  undos.append(*event, c);
232 #else
233  const KAEvent* event = events[i];
234  delEvents.append(event->id());
235  undos.append(*event, resources->resourceForEvent(event->id()));
236 #endif
237  }
238  KAlarm::deleteTemplates(delEvents, this);
239  Undo::saveDeletes(undos);
240 }
241 
242 /******************************************************************************
243 * Called when the group of items selected changes.
244 * Enable/disable the buttons depending on whether/how many templates are
245 * currently highlighted.
246 */
247 void TemplateDlg::slotSelectionChanged()
248 {
249  AlarmCalendar* resources = AlarmCalendar::resources();
250 #ifdef USE_AKONADI
251  QVector<KAEvent> events = mListView->selectedEvents();
252 #else
253  KAEvent::List events = mListView->selectedEvents();
254 #endif
255  int count = events.count();
256  bool readOnly = false;
257  for (int i = 0; i < count; ++i)
258  {
259 #ifdef USE_AKONADI
260  const KAEvent* event = &events[i];
261  if (resources->eventReadOnly(event->itemId()))
262 #else
263  const KAEvent* event = events[i];
264  if (resources->eventReadOnly(event->id()))
265 #endif
266  {
267  readOnly = true;
268  break;
269  }
270  }
271  mEditButton->setEnabled(count == 1);
272  mCopyButton->setEnabled(count == 1);
273  mDeleteButton->setEnabled(count && !readOnly);
274 }
275 
276 /******************************************************************************
277 * Called when the dialog's size has changed.
278 * Records the new size in the config file.
279 */
280 void TemplateDlg::resizeEvent(QResizeEvent* re)
281 {
282  if (isVisible())
283  KAlarm::writeConfigWindowSize(TMPL_DIALOG_NAME, re->size());
284  KDialog::resizeEvent(re);
285 }
286 
287 // vim: et sw=4:
EventListView::selectedEvent
KAEvent * selectedEvent() const
Definition: eventlistview.cpp:134
undo.h
undo/redo facility
templatelistfiltermodel.h
AlarmCalendar::eventReadOnly
bool eventReadOnly(const QString &uniqueID) const
Definition: alarmcalendar.cpp:2093
newalarmaction.h
AlarmCalendar::resources
static AlarmCalendar * resources()
Definition: alarmcalendar.h:130
QWidget
ShellProcess::authorised
static bool authorised()
QPushButton
editdlg.h
alarmcalendar.h
KDialog
AlarmCalendar::resourceForEvent
AlarmResource * resourceForEvent(const QString &eventID) const
Definition: alarmcalendar.cpp:2120
TemplateListModel
Definition: itemlistmodel.h:133
TemplateDlg::create
static TemplateDlg * create(QWidget *parent=0)
Definition: templatedlg.cpp:149
Undo::saveDeletes
static void saveDeletes(const EventList &, const QString &name=QString())
Definition: undo.cpp:343
EventListView::selectedEvents
KAEvent::List selectedEvents() const
Definition: eventlistview.cpp:152
TMPL_DIALOG_NAME
static const char TMPL_DIALOG_NAME[]
Definition: templatedlg.cpp:55
Undo::EventList
Definition: undo.h:67
TemplateListView
Definition: templatelistview.h:29
TemplateListDelegate
Definition: templatelistview.h:37
eventlistmodel.h
TemplateListModel::TemplateNameColumn
Definition: itemlistmodel.h:138
TemplateDlg::resizeEvent
virtual void resizeEvent(QResizeEvent *)
Definition: templatedlg.cpp:280
messagebox.h
TemplateDlg
Definition: templatedlg.h:37
EventListModel::templates
static EventListModel * templates()
Definition: eventlistmodel.cpp:69
KAMessageBox::warningContinueCancel
static int warningContinueCancel(QWidget *parent, ButtonCode defaultButton, const QString &text, const QString &caption=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const QString &dontAskAgainName=QString())
EditAlarmDlg::Type
Type
Definition: editdlg.h:65
functions.h
miscellaneous functions
kalarm.h
AlarmCalendar
Provides read and write access to calendar files and resources.
Definition: alarmcalendar.h:58
NewAlarmAction
Definition: newalarmaction.h:31
shellprocess.h
TemplateListFilterModel
Definition: templatelistfiltermodel.h:29
TemplateDlg::~TemplateDlg
~TemplateDlg()
Definition: templatedlg.cpp:141
Undo::EventList::append
void append(const KAEvent &e, AlarmResource *r)
Definition: undo.h:73
templatelistview.h
TemplateListFilterModel::TemplateNameColumn
Definition: templatelistfiltermodel.h:34
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:59:10 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

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