Development/Tutorials/Collaboration/Attica/Introduction: Difference between revisions

From KDE TechBase
Line 7: Line 7:
}}
}}


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


Line 14: Line 14:
With Attica you can easily access services from providers such as [http://opendesktop.org openDesktop.org].
With Attica you can easily access services from providers such as [http://opendesktop.org openDesktop.org].
It implements the [http://www.freedesktop.org freedesktop.org] specification for the [http://www.freedesktop.org/wiki/Specifications/open-collaboration-services Open Collaboration Services API].
It implements the [http://www.freedesktop.org freedesktop.org] specification for the [http://www.freedesktop.org/wiki/Specifications/open-collaboration-services 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.
====mainwindow.h====
<code cppqt>
//mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <KMainWindow>
#include <KLineEdit>
#include <QLabel>
#include <attica/providermanager.h>
#include <attica/provider.h>
class MainWindow : public KMainWindow
{
    Q_OBJECT
public:
    MainWindow(QWidget *parent=0);
public Q_SLOTS:
    void providersChanged();
private:
    Attica::Provider m_provider;
    Attica::ProviderManager m_manager;
};
#endif
</code>
====mainwindow.cpp====
<code cppqt>
//mainwindow.cpp
#include "mainwindow.h"
#include <KDebug>
#include <QVBoxLayout>
#include <attica/providermanager.h>
#include "simplepersonrequest.h"
#include "contentdownload.h"
#include "contentcreation.h"
MainWindow::MainWindow(QWidget *parent) : KMainWindow(parent)
{
    connect(&m_manager, SIGNAL(providersChanged()), SLOT(providersChanged()));
    m_manager.loadDefaultProviders();
}
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.";
            return;
        }
        QTabWidget* mainWidget = new QTabWidget(this);
        setCentralWidget(mainWidget);
        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"));
    }
}
#include "mainwindow.moc"
</code>

Revision as of 18:45, 17 November 2009


Development/Tutorials/Collaboration/Attica/Introduction


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

Overview

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.

mainwindow.h

//mainwindow.h

  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 {

   Q_OBJECT

public:

   MainWindow(QWidget *parent=0);

public Q_SLOTS:

   void providersChanged();

private:

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

};

  1. endif

mainwindow.cpp

//mainwindow.cpp

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

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

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

}

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.";
           return;
       }
       QTabWidget* mainWidget = new QTabWidget(this);
       setCentralWidget(mainWidget);
       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"