Difference between revisions of "Using a kioslave in KDE 4"

From ThorstensHome
Jump to: navigation, search
m (1 revision(s))
 
Line 1: Line 1:
Here we write a simple browser to show how easy it is to use kioslaves in KDE 4. The browser will download the page www.kde.org and show the html sourcecode.
+
Here we write a simple browser to show how easy it is to use kioslaves in KDE 4. The browser will download the page www.kde.org and show the html sourcecode. Then we use kio_fish instead of kio_http by just changing the address that we want to fetch.
  
= The files =
+
= The browser =
 +
The browser uses kio_http.
  
== main.cpp ==
+
== The files ==
 +
 
 +
=== main.cpp ===
 
<pre>
 
<pre>
 
#include <QString>
 
#include <QString>
Line 29: Line 32:
 
</pre>
 
</pre>
  
== browser.h ==  
+
=== browser.h ===  
 
<pre>
 
<pre>
 
#ifndef KDE4START_H__
 
#ifndef KDE4START_H__
Line 51: Line 54:
 
</pre>
 
</pre>
  
== browser.cpp ==
+
=== browser.cpp ===
 
<pre>
 
<pre>
 
#include <kio/scheduler.h>
 
#include <kio/scheduler.h>
Line 81: Line 84:
 
</pre>
 
</pre>
  
== CMakeLists.txt ==
+
=== CMakeLists.txt ===
 
<pre>
 
<pre>
 
PROJECT( browser )
 
PROJECT( browser )
Line 98: Line 101:
 
</pre>
 
</pre>
  
= Kompile, link and run it =
+
== Kompile, link and run it ==
 
  cmake . && make && ./browser
 
  cmake . && make && ./browser
 +
 +
= kio_fish =
 +
It is now quite easy to use kio_fish instead of kio_http. You just change
 +
http://www.kde.org
 +
to
 +
fish://root@localhost/tmp/fishtest.txt
 +
and fill the file fishtest.txt:
 +
echo hallo>/tmp/fishtest.txt
  
 
= See also =
 
= See also =
 
* [[Write a kioslave for KDE 4]]
 
* [[Write a kioslave for KDE 4]]

Latest revision as of 11:51, 3 January 2009

Here we write a simple browser to show how easy it is to use kioslaves in KDE 4. The browser will download the page www.kde.org and show the html sourcecode. Then we use kio_fish instead of kio_http by just changing the address that we want to fetch.

Contents

The browser

The browser uses kio_http.

The files

main.cpp

#include <QString>
#include <kapplication.h>
#include <kaboutdata.h>
#include <klocalizedstring.h>
#include <kmessagebox.h>
#include <kcmdlineargs.h>
#include <KMainWindow>
#include <browser.h>

int main (int argc, char *argv[])
{
  // KAboutData (const QByteArray &appName, const QByteArray &catalogName, const KLocalizedString &programName, const QByteArray &version,
  const QByteArray& ba=QByteArray("test");
  const KLocalizedString name=ki18n("myName");
  KAboutData aboutData( ba, ba, name, ba, name);
  KCmdLineArgs::init( argc, argv, &aboutData );
  KApplication khello;

  Browser *mw = new Browser();
  mw->show();
  khello.exec();
}

browser.h

#ifndef KDE4START_H__
#define KDE4START_H__

#include <kmainwindow.h>
#include <kio/scheduler.h>
#include <kurl.h>
#include <kio/jobclasses.h>

class Browser : public QWidget
{
  Q_OBJECT
  public:
    Browser();
  public slots:
    void slotButtonClicked();
    void dataishere(KIO::Job *,const QByteArray &);
};
#endif

browser.cpp

#include <kio/scheduler.h>
#include <kurl.h>
#include <kio/jobclasses.h>
#include <kdebug.h>
#include <browser.h>

class TransferJob;

Browser::Browser() : QWidget(NULL)
{
  slotButtonClicked();
}

void Browser::slotButtonClicked()
{
  kDebug() << "entering function";
  // creating a kioslave
  KIO::TransferJob *job = KIO::get(KUrl("http://www.kde.org"));
  connect (job, SIGNAL(  data(KIO::Job *, const QByteArray & )), this, SLOT(dataishere(KIO::Job *,const QByteArray &)));
}

void Browser::dataishere(KIO::Job *,const QByteArray & data )
{
  kDebug() << "data is here";
  kDebug() << data;
}

CMakeLists.txt

PROJECT( browser )
FIND_PACKAGE(KDE4 REQUIRED)
INCLUDE_DIRECTORIES( ${KDE4_INCLUDES} . )


SET(kde4startSources main.cpp browser.cpp )


KDE4_ADD_EXECUTABLE(browser ${kde4startSources} )

TARGET_LINK_LIBRARIES(browser ${KDE4_KDEUI_LIBS} ${KDE4_KPARTS_LIBS} )

install(TARGETS browser  DESTINATION ${BIN_INSTALL_DIR} )

Kompile, link and run it

cmake . && make && ./browser

kio_fish

It is now quite easy to use kio_fish instead of kio_http. You just change

http://www.kde.org

to

fish://root@localhost/tmp/fishtest.txt

and fill the file fishtest.txt:

echo hallo>/tmp/fishtest.txt

See also