~renatofilho/ubuntu-calendar-app/optimize

631 by Renato Araujo Oliveira Filho
Make year view delegates async.
1
/*
2
 * Copyright (C) 2013-2014 Canonical Ltd
3
 *
4
 * This file is part of Ubuntu Calendar App
5
 *
6
 * Ubuntu Calendar App is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License version 3 as
8
 * published by the Free Software Foundation.
9
 *
10
 * Ubuntu Calendar App is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
import QtQuick 2.4
19
import Ubuntu.Components 1.3
20
import QtOrganizer 5.0
21
import "dateExt.js" as DateExt
22
import "colorUtils.js" as Color
23
24
MonthComponent {
25
    id: root
26
    objectName: "MonthComponent"
27
682 by Renato Araujo Oliveira Filho
Update month view to run query only after scrolls stops.
28
    property bool isActive: false
29
    property var modelFilter: invalidFilter
30
31
    onIsActiveChanged: {
32
        if (isActive && (mainModel.filter === invalidFilter)) {
33
            idleRefresh.reset()
34
        }
35
    }
631 by Renato Araujo Oliveira Filho
Make year view delegates async.
36
37
    Timer {
682 by Renato Araujo Oliveira Filho
Update month view to run query only after scrolls stops.
38
        id: idleRefresh
39
40
        function reset()
41
        {
42
            mainModel.filter = invalidFilter
43
            restart()
44
        }
45
46
        interval: root.isCurrentItem ? 1000 : 2000
631 by Renato Araujo Oliveira Filho
Make year view delegates async.
47
        repeat: false
682 by Renato Araujo Oliveira Filho
Update month view to run query only after scrolls stops.
48
        onTriggered: {
49
            mainModel.filter = Qt.binding(function() { return root.modelFilter } )
50
        }
631 by Renato Araujo Oliveira Filho
Make year view delegates async.
51
    }
52
53
    InvalidFilter {
54
        id: invalidFilter
55
    }
56
57
    EventListModel {
58
        id: mainModel
59
60
        startPeriod: root.monthStartDate.midnight();
61
        endPeriod: root.monthStartDate.addDays((/*monthGrid.rows * cols */ 42 )-1).endOfDay()
682 by Renato Araujo Oliveira Filho
Update month view to run query only after scrolls stops.
62
        filter: invalidFilter
631 by Renato Araujo Oliveira Filho
Make year view delegates async.
63
        fetchHint: FetchHint {
64
            detailTypesHint: [ Detail.EventTime,
65
                               Detail.JournalTime,
66
                               Detail.TodoTime
67
                             ]
68
        }
69
70
        onModelChanged: {
71
            var eventStatus = mainModel.containsItems(startPeriod,
72
                                                      endPeriod,
73
                                                      86400/*24*60*60*/);
74
            root.updateEvents(eventStatus)
75
        }
682 by Renato Araujo Oliveira Filho
Update month view to run query only after scrolls stops.
76
77
        onStartPeriodChanged: idleRefresh.reset()
78
        onEndPeriodChanged: idleRefresh.reset()
631 by Renato Araujo Oliveira Filho
Make year view delegates async.
79
    }
80
}