kalarm

templatelistview.cpp

00001 /*
00002  *  templatelistview.cpp  -  widget showing list of alarm templates
00003  *  Program:  kalarm
00004  *  Copyright (C) 2004, 2005 by David Jarvie <software@astrojar.org.uk>
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 
00023 #include <klocale.h>
00024 #include <kdebug.h>
00025 
00026 #include "alarmcalendar.h"
00027 #include "functions.h"
00028 #include "templatelistview.moc"
00029 
00030 
00031 /*=============================================================================
00032 =  Class: TemplateListView
00033 =  Displays the list of outstanding alarms.
00034 =============================================================================*/
00035 QValueList<EventListViewBase*>  TemplateListView::mInstanceList;
00036 
00037 
00038 TemplateListView::TemplateListView(bool includeCmdAlarms, const QString& whatsThisText, QWidget* parent, const char* name)
00039     : EventListViewBase(parent, name),
00040       mWhatsThisText(whatsThisText),
00041       mIconColumn(0),
00042       mNameColumn(1),
00043       mExcludeCmdAlarms(!includeCmdAlarms)
00044 {
00045     addColumn(QString::null);          // icon column
00046     addLastColumn(i18n("Name"));
00047     setSorting(mNameColumn);           // sort initially by name
00048     setColumnAlignment(mIconColumn, Qt::AlignHCenter);
00049     setColumnWidthMode(mIconColumn, QListView::Maximum);
00050 
00051     mInstanceList.append(this);
00052 }
00053 
00054 TemplateListView::~TemplateListView()
00055 {
00056     mInstanceList.remove(this);
00057 }
00058 
00059 /******************************************************************************
00060 *  Add all the templates to the list.
00061 */
00062 void TemplateListView::populate()
00063 {
00064     QValueList<KAEvent> templates = KAlarm::templateList();
00065     for (QValueList<KAEvent>::Iterator it = templates.begin();  it != templates.end();  ++it)
00066         addEntry(*it);
00067 }
00068 
00069 /******************************************************************************
00070 *  Create a new list item for addEntry().
00071 */
00072 EventListViewItemBase* TemplateListView::createItem(const KAEvent& event)
00073 {
00074     return new TemplateListViewItem(this, event);
00075 }
00076 
00077 /******************************************************************************
00078 *  Returns the QWhatsThis text for a specified column.
00079 */
00080 QString TemplateListView::whatsThisText(int column) const
00081 {
00082     if (column == mIconColumn)
00083         return i18n("Alarm type");
00084     if (column == mNameColumn)
00085         return i18n("Name of the alarm template");
00086     return mWhatsThisText;
00087 }
00088 
00089 
00090 /*=============================================================================
00091 =  Class: TemplateListViewItem
00092 =  Contains the details of one alarm for display in the TemplateListView.
00093 =============================================================================*/
00094 
00095 TemplateListViewItem::TemplateListViewItem(TemplateListView* parent, const KAEvent& event)
00096     : EventListViewItemBase(parent, event)
00097 {
00098     setLastColumnText();     // set the template name column text
00099 
00100     int index;
00101     switch (event.action())
00102     {
00103         case KAAlarm::FILE:     index = 2;  break;
00104         case KAAlarm::COMMAND:  index = 3;  break;
00105         case KAAlarm::EMAIL:    index = 4;  break;
00106         case KAAlarm::MESSAGE:
00107         default:                index = 1;  break;
00108     }
00109     mIconOrder.sprintf("%01u", index);
00110     setPixmap(templateListView()->iconColumn(), *eventIcon());
00111 }
00112 
00113 /******************************************************************************
00114 *  Return the alarm summary text.
00115 */
00116 QString TemplateListViewItem::lastColumnText() const
00117 {
00118     return event().templateName();
00119 }
00120 
00121 /******************************************************************************
00122 *  Return the column sort order for one item in the list.
00123 */
00124 QString TemplateListViewItem::key(int column, bool) const
00125 {
00126     TemplateListView* listView = templateListView();
00127     if (column == listView->iconColumn())
00128         return mIconOrder;
00129     return text(column).lower();
00130 }
00131 
KDE Home | KDE Accessibility Home | Description of Access Keys