~ubuntu-branches/ubuntu/quantal/kdepim/quantal

« back to all changes in this revision

Viewing changes to kalarm/itemlistmodel.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:51 UTC
  • mto: This revision was merged to the branch mainline in revision 193.
  • Revision ID: package-import@ubuntu.com-20111215141751-bmhdpiwl23wd9w26
Tags: upstream-4.7.90
ImportĀ upstreamĀ versionĀ 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include "itemlistmodel.h"
22
22
#include "collectionmodel.h"
23
 
#include "kaevent.h"
 
23
 
 
24
#include <kalarmcal/kaevent.h>
24
25
 
25
26
#include <kselectionproxymodel.h>
26
27
 
32
33
= Filter proxy model containing all items (alarms/templates) of specified mime
33
34
= types in enabled collections.
34
35
=============================================================================*/
35
 
ItemListModel::ItemListModel(KAlarm::CalEvent::Types allowed, QObject* parent)
 
36
ItemListModel::ItemListModel(CalEvent::Types allowed, QObject* parent)
36
37
    : EntityMimeTypeFilterModel(parent),
37
38
      mAllowedTypes(allowed),
38
39
      mHaveEvents(false)
46
47
    setHeaderGroup(EntityTreeModel::ItemListHeaders);
47
48
    if (allowed)
48
49
    {
49
 
        QStringList mimeTypes = KAlarm::CalEvent::mimeTypes(allowed);
 
50
        QStringList mimeTypes = CalEvent::mimeTypes(allowed);
50
51
        foreach (const QString& mime, mimeTypes)
51
52
            addMimeTypeInclusionFilter(mime);
52
53
    }
53
54
    setHeaderGroup(EntityTreeModel::ItemListHeaders);
54
55
    setSortRole(AkonadiModel::SortRole);
55
56
    setDynamicSortFilter(true);
56
 
    connect(this, SIGNAL(rowsInserted(const QModelIndex&, int, int)), SLOT(slotRowsInserted()));
57
 
    connect(this, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), SLOT(slotRowsRemoved()));
 
57
    connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(slotRowsInserted()));
 
58
    connect(this, SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(slotRowsRemoved()));
 
59
    connect(AkonadiModel::instance(), SIGNAL(collectionStatusChanged(Akonadi::Collection,AkonadiModel::Change,QVariant,bool)),
 
60
                                      SLOT(collectionStatusChanged(Akonadi::Collection,AkonadiModel::Change,QVariant,bool)));
58
61
}
59
62
 
60
63
int ItemListModel::columnCount(const QModelIndex& /*parent*/) const
86
89
    }
87
90
}
88
91
 
 
92
/******************************************************************************
 
93
* Called when a collection parameter or status has changed.
 
94
* If the collection's enabled status has changed, re-filter the list to add or
 
95
* remove its alarms.
 
96
*/
 
97
void ItemListModel::collectionStatusChanged(const Collection& collection, AkonadiModel::Change change, const QVariant&, bool inserted)
 
98
{
 
99
    Q_UNUSED(inserted);
 
100
    if (!collection.isValid())
 
101
        return;
 
102
    if (change == AkonadiModel::Enabled)
 
103
        invalidateFilter();
 
104
}
 
105
 
 
106
bool ItemListModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
 
107
{
 
108
    if (!EntityMimeTypeFilterModel::filterAcceptsRow(sourceRow, sourceParent))
 
109
        return false;
 
110
    // Get the alarm type of the item
 
111
    QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent);
 
112
    CalEvent::Type type = static_cast<CalEvent::Type>(sourceModel()->data(sourceIndex, AkonadiModel::StatusRole).toInt());
 
113
    Collection parent = sourceIndex.data(AkonadiModel::ParentCollectionRole).value<Collection>();
 
114
    return CollectionControlModel::isEnabled(parent, type);
 
115
}
 
116
 
89
117
#if 0
90
118
QModelIndex ItemListModel::index(int row, int column, const QModelIndex& parent) const
91
119
{
152
180
 
153
181
/*=============================================================================
154
182
= Class: AlarmListModel
155
 
= Filter proxy model containing all alarms of specified mime types in enabled
156
 
= collections.
 
183
= Filter proxy model containing all alarms (not templates) of specified mime
 
184
= types in enabled collections.
157
185
Equivalent to AlarmListFilterModel
158
186
=============================================================================*/
159
187
AlarmListModel* AlarmListModel::mAllInstance = 0;
160
188
 
161
189
AlarmListModel::AlarmListModel(QObject* parent)
162
 
    : ItemListModel(KAlarm::CalEvent::ACTIVE | KAlarm::CalEvent::ARCHIVED, parent),
163
 
      mFilterTypes(KAlarm::CalEvent::ACTIVE | KAlarm::CalEvent::ARCHIVED)
 
190
    : ItemListModel(CalEvent::ACTIVE | CalEvent::ARCHIVED, parent),
 
191
      mFilterTypes(CalEvent::ACTIVE | CalEvent::ARCHIVED)
164
192
{
165
193
}
166
194
 
180
208
    return mAllInstance;
181
209
}
182
210
 
183
 
void AlarmListModel::setEventTypeFilter(KAlarm::CalEvent::Types types)
 
211
void AlarmListModel::setEventTypeFilter(CalEvent::Types types)
184
212
{
185
213
    // Ensure that the filter isn't applied to the 'all' instance, and that
186
214
    // 'types' doesn't include any disallowed alarm types
198
226
{
199
227
    if (!ItemListModel::filterAcceptsRow(sourceRow, sourceParent))
200
228
        return false;
201
 
    if (mFilterTypes == KAlarm::CalEvent::EMPTY)
 
229
    if (mFilterTypes == CalEvent::EMPTY)
202
230
        return false;
203
231
    int type = sourceModel()->data(sourceModel()->index(sourceRow, 0, sourceParent), AkonadiModel::StatusRole).toInt();
204
 
    return static_cast<KAlarm::CalEvent::Type>(type) & mFilterTypes;
 
232
    return static_cast<CalEvent::Type>(type) & mFilterTypes;
205
233
}
206
234
 
207
235
bool AlarmListModel::filterAcceptsColumn(int sourceCol, const QModelIndex&) const
229
257
TemplateListModel* TemplateListModel::mAllInstance = 0;
230
258
 
231
259
TemplateListModel::TemplateListModel(QObject* parent)
232
 
    : ItemListModel(KAlarm::CalEvent::TEMPLATE, parent),
 
260
    : ItemListModel(CalEvent::TEMPLATE, parent),
233
261
      mActionsEnabled(KAEvent::ACT_ALL),
234
262
      mActionsFilter(KAEvent::ACT_ALL)
235
263
{