aboutsummaryrefslogtreecommitdiff
path: root/examples/trackergrid/trackergridpage.cpp
blob: d60ccb9c04fb94df7b890cde841c711c7077ab6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include <MApplicationPage>
#include <MLocale>
#include <MWidgetFactory>
#include <MImage>
#include <MGrid>

#include "trackergridpage.h"

// Implementation for custom grid widget factory plugin
MWidget *GridWidgetFactoryPlugin::onBuild(QMap<QString, QVariant>* data)
{
    qDebug() << "GridWidgetFactoryPlugin::onBuild()";

    // Check that Mime type is image
    if (data->value("?GridItem_Mime").toString().contains("image/")) {
        // Make full path to image file
        QString fullpath = data->value("?GridItem_Path").toString() +
                           QString("/") +
                           data->value("?GridItem_Name").toString();

        // nfo::Image ontology presents paths like this: "file:///home/user"
        // so strip the prefix
        if (fullpath.startsWith(QString("file:/")))
            fullpath = fullpath.right(fullpath.length() - 6);

        // Construct MImage with the full path to image
        qDebug() << "...creating MImage from " << fullpath;
        MImage *widget = new MImage(fullpath);

        // Set widget size
        QSize size(128, 128);
        widget->setMinimumSize(size);
        widget->setMaximumSize(size);
        widget->setPreferredSize(size);

        return (MWidget *)widget;
    }
    return 0;
}

QStringList GridWidgetFactoryPlugin::dataFields()
{
    qDebug() << "GridWidgetFactoryPlugin::dataFields()";

    static QStringList list;

    if (list.empty()) {
        list << "?GridItem_Name";
        list << "?GridItem_Path";
        list << "?GridItem_Mime";
    }

    return list;
}



// Implementation for tracker grid page
TrackerGridPage::TrackerGridPage()
{
    qDebug() << "TrackerGridPage::TrackerGridPage()";

    //% "TrackerGridPage"
    setTitle(qtTrId("xx_tracker_grid_page_title"));
    setObjectName("trackergridpage");
}

TrackerGridPage::~TrackerGridPage()
{
}

void TrackerGridPage::createContent()
{
    qDebug() << "TrackerGridPage::createContent()";

    MApplicationPage::createContent();

    // Grid for presenting tracker items
    grid = new MGrid();
    grid->resize(800, 450);
    grid->setSpacing(10);
    grid->setLayoutMode(MGridModel::SinglePass);
    grid->setBatchSize(100);
    setCentralWidget(grid);

    // Attach a custom grid plugin to widget factory:
    // default plugins cannot handle tracker data format
    MWidgetFactory *pFactory = MWidgetFactory::instance();
    pFactory->attachPlugin(new GridWidgetFactoryPlugin());

    // Query 20 images from tracker
    SopranoLive::RDFSelect query;
    makeQueryForImages(query, 20);
    imageNodes = tracker()->modelQuery(query);

    // Connect signals to get live data updates
    connectUpdateSignals(imageNodes);

    // Pass the abstract item model to grid
    grid->setItemModel(imageNodes.model());
}

// SELECT ?__GridItem_MimeObjOfnie_mimeType ?__GridItem_PathObjOfnfo_belongsToContainer ?__GridItem_NameObjOfnfo_fileName
// WHERE {
//   {
//     ?__1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Image> .
//     ?__1 <http://www.semanticdesktop.org/ontologies/2007/01/19/nie#mimeType> ?__GridItem_MimeObjOfnie_mimeType .
//     ?__1 <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#belongsToContainer> ?__GridItem_PathObjOfnfo_belongsToContainer .
//     ?__1 <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#fileName> ?__GridItem_NameObjOfnfo_fileName .
//   }
// }
// LIMIT 20
void TrackerGridPage::makeQueryForImages(SopranoLive::RDFSelect &query, int limit)
{
    qDebug() << "TrackerGridPage::makeQueryForImages()";

    SopranoLive::RDFVariable image = SopranoLive::RDFVariable::fromType<SopranoLive::nfo::Image>();
    query.limit(limit);
    query.addColumn("GridItem_Mime", image.property<SopranoLive::nie::mimeType>());
    query.addColumn("GridItem_Path", image.property<SopranoLive::nfo::belongsToContainer>());
    query.addColumn("GridItem_Name", image.property<SopranoLive::nfo::fileName>());
    qDebug() << query.getQuery();
}

void TrackerGridPage::connectUpdateSignals(const SopranoLive::LiveNodes &nodes)
{
    qDebug() << "TrackerGridPage::connectUpdateSignals()";

    QObject::connect(nodes.model(), SIGNAL(rowsInserted(QModelIndex, int, int))
                     , this, SLOT(updateGrid()));
    QObject::connect(nodes.model(), SIGNAL(rowsRemoved(QModelIndex, int, int))
                     , this, SLOT(updateGrid()));
    QObject::connect(nodes.model(), SIGNAL(dataChanged(QModelIndex, QModelIndex))
                     , this, SLOT(updateGrid()));
}

void TrackerGridPage::updateGrid()
{
    qDebug() << "TrackerGridPage::updateGrid()";
}

// End of file