Development/Tutorials/Solid/Introduction: Difference between revisions

From KDE TechBase
m (moved Development/Tutorials/Solid Tutorials to Development/Tutorials/Solid/Introduction: Makes it more friendly to link and navigation)
(Mark for updating)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Improve}}
== What is Solid ==
== 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 [http://solid.kde.org solid.kde.org].
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].
Line 4: Line 6:
For a more detailed (still not complete!) description, read [[Development/Architecture/KDE4/Solid|here]].
For a more detailed (still not complete!) description, read [[Development/Architecture/KDE4/Solid|here]].


== Who is this tutorial for? ==
The API documentation can be found at [http://api.kde.org/frameworks-api/frameworks5-apidocs/solid/html/index.html 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.
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.


== Prerequisites ==
== Solid core library tutorials ==
* A working KDE4 development environment. Documentation on setting up a KDE environment can be found [[Getting_Started|here]].
 
== Listing Devices ==
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.
 
<syntaxhighlight lang="cpp-qt">
    Solid::DeviceNotifier *notifier = Solid::DeviceNotifier::instance();
</syntaxhighlight>
 
This gets us the device manager.  All the devices are queried through and returned from the device manager.  Once we have the list of devices we can interact with them as follows:
 
<syntaxhighlight lang="cpp-qt">foreach( Solid::Device device, Solid::Device::allDevices() )
{
    //print the name of device
    kDebug() << device.udi();
}
</syntaxhighlight>
 
device.udi() returns the Unique Device Identifier for the device as a QString. Even if you have more than one identical device, the UDI is guaranteed to be unique.  For example if you have a MythTV box with two PVR-250 T.V. capture cards in it, you will be able to refer to card #1 and #2 by their respective UDI.
 
The complete program along with the CMake files necessary to build it can be found under "[http://websvn.kde.org/trunk/KDE/kdeexamples/solid/tutorial1/ kdeexamples/solid/tutorial1/]".
 
== Searching for specific 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.
 
<syntaxhighlight lang="cpp-qt">
Solid::DeviceNotifier *notifier = Solid::DeviceNotifier::instance();
   
//get a list of all devices that are AudioHw
foreach (Solid::Device device, Solid::Device::listFromType(Solid::DeviceInterface::AudioInterface, QString()))
{
  kDebug() << device.udi().toLatin1().constData();
}
</syntaxhighlight>
 
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:
   
<syntaxhighlight lang="cpp-qt">Solid::Device::listFromType(Solid::Capability::AudioHw,"real_specific_parent" )</syntaxhighlight>
The complete program along with the CMake files required to build it can be found under "[http://websvn.kde.org/trunk/KDE/kdeexamples/solid/tutorial2/ kdeexamples/solid/tutorial2/]".
 
== What do we do with a device once we get it? ==
Now that we got a device, what do we do with it?  First let's look at the relationship between the Solid::Device and Solid::Capability. A Solid::Device can contain many Solid::Capability.  A device can be tested to have a capability in the following way:
<syntaxhighlight lang="cpp-qt">
Solid::DeviceNotifier *notifier = Solid::DeviceNotifier::instance();
 
//get a Processor
QList<Solid::Device> list = Solid::Device::listFromType(Solid::DeviceInterface::Processor, QString());
 
//take the first processor
Solid::Device device = list[0];
if(device.is<Solid::Processor>() ) kDebug() << "We've got a processor!";
else kDebug() << "Device is not a processor.";
 
Solid::Processor *processor = device.as<Solid::Processor>();
kDebug() << "This processors maximum speed is:" << processor->maxSpeed();
 
</syntaxhighlight>
 
To actually use this device as a processor we need to do the following:
<syntaxhighlight lang="cpp-qt">
    Solid::Processor *processor = device.as<Solid::Processor>();
</syntaxhighlight>
The complete program along with the CMake files required to build it can be found under "[http://websvn.kde.org/trunk/KDE/kdeexamples/solid/tutorial3/ kdeexamples/solid/tutorial3/]".
 
== solid-hardware tool ==
 
kdebase-runtime provides solid-hardware, a command line tool to investigate available devices.
 
Listing udi for all installed devices:
 
<syntaxhighlight lang="text">
solid-hardware list
</syntaxhighlight>
 
Listing full details for all installed devices:


<syntaxhighlight lang="text">
;[[Development/Tutorials/Solid/Device_Discovery|Listing Devices]]
solid-hardware list details
:''How to use the Solid core library to discover the hardware and interact with the system.''
</syntaxhighlight>


Listing all audio hardware devices:
;[[Development/Tutorials/Solid/Network_Management|Accessing Network Information]]
:''How to use the Solid system to get information about the network''


<syntaxhighlight lang="text">
;[[Development/Tutorials/Solid/Device_Actions|Creating a Device Action]]
solid-hardware query 'IS AudioInterface'
:''When your application is interested in registering actions with the system for removable hardware''
</syntaxhighlight>


[[Category:Tutorial]]
[[Category:Tutorial]]

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