Development/Tutorials/Solid/Introduction: Difference between revisions

From KDE TechBase
No edit summary
 
(Mark for updating)
 
(51 intermediate revisions by 14 users not shown)
Line 1: Line 1:
{{Improve}}
== What is Solid ==
== What is Solid ==
Solid is the new hardware device framework for KDE 4.  It features, among many things, a hardware discovery layer which allows you to detect and use devices regardless of operating system or architecture.
Solid is the new hardware device framework for KDE 4 that features, among other things, a hardware discovery layer which allows you to detect and use devices regardless of operating system or architecture. You can learn more about the Solid project at [http://solid.kde.org solid.kde.org].


== Who is this tutorial for? ==
For a more detailed (still not complete!) description, read [[Development/Architecture/KDE4/Solid|here]].
This tutorial is written for developers looking to use the solid hardware discovery layer within their applications.  It can also serve as a good starting point for developers looking to start working o the solid framework.


== Prerequisites ==
The API documentation can be found at [http://api.kde.org/frameworks-api/frameworks5-apidocs/solid/html/index.html api.kde.org]
You must first have a working KDE4 development environment.  KDE4 has been merged into the kdelibs package so you will need to have a working copy of 'qt-copy' and 'kdelibs' from the subversion repository.  Avoid checking out source code on mondays as code checked out on that day isn't guaranteed to compile.  A HOW-TO can be found [http://solid.kde.org/wiki/index.php/BuildEnv here].


== Listing Devices ==
== Who are those tutorials for? ==
Our first program will be a simple console based app that gets a list of all the hardware devices and prints them out to the screen.
This tutorial is written for developers looking to use the Solid hardware discovery layer within their applications.  It can also serve as a good starting point for developers looking to start working on the Solid framework.


<code>
== Solid core library tutorials ==
    Solid::DeviceManager &manager = Solid::DeviceManager::self();
</code>
This gets us the device manager.  All devices are the queried through and returned from the device manager.  Once we have the list of devices we can interact with them as follows:
<code>
    foreach(Solid::Device device, manager.allDevices() )
    {
        //print the name of device
        cout << device.udi().toLatin1().constData() << endl;
    }
</code>
<code>device.udi()</code> returns the Unique IDentifier for the device as a QString, meaning even if you have two cards that are identical the udi will be, well, unqiue.  A case where this is inmportant is where we have a MythTV box with two PVR-250 tv capture cards in it.  We will be able to refer to card #1 by it's udi and card #2 by it's udi.<br>
Everything after <code>udi()</code> is required to output the QString to the terminal.<br>
The complete program along with all the CMakeFile can be found under "kdelibs/solid/examples/tutorial1/".


== Searching for specific devices ==
;[[Development/Tutorials/Solid/Device_Discovery|Listing Devices]]
This second program makes uses of filters built into the solid framework.  Using these filters you can list only devices according to supported capabilities, sub-devices of a given parent, and various predicates.  In our example we'll be limiting our list to only audio hardware.  A full list of capabilities can be viewed under the Solid::Capability namespace.
:''How to use the Solid core library to discover the hardware and interact with the system.''
<code>
    Solid::DeviceManager &manager = Solid::DeviceManager::self();
   
    //get a list of all devices that are AudioHw
    foreach(Solid::Device device, manager.findDevicesFromQuery("",Solid::Capability::AudioHw) )
    {
        cout << device.udi().toLatin1().constData() << endl;
    }
</code>
In this example Solid::DeviceManager::findDevicesFromQuery looks for a device with any parent and the Solid::Capability::AudioHw capability.  If we had wanted to specify an AudioHw device with the parent "real_specific_parent" it would look like this:
    <code>manager.findDevicesFromQuery("real_specific_parent", Solid::Capability::AudioHw)</code>
The complete program along with all the CMakeFile can be found under "kdelibs/solid/examples/tutorial2/".


== What do we do with a device once we get it? ==
;[[Development/Tutorials/Solid/Network_Management|Accessing Network Information]]
ow that we got a device, what do we do with it?  First lets look at the relationship between the Solid::Device and Solid::Capbility. A Solid::Device can contain many Solid::Capability.  A device can be tested to have a capability in the following way:
:''How to use the Solid system to get information about the network''
<code>
    Solid::DeviceManager &manager = Solid::DeviceManager::self();
   
    //get a Processor
    Solid::DeviceList list = manager.findDevicesFromQuery("",Solid::Capability::Processor);


    //take the first processor
;[[Development/Tutorials/Solid/Device_Actions|Creating a Device Action]]
    Solid::Device device = list[0];
:''When your application is interested in registering actions with the system for removable hardware''
    if(device.is<Solid::Processor>() ) cout << "We've got a processor!" << endl;
    else cout << "Device is not a processor." << endl;
</code>


To actually use this device as a processor we need to do the following:
[[Category:Tutorial]]
<code>
[[Category:C++]]
    Solid::Processor *processor = device.as<Solid::Processor>();
[[Category:KDE4]]
</code>
[[Category:Solid]]
The complete program along with all the CMakeFile can be found under "kdelibs/solid/examples/tutorial3/".

Latest revision as of 11:18, 31 May 2019

Warning
This section needs improvements: Please help us to

cleanup confusing sections and fix sections which contain a todo


What is Solid

Solid is the new hardware device framework for KDE 4 that features, among other things, a hardware discovery layer which allows you to detect and use devices regardless of operating system or architecture. You can learn more about the Solid project at solid.kde.org.

For a more detailed (still not complete!) description, read here.

The API documentation can be found at api.kde.org

Who are those tutorials for?

This tutorial is written for developers looking to use the Solid hardware discovery layer within their applications. It can also serve as a good starting point for developers looking to start working on the Solid framework.

Solid core library tutorials

Listing Devices
How to use the Solid core library to discover the hardware and interact with the system.
Accessing Network Information
How to use the Solid system to get information about the network
Creating a Device Action
When your application is interested in registering actions with the system for removable hardware