a b/src/qtgui/rclzg.cpp
1
/* Copyright (C) 2012 J.F.Dockes
2
 *   This program is free software; you can redistribute it and/or modify
3
 *   it under the terms of the GNU General Public License as published by
4
 *   the Free Software Foundation; either version 2 of the License, or
5
 *   (at your option) any later version.
6
 *
7
 *   This program is distributed in the hope that it will be useful,
8
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 *   GNU General Public License for more details.
11
 *
12
 *   You should have received a copy of the GNU General Public License
13
 *   along with this program; if not, write to the
14
 *   Free Software Foundation, Inc.,
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
 */
17
18
#ifdef USE_ZEITGEIST
19
#include "rclzg.h"
20
21
#include "debuglog.h"
22
#include "pathut.h"
23
24
#include <QString>
25
#include <QDateTime>
26
#include <QtZeitgeist/QtZeitgeist>
27
#include <QtZeitgeist/Log>
28
#include <QtZeitgeist/Interpretation>
29
#include <QtZeitgeist/Manifestation>
30
#include <QtZeitgeist/DataModel/Event>
31
32
// Can't see no reason why our logger couldn'
33
static QtZeitgeist::Log zglogger;
34
35
void zg_send_event(ZgSendType, const Rcl::Doc& doc)
36
{
37
  static int needinit = 1;
38
  if (needinit) {
39
    QtZeitgeist::init();
40
    needinit = 0;
41
  }
42
43
  // The subject is about the document
44
  QtZeitgeist::DataModel::Subject subject;
45
46
  subject.setUri(QString::fromLocal8Bit(doc.url.c_str()));
47
48
  // TODO: refine these
49
  subject.setInterpretation(QtZeitgeist::Interpretation::Subject::NFODocument);
50
  if (doc.ipath.empty()) 
51
      subject.setManifestation(QtZeitgeist::Manifestation::Subject::NFOFileDataObject);
52
  else
53
      subject.setManifestation(QtZeitgeist::Manifestation::Subject::NFOEmbeddedFileDataObject);      
54
55
  subject.setOrigin(QString::fromLocal8Bit(path_getfather(doc.url).c_str()));
56
57
  subject.setMimeType(doc.mimetype.c_str());
58
59
  string titleOrFilename;
60
  doc.getmeta(Rcl::Doc::keytt, &titleOrFilename);
61
  if (titleOrFilename.empty()) {
62
      doc.getmeta(Rcl::Doc::keyfn, &titleOrFilename);
63
  }
64
  subject.setText(QString::fromUtf8(titleOrFilename.c_str()));
65
66
67
  QtZeitgeist::DataModel::Event event;
68
  event.setTimestamp(QDateTime::currentDateTime());
69
  event.addSubject(subject);
70
71
  event.setInterpretation(QtZeitgeist::Interpretation::Event::ZGAccessEvent);
72
  event.setManifestation(QtZeitgeist::Manifestation::Event::ZGUserActivity);
73
  event.setActor("app://recoll.desktop");
74
75
76
  QtZeitgeist::DataModel::EventList events;
77
  events.push_back(event);
78
79
  LOGDEB(("zg_send_event, sending for %s %s\n", 
80
    doc.mimetype.c_str(), doc.url.c_str()));
81
  zglogger.insertEvents(events);
82
}
83
84
#endif