Port customDataContainersEngine example

This commit is contained in:
Bhushan Shah 2013-09-04 19:39:01 +05:30
parent 0be909e24a
commit 82de6a8ecf
5 changed files with 21 additions and 10 deletions

View File

@ -1,3 +1,3 @@
add_subdirectory(simpleEngine)
add_subdirectory(sourcesOnRequest)
#add_subdirectory(customDataContainers)
add_subdirectory(customDataContainers)

View File

@ -3,8 +3,14 @@ set(customDataContainers_SRCS
httpContainer.cpp
)
kde4_add_plugin(plasma_dataengine_example_customDataContainers ${customDataContainers_SRCS})
target_link_libraries(plasma_dataengine_example_customDataContainers ${KDE4_PLASMA_LIBS} ${KDE4_KIO_LIBS})
kservice_desktop_to_json(plasma-dataengine-example-customDataContainers.desktop)
plasma_add_plugin(plasma_dataengine_example_customDataContainers ${customDataContainers_SRCS})
target_link_libraries(plasma_dataengine_example_customDataContainers
plasma
${KService_LIBRARIES}
${KDE4_KIO_LIBS}
)
install(TARGETS plasma_dataengine_example_customDataContainers DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES plasma-dataengine-example-customDataContainers.desktop DESTINATION ${SERVICES_INSTALL_DIR} )

View File

@ -23,6 +23,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <QUrl>
#include <QDebug>
#include "customDataContainersEngine.h"
#include "httpContainer.h"
@ -44,9 +47,9 @@ bool DataContainersEngine::sourceRequestEvent(const QString &source)
{
// This engine will fetch webpages over http. First thing we do is check
// the source to make sure it is indeed an http URL.
KUrl url(source);
kDebug() << "goin to fetch" << source << url << url.protocol();
if (!url.protocol().startsWith("http", Qt::CaseInsensitive)) {
QUrl url(source);
qDebug() << "goin to fetch" << source << url << url.scheme();
if (!url.scheme().startsWith("http", Qt::CaseInsensitive)) {
return false;
}
@ -80,7 +83,7 @@ bool DataContainersEngine::updateSourceEvent(const QString &source)
}
// export the plugin; use the plugin name and the class name
K_EXPORT_PLASMA_DATAENGINE(org.kde.examples.customDataContainers, DataContainersEngine)
K_EXPORT_PLASMA_DATAENGINE_WITH_JSON(org.kde.examples.customDataContainers, DataContainersEngine, "plasma-dataengine-example-customDataContainers.json")
// include the moc file so the build system makes it for us
#include "customDataContainersEngine.moc"

View File

@ -28,7 +28,7 @@
#include <KIO/Job>
#include <KIO/TransferJob>
HttpContainer::HttpContainer(const KUrl &url, QObject *parent)
HttpContainer::HttpContainer(const QUrl &url, QObject *parent)
: Plasma::DataContainer(parent),
m_url(url)
{

View File

@ -26,6 +26,8 @@
#ifndef HTTPCONTAINER_H
#define HTTPCONTAINER_H
#include <QUrl>
#include <Plasma/DataContainer>
namespace KIO
@ -38,7 +40,7 @@ class HttpContainer : public Plasma::DataContainer
Q_OBJECT
public:
HttpContainer(const KUrl &url, QObject *parent = 0);
HttpContainer(const QUrl &url, QObject *parent = 0);
void fetchUrl(bool reload = true);
@ -47,7 +49,7 @@ private Q_SLOTS:
void fetchFinished(KJob *);
private:
const KUrl m_url;
const QUrl m_url;
QWeakPointer<KJob> m_job;
QByteArray m_data;
};