Zeitgeist Webrowser in four steps

Ever have one of those “Wow, that was easy” moments in software development?

Here’s a web browser that uses QZeitgeist to feed and pull history in four steps and around 100 lines of code.

1) Wire up a QWebKitView to send pages into Zeitgeist:


// In constructor
{
    m_log = new QZeitgeist::Log(this);
    m_webView = new QWebView(this);
    m_webView->load(QUrl("http://zeitgeist-project.com"));
    connect(m_webView, SIGNAL(loadFinished(bool)), this, SLOT(logPage()));
}

void MainWindow::logPage()
{
    QZeitgeist::DataModel::EventList events;
    QZeitgeist::DataModel::Event event;
    event.setActor("applicaton://zeitgeist-browser-demo.desktop");
    event.setInterpretation(QZeitgeist::Interpretation::Event::ZGAccessEvent);
    event.setManifestation(QZeitgeist::Manifestation::Event::ZGUserActivity);

    QZeitgeist::DataModel::Subject subject;
    subject.setInterpretation(QZeitgeist::Interpretation::Subject::NFOWebsite);
    subject.setManifestation(QZeitgeist::Manifestation::Subject::NFORemoteDataObject);
    subject.setUri(m_webView->url().toString());
    subject.setText(m_webView->title());

    event.setSubjects(QZeitgeist::DataModel::SubjectList() << subject);     m_log->insertEvents(QZeitgeist::DataModel::EventList() << event);
    qDebug() << "Logged" << subject.uri();
}

2) Add a view to display your history:

// In constructor
{
    QZeitgeist::LogModel *history = new QZeitgeist::LogModel(this);
    QZeitgeist::DataModel::Event eventTemplate;
    QZeitgeist::DataModel::Subject subjectTemplate;
    subjectTemplate.setInterpretation(QZeitgeist::Interpretation::Subject::NFOWebsite);
    eventTemplate.setSubjects(QZeitgeist::DataModel::SubjectList() << subjectTemplate);     history->setResultType(QZeitgeist::Log::MostRecentSubjects);
    history->setEventTemplates(QZeitgeist::DataModel::EventList() << eventTemplate);     QDockWidget *historyDock = new QDockWidget(tr("History"), this);     addDockWidget(Qt::LeftDockWidgetArea, historyDock);     QAbstractItemView *historyView = new QListView(historyDock);     historyView->setModel(history);
    historyDock->setWidget(historyView);
}

3) Connect the history view to the web view:

// In constructor
{
    connect(historyView, SIGNAL(activated(QModelIndex)), this, SLOT(loadHistory(QModelIndex)));
}

void MainWindow::loadHistory(const QModelIndex &idx)
{
    m_webView->load(idx.data(QZeitgeist::LogModel::URLRole).toUrl());
}

4) Call it a day:

Finished browser, already full of my chrome history. Click to embiggen.

The full source is available in the QZeitgeist demos:
https://projects.kde.org/projects/kdesupport/libqzeitgeist/repository/revisions/master/show/demos/browser

This entry was posted in Fedora, Gnome, KDE. Bookmark the permalink.

6 Responses to Zeitgeist Webrowser in four steps

  1. Edgar Fish says:

    Looks great. Have you patched rekonq to have that feature, too?

  2. sebas says:

    events in logPage seems unused, or is it?

    • Trever says:

      Whoops. I missed a line when copy-pasting it. Thanks for catching that. The demo in the repository is complete though.

  3. Pingback: Trever Fischer dimostra l’integrazione di Zeitgeist su Dragon Player | Indipedia – Indipendenti nella rete

  4. Pingback: Trever Fischer dimostra l’integrazione di Zeitgeist su Dragon Player | RampaCrew

  5. Pingback: A gentle introduction to Zeitgeist’s Python API | eurion.net

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>