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

kalarm

templatedlg.cpp

Go to the documentation of this file.
00001 /*
00002  *  templatedlg.cpp  -  dialog to create, edit and delete alarm templates
00003  *  Program:  kalarm
00004  *  Copyright © 2004-2008 by David Jarvie <djarvie@kde.org>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include "kalarm.h"
00022 #include "templatedlg.moc"
00023 
00024 #include "editdlg.h"
00025 #include "alarmcalendar.h"
00026 #include "alarmresources.h"
00027 #include "eventlistmodel.h"
00028 #include "functions.h"
00029 #include "newalarmaction.h"
00030 #include "templatelistfiltermodel.h"
00031 #include "templatelistview.h"
00032 #include "undo.h"
00033 
00034 #include <QPushButton>
00035 #include <QList>
00036 #include <QVBoxLayout>
00037 #include <QHBoxLayout>
00038 #include <QBoxLayout>
00039 #include <QResizeEvent>
00040 
00041 #include <klocale.h>
00042 #include <kguiitem.h>
00043 #include <kmessagebox.h>
00044 #include <kdebug.h>
00045 #include <kstandardaction.h>
00046 #include <kactioncollection.h>
00047 #include <kaction.h>
00048 #include <kmenu.h>
00049 
00050 using namespace KCal;
00051 
00052 static const char TMPL_DIALOG_NAME[] = "TemplateDialog";
00053 
00054 
00055 TemplateDlg* TemplateDlg::mInstance = 0;
00056 
00057 
00058 TemplateDlg::TemplateDlg(QWidget* parent)
00059     : KDialog(parent)
00060 {
00061     QWidget* topWidget = new QWidget(this);
00062     setMainWidget(topWidget);
00063     setButtons(Close);
00064     setDefaultButton(Ok);
00065     setModal(false);
00066     setCaption(i18nc("@title:window", "Alarm Templates"));
00067     showButtonSeparator(true);
00068     QBoxLayout* topLayout = new QHBoxLayout(topWidget);
00069     topLayout->setMargin(0);
00070     topLayout->setSpacing(spacingHint());
00071 
00072     QBoxLayout* layout = new QVBoxLayout();
00073     layout->setMargin(0);
00074     topLayout->addLayout(layout);
00075     mListFilterModel = new TemplateListFilterModel(EventListModel::templates());
00076     mListFilterModel->setTypeFilter(false);
00077     mListView = new TemplateListView(topWidget);
00078     mListView->setModel(mListFilterModel);
00079     mListView->sortByColumn(TemplateListFilterModel::TemplateNameColumn, Qt::AscendingOrder);
00080     mListView->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
00081     mListView->setWhatsThis(i18nc("@info:whatsthis", "The list of alarm templates"));
00082     mListView->setItemDelegate(new TemplateListDelegate(mListView));
00083     connect(mListView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), SLOT(slotSelectionChanged()));
00084     layout->addWidget(mListView);
00085 
00086     layout = new QVBoxLayout();
00087     layout->setMargin(0);
00088     topLayout->addLayout(layout);
00089     QPushButton* button = new QPushButton(i18nc("@action:button", "New"), topWidget);
00090     mNewAction = new NewAlarmAction(true, i18nc("@action", "New"), this);
00091     button->setMenu(mNewAction->menu());
00092     connect(mNewAction, SIGNAL(selected(EditAlarmDlg::Type)), SLOT(slotNew(EditAlarmDlg::Type)));
00093     button->setWhatsThis(i18nc("@info:whatsthis", "Create a new alarm template"));
00094     layout->addWidget(button);
00095 
00096     mEditButton = new QPushButton(i18nc("@action:button", "Edit..."), topWidget);
00097     connect(mEditButton, SIGNAL(clicked()), SLOT(slotEdit()));
00098     mEditButton->setWhatsThis(i18nc("@info:whatsthis", "Edit the currently highlighted alarm template"));
00099     layout->addWidget(mEditButton);
00100 
00101     mCopyButton = new QPushButton(i18nc("@action:button", "Copy"), topWidget);
00102     connect(mCopyButton, SIGNAL(clicked()), SLOT(slotCopy()));
00103     mCopyButton->setWhatsThis(i18nc("@info:whatsthis", "Create a new alarm template based on a copy of the currently highlighted template"));
00104     layout->addWidget(mCopyButton);
00105 
00106     mDeleteButton = new QPushButton(i18nc("@action:button", "Delete"), topWidget);
00107     connect(mDeleteButton, SIGNAL(clicked()), SLOT(slotDelete()));
00108     mDeleteButton->setWhatsThis(i18nc("@info:whatsthis", "Delete the currently highlighted alarm template"));
00109     layout->addWidget(mDeleteButton);
00110 
00111     KActionCollection* actions = new KActionCollection(this);
00112     KAction* act = KStandardAction::selectAll(mListView, SLOT(selectAll()), actions);
00113     topLevelWidget()->addAction(act);
00114     act = KStandardAction::deselect(mListView, SLOT(clearSelection()), actions);
00115     topLevelWidget()->addAction(act);
00116 
00117     slotSelectionChanged();          // enable/disable buttons as appropriate
00118 
00119     QSize s;
00120     if (KAlarm::readConfigWindowSize(TMPL_DIALOG_NAME, s))
00121         resize(s);
00122 }
00123 
00124 /******************************************************************************
00125 *  Destructor.
00126 */
00127 TemplateDlg::~TemplateDlg()
00128 {
00129     mInstance = 0;
00130 }
00131 
00132 /******************************************************************************
00133 *  Create an instance, if none already exists.
00134 */
00135 TemplateDlg* TemplateDlg::create(QWidget* parent)
00136 {
00137     if (mInstance)
00138         return 0;
00139     mInstance = new TemplateDlg(parent);
00140     return mInstance;
00141 }
00142 
00143 /******************************************************************************
00144 *  Called when the New Template button is clicked to create a new template.
00145 */
00146 void TemplateDlg::slotNew(EditAlarmDlg::Type type)
00147 {
00148     KAlarm::editNewTemplate(type, mListView);
00149 }
00150 
00151 /******************************************************************************
00152 *  Called when the Copy button is clicked to edit a copy of an existing alarm,
00153 *  to add to the list.
00154 */
00155 void TemplateDlg::slotCopy()
00156 {
00157     KAEvent* event = mListView->selectedEvent();
00158     if (event)
00159         KAlarm::editNewTemplate(event, mListView);
00160 }
00161 
00162 /******************************************************************************
00163 *  Called when the Modify button is clicked to edit the currently highlighted
00164 *  alarm in the list.
00165 */
00166 void TemplateDlg::slotEdit()
00167 {
00168     KAEvent* event = mListView->selectedEvent();
00169     if (event)
00170         KAlarm::editTemplate(event, mListView);
00171 }
00172 
00173 /******************************************************************************
00174 *  Called when the Delete button is clicked to delete the currently highlighted
00175 *  alarms in the list.
00176 */
00177 void TemplateDlg::slotDelete()
00178 {
00179     KAEvent::List events = mListView->selectedEvents();
00180     int n = events.count();
00181     if (KMessageBox::warningContinueCancel(this, i18ncp("@info", "Do you really want to delete the selected alarm template?",
00182                                                       "Do you really want to delete the %1 selected alarm templates?", n),
00183                                            i18ncp("@title:window", "Delete Alarm Template", "Delete Alarm Templates", n),
00184                                            KGuiItem(i18nc("@action:button", "&Delete"), "edit-delete"))
00185             != KMessageBox::Continue)
00186         return;
00187 
00188     QStringList eventIDs;
00189     Undo::EventList undos;
00190     AlarmCalendar* resources = AlarmCalendar::resources();
00191     for (int i = 0;  i < n;  ++i)
00192     {
00193         const KAEvent* event = events[i];
00194         eventIDs.append(event->id());
00195         undos.append(*event, resources->resourceForEvent(event->id()));
00196     }
00197     KAlarm::deleteTemplates(eventIDs, this);
00198     Undo::saveDeletes(undos);
00199 }
00200 
00201 /******************************************************************************
00202 * Called when the group of items selected changes.
00203 * Enable/disable the buttons depending on whether/how many templates are
00204 * currently highlighted.
00205 */
00206 void TemplateDlg::slotSelectionChanged()
00207 {
00208     AlarmCalendar* resources = AlarmCalendar::resources();
00209     KAEvent::List events = mListView->selectedEvents();
00210     int count = events.count();
00211     bool readOnly = false;
00212     for (int i = 0;  i < count;  ++i)
00213     {
00214         const KAEvent* event = events[i];
00215         if (resources->eventReadOnly(event->id()))
00216         {
00217             readOnly = true;
00218             break;
00219         }
00220     }
00221     mEditButton->setEnabled(count == 1);
00222     mCopyButton->setEnabled(count == 1);
00223     mDeleteButton->setEnabled(count && !readOnly);
00224 }
00225 
00226 /******************************************************************************
00227 *  Called when the dialog's size has changed.
00228 *  Records the new size in the config file.
00229 */
00230 void TemplateDlg::resizeEvent(QResizeEvent* re)
00231 {
00232     if (isVisible())
00233         KAlarm::writeConfigWindowSize(TMPL_DIALOG_NAME, re->size());
00234     KDialog::resizeEvent(re);
00235 }

kalarm

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

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal