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 the openDesktop.org provider. Make sure you have the KDE Plugin for Attica built, otherwise openDesktop.org will not be in the list of default providers.

+

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 the openDesktop.org provider. Make sure you have the KDE Plugin for Attica built, otherwise openDesktop.org will not be in the list of default providers.

=== Mainwindow ===

=== Mainwindow ===

Line 100:

Line 100:

</syntaxhighlight>

</syntaxhighlight>

−

Now we have a simple mainwindow with a tab widget. The real contents is still missing though. The first widget we'll add gives some information about a Person.

+

Now we have a simple mainwindow with a tab widget. The real contents is still missing though. The first widget we'll add gives some information about a Person.

+

+

Note also that in this case the provider file for the OCS server residing at "https://api.opendesktop.org/v1/" is already loaded calling '''m_manager.loadDefaultProviders();'''. If you want to run your custom server you should first load your provider file and then select it using '''m_manager.providerByUrl()''' method.

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 the openDesktop.org provider. Make sure you have the KDE Plugin for Attica built, otherwise openDesktop.org will not be in the list of default providers.

//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_OBJECTpublic:
MainWindow(QWidget*parent=0);publicQ_SLOTS:// Here we will get notified, when the provider is loadedvoid providersChanged();private:// ProviderManager is the class that lets us "create" providers
Attica::ProviderManager m_manager;// A provider that we will ask for data from openDesktop.org
Attica::Provider m_provider;};#endif

//mainwindow.cpp#include "mainwindow.h"#include <KDebug>#include <QVBoxLayout>#include <attica/providermanager.h>#include "simplepersonrequest.h"
MainWindow::MainWindow(QWidget*parent): KMainWindow(parent){// connect to get notified, when new Providers are loadedconnect(&m_manager, SIGNAL(defaultProvidersLoaded()), SLOT(providersChanged()));// tell it to get the default Providers
m_manager.loadDefaultProviders();}// called when a provider was loadedvoid 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;}// Use a tab widget here, so we can add more in the next tutorialQTabWidget* mainWidget =newQTabWidget(this);
setCentralWidget(mainWidget);// Create a widget that will make use of the Provider// and supply information about a Person
SimplePersonRequest* personWidget =new SimplePersonRequest(m_provider,this);
mainWidget->addTab(personWidget, tr("Person Search"));}}#include "mainwindow.moc"

Now we have a simple mainwindow with a tab widget. The real contents is still missing though. The first widget we'll add gives some information about a Person.

Note also that in this case the provider file for the OCS server residing at "https://api.opendesktop.org/v1/" is already loaded calling m_manager.loadDefaultProviders();. If you want to run your custom server you should first load your provider file and then select it using m_manager.providerByUrl() method.
Here is a small example quoting only the code that changed:

Now that we have a Provider, we can ask it for information. As a first step, let's find out who I am. Entering any user nick into a KLineEdit will look up that Person. Here is a class that subclasses QWidget and simply contains two labels that show the real name and city for a Person. Since the Data has to be fetched from the server using a REST API, it is asynchronous. When the data arrived, we get notified by a signal.