after having learned a lot of new things about programming, I decided to go back to my frustrated project, just to see if the new things I learned would help me to get this working. I actually started all over again, but after two days I find myself with practically the same code as before, but now it works even worse. The problem is that the what I previously used to create a KApplication now has a KDE_DEPRECATED next to it in the documentation (and it says it will make my app crash). I tried to do something with KCmdLineArgs and KAboutData, but I get all kinds of error messages.
So now I'm even further from the solution than before, because I have to get the KApplication part right
and then get the slave to work.
I really don't get it, because the code is at its absolute minimum. I don't see why it wouldn't work. Here's the complete code, just without includes, comments and debug messages:
spoof.cpp
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
using namespace KIO;
extern "C"
{
int kdemain( int argc, char** argv )
{
// This causes an error, see below the code
KApplication app();
if( argc != 4 )
exit( -1 );
kio_spoofProtocol slave( argv[2], argv[3] );
slave.dispatchLoop();
return 0;
}
}
kio_spoofProtocol::kio_spoofProtocol( const QCString &pool_socket, const QCString &app_socket )
: SlaveBase( "kio_spoof", pool_socket, app_socket )
{}
kio_spoofProtocol::~kio_spoofProtocol()
{}
void kio_spoofProtocol::get( const KURL& url )
{
KIO::TransferJob* getJob = KIO::get( KURL( "http://www.google.com" ), false, false );
connect( getJob, SIGNAL( data( KIO::Job*, const QByteArray& ) ), this, SLOT( slotData( KIO::Job*, const QByteArray& ) ) );
connect( getJob, SIGNAL( result( KIO::Job* ) ), this, SLOT( slotResult( KIO::Job* ) ) );
}
void kio_spoofProtocol::slotData( KIO::Job* job, const QByteArray& data )
{
kio_spoofProtocol::data( data );
}
void kio_spoofProtocol::slotResult( KIO::Job* job )
{
finished();
}
void kio_spoofProtocol::mimetype( const KURL& url )
{
mimeType( "text/html" );
finished();
}
#include "spoof.moc"
|
spoof.h
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
class QCString;
class kio_spoofProtocol : public QObject, public KIO::SlaveBase
{
Q_OBJECT
public:
kio_spoofProtocol( const QCString& pool_socket, const QCString& app_socket );
virtual ~kio_spoofProtocol();
virtual void mimetype( const KURL& url );
virtual void get( const KURL& url );
public slots:
void slotData( KIO::Job* job, const QByteArray& data );
void slotResult( KIO::Job* job );
};
|
spoof.protocol
|
Source code
|
1
2
3
4
5
6
7
8
9
|
[Protocol]
exec=kio_spoof
protocol=spoof
input=none
output=stream
reading=true
defaultMimetype=text/html
Icon=remote
Description=A kioslave to spoof the referer
|
Just doing a KApplication app causes this error message:
"FAILURE (KCmdLineArgs): Application has not called KCmdLineArgs::init(...).
Adding a KCmdLineArgs::init() means adding a KAboutData so I tried:
KAboutData about( "kio_spoof", I18N_NOOP( "kio_spoof" ), "0" );
KCmdLineArgs::init( argc, argv, &about );
which gets me a new error message
kio_spoof: Unexpected argument 'spoof'.
I'm completely lost, so any tips about the code are welcome. I'm sorry for putting all the code in the message, but I thought that might be clearer. Thanks in advance.