24 #include <tqpushbutton.h>
25 #include <tqwhatsthis.h>
27 #include <tdelocale.h>
29 #include <tdemessagebox.h>
34 #include "alarmcalendar.h"
36 #include "templatelistview.h"
38 #include "templatedlg.moc"
40 static const char TMPL_DIALOG_NAME[] =
"TemplateDialog";
43 TemplateDlg* TemplateDlg::mInstance = 0;
46 TemplateDlg::TemplateDlg(TQWidget* parent,
const char* name)
47 : KDialogBase(KDialogBase::Plain, i18n(
"Alarm Templates"), Close, Ok, parent, name, false, true)
49 TQWidget* topWidget = plainPage();
50 TQBoxLayout* topLayout =
new TQHBoxLayout(topWidget);
51 topLayout->setSpacing(spacingHint());
53 TQBoxLayout* layout =
new TQVBoxLayout(topLayout);
54 mTemplateList =
new TemplateListView(
true, i18n(
"The list of alarm templates"), topWidget);
55 mTemplateList->setSelectionMode(TQListView::Extended);
56 mTemplateList->setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding));
57 connect(mTemplateList, TQ_SIGNAL(selectionChanged()), TQ_SLOT(slotSelectionChanged()));
58 layout->addWidget(mTemplateList);
60 layout =
new TQVBoxLayout(topLayout);
61 TQPushButton* button =
new TQPushButton(i18n(
"&New..."), topWidget);
62 connect(button, TQ_SIGNAL(clicked()), TQ_SLOT(slotNew()));
63 TQWhatsThis::add(button, i18n(
"Create a new alarm template"));
64 layout->addWidget(button);
66 mEditButton =
new TQPushButton(i18n(
"&Edit..."), topWidget);
67 connect(mEditButton, TQ_SIGNAL(clicked()), TQ_SLOT(slotEdit()));
68 TQWhatsThis::add(mEditButton, i18n(
"Edit the currently highlighted alarm template"));
69 layout->addWidget(mEditButton);
71 mCopyButton =
new TQPushButton(i18n(
"Co&py"), topWidget);
72 connect(mCopyButton, TQ_SIGNAL(clicked()), TQ_SLOT(slotCopy()));
73 TQWhatsThis::add(mCopyButton,
74 i18n(
"Create a new alarm template based on a copy of the currently highlighted template"));
75 layout->addWidget(mCopyButton);
77 mDeleteButton =
new TQPushButton(i18n(
"&Delete"), topWidget);
78 connect(mDeleteButton, TQ_SIGNAL(clicked()), TQ_SLOT(slotDelete()));
79 TQWhatsThis::add(mDeleteButton, i18n(
"Delete the currently highlighted alarm template"));
80 layout->addWidget(mDeleteButton);
82 TDEAccel* accel =
new TDEAccel(
this);
83 accel->insert(TDEStdAccel::SelectAll, mTemplateList, TQ_SLOT(slotSelectAll()));
84 accel->insert(TDEStdAccel::Deselect, mTemplateList, TQ_SLOT(slotDeselect()));
85 accel->readSettings();
87 mTemplateList->refresh();
88 slotSelectionChanged();
91 if (KAlarm::readConfigWindowSize(TMPL_DIALOG_NAME, s))
98 TemplateDlg::~TemplateDlg()
106 TemplateDlg* TemplateDlg::create(TQWidget* parent,
const char* name)
110 mInstance =
new TemplateDlg(parent, name);
118 void TemplateDlg::slotNew()
120 createTemplate(0,
this, mTemplateList);
127 void TemplateDlg::slotCopy()
129 TemplateListViewItem* item = mTemplateList->selectedItem();
133 createTemplate(&event, mTemplateList);
141 void TemplateDlg::createTemplate(
const KAEvent* event, TQWidget* parent, TemplateListView* view)
143 EditAlarmDlg editDlg(
true, i18n(
"New Alarm Template"), parent, 0, event);
144 if (editDlg.exec() == TQDialog::Accepted)
147 editDlg.getEvent(event);
150 KAlarm::addTemplate(event, view, &editDlg);
151 Undo::saveAdd(event);
159 void TemplateDlg::slotEdit()
161 TemplateListViewItem* item = mTemplateList->selectedItem();
165 EditAlarmDlg editDlg(
true, i18n(
"Edit Alarm Template"),
this, 0, &event);
166 if (editDlg.exec() == TQDialog::Accepted)
169 editDlg.getEvent(newEvent);
170 TQString
id =
event.id();
171 newEvent.setEventID(
id);
174 KAlarm::updateTemplate(newEvent, mTemplateList, &editDlg);
175 Undo::saveEdit(event, newEvent);
184 void TemplateDlg::slotDelete()
186 TQValueList<EventListViewItemBase*> items = mTemplateList->selectedItems();
187 int n = items.count();
188 if (KMessageBox::warningContinueCancel(
this, i18n(
"Do you really want to delete the selected alarm template?",
189 "Do you really want to delete the %n selected alarm templates?", n),
190 i18n(
"Delete Alarm Template",
"Delete Alarm Templates", n), KGuiItem(i18n(
"&Delete"),
"edit-delete"))
191 != KMessageBox::Continue)
196 TQValueList<KAEvent> events;
197 AlarmCalendar::templateCalendar()->startUpdate();
198 for (TQValueList<EventListViewItemBase*>::Iterator it = items.begin(); it != items.end(); ++it)
200 TemplateListViewItem* item = (TemplateListViewItem*)(*it);
201 events.append(item->event());
203 if (st != KAlarm::UPDATE_OK)
209 if (!AlarmCalendar::templateCalendar()->endUpdate())
211 status = KAlarm::SAVE_FAILED;
212 warnErr = items.count();
214 Undo::saveDeletes(events);
216 displayUpdateError(
this, status, KAlarm::ERR_TEMPLATE, warnErr);
224 void TemplateDlg::slotSelectionChanged()
226 int count = mTemplateList->selectedCount();
227 mEditButton->setEnabled(count == 1);
228 mCopyButton->setEnabled(count == 1);
229 mDeleteButton->setEnabled(count);
236 void TemplateDlg::resizeEvent(TQResizeEvent* re)
239 KAlarm::writeConfigWindowSize(TMPL_DIALOG_NAME, re->size());
240 KDialog::resizeEvent(re);
KAEvent corresponds to a KCal::Event instance.
UpdateStatus
Return codes from calendar update functions.