Difference between revisions of "Development/Tutorials/Collaboration/Attica/Introduction"

Line 59: Line 59:
#include <attica/providermanager.h>
#include <attica/providermanager.h>
#include "simplepersonrequest.h"
#include "simplepersonrequest.h"
#include "contentdownload.h"
#include "contentcreation.h"
MainWindow::MainWindow(QWidget *parent) : KMainWindow(parent)
MainWindow::MainWindow(QWidget *parent) : KMainWindow(parent)
Line 94: Line 91:
#include "mainwindow.moc"
#include "mainwindow.moc"

Revision as of 18:46, 17 November 2009


Attica Introduction
Tutorial Series   Attica
Previous   Getting started with KDE development
What's Next   n/a
Further Reading   n/a


In this tutorial you learn how to use Attica to access the Open Collaboration Services in your application.

Our goal is to get a list of friends for any user registered on this site.

With Attica you can easily access services from providers such as openDesktop.org. It implements the freedesktop.org specification for the Open Collaboration Services API.

Initializing the Provider Manager

Attica supports multiple Open Collaboration Service (OCS) providers at the same time. Therefor the first thing to do is getting a ProviderManager and either asking it for a default provider (e.g. openDesktop.org for KDE) or setting a different provider by hand. Let's create a mainwindow class that loads a default provider.



  1. ifndef MAINWINDOW_H
  2. define MAINWINDOW_H
  1. include <KMainWindow>
  2. include <KLineEdit>
  3. include <QLabel>
  1. include <attica/providermanager.h>
  2. include <attica/provider.h>

class MainWindow : public KMainWindow {



   MainWindow(QWidget *parent=0);

public Q_SLOTS:

   void providersChanged();


   Attica::Provider m_provider;
   Attica::ProviderManager m_manager;


  1. endif



  1. include "mainwindow.h"
  1. include <KDebug>
  2. include <QVBoxLayout>
  1. include <attica/providermanager.h>
  2. include "simplepersonrequest.h"

MainWindow::MainWindow(QWidget *parent) : KMainWindow(parent) {

   connect(&m_manager, SIGNAL(providersChanged()), SLOT(providersChanged()));


void MainWindow::providersChanged() {

   if (!m_manager.providers().isEmpty()) {
       m_provider = m_manager.providerByUrl(QUrl("https://api.opendesktop.org/v1/"));
       if (!m_provider.isValid()) {
           kDebug() << "Could not find opendesktop.org provider.";
       QTabWidget* mainWidget = new QTabWidget(this);
       SimplePersonRequest* personWidget = new SimplePersonRequest(m_provider, this);
       mainWidget->addTab(personWidget, tr("Person Search"));
       ContentDownload* contentWidget = new ContentDownload(m_provider, this);
       mainWidget->addTab(contentWidget, tr("Content"));
       ContentCreation* contentCreationWidget = new ContentCreation(m_provider, this);
       mainWidget->addTab(contentCreationWidget, tr("Add Content"));


  1. include "mainwindow.moc"



Content is available under Creative Commons License SA 4.0 unless otherwise noted.