kalarm

templatelistview.cpp
1 /*
2  * templatelistview.cpp - widget showing list of alarm templates
3  * Program: kalarm
4  * Copyright (C) 2004, 2005 by David Jarvie <software@astrojar.org.uk>
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 
23 #include <tdelocale.h>
24 #include <kdebug.h>
25 
26 #include "alarmcalendar.h"
27 #include "functions.h"
28 #include "templatelistview.moc"
29 
30 
31 /*=============================================================================
32 = Class: TemplateListView
33 = Displays the list of outstanding alarms.
34 =============================================================================*/
35 TQValueList<EventListViewBase*> TemplateListView::mInstanceList;
36 
37 
38 TemplateListView::TemplateListView(bool includeCmdAlarms, const TQString& whatsThisText, TQWidget* parent, const char* name)
39  : EventListViewBase(parent, name),
40  mWhatsThisText(whatsThisText),
41  mIconColumn(0),
42  mNameColumn(1),
43  mExcludeCmdAlarms(!includeCmdAlarms)
44 {
45  addColumn(TQString()); // icon column
46  addLastColumn(i18n("Name"));
47  setSorting(mNameColumn); // sort initially by name
48  setColumnAlignment(mIconColumn, TQt::AlignHCenter);
49  setColumnWidthMode(mIconColumn, TQListView::Maximum);
50 
51  mInstanceList.append(this);
52 }
53 
54 TemplateListView::~TemplateListView()
55 {
56  mInstanceList.remove(this);
57 }
58 
59 /******************************************************************************
60 * Add all the templates to the list.
61 */
62 void TemplateListView::populate()
63 {
64  TQValueList<KAEvent> templates = KAlarm::templateList();
65  for (TQValueList<KAEvent>::Iterator it = templates.begin(); it != templates.end(); ++it)
66  addEntry(*it);
67 }
68 
69 /******************************************************************************
70 * Create a new list item for addEntry().
71 */
72 EventListViewItemBase* TemplateListView::createItem(const KAEvent& event)
73 {
74  return new TemplateListViewItem(this, event);
75 }
76 
77 /******************************************************************************
78 * Returns the TQWhatsThis text for a specified column.
79 */
80 TQString TemplateListView::whatsThisText(int column) const
81 {
82  if (column == mIconColumn)
83  return i18n("Alarm type");
84  if (column == mNameColumn)
85  return i18n("Name of the alarm template");
86  return mWhatsThisText;
87 }
88 
89 
90 /*=============================================================================
91 = Class: TemplateListViewItem
92 = Contains the details of one alarm for display in the TemplateListView.
93 =============================================================================*/
94 
95 TemplateListViewItem::TemplateListViewItem(TemplateListView* parent, const KAEvent& event)
96  : EventListViewItemBase(parent, event)
97 {
98  setLastColumnText(); // set the template name column text
99 
100  int index;
101  switch (event.action())
102  {
103  case KAAlarm::FILE: index = 2; break;
104  case KAAlarm::COMMAND: index = 3; break;
105  case KAAlarm::EMAIL: index = 4; break;
106  case KAAlarm::MESSAGE:
107  default: index = 1; break;
108  }
109  mIconOrder.sprintf("%01u", index);
110  setPixmap(templateListView()->iconColumn(), *eventIcon());
111 }
112 
113 /******************************************************************************
114 * Return the alarm summary text.
115 */
116 TQString TemplateListViewItem::lastColumnText() const
117 {
118  return event().templateName();
119 }
120 
121 /******************************************************************************
122 * Return the column sort order for one item in the list.
123 */
124 TQString TemplateListViewItem::key(int column, bool) const
125 {
126  TemplateListView* listView = templateListView();
127  if (column == listView->iconColumn())
128  return mIconOrder;
129  return text(column).lower();
130 }
131 
KAEvent corresponds to a KCal::Event instance.
Definition: alarmevent.h:232
miscellaneous functions