1 /***************************************************************************
2 * Copyright (C) 2008 by Pino Toscano <pino@kde.org> *
3 * Copyright (C) 2008 by Harri Porten <porten@kde.org> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
11 #include "kjs_util_p.h"
13 #include <kjs/kjsobject.h>
14 #include <kjs/kjsprototype.h>
15 #include <kjs/kjsarguments.h>
19 using namespace Okular
;
21 static KJSPrototype
*g_utilProto
;
23 static KJSObject
crackURL( KJSContext
*context
, void *,
24 const KJSArguments
&arguments
)
26 if ( arguments
.count() < 1 )
28 return context
->throwException( "Missing URL argument" );
30 QString cURL
= arguments
.at( 0 ).toString( context
);
34 return context
->throwException( "Invalid URL" );
36 if ( url
.protocol() != QLatin1String( "file" )
37 || url
.protocol() != QLatin1String( "http" )
38 || url
.protocol() != QLatin1String( "https" ) )
40 return context
->throwException( "Protocol not valid: '" + url
.protocol() + '\'' );
44 obj
.setProperty( context
, "cScheme", url
.protocol() );
46 obj
.setProperty( context
, "cUser", url
.user() );
48 obj
.setProperty( context
, "cPassword", url
.password() );
49 obj
.setProperty( context
, "cHost", url
.host() );
50 obj
.setProperty( context
, "nPort", url
.port( 80 ) );
51 // TODO cPath (Optional) The path portion of the URL.
52 // TODO cParameters (Optional) The parameter string portion of the URL.
54 obj
.setProperty( context
, "cFragments", url
.ref() );
59 void JSUtil::initType( KJSContext
*ctx
)
61 static bool initialized
= false;
66 g_utilProto
= new KJSPrototype();
67 g_utilProto
->defineFunction( ctx
, "crackURL", crackURL
);
70 KJSObject
JSUtil::object( KJSContext
*ctx
)
72 return g_utilProto
->constructObject( ctx
, 0 );